diff --git a/README.md b/README.md index 64390ac4efb2f59238b1fd7e72036990ea993607..21d6a62e8ccc21bafda0e2b62fb3040669b2673b 100644 --- a/README.md +++ b/README.md @@ -219,25 +219,3 @@ Here's a list of things that I suspect will eventually roll themselves into bugs - escape key to leave menu (/ keys on dom ? /on new right-click etc) - on zoom, check if element is view or not, - if not view (is block) then look for event parent position, not event - -# ~scraaaatch -~ we have to re-write input / output / state items as genuine lists - -ok - - rewrite Input, Output to act differently on types ... and constrain the list: - Object -> serialized at link using JSON - Array -> - String -> - Number -> Can cast to intx, uintx, float, double - Boolean -- write the link, - -... there's a number of ways to go forward. -they sort of have to happen all at the same time, so, - -> the manager needs to receive not-objects, or, objects we feel that we can serialize successfully for cpp ... and view needs to write these ! - -> the manager needs to typecheck on link hookup - -> the link needs to faithfully serialize and un-serialize, and route ... this goes with the serialization - -> you need to write down some things - -msgs view -> manager: - -msgs manager -> view: diff --git a/hunks/comm/websocketclient.js b/hunks/comm/websocketclient.js index bac945012b7a5a5bde8f261bb213bb165be0262a..c6a53fcf1a7e44ae612f7fb5606ac1654ed63bd3 100644 --- a/hunks/comm/websocketclient.js +++ b/hunks/comm/websocketclient.js @@ -14,18 +14,18 @@ import { function WebSocketClient() { Hunkify(this, 'WebSocketClient') - let dtin = new Input('byteArray', 'data') + let dtin = new Input('Object', 'data') this.inputs.push(dtin) - let dtout = new Output('byteArray', 'data') + let dtout = new Output('Object', 'data') this.outputs.push(dtout) // TODO is tackling state sets / updates / onupdate fn's // this is hunk -> manager commune ... - let statusMessage = new State('string', 'status', 'closed') - let retryCountHandle = new State('number', 'retrycount', 3) - let addressState = new State('string', 'address', '127.0.0.1') - let portState = new State('string', 'port', '2042') + let statusMessage = new State('String', 'status', 'closed') + let retryCountHandle = new State('Number', 'retrycount', 3) + let addressState = new State('String', 'address', '127.0.0.1') + let portState = new State('String', 'port', '2042') this.state.push(statusMessage, retryCountHandle, addressState, portState) // this ws is a client, diff --git a/hunks/hunks.js b/hunks/hunks.js index 7373ba0ab2d148628aa6346dad4a123c02410827..b6fb67dc61a53c0d3a24b05ecd8565b382004694 100644 --- a/hunks/hunks.js +++ b/hunks/hunks.js @@ -27,13 +27,13 @@ function Hunkify(hunk, name) { /* -------------------------- INPUT -------------------------- */ /* --------------------------- ---------------------------- */ -function Input(type, name) { +function Input(type, name, linktype) { this.name = name this.type = type this.data = null this.io = false // rules, baby - if(type !== 'Number' || type !== 'Boolean' || type !== 'String' || type !== 'Object' || type !== 'Any'){ + if(!(type === 'Number' || type === 'Boolean' || type === 'String' || type === 'Object' || type === 'Any')){ throw new Error(`unknown type specified at input, wyd? type: ${this.type}, name: ${this.name}`) } @@ -60,13 +60,19 @@ function Input(type, name) { return null } } + + // hurmmm + if(linktype){ + // assume clear upstream on startup, maybe dangerous? + this.icus = true + } } /* --------------------------- ---------------------------- */ /* ------------------------- OUTPUT -------------------------- */ /* --------------------------- ---------------------------- */ -function Output(type, name) { +function Output(type, name, linktype) { this.name = name this.type = type this.ref = null @@ -124,7 +130,7 @@ function Output(type, name) { this.posted = true } } else { // this would cover "Object" and "Any" and whatever else, do your typechecking there - if(type !== "Object" | type !== "Any") throw new Error(`unknown type specified at hunk, wyd? type: ${this.type}, name: ${this.name}`) + if(!(type === "Object" || type === "Any")) throw new Error(`unknown type specified at hunk, wyd? type: ${this.type}, name: ${this.name}`) this.put = (data) => { if (!this.io) { this.ref = data @@ -193,13 +199,21 @@ function Output(type, name) { } } + /* --------------------------- ---------------------------- */ + /* ----------- OUTPUT TRICKS FOR LINK CONNECTIONS ------------ */ + /* --------------------------- ---------------------------- */ + if(linktype){ + // has stash ? + this.needsAck = false; + } + } function State(type, name, startup) { this.name = name this.type = type // have to be a type we can recognize, - if(type !== 'Number' || type !== 'Boolean' || type !== 'String' || type !== 'Object' || type !== 'Any'){ + if(!(type === 'Number' || type === 'Boolean' || type === 'String' || type === 'Object' || type === 'Any')){ throw new Error(`unknown type specified at state, wyd? type: ${this.type}, name: ${this.name}`) } // TODO pls add check for missing startup value ? diff --git a/hunks/link.js b/hunks/link.js index 64b1ed221983847fc00300f39141fb68937e3c9f..e3defddf2b663c11c9ed309a5e38baf374efd923 100644 --- a/hunks/link.js +++ b/hunks/link.js @@ -13,18 +13,25 @@ import { } from './hunks.js' // END HEADER +const MSGKEY_ACK 254 +// counting down from +const MSGKEY_OBJECT 249 +// hmmm .... +const MSGKEY_NUMBER 248 +const MSGKEY_UINT64 247 + function Link() { Hunkify(this, 'Link') - let dtin = new Input('byteArray', 'data') + let dtin = new Input('Object', 'data') this.inputs.push(dtin) - let dtout = new Output('byteArray', 'data') + let dtout = new Output('Object', 'data') this.outputs.push(dtout) // default messages -> manager, besides also data link - let inputList = new State('string', 'inputList', "msgs (byteArray)") - let outputList = new State('string', 'outputList', "msgs (byteArray)") + let inputList = new State('String', 'inputList', "msgs (Object)") + let outputList = new State('String', 'outputList', "msgs (Object)") this.state.push(inputList, outputList) /* --------------------------- ---------------------------- */ @@ -55,12 +62,12 @@ function Link() { // just add in order let ipKeys = getTypeAndNameKeys(inputList.value) for(let kp of ipKeys){ - this.inputs.push(new Input(kp.typeKey, kp.nameKey)) + this.inputs.push(new Input(kp.typeKey, kp.nameKey, true)) } let opKeys = getTypeAndNameKeys(outputList.value) for(let kp of opKeys){ - this.outputs.push(new Output(kp.typeKey, kp.nameKey)) + this.outputs.push(new Output(kp.typeKey, kp.nameKey, true)) } } @@ -95,9 +102,9 @@ function Link() { } else { // the object doesn't already exist, if(input){ - this.inputs[kp + 1] = new Input(nks[kp].typeKey, nks[kp].nameKey) + this.inputs[kp + 1] = new Input(nks[kp].typeKey, nks[kp].nameKey, true) } else { - this.outputs[kp + 1] = new Output(nks[kp].typeKey, nks[kp].nameKey) + this.outputs[kp + 1] = new Output(nks[kp].typeKey, nks[kp].nameKey, true) } } } @@ -129,11 +136,96 @@ function Link() { this.mgr.sendHunkAsDef(this) } + let msg = (port, data, type) => { + // serialize, add to buffer + } + + let demsg = (data) => { + // WRITE IT + let msg = {} + // data[0] is the route, the link we need to bump on + msg.port = data[0] + // ack or not + switch(data[1]){ + case MSGKEY_ACK: + msg.isAck = true + break; + case MSGKEY_OBJECT: + // TODO still + msg.data = JSON.parse() + default: + throw new Error('no recognized type at link') + break; + } + + return msg + } + + // this ... + let ack = (port) => { + // TODO write ... how ? ... buffer outputs ? + } let outbuffer = new Array() this.loop = () => { - // hurm - // ... + // (1) check for data + if(dtin.io){ // if we have data to handle, receive it + // pulls every time, this is ok because we trust the other link + // to be flow-controlling: this should either be for an open port or + // an ack, + let msg = dtin.get() + if(msg.isAck){ + // AN ACK + if(this.inputs[msg.port].isNetClear){ + throw new Error('received ack on unexpected port') + } + // is clear upstream + this.inputs[msg.port].icus = true; + } else { + // NOT AN ACK + // check port existence + if(this.outputs[msg.port] === undefined){ + throw new Error(`link receives message for port not listed: ${msg.port}`) + break; + } + // not an ack, for port, if open, put data + if(this.outputs[msg.port].io){ + // clear ahead, typecheck and put + this.outputs[msg.port].put(msg.data) + this.outputs[msg.port].needsAck = true + // and ack when it is pulled off, + } else { + // oboy: we pulled it off of the link, so + throw new Error(`link receives message for occupied port, ${this.id}, ${this.outputs[msg.port].name}`) + } + } + // this is an array, we have to deserialize it + }// end if(dataIn is occupied) + + // (2) check if we can put + if(!dtout.io){ // if we can send things to the world, do so + // because of looping sys, we can only do this once per turn + dtout.put(outbuffer.shift()) + } + + // (3) check if we can ack, if data has been consumed + for(let o = 1; o < this.outputs.length; o ++){ + // if now clear, ack back + if(this.outputs[o].needsAck && !this.outputs[o].io){ + this.outputs[o].needsAck = false + ack(o) + } + } + + // (4) look at inputs and see if we can put anything on the line + for(let i = 1; i < this.inputs.length; i ++){ + // only pull off of inputs if we are known to be clear downstream + if(this.inputs[i].icus && this.inputs[i].io) + msg(i, this.inputs[i].get(), this.inputs[i].type) + } + } + + // ok ? } // end loop } diff --git a/hunks/manager.js b/hunks/manager.js index 60377a01c65e481388254664cd2e7f49ac5560d4..57de87dbd4979d99ba0901a0c22f769aa27a26da 100644 --- a/hunks/manager.js +++ b/hunks/manager.js @@ -12,8 +12,8 @@ function Manager() { // need this tool let GG = new GoGetter - let msgsin = new Input('message', 'msgs') - let msgsout = new Output('message', 'msgs') + let msgsin = new Input('Object', 'msgs') + let msgsout = new Output('Object', 'msgs') this.inputs.push(msgsin) this.outputs.push(msgsout) diff --git a/hunks/view.js b/hunks/view.js index bce46a4329d981d14d6b6891641e5e8867e107c5..e52ff42038ee5a7929d712edf30aa0d2caed90c8 100644 --- a/hunks/view.js +++ b/hunks/view.js @@ -29,8 +29,8 @@ function View() { // view of a manager, has route to that manager (via a link?) - let msgsin = new Input('message', 'msgs') - let msgsout = new Output('message', 'msgs') + let msgsin = new Input('Object', 'msgs') + let msgsout = new Output('Object', 'msgs') this.inputs.push(msgsin) this.outputs.push(msgsout) diff --git a/programs/ntlink.json b/programs/ntlink.json index 6ddf7bf358d1899961f1e46535b980b8694abd41..4bf5929571cbb9abc05016cfbfbaab0bd7d3f299 100644 --- a/programs/ntlink.json +++ b/programs/ntlink.json @@ -5,8 +5,8 @@ "name": "link", "id": "lnkone", "state": { - "inputList": "msgs (byteArray), ipOne (uint32)", - "outputList": "msgs (byteArray), opOne (uint32)" + "inputList": "msgs (Object), ipOne (Number)", + "outputList": "msgs (Object), opOne (Number)" } }, { diff --git a/scratch.js b/scratch.js new file mode 100644 index 0000000000000000000000000000000000000000..62473e7513448766604df2f209df411580233da9 --- /dev/null +++ b/scratch.js @@ -0,0 +1,14 @@ +let msg = {} + +if(msg.isAck){ + console.log('eval tru') +} else { + console.log('eval false') +} + +let msgs = new Array() +if(msgs[1]){ + console.log('array evals tru') +} else { + console.log('array evals false') +}