aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2018-11-17 11:49:22 +1200
committerDevine Lu Linvega <[email protected]>2018-11-17 11:49:22 +1200
commit85ab1cca1d89ad29783667d395b90fc83bed8d5b (patch)
treea6db1d679cb09bae40be6bb2ea62e7ef426f2c94
parent68fb2d81a53b1d770a6ac455d30058075883ce71 (diff)
downloadOrca-85ab1cca1d89ad29783667d395b90fc83bed8d5b.tar.gz
Orca-85ab1cca1d89ad29783667d395b90fc83bed8d5b.zip
Rebuilding the port system.
-rw-r--r--desktop/core/lib/_base.js13
-rw-r--r--desktop/core/lib/a.js23
-rw-r--r--desktop/core/lib/c.js24
-rw-r--r--desktop/core/lib/f.js20
-rw-r--r--desktop/core/lib/h.js2
-rw-r--r--desktop/core/lib/i.js28
-rw-r--r--desktop/core/lib/j.js4
-rw-r--r--desktop/core/lib/k.js2
-rw-r--r--desktop/core/lib/l.js18
-rw-r--r--desktop/core/lib/m.js23
-rw-r--r--desktop/core/lib/t.js20
-rw-r--r--desktop/core/lib/v.js20
-rw-r--r--desktop/core/lib/x.js6
-rw-r--r--desktop/core/lib/y.js36
-rw-r--r--desktop/core/pico.js4
-rw-r--r--desktop/sources/scripts/source.js2
-rw-r--r--desktop/sources/scripts/terminal.js12
-rw-r--r--examples/benchmark.pico14
18 files changed, 113 insertions, 158 deletions
diff --git a/desktop/core/lib/_base.js b/desktop/core/lib/_base.js
index 5dec65b..25a4eea 100644
--- a/desktop/core/lib/_base.js
+++ b/desktop/core/lib/_base.js
@@ -7,17 +7,26 @@ function FnBase (pico, x, y, glyph = '.', passive = false) {
this.name = 'unknown'
this.glyph = passive ? glyph.toUpperCase() : glyph
this.info = 'Missing docs.'
- this.ports = []
+ this.ports = { inputs: {}, bang: null }
this.docs = 'Hello!'
if (!passive) {
- this.ports.push({ x: 0, y: 0, bang: true })
+ this.ports.bang = true
}
this.id = function () {
return this.x + (this.y * pico.h)
}
+ this.listen = function (port, toValue = false) {
+ const g = pico.glyphAt(this.x + port.x, this.y + port.y)
+ return toValue ? pico.toValue(g) : g
+ }
+
+ this.output = function (g) {
+ pico.add(this.x, this.y + 1, g)
+ }
+
this.haste = function () {
}
diff --git a/desktop/core/lib/a.js b/desktop/core/lib/a.js
index 1588d2d..ff70bff 100644
--- a/desktop/core/lib/a.js
+++ b/desktop/core/lib/a.js
@@ -8,25 +8,14 @@ function FnA (pico, x, y, passive) {
this.name = 'add'
this.info = 'Creates the result of the addition of east and west fns, southward.'
- this.ports.push({ x: -1, y: 0 })
- this.ports.push({ x: 1, y: 0 })
- this.ports.push({ x: 0, y: 1, output: true })
-
- this.haste = function () {
- pico.lock(this.x, this.y + 1)
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x - 1, this.y)
- }
+ this.ports.inputs.a = { x: 1, y: 0 }
+ this.ports.inputs.b = { x: 2, y: 0 }
this.operation = function () {
- const w = this.west()
- const e = this.east()
-
- const val1 = this.toValue(w ? w.glyph : null)
- const val2 = this.toValue(e ? e.glyph : null)
- const res = this.toChar(val1 + val2)
-
- pico.add(this.x, this.y + 1, res)
+ const a = this.listen(this.ports.inputs.a, true)
+ const b = this.listen(this.ports.inputs.b, true)
+ const res = this.toChar(a + b)
+ this.output(`${res}`)
}
}
diff --git a/desktop/core/lib/c.js b/desktop/core/lib/c.js
index d5e291e..fd258c4 100644
--- a/desktop/core/lib/c.js
+++ b/desktop/core/lib/c.js
@@ -7,26 +7,16 @@ function FnC (pico, x, y, passive) {
this.name = 'clock'
this.info = 'Adds a constant value southward.'
- this.ports.push({ x: 0, y: 1, output: true })
- this.ports.push({ x: 1, y: 0, input: true })
- this.ports.push({ x: -1, y: 0, input: true })
- this.haste = function () {
- pico.lock(this.x, this.y + 1)
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x - 1, this.y)
- }
+ this.ports.inputs.min = { x: 1, y: 0 }
+ this.ports.inputs.max = { x: 2, y: 0 }
this.operation = function () {
- const w = this.west()
- const e = this.east()
- const s = this.south()
-
- const min = w ? pico.valueOf(w.glyph) : 0
- const max = e ? pico.valueOf(e.glyph) : 9
- const result = (pico.f % max) + min
-
- pico.add(this.x, this.y + 1, `${pico.allowed[result]}`)
+ const min = this.listen(this.ports.inputs.min, true)
+ const max = this.listen(this.ports.inputs.max, true)
+ const key = (pico.f % max) + min
+ const res = pico.allowed[key] ? pico.allowed[key] : 0
+ this.output(`${res}`)
}
}
diff --git a/desktop/core/lib/f.js b/desktop/core/lib/f.js
index ef567c1..1aac6d7 100644
--- a/desktop/core/lib/f.js
+++ b/desktop/core/lib/f.js
@@ -7,23 +7,15 @@ function FnF (pico, x, y, passive) {
this.name = 'if'
this.info = 'Bangs if east and west fns are equal, southward.'
- this.ports.push({ x: -1, y: 0 })
- this.ports.push({ x: 1, y: 0 })
- this.ports.push({ x: 0, y: 1, output: true })
- this.haste = function () {
- pico.lock(this.x, this.y + 1)
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x - 1, this.y)
- }
+ this.ports.inputs.a = { x: 1, y: 0 }
+ this.ports.inputs.b = { x: 2, y: 0 }
this.operation = function () {
- const w = this.west()
- const e = this.east()
- const val1 = this.toValue(w ? w.glyph : null)
- const val2 = this.toValue(e ? e.glyph : null)
-
- pico.add(this.x, this.y + 1, val1 === val2 ? '1' : '0')
+ const a = this.listen(this.ports.inputs.a, true)
+ const b = this.listen(this.ports.inputs.b, true)
+ const res = a === b ? '1' : '0'
+ this.output(`${res}`)
}
}
diff --git a/desktop/core/lib/h.js b/desktop/core/lib/h.js
index 731208b..f61ee4a 100644
--- a/desktop/core/lib/h.js
+++ b/desktop/core/lib/h.js
@@ -7,7 +7,7 @@ function FnH (pico, x, y, passive) {
this.name = 'halt'
this.info = 'Stops southward fn from operating.'
- this.ports.push({ x: 0, y: 1, output: true })
+ // this.ports.push({ x: 0, y: 1, output: true })
this.haste = function () {
pico.lock(this.x, this.y + 1)
diff --git a/desktop/core/lib/i.js b/desktop/core/lib/i.js
index acdbcba..a3e817f 100644
--- a/desktop/core/lib/i.js
+++ b/desktop/core/lib/i.js
@@ -7,28 +7,18 @@ function FnI (pico, x, y, passive) {
this.name = 'increment'
this.info = 'Increments southward numeric fn on bang.'
- this.ports.push({ x: 0, y: 1, output: true })
- this.ports.push({ x: 1, y: 0, input: true })
- this.ports.push({ x: -1, y: 0, input: true })
- this.haste = function () {
- pico.lock(this.x, this.y + 1)
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x - 1, this.y)
- }
+ this.ports.inputs.min = { x: 1, y: 0 }
+ this.ports.inputs.max = { x: 2, y: 0 }
+ this.ports.inputs.mod = { x: 0, y: 1 }
this.operation = function () {
- const w = this.west()
- const e = this.east()
- const s = this.south()
-
- const min = w ? pico.valueOf(w.glyph) : 0
- const max = e ? pico.valueOf(e.glyph) : 9
- const val = s ? pico.valueOf(s.glyph) : 0
-
- const result = val + 1 >= max ? min : val + 1
-
- pico.add(this.x, this.y + 1, `${pico.allowed[result]}`)
+ const min = this.listen(this.ports.inputs.min, true)
+ const max = this.listen(this.ports.inputs.max, true)
+ const mod = this.listen(this.ports.inputs.mod, true)
+ const key = mod + 1 >= (max || 9) ? min : mod + 1
+ const res = pico.allowed[key] ? pico.allowed[key] : 0
+ this.output(`${res}`)
}
}
diff --git a/desktop/core/lib/j.js b/desktop/core/lib/j.js
index 6a895c0..e231068 100644
--- a/desktop/core/lib/j.js
+++ b/desktop/core/lib/j.js
@@ -7,8 +7,8 @@ function FnJ (pico, x, y, passive) {
this.name = 'jump'
this.info = 'Copies the northward fn, southwardly.'
- this.ports.push({ x: 0, y: -1, input: true })
- this.ports.push({ x: 0, y: 1, output: true })
+ // this.ports.push({ x: 0, y: -1, input: true })
+ // this.ports.push({ x: 0, y: 1, output: true })
this.haste = function () {
pico.lock(this.x, this.y + 1)
diff --git a/desktop/core/lib/k.js b/desktop/core/lib/k.js
index 3c0ae1f..cd9d5b2 100644
--- a/desktop/core/lib/k.js
+++ b/desktop/core/lib/k.js
@@ -7,7 +7,7 @@ function FnK (pico, x, y, passive) {
this.name = 'kill'
this.info = 'Kills southward fns, on bang.'
- this.ports.push({ x: 0, y: 1, output: true })
+ // this.ports.push({ x: 0, y: 1, output: true })
this.operation = function () {
pico.remove(this.x, this.y + 1)
diff --git a/desktop/core/lib/l.js b/desktop/core/lib/l.js
index 8242965..c6557f7 100644
--- a/desktop/core/lib/l.js
+++ b/desktop/core/lib/l.js
@@ -7,15 +7,15 @@ function FnL (pico, x, y, passive) {
this.name = 'loop'
this.info = 'Loop a number of characters ahead.'
- this.ports.push({ x: -1, y: 0, input: true })
-
- if (pico) {
- this.w = this.west()
- this.len = this.w ? pico.valueOf(this.w.glyph) : 0
- for (let x = 1; x <= this.len; x++) {
- this.ports.push({ x: x, y: 0, output: true })
- }
- }
+ // this.ports.push({ x: -1, y: 0, input: true })
+
+ // if (pico) {
+ // this.w = this.west()
+ // this.len = this.w ? pico.valueOf(this.w.glyph) : 0
+ // for (let x = 1; x <= this.len; x++) {
+ // this.ports.push({ x: x, y: 0, output: true })
+ // }
+ // }
this.haste = function () {
for (let x = 1; x <= this.len; x++) {
diff --git a/desktop/core/lib/m.js b/desktop/core/lib/m.js
index 74e3243..cbdf37c 100644
--- a/desktop/core/lib/m.js
+++ b/desktop/core/lib/m.js
@@ -7,25 +7,16 @@ function FnM (pico, x, y, passive) {
this.name = 'modulo'
this.info = 'Creates the result of the modulo operation of east and west fns, southward.'
- this.ports.push({ x: -1, y: 0 })
- this.ports.push({ x: 1, y: 0 })
- this.ports.push({ x: 0, y: 1, output: true })
- this.haste = function () {
- pico.lock(this.x, this.y + 1)
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x - 1, this.y)
- }
+ this.ports.inputs.val = { x: 1, y: 0 }
+ this.ports.inputs.mod = { x: 2, y: 0 }
this.operation = function () {
- const w = this.west()
- const e = this.east()
-
- const val = this.toValue(w ? w.glyph : null)
- const mod = this.toValue(e ? e.glyph : null)
- const res = this.toChar(val % (mod !== 0 ? mod : 1))
-
- pico.add(this.x, this.y + 1, res)
+ const val = this.listen(this.ports.inputs.val, true)
+ const mod = this.listen(this.ports.inputs.mod, true)
+ const key = val % (mod !== 0 ? mod : 1)
+ const res = pico.allowed[key] ? pico.allowed[key] : 0
+ this.output(`${res}`)
}
}
diff --git a/desktop/core/lib/t.js b/desktop/core/lib/t.js
index 2a4547b..9b2da12 100644
--- a/desktop/core/lib/t.js
+++ b/desktop/core/lib/t.js
@@ -7,19 +7,19 @@ function FnT (pico, x, y, passive) {
this.name = 'track'
this.info = 'Read character at position.'
- this.ports.push({ x: -1, y: 0, input: true }, { x: -2, y: 0, input: true }, { x: 0, y: 1, output: true })
+ // this.ports.push({ x: -1, y: 0, input: true }, { x: -2, y: 0, input: true }, { x: 0, y: 1, output: true })
- if (pico) {
- this.lenCh = pico.glyphAt(this.x - 1, this.y)
- this.len = this.lenCh ? pico.valueOf(this.lenCh) : 0
- this.valCh = pico.glyphAt(this.x - 2, this.y)
- this.val = this.valCh ? pico.valueOf(this.valCh) : 0
+ // if (pico) {
+ // this.lenCh = pico.glyphAt(this.x - 1, this.y)
+ // this.len = this.lenCh ? pico.valueOf(this.lenCh) : 0
+ // this.valCh = pico.glyphAt(this.x - 2, this.y)
+ // this.val = this.valCh ? pico.valueOf(this.valCh) : 0
- if (this.lenCh === '.' || this.valCh === '.') { return }
+ // if (this.lenCh === '.' || this.valCh === '.') { return }
- if (!this.len || this.len < 1 || this.val < 0) { return }
- this.ports.push({ x: (this.val % this.len) + 1, y: 0, output: true })
- }
+ // if (!this.len || this.len < 1 || this.val < 0) { return }
+ // this.ports.push({ x: (this.val % this.len) + 1, y: 0, output: true })
+ // }
this.haste = function () {
pico.lock(this.x - 1, this.y)
diff --git a/desktop/core/lib/v.js b/desktop/core/lib/v.js
index 664cc5a..4255440 100644
--- a/desktop/core/lib/v.js
+++ b/desktop/core/lib/v.js
@@ -8,16 +8,16 @@ function FnV (pico, x, y, passive) {
this.name = 'values'
this.info = 'Count the number of fns present eastwardly.'
- this.ports.push({ x: 0, y: 1, output: true })
- this.ports.push({ x: -1, y: 0, input: true })
-
- if (pico) {
- this.w = this.west()
- this.len = this.w ? pico.valueOf(this.w.glyph) : 0
- for (let x = 1; x <= this.len; x++) {
- this.ports.push({ x: x, y: 0, input: true })
- }
- }
+ // this.ports.push({ x: 0, y: 1, output: true })
+ // this.ports.push({ x: -1, y: 0, input: true })
+
+ // if (pico) {
+ // this.w = this.west()
+ // this.len = this.w ? pico.valueOf(this.w.glyph) : 0
+ // for (let x = 1; x <= this.len; x++) {
+ // this.ports.push({ x: x, y: 0, input: true })
+ // }
+ // }
this.haste = function () {
for (let x = 1; x <= this.len; x++) {
diff --git a/desktop/core/lib/x.js b/desktop/core/lib/x.js
index a7ef9d0..ba12531 100644
--- a/desktop/core/lib/x.js
+++ b/desktop/core/lib/x.js
@@ -7,9 +7,9 @@ function FnX (pico, x, y, passive) {
this.name = 'split'
this.info = 'Bangs eastward when westward fn is 0, and southward when fn is 1.'
- this.ports.push({ x: -1, y: 0 })
- this.ports.push({ x: 0, y: 1, output: true })
- this.ports.push({ x: 1, y: 0, output: true })
+ // this.ports.push({ x: -1, y: 0 })
+ // this.ports.push({ x: 0, y: 1, output: true })
+ // this.ports.push({ x: 1, y: 0, output: true })
this.operation = function () {
if (this.west('0')) {
diff --git a/desktop/core/lib/y.js b/desktop/core/lib/y.js
index 074457a..402e31f 100644
--- a/desktop/core/lib/y.js
+++ b/desktop/core/lib/y.js
@@ -7,30 +7,24 @@ function FnY (pico, x, y, passive) {
this.name = 'type'
this.info = 'Compares the type(num/alpha/special) of westward and eastward fns, and return 1 or 0 southward.'
- this.ports.push({ x: -1, y: 0, input: true })
- this.ports.push({ x: 1, y: 0, input: true })
- this.ports.push({ x: 0, y: 1, output: true })
-
- this.haste = function () {
- pico.lock(this.x, this.y + 1)
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x - 1, this.y)
- }
+
+ this.ports.inputs.a = { x: 1, y: 0 }
+ this.ports.inputs.b = { x: 2, y: 0 }
this.operation = function () {
- const w = this.west()
- const e = this.east()
-
- if (!w && !this.east()) {
- pico.add(this.x, this.y + 1, '1')
- } else if ((w && !e) || (e && !w)) {
- pico.add(this.x, this.y + 1, '0')
- } else if ((w && !e) || (e && !w)) {
- pico.add(this.x, this.y + 1, '0')
- } else if (isNum(w.glyph) === isNum(e.glyph)) {
- pico.add(this.x, this.y + 1, '1')
+ const a = this.listen(this.ports.inputs.a)
+ const b = this.listen(this.ports.inputs.b)
+
+ if (!a && !this.east()) {
+ this.output('1')
+ } else if ((a && !b) || (b && !a)) {
+ this.output('0')
+ } else if ((a && !b) || (b && !a)) {
+ this.output('0')
+ } else if (isNum(a) === isNum(b)) {
+ this.output('1')
} else {
- pico.add(this.x, this.y + 1, '0')
+ this.output('0')
}
}
diff --git a/desktop/core/pico.js b/desktop/core/pico.js
index 55e6efa..5e0c91b 100644
--- a/desktop/core/pico.js
+++ b/desktop/core/pico.js
@@ -131,8 +131,8 @@ function Pico (w, h) {
return this.lib.alpha[g.toLowerCase()] || this.lib.num[g] || this.lib.special[g]
}
- this.valueOf = function (g) {
- return this.isAllowed(`${g}`) ? pico.allowed.indexOf(`${g}`.toLowerCase()) : 0
+ this.toValue = function (g) {
+ return g !== '.' && this.isAllowed(`${g}`) ? pico.allowed.indexOf(`${g}`.toLowerCase()) : 0
}
this.glyphAt = function (x, y, req = null) {
diff --git a/desktop/sources/scripts/source.js b/desktop/sources/scripts/source.js
index f01f42a..f23272f 100644
--- a/desktop/sources/scripts/source.js
+++ b/desktop/sources/scripts/source.js
@@ -66,7 +66,7 @@ function Source (pico, terminal) {
}
this.toString = function () {
- return this.path ? this.name() : 'unsaved'
+ return this.path ? this.name() : 'blank'
}
}
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index 8c624ec..b486802 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -114,7 +114,7 @@ function Terminal (pico) {
if (pico.isLocked(g.x, g.y)) { continue }
for (const id in g.ports) {
const port = g.ports[id]
- h[`${g.x + port.x}:${g.y + port.y}`] = port.output ? 2 : port.bang ? 1 : 3
+ // h[`${g.x + port.x}:${g.y + port.y}`] = port.output ? 2 : port.bang ? 1 : 3
}
}
@@ -153,15 +153,15 @@ function Terminal (pico) {
// Cursor
this.write(`${this.cursor.x},${this.cursor.y}`, col * 0, 1)
this.write(`${this.cursor.w}:${this.cursor.h}`, col * 1, 1)
- this.write(`${pico.w}x${pico.h}`, col * 2, 1)
- this.write(this.debug, col * 3, 1)
+ this.write(`${this.cursor._mode()}`, col * 2, 1)
+ this.write(`${this.cursor.inspect()}`.substr(0, col - 1), col * 3, 1)
// Grid
- this.write(`${this.cursor.inspect()}`.substr(0, col), col * 0, 0)
- this.write(`${this.cursor._mode()}`, col * 1, 0)
+ this.write(`${pico.w}x${pico.h}`, col * 0, 0)
+ this.write(`${this.source}`.substr(0, 5), col * 1, 0)
this.write(`${this.bpm}`, col * 2, 0)
this.write(`${this.midi}`, col * 3, 0)
- this.write(`${this.source}`, col * 4, 0)
+ this.write(this.debug, col * 4, 0)
}
this.write = function (text, offsetX, offsetY) {
diff --git a/examples/benchmark.pico b/examples/benchmark.pico
index 5fb34c2..0c62f15 100644
--- a/examples/benchmark.pico
+++ b/examples/benchmark.pico
@@ -1,22 +1,22 @@
.................................................
-....A.......C.......F.......I.......M.......Y....
+...A.......C.......F.......I.......M.......Y.....
.................................................
.................................................
-...2A......2C......2F......2I......2M......2Y....
+...A2......C2......F2......I2......M2......Y2....
.................................................
.................................................
-....A2......C2......F2......I2......M2......Y2...
+...A.2.....C.2.....F.2.....I.2.....M.2.....Y.2...
.................................................
.................................................
-...2A2.....2C2.....2F2.....2I2.....2M2.....2Y2...
+...A22.....C22.....F22.....I22.....M22.....Y22...
.................................................
.................................................
-...2A3.....2C3.....2F3.....2I3.....2M3.....2Y3...
+...A23.....C23.....F23.....I23.....M23.....Y23...
.................................................
.................................................
-...2AK.....2CK.....2FK.....2IK.....9MK.....2YK...
+...A2K.....C2K.....F2K.....I2K.....M9K.....Y2K...
.................................................
.................................................
-...KA2.....KC2.....KFK.....KI2.....KM6.....KYK...
+...AK2.....CK2.....FKK.....IK2.....MK6.....YKK...
.................................................
................................................. \ No newline at end of file