all repos — mn @ fade7297a45e8660f982651553f85f983bca0eba

A truly minimal concatenative programming language.

Improvements and optimization.
h3rald h3rald@h3rald.com
Fri, 26 Mar 2021 21:13:10 +0100
commit

fade7297a45e8660f982651553f85f983bca0eba

parent

2e36b444705603bda077fce3b5af84f7153bbb1a

9 files changed, 19 insertions(+), 100 deletions(-)

jump to
M mn.nimmn.nim

@@ -1,7 +1,7 @@

import streams, strutils, - mnpkg/baseutils, + os, mnpkg/parser, mnpkg/value, mnpkg/scope,

@@ -43,7 +43,7 @@ proc mnFile*(filename: string, op = "interpret", main = true): seq[string] {.discardable.}

proc mnStream(s: Stream, filename: string, op = "interpret", main = true): seq[string] {.discardable.}= var i = newMinInterpreter(filename = filename) - i.pwd = filename.parentDirEx + i.pwd = filename.parentDir i.interpret(s) newSeq[string](0)

@@ -96,7 +96,7 @@ var s = newStringStream("")

i.open(s, "<repl>") var line: string while true: - stdout.write("=| ") + stdout.write(":: ") stdout.flushFile() line = stdin.readLine() let r = i.interpret($line)
M mn.nimsmn.nims

@@ -8,8 +8,6 @@ switch("amd64.linux.gcc.path", "/usr/local/bin")

switch("amd64.linux.gcc.exe", "x86_64-linux-musl-gcc") switch("amd64.linux.gcc.linkerexe", "x86_64-linux-musl-gcc") -switch("opt", "size") - when not defined(dev): switch("define", "release")
D mnpkg/baseutils.nim

@@ -1,11 +0,0 @@

-import - os - -proc reverse*[T](xs: openarray[T]): seq[T] = - result = newSeq[T](xs.len) - for i, x in xs: - result[result.len-i-1] = x - -proc parentDirEx*(s: string): string = - return s.parentDir -
M mnpkg/interpreter.nimmnpkg/interpreter.nim

@@ -6,7 +6,6 @@ osproc,

critbits, algorithm import - baseutils, value, scope, parser

@@ -85,7 +84,7 @@ if not filename.isAbsolute:

path = joinPath(getCurrentDir(), filename) result = newMinInterpreter() result.filename = filename - result.pwd = path.parentDirEx + result.pwd = path.parentDir result.stack = i.stack result.trace = i.trace result.stackcopy = i.stackcopy

@@ -120,33 +119,6 @@ proc close*(i: In) =

i.parser.close(); proc push*(i: In, val: MnValue) {.gcsafe.} - -proc call*(i: In, q: var MnValue): MnValue {.gcsafe.}= - var i2 = newMinInterpreter("<call>") - i2.trace = i.trace - i2.scope = i.scope - try: - i2.withScope(): - for v in q.qVal: - i2.push v - except: - i.currSym = i2.currSym - i.trace = i2.trace - raise - return i2.stack.newVal - -proc callValue*(i: In, v: var MnValue): MnValue {.gcsafe.}= - var i2 = newMinInterpreter("<call-value>") - i2.trace = i.trace - i2.scope = i.scope - try: - i2.withScope(): - i2.push v - except: - i.currSym = i2.currSym - i.trace = i2.trace - raise - return i2.stack[0] proc apply*(i: In, op: MnOperator, sym = "") {.gcsafe.}= if op.kind == mnProcOp:
M mnpkg/parser.nimmnpkg/parser.nim

@@ -87,7 +87,6 @@ mnLangScope

MnScope* = object parent*: ref MnScope symbols*: CritBitTree[MnOperator] - sigils*: CritBitTree[MnOperator] kind*: MnScopeKind MnOperatorProc* = proc (i: In) {.gcsafe.} MnOperatorKind* = enum
M mnpkg/scope.nimmnpkg/scope.nim

@@ -7,7 +7,6 @@

proc copy*(s: ref MnScope): ref MnScope = var scope = newScope(s.parent) scope.symbols = s.symbols - scope.sigils = s.sigils new(result) result[] = scope

@@ -49,45 +48,6 @@ else:

# Go up the scope chain and attempt to find the symbol if not scope.parent.isNil: result = scope.parent.setSymbol(key, value, override) - -proc getSigil*(scope: ref MnScope, key: string): MnOperator = - if scope.sigils.hasKey(key): - return scope.sigils[key] - elif not scope.parent.isNil: - return scope.parent.getSigil(key) - else: - raiseUndefined("Sigil '$1' not found." % key) - -proc hasSigil*(scope: ref MnScope, key: string): bool = - if scope.isNil: - return false - elif scope.sigils.hasKey(key): - return true - elif not scope.parent.isNil: - return scope.parent.hasSigil(key) - else: - return false - -proc delSigil*(scope: ref MnScope, key: string): bool {.discardable.}= - if scope.sigils.hasKey(key): - if scope.sigils[key].sealed: - raiseInvalid("Sigil '$1' is sealed." % key) - scope.sigils.excl(key) - return true - return false - -proc setSigil*(scope: ref MnScope, key: string, value: MnOperator, override = false): bool {.discardable.}= - result = false - # check if a sigil already exists in current scope - if not scope.isNil and scope.sigils.hasKey(key): - if not override and scope.sigils[key].sealed: - raiseInvalid("Sigil '$1' is sealed." % key) - scope.sigils[key] = value - result = true - else: - # Go up the scope chain and attempt to find the sigil - if not scope.parent.isNil: - result = scope.parent.setSymbol(key, value) proc previous*(scope: ref MnScope): ref MnScope = if scope.parent.isNil:
M mnpkg/utils.nimmnpkg/utils.nim

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

import strutils, + algorithm, critbits, math import - baseutils, parser, value, interpreter

@@ -115,21 +115,20 @@ else:

raiseInvalid("Unknown type '$#'" % t) -# The following is used in operator signatures proc expect*(i: var MnInterpreter, elements: varargs[string]): seq[MnValue] {.gcsafe.}= let sym = i.currSym.getString var valid = newSeq[string](0) result = newSeq[MnValue](0) let message = proc(invalid: string, elements: varargs[string]): string = var pelements = newSeq[string](0) - for e in elements.reverse: + for e in elements.reversed: pelements.add e let stack = pelements.join(" ") result = "Incorrect values found on the stack:\n" result &= "- expected: " & stack & " $1\n" % sym var other = "" if valid.len > 0: - other = valid.reverse.join(" ") & " " + other = valid.reversed.join(" ") & " " result &= "- got: " & invalid & " " & other & sym var res = false var vTypes = newSeq[string](0)

@@ -143,8 +142,6 @@ valid.add el

else: raiseInvalid(message(vTypes[c], elements)) c = c+1 - - proc reqQuotationOfQuotations*(i: var MnInterpreter, a: var MnValue) = a = i.pop
M mntool.mnmntool.mn

@@ -1,7 +1,7 @@

#!/usr/bin/env mn ; Validation -(args size 2 <) ("No task specified" puts 1 exit) when +(args size 2 <) ("No task specified" puts pop 1 exit) when args 1 get ":" split "taskspec" let taskspec 0 get "task" let
M tasks/build.mntasks/build.mn

@@ -3,12 +3,16 @@

( (stage) let (target_os) let - "mn_v$#_$#_x64" (cfg_version target_os) interpolate (o) let + (fullname) let + "mn" (o) let + (fullname) + ("mn_v$#_$#_x64" (cfg_version target_os) interpolate (o) bind) + when (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 + "nim c -d:$# --os:$# -o:$# --gc:orc --deepcopy:on --opt:size mn" (stage target_os o) interpolate (cmd) let cmd puts pop cmd run ) (compile) lambda

@@ -16,21 +20,21 @@

#| Tasks |# ( - os "release" compile + false os "release" compile ) (build__default) lambda ( - os "dev" compile + false os "dev" compile ) (build__dev) lambda ( - "windows" "release" compile + true "windows" "release" compile ) (build__windows) lambda ( - "linux" "release" compile + true "linux" "release" compile ) (build__linux) lambda ( - "macosx" "release" compile + true "macosx" "release" compile ) (build__macosx) lambda