all repos — min @ db441f0e2f777f4b06e59fe189f80cd408b0ff98

A small but practical concatenative programming language.

Moved all remaining sealed symbols to stack module.
h3rald h3rald@h3rald.com
Sat, 25 Mar 2017 10:30:56 +0100
commit

db441f0e2f777f4b06e59fe189f80cd408b0ff98

parent

314c9a11a145621f934d5d73fabab926c57c21f0

3 files changed, 98 insertions(+), 28 deletions(-)

jump to
M lib/min_lang.nimlib/min_lang.nim

@@ -441,13 +441,6 @@ let v = i.pop

q.qVal.add v i.push q - .symbol("cons") do (i: In): - var q: MinValue - i.reqQuotation q - let v = i.pop - q.qVal = @[v] & q.qVal - i.push q - .symbol("at") do (i: In): var index, q: MinValue i.reqIntAndQuotation index, q
M lib/min_stack.nimlib/min_stack.nim

@@ -11,7 +11,10 @@ # Operations on the whole stack

proc stack_module*(i: In)= i.define("stack") - + + .symbol("i") do (i: In): + i.push "unquote".newSym + .symbol("id") do (i: In): discard

@@ -20,9 +23,31 @@ if i.stack.len < 1:

raiseEmptyStack() discard i.pop + # (pop) dip + .symbol("popd") do (i: In): + i.push newVal(@["pop".newSym], i.scope) + i.push "dip".newSym + + # ((pop) dip i) + .symbol("k") do (i: In): + i.push newVal(@["pop".newSym], i.scope) + i.push "dip".newSym + i.push "i".newSym + .symbol("dup") do (i: In): i.push i.peek + # (dup) dip + .symbol("dupd") do (i: In): + i.push newVal(@["dup".newSym], i.scope) + i.push "dip".newSym + + #((dup) dip i) + .symbol("q") do (i: In): + i.push newVal(@["dup".newSym], i.scope) + i.push "dip".newSym + i.push "i".newSym + .symbol("dip") do (i: In): var q: MinValue i.reqQuotation q

@@ -30,6 +55,12 @@ let v = i.pop

i.unquote("<dip>", q) i.push v + # ((dip) cons cons) + .symbol("take") do (i: In): + i.push newVal(@["dip".newSym], i.scope) + i.push "cons".newSym + i.push "cons".newSym + .symbol("swap") do (i: In): if i.stack.len < 2: raiseEmptyStack()

@@ -37,6 +68,70 @@ let a = i.pop

let b = i.pop i.push a i.push b + + # (swap) dip + .symbol("swapd") do (i: In): + i.push newVal(@["swap".newSym], i.scope) + i.push "dip".newSym + + # ((cons) dip i) + .symbol("c") do (i: In): + i.push newVal(@["swap".newSym], i.scope) + i.push "dip".newSym + i.push "i".newSym + + .symbol("cons") do (i: In): + var q: MinValue + i.reqQuotation q + let v = i.pop + q.qVal = @[v] & q.qVal + i.push q + + # (() cons dip) + .symbol("dig1") do (i: In): + i.push newVal(@[], i.scope) + i.push "cons".newSym + i.push "dip".newSym + + # (() cons cons dip) + .symbol("dig2") do (i: In): + i.push newVal(@[], i.scope) + i.push "cons".newSym + i.push "cons".newSym + i.push "dip".newSym + + # (() cons cons cons dip) + .symbol("dig3") do (i: In): + i.push newVal(@[], i.scope) + i.push "cons".newSym + i.push "cons".newSym + i.push "cons".newSym + i.push "dip".newSym + + # ((() cons) dip swap i) + .symbol("bury1") do (i: In): + i.push newVal(@[newVal(@[], i.scope), "cons".newSym], i.scope) + i.push "dip".newSym + i.push "swap".newSym + i.push "i".newSym + + # ((() cons cons) dip swap i) + .symbol("bury2") do (i: In): + i.push newVal(@[newVal(@[], i.scope), "cons".newSym, "cons".newSym], i.scope) + i.push "dip".newSym + i.push "swap".newSym + i.push "i".newSym + + # ((() cons cons cons) dip swap i) + .symbol("bury3") do (i: In): + i.push newVal(@[newVal(@[], i.scope), "cons".newSym, "cons".newSym, "cons".newSym], i.scope) + i.push "dip".newSym + i.push "swap".newSym + i.push "i".newSym + + .symbol("swons") do (i: In): + i.push "swap".newSym + i.push "cons".newSym .symbol("sip") do (i: In): var a, b: MinValue
M prelude.minprelude.min

@@ -9,30 +9,12 @@ 'time import

'fs import 'crypto import -; Stack Operators -(swap cons) :swons -((pop) dip) :popd -((dup) dip) :dupd -((swap) dip) :swapd -((dup) dip i) :q -((pop) dip i) :k -((cons) dip i) :b -((swap) dip i) :c -((dip) cons cons) :take -(() cons dip) :dig1 -(() cons cons dip) :dig2 -(() cons cons cons dip) :dig3 -((() cons) dip swap i) :bury1 -((() cons cons) dip swap i) :bury2 -((() cons cons cons) dip swap i) :bury3 - -('swons 'popd 'dupd 'swapd 'q 'k 'b 'c 'take 'dig1 'dig2 'dig3 'bury1 'bury2 'bury3) 'seal foreach - ; Unsealed symbols () :startup ("[$1]$$ " (.) %) :prompt ; Load all stored symbols +stored-symbols ('load-symbol ROOT with) foreach -stored-symbols ('load-symbol ROOT with) foreach +; Execute startup symbol within ROOT scope 'startup ROOT with