all repos — min @ f48896afcaaba3390d9a8c23fa5a8679a37939a5

A small but practical concatenative programming language.

Added file/directory operations.
h3rald h3rald@h3rald.com
Sun, 30 Nov 2014 16:04:18 +0100
commit

f48896afcaaba3390d9a8c23fa5a8679a37939a5

parent

95b000b3d74d650ce3c0c10258627b74d80dc48c

2 files changed, 70 insertions(+), 1 deletions(-)

jump to
M prelude.minprelude.min

@@ -15,6 +15,9 @@ [$HOME] [$HOMEPATH] :

[$USER] [$USERNAME] : -// Other +// Mathematical + +[1 +] [succ] : +[1 -] [pred] : [[ dup 0 == ] [ 1 + ] [ dup 1 - ] [ * ] linrec] [factorial] :
M primitives.nimprimitives.nim

@@ -159,6 +159,19 @@ i.push newVal(q.strVal[1..q.strVal.len-1])

else: i.error(errIncorrect, "A quotation or a string is required on the stack") +# Operations on strings + + +minsym "split": + let sep = i.pop + let s = i.pop + if s.isString and sep.isString: + for e in s.strVal.split(sep.strVal): + i.push e.newVal + else: + i.error errIncorrect, "Two strings are required on the stack" + + # Arithmetic minsym "+":

@@ -427,6 +440,16 @@

minsym "pwd": i.push newVal(getCurrentDir()) +minsym "cd": + let f = i.pop + if f.isString: + try: + f.strVal.setCurrentDir + except: + warn getCurrentExceptionMsg() + else: + i.error errIncorrect, "A string is required on the stack" + minsym "ls": let a = i.pop var list = newSeq[TMinValue](0)

@@ -472,6 +495,49 @@

minsym "cpu": i.push hostCPU.newVal +minsym "file?": + let f = i.pop + if f.isString: + i.push f.strVal.fileExists.newVal + else: + i.error errIncorrect, "A string is required on the stack" + +minsym "dir?": + let f = i.pop + if f.isString: + i.push f.strVal.dirExists.newVal + else: + i.error errIncorrect, "A string is required on the stack" + +minsym "rm": + let f = i.pop + if f.isString: + try: + f.strVal.removeFile + except: + warn getCurrentExceptionMsg() + else: + i.error errIncorrect, "A string is required on the stack" + +minsym "rmdir": + let f = i.pop + if f.isString: + try: + f.strVal.removeDir + except: + warn getCurrentExceptionMsg() + else: + i.error errIncorrect, "A string is required on the stack" + +minsym "mkdir": + let f = i.pop + if f.isString: + try: + f.strVal.createDir + except: + warn getCurrentExceptionMsg() + else: + i.error errIncorrect, "A string is required on the stack" # Aliases minalias "quit", "exit"