all repos — min @ 029ecde47fd8c3776afaac6e6473ab658231d437

A small but practical concatenative programming language.

Fixing compilation support
h3rald h3rald@h3rald.com
Wed, 30 Dec 2020 22:37:18 +0100
commit

029ecde47fd8c3776afaac6e6473ab658231d437

parent

de8740f5bad48bd8ebd0df3acc63018065f828bf

5 files changed, 28 insertions(+), 50 deletions(-)

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

@@ -1,8 +1,20 @@

+import strutils + proc reverse*[T](xs: openarray[T]): seq[T] = result = newSeq[T](xs.len) for i, x in xs: result[result.len-i-1] = x +proc simplifyPath*(filename: string, file: string): string = + let fn = strutils.replace(filename, "./", "") + var dirs: seq[string] = fn.split("/") + discard dirs.pop + let pwd = dirs.join("/") + if pwd == "": + result = file + else: + result = pwd&"/"&file + when defined(mini): import
M core/interpreter.nimcore/interpreter.nim

@@ -405,7 +405,7 @@ i2.open(newStringStream(contents), s)

discard i2.parser.getToken() discard i2.interpret(parseOnly) if snapshot != i2.stack: - raiseInvalid("Code in required file '$#' is polluting the stack" % s) + raiseInvalid("Module '$#' is polluting the stack" % s) result = newDict(i2.scope) result.objType = "module" for key, value in i2.scope.symbols.pairs:
M core/parser.nimcore/parser.nim

@@ -693,6 +693,7 @@ result = newSeq[string](0)

case p.token of tkNull: result = @[op&"MinValue(kind: minNull)"] + discard getToken(p) of tkTrue: result = @[op&"MinValue(kind: minBool, boolVal: true)"] discard getToken(p)
M lib/min_lang.nimlib/min_lang.nim

@@ -19,6 +19,7 @@ ../packages/nim-sgregex/sgregex

import ../core/env, ../core/meta, + ../core/baseutils, ../core/parser, ../core/value, ../core/interpreter,

@@ -110,35 +111,21 @@ var file = s.getString

if not file.endsWith(".min"): file = file & ".min" info("[require] File: ", file) - if MINCOMPILED: - var normalizedFile = strutils.replace(strutils.replace(file, "\\", "/"), "./", "") - var compiledFile = normalizedFile - var normalizedCurrFile = strutils.replace(strutils.replace(i.filename, "\\", "/"), "./", "") - var parts = normalizedCurrFile.split("/") - if parts.len > 1: - discard parts.pop - compiledFile = parts.join("/") & "/" & normalizedFile - if COMPILEDMINFILES.hasKey(compiledFile): - var i2 = i.copy(file) - COMPILEDMINFILES[compiledFile](i2) - var mdl = newDict(i2.scope) - mdl.objType = "module" - for key, value in i2.scope.symbols.pairs: - mdl.scope.symbols[key] = value - i.push(mdl) - return - let fn = strutils.replace(i.filename, "./", "") - var dirs: seq[string] = fn.split("/") - discard dirs.pop - var pwd = dirs.join("/") - var f: string - if pwd == "": - f = file - else: - f = pwd&"/"&file + let f = simplifyPath(i.filename, file) if not f.fileExists: raiseInvalid("File '$1' does not exist." % file) - i.push i.require(f) + if MINCOMPILED: + if COMPILEDMINFILES.hasKey(f): + var i2 = i.copy(f) + i2.withScope(): + COMPILEDMINFILES[f](i2) + var mdl = newDict(i2.scope) + mdl.objType = "module" + for key, value in i2.scope.symbols.pairs: + mdl.scope.symbols[key] = value + i.push(mdl) + else: + i.push i.require(f) def.symbol("read") do (i: In): let vals = i.expect("'sym")
M min.nimmin.nim

@@ -472,28 +472,6 @@ if MODULEPATH.len > 0:

for f in walkDirRec(MODULEPATH): if f.endsWith(".min"): MINMODULES.add f - if INSTALL: - if not libfile.fileExists: - logging.fatal("Dynamic library file not found:" & libfile) - quit(4) - try: - libfile.copyFile(MINLIBS/libfile.extractFilename) - except: - logging.fatal("Unable to install library file: " & libfile) - quit(5) - logging.notice("Dynamic linbrary installed successfully: " & libfile.extractFilename) - quit(0) - elif UNINSTALL: - if not (MINLIBS/libfile.extractFilename).fileExists: - logging.fatal("Dynamic library file not found:" & libfile) - quit(4) - try: - removeFile(MINLIBS/libfile.extractFilename) - except: - logging.fatal("Unable to uninstall library file: " & libfile) - quit(6) - logging.notice("Dynamic linbrary uninstalled successfully: " & libfile.extractFilename) - quit(0) elif REPL: minRepl() quit(0)