diff options
author | Araq <rumpf_a@web.de> | 2015-11-10 15:29:53 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-11-10 15:31:21 +0100 |
commit | 2aff71613464a27558c9e90cf85f038c240babb2 (patch) | |
tree | c248fb8aa2bad7f9f72f337b1155b31e36947ad9 /compiler | |
parent | 81f876040b3f301eff1cc49fcc3812c040086664 (diff) | |
download | Nim-2aff71613464a27558c9e90cf85f038c240babb2.tar.gz |
os.walkDir is available at compile time
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/vmgen.nim | 6 | ||||
-rw-r--r-- | compiler/vmhooks.nim | 7 | ||||
-rw-r--r-- | compiler/vmops.nim | 10 |
3 files changed, 20 insertions, 3 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 97c6a5580..2a16406e7 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1604,7 +1604,8 @@ proc matches(s: PSym; x: string): bool = var s = s var L = y.len-1 while L >= 0: - if s == nil or y[L].cmpIgnoreStyle(s.name.s) != 0: return false + if s == nil or (y[L].cmpIgnoreStyle(s.name.s) != 0 and y[L] != "*"): + return false s = s.owner dec L result = true @@ -1613,7 +1614,8 @@ proc matches(s: PSym; y: varargs[string]): bool = var s = s var L = y.len-1 while L >= 0: - if s == nil or y[L].cmpIgnoreStyle(s.name.s) != 0: return false + if s == nil or (y[L].cmpIgnoreStyle(s.name.s) != 0 and y[L] != "*"): + return false s = if sfFromGeneric in s.flags: s.owner.owner else: s.owner dec L result = true diff --git a/compiler/vmhooks.nim b/compiler/vmhooks.nim index 576b0565f..3456e893b 100644 --- a/compiler/vmhooks.nim +++ b/compiler/vmhooks.nim @@ -55,9 +55,16 @@ template getX(k, field) {.immediate, dirty.} = result = s[i+a.rb+1].field proc getInt*(a: VmArgs; i: Natural): BiggestInt = getX(rkInt, intVal) +proc getBool*(a: VmArgs; i: Natural): bool = getInt(a, i) != 0 proc getFloat*(a: VmArgs; i: Natural): BiggestFloat = getX(rkFloat, floatVal) proc getString*(a: VmArgs; i: Natural): string = doAssert i < a.rc-1 let s = cast[seq[TFullReg]](a.slots) doAssert s[i+a.rb+1].kind == rkNode result = s[i+a.rb+1].node.strVal + +proc getNode*(a: VmArgs; i: Natural): PNode = + doAssert i < a.rc-1 + let s = cast[seq[TFullReg]](a.slots) + doAssert s[i+a.rb+1].kind == rkNode + result = s[i+a.rb+1].node diff --git a/compiler/vmops.nim b/compiler/vmops.nim index e1a0dfef8..e40e05eff 100644 --- a/compiler/vmops.nim +++ b/compiler/vmops.nim @@ -13,7 +13,7 @@ from math import sqrt, ln, log10, log2, exp, round, arccos, arcsin, arctan, arctan2, cos, cosh, hypot, sinh, sin, tan, tanh, pow, trunc, floor, ceil, fmod -from os import getEnv, existsEnv, dirExists, fileExists +from os import getEnv, existsEnv, dirExists, fileExists, walkDir template mathop(op) {.immediate, dirty.} = registerCallback(c, "stdlib.math." & astToStr(op), `op Wrapper`) @@ -48,6 +48,12 @@ proc getCurrentExceptionMsgWrapper(a: VmArgs) {.nimcall.} = setResult(a, if a.currentException.isNil: "" else: a.currentException.sons[3].skipColon.strVal) +proc staticWalkDirImpl(path: string, relative: bool): PNode = + result = newNode(nkBracket) + for k, f in walkDir(path, relative): + result.add newTree(nkPar, newIntNode(nkIntLit, k.ord), + newStrNode(nkStrLit, f)) + proc registerAdditionalOps*(c: PCtx) = wrap1f(sqrt) wrap1f(ln) @@ -78,3 +84,5 @@ proc registerAdditionalOps*(c: PCtx) = wrap1s(fileExists) wrap2svoid(writeFile) systemop getCurrentExceptionMsg + registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} = + setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1))) |