From 7f0423a46daa1cc755aaa02afda2b77de93d6d13 Mon Sep 17 00:00:00 2001 From: Jake Read <jake.read@cba.mit.edu> Date: Fri, 1 Nov 2019 13:45:23 -0400 Subject: [PATCH] update template --- README.md | 2 +- hunks/data/log_objects.js | 8 +- hunks/data/logger.js | 3 + hunks/template.js | 44 +++---- .../contexts/cuttlefish/template-example.json | 117 ++++++++++++++++++ typeset.js | 3 + 6 files changed, 146 insertions(+), 31 deletions(-) create mode 100644 save/contexts/cuttlefish/template-example.json diff --git a/README.md b/README.md index c0b5650..b9132e6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Cuttlefish -Cuttlefish is a modular browser computing system and a member of [the squidworks project](https://gitlab.cba.mit.edu/squidworks/squidworks) to develop a distributed dataflow computing protocol. It is modular code wrapped in dataflow descriptors and handles that allow rapid assembly of computing applications (programs!). Cuttlefish also serves as the eyes into remote dataflow sytems - meaning we can use it as a tool to assemble big networks of computers, all using the same dataflow assumptions - to build, use, update, and discover distributed programs. +Cuttlefish is a modular browser computing system and a member of [the squidworks project](https://gitlab.cba.mit.edu/squidworks/squidworks), an effort to develop a distributed dataflow computing protocol. Here, modular code is wrapped in dataflow descriptors and handles that allow rapid assembly of computing applications (programs!). Cuttlefish also serves as the eyes into remote dataflow sytems - meaning we can use it as a tool to assemble big networks of computers, all using the same dataflow assumptions - to build, use, update, and discover distributed programs.  diff --git a/hunks/data/log_objects.js b/hunks/data/log_objects.js index a61b01b..4c29367 100644 --- a/hunks/data/log_objects.js +++ b/hunks/data/log_objects.js @@ -10,12 +10,10 @@ export default function ObjectLogger() { Hunkify(this) // hmm... - let tolog = new Input('reference', 'tolog', this) - this.inputs.push(tolog) + let tolog = this.input('reference', 'tolog') - let prefix = new State('string', 'prefix', 'LOG:') - let logToConsole = new State('boolean', 'console', true) - this.states.push(prefix, logToConsole) + let prefix = this.state('string', 'prefix', 'LOG:') + let logToConsole = this.state('boolean', 'console', true) this.dom = {} diff --git a/hunks/data/logger.js b/hunks/data/logger.js index c1e6f3a..8218431 100644 --- a/hunks/data/logger.js +++ b/hunks/data/logger.js @@ -40,6 +40,9 @@ export default function ReferenceLogger() { stringRep = raw.join(', ') } else if (typeof raw === "boolean") { stringRep = raw.toString() + } else { + // let js do w/e witchcraft it chooses + stringRep = raw } $(this.dom).children('.txt').html(stringRep) if (logToConsole.value === true) { diff --git a/hunks/template.js b/hunks/template.js index 6434401..f814219 100644 --- a/hunks/template.js +++ b/hunks/template.js @@ -12,51 +12,48 @@ import { State } from './hunks.js' -function Name() { +// our function name actually doesn't matter: hunks in js are named by their +// location on disk +export default function Name() { // this fn attaches handles to our function-object, Hunkify(this) - // inputs, outputs, and state are objects. they have a type (string identifier) - // see 'typeset.js' - // a name (doesn't have to be unique), and we pass them a handle to ourselves... - let inA = new Input('number', 'name', this) - // inputs, outputs and state are all kept locally in these arrays, - // if we don't include them here, the manager will have a hard time finding them ... - this.inputs.push(inA) + // inputs, outputs, and state are objects. + // they each have a type and a name + let inA = this.input('string', 'quiet') + let outB = this.output('string', 'loud') - let outB = new Output('number', 'name', this) - this.outputs.push(outB) - - let stateItem = new State('string', 'name', 'startupValue') - this.states.push(stateItem) + // states take another argument: their default startup value + let stateItem = this.state('string', 'exclaim', '!') // State items also have change handlers, stateItem.onChange = (value) => { - // at this point, something external (probably a human) - // has requested that we change this state variable, + // at this point, a request to update this state item to the provided value + // has been made console.log('requests:', value) // we can reject that, by doing nothing here, or we can stateItem.set(value) + // or compute on it, set limits, etc } // hunks can choose to- or not- have init code. - // at init, the module has been loaded and state variables have been + // at init, the module has been loaded into the JS engine and state variables have been // recalled from any program save - so this is a good point // to check any of those, and setup accordingly ... this.init = () => { this.log('hello template world') } + // there are no rules within this closure, local functions, data, etc... let internalVariable = 'local globals' - - function internalFunc(data) { - // scoped function, not accessible externally - // do work, - return (data) + function internalFunc(str) { + let caps = str.toUpperCase() + caps += stateItem.value + return (caps) } // to divide time between hunks, each has a loop function - // this is the hunks' runtime: a manager calls this once-per-round + // this is the hunks' runtime, and is called repeatedly, as the process runs // here is where we check inputs, put to outputs, do work, etc this.loop = () => { // typically we check inputs and outputs first, @@ -69,6 +66,3 @@ function Name() { } } } - -// the hunk is also an ES6 module, this is how we export those: -export default Name diff --git a/save/contexts/cuttlefish/template-example.json b/save/contexts/cuttlefish/template-example.json new file mode 100644 index 0000000..1852ceb --- /dev/null +++ b/save/contexts/cuttlefish/template-example.json @@ -0,0 +1,117 @@ +{ + "interpreterName": "cuttlefish", + "interpreterVersion": "v0.1", + "hunks": [ + { + "type": "manager", + "name": "nrol", + "inputs": [ + { + "name": "msgs", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "msgs", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "1", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "view", + "name": "tlview", + "inputs": [ + { + "name": "msgs", + "type": "byteArray" + } + ], + "outputs": [ + { + "name": "msgs", + "type": "byteArray", + "connections": [ + { + "inHunkIndex": "0", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "template", + "name": "template_2", + "inputs": [ + { + "name": "quiet", + "type": "string" + } + ], + "outputs": [ + { + "name": "loud", + "type": "string", + "connections": [ + { + "inHunkIndex": "4", + "inHunkInput": "0" + } + ] + } + ], + "states": [ + { + "name": "exclaim", + "type": "string", + "value": "!" + } + ] + }, + { + "type": "interface/string", + "name": "interface/string_3", + "outputs": [ + { + "name": "string", + "type": "string", + "connections": [ + { + "inHunkIndex": "2", + "inHunkInput": "0" + } + ] + } + ] + }, + { + "type": "data/logger", + "name": "data/logger_5", + "inputs": [ + { + "name": "tolog", + "type": "reference" + } + ], + "states": [ + { + "name": "prefix", + "type": "string", + "value": "LOG:" + }, + { + "name": "console", + "type": "boolean", + "value": "true" + } + ] + } + ] +} \ No newline at end of file diff --git a/typeset.js b/typeset.js index d9f2b13..a41959e 100644 --- a/typeset.js +++ b/typeset.js @@ -226,6 +226,9 @@ const TSET = [ } else { return false } + }, + reference: function(str){ + return str } } }, { -- GitLab