diff options
author | Araq <rumpf_a@web.de> | 2015-04-24 12:27:39 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-04-24 12:35:13 +0200 |
commit | c1730e1eadb4ad0090a901d578840db281cb4715 (patch) | |
tree | f5a2433a4d826b941c684bd63046aebf18ff35a7 | |
parent | 3317faf80da14463fd75e9b7543d957782f73581 (diff) | |
download | Nim-c1730e1eadb4ad0090a901d578840db281cb4715.tar.gz |
fixes #2335
-rw-r--r-- | compiler/ccgstmts.nim | 11 | ||||
-rw-r--r-- | doc/nimc.txt | 21 |
2 files changed, 29 insertions, 3 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index c1e6b01ae..b6572d960 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -1001,12 +1001,19 @@ proc genAsmStmt(p: BProc, t: PNode) = else: lineF(p, cpsStmts, CC[cCompiler].asmStmtFrmt, [s]) +proc determineSection(n: PNode): TCFileSection = + result = cfsProcHeaders + if n.len >= 1 and n.sons[0].kind in {nkStrLit..nkTripleStrLit}: + if n.sons[0].strVal.startsWith("/*TYPESECTION*/"): result = cfsTypes + elif n.sons[0].strVal.startsWith("/*VARSECTION*/"): result = cfsVars + proc genEmit(p: BProc, t: PNode) = var s = genAsmOrEmitStmt(p, t.sons[1]) if p.prc == nil: # top level emit pragma? - genCLineDir(p.module.s[cfsProcHeaders], t.info) - add(p.module.s[cfsProcHeaders], s) + let section = determineSection(t[1]) + genCLineDir(p.module.s[section], t.info) + add(p.module.s[section], s) else: genLineDir(p, t) line(p, cpsStmts, s) diff --git a/doc/nimc.txt b/doc/nimc.txt index cfbccc479..fb1873539 100644 --- a/doc/nimc.txt +++ b/doc/nimc.txt @@ -386,6 +386,25 @@ Example: As can be seen from the example, to Nim symbols can be referred via backticks. Use two backticks to produce a single verbatim backtick. +For a toplevel emit statement the section where in the generated C/C++ file +the code should be emitted can be influenced via the +prefixes ``/*TYPESECTION*/`` or ``/*VARSECTION*/``: + +.. code-block:: Nim + {.emit: """/*TYPESECTION*/ + struct Vector3 { + public: + Vector3(): x(5) {} + Vector3(float x_): x(x_) {} + float x; + }; + """.} + + type Vector3 {.importcpp: "Vector3", nodecl} = object + x: cfloat + + proc constructVector3(a: cfloat): Vector3 {.importcpp: "Vector3(@)", nodecl} + ImportCpp pragma ---------------- @@ -611,7 +630,7 @@ Produces: Produces: .. code-block:: C - + std::vector<int>::iterator x; |