diff options
author | Hans Raaf <hara@oderwat.de> | 2016-05-11 22:51:27 +0200 |
---|---|---|
committer | Hans Raaf <hara@oderwat.de> | 2016-05-11 22:51:27 +0200 |
commit | d3bae50c3ca2bf38235bbc33f3f08ffa0f8e9a15 (patch) | |
tree | 260b575727cc6dfbbe25f07a173152563fcb7712 /lib/system | |
parent | b654aa399acf8e935bc83d58d74f2269b74f36b7 (diff) | |
download | Nim-d3bae50c3ca2bf38235bbc33f3f08ffa0f8e9a15.tar.gz |
PHP codegen array constructor hack.
Because of PHP can't have refs for literal function parameters I needed to come up with a hack such that the following code compiles with PHP target. ```nim type Foo = tuple[a: string, b: int] var foo: array [0..2, Foo] foo[0] = ("Test", 1) foo[1] = ("Me", 2) for x in foo: echo x.a echo x.b ```
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/jssys.nim | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index cdaf7dae6..220683717 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -731,16 +731,19 @@ proc genericReset(x: JSRef, ti: PNimType): JSRef {.compilerproc.} = else: discard -proc arrayConstr(len: int, value: JSRef, typ: PNimType): JSRef {. - asmNoStackFrame, compilerproc.} = - # types are fake - when defined(nimphp): +when defined(nimphp): + proc arrayConstr(len: int, value: string, typ: string): JSRef {. + asmNoStackFrame, compilerproc.} = + # types are fake asm """ $result = array(); for ($i = 0; $i < `len`; $i++) $result[] = `value`; return $result; """ - else: +else: + proc arrayConstr(len: int, value: JSRef, typ: PNimType): JSRef {. + asmNoStackFrame, compilerproc.} = + # types are fake asm """ var result = new Array(`len`); for (var i = 0; i < `len`; ++i) result[i] = nimCopy(null, `value`, `typ`); |