fixed tuples in a static context; preparations for correct compile time evaluation of integral ops

This commit is contained in:
Araq
2014-03-22 02:52:06 +01:00
parent fb5ece805f
commit e53fc91282
5 changed files with 30 additions and 4 deletions

View File

@@ -19,7 +19,7 @@ const
when debugIds:
import intsets
var usedIds = InitIntSet()
var usedIds = initIntSet()
proc registerID*(id: PIdObj) =
when debugIds:

View File

@@ -902,8 +902,32 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let newLen = regs[rb].intVal.int
if regs[ra].node.isNil: stackTrace(c, tos, pc, errNilAccess)
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")
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:
decodeB(rkInt)
regs[ra].intVal = ord(regs[rb].node.kind == nkNilLit)

View File

@@ -64,6 +64,7 @@ type
opcContainsSet, opcRepr, opcSetLenStr, opcSetLenSeq,
opcSwap, opcIsNil, opcOf, opcIs,
opcSubStr, opcConv, opcCast, opcQuit, opcReset,
opcNarrowS, opcNarrowU,
opcAddStrCh,
opcAddStrStr,

View File

@@ -1226,7 +1226,8 @@ proc genVarSection(c: PCtx; n: PNode) =
if s.position == 0:
if sfImportc in s.flags: c.importcSym(a.info, s)
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)
s.position = c.globals.len
if a.sons[2].kind == nkEmpty:

View File

@@ -74,7 +74,7 @@ Is translated into:
printf("%s\x0A", x)
else:
template OUT*(x: expr): stmt =
nil
discard
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