aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2019-06-11 14:54:25 +0900
committerDevine Lu Linvega <[email protected]>2019-06-11 14:54:25 +0900
commitbae63fd82eb0d3dc2bf173c061516c5d91220462 (patch)
treeb1a7a1ca351e84e55fbca68684fcf28c02a58e94
parent99944fae4fd5441c84f11b5ebb99941fbed4c882 (diff)
downloadOrca-bae63fd82eb0d3dc2bf173c061516c5d91220462.tar.gz
Orca-bae63fd82eb0d3dc2bf173c061516c5d91220462.zip
Improved the display of output ports, especially for G and Q
-rw-r--r--desktop/core/library/g.js13
-rw-r--r--desktop/core/library/k.js14
-rw-r--r--desktop/core/library/o.js2
-rw-r--r--desktop/core/library/p.js6
-rw-r--r--desktop/core/library/q.js14
-rw-r--r--desktop/core/library/t.js4
-rw-r--r--desktop/core/library/v.js2
-rw-r--r--desktop/core/library/x.js2
-rw-r--r--desktop/core/operator.js33
-rw-r--r--desktop/sources/scripts/terminal.js2
10 files changed, 54 insertions, 38 deletions
diff --git a/desktop/core/library/g.js b/desktop/core/library/g.js
index 6f55c07..bc08aef 100644
--- a/desktop/core/library/g.js
+++ b/desktop/core/library/g.js
@@ -17,13 +17,12 @@ export default function OperatorG (orca, x, y, passive) {
const x = this.listen(this.ports.x, true)
const y = this.listen(this.ports.y, true) + 1
for (let offset = 0; offset < len; offset++) {
- if (offset > 0) {
- orca.lock(this.x + offset, this.y)
- }
- const port = { x: offset + 1, y: 0 }
- const value = this.listen(port)
- orca.write(this.x + x + offset, this.y + y, value)
+ const inPort = { x: offset + 1, y: 0 }
+ const outPort = { x: x + offset, y: y, output: true }
+ this.addPort(`in${offset}`, inPort)
+ this.addPort(`out${offset}`, outPort)
+ const res = this.listen(inPort)
+ this.output(`${res}`, outPort)
}
- this.ports.output = { x: x, y: y }
}
}
diff --git a/desktop/core/library/k.js b/desktop/core/library/k.js
index 8fce517..0163bb5 100644
--- a/desktop/core/library/k.js
+++ b/desktop/core/library/k.js
@@ -12,12 +12,16 @@ export default function OperatorK (orca, x, y, passive) {
this.operation = function (force = false) {
this.len = this.listen(this.ports.len, true)
- for (let x = 1; x <= this.len; x++) {
- orca.lock(this.x + x, this.y)
- const key = orca.glyphAt(this.x + x, this.y)
+ for (let offset = 0; offset < this.len; offset++) {
+ const key = orca.glyphAt(this.x + offset + 1, this.y)
+ orca.lock(this.x + offset + 1, this.y)
if (key === '.') { continue }
- orca.lock(this.x + x, this.y + 1)
- orca.write(this.x + x, this.y + 1, orca.valueIn(key))
+ const inPort = { x: offset + 1, y: 0 }
+ const outPort = { x: offset + 1, y: 1, output: true }
+ this.addPort(`in${offset}`, inPort)
+ this.addPort(`out${offset}`, outPort)
+ const res = orca.valueIn(key)
+ this.output(`${res}`, outPort)
}
}
}
diff --git a/desktop/core/library/o.js b/desktop/core/library/o.js
index 5f39a88..7a126ce 100644
--- a/desktop/core/library/o.js
+++ b/desktop/core/library/o.js
@@ -15,7 +15,7 @@ export default function OperatorO (orca, x, y, passive) {
this.operation = function (force = false) {
const x = this.listen(this.ports.x, true)
const y = this.listen(this.ports.y, true)
- this.ports.read = { x: x + 1, y: y }
+ this.addPort('read', { x: x + 1, y: y })
return this.listen(this.ports.read)
}
}
diff --git a/desktop/core/library/p.js b/desktop/core/library/p.js
index 4e48af9..2d42745 100644
--- a/desktop/core/library/p.js
+++ b/desktop/core/library/p.js
@@ -8,15 +8,15 @@ export default function OperatorP (orca, x, y, passive) {
this.name = 'push'
this.info = 'Writes eastward operand'
- this.ports.len = { x: -1, y: 0, clamp: { min: 1 } }
this.ports.key = { x: -2, y: 0 }
+ this.ports.len = { x: -1, y: 0, clamp: { min: 1 } }
this.ports.val = { x: 1, y: 0 }
this.operation = function (force = false) {
const len = this.listen(this.ports.len, true)
const key = this.listen(this.ports.key, true)
- for (let x = 0; x < len; x++) {
- orca.lock(this.x + x, this.y + 1)
+ for (let offset = 0; offset < len; offset++) {
+ orca.lock(this.x + offset, this.y + 1)
}
this.ports.output = { x: (key % len), y: 1 }
return this.listen(this.ports.val)
diff --git a/desktop/core/library/q.js b/desktop/core/library/q.js
index 318758d..af12331 100644
--- a/desktop/core/library/q.js
+++ b/desktop/core/library/q.js
@@ -16,13 +16,13 @@ export default function OperatorQ (orca, x, y, passive) {
const len = this.listen(this.ports.len, true)
const x = this.listen(this.ports.x, true)
const y = this.listen(this.ports.y, true)
- for (let i = 1; i <= len; i++) {
- orca.lock(this.x + x + i, this.y + y)
- this.ports[`val${i}`] = { x: x + i, y: y }
- this.ports.output = { x: i - len, y: 1 }
- const res = this.listen(this.ports[`val${i}`])
- this.output(`${res}`)
+ for (let offset = 0; offset < len; offset++) {
+ const inPort = { x: x + offset + 1, y: y }
+ const outPort = { x: offset - len + 1, y: 1, output: true }
+ this.addPort(`in${offset}`, inPort)
+ this.addPort(`out${offset}`, outPort)
+ const res = this.listen(inPort)
+ this.output(`${res}`, outPort)
}
- this.ports.output = { x: 0, y: 1 }
}
}
diff --git a/desktop/core/library/t.js b/desktop/core/library/t.js
index 287a664..0e51cfe 100644
--- a/desktop/core/library/t.js
+++ b/desktop/core/library/t.js
@@ -15,8 +15,8 @@ export default function OperatorT (orca, x, y, passive) {
this.operation = function (force = false) {
const len = this.listen(this.ports.len, true)
const key = this.listen(this.ports.key, true)
- for (let x = 1; x <= len; x++) {
- orca.lock(this.x + x, this.y)
+ for (let offset = 0; offset < len; offset++) {
+ orca.lock(this.x + offset + 1, this.y)
}
this.ports.val = { x: (key % len) + 1, y: 0 }
return this.listen(this.ports.val)
diff --git a/desktop/core/library/v.js b/desktop/core/library/v.js
index 8b2fc96..187a5cd 100644
--- a/desktop/core/library/v.js
+++ b/desktop/core/library/v.js
@@ -15,7 +15,7 @@ export default function OperatorV (orca, x, y, passive) {
const write = this.listen(this.ports.write)
const read = this.listen(this.ports.read)
if (write === '.' && read !== '.') {
- this.ports.output = { x: 0, y: 1 }
+ this.addPort('output', { x: 0, y: 1 })
}
if (write !== '.') {
orca.variables[write] = read
diff --git a/desktop/core/library/x.js b/desktop/core/library/x.js
index 94a41dc..1230d8a 100644
--- a/desktop/core/library/x.js
+++ b/desktop/core/library/x.js
@@ -15,7 +15,7 @@ export default function OperatorX (orca, x, y, passive) {
this.operation = function (force = false) {
const x = this.listen(this.ports.x, true)
const y = this.listen(this.ports.y, true) + 1
- this.ports.output = { x: x, y: y }
+ this.addPort('output', { x: x, y: y })
return this.listen(this.ports.val)
}
}
diff --git a/desktop/core/operator.js b/desktop/core/operator.js
index f2a9ce5..bb118b3 100644
--- a/desktop/core/operator.js
+++ b/desktop/core/operator.js
@@ -24,10 +24,10 @@ export default function Operator (orca, x, y, glyph = '.', passive = false) {
return glyph
}
- this.output = function (g) {
- if (!this.ports.output) { console.warn(this.name, 'Trying to output, but no port'); return }
+ this.output = function (g, port = this.ports.output) {
+ if (!port) { console.warn(this.name, 'Trying to output, but no port'); return }
if (!g) { return }
- orca.write(this.x + this.ports.output.x, this.y + this.ports.output.y, this.shouldUpperCase() === true ? `${g}`.toUpperCase() : g)
+ orca.write(this.x + port.x, this.y + port.y, this.shouldUpperCase() === true ? `${g}`.toUpperCase() : g)
}
this.bang = function (b) {
@@ -38,13 +38,14 @@ export default function Operator (orca, x, y, glyph = '.', passive = false) {
// Phases
this.run = function (force = false) {
+ // Operate
+ const payload = this.operation(force)
// Permissions
for (const id in this.ports) {
orca.lock(this.x + this.ports[id].x, this.y + this.ports[id].y)
}
this.draw = true
- // Operate
- const payload = this.operation(force)
+
if (this.ports.output) {
if (this.ports.output.bang === true) {
this.bang(payload)
@@ -99,6 +100,10 @@ export default function Operator (orca, x, y, glyph = '.', passive = false) {
// Docs
+ this.addPort = function (name, pos) {
+ this.ports[name] = pos
+ }
+
this.getPorts = function () {
const a = []
if (this.draw === true) {
@@ -107,15 +112,23 @@ export default function Operator (orca, x, y, glyph = '.', passive = false) {
if (!this.passive) { return a }
for (const id in this.ports) {
const port = this.ports[id]
- a.push([this.x + port.x, this.y + port.y, port.x < 0 || port.y < 0 ? 1 : 2, `${this.glyph}-${id}`])
- }
- if (this.ports.output) {
- const port = this.ports.output
- a.push([this.x + port.x, this.y + port.y, port.reader || port.bang ? 8 : 3, `${this.glyph}-output`])
+ const type = this.getPortType(id)
+ a.push([this.x + port.x, this.y + port.y, type, `${this.glyph}-${id}`])
}
return a
}
+ this.getPortType = function (id) {
+ const port = this.ports[id]
+ if (port.output || id === 'output') {
+ return port.reader || port.bang ? 8 : 3
+ }
+ if (port.x < 0 || port.y < 0) {
+ return 1
+ }
+ return 2
+ }
+
this.shouldUpperCase = function (ports = this.ports) {
if (!this.ports.output || !this.ports.output.sensitive) { return false }
const value = this.listen({ x: 1, y: 0 })
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index b78e9bb..e625d4c 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -12,7 +12,7 @@ import Controller from './lib/controller.js'
import library from '../../core/library.js'
export default function Terminal () {
- this.version = 138
+ this.version = 139
this.library = library
this.orca = new Orca(this)