From 9659540b18b9bd76ea027c83a10077103fcc6318 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 18 Aug 2015 14:01:40 +0200 Subject: [PATCH] preparations for Nimble NimScript integrations; minor cleanups --- compiler/modules.nim | 1 - compiler/nim.cfg | 1 - compiler/scriptconfig.nim | 3 ++- compiler/vm.nim | 4 ++++ config/nim.cfg | 1 - lib/system/nimscript.nim | 27 ++++++++++++++++++++++++ todo.txt | 43 +++++++++++++++++++++++++++++++++++++-- 7 files changed, 74 insertions(+), 6 deletions(-) diff --git a/compiler/modules.nim b/compiler/modules.nim index ad68e63154..85c99c4ecd 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -92,7 +92,6 @@ proc resetAllModulesHard* = magicsys.resetSysTypes() # XXX #gOwners = @[] - #rangeDestructorProc = nil proc checkDepMem(fileIdx: int32): TNeedRecompile = template markDirty = diff --git a/compiler/nim.cfg b/compiler/nim.cfg index 64631a4374..4f9962ea83 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -17,5 +17,4 @@ define:useStdoutAsStdmsg cs:partial #define:useNodeIds -symbol:nimfix #gc:markAndSweep diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim index 1e4fc25afd..148a382c25 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/scriptconfig.nim @@ -25,7 +25,8 @@ proc listDirs(a: VmArgs, filter: set[PathComponent]) = if kind in filter: result.add path setResult(a, result) -proc setupVM(module: PSym; scriptName: string): PEvalContext = +proc setupVM*(module: PSym; scriptName: string): PEvalContext = + # For Nimble we need to export 'setupVM'. result = newCtx(module) result.mode = emRepl registerAdditionalOps(result) diff --git a/compiler/vm.nim b/compiler/vm.nim index 57ed8397ca..b15c555651 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1401,6 +1401,10 @@ proc evalExpr*(c: PCtx, n: PNode): PNode = assert c.code[start].opcode != opcEof result = execute(c, start) +proc getGlobalValue*(c: PCtx; s: PSym): PNode = + internalAssert s.kind in {skLet, skVar} and sfGlobal in s.flags + result = c.globals.sons[s.position-1] + include vmops # for now we share the 'globals' environment. XXX Coming soon: An API for diff --git a/config/nim.cfg b/config/nim.cfg index 09864e0e5c..a854a30ef9 100644 --- a/config/nim.cfg +++ b/config/nim.cfg @@ -50,7 +50,6 @@ path="$lib/js" path="$lib/pure/unidecode" @if nimbabel: - babelpath="$home/.babel/pkgs/" nimblepath="$home/.nimble/pkgs/" @end diff --git a/lib/system/nimscript.nim b/lib/system/nimscript.nim index 6f5977869d..013b2cbc0e 100644 --- a/lib/system/nimscript.nim +++ b/lib/system/nimscript.nim @@ -150,3 +150,30 @@ template task*(name: untyped; description: string; body: untyped): untyped = elif cmd ==? astToStr(name): setCommand "nop" `name Task`() + +type + VersionReq* = distinct string ## Describes a version requirement. + +template v*(name: string{lit}): VersionReq = VersionReq(name) +template special*(name: string): VersionReq = VersionReq(name) +template `<`*(v: VersionReq): VersionReq = VersionReq("<" & string(v)) +template `<=`*(v: VersionReq): VersionReq = VersionReq("<=" & string(v)) +template `>`*(v: VersionReq): VersionReq = VersionReq(">" & string(v)) +template `>=`*(v: VersionReq): VersionReq = VersionReq(">=" & string(v)) +template `&`*(a, b: VersionReq): VersionReq = + VersionReq(string(a) & " & " & string(b)) + +const + anyVersion* = VersionReq("*") + +var + packageName* = "" + version*, author*, description*, license*, srcdir*, + binDir*, backend*: string + + skipDirs*, skipFiles*, skipExt*, installDirs*, installFiles*, + installExt*, bin*: seq[string] + requiresData*: seq[(string, VersionReq)] + +proc requires*(name: string; v: VersionReq) = + requiresData.add((name, v)) diff --git a/todo.txt b/todo.txt index 0d4dbd2ad3..ee30894dae 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,9 @@ version 0.11.4 ============== +- make tuple unpacking work in a non-var/let context +- built-in 'getImpl' + - document special cased varargs[untyped] and varargs[typed] - The remaining bugs of the lambda lifting pass that is responsible to enable @@ -50,14 +53,50 @@ Low priority: Misc ---- -- make tuple unpacking work in a non-var/let context -- built-in 'getImpl' - prevent 'alloc(TypeWithGCedMemory)' Bugs ==== +- Can lead to wrong C code: + +template cd*(dir: string, body: stmt) = + ## Sets the current dir to ``dir``, executes ``body`` and restores the + ## previous working dir. + let lastDir = getCurrentDir() + setCurrentDir(dir) + try: + body + finally: + setCurrentDir(lastDir) + +proc test = + cd dir: + var output = execProcess("git tag") + case meth + of DownloadMethod.git: + output = execProcess("git tag") + of DownloadMethod.hg: + output = execProcess("hg tags") + if output.len > 0: + case meth + of DownloadMethod.git: + result = @[] + for i in output.splitLines(): + if i == "": continue + result.add(i) + of DownloadMethod.hg: + result = @[] + for i in output.splitLines(): + if i == "": continue + var tag = "" + discard parseUntil(i, tag, ' ') + if tag != "tip": + result.add(tag) + else: + result = @[] + - VM: Pegs do not work at compile-time - VM: ptr/ref T cannot work in general - blocks can "export" an identifier but the CCG generates {} for them ...