resolved conflict; added missing files
This commit is contained in:
commit
3f35e2d39e
14 changed files with 657 additions and 327 deletions
|
|
@ -674,7 +674,7 @@ proc genProcHeader(m: BModule, prc: PSym): PRope =
|
||||||
|
|
||||||
# ------------------ type info generation -------------------------------------
|
# ------------------ type info generation -------------------------------------
|
||||||
|
|
||||||
proc genTypeInfo(m: BModule, typ: PType): PRope
|
proc genTypeInfo(m: BModule, t: PType): PRope
|
||||||
proc getNimNode(m: BModule): PRope =
|
proc getNimNode(m: BModule): PRope =
|
||||||
result = ropef("$1[$2]", [m.typeNodesName, toRope(m.typeNodes)])
|
result = ropef("$1[$2]", [m.typeNodesName, toRope(m.typeNodes)])
|
||||||
inc(m.typeNodes)
|
inc(m.typeNodes)
|
||||||
|
|
@ -692,7 +692,7 @@ proc isObjLackingTypeField(typ: PType): bool {.inline.} =
|
||||||
result = (typ.kind == tyObject) and ((tfFinal in typ.flags) and
|
result = (typ.kind == tyObject) and ((tfFinal in typ.flags) and
|
||||||
(typ.sons[0] == nil) or isPureObject(typ))
|
(typ.sons[0] == nil) or isPureObject(typ))
|
||||||
|
|
||||||
proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
|
proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
|
||||||
var nimtypeKind: int
|
var nimtypeKind: int
|
||||||
#allocMemTI(m, typ, name)
|
#allocMemTI(m, typ, name)
|
||||||
if isObjLackingTypeField(typ):
|
if isObjLackingTypeField(typ):
|
||||||
|
|
@ -901,21 +901,21 @@ type
|
||||||
|
|
||||||
include ccgtrav
|
include ccgtrav
|
||||||
|
|
||||||
proc genTypeInfo(m: BModule, typ: PType): PRope =
|
proc genTypeInfo(m: BModule, t: PType): PRope =
|
||||||
var t = getUniqueType(typ)
|
var t = getUniqueType(t)
|
||||||
result = ropef("NTI$1", [toRope(t.id)])
|
result = ropef("NTI$1", [toRope(t.id)])
|
||||||
let owner = typ.skipTypes(typedescPtrs).owner.getModule
|
if ContainsOrIncl(m.typeInfoMarker, t.id):
|
||||||
|
return con("(&".toRope, result, ")".toRope)
|
||||||
|
let owner = t.skipTypes(typedescPtrs).owner.getModule
|
||||||
if owner != m.module:
|
if owner != m.module:
|
||||||
# make sure the type info is created in the owner module
|
# make sure the type info is created in the owner module
|
||||||
discard genTypeInfo(owner.bmod, typ)
|
discard genTypeInfo(owner.bmod, t)
|
||||||
# refenrece the type info as extern here
|
# reference the type info as extern here
|
||||||
discard cgsym(m, "TNimType")
|
discard cgsym(m, "TNimType")
|
||||||
discard cgsym(m, "TNimNode")
|
discard cgsym(m, "TNimNode")
|
||||||
appf(m.s[cfsVars], "extern TNimType $1; /* $2 */$n",
|
appf(m.s[cfsVars], "extern TNimType $1; /* $2 */$n",
|
||||||
[result, toRope(typeToString(t))])
|
[result, toRope(typeToString(t))])
|
||||||
return con("(&".toRope, result, ")".toRope)
|
return con("(&".toRope, result, ")".toRope)
|
||||||
if ContainsOrIncl(m.typeInfoMarker, t.id):
|
|
||||||
return con("(&".toRope, result, ")".toRope)
|
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyEmpty: result = toRope"0"
|
of tyEmpty: result = toRope"0"
|
||||||
of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar:
|
of tyPointer, tyBool, tyChar, tyCString, tyString, tyInt..tyUInt64, tyVar:
|
||||||
|
|
|
||||||
|
|
@ -1031,7 +1031,7 @@ proc genInitCode(m: BModule) =
|
||||||
var procname = CStringLit(m.initProc, prc, m.module.name.s)
|
var procname = CStringLit(m.initProc, prc, m.module.name.s)
|
||||||
app(prc, initFrame(m.initProc, procname, m.module.info.quotedFilename))
|
app(prc, initFrame(m.initProc, procname, m.module.info.quotedFilename))
|
||||||
else:
|
else:
|
||||||
app(prc, ~"\tvolatile TFrame F; F.len = 0;$N")
|
app(prc, ~"\tTFrame F; F.len = 0;$N")
|
||||||
|
|
||||||
app(prc, genSectionStart(cpsInit))
|
app(prc, genSectionStart(cpsInit))
|
||||||
app(prc, m.preInitProc.s(cpsInit))
|
app(prc, m.preInitProc.s(cpsInit))
|
||||||
|
|
|
||||||
346
compiler/guards.nim
Normal file
346
compiler/guards.nim
Normal file
|
|
@ -0,0 +1,346 @@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# The Nimrod Compiler
|
||||||
|
# (c) Copyright 2013 Andreas Rumpf
|
||||||
|
#
|
||||||
|
# See the file "copying.txt", included in this
|
||||||
|
# distribution, for details about the copyright.
|
||||||
|
#
|
||||||
|
|
||||||
|
## This module implements the 'implies' relation for guards.
|
||||||
|
|
||||||
|
import ast, astalgo, msgs, magicsys, nimsets, trees, types, renderer
|
||||||
|
|
||||||
|
const
|
||||||
|
someEq = {mEqI, mEqI64, mEqF64, mEqEnum, mEqCh, mEqB, mEqRef, mEqProc,
|
||||||
|
mEqUntracedRef, mEqStr, mEqSet, mEqCString}
|
||||||
|
|
||||||
|
# set excluded here as the semantics are vastly different:
|
||||||
|
someLe = {mLeI, mLeI64, mLeF64, mLeU, mLeU64, mLeEnum,
|
||||||
|
mLeCh, mLeB, mLePtr, mLeStr}
|
||||||
|
someLt = {mLtI, mLtI64, mLtF64, mLtU, mLtU64, mLtEnum,
|
||||||
|
mLtCh, mLtB, mLtPtr, mLtStr}
|
||||||
|
|
||||||
|
someLen = {mLengthOpenArray, mLengthStr, mLengthArray, mLengthSeq}
|
||||||
|
|
||||||
|
someIn = {mInRange, mInSet}
|
||||||
|
|
||||||
|
proc isValue(n: PNode): bool = n.kind in {nkCharLit..nkNilLit}
|
||||||
|
proc isLocation(n: PNode): bool = not n.isValue
|
||||||
|
#n.kind in {nkSym, nkBracketExpr, nkDerefExpr, nkHiddenDeref, nkDotExpr}
|
||||||
|
|
||||||
|
proc isLet(n: PNode): bool =
|
||||||
|
if n.kind == nkSym:
|
||||||
|
# XXX allow skResult, skVar here if not re-bound
|
||||||
|
if n.sym.kind in {skLet, skTemp, skForVar}:
|
||||||
|
result = true
|
||||||
|
elif n.sym.kind == skParam and skipTypes(n.sym.typ,
|
||||||
|
abstractInst).kind != tyVar:
|
||||||
|
result = true
|
||||||
|
|
||||||
|
proc isLetLocation(m: PNode): bool =
|
||||||
|
var n = m
|
||||||
|
while true:
|
||||||
|
case n.kind
|
||||||
|
of nkDotExpr, nkCheckedFieldExpr, nkObjUpConv, nkObjDownConv:
|
||||||
|
n = n.sons[0]
|
||||||
|
of nkBracketExpr:
|
||||||
|
if isConstExpr(n.sons[1]) or isLet(n.sons[1]):
|
||||||
|
n = n.sons[0]
|
||||||
|
else: return
|
||||||
|
of nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
||||||
|
n = n.sons[1]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
result = n.isLet
|
||||||
|
|
||||||
|
proc neg(n: PNode): PNode =
|
||||||
|
if n.getMagic == mNot:
|
||||||
|
result = n.sons[1]
|
||||||
|
else:
|
||||||
|
result = newNodeI(nkCall, n.info, 2)
|
||||||
|
result.sons[0] = newSymNode(getSysMagic("not", mNot))
|
||||||
|
result.sons[1] = n
|
||||||
|
|
||||||
|
proc usefulFact(n: PNode): PNode =
|
||||||
|
case n.getMagic
|
||||||
|
of someEq+someLe+someLt:
|
||||||
|
if isLetLocation(n.sons[1]) or n.len == 3 and isLetLocation(n.sons[2]):
|
||||||
|
# XXX algebraic simplifications! 'i-1 < a.len' --> 'i < a.len+1'
|
||||||
|
result = n
|
||||||
|
of someIn, mIsNil:
|
||||||
|
if isLetLocation(n.sons[1]):
|
||||||
|
result = n
|
||||||
|
of mAnd:
|
||||||
|
let
|
||||||
|
a = usefulFact(n.sons[1])
|
||||||
|
b = usefulFact(n.sons[2])
|
||||||
|
if a != nil and b != nil:
|
||||||
|
result = newNodeI(nkCall, n.info, 3)
|
||||||
|
result.sons[0] = newSymNode(getSysMagic("and", mAnd))
|
||||||
|
result.sons[1] = a
|
||||||
|
result.sons[2] = b
|
||||||
|
elif a != nil:
|
||||||
|
result = a
|
||||||
|
elif b != nil:
|
||||||
|
result = b
|
||||||
|
of mNot:
|
||||||
|
case n.sons[1].getMagic
|
||||||
|
of mNot:
|
||||||
|
# normalize 'not (not a)' into 'a':
|
||||||
|
result = usefulFact(n.sons[1].sons[1])
|
||||||
|
of mOr:
|
||||||
|
# not (a or b) --> not a and not b
|
||||||
|
let n = n.sons[1]
|
||||||
|
let
|
||||||
|
a = usefulFact(n.sons[1])
|
||||||
|
b = usefulFact(n.sons[2])
|
||||||
|
if a != nil and b != nil:
|
||||||
|
result = newNodeI(nkCall, n.info, 3)
|
||||||
|
result.sons[0] = newSymNode(getSysMagic("and", mAnd))
|
||||||
|
result.sons[1] = a.neg
|
||||||
|
result.sons[2] = b.neg
|
||||||
|
else:
|
||||||
|
let a = usefulFact(n.sons[1])
|
||||||
|
if a != nil: result = n
|
||||||
|
of mOr:
|
||||||
|
# 'or' sucks! (p.isNil or q.isNil) --> hard to do anything
|
||||||
|
# with that knowledge...
|
||||||
|
# DeMorgan helps a little though:
|
||||||
|
# not a or not b --> not (a and b)
|
||||||
|
# (x == 3) or (y == 2) ---> not ( not (x==3) and not (y == 2))
|
||||||
|
# not (x != 3 and y != 2)
|
||||||
|
let
|
||||||
|
a = usefulFact(n.sons[1])
|
||||||
|
b = usefulFact(n.sons[2])
|
||||||
|
if a != nil and b != nil:
|
||||||
|
result = newNodeI(nkCall, n.info, 3)
|
||||||
|
result.sons[0] = newSymNode(getSysMagic("and", mAnd))
|
||||||
|
result.sons[1] = a.neg
|
||||||
|
result.sons[2] = b.neg
|
||||||
|
result = result.neg
|
||||||
|
elif n.kind == nkSym and n.sym.kind == skLet:
|
||||||
|
# consider:
|
||||||
|
# let a = 2 < x
|
||||||
|
# if a:
|
||||||
|
# ...
|
||||||
|
# We make can easily replace 'a' by '2 < x' here:
|
||||||
|
result = usefulFact(n.sym.ast)
|
||||||
|
elif n.kind == nkStmtListExpr:
|
||||||
|
result = usefulFact(n.lastSon)
|
||||||
|
|
||||||
|
type
|
||||||
|
TModel* = seq[PNode] # the "knowledge base"
|
||||||
|
|
||||||
|
proc addFact*(m: var TModel, n: PNode) =
|
||||||
|
let n = usefulFact(n)
|
||||||
|
if n != nil: m.add n
|
||||||
|
|
||||||
|
proc addFactNeg*(m: var TModel, n: PNode) = addFact(m, n.neg)
|
||||||
|
|
||||||
|
proc sameTree(a, b: PNode): bool =
|
||||||
|
result = false
|
||||||
|
if a == b:
|
||||||
|
result = true
|
||||||
|
elif (a != nil) and (b != nil) and (a.kind == b.kind):
|
||||||
|
case a.kind
|
||||||
|
of nkSym: result = a.sym == b.sym
|
||||||
|
of nkIdent: result = a.ident.id == b.ident.id
|
||||||
|
of nkCharLit..nkInt64Lit: result = a.intVal == b.intVal
|
||||||
|
of nkFloatLit..nkFloat64Lit: result = a.floatVal == b.floatVal
|
||||||
|
of nkStrLit..nkTripleStrLit: result = a.strVal == b.strVal
|
||||||
|
of nkType: result = a.typ == b.typ
|
||||||
|
of nkEmpty, nkNilLit: result = true
|
||||||
|
else:
|
||||||
|
if sonsLen(a) == sonsLen(b):
|
||||||
|
for i in countup(0, sonsLen(a) - 1):
|
||||||
|
if not sameTree(a.sons[i], b.sons[i]): return
|
||||||
|
result = true
|
||||||
|
|
||||||
|
proc valuesUnequal(a, b: PNode): bool =
|
||||||
|
if a.isValue and b.isValue:
|
||||||
|
result = not SameValue(a, b)
|
||||||
|
|
||||||
|
type
|
||||||
|
TImplication* = enum
|
||||||
|
impUnknown, impNo, impYes
|
||||||
|
|
||||||
|
proc impliesEq(fact, eq: PNode): TImplication =
|
||||||
|
let (loc, val) = if isLocation(eq.sons[1]): (1, 2) else: (2, 1)
|
||||||
|
|
||||||
|
case fact.sons[0].sym.magic
|
||||||
|
of someEq:
|
||||||
|
if sameTree(fact.sons[1], eq.sons[loc]):
|
||||||
|
# this is not correct; consider: a == b; a == 1 --> unknown!
|
||||||
|
if sameTree(fact.sons[2], eq.sons[val]): result = impYes
|
||||||
|
elif valuesUnequal(fact.sons[2], eq.sons[val]): result = impNo
|
||||||
|
elif sameTree(fact.sons[2], eq.sons[loc]):
|
||||||
|
if sameTree(fact.sons[1], eq.sons[val]): result = impYes
|
||||||
|
elif valuesUnequal(fact.sons[1], eq.sons[val]): result = impNo
|
||||||
|
of mInSet:
|
||||||
|
if sameTree(fact.sons[1], eq.sons[loc]) and isValue(eq.sons[val]):
|
||||||
|
if inSet(fact.sons[2], eq.sons[val]): result = impYes
|
||||||
|
else: result = impNo
|
||||||
|
of mIsNil:
|
||||||
|
if sameTree(fact.sons[1], eq.sons[loc]):
|
||||||
|
if eq.sons[val].kind == nkNilLit:
|
||||||
|
result = impYes
|
||||||
|
of mNot, mOr, mAnd: internalError(eq.info, "impliesEq")
|
||||||
|
else: nil
|
||||||
|
|
||||||
|
proc impliesIsNil(fact, eq: PNode): TImplication =
|
||||||
|
case fact.sons[0].sym.magic
|
||||||
|
of someEq:
|
||||||
|
if sameTree(fact.sons[1], eq.sons[1]):
|
||||||
|
if fact.sons[2].kind == nkNilLit: result = impYes
|
||||||
|
elif sameTree(fact.sons[2], eq.sons[1]):
|
||||||
|
if fact.sons[1].kind == nkNilLit: result = impYes
|
||||||
|
of mIsNil:
|
||||||
|
if sameTree(fact.sons[1], eq.sons[1]):
|
||||||
|
result = impYes
|
||||||
|
of mNot, mOr, mAnd: internalError(eq.info, "impliesIsNil")
|
||||||
|
else: nil
|
||||||
|
|
||||||
|
proc pred(n: PNode): PNode =
|
||||||
|
if n.kind in {nkCharLit..nkUInt64Lit} and n.intVal != low(biggestInt):
|
||||||
|
result = copyNode(n)
|
||||||
|
dec result.intVal
|
||||||
|
else:
|
||||||
|
result = n
|
||||||
|
|
||||||
|
proc impliesGe(fact, x, c: PNode): TImplication =
|
||||||
|
InternalAssert isLocation(x)
|
||||||
|
case fact.sons[0].sym.magic
|
||||||
|
of someEq:
|
||||||
|
if sameTree(fact.sons[1], x):
|
||||||
|
if isValue(fact.sons[2]) and isValue(c):
|
||||||
|
# fact: x = 4; question x >= 56? --> true iff 4 >= 56
|
||||||
|
if leValue(c, fact.sons[2]): result = impYes
|
||||||
|
else: result = impNo
|
||||||
|
elif sameTree(fact.sons[2], x):
|
||||||
|
if isValue(fact.sons[1]) and isValue(c):
|
||||||
|
if leValue(c, fact.sons[1]): result = impYes
|
||||||
|
else: result = impNo
|
||||||
|
of someLt:
|
||||||
|
if sameTree(fact.sons[1], x):
|
||||||
|
if isValue(fact.sons[2]) and isValue(c):
|
||||||
|
# fact: x < 4; question N <= x? --> false iff N <= 4
|
||||||
|
if leValue(fact.sons[2], c): result = impNo
|
||||||
|
# fact: x < 4; question 2 <= x? --> we don't know
|
||||||
|
elif sameTree(fact.sons[2], x):
|
||||||
|
# fact: 3 < x; question: N-1 < x ? --> true iff N-1 <= 3
|
||||||
|
if isValue(fact.sons[1]) and isValue(c):
|
||||||
|
if leValue(c.pred, fact.sons[1]): result = impYes
|
||||||
|
of someLe:
|
||||||
|
if sameTree(fact.sons[1], x):
|
||||||
|
if isValue(fact.sons[2]) and isValue(c):
|
||||||
|
# fact: x <= 4; question x >= 56? --> false iff 4 <= 56
|
||||||
|
if leValue(fact.sons[2], c): result = impNo
|
||||||
|
# fact: x <= 4; question x >= 2? --> we don't know
|
||||||
|
elif sameTree(fact.sons[2], x):
|
||||||
|
# fact: 3 <= x; question: x >= 2 ? --> true iff 2 <= 3
|
||||||
|
if isValue(fact.sons[1]) and isValue(c):
|
||||||
|
if leValue(c, fact.sons[1]): result = impYes
|
||||||
|
of mNot, mOr, mAnd: internalError(x.info, "impliesGe")
|
||||||
|
else: nil
|
||||||
|
|
||||||
|
proc impliesLe(fact, x, c: PNode): TImplication =
|
||||||
|
if not isLocation(x):
|
||||||
|
return impliesGe(fact, c, x)
|
||||||
|
case fact.sons[0].sym.magic
|
||||||
|
of someEq:
|
||||||
|
if sameTree(fact.sons[1], x):
|
||||||
|
if isValue(fact.sons[2]) and isValue(c):
|
||||||
|
# fact: x = 4; question x <= 56? --> true iff 4 <= 56
|
||||||
|
if leValue(fact.sons[2], c): result = impYes
|
||||||
|
else: result = impNo
|
||||||
|
elif sameTree(fact.sons[2], x):
|
||||||
|
if isValue(fact.sons[1]) and isValue(c):
|
||||||
|
if leValue(fact.sons[1], c): result = impYes
|
||||||
|
else: result = impNo
|
||||||
|
of someLt:
|
||||||
|
if sameTree(fact.sons[1], x):
|
||||||
|
if isValue(fact.sons[2]) and isValue(c):
|
||||||
|
# fact: x < 4; question x <= N? --> true iff N-1 <= 4
|
||||||
|
if leValue(fact.sons[2], c.pred): result = impYes
|
||||||
|
# fact: x < 4; question x <= 2? --> we don't know
|
||||||
|
elif sameTree(fact.sons[2], x):
|
||||||
|
# fact: 3 < x; question: x <= 1 ? --> false iff 1 <= 3
|
||||||
|
if isValue(fact.sons[1]) and isValue(c):
|
||||||
|
if leValue(c, fact.sons[1]): result = impNo
|
||||||
|
|
||||||
|
of someLe:
|
||||||
|
if sameTree(fact.sons[1], x):
|
||||||
|
if isValue(fact.sons[2]) and isValue(c):
|
||||||
|
# fact: x <= 4; question x <= 56? --> true iff 4 <= 56
|
||||||
|
if leValue(fact.sons[2], c): result = impYes
|
||||||
|
# fact: x <= 4; question x <= 2? --> we don't know
|
||||||
|
|
||||||
|
elif sameTree(fact.sons[2], x):
|
||||||
|
# fact: 3 <= x; question: x <= 2 ? --> false iff 2 < 3
|
||||||
|
if isValue(fact.sons[1]) and isValue(c):
|
||||||
|
if leValue(c, fact.sons[1].pred): result = impNo
|
||||||
|
|
||||||
|
of mNot, mOr, mAnd: internalError(x.info, "impliesLe")
|
||||||
|
else: nil
|
||||||
|
|
||||||
|
proc impliesLt(fact, x, c: PNode): TImplication =
|
||||||
|
# x < 3 same as x <= 2:
|
||||||
|
let p = c.pred
|
||||||
|
if p != c:
|
||||||
|
result = impliesLe(fact, x, p)
|
||||||
|
else:
|
||||||
|
# 4 < x same as 3 <= x
|
||||||
|
let q = x.pred
|
||||||
|
if q != x:
|
||||||
|
result = impliesLe(fact, q, c)
|
||||||
|
|
||||||
|
proc factImplies(fact, prop: PNode, isNegation: bool): TImplication =
|
||||||
|
case fact.getMagic
|
||||||
|
of mNot:
|
||||||
|
case factImplies(fact.sons[1], prop, not isNegation)
|
||||||
|
of impUnknown: return impUnknown
|
||||||
|
of impNo: return impYes
|
||||||
|
of impYes: return impNo
|
||||||
|
of mAnd:
|
||||||
|
if not isNegation:
|
||||||
|
result = factImplies(fact.sons[1], prop, isNegation)
|
||||||
|
if result != impUnknown: return result
|
||||||
|
return factImplies(fact.sons[2], prop, isNegation)
|
||||||
|
else:
|
||||||
|
# careful! not (a and b) means not a or not b:
|
||||||
|
# a or b --> both need to imply 'prop'
|
||||||
|
let a = factImplies(fact.sons[1], prop, isNegation)
|
||||||
|
let b = factImplies(fact.sons[2], prop, isNegation)
|
||||||
|
if a == b: return a
|
||||||
|
return impUnknown
|
||||||
|
else: discard
|
||||||
|
|
||||||
|
case prop.sons[0].sym.magic
|
||||||
|
of mNot:
|
||||||
|
case fact.factImplies(prop.sons[1], isNegation)
|
||||||
|
of impUnknown: result = impUnknown
|
||||||
|
of impNo: result = impYes
|
||||||
|
of impYes: result = impNo
|
||||||
|
of mIsNil:
|
||||||
|
result = impliesIsNil(fact, prop)
|
||||||
|
of someEq:
|
||||||
|
result = impliesEq(fact, prop)
|
||||||
|
of someLe:
|
||||||
|
result = impliesLe(fact, prop.sons[1], prop.sons[2])
|
||||||
|
of someLt:
|
||||||
|
result = impliesLt(fact, prop.sons[1], prop.sons[2])
|
||||||
|
else:
|
||||||
|
internalError(prop.info, "invalid proposition")
|
||||||
|
|
||||||
|
proc doesImply*(facts: TModel, prop: PNode): TImplication =
|
||||||
|
assert prop.kind in nkCallKinds
|
||||||
|
for f in facts:
|
||||||
|
result = f.factImplies(prop, false)
|
||||||
|
if result != impUnknown: return
|
||||||
|
|
||||||
|
proc impliesNotNil*(facts: TModel, arg: PNode): TImplication =
|
||||||
|
var x = newNodeI(nkCall, arg.info, 2)
|
||||||
|
x.sons[0] = newSymNode(getSysMagic("isNil", mIsNil))
|
||||||
|
x.sons[1] = arg
|
||||||
|
result = doesImply(facts, x.neg)
|
||||||
|
|
@ -93,10 +93,10 @@ hint[LineTooLong]=off
|
||||||
cc = clang
|
cc = clang
|
||||||
tlsEmulation:on
|
tlsEmulation:on
|
||||||
gcc.options.always = "-w -fasm-blocks"
|
gcc.options.always = "-w -fasm-blocks"
|
||||||
gpp.options.always = "-w -fasm-blocks"
|
gpp.options.always = "-w -fasm-blocks -fpermissive"
|
||||||
@else:
|
@else:
|
||||||
gcc.options.always = "-w"
|
gcc.options.always = "-w"
|
||||||
gpp.options.always = "-w"
|
gpp.options.always = "-w -fpermissive"
|
||||||
@end
|
@end
|
||||||
|
|
||||||
gcc.options.speed = "-O3 -fno-strict-aliasing"
|
gcc.options.speed = "-O3 -fno-strict-aliasing"
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ Advanced commands:
|
||||||
//check checks the project for syntax and semantic
|
//check checks the project for syntax and semantic
|
||||||
//idetools compiler support for IDEs: possible options:
|
//idetools compiler support for IDEs: possible options:
|
||||||
--track:FILE,LINE,COL track a file/cursor position
|
--track:FILE,LINE,COL track a file/cursor position
|
||||||
|
--trackDirty:DIRTY_FILE,ORIG_FILE,LINE,COL
|
||||||
|
track a file, currently not saved to disk
|
||||||
--suggest suggest all possible symbols at position
|
--suggest suggest all possible symbols at position
|
||||||
--def list all possible definitions at position
|
--def list all possible definitions at position
|
||||||
--context list possible invokation context
|
--context list possible invokation context
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,7 @@ proc lispRepr*(n: PNimrodNode): string {.compileTime.} =
|
||||||
|
|
||||||
add(result, ")")
|
add(result, ")")
|
||||||
|
|
||||||
macro dumpTree*(s: stmt): stmt = echo s.treeRepr
|
macro dumpTree*(s: stmt): stmt {.immediate.} = echo s.treeRepr
|
||||||
## Accepts a block of nimrod code and prints the parsed abstract syntax
|
## Accepts a block of nimrod code and prints the parsed abstract syntax
|
||||||
## tree using the `toTree` function. Printing is done *at compile time*.
|
## tree using the `toTree` function. Printing is done *at compile time*.
|
||||||
##
|
##
|
||||||
|
|
@ -398,16 +398,16 @@ macro dumpTree*(s: stmt): stmt = echo s.treeRepr
|
||||||
## tree and to discover what kind of nodes must be created to represent
|
## tree and to discover what kind of nodes must be created to represent
|
||||||
## a certain expression/statement.
|
## a certain expression/statement.
|
||||||
|
|
||||||
macro dumpLisp*(s: stmt): stmt = echo s.lispRepr
|
macro dumpLisp*(s: stmt): stmt {.immediate.} = echo s.lispRepr
|
||||||
## Accepts a block of nimrod code and prints the parsed abstract syntax
|
## Accepts a block of nimrod code and prints the parsed abstract syntax
|
||||||
## tree using the `toLisp` function. Printing is done *at compile time*.
|
## tree using the `toLisp` function. Printing is done *at compile time*.
|
||||||
##
|
##
|
||||||
## See `dumpTree`.
|
## See `dumpTree`.
|
||||||
|
|
||||||
macro dumpTreeImm*(s: stmt): stmt {.immediate.} = echo s.treeRepr
|
macro dumpTreeImm*(s: stmt): stmt {.immediate, deprecated.} = echo s.treeRepr
|
||||||
## The ``immediate`` version of `dumpTree`.
|
## The ``immediate`` version of `dumpTree`.
|
||||||
|
|
||||||
macro dumpLispImm*(s: stmt): stmt {.immediate.} = echo s.lispRepr
|
macro dumpLispImm*(s: stmt): stmt {.immediate, deprecated.} = echo s.lispRepr
|
||||||
## The ``immediate`` version of `dumpLisp`.
|
## The ``immediate`` version of `dumpLisp`.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -437,11 +437,11 @@ struct TFrame {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define nimfr(proc, file) \
|
#define nimfr(proc, file) \
|
||||||
volatile TFrame F; \
|
TFrame F; \
|
||||||
F.procname = proc; F.filename = file; F.line = 0; F.len = 0; nimFrame(&F);
|
F.procname = proc; F.filename = file; F.line = 0; F.len = 0; nimFrame(&F);
|
||||||
|
|
||||||
#define nimfrs(proc, file, slots, length) \
|
#define nimfrs(proc, file, slots, length) \
|
||||||
volatile struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; TVarSlot s[slots];} F; \
|
struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; TVarSlot s[slots];} F; \
|
||||||
F.procname = proc; F.filename = file; F.line = 0; F.len = length; nimFrame((TFrame*)&F);
|
F.procname = proc; F.filename = file; F.line = 0; F.len = length; nimFrame((TFrame*)&F);
|
||||||
|
|
||||||
#define nimln(n, file) \
|
#define nimln(n, file) \
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ import
|
||||||
|
|
||||||
proc pushstring*(L: PState, s: string)
|
proc pushstring*(L: PState, s: string)
|
||||||
# compatibilty macros
|
# compatibilty macros
|
||||||
proc getn*(L: PState, n: int): int
|
proc getn*(L: PState, n: cint): cint
|
||||||
# calls lua_objlen
|
# calls lua_objlen
|
||||||
proc setn*(L: PState, t, n: int)
|
proc setn*(L: PState, t, n: cint)
|
||||||
# does nothing!
|
# does nothing!
|
||||||
type
|
type
|
||||||
Treg*{.final.} = object
|
Treg*{.final.} = object
|
||||||
|
|
@ -37,58 +37,45 @@ type
|
||||||
|
|
||||||
Preg* = ptr Treg
|
Preg* = ptr Treg
|
||||||
|
|
||||||
proc openlib*(L: PState, libname: cstring, lr: Preg, nup: int){.cdecl,
|
|
||||||
dynlib: lua.LIB_NAME, importc: "luaL_openlib".}
|
{.push callConv: cdecl, dynlib: lua.LIB_NAME.}
|
||||||
proc register*(L: PState, libname: cstring, lr: Preg){.cdecl,
|
{.push importc: "luaL_$1".}
|
||||||
dynlib: lua.LIB_NAME, importc: "luaL_register".}
|
|
||||||
proc getmetafield*(L: PState, obj: int, e: cstring): int{.cdecl,
|
proc openlib*(L: PState, libname: cstring, lr: Preg, nup: cint)
|
||||||
dynlib: lua.LIB_NAME, importc: "luaL_getmetafield".}
|
proc register*(L: PState, libname: cstring, lr: Preg)
|
||||||
proc callmeta*(L: PState, obj: int, e: cstring): int{.cdecl,
|
|
||||||
dynlib: LIB_NAME, importc: "luaL_callmeta".}
|
proc getmetafield*(L: PState, obj: cint, e: cstring): cint
|
||||||
proc typerror*(L: PState, narg: int, tname: cstring): int{.cdecl,
|
proc callmeta*(L: PState, obj: cint, e: cstring): cint
|
||||||
dynlib: LIB_NAME, importc: "luaL_typerror".}
|
proc typerror*(L: PState, narg: cint, tname: cstring): cint
|
||||||
proc argerror*(L: PState, numarg: int, extramsg: cstring): int{.cdecl,
|
proc argerror*(L: PState, numarg: cint, extramsg: cstring): cint
|
||||||
dynlib: LIB_NAME, importc: "luaL_argerror".}
|
proc checklstring*(L: PState, numArg: cint, len: ptr int): cstring
|
||||||
proc checklstring*(L: PState, numArg: int, len: ptr int): cstring{.cdecl,
|
proc optlstring*(L: PState, numArg: cint, def: cstring, len: ptr cint): cstring
|
||||||
dynlib: LIB_NAME, importc: "luaL_checklstring".}
|
proc checknumber*(L: PState, numArg: cint): Number
|
||||||
proc optlstring*(L: PState, numArg: int, def: cstring, len: ptr int): cstring{.
|
proc optnumber*(L: PState, nArg: cint, def: Number): Number
|
||||||
cdecl, dynlib: LIB_NAME, importc: "luaL_optlstring".}
|
proc checkinteger*(L: PState, numArg: cint): Integer
|
||||||
proc checknumber*(L: PState, numArg: int): Number{.cdecl,
|
proc optinteger*(L: PState, nArg: cint, def: Integer): Integer
|
||||||
dynlib: LIB_NAME, importc: "luaL_checknumber".}
|
proc checkstack*(L: PState, sz: cint, msg: cstring)
|
||||||
proc optnumber*(L: PState, nArg: int, def: Number): Number{.cdecl,
|
proc checktype*(L: PState, narg, t: cint)
|
||||||
dynlib: LIB_NAME, importc: "luaL_optnumber".}
|
|
||||||
proc checkinteger*(L: PState, numArg: int): Integer{.cdecl,
|
proc checkany*(L: PState, narg: cint)
|
||||||
dynlib: LIB_NAME, importc: "luaL_checkinteger".}
|
proc newmetatable*(L: PState, tname: cstring): cint
|
||||||
proc optinteger*(L: PState, nArg: int, def: Integer): Integer{.
|
|
||||||
cdecl, dynlib: LIB_NAME, importc: "luaL_optinteger".}
|
proc checkudata*(L: PState, ud: cint, tname: cstring): Pointer
|
||||||
proc checkstack*(L: PState, sz: int, msg: cstring){.cdecl,
|
proc where*(L: PState, lvl: cint)
|
||||||
dynlib: LIB_NAME, importc: "luaL_checkstack".}
|
proc error*(L: PState, fmt: cstring): cint{.varargs.}
|
||||||
proc checktype*(L: PState, narg, t: int){.cdecl, dynlib: LIB_NAME,
|
proc checkoption*(L: PState, narg: cint, def: cstring, lst: cstringArray): cint
|
||||||
importc: "luaL_checktype".}
|
|
||||||
proc checkany*(L: PState, narg: int){.cdecl, dynlib: LIB_NAME,
|
proc unref*(L: PState, t, theref: cint)
|
||||||
importc: "luaL_checkany".}
|
proc loadfile*(L: PState, filename: cstring): cint
|
||||||
proc newmetatable*(L: PState, tname: cstring): int{.cdecl,
|
proc loadbuffer*(L: PState, buff: cstring, size: cint, name: cstring): cint
|
||||||
dynlib: LIB_NAME, importc: "luaL_newmetatable".}
|
proc loadstring*(L: PState, s: cstring): cint
|
||||||
proc checkudata*(L: PState, ud: int, tname: cstring): Pointer{.cdecl,
|
proc newstate*(): PState
|
||||||
dynlib: LIB_NAME, importc: "luaL_checkudata".}
|
|
||||||
proc where*(L: PState, lvl: int){.cdecl, dynlib: LIB_NAME,
|
{.pop.}
|
||||||
importc: "luaL_where".}
|
proc reference*(L: PState, t: cint): cint{.importc: "luaL_ref".}
|
||||||
proc error*(L: PState, fmt: cstring): int{.cdecl, varargs,
|
|
||||||
dynlib: LIB_NAME, importc: "luaL_error".}
|
{.pop.}
|
||||||
proc checkoption*(L: PState, narg: int, def: cstring, lst: cstringArray): int{.
|
|
||||||
cdecl, dynlib: LIB_NAME, importc: "luaL_checkoption".}
|
|
||||||
proc reference*(L: PState, t: int): int{.cdecl, dynlib: LIB_NAME,
|
|
||||||
importc: "luaL_ref".}
|
|
||||||
proc unref*(L: PState, t, theref: int){.cdecl, dynlib: LIB_NAME,
|
|
||||||
importc: "luaL_unref".}
|
|
||||||
proc loadfile*(L: PState, filename: cstring): int{.cdecl,
|
|
||||||
dynlib: LIB_NAME, importc: "luaL_loadfile".}
|
|
||||||
proc loadbuffer*(L: PState, buff: cstring, size: int, name: cstring): int{.
|
|
||||||
cdecl, dynlib: LIB_NAME, importc: "luaL_loadbuffer".}
|
|
||||||
proc loadstring*(L: PState, s: cstring): int{.cdecl, dynlib: LIB_NAME,
|
|
||||||
importc: "luaL_loadstring".}
|
|
||||||
proc newstate*(): PState{.cdecl, dynlib: LIB_NAME,
|
|
||||||
importc: "luaL_newstate".}
|
|
||||||
proc open*(): PState
|
proc open*(): PState
|
||||||
# compatibility; moved from unit lua to lauxlib because it needs luaL_newstate
|
# compatibility; moved from unit lua to lauxlib because it needs luaL_newstate
|
||||||
#
|
#
|
||||||
|
|
@ -96,18 +83,18 @@ proc open*(): PState
|
||||||
#** some useful macros
|
#** some useful macros
|
||||||
#** ===============================================================
|
#** ===============================================================
|
||||||
#
|
#
|
||||||
proc argcheck*(L: PState, cond: bool, numarg: int, extramsg: cstring)
|
proc argcheck*(L: PState, cond: bool, numarg: cint, extramsg: cstring)
|
||||||
proc checkstring*(L: PState, n: int): cstring
|
proc checkstring*(L: PState, n: cint): cstring
|
||||||
proc optstring*(L: PState, n: int, d: cstring): cstring
|
proc optstring*(L: PState, n: cint, d: cstring): cstring
|
||||||
proc checkint*(L: PState, n: int): int
|
proc checkint*(L: PState, n: cint): cint
|
||||||
proc checklong*(L: PState, n: int): int32
|
proc checklong*(L: PState, n: cint): clong
|
||||||
proc optint*(L: PState, n: int, d: float64): int
|
proc optint*(L: PState, n: cint, d: float64): cint
|
||||||
proc optlong*(L: PState, n: int, d: float64): int32
|
proc optlong*(L: PState, n: cint, d: float64): clong
|
||||||
proc dofile*(L: PState, filename: cstring): int
|
proc dofile*(L: PState, filename: cstring): cint
|
||||||
proc dostring*(L: PState, str: cstring): int
|
proc dostring*(L: PState, str: cstring): cint
|
||||||
proc getmetatable*(L: PState, tname: cstring)
|
proc getmetatable*(L: PState, tname: cstring)
|
||||||
# not translated:
|
# not translated:
|
||||||
# #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
|
# #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
|
||||||
#
|
#
|
||||||
#** =======================================================
|
#** =======================================================
|
||||||
#** Generic Buffer manipulation
|
#** Generic Buffer manipulation
|
||||||
|
|
@ -119,7 +106,7 @@ const # note: this is just arbitrary, as it related to t
|
||||||
type
|
type
|
||||||
Buffer*{.final.} = object
|
Buffer*{.final.} = object
|
||||||
p*: cstring # current position in buffer
|
p*: cstring # current position in buffer
|
||||||
lvl*: int # number of strings in the stack (level)
|
lvl*: cint # number of strings in the stack (level)
|
||||||
L*: PState
|
L*: PState
|
||||||
buffer*: array[0..BUFFERSIZE - 1, Char] # warning: see note above about LUAL_BUFFERSIZE
|
buffer*: array[0..BUFFERSIZE - 1, Char] # warning: see note above about LUAL_BUFFERSIZE
|
||||||
|
|
||||||
|
|
@ -130,80 +117,76 @@ proc addchar*(B: PBuffer, c: Char)
|
||||||
# compatibility only (alias for luaL_addchar)
|
# compatibility only (alias for luaL_addchar)
|
||||||
proc putchar*(B: PBuffer, c: Char)
|
proc putchar*(B: PBuffer, c: Char)
|
||||||
# warning: see note above about LUAL_BUFFERSIZE
|
# warning: see note above about LUAL_BUFFERSIZE
|
||||||
proc addsize*(B: PBuffer, n: int)
|
proc addsize*(B: PBuffer, n: cint)
|
||||||
proc buffinit*(L: PState, B: PBuffer){.cdecl, dynlib: LIB_NAME,
|
|
||||||
importc: "luaL_buffinit".}
|
{.push callConv: cdecl, dynlib: lua.LIB_NAME, importc: "luaL_$1".}
|
||||||
proc prepbuffer*(B: PBuffer): cstring{.cdecl, dynlib: LIB_NAME,
|
proc buffinit*(L: PState, B: PBuffer)
|
||||||
importc: "luaL_prepbuffer".}
|
proc prepbuffer*(B: PBuffer): cstring
|
||||||
proc addlstring*(B: PBuffer, s: cstring, L: int){.cdecl,
|
proc addlstring*(B: PBuffer, s: cstring, L: cint)
|
||||||
dynlib: LIB_NAME, importc: "luaL_addlstring".}
|
proc addstring*(B: PBuffer, s: cstring)
|
||||||
proc addstring*(B: PBuffer, s: cstring){.cdecl, dynlib: LIB_NAME,
|
proc addvalue*(B: PBuffer)
|
||||||
importc: "luaL_addstring".}
|
proc pushresult*(B: PBuffer)
|
||||||
proc addvalue*(B: PBuffer){.cdecl, dynlib: LIB_NAME,
|
proc gsub*(L: PState, s, p, r: cstring): cstring
|
||||||
importc: "luaL_addvalue".}
|
proc findtable*(L: PState, idx: cint, fname: cstring, szhint: cint): cstring
|
||||||
proc pushresult*(B: PBuffer){.cdecl, dynlib: LIB_NAME,
|
|
||||||
importc: "luaL_pushresult".}
|
|
||||||
proc gsub*(L: PState, s, p, r: cstring): cstring{.cdecl,
|
|
||||||
dynlib: LIB_NAME, importc: "luaL_gsub".}
|
|
||||||
proc findtable*(L: PState, idx: int, fname: cstring, szhint: int): cstring{.
|
|
||||||
cdecl, dynlib: LIB_NAME, importc: "luaL_findtable".}
|
|
||||||
# compatibility with ref system
|
# compatibility with ref system
|
||||||
# pre-defined references
|
# pre-defined references
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
const
|
const
|
||||||
NOREF* = - 2
|
NOREF* = - 2
|
||||||
REFNIL* = - 1
|
REFNIL* = - 1
|
||||||
|
|
||||||
proc unref*(L: PState, theref: int)
|
proc unref*(L: PState, theref: cint)
|
||||||
proc getref*(L: PState, theref: int)
|
proc getref*(L: PState, theref: cint)
|
||||||
#
|
#
|
||||||
#** Compatibility macros and functions
|
#** Compatibility macros and functions
|
||||||
#
|
#
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
proc pushstring(L: PState, s: string) =
|
proc pushstring(L: PState, s: string) =
|
||||||
pushlstring(L, cstring(s), len(s))
|
pushlstring(L, cstring(s), s.len.cint)
|
||||||
|
|
||||||
proc getn(L: PState, n: int): int =
|
proc getn(L: PState, n: cint): cint =
|
||||||
Result = objlen(L, n)
|
Result = objlen(L, n)
|
||||||
|
|
||||||
proc setn(L: PState, t, n: int) =
|
proc setn(L: PState, t, n: cint) =
|
||||||
# does nothing as this operation is deprecated
|
# does nothing as this operation is deprecated
|
||||||
nil
|
nil
|
||||||
|
|
||||||
proc open(): PState =
|
proc open(): PState =
|
||||||
Result = newstate()
|
Result = newstate()
|
||||||
|
|
||||||
proc dofile(L: PState, filename: cstring): int =
|
proc dofile(L: PState, filename: cstring): cint =
|
||||||
Result = loadfile(L, filename)
|
Result = loadfile(L, filename)
|
||||||
if Result == 0: Result = pcall(L, 0, MULTRET, 0)
|
if Result == 0: Result = pcall(L, 0, MULTRET, 0)
|
||||||
|
|
||||||
proc dostring(L: PState, str: cstring): int =
|
proc dostring(L: PState, str: cstring): cint =
|
||||||
Result = loadstring(L, str)
|
Result = loadstring(L, str)
|
||||||
if Result == 0: Result = pcall(L, 0, MULTRET, 0)
|
if Result == 0: Result = pcall(L, 0, MULTRET, 0)
|
||||||
|
|
||||||
proc getmetatable(L: PState, tname: cstring) =
|
proc getmetatable(L: PState, tname: cstring) =
|
||||||
getfield(L, REGISTRYINDEX, tname)
|
getfield(L, REGISTRYINDEX, tname)
|
||||||
|
|
||||||
proc argcheck(L: PState, cond: bool, numarg: int, extramsg: cstring) =
|
proc argcheck(L: PState, cond: bool, numarg: cint, extramsg: cstring) =
|
||||||
if not cond:
|
if not cond:
|
||||||
discard argerror(L, numarg, extramsg)
|
discard argerror(L, numarg, extramsg)
|
||||||
|
|
||||||
proc checkstring(L: PState, n: int): cstring =
|
proc checkstring(L: PState, n: cint): cstring =
|
||||||
Result = checklstring(L, n, nil)
|
Result = checklstring(L, n, nil)
|
||||||
|
|
||||||
proc optstring(L: PState, n: int, d: cstring): cstring =
|
proc optstring(L: PState, n: cint, d: cstring): cstring =
|
||||||
Result = optlstring(L, n, d, nil)
|
Result = optlstring(L, n, d, nil)
|
||||||
|
|
||||||
proc checkint(L: PState, n: int): int =
|
proc checkint(L: PState, n: cint): cint =
|
||||||
Result = toInt(checknumber(L, n))
|
Result = cint(checknumber(L, n))
|
||||||
|
|
||||||
proc checklong(L: PState, n: int): int32 =
|
proc checklong(L: PState, n: cint): clong =
|
||||||
Result = int32(ToInt(checknumber(L, n)))
|
Result = int32(ToInt(checknumber(L, n)))
|
||||||
|
|
||||||
proc optint(L: PState, n: int, d: float64): int =
|
proc optint(L: PState, n: cint, d: float64): cint =
|
||||||
Result = int(ToInt(optnumber(L, n, d)))
|
Result = optnumber(L, n, d).cint
|
||||||
|
|
||||||
proc optlong(L: PState, n: int, d: float64): int32 =
|
proc optlong(L: PState, n: cint, d: float64): clong =
|
||||||
Result = int32(ToInt(optnumber(L, n, d)))
|
Result = int32(ToInt(optnumber(L, n, d)))
|
||||||
|
|
||||||
proc addchar(B: PBuffer, c: Char) =
|
proc addchar(B: PBuffer, c: Char) =
|
||||||
|
|
@ -215,11 +198,11 @@ proc addchar(B: PBuffer, c: Char) =
|
||||||
proc putchar(B: PBuffer, c: Char) =
|
proc putchar(B: PBuffer, c: Char) =
|
||||||
addchar(B, c)
|
addchar(B, c)
|
||||||
|
|
||||||
proc addsize(B: PBuffer, n: int) =
|
proc addsize(B: PBuffer, n: cint) =
|
||||||
B.p = cast[cstring](cast[int](B.p) + n)
|
B.p = cast[cstring](cast[int](B.p) + n)
|
||||||
|
|
||||||
proc unref(L: PState, theref: int) =
|
proc unref(L: PState, theref: cint) =
|
||||||
unref(L, REGISTRYINDEX, theref)
|
unref(L, REGISTRYINDEX, theref)
|
||||||
|
|
||||||
proc getref(L: PState, theref: int) =
|
proc getref(L: PState, theref: cint) =
|
||||||
rawgeti(L, REGISTRYINDEX, theref)
|
rawgeti(L, REGISTRYINDEX, theref)
|
||||||
|
|
|
||||||
|
|
@ -51,16 +51,16 @@ when defined(useLuajit):
|
||||||
else:
|
else:
|
||||||
when defined(MACOSX):
|
when defined(MACOSX):
|
||||||
const
|
const
|
||||||
NAME* = "liblua(|5.2|5.1|5.0).dylib"
|
NAME* = "liblua(|5.1|5.0).dylib"
|
||||||
LIB_NAME* = "liblua(|5.2|5.1|5.0).dylib"
|
LIB_NAME* = "liblua(|5.1|5.0).dylib"
|
||||||
elif defined(UNIX):
|
elif defined(UNIX):
|
||||||
const
|
const
|
||||||
NAME* = "liblua(|5.2|5.1|5.0).so(|.0)"
|
NAME* = "liblua(|5.1|5.0).so(|.0)"
|
||||||
LIB_NAME* = "liblua(|5.2|5.1|5.0).so(|.0)"
|
LIB_NAME* = "liblua(|5.1|5.0).so(|.0)"
|
||||||
else:
|
else:
|
||||||
const
|
const
|
||||||
NAME* = "lua(|5.2|5.1|5.0).dll"
|
NAME* = "lua(|5.1|5.0).dll"
|
||||||
LIB_NAME* = "lua(|5.2|5.1|5.0).dll"
|
LIB_NAME* = "lua(|5.1|5.0).dll"
|
||||||
|
|
||||||
const
|
const
|
||||||
VERSION* = "Lua 5.1"
|
VERSION* = "Lua 5.1"
|
||||||
|
|
@ -76,7 +76,7 @@ const
|
||||||
ENVIRONINDEX* = - 10001
|
ENVIRONINDEX* = - 10001
|
||||||
GLOBALSINDEX* = - 10002
|
GLOBALSINDEX* = - 10002
|
||||||
|
|
||||||
proc upvalueindex*(I: int): int
|
proc upvalueindex*(I: cint): cint
|
||||||
const # thread status; 0 is OK
|
const # thread status; 0 is OK
|
||||||
constYIELD* = 1
|
constYIELD* = 1
|
||||||
ERRRUN* = 2
|
ERRRUN* = 2
|
||||||
|
|
@ -86,16 +86,16 @@ const # thread status; 0 is OK
|
||||||
|
|
||||||
type
|
type
|
||||||
PState* = Pointer
|
PState* = Pointer
|
||||||
CFunction* = proc (L: PState): int{.cdecl.}
|
CFunction* = proc (L: PState): cint{.cdecl.}
|
||||||
|
|
||||||
#
|
#
|
||||||
#** functions that read/write blocks when loading/dumping Lua chunks
|
#** functions that read/write blocks when loading/dumping Lua chunks
|
||||||
#
|
#
|
||||||
|
|
||||||
type
|
type
|
||||||
Reader* = proc (L: PState, ud: Pointer, sz: ptr int): cstring{.cdecl.}
|
Reader* = proc (L: PState, ud: Pointer, sz: ptr cint): cstring{.cdecl.}
|
||||||
Writer* = proc (L: PState, p: Pointer, sz: int, ud: Pointer): int{.cdecl.}
|
Writer* = proc (L: PState, p: Pointer, sz: cint, ud: Pointer): cint{.cdecl.}
|
||||||
Alloc* = proc (ud, theptr: Pointer, osize, nsize: int){.cdecl.}
|
Alloc* = proc (ud, theptr: Pointer, osize, nsize: cint){.cdecl.}
|
||||||
|
|
||||||
const
|
const
|
||||||
TNONE* = - 1
|
TNONE* = - 1
|
||||||
|
|
@ -112,130 +112,86 @@ const
|
||||||
|
|
||||||
type # Type of Numbers in Lua
|
type # Type of Numbers in Lua
|
||||||
Number* = float
|
Number* = float
|
||||||
Integer* = int
|
Integer* = cint
|
||||||
|
|
||||||
|
{.pragma: ilua, importc: "lua_$1".}
|
||||||
|
|
||||||
|
{.push callConv: cdecl, dynlib: LibName.}
|
||||||
|
#{.push importc: "lua_$1".}
|
||||||
|
|
||||||
|
proc newstate*(f: Alloc, ud: Pointer): PState {.ilua.}
|
||||||
|
|
||||||
|
proc close*(L: PState){.ilua.}
|
||||||
|
proc newthread*(L: PState): PState{.ilua.}
|
||||||
|
proc atpanic*(L: PState, panicf: CFunction): CFunction{.ilua.}
|
||||||
|
|
||||||
|
proc gettop*(L: PState): cint{.ilua.}
|
||||||
|
proc settop*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc pushvalue*(L: PState, Idx: cint){.ilua.}
|
||||||
|
proc remove*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc insert*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc replace*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc checkstack*(L: PState, sz: cint): cint{.ilua.}
|
||||||
|
proc xmove*(`from`, `to`: PState, n: cint){.ilua.}
|
||||||
|
proc isnumber*(L: PState, idx: cint): cint{.ilua.}
|
||||||
|
proc isstring*(L: PState, idx: cint): cint{.ilua.}
|
||||||
|
proc iscfunction*(L: PState, idx: cint): cint{.ilua.}
|
||||||
|
proc isuserdata*(L: PState, idx: cint): cint{.ilua.}
|
||||||
|
proc luatype*(L: PState, idx: cint): cint{.importc: "lua_type".}
|
||||||
|
proc typename*(L: PState, tp: cint): cstring{.ilua.}
|
||||||
|
proc equal*(L: PState, idx1, idx2: cint): cint{.ilua.}
|
||||||
|
proc rawequal*(L: PState, idx1, idx2: cint): cint{.ilua.}
|
||||||
|
proc lessthan*(L: PState, idx1, idx2: cint): cint{.ilua.}
|
||||||
|
proc tonumber*(L: PState, idx: cint): Number{.ilua.}
|
||||||
|
proc tointeger*(L: PState, idx: cint): Integer{.ilua.}
|
||||||
|
proc toboolean*(L: PState, idx: cint): cint{.ilua.}
|
||||||
|
proc tolstring*(L: PState, idx: cint, length: ptr cint): cstring{.ilua.}
|
||||||
|
proc objlen*(L: PState, idx: cint): cint{.ilua.}
|
||||||
|
proc tocfunction*(L: PState, idx: cint): CFunction{.ilua.}
|
||||||
|
proc touserdata*(L: PState, idx: cint): Pointer{.ilua.}
|
||||||
|
proc tothread*(L: PState, idx: cint): PState{.ilua.}
|
||||||
|
proc topointer*(L: PState, idx: cint): Pointer{.ilua.}
|
||||||
|
proc pushnil*(L: PState){.ilua.}
|
||||||
|
proc pushnumber*(L: PState, n: Number){.ilua.}
|
||||||
|
proc pushinteger*(L: PState, n: Integer){.ilua.}
|
||||||
|
proc pushlstring*(L: PState, s: cstring, len: cint){.ilua.}
|
||||||
|
proc pushstring*(L: PState, s: cstring){.ilua.}
|
||||||
|
proc pushvfstring*(L: PState, fmt: cstring, argp: Pointer): cstring{.ilua.}
|
||||||
|
proc pushfstring*(L: PState, fmt: cstring): cstring{.varargs,ilua.}
|
||||||
|
proc pushcclosure*(L: PState, fn: CFunction, n: cint){.ilua.}
|
||||||
|
proc pushboolean*(L: PState, b: cint){.ilua.}
|
||||||
|
proc pushlightuserdata*(L: PState, p: Pointer){.ilua.}
|
||||||
|
proc pushthread*(L: PState){.ilua.}
|
||||||
|
proc gettable*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc getfield*(L: Pstate, idx: cint, k: cstring){.ilua.}
|
||||||
|
proc rawget*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc rawgeti*(L: PState, idx, n: cint){.ilua.}
|
||||||
|
proc createtable*(L: PState, narr, nrec: cint){.ilua.}
|
||||||
|
proc newuserdata*(L: PState, sz: cint): Pointer{.ilua.}
|
||||||
|
proc getmetatable*(L: PState, objindex: cint): cint{.ilua.}
|
||||||
|
proc getfenv*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc settable*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc setfield*(L: PState, idx: cint, k: cstring){.ilua.}
|
||||||
|
proc rawset*(L: PState, idx: cint){.ilua.}
|
||||||
|
proc rawseti*(L: PState, idx, n: cint){.ilua.}
|
||||||
|
proc setmetatable*(L: PState, objindex: cint): cint{.ilua.}
|
||||||
|
proc setfenv*(L: PState, idx: cint): cint{.ilua.}
|
||||||
|
proc call*(L: PState, nargs, nresults: cint){.ilua.}
|
||||||
|
proc pcall*(L: PState, nargs, nresults, errf: cint): cint{.ilua.}
|
||||||
|
proc cpcall*(L: PState, func: CFunction, ud: Pointer): cint{.ilua.}
|
||||||
|
proc load*(L: PState, reader: Reader, dt: Pointer, chunkname: cstring): cint{.ilua.}
|
||||||
|
proc dump*(L: PState, writer: Writer, data: Pointer): cint{.ilua.}
|
||||||
|
proc luayield*(L: PState, nresults: cint): cint{.importc: "lua_yield".}
|
||||||
|
proc resume*(L: PState, narg: cint): cint{.ilua.}
|
||||||
|
proc status*(L: PState): cint{.ilua.}
|
||||||
|
proc gc*(L: PState, what, data: cint): cint{.ilua.}
|
||||||
|
proc error*(L: PState): cint{.ilua.}
|
||||||
|
proc next*(L: PState, idx: cint): cint{.ilua.}
|
||||||
|
proc concat*(L: PState, n: cint){.ilua.}
|
||||||
|
proc getallocf*(L: PState, ud: ptr Pointer): Alloc{.ilua.}
|
||||||
|
proc setallocf*(L: PState, f: Alloc, ud: Pointer){.ilua.}
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
proc newstate*(f: Alloc, ud: Pointer): PState{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_newstate".}
|
|
||||||
proc close*(L: PState){.cdecl, dynlib: NAME, importc: "lua_close".}
|
|
||||||
proc newthread*(L: PState): PState{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_newthread".}
|
|
||||||
proc atpanic*(L: PState, panicf: CFunction): CFunction{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_atpanic".}
|
|
||||||
proc gettop*(L: PState): int{.cdecl, dynlib: NAME, importc: "lua_gettop".}
|
|
||||||
proc settop*(L: PState, idx: int){.cdecl, dynlib: NAME, importc: "lua_settop".}
|
|
||||||
proc pushvalue*(L: PState, Idx: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pushvalue".}
|
|
||||||
proc remove*(L: PState, idx: int){.cdecl, dynlib: NAME, importc: "lua_remove".}
|
|
||||||
proc insert*(L: PState, idx: int){.cdecl, dynlib: NAME, importc: "lua_insert".}
|
|
||||||
proc replace*(L: PState, idx: int){.cdecl, dynlib: NAME, importc: "lua_replace".}
|
|
||||||
proc checkstack*(L: PState, sz: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_checkstack".}
|
|
||||||
proc xmove*(`from`, `to`: PState, n: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_xmove".}
|
|
||||||
proc isnumber*(L: PState, idx: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_isnumber".}
|
|
||||||
proc isstring*(L: PState, idx: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_isstring".}
|
|
||||||
proc iscfunction*(L: PState, idx: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_iscfunction".}
|
|
||||||
proc isuserdata*(L: PState, idx: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_isuserdata".}
|
|
||||||
proc luatype*(L: PState, idx: int): int{.cdecl, dynlib: NAME, importc: "lua_type".}
|
|
||||||
proc typename*(L: PState, tp: int): cstring{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_typename".}
|
|
||||||
proc equal*(L: PState, idx1, idx2: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_equal".}
|
|
||||||
proc rawequal*(L: PState, idx1, idx2: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_rawequal".}
|
|
||||||
proc lessthan*(L: PState, idx1, idx2: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_lessthan".}
|
|
||||||
proc tonumber*(L: PState, idx: int): Number{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_tonumber".}
|
|
||||||
proc tointeger*(L: PState, idx: int): Integer{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_tointeger".}
|
|
||||||
proc toboolean*(L: PState, idx: int): cint{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_toboolean".}
|
|
||||||
proc tolstring*(L: PState, idx: int, length: ptr int): cstring{.cdecl,
|
|
||||||
dynlib: NAME, importc: "lua_tolstring".}
|
|
||||||
proc objlen*(L: PState, idx: int): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_objlen".}
|
|
||||||
proc tocfunction*(L: PState, idx: int): CFunction{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_tocfunction".}
|
|
||||||
proc touserdata*(L: PState, idx: int): Pointer{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_touserdata".}
|
|
||||||
proc tothread*(L: PState, idx: int): PState{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_tothread".}
|
|
||||||
proc topointer*(L: PState, idx: int): Pointer{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_topointer".}
|
|
||||||
proc pushnil*(L: PState){.cdecl, dynlib: NAME, importc: "lua_pushnil".}
|
|
||||||
proc pushnumber*(L: PState, n: Number){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pushnumber".}
|
|
||||||
proc pushinteger*(L: PState, n: Integer){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pushinteger".}
|
|
||||||
proc pushlstring*(L: PState, s: cstring, len: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pushlstring".}
|
|
||||||
proc pushstring*(L: PState, s: cstring){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pushstring".}
|
|
||||||
proc pushvfstring*(L: PState, fmt: cstring, argp: Pointer): cstring{.cdecl,
|
|
||||||
dynlib: NAME, importc: "lua_pushvfstring".}
|
|
||||||
proc pushfstring*(L: PState, fmt: cstring): cstring{.cdecl, varargs,
|
|
||||||
dynlib: NAME, importc: "lua_pushfstring".}
|
|
||||||
proc pushcclosure*(L: PState, fn: CFunction, n: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pushcclosure".}
|
|
||||||
proc pushboolean*(L: PState, b: cint){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pushboolean".}
|
|
||||||
proc pushlightuserdata*(L: PState, p: Pointer){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pushlightuserdata".}
|
|
||||||
proc pushthread*(L: PState){.cdecl, dynlib: NAME, importc: "lua_pushthread".}
|
|
||||||
proc gettable*(L: PState, idx: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_gettable".}
|
|
||||||
proc getfield*(L: Pstate, idx: int, k: cstring){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_getfield".}
|
|
||||||
proc rawget*(L: PState, idx: int){.cdecl, dynlib: NAME, importc: "lua_rawget".}
|
|
||||||
proc rawgeti*(L: PState, idx, n: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_rawgeti".}
|
|
||||||
proc createtable*(L: PState, narr, nrec: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_createtable".}
|
|
||||||
proc newuserdata*(L: PState, sz: int): Pointer{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_newuserdata".}
|
|
||||||
proc getmetatable*(L: PState, objindex: int): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_getmetatable".}
|
|
||||||
proc getfenv*(L: PState, idx: int){.cdecl, dynlib: NAME, importc: "lua_getfenv".}
|
|
||||||
proc settable*(L: PState, idx: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_settable".}
|
|
||||||
proc setfield*(L: PState, idx: int, k: cstring){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_setfield".}
|
|
||||||
proc rawset*(L: PState, idx: int){.cdecl, dynlib: NAME, importc: "lua_rawset".}
|
|
||||||
proc rawseti*(L: PState, idx, n: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_rawseti".}
|
|
||||||
proc setmetatable*(L: PState, objindex: int): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_setmetatable".}
|
|
||||||
proc setfenv*(L: PState, idx: int): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_setfenv".}
|
|
||||||
proc call*(L: PState, nargs, nresults: int){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_call".}
|
|
||||||
proc pcall*(L: PState, nargs, nresults, errf: int): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_pcall".}
|
|
||||||
proc cpcall*(L: PState, func: CFunction, ud: Pointer): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_cpcall".}
|
|
||||||
proc load*(L: PState, reader: Reader, dt: Pointer, chunkname: cstring): int{.
|
|
||||||
cdecl, dynlib: NAME, importc: "lua_load".}
|
|
||||||
proc dump*(L: PState, writer: Writer, data: Pointer): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_dump".}
|
|
||||||
proc luayield*(L: PState, nresults: int): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_yield".}
|
|
||||||
proc resume*(L: PState, narg: int): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_resume".}
|
|
||||||
proc status*(L: PState): int{.cdecl, dynlib: NAME, importc: "lua_status".}
|
|
||||||
proc gc*(L: PState, what, data: int): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_gc".}
|
|
||||||
proc error*(L: PState): int{.cdecl, dynlib: NAME, importc: "lua_error".}
|
|
||||||
proc next*(L: PState, idx: int): int{.cdecl, dynlib: NAME, importc: "lua_next".}
|
|
||||||
proc concat*(L: PState, n: int){.cdecl, dynlib: NAME, importc: "lua_concat".}
|
|
||||||
proc getallocf*(L: PState, ud: ptr Pointer): Alloc{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_getallocf".}
|
|
||||||
proc setallocf*(L: PState, f: Alloc, ud: Pointer){.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_setallocf".}
|
|
||||||
#
|
#
|
||||||
#** Garbage-collection functions and options
|
#** Garbage-collection functions and options
|
||||||
#
|
#
|
||||||
|
|
@ -256,29 +212,29 @@ const
|
||||||
#** ===============================================================
|
#** ===============================================================
|
||||||
#
|
#
|
||||||
|
|
||||||
proc pop*(L: PState, n: int)
|
proc pop*(L: PState, n: cint)
|
||||||
proc newtable*(L: Pstate)
|
proc newtable*(L: Pstate)
|
||||||
proc register*(L: PState, n: cstring, f: CFunction)
|
proc register*(L: PState, n: cstring, f: CFunction)
|
||||||
proc pushcfunction*(L: PState, f: CFunction)
|
proc pushcfunction*(L: PState, f: CFunction)
|
||||||
proc strlen*(L: Pstate, i: int): int
|
proc strlen*(L: Pstate, i: cint): cint
|
||||||
proc isfunction*(L: PState, n: int): bool
|
proc isfunction*(L: PState, n: cint): bool
|
||||||
proc istable*(L: PState, n: int): bool
|
proc istable*(L: PState, n: cint): bool
|
||||||
proc islightuserdata*(L: PState, n: int): bool
|
proc islightuserdata*(L: PState, n: cint): bool
|
||||||
proc isnil*(L: PState, n: int): bool
|
proc isnil*(L: PState, n: cint): bool
|
||||||
proc isboolean*(L: PState, n: int): bool
|
proc isboolean*(L: PState, n: cint): bool
|
||||||
proc isthread*(L: PState, n: int): bool
|
proc isthread*(L: PState, n: cint): bool
|
||||||
proc isnone*(L: PState, n: int): bool
|
proc isnone*(L: PState, n: cint): bool
|
||||||
proc isnoneornil*(L: PState, n: int): bool
|
proc isnoneornil*(L: PState, n: cint): bool
|
||||||
proc pushliteral*(L: PState, s: cstring)
|
proc pushliteral*(L: PState, s: cstring)
|
||||||
proc setglobal*(L: PState, s: cstring)
|
proc setglobal*(L: PState, s: cstring)
|
||||||
proc getglobal*(L: PState, s: cstring)
|
proc getglobal*(L: PState, s: cstring)
|
||||||
proc tostring*(L: PState, i: int): cstring
|
proc tostring*(L: PState, i: cint): cstring
|
||||||
#
|
#
|
||||||
#** compatibility macros and functions
|
#** compatibility macros and functions
|
||||||
#
|
#
|
||||||
|
|
||||||
proc getregistry*(L: PState)
|
proc getregistry*(L: PState)
|
||||||
proc getgccount*(L: PState): int
|
proc getgccount*(L: PState): cint
|
||||||
type
|
type
|
||||||
Chunkreader* = Reader
|
Chunkreader* = Reader
|
||||||
Chunkwriter* = Writer
|
Chunkwriter* = Writer
|
||||||
|
|
@ -307,18 +263,18 @@ const
|
||||||
|
|
||||||
type
|
type
|
||||||
TDebug*{.final.} = object # activation record
|
TDebug*{.final.} = object # activation record
|
||||||
event*: int
|
event*: cint
|
||||||
name*: cstring # (n)
|
name*: cstring # (n)
|
||||||
namewhat*: cstring # (n) `global', `local', `field', `method'
|
namewhat*: cstring # (n) `global', `local', `field', `method'
|
||||||
what*: cstring # (S) `Lua', `C', `main', `tail'
|
what*: cstring # (S) `Lua', `C', `main', `tail'
|
||||||
source*: cstring # (S)
|
source*: cstring # (S)
|
||||||
currentline*: int # (l)
|
currentline*: cint # (l)
|
||||||
nups*: int # (u) number of upvalues
|
nups*: cint # (u) number of upvalues
|
||||||
linedefined*: int # (S)
|
linedefined*: cint # (S)
|
||||||
lastlinedefined*: int # (S)
|
lastlinedefined*: cint # (S)
|
||||||
short_src*: array[0..IDSIZE - 1, Char] # (S)
|
short_src*: array[0.. <IDSIZE, Char] # (S) \
|
||||||
# private part
|
# private part
|
||||||
i_ci*: int # active function
|
i_ci*: cint # active function
|
||||||
|
|
||||||
PDebug* = ptr TDebug
|
PDebug* = ptr TDebug
|
||||||
Hook* = proc (L: PState, ar: PDebug){.cdecl.}
|
Hook* = proc (L: PState, ar: PDebug){.cdecl.}
|
||||||
|
|
@ -329,31 +285,27 @@ type
|
||||||
#** ======================================================================
|
#** ======================================================================
|
||||||
#
|
#
|
||||||
|
|
||||||
proc getstack*(L: PState, level: int, ar: PDebug): int{.cdecl, dynlib: NAME,
|
{.push callConv: cdecl, dynlib: lua.LIB_NAME.}
|
||||||
importc: "lua_getstack".}
|
|
||||||
proc getinfo*(L: PState, what: cstring, ar: PDebug): int{.cdecl, dynlib: NAME,
|
proc getstack*(L: PState, level: cint, ar: PDebug): cint{.ilua.}
|
||||||
importc: "lua_getinfo".}
|
proc getinfo*(L: PState, what: cstring, ar: PDebug): cint{.ilua.}
|
||||||
proc getlocal*(L: PState, ar: PDebug, n: int): cstring{.cdecl, dynlib: NAME,
|
proc getlocal*(L: PState, ar: PDebug, n: cint): cstring{.ilua.}
|
||||||
importc: "lua_getlocal".}
|
proc setlocal*(L: PState, ar: PDebug, n: cint): cstring{.ilua.}
|
||||||
proc setlocal*(L: PState, ar: PDebug, n: int): cstring{.cdecl, dynlib: NAME,
|
proc getupvalue*(L: PState, funcindex: cint, n: cint): cstring{.ilua.}
|
||||||
importc: "lua_setlocal".}
|
proc setupvalue*(L: PState, funcindex: cint, n: cint): cstring{.ilua.}
|
||||||
proc getupvalue*(L: PState, funcindex: int, n: int): cstring{.cdecl,
|
proc sethook*(L: PState, func: Hook, mask: cint, count: cint): cint{.ilua.}
|
||||||
dynlib: NAME, importc: "lua_getupvalue".}
|
proc gethook*(L: PState): Hook{.ilua.}
|
||||||
proc setupvalue*(L: PState, funcindex: int, n: int): cstring{.cdecl,
|
proc gethookmask*(L: PState): cint{.ilua.}
|
||||||
dynlib: NAME, importc: "lua_setupvalue".}
|
proc gethookcount*(L: PState): cint{.ilua.}
|
||||||
proc sethook*(L: PState, func: Hook, mask: int, count: int): int{.cdecl,
|
|
||||||
dynlib: NAME, importc: "lua_sethook".}
|
{.pop.}
|
||||||
proc gethook*(L: PState): Hook{.cdecl, dynlib: NAME, importc: "lua_gethook".}
|
|
||||||
proc gethookmask*(L: PState): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_gethookmask".}
|
|
||||||
proc gethookcount*(L: PState): int{.cdecl, dynlib: NAME,
|
|
||||||
importc: "lua_gethookcount".}
|
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
proc upvalueindex(I: int): int =
|
proc upvalueindex(I: cint): cint =
|
||||||
Result = GLOBALSINDEX - i
|
Result = GLOBALSINDEX - i
|
||||||
|
|
||||||
proc pop(L: PState, n: int) =
|
proc pop(L: PState, n: cint) =
|
||||||
settop(L, - n - 1)
|
settop(L, - n - 1)
|
||||||
|
|
||||||
proc newtable(L: PState) =
|
proc newtable(L: PState) =
|
||||||
|
|
@ -366,35 +318,35 @@ proc register(L: PState, n: cstring, f: CFunction) =
|
||||||
proc pushcfunction(L: PState, f: CFunction) =
|
proc pushcfunction(L: PState, f: CFunction) =
|
||||||
pushcclosure(L, f, 0)
|
pushcclosure(L, f, 0)
|
||||||
|
|
||||||
proc strlen(L: PState, i: int): int =
|
proc strlen(L: PState, i: cint): cint =
|
||||||
Result = objlen(L, i)
|
Result = objlen(L, i)
|
||||||
|
|
||||||
proc isfunction(L: PState, n: int): bool =
|
proc isfunction(L: PState, n: cint): bool =
|
||||||
Result = luatype(L, n) == TFUNCTION
|
Result = luatype(L, n) == TFUNCTION
|
||||||
|
|
||||||
proc istable(L: PState, n: int): bool =
|
proc istable(L: PState, n: cint): bool =
|
||||||
Result = luatype(L, n) == TTABLE
|
Result = luatype(L, n) == TTABLE
|
||||||
|
|
||||||
proc islightuserdata(L: PState, n: int): bool =
|
proc islightuserdata(L: PState, n: cint): bool =
|
||||||
Result = luatype(L, n) == TLIGHTUSERDATA
|
Result = luatype(L, n) == TLIGHTUSERDATA
|
||||||
|
|
||||||
proc isnil(L: PState, n: int): bool =
|
proc isnil(L: PState, n: cint): bool =
|
||||||
Result = luatype(L, n) == TNIL
|
Result = luatype(L, n) == TNIL
|
||||||
|
|
||||||
proc isboolean(L: PState, n: int): bool =
|
proc isboolean(L: PState, n: cint): bool =
|
||||||
Result = luatype(L, n) == TBOOLEAN
|
Result = luatype(L, n) == TBOOLEAN
|
||||||
|
|
||||||
proc isthread(L: PState, n: int): bool =
|
proc isthread(L: PState, n: cint): bool =
|
||||||
Result = luatype(L, n) == TTHREAD
|
Result = luatype(L, n) == TTHREAD
|
||||||
|
|
||||||
proc isnone(L: PState, n: int): bool =
|
proc isnone(L: PState, n: cint): bool =
|
||||||
Result = luatype(L, n) == TNONE
|
Result = luatype(L, n) == TNONE
|
||||||
|
|
||||||
proc isnoneornil(L: PState, n: int): bool =
|
proc isnoneornil(L: PState, n: cint): bool =
|
||||||
Result = luatype(L, n) <= 0
|
Result = luatype(L, n) <= 0
|
||||||
|
|
||||||
proc pushliteral(L: PState, s: cstring) =
|
proc pushliteral(L: PState, s: cstring) =
|
||||||
pushlstring(L, s, len(s))
|
pushlstring(L, s, s.len.cint)
|
||||||
|
|
||||||
proc setglobal(L: PState, s: cstring) =
|
proc setglobal(L: PState, s: cstring) =
|
||||||
setfield(L, GLOBALSINDEX, s)
|
setfield(L, GLOBALSINDEX, s)
|
||||||
|
|
@ -402,11 +354,11 @@ proc setglobal(L: PState, s: cstring) =
|
||||||
proc getglobal(L: PState, s: cstring) =
|
proc getglobal(L: PState, s: cstring) =
|
||||||
getfield(L, GLOBALSINDEX, s)
|
getfield(L, GLOBALSINDEX, s)
|
||||||
|
|
||||||
proc tostring(L: PState, i: int): cstring =
|
proc tostring(L: PState, i: cint): cstring =
|
||||||
Result = tolstring(L, i, nil)
|
Result = tolstring(L, i, nil)
|
||||||
|
|
||||||
proc getregistry(L: PState) =
|
proc getregistry(L: PState) =
|
||||||
pushvalue(L, REGISTRYINDEX)
|
pushvalue(L, REGISTRYINDEX)
|
||||||
|
|
||||||
proc getgccount(L: PState): int =
|
proc getgccount(L: PState): cint =
|
||||||
Result = gc(L, GCCOUNT, 0)
|
Result = gc(L, GCCOUNT, 0)
|
||||||
|
|
|
||||||
|
|
@ -32,35 +32,33 @@ const
|
||||||
DBLIBNAME* = "debug"
|
DBLIBNAME* = "debug"
|
||||||
LOADLIBNAME* = "package"
|
LOADLIBNAME* = "package"
|
||||||
|
|
||||||
proc open_base*(L: PState): cint{.cdecl, dynlib: LIB_NAME,
|
{.pragma: ilua, importc: "lua$1".}
|
||||||
importc: "luaopen_base".}
|
|
||||||
proc open_table*(L: PState): cint{.cdecl, dynlib: LIB_NAME,
|
{.push callConv: cdecl, dynlib: lua.LIB_NAME.}
|
||||||
importc: "luaopen_table".}
|
proc open_base*(L: PState): cint{.ilua.}
|
||||||
proc open_io*(L: PState): cint{.cdecl, dynlib: LIB_NAME, importc: "luaopen_io".}
|
proc open_table*(L: PState): cint{.ilua.}
|
||||||
proc open_string*(L: PState): cint{.cdecl, dynlib: LIB_NAME,
|
proc open_io*(L: PState): cint{.ilua.}
|
||||||
importc: "luaopen_string".}
|
proc open_string*(L: PState): cint{.ilua.}
|
||||||
proc open_math*(L: PState): cint{.cdecl, dynlib: LIB_NAME,
|
proc open_math*(L: PState): cint{.ilua.}
|
||||||
importc: "luaopen_math".}
|
proc open_debug*(L: PState): cint{.ilua.}
|
||||||
proc open_debug*(L: PState): cint{.cdecl, dynlib: LIB_NAME,
|
proc open_package*(L: PState): cint{.ilua.}
|
||||||
importc: "luaopen_debug".}
|
proc openlibs*(L: PState){.importc: "luaL_openlibs".}
|
||||||
proc open_package*(L: PState): cint{.cdecl, dynlib: LIB_NAME,
|
{.pop.}
|
||||||
importc: "luaopen_package".}
|
|
||||||
proc openlibs*(L: PState){.cdecl, dynlib: LIB_NAME, importc: "luaL_openlibs".}
|
|
||||||
|
|
||||||
proc baselibopen*(L: PState): Bool =
|
proc baselibopen*(L: PState): Bool =
|
||||||
Result = open_base(L) != 0'i32
|
open_base(L) != 0'i32
|
||||||
|
|
||||||
proc tablibopen*(L: PState): Bool =
|
proc tablibopen*(L: PState): Bool =
|
||||||
Result = open_table(L) != 0'i32
|
open_table(L) != 0'i32
|
||||||
|
|
||||||
proc iolibopen*(L: PState): Bool =
|
proc iolibopen*(L: PState): Bool =
|
||||||
Result = open_io(L) != 0'i32
|
open_io(L) != 0'i32
|
||||||
|
|
||||||
proc strlibopen*(L: PState): Bool =
|
proc strlibopen*(L: PState): Bool =
|
||||||
Result = open_string(L) != 0'i32
|
open_string(L) != 0'i32
|
||||||
|
|
||||||
proc mathlibopen*(L: PState): Bool =
|
proc mathlibopen*(L: PState): Bool =
|
||||||
Result = open_math(L) != 0'i32
|
open_math(L) != 0'i32
|
||||||
|
|
||||||
proc dblibopen*(L: PState): Bool =
|
proc dblibopen*(L: PState): Bool =
|
||||||
Result = open_debug(L) != 0'i32
|
open_debug(L) != 0'i32
|
||||||
|
|
|
||||||
24
tests/reject/tnotnil1.nim
Normal file
24
tests/reject/tnotnil1.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "'y' is provably nil"
|
||||||
|
line:22
|
||||||
|
"""
|
||||||
|
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
TObj = object
|
||||||
|
x, y: int
|
||||||
|
|
||||||
|
proc q(x: pointer not nil) =
|
||||||
|
nil
|
||||||
|
|
||||||
|
proc p() =
|
||||||
|
var x: pointer
|
||||||
|
let y = x
|
||||||
|
if not y.isNil:
|
||||||
|
q(y)
|
||||||
|
else:
|
||||||
|
q(y)
|
||||||
|
|
||||||
|
p()
|
||||||
24
tests/reject/tnotnil2.nim
Normal file
24
tests/reject/tnotnil2.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "cannot prove 'y' is not nil"
|
||||||
|
line:22
|
||||||
|
"""
|
||||||
|
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
TObj = object
|
||||||
|
x, y: int
|
||||||
|
|
||||||
|
proc q(x: pointer not nil) =
|
||||||
|
nil
|
||||||
|
|
||||||
|
proc p() =
|
||||||
|
var x: pointer
|
||||||
|
let y = x
|
||||||
|
if not y.isNil or y != x:
|
||||||
|
q(y)
|
||||||
|
else:
|
||||||
|
q(y)
|
||||||
|
|
||||||
|
p()
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -25,7 +25,6 @@ Bugs
|
||||||
- blocks can "export" an identifier but the CCG generates {} for them ...
|
- blocks can "export" an identifier but the CCG generates {} for them ...
|
||||||
- osproc execProcesses can deadlock if all processes fail (as experienced
|
- osproc execProcesses can deadlock if all processes fail (as experienced
|
||||||
in c++ mode)
|
in c++ mode)
|
||||||
- bootstrapping does not work in C++ mode
|
|
||||||
- result = result shr 8 for the "system()" wrapper
|
- result = result shr 8 for the "system()" wrapper
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ Language Additions
|
||||||
|
|
||||||
- Arrays can now be declared with a single integer literal ``N`` instead of a
|
- Arrays can now be declared with a single integer literal ``N`` instead of a
|
||||||
range; the range is then ``0..N-1``.
|
range; the range is then ``0..N-1``.
|
||||||
|
- ``macros.dumpTree`` and ``macros.dumpLisp`` have been made ``immediate``,
|
||||||
|
``dumpTreeImm`` and ``dumpLispImm`` are now deprecated.
|
||||||
- Added ``requiresInit`` pragma to enforce explicit initialization.
|
- Added ``requiresInit`` pragma to enforce explicit initialization.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue