all repos — min @ 1d555258128e0345415220db952e1a3957215af3

A small but practical concatenative programming language.

Added scope symbol; fixes.
h3rald h3rald@h3rald.com
Wed, 17 Jun 2020 10:23:07 +0200
commit

1d555258128e0345415220db952e1a3957215af3

parent

139e79c92c2b0239f742d54ab131de1a56a7ba30

4 files changed, 33 insertions(+), 11 deletions(-)

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

@@ -51,9 +51,7 @@

template withDictScope*(i: In, s: ref MinScope, body: untyped): untyped = let origScope = i.scope try: - var scope = s.copy - scope.parent = origscope - i.scope = scope + i.scope = s body finally: i.scope = origScope
M lib/min_lang.nimlib/min_lang.nim

@@ -142,6 +142,13 @@ code.filename = i.filename

info("[module] $1 ($2 symbols)" % [name.getString, $code.scope.symbols.len]) i.scope.symbols[name.getString] = MinOperator(kind: minValOp, val: code) + def.symbol("scope") do (i: In): + var dict = newDict(i.scope.parent) + dict.objType = "module" + dict.filename = i.filename + dict.scope = i.scope + i.push dict + def.symbol("import") do (i: In): var vals = i.expect("'sym") let rawName = vals[0]

@@ -199,10 +206,13 @@

def.symbol("with") do (i: In): let vals = i.expect("dict", "quot") var qscope = vals[0] - let qprog = vals[1] + var qprog = vals[1] i.withDictScope(qscope.scope): + #i.apply qprog for v in qprog.qVal: i.push v + #var results = i.expect("quot") + #i.apply results[0] def.symbol("publish") do (i: In): let vals = i.expect("dict", "'sym")
M site/contents/_defs_.mdsite/contents/_defs_.md

@@ -10,6 +10,7 @@ {{4 => [<sub>4</sub>](class:kwd)}}

{{e => [dict:error](class:kwd)}} {{tinfo => [dict:timeinfo](class:kwd)}} {{d => [dict](class:kwd)}} +{{m => [module](class:kwd)}} {{d1 => [dict<sub>1</sub>](class:kwd)}} {{d2 => [dict<sub>2</sub>](class:kwd)}} {{flt => [float](class:kwd)}}
M site/contents/reference-lang.mdsite/contents/reference-lang.md

@@ -176,7 +176,7 @@ > > Example

> > > > The following program leaves `120` on the stack, the factorial of 5: > > -> > (dup 0 ==) 'succ (dup pred) '* linrec +> > 5 (dup 0 ==) 'succ (dup pred) '* linrec #} {#op||lite?||{{null}}||{{b}}||

@@ -208,12 +208,6 @@ Returns the current log level (debug, info, notive, warn, error or fatal). #}

{#op||module||{{d}} {{sl}}||{{null}}|| Creates a new module {{sl}} based on dictionary {{d}}. #} - -{#op||scope-sigils||{{d}}||({{s0p}})|| -Returns a list of all sigils defined in dictionary {{d}}.#} - -{#op||scope-symbols||{{d}}||({{s0p}})|| -Returns a list of all symbols defined in dictionary {{d}}.#} {#op||opts||{{null}}||{{d}}|| Returns a dictionary of all options passed to the current program, with their respective values.#}

@@ -266,6 +260,25 @@ #}

{#op||save-symbol||{{sl}}||{{null}}|| Saves the contents of symbol {{sl}} to the [.min\_symbols](class:file) file. #} + +{#op||scope||{{null}}||({{m}})|| +> Returns a module {{m}} corresponding to the current scope. +> +> This can be useful to save a reference to a given execution scope to access later on. +> +> > %sidebar% +> > Example +> > +> > The following program leaves `{(2) :two ;module}` on the stack: +> > +> > {} :myscope (2 :due scope @myscope) -> + #} + +{#op||scope-sigils||{{d}}||({{s0p}})|| +Returns a list of all sigils defined in dictionary {{d}}.#} + +{#op||scope-symbols||{{d}}||({{s0p}})|| +Returns a list of all symbols defined in dictionary {{d}}.#} {#op||seal||{{sl}}||{{null}}|| Seals symbol {{sl}}, so that it cannot be re-assigned. #}