Skip to content

Commit 8be31c3

Browse files
committed
parses compile pragmas in Nim 2
1 parent e3fdb8b commit 8be31c3

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/nimony/indexgen.nim

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Nimony index generator.
88

9-
import std / [os, assertions, sets, tables]
9+
import std / [os, assertions, sets, syncio, tables]
1010
include ".." / lib / nifprelude
1111
import ".." / lib / [nifindexes, symparser]
1212
import decls, nimony_model, programs, vtables_frontend, semos
@@ -90,6 +90,8 @@ proc indexFromNif*(infile: string) =
9090
var converterIndexMap = default seq[(SymId, SymId)]
9191
var classIndexMap = default seq[ClassIndexEntry]
9292
var exports = default Table[string, HashSet[SymId]] # Module suffix -> symbols to export in the module
93+
var toBuild = createTokenBuf()
94+
let compileTag = pool.strings.getOrIncl("compile")
9395

9496
assert n.stmtKind == StmtsS
9597
inc n
@@ -135,6 +137,37 @@ proc indexFromNif*(infile: string) =
135137
exports.mgetOrPut(suffix).incl sym
136138
inc n
137139
inc n
140+
of PragmasS:
141+
var x = n
142+
let root = n
143+
skip n
144+
inc x
145+
if x.substructureKind == KvU:
146+
inc x
147+
if x.kind == Ident and x.litId == compileTag:
148+
# In Nim 2, compile pragma can take three forms.
149+
# `{.compile: ("file.c", "$1.o").}` form is not supported.
150+
inc x
151+
if x.kind == StringLit:
152+
toBuild.buildTree TagId(TupX), NoLineInfo:
153+
toBuild.addStrLit "C"
154+
toBuild.add x
155+
toBuild.addStrLit ""
156+
else:
157+
error " Error: Unsupported compile pragma form.", root
158+
elif x.stmtKind == CallS:
159+
inc x
160+
if x.kind == Ident and x.litId == compileTag:
161+
inc x
162+
assert x.kind == StringLit
163+
toBuild.buildTree TagId(TupX), NoLineInfo:
164+
toBuild.addStrLit "C"
165+
toBuild.add x
166+
inc x
167+
if x.kind == StringLit:
168+
toBuild.add x
169+
else:
170+
toBuild.addStrLit ""
138171
else:
139172
skip n
140173
else:
@@ -149,3 +182,10 @@ proc indexFromNif*(infile: string) =
149182
converters: move converterIndexMap,
150183
classes: move classIndexMap,
151184
exportBuf: exportBuf)
185+
186+
var content = "(.nif24)\n"
187+
if toBuild.len > 0:
188+
content.add "(build\n"
189+
content.add toString(toBuild)
190+
content.add ")"
191+
writeFile changeFileExt(infile, ".deps.nif"), content

0 commit comments

Comments
 (0)