mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-04 06:28:38 +00:00
more fixes for dy(n)lib typo; fixes #15
This commit is contained in:
@@ -119,7 +119,7 @@ from a C function prototype with the ``dynlib`` pragma:
|
||||
# if defined(windows)
|
||||
# define iupdll "iup.dll"
|
||||
# elif defined(macosx)
|
||||
# define iupdll "libiup.dynlib"
|
||||
# define iupdll "libiup.dylib"
|
||||
# else
|
||||
# define iupdll "libiup.so"
|
||||
# endif
|
||||
@@ -133,7 +133,7 @@ Is translated to:
|
||||
when defined(windows):
|
||||
const iupdll* = "iup.dll"
|
||||
elif defined(macosx):
|
||||
const iupdll* = "libiup.dynlib"
|
||||
const iupdll* = "libiup.dylib"
|
||||
else:
|
||||
const iupdll* = "libiup.so"
|
||||
|
||||
|
||||
@@ -412,7 +412,7 @@ proc ipart(x: float): float = return x.trunc()
|
||||
proc fpart(x: float): float = return x - ipart(x)
|
||||
proc rfpart(x: float): float = return 1.0 - fpart(x)
|
||||
|
||||
proc drawLineAA(sur: PSurface, p1, p2: TPoint, color: TColor) =
|
||||
proc drawLineAA*(sur: PSurface, p1, p2: TPoint, color: TColor) =
|
||||
## Draws a anti-aliased line from ``p1`` to ``p2``, using Xiaolin Wu's
|
||||
## line algorithm
|
||||
var (x1, x2, y1, y2) = (p1.x.toFloat(), p2.x.toFloat(),
|
||||
|
||||
@@ -45,7 +45,8 @@ const
|
||||
DocumentFragmentNode* = 11
|
||||
|
||||
# Nodes which are childless - Not sure about AttributeNode
|
||||
childlessObjects = {DocumentNode, AttributeNode, TextNode, CDataSectionNode, ProcessingInstructionNode, CommentNode}
|
||||
childlessObjects = {DocumentNode, AttributeNode, TextNode,
|
||||
CDataSectionNode, ProcessingInstructionNode, CommentNode}
|
||||
# Illegal characters
|
||||
illegalChars = {'>', '<', '&', '"'}
|
||||
|
||||
@@ -73,7 +74,7 @@ type
|
||||
Element = object of Node
|
||||
FTagName: string # Read-only
|
||||
|
||||
PCharacterData = ref CharacterData
|
||||
PCharacterData* = ref CharacterData
|
||||
CharacterData = object of Node
|
||||
data*: string
|
||||
|
||||
@@ -109,10 +110,10 @@ type
|
||||
# DOMImplementation
|
||||
proc getDOM*(): PDOMImplementation =
|
||||
## Returns a DOMImplementation
|
||||
var DOMImpl: PDOMImplementation
|
||||
new(DOMImpl)
|
||||
DOMImpl.Features = @[(name: "core", version: "2.0"), (name: "core", version: "1.0"), (name: "XML", version: "2.0")]
|
||||
return DOMImpl
|
||||
new(result)
|
||||
result.Features = @[(name: "core", version: "2.0"),
|
||||
(name: "core", version: "1.0"),
|
||||
(name: "XML", version: "2.0")]
|
||||
|
||||
proc createDocument*(dom: PDOMImplementation, namespaceURI: string, qualifiedName: string): PDocument =
|
||||
## Creates an XML Document object of the specified type with its document element.
|
||||
|
||||
@@ -22741,144 +22741,144 @@ proc AnsiLowerBuff*(lpsz: LPSTR, cchLength: DWORD): DWORD{.stdcall,
|
||||
|
||||
# WinBase.h
|
||||
|
||||
proc FreeModule(h: HINST): WINBOOL =
|
||||
proc FreeModule*(h: HINST): WINBOOL =
|
||||
result = FreeLibrary(h)
|
||||
|
||||
proc MakeProcInstance(p, i: pointer): pointer =
|
||||
proc MakeProcInstance*(p, i: pointer): pointer =
|
||||
result = p
|
||||
|
||||
proc FreeProcInstance(p: pointer): pointer =
|
||||
proc FreeProcInstance*(p: pointer): pointer =
|
||||
result = p
|
||||
|
||||
proc GlobalDiscard(hglbMem: HGLOBAL): HGLOBAL =
|
||||
proc GlobalDiscard*(hglbMem: HGLOBAL): HGLOBAL =
|
||||
result = GlobalReAlloc(hglbMem, 0, GMEM_MOVEABLE)
|
||||
|
||||
proc LocalDiscard(hlocMem: HLOCAL): HLOCAL =
|
||||
proc LocalDiscard*(hlocMem: HLOCAL): HLOCAL =
|
||||
result = LocalReAlloc(hlocMem, 0, LMEM_MOVEABLE)
|
||||
|
||||
# WinGDI.h
|
||||
|
||||
proc GetGValue(rgb: int32): int8 =
|
||||
proc GetGValue*(rgb: int32): int8 =
|
||||
result = toU8(rgb shr 8'i32)
|
||||
proc RGB(r, g, b: int): COLORREF =
|
||||
proc RGB*(r, g, b: int): COLORREF =
|
||||
result = toU32(r) or (toU32(g) shl 8) or (toU32(b) shl 16)
|
||||
proc RGB(r, g, b: range[0 .. 255]): COLORREF =
|
||||
proc RGB*(r, g, b: range[0 .. 255]): COLORREF =
|
||||
result = r or g shl 8 or b shl 16
|
||||
|
||||
proc PALETTERGB(r, g, b: range[0..255]): COLORREF =
|
||||
proc PALETTERGB*(r, g, b: range[0..255]): COLORREF =
|
||||
result = 0x02000000 or RGB(r, g, b)
|
||||
|
||||
proc PALETTEINDEX(i: DWORD): COLORREF =
|
||||
proc PALETTEINDEX*(i: DWORD): COLORREF =
|
||||
result = COLORREF(0x01000000'i32 or i and 0xffff'i32)
|
||||
|
||||
|
||||
proc GetRValue(rgb: COLORREF): int8 =
|
||||
proc GetRValue*(rgb: COLORREF): int8 =
|
||||
result = toU8(rgb)
|
||||
|
||||
proc GetGValue(rgb: COLORREF): int8 =
|
||||
proc GetGValue*(rgb: COLORREF): int8 =
|
||||
result = toU8(rgb shr 8)
|
||||
|
||||
proc GetBValue(rgb: COLORREF): int8 =
|
||||
proc GetBValue*(rgb: COLORREF): int8 =
|
||||
result = toU8(rgb shr 16)
|
||||
|
||||
#
|
||||
|
||||
proc HIBYTE(w: int32): int8 =
|
||||
proc HIBYTE*(w: int32): int8 =
|
||||
result = toU8(w shr 8'i32 and 0x000000FF'i32)
|
||||
|
||||
proc HIWORD(L: int32): int16 =
|
||||
proc HIWORD*(L: int32): int16 =
|
||||
result = toU16(L shr 16'i32 and 0x0000FFFF'i32)
|
||||
|
||||
proc LOBYTE(w: int32): int8 =
|
||||
proc LOBYTE*(w: int32): int8 =
|
||||
result = toU8(w)
|
||||
|
||||
proc LOWORD(L: int32): int16 =
|
||||
proc LOWORD*(L: int32): int16 =
|
||||
result = toU16(L)
|
||||
|
||||
proc MAKELONG(a, b: int32): LONG =
|
||||
proc MAKELONG*(a, b: int32): LONG =
|
||||
result = a and 0x0000ffff'i32 or b shl 16'i32
|
||||
|
||||
proc MAKEWORD(a, b: int32): int16 =
|
||||
proc MAKEWORD*(a, b: int32): int16 =
|
||||
result = toU16(a and 0xff'i32) or toU16(b shl 8'i32)
|
||||
|
||||
proc SEXT_HIWORD(L: int32): int32 =
|
||||
proc SEXT_HIWORD*(L: int32): int32 =
|
||||
# return type might be wrong
|
||||
result = HIWORD(L)
|
||||
|
||||
proc ZEXT_HIWORD(L: int32): int32 =
|
||||
proc ZEXT_HIWORD*(L: int32): int32 =
|
||||
# return type might be wrong
|
||||
result = ze(HIWORD(L))
|
||||
|
||||
proc SEXT_LOWORD(L: int32): int32 =
|
||||
proc SEXT_LOWORD*(L: int32): int32 =
|
||||
result = LOWORD(L)
|
||||
|
||||
proc INDEXTOOVERLAYMASK(i: int32): int32 =
|
||||
proc INDEXTOOVERLAYMASK*(i: int32): int32 =
|
||||
# return type might be wrong
|
||||
result = i shl 8'i32
|
||||
|
||||
proc INDEXTOSTATEIMAGEMASK(i: int32): int32 =
|
||||
proc INDEXTOSTATEIMAGEMASK*(i: int32): int32 =
|
||||
# return type might be wrong
|
||||
result = i shl 12'i32
|
||||
|
||||
proc MAKEINTATOM(i: int32): LPTSTR =
|
||||
proc MAKEINTATOM*(i: int32): LPTSTR =
|
||||
result = cast[LPTSTR](cast[ULONG_PTR](ToU16(i)))
|
||||
|
||||
proc MAKELANGID(p, s: int32): int32 =
|
||||
proc MAKELANGID*(p, s: int32): int32 =
|
||||
# return type might be wrong
|
||||
result = toU16(s) shl 10'i16 or toU16(p)
|
||||
|
||||
proc PRIMARYLANGID(lgid: int32): int16 =
|
||||
proc PRIMARYLANGID*(lgid: int32): int16 =
|
||||
result = toU16(lgid) and 0x000003FF'i16
|
||||
|
||||
proc SUBLANGID(lgid: int32): int32 =
|
||||
proc SUBLANGID*(lgid: int32): int32 =
|
||||
# return type might be wrong
|
||||
result = toU16(lgid) shr 10'i16
|
||||
|
||||
proc LANGIDFROMLCID(lcid: int32): int16 =
|
||||
proc LANGIDFROMLCID*(lcid: int32): int16 =
|
||||
result = toU16(lcid)
|
||||
|
||||
proc SORTIDFROMLCID(lcid: int32): int16 =
|
||||
proc SORTIDFROMLCID*(lcid: int32): int16 =
|
||||
result = toU16((lcid and 0x000FFFFF'i32) shr 16'i32)
|
||||
|
||||
proc MAKELCID(lgid, srtid: int32): DWORD =
|
||||
proc MAKELCID*(lgid, srtid: int32): DWORD =
|
||||
result = toU32(srtid shl 16'i32 or lgid and 0xffff'i32)
|
||||
|
||||
proc MAKELPARAM(L, h: int32): LPARAM =
|
||||
proc MAKELPARAM*(L, h: int32): LPARAM =
|
||||
result = LPARAM(MAKELONG(L, h))
|
||||
|
||||
proc MAKELRESULT(L, h: int32): LRESULT =
|
||||
proc MAKELRESULT*(L, h: int32): LRESULT =
|
||||
result = LRESULT(MAKELONG(L, h))
|
||||
|
||||
proc MAKEROP4(fore, back: int32): DWORD =
|
||||
proc MAKEROP4*(fore, back: int32): DWORD =
|
||||
result = back shl 8'i32 and 0xFF000000'i32 or fore
|
||||
|
||||
proc MAKEWPARAM(L, h: int32): WPARAM =
|
||||
proc MAKEWPARAM*(L, h: int32): WPARAM =
|
||||
result = WPARAM(MAKELONG(L, h))
|
||||
|
||||
proc GET_X_LPARAM(lp: Windows.LParam): int32 =
|
||||
proc GET_X_LPARAM*(lp: Windows.LParam): int32 =
|
||||
result = int16(LOWORD(lp))
|
||||
|
||||
proc GET_Y_LPARAM(lp: Windows.LParam): int32 =
|
||||
proc GET_Y_LPARAM*(lp: Windows.LParam): int32 =
|
||||
result = int16(HIWORD(lp))
|
||||
|
||||
proc UNICODE_NULL(): WCHAR =
|
||||
proc UNICODE_NULL*(): WCHAR =
|
||||
result = 0'i16
|
||||
|
||||
|
||||
|
||||
proc GetFirstChild(h: HWND): HWND =
|
||||
proc GetFirstChild*(h: HWND): HWND =
|
||||
result = GetTopWindow(h)
|
||||
|
||||
proc GetNextSibling(h: HWND): HWND =
|
||||
proc GetNextSibling*(h: HWND): HWND =
|
||||
result = GetWindow(h, GW_HWNDNEXT)
|
||||
|
||||
proc GetWindowID(h: HWND): int32 =
|
||||
proc GetWindowID*(h: HWND): int32 =
|
||||
result = GetDlgCtrlID(h)
|
||||
|
||||
proc SubclassWindow(h: HWND, p: LONG): LONG =
|
||||
proc SubclassWindow*(h: HWND, p: LONG): LONG =
|
||||
result = SetWindowLong(h, GWL_WNDPROC, p)
|
||||
|
||||
proc GET_WM_COMMAND_CMD(w, L: int32): int32 =
|
||||
proc GET_WM_COMMAND_CMD*(w, L: int32): int32 =
|
||||
# return type might be wrong
|
||||
result = HIWORD(w)
|
||||
|
||||
|
||||
@@ -49,11 +49,12 @@
|
||||
#
|
||||
|
||||
when defined(windows):
|
||||
const
|
||||
LIB_CAIRO* = "libcairo-2.dll"
|
||||
const LIB_CAIRO* = "libcairo-2.dll"
|
||||
elif defined(macosx):
|
||||
const LIB_CAIRO* = "libcairo.dylib"
|
||||
else:
|
||||
const
|
||||
LIB_CAIRO* = "libcairo.so"
|
||||
const LIB_CAIRO* = "libcairo.so"
|
||||
|
||||
type
|
||||
PByte = cstring
|
||||
TStatus* = enum
|
||||
|
||||
@@ -5,6 +5,9 @@ import
|
||||
when defined(windows):
|
||||
const
|
||||
lib = "libatk-1.0-0.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
lib = "libatk-1.0.dylib"
|
||||
else:
|
||||
const
|
||||
lib = "libatk-1.0.so"
|
||||
|
||||
@@ -5,7 +5,7 @@ import
|
||||
when defined(win32):
|
||||
const
|
||||
lib = "libgdk-win32-2.0-0.dll"
|
||||
elif defined(darwin):
|
||||
elif defined(macosx):
|
||||
# linklib gtk-x11-2.0
|
||||
# linklib gdk-x11-2.0
|
||||
# linklib pango-1.0.0
|
||||
@@ -14,7 +14,7 @@ elif defined(darwin):
|
||||
# linklib gdk_pixbuf-2.0.0
|
||||
# linklib atk-1.0.0
|
||||
const
|
||||
lib = "gdk-x11-2.0"
|
||||
lib = "libgdk-x11-2.0.dylib"
|
||||
else:
|
||||
const
|
||||
lib = "libgdk-x11-2.0.so(|.0)"
|
||||
|
||||
@@ -5,9 +5,9 @@ import
|
||||
when defined(win32):
|
||||
const
|
||||
pixbuflib = "libgdk_pixbuf-2.0-0.dll"
|
||||
elif defined(darwin):
|
||||
elif defined(macosx):
|
||||
const
|
||||
pixbuflib = "gdk_pixbuf-2.0.0"
|
||||
pixbuflib = "libgdk_pixbuf-2.0.0.dylib"
|
||||
# linklib gtk-x11-2.0
|
||||
# linklib gdk-x11-2.0
|
||||
# linklib pango-1.0.0
|
||||
|
||||
@@ -5,6 +5,9 @@ import
|
||||
when defined(WIN32):
|
||||
const
|
||||
GLExtLib = "libgdkglext-win32-1.0-0.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
GLExtLib = "libgdkglext-x11-1.0.dylib"
|
||||
else:
|
||||
const
|
||||
GLExtLib = "libgdkglext-x11-1.0.so"
|
||||
|
||||
@@ -4,6 +4,11 @@ when defined(windows):
|
||||
gliblib = "libglib-2.0-0.dll"
|
||||
gmodulelib = "libgmodule-2.0-0.dll"
|
||||
gobjectlib = "libgobject-2.0-0.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
gliblib = "libglib-2.0.dylib"
|
||||
gmodulelib = "libgmodule-2.0.dylib"
|
||||
gobjectlib = "libgobject-2.0.dylib"
|
||||
else:
|
||||
const
|
||||
gliblib = "libglib-2.0.so(|.0)"
|
||||
|
||||
@@ -5,9 +5,9 @@ import
|
||||
when defined(win32):
|
||||
const
|
||||
lib = "libgtk-win32-2.0-0.dll"
|
||||
elif defined(darwin):
|
||||
elif defined(macosx):
|
||||
const
|
||||
lib = "gtk-x11-2.0"
|
||||
lib = "libgtk-x11-2.0.dylib"
|
||||
# linklib gtk-x11-2.0
|
||||
# linklib gdk-x11-2.0
|
||||
# linklib pango-1.0.0
|
||||
|
||||
@@ -2,8 +2,15 @@
|
||||
import
|
||||
Glib2, Gdk2, gtk2, GdkGLExt
|
||||
|
||||
const
|
||||
GLExtLib* = if defined(WIN32): "libgtkglext-win32-1.0-0.dll" else: "libgtkglext-x11-1.0.so"
|
||||
when defined(windows):
|
||||
const
|
||||
GLExtLib* = "libgtkglext-win32-1.0-0.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
GLExtLib* = "libgtkglext-x11-1.0.dylib"
|
||||
else:
|
||||
const
|
||||
GLExtLib* = "libgtkglext-x11-1.0.so"
|
||||
|
||||
const
|
||||
HEADER_GTKGLEXT_MAJOR_VERSION* = 1
|
||||
|
||||
@@ -3,9 +3,11 @@ import
|
||||
gtk2, glib2, atk, pango, gdk2pixbuf, gdk2
|
||||
|
||||
when defined(windows):
|
||||
{.define: WINDOWING_WIN32.}
|
||||
const
|
||||
htmllib = "libgtkhtml-win32-2.0-0.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
htmllib = "libgtkhtml-2.dylib"
|
||||
else:
|
||||
const
|
||||
htmllib = "libgtkhtml-2.so"
|
||||
|
||||
@@ -5,6 +5,9 @@ import
|
||||
when defined(win32):
|
||||
const
|
||||
LibGladeLib = "libglade-2.0-0.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
LibGladeLib = "libglade-2.0.dylib"
|
||||
else:
|
||||
const
|
||||
LibGladeLib = "libglade-2.0.so"
|
||||
|
||||
@@ -5,6 +5,9 @@ import
|
||||
when defined(win32):
|
||||
const
|
||||
lib* = "libpango-1.0-0.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
lib* = "libpango-1.0.dylib"
|
||||
else:
|
||||
const
|
||||
lib* = "libpango-1.0.so.0"
|
||||
|
||||
37
rod/ast.nim
37
rod/ast.nim
@@ -61,7 +61,8 @@ type
|
||||
# (used for macros)
|
||||
nkNilLit, # the nil literal
|
||||
# end of atoms
|
||||
nkDotCall, # used to temporarily flag a nkCall node; this is used
|
||||
nkDotCall, # used to temporarily flag a nkCall node;
|
||||
# this is used
|
||||
# for transforming ``s.len`` to ``len(s)``
|
||||
nkCommand, # a call like ``p 2, 4`` without parenthesis
|
||||
nkCall, # a call like p(x, y) or an operation like +(a, b)
|
||||
@@ -115,7 +116,8 @@ type
|
||||
# end of expressions
|
||||
|
||||
nkAsgn, # a = b
|
||||
nkFastAsgn, # internal node for a fast ``a = b`` (no string copy)
|
||||
nkFastAsgn, # internal node for a fast ``a = b``
|
||||
# (no string copy)
|
||||
nkGenericParams, # generic parameters
|
||||
nkFormalParams, # formal parameters
|
||||
nkOfInherit, # inherited from symbol
|
||||
@@ -128,7 +130,8 @@ type
|
||||
nkTemplateDef, # a template
|
||||
nkIteratorDef, # an iterator
|
||||
|
||||
nkOfBranch, # used inside case statements for (cond, action)-pairs
|
||||
nkOfBranch, # used inside case statements
|
||||
# for (cond, action)-pairs
|
||||
nkElifBranch, # used in if statements
|
||||
nkExceptBranch, # an except section
|
||||
nkElse, # an else part
|
||||
@@ -296,7 +299,8 @@ type
|
||||
skForVar, # a for loop variable
|
||||
skLabel, # a label (for block statement)
|
||||
skStub # symbol is a stub and not yet loaded from the ROD
|
||||
# file (it is loaded on demand, which may mean: never)
|
||||
# file (it is loaded on demand, which may
|
||||
# mean: never)
|
||||
TSymKinds* = set[TSymKind]
|
||||
|
||||
TMagic* = enum # symbols that require compiler magic:
|
||||
@@ -312,10 +316,12 @@ type
|
||||
mMinF64, mMaxF64, mAddU, mSubU, mMulU,
|
||||
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,
|
||||
mEqProc, mEqUntracedRef, mLePtr, mLtPtr, mEqCString, mXor, mUnaryMinusI,
|
||||
mUnaryMinusI64, mAbsI, mAbsI64, mNot, mUnaryPlusI, mBitnotI, mUnaryPlusI64,
|
||||
mUnaryMinusI64, mAbsI, mAbsI64, mNot,
|
||||
mUnaryPlusI, mBitnotI, mUnaryPlusI64,
|
||||
mBitnotI64, mUnaryPlusF64, mUnaryMinusF64, mAbsF64, mZe8ToI, mZe8ToI64,
|
||||
mZe16ToI, mZe16ToI64, mZe32ToI64, mZeIToI64, mToU8, mToU16, mToU32,
|
||||
mToFloat, mToBiggestFloat, mToInt, mToBiggestInt, mCharToStr, mBoolToStr,
|
||||
@@ -521,7 +527,8 @@ const
|
||||
ConcreteTypes*: TTypeKinds = { # types of the expr that may occur in::
|
||||
# var x = expr
|
||||
tyBool, tyChar, tyEnum, tyArray, tyObject,
|
||||
tySet, tyTuple, tyRange, tyPtr, tyRef, tyVar, tySequence, tyProc, tyPointer,
|
||||
tySet, tyTuple, tyRange, tyPtr, tyRef, tyVar, tySequence, tyProc,
|
||||
tyPointer,
|
||||
tyOpenArray, tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128}
|
||||
|
||||
ConstantDataTypes*: TTypeKinds = {tyArray, tySet, tyTuple}
|
||||
@@ -609,7 +616,8 @@ type
|
||||
const
|
||||
InitIntSetSize* = 8 # must be a power of two!
|
||||
TrunkShift* = 9
|
||||
BitsPerTrunk* = 1 shl TrunkShift # needs to be a power of 2 and divisible by 64
|
||||
BitsPerTrunk* = 1 shl TrunkShift # needs to be a power of 2 and
|
||||
# divisible by 64
|
||||
TrunkMask* = BitsPerTrunk - 1
|
||||
IntsPerTrunk* = BitsPerTrunk div (sizeof(TBitScalar) * 8)
|
||||
IntShift* = 5 + ord(sizeof(TBitScalar) == 8) # 5 or 6, depending on int width
|
||||
@@ -718,7 +726,8 @@ proc discardSons(father: PNode) =
|
||||
|
||||
proc newNode(kind: TNodeKind): PNode =
|
||||
new(result)
|
||||
result.kind = kind #result.info := UnknownLineInfo(); inlined:
|
||||
result.kind = kind
|
||||
#result.info = UnknownLineInfo() inlined:
|
||||
result.info.fileIndex = int32(- 1)
|
||||
result.info.col = int16(- 1)
|
||||
result.info.line = int16(- 1)
|
||||
@@ -773,8 +782,9 @@ proc NewType(kind: TTypeKind, owner: PSym): PType =
|
||||
result.align = 2 # default alignment
|
||||
result.id = getID()
|
||||
if debugIds:
|
||||
RegisterId(result) #if result.id < 2000 then
|
||||
# MessageOut(typeKindToStr[kind] +{&} ' has id: ' +{&} toString(result.id));
|
||||
RegisterId(result)
|
||||
#if result.id < 2000 then
|
||||
# MessageOut(typeKindToStr[kind] & ' has id: ' & toString(result.id))
|
||||
|
||||
proc assignType(dest, src: PType) =
|
||||
dest.kind = src.kind
|
||||
@@ -827,8 +837,9 @@ proc NewSym(symKind: TSymKind, Name: PIdent, owner: PSym): PSym =
|
||||
result.offset = - 1
|
||||
result.id = getID()
|
||||
if debugIds:
|
||||
RegisterId(result) #if result.id < 2000 then
|
||||
# MessageOut(name.s +{&} ' has id: ' +{&} toString(result.id));
|
||||
RegisterId(result)
|
||||
#if result.id < 2000:
|
||||
# MessageOut(name.s & " has id: " & toString(result.id))
|
||||
|
||||
proc initStrTable(x: var TStrTable) =
|
||||
x.counter = 0
|
||||
|
||||
@@ -38,42 +38,34 @@ type
|
||||
efNone, efLValue
|
||||
TEvalFlags = set[TEvalFlag]
|
||||
|
||||
|
||||
proc newStackFrame*(): PStackFrame
|
||||
proc pushStackFrame*(c: PEvalContext, t: PStackFrame)
|
||||
proc popStackFrame*(c: PEvalContext)
|
||||
proc newEvalContext*(module: PSym, filename: string,
|
||||
optEval: bool): PEvalContext
|
||||
proc eval*(c: PEvalContext, n: PNode): PNode
|
||||
# eval never returns nil! This simplifies the code a lot and
|
||||
# makes it faster too.
|
||||
proc evalConstExpr*(module: PSym, e: PNode): PNode
|
||||
proc evalPass*(): TPass
|
||||
# implementation
|
||||
|
||||
const
|
||||
evalMaxIterations = 500_000 # max iterations of all loops
|
||||
evalMaxRecDepth = 10_000 # max recursion depth for evaluation
|
||||
evalMaxRecDepth = 10_000 # max recursion depth for evaluation
|
||||
|
||||
# Much better: use a timeout! -> Wether code compiles depends on the machine
|
||||
# the compiler runs on then! Bad idea!
|
||||
|
||||
proc newStackFrame(): PStackFrame =
|
||||
proc newStackFrame*(): PStackFrame =
|
||||
new(result)
|
||||
initIdNodeTable(result.mapping)
|
||||
result.params = @[]
|
||||
|
||||
proc newEvalContext(module: PSym, filename: string,
|
||||
optEval: bool): PEvalContext =
|
||||
proc newEvalContext*(module: PSym, filename: string,
|
||||
optEval: bool): PEvalContext =
|
||||
new(result)
|
||||
result.module = module
|
||||
result.optEval = optEval
|
||||
|
||||
proc pushStackFrame(c: PEvalContext, t: PStackFrame) =
|
||||
proc pushStackFrame*(c: PEvalContext, t: PStackFrame) {.inline.} =
|
||||
t.next = c.tos
|
||||
c.tos = t
|
||||
|
||||
proc popStackFrame(c: PEvalContext) =
|
||||
proc popStackFrame*(c: PEvalContext) {.inline.} =
|
||||
if (c.tos == nil): InternalError("popStackFrame")
|
||||
c.tos = c.tos.next
|
||||
|
||||
@@ -83,10 +75,19 @@ proc stackTraceAux(x: PStackFrame) =
|
||||
if x != nil:
|
||||
stackTraceAux(x.next)
|
||||
var info = if x.call != nil: x.call.info else: UnknownLineInfo()
|
||||
MsgWriteln(`%`("file: $1, line: $2",
|
||||
[toFilename(info), $(toLineNumber(info))]))
|
||||
# we now use the same format as in system/except.nim
|
||||
var s = toFilename(info)
|
||||
var line = toLineNumber(info)
|
||||
if line > 0:
|
||||
add(s, '(')
|
||||
add(s, $line)
|
||||
add(s, ')')
|
||||
if x.prc != nil:
|
||||
for k in 1..max(1, 25-s.len): add(s, ' ')
|
||||
add(s, x.prc.name.s)
|
||||
MsgWriteln(s)
|
||||
|
||||
proc stackTrace(c: PEvalContext, n: PNode, msg: TMsgKind, arg: string = "") =
|
||||
proc stackTrace(c: PEvalContext, n: PNode, msg: TMsgKind, arg = "") =
|
||||
MsgWriteln("stack trace: (most recent call last)")
|
||||
stackTraceAux(c.tos)
|
||||
Fatal(n.info, msg, arg)
|
||||
@@ -253,7 +254,6 @@ proc evalVar(c: PEvalContext, n: PNode): PNode =
|
||||
assert(a.sons[0].kind == nkSym)
|
||||
var v = a.sons[0].sym
|
||||
if a.sons[2].kind != nkEmpty:
|
||||
#if a.sons[2].kind == nkNone: echo "Yep"
|
||||
result = evalAux(c, a.sons[2], {})
|
||||
if isSpecial(result): return
|
||||
else:
|
||||
@@ -373,6 +373,7 @@ proc evalAsgn(c: PEvalContext, n: PNode): PNode =
|
||||
discardSons(x)
|
||||
for i in countup(0, sonsLen(result) - 1): addSon(x, result.sons[i])
|
||||
result = emptyNode
|
||||
assert result.kind == nkEmpty
|
||||
|
||||
proc evalSwap(c: PEvalContext, n: PNode): PNode =
|
||||
result = evalAux(c, n.sons[0], {efLValue})
|
||||
@@ -918,7 +919,7 @@ proc evalMagicOrCall(c: PEvalContext, n: PNode): PNode =
|
||||
result = evalAux(c, n.sons[2], {efLValue})
|
||||
if result.kind == nkExceptBranch: return
|
||||
var a = result
|
||||
if (k < 0) or (k > ord(high(TNodeKind))):
|
||||
if k < 0 or k > ord(high(TNodeKind)):
|
||||
internalError(n.info, "request to create a NimNode with invalid kind")
|
||||
result = newNodeI(TNodeKind(int(k)),
|
||||
if a.kind == nkNilLit: n.info else: a.info)
|
||||
@@ -1015,8 +1016,7 @@ proc evalAux(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
|
||||
case n.kind # atoms:
|
||||
of nkEmpty: result = n
|
||||
of nkSym: result = evalSym(c, n, flags)
|
||||
of nkType..pred(nkNilLit): result = copyNode(n)
|
||||
of nkNilLit: result = n # end of atoms
|
||||
of nkType..nkNilLit: result = copyNode(n) # end of atoms
|
||||
of nkCall, nkHiddenCallConv, nkMacroStmt, nkCommand, nkCallStrLit:
|
||||
result = evalMagicOrCall(c, n)
|
||||
of nkCurly, nkBracket, nkRange:
|
||||
@@ -1089,7 +1089,7 @@ proc evalConstExpr(module: PSym, e: PNode): PNode =
|
||||
s.call = e
|
||||
pushStackFrame(p, s)
|
||||
result = eval(p, e)
|
||||
if (result != nil) and (result.kind == nkExceptBranch): result = nil
|
||||
if result != nil and result.kind == nkExceptBranch: result = nil
|
||||
popStackFrame(p)
|
||||
|
||||
proc myOpen(module: PSym, filename: string): PPassContext =
|
||||
@@ -1100,7 +1100,7 @@ proc myOpen(module: PSym, filename: string): PPassContext =
|
||||
proc myProcess(c: PPassContext, n: PNode): PNode =
|
||||
result = eval(PEvalContext(c), n)
|
||||
|
||||
proc evalPass(): TPass =
|
||||
proc evalPass*(): TPass =
|
||||
initPass(result)
|
||||
result.open = myOpen
|
||||
result.close = myProcess
|
||||
|
||||
Reference in New Issue
Block a user