all repos — min @ 4c0fcf7d4e3ff921a8ea04a1e25aba8191862f28

A small but practical concatenative programming language.

Fixed compilation errors and warning for Nim 0.15.0.
h3rald h3rald@h3rald.com
Sat, 01 Oct 2016 12:33:16 +0200
commit

4c0fcf7d4e3ff921a8ea04a1e25aba8191862f28

parent

8a2bdd17ba07c08d169f0e79191d6bca6c0adefd

M core/interpreter.nimcore/interpreter.nim

@@ -91,7 +91,7 @@ q.scope = new MinScope

q.scope.name = id q.scope.parent = i.scope -template createScope*(i: In, id: string, q: MinValue, body: stmt): stmt {.immediate.} = +template createScope*(i: In, id: string, q: MinValue, body: untyped): untyped = q.scope = new MinScope q.scope.name = id q.scope.parent = i.scope

@@ -102,7 +102,7 @@ body

#i.debug "[scope] " & scope.fullname i.scope = scope -template withScope*(i: In, q: MinValue, body: stmt): stmt {.immediate.} = +template withScope*(i: In, q: MinValue, body: untyped): untyped = #i.debug "[scope] " & q.scope.fullname let origScope = i.scope i.scope = q.scope

@@ -148,7 +148,7 @@ stderr.writeLine("`$1`: Error - $2" % [i.currSym.symVal, message])

else: stderr.writeLine("$1 [$2,$3] `$4`: Error - $5" % [i.filename, $i.currSym.line, $i.currSym.column, i.currSym.symVal, message]) -template execute(i: In, body: stmt) {.immediate.}= +template execute(i: In, body: untyped) = let stack = i.copystack try: body
M core/linedit.nimcore/linedit.nim

@@ -8,8 +8,8 @@ os

# getch/putch implementations when defined(windows): - proc getchar(): cint {.header: "<conio.h>", importc: "_getch".} - proc putchar(c: cint): cint {.discardable, header: "<conio.h>", importc: "_putch".} + proc getchar*(): cint {.header: "<conio.h>", importc: "_getch".} + proc putchar*(c: cint): cint {.discardable, header: "<conio.h>", importc: "_putch".} proc termSetup*() = discard

@@ -33,10 +33,10 @@ let TERMSETTINGS* = termSave()

proc termRestore*() = discard execCmd "stty </dev/tty " & TERMSETTINGS - proc getchar(): cint = + proc getchar*(): cint = return stdin.readChar().ord.cint - proc putchar(c: cint) = + proc putchar*(c: cint) = stdout.write(c.chr) # Types

@@ -46,6 +46,7 @@ Key* = int

KeySeq* = seq[Key] KeyCallback* = proc(ed: var LineEditor) LineError* = ref Exception + LineEditorError* = ref Exception LineEditorMode = enum mdInsert mdReplace

@@ -59,6 +60,7 @@ position: int

queue: Queue[string] max: int LineEditor* = object + completionCallback*: proc(ed: LineEditor): seq[string] history: LineHistory line: Line mode: LineEditorMode

@@ -204,9 +206,6 @@ putchar(32)

stdout.cursorBackward(diff) proc addToLineAtPosition(ed: var LineEditor, s: string) = - let fromStart = ed.line.fromStart - let toEnd = ed.line.toEnd - let diff = toEnd.len - s.len for c in s: ed.printChar(c.ord)

@@ -236,7 +235,6 @@ result.max = size

if historyFile.isNil: return if result.file.fileExists: - var line: string let lines = result.file.readFile.split("\n") for line in lines: if line != "":

@@ -278,11 +276,10 @@ if ed.history.queue.len > 0:

ed.history.position = ed.history.queue.len ed.history.tainted = false -var completionCallback* = proc (ed: LineEditor): seq[string] {.closure.}= - return @[] - proc completeLine*(ed: var LineEditor): int = - let compl = completionCallback(ed) + if ed.completionCallback.isNil: + raise LineEditorError(msg: "Completion callback is not set") + let compl = ed.completionCallback(ed) let position = ed.line.position let words = ed.line.fromStart.split(" ") var word: string
M core/parser.nimcore/parser.nim

@@ -119,7 +119,7 @@ raise MinEmptyStackError(msg: "Insufficient items on the stack")

