all repos — min @ b6881742374d33fef328ed53e01d632b4efc4f0d

A small but practical concatenative programming language.

Fixed cd command & path management.
* Closes #26.
h3rald h3rald@h3rald.com
Sat, 17 Mar 2018 10:53:20 +0100
commit

b6881742374d33fef328ed53e01d632b4efc4f0d

parent

9777b202e49effb7959a7f7e329df6883ed2ddd8

3 files changed, 17 insertions(+), 7 deletions(-)

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

@@ -4,6 +4,7 @@ strutils,

critbits, os, algorithm, + ospaths, logging import value,

@@ -39,6 +40,9 @@ res = i.scope

i.scope = origScope proc newMinInterpreter*(filename = "input", pwd = ""): MinInterpreter {.extern:"min_exported_symbol_$1".}= + var path = pwd + if not pwd.isAbsolute: + path = joinPath(getCurrentDir(), pwd) var stack:MinStack = newSeq[MinValue](0) var trace:MinStack = newSeq[MinValue](0) var stackcopy:MinStack = newSeq[MinValue](0)

@@ -46,7 +50,7 @@ var pr:MinParser

var scope = new MinScope var i:MinInterpreter = MinInterpreter( filename: filename, - pwd: pwd, + pwd: path, parser: pr, stack: stack, trace: trace,

@@ -57,9 +61,12 @@ )

return i proc copy*(i: MinInterpreter, filename: string): MinInterpreter {.extern:"min_exported_symbol_$1_2".}= + var path = filename + if not filename.isAbsolute: + path = joinPath(getCurrentDir(), filename) result = newMinInterpreter() result.filename = filename - result.pwd = filename.parentDir + result.pwd = path.parentDir result.stack = i.stack result.trace = i.trace result.stackcopy = i.stackcopy
M lib/min_lang.nimlib/min_lang.nim

@@ -175,7 +175,7 @@ file = file & ".min"

file = i.pwd.joinPath(file) info("[load] File: ", file) if not file.fileExists: - raiseInvalid("File '$1' does not exists." % file) + raiseInvalid("File '$1' does not exist." % file) i.load file def.symbol("read") do (i: In):

@@ -186,7 +186,7 @@ if not file.endsWith(".min"):

file = file & ".min" info("[read] File: ", file) if not file.fileExists: - raiseInvalid("File '$1' does not exists." % file) + raiseInvalid("File '$1' does not exist." % file) i.push i.read file def.symbol("with") do (i: In):
M lib/min_sys.nimlib/min_sys.nim

@@ -3,7 +3,8 @@ tables,

os, osproc, strutils, - sequtils + sequtils, + logging import ../core/parser, ../core/value,

@@ -28,8 +29,10 @@ i.push newVal(getCurrentDir().parentDir.unix)

def.symbol("cd") do (i: In): let vals = i.expect("'sym") - let f = vals[0] - f.getString.setCurrentDir + let f = vals[0].getString + i.pwd = joinPath(getCurrentDir(), f) + info("Current directory changed to: ", i.pwd) + f.setCurrentDir def.symbol("ls") do (i: In): let vals = i.expect("'sym")