all repos — min @ 267c507c1fc6fcc85b99ec5f8b3ac14a9139d9d3

A small but practical concatenative programming language.

Added dynamic library management via .minlibs folder.
h3rald h3rald@h3rald.com
Sat, 28 Oct 2017 17:26:19 +0200
commit

267c507c1fc6fcc85b99ec5f8b3ac14a9139d9d3

parent

9739ee9bc63521491be4de54a7062ea983ae5ba7

3 files changed, 36 insertions(+), 3 deletions(-)

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

@@ -47,3 +47,4 @@

let MINRC* = HOME / ".minrc" let MINSYMBOLS* = HOME / ".min_symbols" let MINHISTORY* = HOME / ".min_history" +let MINLIBS* = HOME / ".minlibs"
M min.nimmin.nim

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

-{.passL: "-rdynamic".} import streams, critbits,

@@ -140,8 +139,8 @@ type

LibProc = proc(i: In) {.nimcall.} proc dynLib*(i: In) = - info("Trying to load libraries from " & $(getAppDir() / "dynlibs")) - for library in walkFiles(getAppDir() / "dynlibs/*"): + discard MINLIBS.existsOrCreateDir + for library in walkFiles(MINLIBS & "/*"): var modname = library.splitFile.name var libfile = library.splitFile.name & library.splitFile.ext if modname.len > 3 and modname[0..2] == "lib":

@@ -246,6 +245,9 @@

when isMainModule: var REPL = false + var INSTALL = false + var UNINSTALL = false + var libfile = "" let usage* = """ $1 v$2 - a tiny concatenative shell and programming language (c) 2014-2017 Fabio Cevasco

@@ -256,6 +258,8 @@

Arguments: filename A $1 file to interpret (default: STDIN). Options: + --install:<lib> Install dynamic library file <lib> + --uninstall:<lib> Uninstall dynamic library file <lib> -e, --evaluate Evaluate a $1 program inline -h, --help Print this help -v, --version Print the program version

@@ -283,6 +287,12 @@ echo version

quit(0) of "interactive", "i": REPL = true + of "install": + INSTALL = true + libfile = val + of "uninstall": + UNINSTALL = true + libfile = val else: discard else:

@@ -292,6 +302,28 @@ if s != "":

minString(s) elif file != "": minFile file + elif INSTALL: + if not libfile.existsFile: + fatal("Dynamic library file not found:" & libfile) + quit(4) + try: + libfile.copyFile(MINLIBS/libfile.extractFilename) + except: + fatal("Unable to install library file: " & libfile) + quit(5) + notice("Dynamic linbrary installed successfully: " & libfile.extractFilename) + quit(0) + elif UNINSTALL: + if not (MINLIBS/libfile.extractFilename).existsFile: + fatal("Dynamic library file not found:" & libfile) + quit(4) + try: + removeFile(MINLIBS/libfile.extractFilename) + except: + fatal("Unable to uninstall library file: " & libfile) + quit(6) + notice("Dynamic linbrary uninstalled successfully: " & libfile.extractFilename) + quit(0) elif REPL: minRepl() quit(0)