diff options
author | Araq <rumpf_a@web.de> | 2014-03-22 02:52:06 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-03-22 02:52:06 +0100 |
commit | e53fc91282bc8a5dabc4f12e041fa6ce5400c007 (patch) | |
tree | be7fcdd03635a91596ab813643f3b293db7d30e8 /compiler | |
parent | fb5ece805ff5b752ec2e9dc0c49fc34d5abdc6a9 (diff) | |
download | Nim-e53fc91282bc8a5dabc4f12e041fa6ce5400c007.tar.gz |
fixed tuples in a static context; preparations for correct compile time evaluation of integral ops
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/idgen.nim | 2 | ||||
-rw-r--r-- | compiler/vm.nim | 26 | ||||
-rw-r--r-- | compiler/vmdef.nim | 1 | ||||
-rw-r--r-- | compiler/vmgen.nim | 3 |
4 files changed, 29 insertions, 3 deletions
diff --git a/compiler/idgen.nim b/compiler/idgen.nim index c4f5f2a9e..d932e3d9d 100644 --- a/compiler/idgen.nim +++ b/compiler/idgen.nim @@ -19,7 +19,7 @@ const when debugIds: import intsets - var usedIds = InitIntSet() + var usedIds = initIntSet() proc registerID*(id: PIdObj) = when debugIds: diff --git a/compiler/vm.nim b/compiler/vm.nim index 5c8e533f1..06f0e8886 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -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) diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 102fc3024..7725d79b8 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -64,6 +64,7 @@ type opcContainsSet, opcRepr, opcSetLenStr, opcSetLenSeq, opcSwap, opcIsNil, opcOf, opcIs, opcSubStr, opcConv, opcCast, opcQuit, opcReset, + opcNarrowS, opcNarrowU, opcAddStrCh, opcAddStrStr, diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 0fc71189d..5e51ecf4c 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -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: |