Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
This commit is contained in:
commit
556efb5158
4 changed files with 100 additions and 90 deletions
|
|
@ -913,21 +913,21 @@ proc addIntTypes(result: var PRope) {.inline.} =
|
||||||
|
|
||||||
proc getCopyright(cfilenoext: string): PRope =
|
proc getCopyright(cfilenoext: string): PRope =
|
||||||
if optCompileOnly in gGlobalOptions:
|
if optCompileOnly in gGlobalOptions:
|
||||||
result = ropeff("/* Generated by Nimrod Compiler v$1 */$n" &
|
result = ropeff("/* Generated by Nimrod Compiler v$1 */$N" &
|
||||||
"/* (c) 2014 Andreas Rumpf */$n" &
|
"/* (c) 2014 Andreas Rumpf */$N" &
|
||||||
"/* The generated code is subject to the original license. */$n",
|
"/* The generated code is subject to the original license. */$N",
|
||||||
"; Generated by Nimrod Compiler v$1$n" &
|
"; Generated by Nimrod Compiler v$1$N" &
|
||||||
"; (c) 2012 Andreas Rumpf$n", [toRope(VersionAsString)])
|
"; (c) 2012 Andreas Rumpf$N", [toRope(VersionAsString)])
|
||||||
else:
|
else:
|
||||||
result = ropeff("/* Generated by Nimrod Compiler v$1 */$n" &
|
result = ropeff("/* Generated by Nimrod Compiler v$1 */$N" &
|
||||||
"/* (c) 2014 Andreas Rumpf */$n" &
|
"/* (c) 2014 Andreas Rumpf */$N" &
|
||||||
"/* The generated code is subject to the original license. */$n" &
|
"/* The generated code is subject to the original license. */$N" &
|
||||||
"/* Compiled for: $2, $3, $4 */$n" &
|
"/* Compiled for: $2, $3, $4 */$N" &
|
||||||
"/* Command for C compiler:$n $5 */$n",
|
"/* Command for C compiler:$n $5 */$N",
|
||||||
"; Generated by Nimrod Compiler v$1$n" &
|
"; Generated by Nimrod Compiler v$1$N" &
|
||||||
"; (c) 2014 Andreas Rumpf$n" &
|
"; (c) 2014 Andreas Rumpf$N" &
|
||||||
"; Compiled for: $2, $3, $4$n" &
|
"; Compiled for: $2, $3, $4$N" &
|
||||||
"; Command for LLVM compiler:$n $5$n", [toRope(VersionAsString),
|
"; Command for LLVM compiler:$N $5$N", [toRope(VersionAsString),
|
||||||
toRope(platform.OS[targetOS].name),
|
toRope(platform.OS[targetOS].name),
|
||||||
toRope(platform.CPU[targetCPU].name),
|
toRope(platform.CPU[targetCPU].name),
|
||||||
toRope(extccomp.CC[extccomp.cCompiler].name),
|
toRope(extccomp.CC[extccomp.cCompiler].name),
|
||||||
|
|
@ -941,61 +941,71 @@ proc genFilenames(m: BModule): PRope =
|
||||||
discard cgsym(m, "dbgRegisterFilename")
|
discard cgsym(m, "dbgRegisterFilename")
|
||||||
result = nil
|
result = nil
|
||||||
for i in 0.. <fileInfos.len:
|
for i in 0.. <fileInfos.len:
|
||||||
result.appf("dbgRegisterFilename($1);$n", fileInfos[i].projPath.makeCString)
|
result.appf("dbgRegisterFilename($1);$N", fileInfos[i].projPath.makeCString)
|
||||||
|
|
||||||
proc genMainProc(m: BModule) =
|
proc genMainProc(m: BModule) =
|
||||||
const
|
const
|
||||||
PreMainBody =
|
PreMainBody =
|
||||||
"\tsystemDatInit();$n" &
|
"\tsystemDatInit();$N" &
|
||||||
"\tsystemInit();$n" &
|
"\tsystemInit();$N" &
|
||||||
"$1" &
|
"$1" &
|
||||||
"$2" &
|
"$2" &
|
||||||
"$3" &
|
"$3" &
|
||||||
"$4"
|
"$4"
|
||||||
|
|
||||||
MainProcs =
|
MainProcs =
|
||||||
"\tPreMain();$n" &
|
"\tNimMain();$N"
|
||||||
"\tNimMain();$n"
|
|
||||||
|
|
||||||
MainProcsWithResult =
|
MainProcsWithResult =
|
||||||
MainProcs & "\treturn nim_program_result;$n"
|
MainProcs & "\treturn nim_program_result;$N"
|
||||||
|
|
||||||
|
NimMainBody =
|
||||||
|
"N_CDECL(void, NimMain)(void) {$N" &
|
||||||
|
"\tPreMain();$N" &
|
||||||
|
"$1$N" &
|
||||||
|
"}$N"
|
||||||
|
|
||||||
PosixNimMain =
|
PosixNimMain =
|
||||||
"int cmdCount;$n" &
|
"int cmdCount;$N" &
|
||||||
"char** cmdLine;$n" &
|
"char** cmdLine;$N" &
|
||||||
"char** gEnv;$n" &
|
"char** gEnv;$N" &
|
||||||
"N_CDECL(void, NimMain)(void) {$n$1}$n"
|
NimMainBody
|
||||||
|
|
||||||
PosixCMain = "int main(int argc, char** args, char** env) {$n" &
|
PosixCMain =
|
||||||
"\tcmdLine = args;$n" & "\tcmdCount = argc;$n" & "\tgEnv = env;$n" &
|
"int main(int argc, char** args, char** env) {$N" &
|
||||||
|
"\tcmdLine = args;$N" &
|
||||||
|
"\tcmdCount = argc;$N" &
|
||||||
|
"\tgEnv = env;$N" &
|
||||||
MainProcsWithResult &
|
MainProcsWithResult &
|
||||||
"}$n"
|
"}$N"
|
||||||
|
|
||||||
StandaloneCMain = "int main(void) {$n" &
|
StandaloneCMain =
|
||||||
|
"int main(void) {$N" &
|
||||||
MainProcs &
|
MainProcs &
|
||||||
"\treturn 0;$n" & "}$n"
|
"\treturn 0;$N" &
|
||||||
|
"}$N"
|
||||||
|
|
||||||
WinNimMain = "N_CDECL(void, NimMain)(void) {$n$1}$n"
|
WinNimMain = NimMainBody
|
||||||
|
|
||||||
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" &
|
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $N" &
|
||||||
" HINSTANCE hPrevInstance, $n" &
|
" HINSTANCE hPrevInstance, $N" &
|
||||||
" LPSTR lpCmdLine, int nCmdShow) {$n" &
|
" LPSTR lpCmdLine, int nCmdShow) {$N" &
|
||||||
MainProcsWithResult & "}$n"
|
MainProcsWithResult & "}$N"
|
||||||
|
|
||||||
WinNimDllMain = "N_LIB_EXPORT N_CDECL(void, NimMain)(void) {$n$1}$n"
|
WinNimDllMain = "N_LIB_EXPORT " & NimMainBody
|
||||||
|
|
||||||
WinCDllMain =
|
WinCDllMain =
|
||||||
"BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $n" &
|
"BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $N" &
|
||||||
" LPVOID lpvReserved) {$n" &
|
" LPVOID lpvReserved) {$N" &
|
||||||
"\tif(fwdreason == DLL_PROCESS_ATTACH) {" & MainProcs & "}$n" &
|
"\tif(fwdreason == DLL_PROCESS_ATTACH) {$N" & MainProcs & "}$N" &
|
||||||
"\treturn 1;$n}$n"
|
"\treturn 1;$N}$N"
|
||||||
|
|
||||||
PosixNimDllMain = WinNimDllMain
|
PosixNimDllMain = WinNimDllMain
|
||||||
|
|
||||||
PosixCDllMain =
|
PosixCDllMain =
|
||||||
"void NIM_POSIX_INIT NimMainInit(void) {$n" &
|
"void NIM_POSIX_INIT NimMainInit(void) {$N" &
|
||||||
MainProcs &
|
MainProcs &
|
||||||
"}$n"
|
"}$N"
|
||||||
|
|
||||||
var nimMain, otherMain: TFormatStr
|
var nimMain, otherMain: TFormatStr
|
||||||
if platform.targetOS == osWindows and
|
if platform.targetOS == osWindows and
|
||||||
|
|
@ -1022,9 +1032,9 @@ proc genMainProc(m: BModule) =
|
||||||
|
|
||||||
let initStackBottomCall = if emulatedThreadVars() or
|
let initStackBottomCall = if emulatedThreadVars() or
|
||||||
platform.targetOS == osStandalone: "".toRope
|
platform.targetOS == osStandalone: "".toRope
|
||||||
else: ropecg(m, "\t#initStackBottom();$n")
|
else: ropecg(m, "\t#initStackBottom();$N")
|
||||||
inc(m.labels)
|
inc(m.labels)
|
||||||
appcg(m, m.s[cfsProcs], "void PreMain() {$n" & PreMainBody & "}$n", [
|
appcg(m, m.s[cfsProcs], "void PreMain() {$N" & PreMainBody & "}$N", [
|
||||||
mainDatInit, initStackBottomCall, gBreakpoints, otherModsInit])
|
mainDatInit, initStackBottomCall, gBreakpoints, otherModsInit])
|
||||||
|
|
||||||
appcg(m, m.s[cfsProcs], nimMain, [mainModInit, toRope(m.labels)])
|
appcg(m, m.s[cfsProcs], nimMain, [mainModInit, toRope(m.labels)])
|
||||||
|
|
@ -1049,8 +1059,8 @@ proc registerModuleToMain(m: PSym) =
|
||||||
appff(mainModProcs, "N_NOINLINE(void, $1)(void);$N",
|
appff(mainModProcs, "N_NOINLINE(void, $1)(void);$N",
|
||||||
"declare void $1() noinline$N", [datInit])
|
"declare void $1() noinline$N", [datInit])
|
||||||
if sfSystemModule notin m.flags:
|
if sfSystemModule notin m.flags:
|
||||||
appff(mainDatInit, "\t$1();$n", "call void ()* $1$n", [datInit])
|
appff(mainDatInit, "\t$1();$N", "call void ()* $1$n", [datInit])
|
||||||
let initCall = ropeff("\t$1();$n", "call void ()* $1$n", [init])
|
let initCall = ropeff("\t$1();$N", "call void ()* $1$n", [init])
|
||||||
if sfMainModule in m.flags:
|
if sfMainModule in m.flags:
|
||||||
app(mainModInit, initCall)
|
app(mainModInit, initCall)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1058,7 +1068,7 @@ proc registerModuleToMain(m: PSym) =
|
||||||
|
|
||||||
proc genInitCode(m: BModule) =
|
proc genInitCode(m: BModule) =
|
||||||
var initname = getInitName(m.module)
|
var initname = getInitName(m.module)
|
||||||
var prc = ropeff("N_NOINLINE(void, $1)(void) {$n",
|
var prc = ropeff("N_NOINLINE(void, $1)(void) {$N",
|
||||||
"define void $1() noinline {$n", [initname])
|
"define void $1() noinline {$n", [initname])
|
||||||
if m.typeNodes > 0:
|
if m.typeNodes > 0:
|
||||||
appcg(m, m.s[cfsTypeInit1], "static #TNimNode $1[$2];$n",
|
appcg(m, m.s[cfsTypeInit1], "static #TNimNode $1[$2];$n",
|
||||||
|
|
@ -1101,7 +1111,7 @@ proc genInitCode(m: BModule) =
|
||||||
app(prc, deinitGCFrame(m.initProc))
|
app(prc, deinitGCFrame(m.initProc))
|
||||||
appf(prc, "}$N$N")
|
appf(prc, "}$N$N")
|
||||||
|
|
||||||
prc.appff("N_NOINLINE(void, $1)(void) {$n",
|
prc.appff("N_NOINLINE(void, $1)(void) {$N",
|
||||||
"define void $1() noinline {$n", [getDatInitName(m.module)])
|
"define void $1() noinline {$n", [getDatInitName(m.module)])
|
||||||
|
|
||||||
for i in cfsTypeInit1..cfsDynLibInit:
|
for i in cfsTypeInit1..cfsDynLibInit:
|
||||||
|
|
|
||||||
|
|
@ -447,39 +447,39 @@ proc chr*(u: range[0..255]): char {.magic: "Chr", noSideEffect.}
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# built-in operators
|
# built-in operators
|
||||||
|
|
||||||
proc ze*(x: int8): int {.magic: "Ze8ToI", noSideEffect.}
|
when not defined(JS):
|
||||||
|
proc ze*(x: int8): int {.magic: "Ze8ToI", noSideEffect.}
|
||||||
## zero extends a smaller integer type to ``int``. This treats `x` as
|
## zero extends a smaller integer type to ``int``. This treats `x` as
|
||||||
## unsigned.
|
## unsigned.
|
||||||
proc ze*(x: int16): int {.magic: "Ze16ToI", noSideEffect.}
|
proc ze*(x: int16): int {.magic: "Ze16ToI", noSideEffect.}
|
||||||
## zero extends a smaller integer type to ``int``. This treats `x` as
|
## zero extends a smaller integer type to ``int``. This treats `x` as
|
||||||
## unsigned.
|
## unsigned.
|
||||||
|
|
||||||
proc ze64*(x: int8): int64 {.magic: "Ze8ToI64", noSideEffect.}
|
proc ze64*(x: int8): int64 {.magic: "Ze8ToI64", noSideEffect.}
|
||||||
## zero extends a smaller integer type to ``int64``. This treats `x` as
|
## zero extends a smaller integer type to ``int64``. This treats `x` as
|
||||||
## unsigned.
|
## unsigned.
|
||||||
proc ze64*(x: int16): int64 {.magic: "Ze16ToI64", noSideEffect.}
|
proc ze64*(x: int16): int64 {.magic: "Ze16ToI64", noSideEffect.}
|
||||||
## zero extends a smaller integer type to ``int64``. This treats `x` as
|
## zero extends a smaller integer type to ``int64``. This treats `x` as
|
||||||
## unsigned.
|
## unsigned.
|
||||||
|
|
||||||
proc ze64*(x: int32): int64 {.magic: "Ze32ToI64", noSideEffect.}
|
proc ze64*(x: int32): int64 {.magic: "Ze32ToI64", noSideEffect.}
|
||||||
## zero extends a smaller integer type to ``int64``. This treats `x` as
|
## zero extends a smaller integer type to ``int64``. This treats `x` as
|
||||||
## unsigned.
|
## unsigned.
|
||||||
proc ze64*(x: int): int64 {.magic: "ZeIToI64", noSideEffect.}
|
proc ze64*(x: int): int64 {.magic: "ZeIToI64", noSideEffect.}
|
||||||
## zero extends a smaller integer type to ``int64``. This treats `x` as
|
## zero extends a smaller integer type to ``int64``. This treats `x` as
|
||||||
## unsigned. Does nothing if the size of an ``int`` is the same as ``int64``.
|
## unsigned. Does nothing if the size of an ``int`` is the same as ``int64``.
|
||||||
## (This is the case on 64 bit processors.)
|
## (This is the case on 64 bit processors.)
|
||||||
|
|
||||||
proc toU8*(x: int): int8 {.magic: "ToU8", noSideEffect.}
|
proc toU8*(x: int): int8 {.magic: "ToU8", noSideEffect.}
|
||||||
## treats `x` as unsigned and converts it to a byte by taking the last 8 bits
|
## treats `x` as unsigned and converts it to a byte by taking the last 8 bits
|
||||||
## from `x`.
|
## from `x`.
|
||||||
proc toU16*(x: int): int16 {.magic: "ToU16", noSideEffect.}
|
proc toU16*(x: int): int16 {.magic: "ToU16", noSideEffect.}
|
||||||
## treats `x` as unsigned and converts it to an ``int16`` by taking the last
|
## treats `x` as unsigned and converts it to an ``int16`` by taking the last
|
||||||
## 16 bits from `x`.
|
## 16 bits from `x`.
|
||||||
proc toU32*(x: int64): int32 {.magic: "ToU32", noSideEffect.}
|
proc toU32*(x: int64): int32 {.magic: "ToU32", noSideEffect.}
|
||||||
## treats `x` as unsigned and converts it to an ``int32`` by taking the
|
## treats `x` as unsigned and converts it to an ``int32`` by taking the
|
||||||
## last 32 bits from `x`.
|
## last 32 bits from `x`.
|
||||||
|
|
||||||
|
|
||||||
# integer calculations:
|
# integer calculations:
|
||||||
proc `+` *(x: int): int {.magic: "UnaryPlusI", noSideEffect.}
|
proc `+` *(x: int): int {.magic: "UnaryPlusI", noSideEffect.}
|
||||||
proc `+` *(x: int8): int8 {.magic: "UnaryPlusI", noSideEffect.}
|
proc `+` *(x: int8): int8 {.magic: "UnaryPlusI", noSideEffect.}
|
||||||
|
|
|
||||||
|
|
@ -472,17 +472,17 @@ proc Ze(a: int): int {.compilerproc.} =
|
||||||
proc Ze64(a: int64): int64 {.compilerproc.} =
|
proc Ze64(a: int64): int64 {.compilerproc.} =
|
||||||
result = a
|
result = a
|
||||||
|
|
||||||
proc toU8(a: int): int8 {.noStackFrame, compilerproc.} =
|
proc ToU8(a: int): int8 {.noStackFrame, compilerproc.} =
|
||||||
asm """
|
asm """
|
||||||
return `a`;
|
return `a`;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc toU16(a: int): int16 {.noStackFrame, compilerproc.} =
|
proc ToU16(a: int): int16 {.noStackFrame, compilerproc.} =
|
||||||
asm """
|
asm """
|
||||||
return `a`;
|
return `a`;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc toU32(a: int): int32 {.noStackFrame, compilerproc.} =
|
proc ToU32(a: int): int32 {.noStackFrame, compilerproc.} =
|
||||||
asm """
|
asm """
|
||||||
return `a`;
|
return `a`;
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ discard """
|
||||||
WARNING: false first asseertion from bar
|
WARNING: false first asseertion from bar
|
||||||
ERROR: false second assertion from bar
|
ERROR: false second assertion from bar
|
||||||
-1
|
-1
|
||||||
tests/run/tfailedassert.nim:27 false assertion from foo
|
tests/assert/tfailedassert.nim:27 false assertion from foo
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue