JS codegen: supports more builtins

This commit is contained in:
Araq 2013-09-24 23:56:23 +02:00
commit 9bfcdc40ef
3 changed files with 32 additions and 11 deletions

View file

@ -209,17 +209,26 @@ proc getGeneratedPath: string =
result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir /
genSubDir
proc getPackageName(path: string): string =
var q = 1
var b = 0
if path[len(path)-1] in {dirsep, altsep}: q = 2
for i in countdown(len(path)-q, 0):
if path[i] in {dirsep, altsep}:
if b == 0: b = i
else:
let x = path.substr(i+1, b-1)
case x.normalize
of "lib", "src", "source", "package", "pckg", "library": b = i
else: return x
proc withPackageName*(path: string): string =
var x = path
while true:
x = parentDir(x)
if x.len == 0: break
case x.normalize
of "lib", "src", "source", "package", "pckg", "library": discard
else:
let (path, file, ext) = path.splitFile
return (path / (x & '_' & file)) & ext
result = path
let x = path.getPackageName
if x.isNil:
result = path
else:
let (p, file, ext) = path.splitFile
result = (p / (x & '_' & file)) & ext
proc toGeneratedFile*(path, ext: string): string =
## converts "/home/a/mymodule.nim", "rod" to "/home/a/nimcache/mymodule.rod"