all repos — min @ 6af03b71ff51203b93e8473b5ec781d4dcecada5

A small but practical concatenative programming language.

Implemented persistent symbols.
h3rald h3rald@h3rald.com
Sat, 03 Sep 2016 23:22:40 +0200
commit

6af03b71ff51203b93e8473b5ec781d4dcecada5

parent

4f157a8e003dd068d99a9cf1c95ccea268a2496d

3 files changed, 53 insertions(+), 11 deletions(-)

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

@@ -1,4 +1,4 @@

-import lexbase, critbits +import lexbase, critbits, os type MinTokenKind* = enum

@@ -103,3 +103,13 @@ proc isNotNil*[T](obj: T): bool =

return not obj.isNil const version* = "1.0.0-dev" + +when defined(windows): + const HOME* = getenv("HOMEPATH") +when not defined(windows): + const HOME* = getenv("HOME") + +const MINIMRC* = HOME / ".minimrc" +const MINIMSYMBOLS* = HOME / ".minim_symbols" +const MINIMHISTORY* = HOME / ".minim_history" +
M lib/min_lang.nimlib/min_lang.nim

@@ -447,11 +447,46 @@

.symbol("clear") do (i: In): linenoiseClearScreen() + # Save/load symbols - .symbol("store-symbol") do (i: In): + .symbol("save-symbol") do (i: In): var s:MinValue i.reqStringLike s + let sym = s.getString + let op = i.scope.getSymbol(sym) + if op.kind == minProcOp: + raiseInvalid("Symbol '$1' cannot be serialized." % sym) + let json = MINIMSYMBOLS.readFile.parseJson + json[sym] = %op.val + MINIMSYMBOLS.writeFile(json.pretty) + .symbol("load-symbol") do (i: In): + var s:MinValue + i.reqStringLike s + let sym = s.getString + let json = MINIMSYMBOLS.readFile.parseJson + if not json.hasKey(sym): + raiseUndefined("Symbol '$1' not found." % sym) + let val = json[sym].fromJson + i.scope.symbols[sym] = MinOperator(kind: minValOp, val: val) + + .symbol("stored-symbols") do (i: In): + var s:MinValue + var q = newSeq[MinValue](0) + let json = MINIMSYMBOLS.readFile.parseJson + for k,v in json.pairs: + q.add k.newVal + i.push q.newVal + + .symbol("remove-symbol") do (i: In): + var s:MinValue + i.reqStringLike s + let sym = s.getString + var json = MINIMSYMBOLS.readFile.parseJson + if not json.hasKey(sym): + raiseUndefined("Symbol '$1' not found." % sym) + json.delete(sym) + MINIMSYMBOLS.writeFile(json.pretty) # Sigils

@@ -486,5 +521,11 @@ i.push("call".newSym)

.sigil("/") do (i: In): i.push("dget".newSym) + + .sigil(">") do (i: In): + i.push("save-symbol".newSym) + + .sigil("<") do (i: In): + i.push("load-symbol".newSym) .finalize()
M minim.nimminim.nim

@@ -25,15 +25,6 @@

var REPL = false var DEBUGGING = false const PRELUDE* = "prelude.min".slurp.strip -when defined(windows): - const HOME = getenv("HOMEPATH") -when not defined(windows): - const HOME = getenv("HOME") - -const MINIMRC = HOME / ".minimrc" -const MINIMSYMBOLS = HOME / ".minim_symbols" -const MINIMHISTORY = HOME / ".minim_history" - let usage* = " MiNiM v" & version & " - a tiny concatenative programming language" & """ (c) 2014-2016 Fabio Cevasco