compilation cache: DLL interfacing now works
This commit is contained in:
parent
90db9171a2
commit
abe9dfafe8
5 changed files with 44 additions and 44 deletions
|
|
@ -531,7 +531,9 @@ proc genProcHeader(m: BModule, prc: PSym): PRope =
|
||||||
var check = initIntSet()
|
var check = initIntSet()
|
||||||
fillLoc(prc.loc, locProc, prc.typ, mangleName(prc), OnUnknown)
|
fillLoc(prc.loc, locProc, prc.typ, mangleName(prc), OnUnknown)
|
||||||
genProcParams(m, prc.typ, rettype, params, check)
|
genProcParams(m, prc.typ, rettype, params, check)
|
||||||
genCLineDir(result, prc.ast.sons[codePos])
|
# careful here! don't access ``prc.ast`` as that could reload large parts of
|
||||||
|
# the object graph!
|
||||||
|
genCLineDir(result, prc.info)
|
||||||
appf(result, "$1($2, $3)$4",
|
appf(result, "$1($2, $3)$4",
|
||||||
[toRope(CallingConvToStr[prc.typ.callConv]), rettype, prc.loc.r, params])
|
[toRope(CallingConvToStr[prc.typ.callConv]), rettype, prc.loc.r, params])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,8 +148,8 @@ proc appcg(p: BProc, s: TCProcSection, frmt: TFormatStr,
|
||||||
args: openarray[PRope]) =
|
args: openarray[PRope]) =
|
||||||
app(p.s[s], ropecg(p.module, frmt, args))
|
app(p.s[s], ropecg(p.module, frmt, args))
|
||||||
|
|
||||||
proc safeLineNm(t: PNode) : int =
|
proc safeLineNm(info: TLineInfo): int =
|
||||||
result = toLinenumber(t.info) # BUGFIX
|
result = toLinenumber(info)
|
||||||
if result < 0: result = 0 # negative numbers are not allowed in #line
|
if result < 0: result = 0 # negative numbers are not allowed in #line
|
||||||
|
|
||||||
proc genCLineDir(r: var PRope, filename: string, line: int) =
|
proc genCLineDir(r: var PRope, filename: string, line: int) =
|
||||||
|
|
@ -158,11 +158,11 @@ proc genCLineDir(r: var PRope, filename: string, line: int) =
|
||||||
appff(r, "$N#line $2 $1$N", "; line $2 \"$1\"$n",
|
appff(r, "$N#line $2 $1$N", "; line $2 \"$1\"$n",
|
||||||
[toRope(makeSingleLineCString(filename)), toRope(line)])
|
[toRope(makeSingleLineCString(filename)), toRope(line)])
|
||||||
|
|
||||||
proc genCLineDir(r: var PRope, t: PNode) =
|
proc genCLineDir(r: var PRope, info: TLineInfo) =
|
||||||
genCLineDir(r, t.info.toFullPath, t.safeLineNm)
|
genCLineDir(r, info.toFullPath, info.safeLineNm)
|
||||||
|
|
||||||
proc genLineDir(p: BProc, t: PNode) =
|
proc genLineDir(p: BProc, t: PNode) =
|
||||||
var line = t.safeLineNm
|
var line = t.info.safeLineNm
|
||||||
genCLineDir(p.s[cpsStmts], t.info.toFullPath, line)
|
genCLineDir(p.s[cpsStmts], t.info.toFullPath, line)
|
||||||
if ({optStackTrace, optEndb} * p.Options == {optStackTrace, optEndb}) and
|
if ({optStackTrace, optEndb} * p.Options == {optStackTrace, optEndb}) and
|
||||||
(p.prc == nil or sfPure notin p.prc.flags):
|
(p.prc == nil or sfPure notin p.prc.flags):
|
||||||
|
|
@ -447,7 +447,6 @@ proc SymInDynamicLib(m: BModule, sym: PSym) =
|
||||||
var lib = sym.annex
|
var lib = sym.annex
|
||||||
var extname = sym.loc.r
|
var extname = sym.loc.r
|
||||||
loadDynamicLib(m, lib)
|
loadDynamicLib(m, lib)
|
||||||
#discard cgsym(m, "nimGetProcAddr")
|
|
||||||
if gCmd == cmdCompileToLLVM: incl(sym.loc.flags, lfIndirect)
|
if gCmd == cmdCompileToLLVM: incl(sym.loc.flags, lfIndirect)
|
||||||
var tmp = mangleDynLibProc(sym)
|
var tmp = mangleDynLibProc(sym)
|
||||||
sym.loc.r = tmp # from now on we only need the internal name
|
sym.loc.r = tmp # from now on we only need the internal name
|
||||||
|
|
@ -461,6 +460,10 @@ proc SymInDynamicLib(m: BModule, sym: PSym) =
|
||||||
"$1 = linkonce global $2 zeroinitializer$n",
|
"$1 = linkonce global $2 zeroinitializer$n",
|
||||||
[sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
[sym.loc.r, getTypeDesc(m, sym.loc.t)])
|
||||||
|
|
||||||
|
proc SymInDynamicLibPartial(m: BModule, sym: PSym) =
|
||||||
|
sym.loc.r = mangleDynLibProc(sym)
|
||||||
|
sym.typ.sym = nil # generate a new name
|
||||||
|
|
||||||
proc cgsym(m: BModule, name: string): PRope =
|
proc cgsym(m: BModule, name: string): PRope =
|
||||||
var sym = magicsys.getCompilerProc(name)
|
var sym = magicsys.getCompilerProc(name)
|
||||||
if sym != nil:
|
if sym != nil:
|
||||||
|
|
@ -610,6 +613,8 @@ proc genProcNoForward(m: BModule, prc: PSym) =
|
||||||
var q = findPendingModule(m, prc)
|
var q = findPendingModule(m, prc)
|
||||||
if q != nil and not ContainsOrIncl(q.declaredThings, prc.id):
|
if q != nil and not ContainsOrIncl(q.declaredThings, prc.id):
|
||||||
SymInDynamicLib(q, prc)
|
SymInDynamicLib(q, prc)
|
||||||
|
else:
|
||||||
|
SymInDynamicLibPartial(m, prc)
|
||||||
elif sfImportc notin prc.flags:
|
elif sfImportc notin prc.flags:
|
||||||
var q = findPendingModule(m, prc)
|
var q = findPendingModule(m, prc)
|
||||||
if q != nil and not ContainsOrIncl(q.declaredThings, prc.id):
|
if q != nil and not ContainsOrIncl(q.declaredThings, prc.id):
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@ proc addFileToLink*(filename: string) =
|
||||||
# BUGFIX: was ``appendStr``
|
# BUGFIX: was ``appendStr``
|
||||||
|
|
||||||
proc execExternalProgram*(cmd: string) =
|
proc execExternalProgram*(cmd: string) =
|
||||||
if (optListCmd in gGlobalOptions) or (gVerbosity > 0): MsgWriteln(cmd)
|
if optListCmd in gGlobalOptions or gVerbosity > 0: MsgWriteln(cmd)
|
||||||
if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "")
|
if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "")
|
||||||
|
|
||||||
proc generateScript(projectFile: string, script: PRope) =
|
proc generateScript(projectFile: string, script: PRope) =
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,6 @@ proc getOrdValue*(n: PNode): biggestInt
|
||||||
proc computeSize*(typ: PType): biggestInt
|
proc computeSize*(typ: PType): biggestInt
|
||||||
proc getSize*(typ: PType): biggestInt
|
proc getSize*(typ: PType): biggestInt
|
||||||
proc isPureObject*(typ: PType): bool
|
proc isPureObject*(typ: PType): bool
|
||||||
proc inheritanceDiff*(a, b: PType): int
|
|
||||||
# | returns: 0 iff `a` == `b`
|
|
||||||
# | returns: -x iff `a` is the x'th direct superclass of `b`
|
|
||||||
# | returns: +x iff `a` is the x'th direct subclass of `b`
|
|
||||||
# | returns: `maxint` iff `a` and `b` are not compatible at all
|
|
||||||
proc InvalidGenericInst*(f: PType): bool
|
proc InvalidGenericInst*(f: PType): bool
|
||||||
# for debugging
|
# for debugging
|
||||||
type
|
type
|
||||||
|
|
@ -93,22 +88,6 @@ proc typeAllowed*(t: PType, kind: TSymKind): bool
|
||||||
proc InvalidGenericInst(f: PType): bool =
|
proc InvalidGenericInst(f: PType): bool =
|
||||||
result = (f.kind == tyGenericInst) and (lastSon(f) == nil)
|
result = (f.kind == tyGenericInst) and (lastSon(f) == nil)
|
||||||
|
|
||||||
proc inheritanceDiff(a, b: PType): int =
|
|
||||||
# conversion to superclass?
|
|
||||||
var x = a
|
|
||||||
result = 0
|
|
||||||
while x != nil:
|
|
||||||
if x.id == b.id: return
|
|
||||||
x = x.sons[0]
|
|
||||||
dec(result)
|
|
||||||
var y = b
|
|
||||||
result = 0
|
|
||||||
while y != nil:
|
|
||||||
if y.id == a.id: return
|
|
||||||
y = y.sons[0]
|
|
||||||
inc(result)
|
|
||||||
result = high(int)
|
|
||||||
|
|
||||||
proc isPureObject(typ: PType): bool =
|
proc isPureObject(typ: PType): bool =
|
||||||
var t = typ
|
var t = typ
|
||||||
while t.sons[0] != nil: t = t.sons[0]
|
while t.sons[0] != nil: t = t.sons[0]
|
||||||
|
|
@ -553,24 +532,19 @@ type
|
||||||
|
|
||||||
TSameTypeClosure = object {.pure.}
|
TSameTypeClosure = object {.pure.}
|
||||||
cmp: TDistinctCompare
|
cmp: TDistinctCompare
|
||||||
initSets: bool
|
|
||||||
recCheck: int
|
recCheck: int
|
||||||
a: TIntSet
|
s: seq[tuple[a,b: int]] # seq for a set as it's hopefully faster
|
||||||
b: TIntSet
|
# (few elements expected)
|
||||||
|
|
||||||
proc initSameTypeClosure: TSameTypeClosure =
|
proc initSameTypeClosure: TSameTypeClosure =
|
||||||
# we do the initialization lazy for performance (avoids memory allocations)
|
# we do the initialization lazy for performance (avoids memory allocations)
|
||||||
nil
|
nil
|
||||||
|
|
||||||
proc containsOrIncl(c: var TSameTypeClosure, a, b: PType): bool =
|
proc containsOrIncl(c: var TSameTypeClosure, a, b: PType): bool =
|
||||||
result = c.initSets and c.a.contains(a.id) and c.b.contains(b.id)
|
result = not IsNil(c.s) and c.s.contains((a.id, b.id))
|
||||||
if not result:
|
if not result:
|
||||||
if not c.initSets:
|
if IsNil(c.s): c.s = @[]
|
||||||
c.initSets = true
|
c.s.add((a.id, b.id))
|
||||||
c.a = initIntSet()
|
|
||||||
c.b = initIntSet()
|
|
||||||
c.a.incl(a.id)
|
|
||||||
c.b.incl(b.id)
|
|
||||||
|
|
||||||
proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool
|
proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool
|
||||||
proc SameTypeOrNilAux(a, b: PType, c: var TSameTypeClosure): bool =
|
proc SameTypeOrNilAux(a, b: PType, c: var TSameTypeClosure): bool =
|
||||||
|
|
@ -731,7 +705,7 @@ proc SameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
# again: Since the recursion check is only to not get caught in an endless
|
# again: Since the recursion check is only to not get caught in an endless
|
||||||
# recursion, we use a counter and only if it's value is over some
|
# recursion, we use a counter and only if it's value is over some
|
||||||
# threshold we perform the expansive exact cycle check:
|
# threshold we perform the expansive exact cycle check:
|
||||||
if c.recCheck < 20:
|
if c.recCheck < 3:
|
||||||
inc c.recCheck
|
inc c.recCheck
|
||||||
else:
|
else:
|
||||||
if containsOrIncl(c, a, b): return true
|
if containsOrIncl(c, a, b): return true
|
||||||
|
|
@ -797,6 +771,25 @@ proc compareTypes*(x, y: PType, cmp: TDistinctCompare): bool =
|
||||||
c.cmp = cmp
|
c.cmp = cmp
|
||||||
result = sameTypeAux(x, y, c)
|
result = sameTypeAux(x, y, c)
|
||||||
|
|
||||||
|
proc inheritanceDiff*(a, b: PType): int =
|
||||||
|
# | returns: 0 iff `a` == `b`
|
||||||
|
# | returns: -x iff `a` is the x'th direct superclass of `b`
|
||||||
|
# | returns: +x iff `a` is the x'th direct subclass of `b`
|
||||||
|
# | returns: `maxint` iff `a` and `b` are not compatible at all
|
||||||
|
var x = a
|
||||||
|
result = 0
|
||||||
|
while x != nil:
|
||||||
|
if sameObjectTypes(x, b): return
|
||||||
|
x = x.sons[0]
|
||||||
|
dec(result)
|
||||||
|
var y = b
|
||||||
|
result = 0
|
||||||
|
while y != nil:
|
||||||
|
if sameObjectTypes(y, a): return
|
||||||
|
y = y.sons[0]
|
||||||
|
inc(result)
|
||||||
|
result = high(int)
|
||||||
|
|
||||||
proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool
|
proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool
|
||||||
proc typeAllowedNode(marker: var TIntSet, n: PNode, kind: TSymKind): bool =
|
proc typeAllowedNode(marker: var TIntSet, n: PNode, kind: TSymKind): bool =
|
||||||
result = true
|
result = true
|
||||||
|
|
|
||||||
4
todo.txt
4
todo.txt
|
|
@ -16,7 +16,6 @@ Version 0.8.14
|
||||||
incremental compilation
|
incremental compilation
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
- fix DLL interfacing!
|
|
||||||
- the loading has to be MUCH more lazy! --> next version: We should re-load
|
- the loading has to be MUCH more lazy! --> next version: We should re-load
|
||||||
symbol.ast lazily
|
symbol.ast lazily
|
||||||
- adapt thread var implementation to care about the new merge operation
|
- adapt thread var implementation to care about the new merge operation
|
||||||
|
|
@ -28,6 +27,7 @@ incremental compilation
|
||||||
- test type converters
|
- test type converters
|
||||||
- test G, A, B example from the documentation; test init sections
|
- test G, A, B example from the documentation; test init sections
|
||||||
- test method generation
|
- test method generation
|
||||||
|
- test DLL interfacing
|
||||||
|
|
||||||
|
|
||||||
version 0.9.0
|
version 0.9.0
|
||||||
|
|
@ -35,7 +35,7 @@ version 0.9.0
|
||||||
|
|
||||||
- test the sort implementation again
|
- test the sort implementation again
|
||||||
- const ptr/ref
|
- const ptr/ref
|
||||||
- unsigned ints and bignums
|
- unsigned ints and bignums; requires abstract integer literal type
|
||||||
- implement the high level optimizer
|
- implement the high level optimizer
|
||||||
- warning for implicit openArray -> varargs convention
|
- warning for implicit openArray -> varargs convention
|
||||||
- implement explicit varargs
|
- implement explicit varargs
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue