fix compilation errors when bootstrapping with C++

This commit is contained in:
Zahary Karadjov 2012-06-04 01:56:10 +03:00
commit 4105a91c48
6 changed files with 41 additions and 25 deletions

View file

@ -881,10 +881,15 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
# seq &= x --> # seq &= x -->
# seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x)); # seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x));
# seq->data[seq->len-1] = x; # seq->data[seq->len-1] = x;
let seqAppendPattern = if gCmd != cmdCompileToCpp:
"$1 = ($2) #incrSeq(&($1)->Sup, sizeof($3));$n"
else:
"$1 = ($2) #incrSeq($1, sizeof($3));$n"
var a, b, dest: TLoc var a, b, dest: TLoc
InitLocExpr(p, e.sons[1], a) InitLocExpr(p, e.sons[1], a)
InitLocExpr(p, e.sons[2], b) InitLocExpr(p, e.sons[2], b)
appcg(p, cpsStmts, "$1 = ($2) #incrSeq(&($1)->Sup, sizeof($3));$n", [ appcg(p, cpsStmts, seqAppendPattern, [
rdLoc(a), rdLoc(a),
getTypeDesc(p.module, skipTypes(e.sons[1].typ, abstractVar)), getTypeDesc(p.module, skipTypes(e.sons[1].typ, abstractVar)),
getTypeDesc(p.module, skipTypes(e.sons[2].Typ, abstractVar))]) getTypeDesc(p.module, skipTypes(e.sons[2].Typ, abstractVar))])
@ -1114,8 +1119,12 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
InitLocExpr(p, e.sons[1], a) InitLocExpr(p, e.sons[1], a)
InitLocExpr(p, e.sons[2], b) InitLocExpr(p, e.sons[2], b)
var t = skipTypes(e.sons[1].typ, abstractVar) var t = skipTypes(e.sons[1].typ, abstractVar)
appcg(p, cpsStmts, let setLenPattern = if gCmd != cmdCompileToCpp:
"$1 = ($3) #setLengthSeq(&($1)->Sup, sizeof($4), $2);$n", [ "$1 = ($3) #setLengthSeq(&($1)->Sup, sizeof($4), $2);$n"
else:
"$1 = ($3) #setLengthSeq($1, sizeof($4), $2);$n"
appcg(p, cpsStmts, setLenPattern, [
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t), rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
getTypeDesc(p.module, t.sons[0])]) getTypeDesc(p.module, t.sons[0])])
keepAlive(p, a) keepAlive(p, a)

View file

