all repos — mn @ 2e36b444705603bda077fce3b5af84f7153bbb1a

A truly minimal concatenative programming language.

Added tasks; changed semantics for commands.
h3rald h3rald@h3rald.com
Wed, 24 Mar 2021 19:51:10 +0100
commit

2e36b444705603bda077fce3b5af84f7153bbb1a

parent

70ce1af3f6d8c1ff7b0e96b23dd999cf9290abce

M .gitignore.gitignore

@@ -2,3 +2,4 @@ nimcache/

nimblecache/ htmldocs/ mn.exe +mn_v*
M mnpkg/interpreter.nimmnpkg/interpreter.nim

@@ -2,6 +2,7 @@ import

streams, strutils, os, + osproc, critbits, algorithm import

@@ -225,7 +226,8 @@ discard i.trace.pop

elif val.kind == mnCommand: if DEBUG: echo "-- push command: $#" % val.cmdVal - i.push execShellCmd(val.cmdVal).newVal + let res = execCmdEx(val.cmdVal) + i.push res.output.newVal else: if DEBUG: echo "-- push literal: $#" % $val

@@ -252,8 +254,8 @@ raise

except: let msg = getCurrentExceptionMsg() i.stack = i.stackcopy - #i.stackTrace() - #i.trace = @[] + i.stackTrace() + i.trace = @[] raise MnTrappedException(msg: msg) proc interpret*(i: In, parseOnly=false): MnValue {.discardable.} =
M mnpkg/lang.nimmnpkg/lang.nim

@@ -142,46 +142,16 @@ def.symbol("type") do (i: In):

let vals = i.expect("a") i.push vals[0].typeName.newVal - def.symbol("throw") do (i: In): + def.symbol("quotesym") do (i: In): let vals = i.expect("str") - let err = vals[0] - raiseRuntime(err.getString) + let s = vals[0] + i.push(@[i.newSym(s.strVal)].newVal) - def.symbol("try") do (i: In): - let vals = i.expect("quot") - let prog = vals[0] - if prog.qVal.len == 0: - raiseInvalid("Quotation must contain at least one element") - var code = prog.qVal[0] - var final, catch: MnValue - var hasFinally = false - var hasCatch = false - if prog.qVal.len > 1: - catch = prog.qVal[1] - hasCatch = true - if prog.qVal.len > 2: - final = prog.qVal[2] - hasFinally = true - if (not code.isQuotation) or (hasCatch and not catch.isQuotation) or (hasFinally and not final.isQuotation): - raiseInvalid("Quotation must contain at least one quotation") - try: - i.dequote(code) - except MnRuntimeError: - if not hasCatch: - return - let e = (MnRuntimeError)getCurrentException() - i.push e.data - i.dequote(catch) - except: - if not hasCatch: - return - let e = getCurrentException() - i.push e.msg.newVal - i.dequote(catch) - finally: - if hasFinally: - i.dequote(final) - + def.symbol("quotecmd") do (i: In): + let vals = i.expect("str") + let s = vals[0] + i.push(@[newCmd(s.strVal)].newVal) + def.symbol("quote") do (i: In): let vals = i.expect("a") let a = vals[0]

@@ -191,8 +161,6 @@ def.symbol("dequote") do (i: In):

let vals = i.expect("quot") var q = vals[0] i.dequote(q) - - # Conditionals def.symbol("when") do (i: In): let vals = i.expect("quot", "quot")

@@ -218,15 +186,14 @@ i.dequote(d)

i.dequote(b) check = i.pop - def.symbol("quotesym") do (i: In): - let vals = i.expect("str") - let s = vals[0] - i.push(@[i.newSym(s.strVal)].newVal) + def.symbol("os") do (i: In): + i.push hostOS.newVal - def.symbol("quotecmd") do (i: In): - let vals = i.expect("str") - let s = vals[0] - i.push(@[newCmd(s.strVal)].newVal) + def.symbol("run") do (i: In): + let vals = i.expect("'sym") + let cmd = vals[0] + let res = execShellCmd(cmd.getString) + i.push(res.newVal) def.symbol("getenv") do (i: In): let vals = i.expect("'sym")

@@ -406,17 +373,13 @@ if check.isBool and check.boolVal == true:

res.add e i.push res.newVal - def.symbol("reduce") do (i: In): - let vals = i.expect("quot", "a", "quot") - var q = vals[0] - var acc = vals[1] - let s = vals[2] - for el in s.qVal: - i.push acc - i.push el - i.dequote q - acc = i.pop - i.push acc + def.symbol("foreach") do (i: In): + let vals = i.expect("quot", "quot") + var prog = vals[0] + var list = vals[1] + for litem in list.qVal: + i.push litem + i.dequote(prog) def.symbol("slice") do (i: In): let vals = i.expect("int", "int", "quot")
A tasks/build.mn

@@ -0,0 +1,36 @@

+"tasks/pre.mn" read eval + +( + (stage) let + (target_os) let + "mn_v$#_$#_x64" (cfg_version target_os) interpolate (o) let + (target_os "windows" ==) + ("$#.exe" (o) interpolate (o) bind) + when + "Building mn - $# (x64) - $#" (target_os stage) interpolate puts pop + "nim c -d:$# --os:$# -o:$# mn" (stage target_os o) interpolate (cmd) let + cmd puts pop + cmd run +) (compile) lambda + +#| Tasks |# + +( + os "release" compile +) (build__default) lambda + +( + os "dev" compile +) (build__dev) lambda + +( + "windows" "release" compile +) (build__windows) lambda + +( + "linux" "release" compile +) (build__linux) lambda + +( + "macosx" "release" compile +) (build__macosx) lambda
A tasks/clean.mn

@@ -0,0 +1,8 @@

+( + [ls] "\n" split ("mn_v" indexof -1 >) filter (files) let + files ( + (file) let + "Removing: $#" (file) interpolate puts pop + "rm $#" (file) interpolate run + ) foreach +) (clean__default) lambda
A tasks/pre.mn

@@ -0,0 +1,16 @@

+null "cfg_author" let +null "cfg_version" let +null "cfg_name" let +null "cfg_description" let + +"mn.yml" read "\n" split +( + ; Process each line + ":" split (parts) let + (parts size 1 >) + ( + parts 0 get strip (name) let + parts 1 get strip (value) let + value "cfg_$#" (name) interpolate bind + ) when +) foreach
A tasks/release.mn

@@ -0,0 +1,9 @@

+"tasks/clean.mn" read eval +"tasks/build.mn" read eval + +( + clean__default + build__linux + build__windows + build__macosx +) (release__default) lambda