Tidying up; removing unnecessary aliases.
h3rald h3rald@h3rald.com
Sun, 30 Oct 2016 08:58:18 +0100
8 files changed,
30 insertions(+),
70 deletions(-)
M
core/interpreter.nim
→
core/interpreter.nim
@@ -106,7 +106,6 @@ i.parser.close();
proc push*(i: In, val: MinValue) {.gcsafe.} - proc apply*(i: In, op: MinOperator, s: var ref MinScope, name="apply") = case op.kind of minProcOp:@@ -148,10 +147,6 @@ discard i.trace.pop
else: i.stack.add(val) -proc push*(i: In, q: seq[MinValue]) = - for e in q: - i.push e - proc pop*(i: In): MinValue = if i.stack.len > 0: return i.stack.pop@@ -193,7 +188,6 @@ proc unquote*(i: In, name: string, q: var MinValue, scope: var ref MinScope) =
i.withScope(q, scope): for v in q.qVal: i.push v - proc unquote*(i: In, name: string, q: var MinValue) = var scope = newScopeRef(i.scope)
M
core/parser.nim
→
core/parser.nim
@@ -152,11 +152,6 @@ proc newScopeRef*(parent: ref MinScope, name="scope"): ref MinScope =
new(result) result[] = newScope(parent, name) -proc fullname*(scope: ref MinScope): string = - result = scope.name - if not scope.parent.isNil: - result = scope.parent.fullname & ":" & result - proc open*(my: var MinParser, input: Stream, filename: string) = lexbase.open(my, input) my.filename = filename
M
core/scope.nim
→
core/scope.nim
@@ -4,6 +4,11 @@ critbits
import parser +proc fullname*(scope: ref MinScope): string = + result = scope.name + if not scope.parent.isNil: + result = scope.parent.fullname & ":" & result + proc copy*(s: ref MinScope): ref MinScope = var scope = newScope(s.parent, "copy($1)" % s.name) scope.symbols = s.symbols
M
lib/min_lang.nim
→
lib/min_lang.nim
@@ -221,20 +221,6 @@ for sym, val in mdl.scope.symbols.pairs:
i.debug "[import] $1:$2" % [i.scope.fullname, sym] i.scope.symbols[sym] = val - #.symbol("sigil") do (i: In): - # var q1, q2: MinValue - # i.reqTwoQuotations q1, q2 - # if q1.qVal.len == 1 and q1.qVal[0].kind == minSymbol: - # var symbol = q1.qVal[0].symVal - # if symbol.len == 1: - # if i.scope.hasSigil(symbol): - # raiseInvalid("Sigil '$1' already exists" % [symbol]) - # i.scope.sigils[symbol] = MinOperator(kind: minValOp, val: q2) - # else: - # raiseInvalid("A sigil can only have one character") - # else: - # raiseInvalid("The top quotation must contain only one symbol value") - .symbol("eval") do (i: In): var s: MinValue i.reqString s@@ -500,7 +486,7 @@ if q.qVal.len-1 < index.intVal:
raiseOutOfBounds("Insufficient items in quotation") i.push q.qVal[index.intVal.int] - .symbol("size") do (i: In): + .symbol("length") do (i: In): var q: MinValue i.reqStringOrQuotation q if q.isQuotation:@@ -558,7 +544,7 @@
# 4 ( # ((> 3) ("Greater than 3" put!)) # ((< 3) ("Smaller than 3" put!)) - # ('true ("Exactly 3" put!)) + # ((true) ("Exactly 3" put!)) # ) case .symbol("case") do (i: In): var cases: MinValue@@ -588,7 +574,8 @@
.symbol("while") do (i: In): var d, b: MinValue i.reqTwoQuotations d, b - i.push b.qVal + for e in b.qVal: + i.push e i.unquote("<while-check>", b) var check = i.pop while check.isBool and check.boolVal == true:
M
minim.nim
→
minim.nim
@@ -27,23 +27,7 @@ lib/min_sys,
lib/min_crypto, lib/min_fs -var REPL = false -var DEBUGGING = false const PRELUDE* = "prelude.min".slurp.strip -let usage* = """ $1 v$2 - a tiny concatenative shell and programming language - (c) 2014-2016 Fabio Cevasco - - Usage: - minim [options] [filename] - - Arguments: - filename A $1 file to interpret (default: STDIN). - Options: - -e, --evaluate Evaluate a $1 program inline - -h, --help Print this help - -v, --version Print the program version - -i, --interactive Start $1 shell""" % [appname, version] - proc getExecs(): seq[string] = var res = newSeq[string](0)@@ -194,12 +178,26 @@
proc minimRepl*(debugging = false) = var i = newMinInterpreter(debugging) i.minimRepl - -### +when isMainModule: -when isMainModule: + var REPL = false + var DEBUGGING = false + + let usage* = """ $1 v$2 - a tiny concatenative shell and programming language + (c) 2014-2016 Fabio Cevasco + Usage: + minim [options] [filename] + + Arguments: + filename A $1 file to interpret (default: STDIN). + Options: + -e, --evaluate Evaluate a $1 program inline + -h, --help Print this help + -v, --version Print the program version + -i, --interactive Start $1 shell""" % [appname, version] + var file, s: string = "" for kind, key, val in getopt():
M
minim.vim
→
minim.vim
@@ -12,7 +12,7 @@ setl iskeyword+=?,$,+,*,/,%,=,>,<,&,-,',.,:,~,!
setl iskeyword+=^ setl iskeyword+=@ -syntax keyword minimDefaultSymbol ! != $ & ' * + - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes and append apply ask at atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize case cd chmod choose clear-stack column-print concat confirm cons cp cpu crypto ctime datetime ddel debug debug? decode decrypt define define* delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dump-stack dup dupd echo encode encrypt env? eq eval even? exit fappend file? filename filter first float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite gets get-stack getenv gt gte hardlink hidden? i id ifte import indent inspect int int? interpolate interval io join k keys length linrec load load-symbol logic lowercase ls ls-r lt lte map match md5 mkdir mod module mtime mv newline not noteq now num number? odd? or os password pop popd pred prepend print print! prompt publish puts puts! putenv q quit quotation? quote raise regex remove-symbol repeat replace rest rm rmdir run save-symbol scope scope? seal search select set-stack sha1 sha224 sha256 sha384 sha512 sigils sip size sleep sort source split startup stored-symbols str string string? strip succ swap swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unit unquote uppercase unzip values version which while with xor zap zip contains +syntax keyword minimDefaultSymbol ! != $ & ' * + - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes and append ask at atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize case cd chmod choose clear-stack column-print concat confirm cons cp cpu crypto ctime datetime ddel debug debug? decode decrypt define delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dump-stack dup dupd encode encrypt env? eval even? exit fappend file? filename filter first float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite gets get-stack getenv hardlink hidden? ifte import indent inspect int int? interpolate interval io join k keys length linrec load load-symbol logic lowercase ls ls-r map match md5 mkdir mod module mtime mv newline not now num number? odd? os password pop popd pred print print! prompt publish puts puts! putenv q quotation? quote raise regex remove-symbol repeat replace rest rm rmdir run save-symbol scope scope? seal search set-stack sha1 sha224 sha256 sha384 sha512 sigils sip sleep sort source split startup stored-symbols str string string? strip succ swap swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unquote uppercase unzip values version which while with xor zip contains syntax match minimDefaultSigil ;\<[:@'~!$%&$=<>^*]; contained
M
prelude.min
→
prelude.min
@@ -8,25 +8,6 @@ 'time import
'fs import 'crypto import -; Aliases -'exit :quit -'== :eq -'!= :noteq -'> :gt -'< :lt -'>= :gte -'<= :lte -'puts :echo -'pop :zap -'quote :unit -'unquote :i -'unquote :apply -'filter :select -'cons :prepend -'size :length - -('quit 'eq 'noteq 'gt 'lt 'gte 'lte 'echo 'zap 'unit 'i 'apply 'select 'prepend 'length) 'seal foreach - ; Mathematical Operators (1 +) :succ (1 -) :pred
M
tests/lang.min
→
tests/lang.min
@@ -2,8 +2,8 @@ 'test load
'test import newline -symbols size :total-symbols -sigils size :total-sigils +symbols length :total-symbols +sigils length :total-sigils "Total Symbols: $1" (total-symbols) % puts! "Total Sigils: $1" (total-sigils) % puts! newline@@ -98,7 +98,7 @@
(1 (2 3) cons (1 2 3) ==) assert ((1 2 3 4) 2 at 3 ==) assert - ((1 2 3) size 3 ==) assert + ((1 2 3) length 3 ==) assert ((1 2 3 4) 5 contains false ==) assert ((1 2 3 4) 2 contains) assert