@ -556,13 +556,14 @@ proc genTryStmtCpp(p: BProc, t: PNode) =
i, length, blen: int i, length, blen: int
genLineDir(p, t) genLineDir(p, t)
exc = getTempName() exc = getTempName()
if optStackTrace in p.Options: discard cgsym(p.module, "E_Base")
appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
add(p.nestedTryStmts, t) add(p.nestedTryStmts, t)
startBlock(p, "try {$n") startBlock(p, "try {$n")
genStmts(p, t.sons[0]) genStmts(p, t.sons[0])
length = sonsLen(t) length = sonsLen(t)
endBlock(p, ropecg(p.module, "} catch (NimException& $1) {$n", [exc])) endBlock(p, ropecg(p.module, "} catch (NimException& $1) {$n", [exc]))
if optStackTrace in p.Options:
appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
inc p.inExceptBlock inc p.inExceptBlock
i = 1 i = 1
var catchAllPresent = false var catchAllPresent = false
@ -581,7 +582,6 @@ proc genTryStmtCpp(p: BProc, t: PNode) =
appcg(p.module, orExpr, appcg(p.module, orExpr,
"#isObj($1.exp->m_type, $2)", "#isObj($1.exp->m_type, $2)",
[exc, genTypeInfo(p.module, t.sons[i].sons[j].typ)]) [exc, genTypeInfo(p.module, t.sons[i].sons[j].typ)])
if i > 1: app(p.s(cpsStmts), "else ")
appf(p.s(cpsStmts), "if ($1) ", [orExpr]) appf(p.s(cpsStmts), "if ($1) ", [orExpr])
genSimpleBlock(p, t.sons[i].sons[blen-1]) genSimpleBlock(p, t.sons[i].sons[blen-1])
inc(i) inc(i)
@ -639,13 +639,13 @@ proc genTryStmt(p: BProc, t: PNode) =
appcg(p, cpsLocals, "#TSafePoint $1;$n", [safePoint]) appcg(p, cpsLocals, "#TSafePoint $1;$n", [safePoint])
appcg(p, cpsStmts, "#pushSafePoint(&$1);$n" & appcg(p, cpsStmts, "#pushSafePoint(&$1);$n" &
"$1.status = setjmp($1.context);$n", [safePoint]) "$1.status = setjmp($1.context);$n", [safePoint])
if optStackTrace in p.Options:
appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
startBlock(p, "if ($1.status == 0) {$n", [safePoint]) startBlock(p, "if ($1.status == 0) {$n", [safePoint])
var length = sonsLen(t) var length = sonsLen(t)
add(p.nestedTryStmts, t) add(p.nestedTryStmts, t)
genStmts(p, t.sons[0]) genStmts(p, t.sons[0])
endBlock(p, ropecg(p.module, "#popSafePoint();$n } else {$n#popSafePoint();$n")) endBlock(p, ropecg(p.module, "#popSafePoint();$n } else {$n#popSafePoint();$n"))
if optStackTrace in p.Options:
appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
inc p.inExceptBlock inc p.inExceptBlock
var i = 1 var i = 1
while (i < length) and (t.sons[i].kind == nkExceptBranch): while (i < length) and (t.sons[i].kind == nkExceptBranch):

View file

@ -62,6 +62,7 @@ hint[LineTooLong]=off
@if not bsd: @if not bsd:
# -fopenmp # -fopenmp
gcc.options.linker = "-ldl" gcc.options.linker = "-ldl"
gpp.options.linker = "-ldl"
clang.options.linker = "-ldl" clang.options.linker = "-ldl"
tcc.options.linker = "-ldl" tcc.options.linker = "-ldl"
@else: @else:
@ -83,24 +84,23 @@ icc.options.linker = "-cxxlib"
tlsEmulation:on tlsEmulation:on
@end @end
@end @end
gcc.options.debug = "-g3 -O0"
@if macosx: @if macosx:
tlsEmulation:on tlsEmulation:on
@if not release: gcc.options.always = "-w -fasm-blocks"
gcc.options.always = "-w -fasm-blocks -O1" gpp.options.always = "-w -fasm-blocks"
@else:
gcc.options.always = "-w -fasm-blocks"
@end
@else: @else:
@if not release: gcc.options.always = "-w"
gcc.options.always = "-w" gpp.options.always = "-w"
@else:
gcc.options.always = "-w"
@end
@end @end
gcc.options.speed = "-O3 -fno-strict-aliasing" gcc.options.speed = "-O3 -fno-strict-aliasing"
gcc.options.size = "-Os" gcc.options.size = "-Os"
gcc.options.debug = "-g3 -O0"
gpp.options.speed = "-O3 -fno-strict-aliasing"
gpp.options.size = "-Os"
gpp.options.debug = "-g3 -O0"
#passl = "-pg" #passl = "-pg"
# Configuration for the LLVM GCC compiler: # Configuration for the LLVM GCC compiler:

View file

