diff options
-rw-r--r-- | compiler/jsgen.nim | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 33a8dc12d..3bbb22745 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -2089,7 +2089,8 @@ proc getClassName(t: PType): Rope = s = skipTypes(t, abstractPtrs).sym if s.isNil or sfAnon in s.flags: internalError("cannot retrieve class name") - result = mangleName(s, targetPHP) + if s.loc.r != nil: result = s.loc.r + else: result = rope(s.name.s) proc genClass(obj: PType; content: Rope; ext: string) = let cls = getClassName(obj) @@ -2100,6 +2101,7 @@ proc genClass(obj: PType; content: Rope; ext: string) = let result = ("<?php$n" & "/* Generated by the Nim Compiler v$# */$n" & "/* (c) 2016 Andreas Rumpf */$n$n" & + "require_once \"nimsystem.php\";$n" & "class $#$# {$n$#$n}$n") % [rope(VersionAsString), cls, extends, content] @@ -2112,13 +2114,15 @@ proc myClose(b: PPassContext, n: PNode): PNode = var m = BModule(b) if sfMainModule in m.module.flags: let ext = if m.target == targetJS: "js" else: "php" + let f = if globals.classes.len == 0: m.module.filename + else: "nimsystem" let code = wholeCode(m) let outfile = if options.outFile.len > 0: if options.outFile.isAbsolute: options.outFile else: getCurrentDir() / options.outFile else: - changeFileExt(completeCFilePath(m.module.filename), ext) + changeFileExt(completeCFilePath(f), ext) discard writeRopeIfNotEqual(genHeader(m.target) & code, outfile) for obj, content in items(globals.classes): genClass(obj, content, ext) |