Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/nimony/indexgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Nimony index generator.

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

assert n.stmtKind == StmtsS
inc n
Expand Down Expand Up @@ -135,6 +137,37 @@ proc indexFromNif*(infile: string) =
exports.mgetOrPut(suffix).incl sym
inc n
inc n
of PragmasS:
var x = n
let root = n
skip n
inc x
if x.substructureKind == KvU:
inc x
if x.kind == Ident and x.litId == compileTag:
# In Nim 2, compile pragma can take three forms.
# `{.compile: ("file.c", "$1.o").}` form is not supported.
inc x
if x.kind == StringLit:
toBuild.buildTree TagId(TupX), NoLineInfo:
toBuild.addStrLit "C"
toBuild.add x
toBuild.addStrLit ""
else:
error " Error: Unsupported compile pragma form.", root
elif x.stmtKind == CallS:
inc x
if x.kind == Ident and x.litId == compileTag:
inc x
assert x.kind == StringLit
toBuild.buildTree TagId(TupX), NoLineInfo:
toBuild.addStrLit "C"
toBuild.add x
inc x
if x.kind == StringLit:
toBuild.add x
else:
toBuild.addStrLit ""
else:
skip n
else:
Expand All @@ -149,3 +182,10 @@ proc indexFromNif*(infile: string) =
converters: move converterIndexMap,
classes: move classIndexMap,
exportBuf: exportBuf)

var content = "(.nif24)\n"
if toBuild.len > 0:
content.add "(build\n"
content.add toString(toBuild)
content.add ")"
writeFile changeFileExt(infile, ".deps.nif"), content
Loading