const - errorMessages: array [MinParserError, string] = [ + errorMessages: array[MinParserError, string] = [ "no error", "invalid token", "string expected",

@@ -129,7 +129,7 @@ "'*/' expected",

"EOF expected", "expression expected" ] - tokToStr: array [MinTokenKind, string] = [ + tokToStr: array[MinTokenKind, string] = [ "invalid token", "EOF", "string literal",
M lib/min_crypto.nimlib/min_crypto.nim

@@ -29,22 +29,22 @@

.symbol("sha224") do (i: In): var s: MinValue i.reqStringLike s - i.push computeSHA224(s.getString).hex.toLower.newVal + i.push computeSHA224(s.getString).hex.toLowerAscii.newVal .symbol("sha256") do (i: In): var s: MinValue i.reqStringLike s - i.push computeSHA256(s.getString).hex.toLower.newVal + i.push computeSHA256(s.getString).hex.toLowerAscii.newVal .symbol("sha384") do (i: In): var s: MinValue i.reqStringLike s - i.push computeSHA384(s.getString).hex.toLower.newVal + i.push computeSHA384(s.getString).hex.toLowerAscii.newVal .symbol("sha512") do (i: In): var s: MinValue i.reqStringLike s - i.push computeSHA512(s.getString).hex.toLower.newVal + i.push computeSHA512(s.getString).hex.toLowerAscii.newVal .symbol("encode") do (i: In): var s: MinValue
M lib/min_lang.nimlib/min_lang.nim

@@ -155,7 +155,7 @@

# Language constructs .symbol("define") do (i: In): - var sym, val: MinValue + var sym: MinValue i.reqStringLike sym var q1 = i.pop # existing (auto-quoted) var symbol: string

@@ -171,7 +171,7 @@ raiseUndefined("Attempting to redefined sealed symbol '$1'" % symbol)

i.scope.symbols[symbol] = MinOperator(kind: minValOp, val: q1, sealed: false) .symbol("bind") do (i: In): - var sym, val: MinValue + var sym: MinValue i.reqStringLike sym var q1 = i.pop # existing (auto-quoted) var symbol: string

@@ -627,7 +627,6 @@ 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:
M lib/min_str.nimlib/min_str.nim

@@ -64,22 +64,22 @@

.symbol("lowercase") do (i: In): var s: MinValue i.reqStringLike s - i.push s.getString.toLower.newVal + i.push s.getString.toLowerAscii.newVal .symbol("uppercase") do (i: In): var s: MinValue i.reqStringLike s - i.push s.getString.toUpper.newVal + i.push s.getString.toUpperAscii.newVal .symbol("capitalize") do (i: In): var s: MinValue i.reqStringLike s - i.push s.getString.capitalize.newVal + i.push s.getString.capitalizeAscii.newVal .symbol("titleize") do (i: In): var s: MinValue i.reqStringLike s - i.push s.getString.split(" ").mapIt(it.capitalize).join(" ").newVal + i.push s.getString.split(" ").mapIt(it.capitalizeAscii).join(" ").newVal .symbol("repeat") do (i: In): var s, n: MinValue
M lib/min_time.nimlib/min_time.nim

@@ -27,7 +27,7 @@ if t.kind == minInt:

time = t.intVal.fromSeconds else: time = t.floatVal.fromSeconds - let tinfo = time.timeToTimeInfo + let tinfo = time.getLocalTime var info = newSeq[MinValue](0).newVal info.qVal.add @["year".newSym, tinfo.year.newVal].newVal info.qVal.add @["month".newSym, (tinfo.month.int+1).newVal].newVal

@@ -47,7 +47,7 @@ if t.kind == minInt:

time = t.intVal.fromSeconds else: time = t.floatVal.fromSeconds - i.push time.timeToTimeInfo.format("yyyy-MM-dd'T'HH:mm:ss'Z'").newVal + i.push time.getLocalTime.format("yyyy-MM-dd'T'HH:mm:ss'Z'").newVal .symbol("tformat") do (i: In): var t, s: MinValue

@@ -58,7 +58,7 @@ if t.kind == minInt:

time = t.intVal.fromSeconds else: time = t.floatVal.fromSeconds - i.push time.timeToTimeInfo.format(s.getString).newVal + i.push time.getLocalTime.format(s.getString).newVal .finalize()
M minim.nimminim.nim

@@ -164,7 +164,7 @@ else:

discard execShellCmd("clear") while true: let symbols = toSeq(i.scope.symbols.keys) - completionCallback = proc(ed: LineEditor): seq[string] {.locks: 0.}= + ed.completionCallback = proc(ed: LineEditor): seq[string] = return ed.getCompletions(symbols) line = ed.readLine(": ") i.parser.buf = $i.parser.buf & $line
M minim.nimbleminim.nimble

@@ -7,4 +7,4 @@ license = "MIT"

bin = "minim" [Deps] -requires: "nimrod >= 0.14.2" +requires: "nimrod >= 0.15.0"
M tests/time.mintests/time.min

@@ -7,7 +7,7 @@ (timestamp 1464951736 >) assert

(now 1464951736 >) assert - (1464951736 datetime "2016-06-03T12:02:16Z" ==) assert + (1464951736 datetime "2016-06-03T11:02:16Z" ==) assert (1464951736 "yy-MM-dd" tformat "16-06-03" ==) assert
M vendor/sgregex.nimvendor/sgregex.nim

@@ -29,7 +29,7 @@ proc srx_Destroy*(R: ptr srx_Context): cint

proc srx_DumpToStdout*(R: ptr srx_Context) proc srx_MatchExt*(R: ptr srx_Context; str: cstring; size: csize; offset: csize): cint -template srx_Match*(R, str, off: expr): expr = +template srx_Match*(R: ptr srx_Context, str: cstring, off: csize): cint = srx_MatchExt(R, str, RX_STRLENGTHFUNC(str), off) proc srx_GetCaptureCount*(R: ptr srx_Context): cint

@@ -39,7 +39,7 @@ proc srx_GetCapturedPtrs*(R: ptr srx_Context; which: cint;

pbeg: cstringArray; pend: cstringArray): cint proc srx_ReplaceExt*(R: ptr srx_Context; str: cstring; strsize: csize; rep: cstring; repsize: csize; outsize: ptr csize): cstring -template srx_Replace*(R, str, rep: expr): expr = +template srx_Replace*(R: ptr srx_Context, str: cstring, rep: cstring): cstring = srx_ReplaceExt(R, str, RX_STRLENGTHFUNC(str), rep, RX_STRLENGTHFUNC(rep), nil) proc srx_FreeReplaced*(R: ptr srx_Context; repstr: cstring)
M vendor/sha1.nimvendor/sha1.nim

@@ -27,7 +27,7 @@ #Ported to Nimrod by Erik O'Leary

# ## Imports -import unsigned, strutils, base64 +import strutils, base64 ## Fields const sha_digest_size = 20

@@ -72,10 +72,10 @@ e = state[4]

var round = 0 - template rot(value, bits: uint32): uint32 {.immediate.} = + template rot(value, bits: uint32): uint32 = (value shl bits) or (value shr (32 - bits)) - template sha1(fun, val: uint32): stmt = + template sha1(fun, val: uint32): untyped = let t = rot(a, 5) + fun + e + val + w[round] e = d d = c

@@ -83,12 +83,12 @@ c = rot(b, 30)

b = a a = t - template process(body: stmt): stmt = + template process(body: untyped): untyped = w[round] = rot(w[round - 3] xor w[round - 8] xor w[round - 14] xor w[round - 16], 1) body inc(round) - template wrap(dest, value: expr): stmt {.immediate.} = + template wrap(dest, value: typed): untyped = let v = dest + value dest = v

@@ -118,7 +118,7 @@ wrap state[2], c

wrap state[3], d wrap state[4], e -template computeInternal(src: expr): stmt {.immediate.} = +template computeInternal(src: typed): untyped = #Initialize state var state: SHA1State init(state)

@@ -178,7 +178,7 @@ proc compute*(src: string) : SHA1Digest =

## Calculate SHA1 from input string computeInternal(src) -proc compute*(src: openarray[TInteger|char]) : SHA1Digest = +proc compute*(src: openarray[SomeInteger|char]) : SHA1Digest = ## Calculate SHA1 from input array computeInternal(src)