added system.appType magic
This commit is contained in:
parent
de27098546
commit
cdf03b06b9
11 changed files with 49 additions and 14 deletions
|
|
@ -56,6 +56,7 @@ extension ext
|
||||||
separator sep
|
separator sep
|
||||||
column col, column col is preferred, inconsistent right
|
column col, column col is preferred, inconsistent right
|
||||||
now
|
now
|
||||||
|
application app
|
||||||
configuration cfg
|
configuration cfg
|
||||||
message msg
|
message msg
|
||||||
argument arg
|
argument arg
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,19 @@ The generated files that Nimrod produces all go into a subdirectory called
|
||||||
``nimcache`` in your project directory. This makes it easy to delete all
|
``nimcache`` in your project directory. This makes it easy to delete all
|
||||||
generated files.
|
generated files.
|
||||||
|
|
||||||
However, the generated C code is not platform independant. C code generated for
|
However, the generated C code is not platform independent. C code generated for
|
||||||
Linux does not compile on Windows, for instance. The comment on top of the
|
Linux does not compile on Windows, for instance. The comment on top of the
|
||||||
C file lists the OS, CPU and CC the file has been compiled for.
|
C file lists the OS, CPU and CC the file has been compiled for.
|
||||||
|
|
||||||
|
..
|
||||||
|
DLL generation
|
||||||
|
==============
|
||||||
|
|
||||||
|
Nimrod supports the generation of DLLs. However, there must be only one
|
||||||
|
instance of the GC per address space. This instance is contained in
|
||||||
|
``nimrtl.dll``. This means that every generated Nimrod DLL depends
|
||||||
|
on ``nimrtl.dll``.
|
||||||
|
|
||||||
|
|
||||||
Additional Features
|
Additional Features
|
||||||
===================
|
===================
|
||||||
|
|
|
||||||
|
|
@ -813,11 +813,15 @@ const
|
||||||
hostOS* {.magic: "HostOS"}: string = ""
|
hostOS* {.magic: "HostOS"}: string = ""
|
||||||
## a string that describes the host operating system. Possible values:
|
## a string that describes the host operating system. Possible values:
|
||||||
## "windows", "macosx", "linux", "netbsd", "freebsd", "openbsd", "solaris",
|
## "windows", "macosx", "linux", "netbsd", "freebsd", "openbsd", "solaris",
|
||||||
## "aix"
|
## "aix".
|
||||||
|
|
||||||
hostCPU* {.magic: "HostCPU"}: string = ""
|
hostCPU* {.magic: "HostCPU"}: string = ""
|
||||||
## a string that describes the host CPU. Possible values:
|
## a string that describes the host CPU. Possible values:
|
||||||
## "i386", "alpha", "powerpc", "sparc", "amd64", "mips", "arm"
|
## "i386", "alpha", "powerpc", "sparc", "amd64", "mips", "arm".
|
||||||
|
|
||||||
|
appType* {.magic: "AppType"}: string = ""
|
||||||
|
## a string that describes the application type. Possible values:
|
||||||
|
## "console", "gui", "lib".
|
||||||
|
|
||||||
proc toFloat*(i: int): float {.
|
proc toFloat*(i: int): float {.
|
||||||
magic: "ToFloat", noSideEffect, importc: "toFloat".}
|
magic: "ToFloat", noSideEffect, importc: "toFloat".}
|
||||||
|
|
@ -1570,7 +1574,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
||||||
result = n.sons[n.len]
|
result = n.sons[n.len]
|
||||||
|
|
||||||
include "system/systhread"
|
include "system/systhread"
|
||||||
include "system/mm"
|
include "system/mmdisp"
|
||||||
include "system/sysstr"
|
include "system/sysstr"
|
||||||
include "system/assign"
|
include "system/assign"
|
||||||
include "system/repr"
|
include "system/repr"
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,12 @@ when defined(boehmgc):
|
||||||
|
|
||||||
include "system/cellsets"
|
include "system/cellsets"
|
||||||
elif defined(nogc):
|
elif defined(nogc):
|
||||||
|
# Even though we don't want the GC, we cannot simply use C's memory manager
|
||||||
|
# because Nimrod's runtime wants ``realloc`` to zero out the additional
|
||||||
|
# space which C's ``realloc`` does not. And we cannot get the old size of an
|
||||||
|
# object, because C does not support this operation... Even though every
|
||||||
|
# possible implementation has to have a way to determine the object's size.
|
||||||
|
# C just sucks.
|
||||||
include "system/alloc"
|
include "system/alloc"
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
|
|
@ -308,7 +308,8 @@ type
|
||||||
mShrI, mShlI, mBitandI, mBitorI, mBitxorI, mMinI, mMaxI,
|
mShrI, mShlI, mBitandI, mBitorI, mBitxorI, mMinI, mMaxI,
|
||||||
mShrI64, mShlI64, mBitandI64, mBitorI64, mBitxorI64, mMinI64, mMaxI64,
|
mShrI64, mShlI64, mBitandI64, mBitorI64, mBitxorI64, mMinI64, mMaxI64,
|
||||||
mMinF64, mMaxF64, mAddU, mSubU, mMulU,
|
mMinF64, mMaxF64, mAddU, mSubU, mMulU,
|
||||||
mDivU, mModU, mAddU64, mSubU64, mMulU64, mDivU64, mModU64, mEqI, mLeI, mLtI,
|
mDivU, mModU, mAddU64, mSubU64, mMulU64, mDivU64, mModU64, mEqI, mLeI,
|
||||||
|
mLtI,
|
||||||
mEqI64, mLeI64, mLtI64, mEqF64, mLeF64, mLtF64, mLeU, mLtU, mLeU64, mLtU64,
|
mEqI64, mLeI64, mLtI64, mEqF64, mLeF64, mLtF64, mLeU, mLtU, mLeU64, mLtU64,
|
||||||
mEqEnum, mLeEnum, mLtEnum, mEqCh, mLeCh, mLtCh, mEqB, mLeB, mLtB, mEqRef,
|
mEqEnum, mLeEnum, mLtEnum, mEqCh, mLeCh, mLtCh, mEqB, mLeB, mLtB, mEqRef,
|
||||||
mEqProc, mEqUntracedRef, mLePtr, mLtPtr, mEqCString, mXor, mUnaryMinusI,
|
mEqProc, mEqUntracedRef, mLePtr, mLtPtr, mEqCString, mXor, mUnaryMinusI,
|
||||||
|
|
@ -326,7 +327,8 @@ type
|
||||||
mInt64, mFloat, mFloat32, mFloat64, mBool, mChar, mString, mCstring,
|
mInt64, mFloat, mFloat32, mFloat64, mBool, mChar, mString, mCstring,
|
||||||
mPointer, mEmptySet, mIntSetBaseType, mNil, mExpr, mStmt, mTypeDesc,
|
mPointer, mEmptySet, mIntSetBaseType, mNil, mExpr, mStmt, mTypeDesc,
|
||||||
mIsMainModule, mCompileDate, mCompileTime, mNimrodVersion, mNimrodMajor,
|
mIsMainModule, mCompileDate, mCompileTime, mNimrodVersion, mNimrodMajor,
|
||||||
mNimrodMinor, mNimrodPatch, mCpuEndian, mHostOS, mHostCPU, mNaN, mInf,
|
mNimrodMinor, mNimrodPatch, mCpuEndian, mHostOS, mHostCPU, mAppType,
|
||||||
|
mNaN, mInf,
|
||||||
mNegInf, mNLen, mNChild, mNSetChild, mNAdd, mNAddMultiple, mNDel, mNKind,
|
mNegInf, mNLen, mNChild, mNSetChild, mNAdd, mNAddMultiple, mNDel, mNKind,
|
||||||
mNIntVal, mNFloatVal, mNSymbol, mNIdent, mNGetType, mNStrVal, mNSetIntVal,
|
mNIntVal, mNFloatVal, mNSymbol, mNIdent, mNGetType, mNStrVal, mNSetIntVal,
|
||||||
mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal,
|
mNSetFloatVal, mNSetSymbol, mNSetIdent, mNSetType, mNSetStrVal,
|
||||||
|
|
|
||||||
4
rod/c2nim/c2nim.cfg
Executable file
4
rod/c2nim/c2nim.cfg
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Use the modules of the compiler
|
||||||
|
|
||||||
|
path: "$nimrod/rod"
|
||||||
|
|
||||||
|
|
@ -170,7 +170,7 @@ in the future as it cannot work for backends that do not generate C code.
|
||||||
that can be used for the same purpose.
|
that can be used for the same purpose.
|
||||||
|
|
||||||
c2nim does not do any name mangling by default. However the
|
c2nim does not do any name mangling by default. However the
|
||||||
``#prefix`` and ``#suffix`` directives can be used to strip prefixes and
|
``#prefix`` and ``#suffix`` directives can be used to strip prefixes and
|
||||||
suffixes from the identifiers in the C code:
|
suffixes from the identifiers in the C code:
|
||||||
|
|
||||||
.. code-block:: C
|
.. code-block:: C
|
||||||
|
|
|
||||||
|
|
@ -156,14 +156,14 @@ proc splitSwitch(switch: string, cmd, arg: var string, pass: TCmdLinePass,
|
||||||
info: TLineInfo) =
|
info: TLineInfo) =
|
||||||
cmd = ""
|
cmd = ""
|
||||||
var i = 0
|
var i = 0
|
||||||
if (i < len(switch) + 0) and (switch[i] == '-'): inc(i)
|
if i < len(switch) and switch[i] == '-': inc(i)
|
||||||
if (i < len(switch) + 0) and (switch[i] == '-'): inc(i)
|
if i < len(switch) and switch[i] == '-': inc(i)
|
||||||
while i < len(switch) + 0:
|
while i < len(switch):
|
||||||
case switch[i]
|
case switch[i]
|
||||||
of 'a'..'z', 'A'..'Z', '0'..'9', '_', '.': add(cmd, switch[i])
|
of 'a'..'z', 'A'..'Z', '0'..'9', '_', '.': add(cmd, switch[i])
|
||||||
else: break
|
else: break
|
||||||
inc(i)
|
inc(i)
|
||||||
if i >= len(switch) + 0: arg = ""
|
if i >= len(switch): arg = ""
|
||||||
elif switch[i] in {':', '=', '['}: arg = copy(switch, i + 1)
|
elif switch[i] in {':', '=', '['}: arg = copy(switch, i + 1)
|
||||||
else: InvalidCmdLineOption(pass, switch, info)
|
else: InvalidCmdLineOption(pass, switch, info)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,9 @@
|
||||||
# Note that the left and right pointers are not needed for leafs.
|
# Note that the left and right pointers are not needed for leafs.
|
||||||
# Leafs have relatively high memory overhead (~30 bytes on a 32
|
# Leafs have relatively high memory overhead (~30 bytes on a 32
|
||||||
# bit machines) and we produce many of them. This is why we cache and
|
# bit machines) and we produce many of them. This is why we cache and
|
||||||
# share leafs accross different rope trees.
|
# share leaves accross different rope trees.
|
||||||
# To cache them they are inserted in another tree, a splay tree for best
|
# To cache them they are inserted in another tree, a splay tree for best
|
||||||
# performance. But for the caching tree we use the leafs' left and right
|
# performance. But for the caching tree we use the leaves' left and right
|
||||||
# pointers.
|
# pointers.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -274,6 +274,14 @@ proc magicCall(m: PSym, n: PNode): PNode =
|
||||||
b = nil
|
b = nil
|
||||||
result = evalOp(s.magic, n, a, b, c)
|
result = evalOp(s.magic, n, a, b, c)
|
||||||
|
|
||||||
|
proc getAppType(n: PNode): PNode =
|
||||||
|
if gGlobalOptions.contains(optGenDynLib):
|
||||||
|
result = newStrNodeT("lib", n)
|
||||||
|
elif gGlobalOptions.contains(optGenGuiApp):
|
||||||
|
result = newStrNodeT("gui", n)
|
||||||
|
else:
|
||||||
|
result = newStrNodeT("console", n)
|
||||||
|
|
||||||
proc getConstExpr(m: PSym, n: PNode): PNode =
|
proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
result = nil
|
result = nil
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
@ -293,6 +301,7 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
of mCpuEndian: result = newIntNodeT(ord(CPU[targetCPU].endian), n)
|
of mCpuEndian: result = newIntNodeT(ord(CPU[targetCPU].endian), n)
|
||||||
of mHostOS: result = newStrNodeT(toLower(platform.OS[targetOS].name), n)
|
of mHostOS: result = newStrNodeT(toLower(platform.OS[targetOS].name), n)
|
||||||
of mHostCPU: result = newStrNodeT(toLower(platform.CPU[targetCPU].name), n)
|
of mHostCPU: result = newStrNodeT(toLower(platform.CPU[targetCPU].name), n)
|
||||||
|
of mAppType: result = getAppType(n)
|
||||||
of mNaN: result = newFloatNodeT(NaN, n)
|
of mNaN: result = newFloatNodeT(NaN, n)
|
||||||
of mInf: result = newFloatNodeT(Inf, n)
|
of mInf: result = newFloatNodeT(Inf, n)
|
||||||
of mNegInf: result = newFloatNodeT(NegInf, n)
|
of mNegInf: result = newFloatNodeT(NegInf, n)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ proc execCode(code: string): string =
|
||||||
else:
|
else:
|
||||||
raise newException(EIO, "Unable to open file")
|
raise newException(EIO, "Unable to open file")
|
||||||
result = osproc.execProcess(
|
result = osproc.execProcess(
|
||||||
"nimrod run --verbosity:0 --hint[Conf]:off temp.nim")
|
"nimrod c -r --verbosity:0 --hint[Conf]:off temp.nim")
|
||||||
|
|
||||||
var shiftPressed = False
|
var shiftPressed = False
|
||||||
var w: gtk2.PWindow
|
var w: gtk2.PWindow
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue