diff options
author | Araq <rumpf_a@web.de> | 2013-09-24 23:56:23 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-09-24 23:56:23 +0200 |
commit | 9bfcdc40ef681f9d33af52db8cd196513a64cd3f (patch) | |
tree | 2a50713cdec35c717e6e2c13a093de1b513f378b /compiler/options.nim | |
parent | e3ecc328a19386142b13f3ef1cc801e7c158235f (diff) | |
download | Nim-9bfcdc40ef681f9d33af52db8cd196513a64cd3f.tar.gz |
JS codegen: supports more builtins
Diffstat (limited to 'compiler/options.nim')
-rw-r--r-- | compiler/options.nim | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/compiler/options.nim b/compiler/options.nim index e50535b8e..2b607a48b 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -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" |