fixed tuples in a static context; preparations for correct compile time evaluation of integral ops
This commit is contained in:
parent
fb5ece805f
commit
e53fc91282
5 changed files with 30 additions and 4 deletions
|
|
@ -19,7 +19,7 @@ const
|
||||||
when debugIds:
|
when debugIds:
|
||||||
import intsets
|
import intsets
|
||||||
|
|
||||||
var usedIds = InitIntSet()
|
var usedIds = initIntSet()
|
||||||
|
|
||||||
proc registerID*(id: PIdObj) =
|
proc registerID*(id: PIdObj) =
|
||||||
when debugIds:
|
when debugIds:
|
||||||
|
|
|
||||||
|
|
@ -902,8 +902,32 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
let newLen = regs[rb].intVal.int
|
let newLen = regs[rb].intVal.int
|
||||||
if regs[ra].node.isNil: stackTrace(c, tos, pc, errNilAccess)
|
if regs[ra].node.isNil: stackTrace(c, tos, pc, errNilAccess)
|
||||||
else: setLen(regs[ra].node.sons, newLen)
|
else: setLen(regs[ra].node.sons, newLen)
|
||||||
of opcSwap, opcReset:
|
of opcSwap:
|
||||||
|
let rb = instr.regB
|
||||||
|
if regs[ra].kind == regs[rb].kind:
|
||||||
|
case regs[ra].kind
|
||||||
|
of rkNone: discard
|
||||||
|
of rkInt: swap regs[ra].intVal, regs[rb].intVal
|
||||||
|
of rkFloat: swap regs[ra].floatVal, regs[rb].floatVal
|
||||||
|
of rkNode: swap regs[ra].node, regs[rb].node
|
||||||
|
of rkRegisterAddr: swap regs[ra].regAddr, regs[rb].regAddr
|
||||||
|
of rkNodeAddr: swap regs[ra].nodeAddr, regs[rb].nodeAddr
|
||||||
|
else:
|
||||||
|
internalError(c.debug[pc], "cannot swap operands")
|
||||||
|
of opcReset:
|
||||||
internalError(c.debug[pc], "too implement")
|
internalError(c.debug[pc], "too implement")
|
||||||
|
of opcNarrowS:
|
||||||
|
decodeBC(rkInt)
|
||||||
|
let min = -(1 shl (rc-1))
|
||||||
|
let max = (1 shl (rc-1))-1
|
||||||
|
if regs[rb].intVal >= min and regs[rb].intVal <= max:
|
||||||
|
regs[ra].intVal = regs[rb].intVal
|
||||||
|
else:
|
||||||
|
stackTrace(c, tos, pc, errGenerated,
|
||||||
|
msgKindToString(errUnhandledExceptionX) % "value out of range")
|
||||||
|
of opcNarrowU:
|
||||||
|
decodeBC(rkInt)
|
||||||
|
regs[ra].intVal = regs[rb].intVal and ((1'i64 shl rc)-1)
|
||||||
of opcIsNil:
|
of opcIsNil:
|
||||||
decodeB(rkInt)
|
decodeB(rkInt)
|
||||||
regs[ra].intVal = ord(regs[rb].node.kind == nkNilLit)
|
regs[ra].intVal = ord(regs[rb].node.kind == nkNilLit)
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ type
|
||||||
opcContainsSet, opcRepr, opcSetLenStr, opcSetLenSeq,
|
opcContainsSet, opcRepr, opcSetLenStr, opcSetLenSeq,
|
||||||
opcSwap, opcIsNil, opcOf, opcIs,
|
opcSwap, opcIsNil, opcOf, opcIs,
|
||||||
opcSubStr, opcConv, opcCast, opcQuit, opcReset,
|
opcSubStr, opcConv, opcCast, opcQuit, opcReset,
|
||||||
|
opcNarrowS, opcNarrowU,
|
||||||
|
|
||||||
opcAddStrCh,
|
opcAddStrCh,
|
||||||
opcAddStrStr,
|
opcAddStrStr,
|
||||||
|
|
|
||||||
|
|
@ -1226,7 +1226,8 @@ proc genVarSection(c: PCtx; n: PNode) =
|
||||||
if s.position == 0:
|
if s.position == 0:
|
||||||
if sfImportc in s.flags: c.importcSym(a.info, s)
|
if sfImportc in s.flags: c.importcSym(a.info, s)
|
||||||
else:
|
else:
|
||||||
let sa = if s.ast.isNil: getNullValue(s.typ, a.info) else: s.ast
|
let sa = if s.ast.isNil: getNullValue(s.typ, a.info)
|
||||||
|
else: canonConst(s.ast)
|
||||||
c.globals.add(sa)
|
c.globals.add(sa)
|
||||||
s.position = c.globals.len
|
s.position = c.globals.len
|
||||||
if a.sons[2].kind == nkEmpty:
|
if a.sons[2].kind == nkEmpty:
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ Is translated into:
|
||||||
printf("%s\x0A", x)
|
printf("%s\x0A", x)
|
||||||
else:
|
else:
|
||||||
template OUT*(x: expr): stmt =
|
template OUT*(x: expr): stmt =
|
||||||
nil
|
discard
|
||||||
|
|
||||||
As can been seen from the example, C's macros with parameters are mapped
|
As can been seen from the example, C's macros with parameters are mapped
|
||||||
to Nimrod's templates. This mapping is the best one can do, but it is of course
|
to Nimrod's templates. This mapping is the best one can do, but it is of course
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue