all repos — min @ 35ffae135e2415a49d19c673337ed3f01b915d00

A small but practical concatenative programming language.

Improved REPL; updated sgregex wrapper code.
h3rald h3rald@h3rald.com
Tue, 30 Aug 2016 20:45:53 +0200
commit

35ffae135e2415a49d19c673337ed3f01b915d00

parent

0ce5ec4ab6763c180130f18fd849d99e590b5822

3 files changed, 22 insertions(+), 14 deletions(-)

jump to
M core/types.nimcore/types.nim

@@ -80,7 +80,7 @@ evaluating*: bool

unsafe*: bool In* = var MinInterpreter Val* = var MinValue - MinOperator* = proc (i: In) {.gcsafe, closure.} + MinOperator* = proc (i: In) {.closure.} MinSigil* = proc (i: In, sym: string) MinParsingError* = ref object of ValueError MinUndefinedError* = ref object of ValueError
M minim.nimminim.nim

@@ -124,9 +124,18 @@ except:

warn getCurrentExceptionMsg() finally: if i.stack.len > 0: - echo("[$1] -> $2" % [$i.stack.len, $i.stack[i.stack.len - 1]]) + let last = i.stack[i.stack.len - 1] + let n = $i.stack.len + var output: string + if last.isQuotation and last.qVal.len > 1: + echo "{$1} -> (" % n + for item in last.qVal: + echo " " & $item + echo " ".repeat(n.len) & " )" + else: + echo "{$1} -> $2" % [$i.stack.len, $i.stack[i.stack.len - 1]] else: - echo "[0]" + echo "{0} --" proc minimRepl*(debugging = false) = var i = newMinInterpreter(debugging)
M vendor/sgregex.nimvendor/sgregex.nim

@@ -17,21 +17,20 @@

proc RX_STRLENGTHFUNC*(str: string): int = return str.len -proc srx_DefaultMemFunc*(userdata: pointer, ptr1: pointer, size: csize): pointer = - #cast[ptr string](userdata) - #if not size.isNil: - #return realloc(ptr, size) - #free(ptr1) - return nil - type srx_Context* = object +proc srx_DefaultMemFunc*(userdata: pointer, ptr1: pointer, size: csize): pointer = + discard cast[string](userdata) + if size > 0: + return realloc(ptr1, size) + dealloc(ptr1) + return nil + {.push importc.} -proc srx_CreateExt*(str: cstring; strsize: csize; mods: cstring; - errnpos: ptr cint; memfn: srx_MemFunc; memctx: pointer): ptr srx_Context -template srx_Create*(str, mods: expr): expr = - srx_CreateExt(str, RX_STRLENGTHFUNC(str), mods, nil, nil, nil)#srx_DefaultMemFunc, nil) +proc srx_CreateExt*(str: cstring; strsize: csize; mods: cstring; errnpos: ptr cint; memfn: srx_MemFunc; memctx: pointer): ptr srx_Context +template srx_Create*(str, mods: string): ptr srx_Context = + srx_CreateExt(str, RX_STRLENGTHFUNC(str), mods, nil, srx_DefaultMemFunc, nil) proc srx_Destroy*(R: ptr srx_Context): cint proc srx_DumpToStdout*(R: ptr srx_Context)