@ -1346,11 +1346,15 @@ when defined(linux) or defined(solaris) or defined(bsd) or defined(aix):
setlen(result, len) setlen(result, len)
when defined(macosx): when defined(macosx):
type
cuint32* {.importc: "unsigned int", nodecl.} = int
## This is the same as the type ``uint32_t`` in *C*.
# a really hacky solution: since we like to include 2 headers we have to # a really hacky solution: since we like to include 2 headers we have to
# define two procs which in reality are the same # define two procs which in reality are the same
proc getExecPath1(c: cstring, size: var int32) {. proc getExecPath1(c: cstring, size: var cuint32) {.
importc: "_NSGetExecutablePath", header: "<sys/param.h>".} importc: "_NSGetExecutablePath", header: "<sys/param.h>".}
proc getExecPath2(c: cstring, size: var int32): bool {. proc getExecPath2(c: cstring, size: var cuint32): bool {.
importc: "_NSGetExecutablePath", header: "<mach-o/dyld.h>".} importc: "_NSGetExecutablePath", header: "<mach-o/dyld.h>".}
proc getAppFilename*(): string {.rtl, extern: "nos$1".} = proc getAppFilename*(): string {.rtl, extern: "nos$1".} =
@ -1379,7 +1383,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1".} =
elif defined(bsd): elif defined(bsd):
result = getApplAux("/proc/" & $getpid() & "/file") result = getApplAux("/proc/" & $getpid() & "/file")
elif defined(macosx): elif defined(macosx):
var size: int32 var size: cuint32
getExecPath1(nil, size) getExecPath1(nil, size)
result = newString(int(size)) result = newString(int(size))
if getExecPath2(result, size): if getExecPath2(result, size):

View file

@ -123,7 +123,7 @@ when defined(macosx) or defined(bsd):
HW_AVAILCPU = 25 HW_AVAILCPU = 25
HW_NCPU = 3 HW_NCPU = 3
proc sysctl(x: ptr array[0..3, cint], y: cint, z: pointer, proc sysctl(x: ptr array[0..3, cint], y: cint, z: pointer,
a: var int, b: pointer, c: int): cint {. a: var csize, b: pointer, c: int): cint {.
importc: "sysctl", header: "<sys/sysctl.h>".} importc: "sysctl", header: "<sys/sysctl.h>".}
proc countProcessors*(): int {.rtl, extern: "nosp$1".} = proc countProcessors*(): int {.rtl, extern: "nosp$1".} =
@ -135,7 +135,8 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} =
elif defined(macosx) or defined(bsd): elif defined(macosx) or defined(bsd):
var var
mib: array[0..3, cint] mib: array[0..3, cint]
len, numCPU: int numCPU: int
len: csize
mib[0] = CTL_HW mib[0] = CTL_HW
mib[1] = HW_AVAILCPU mib[1] = HW_AVAILCPU
len = sizeof(numCPU) len = sizeof(numCPU)

View file

@ -935,6 +935,8 @@ type # these work for most platforms:
## This is the same as the type ``short`` in *C*. ## This is the same as the type ``short`` in *C*.
cint* {.importc: "int", nodecl.} = int32 cint* {.importc: "int", nodecl.} = int32
## This is the same as the type ``int`` in *C*. ## This is the same as the type ``int`` in *C*.
csize* {.importc: "size_t", nodecl.} = int
## This is the same as the type ``size_t`` in *C*.
clong* {.importc: "long", nodecl.} = int clong* {.importc: "long", nodecl.} = int
## This is the same as the type ``long`` in *C*. ## This is the same as the type ``long`` in *C*.
clonglong* {.importc: "long long", nodecl.} = int64 clonglong* {.importc: "long long", nodecl.} = int64
@ -951,7 +953,7 @@ type # these work for most platforms:
## This is binary compatible to the type ``char**`` in *C*. The array's ## This is binary compatible to the type ``char**`` in *C*. The array's
## high value is large enough to disable bounds checking in practice. ## high value is large enough to disable bounds checking in practice.
## Use `cstringArrayToSeq` to convert it into a ``seq[string]``. ## Use `cstringArrayToSeq` to convert it into a ``seq[string]``.
PFloat32* = ptr Float32 ## an alias for ``ptr float32`` PFloat32* = ptr Float32 ## an alias for ``ptr float32``
PFloat64* = ptr Float64 ## an alias for ``ptr float64`` PFloat64* = ptr Float64 ## an alias for ``ptr float64``
PInt64* = ptr Int64 ## an alias for ``ptr int64`` PInt64* = ptr Int64 ## an alias for ``ptr int64``