Merge branch 'master' into asyncmacro

This commit is contained in:
Dominik Picheta 2013-07-25 22:16:06 +01:00
commit 3ead23cb26
4 changed files with 44 additions and 16 deletions

View file

@ -1028,9 +1028,9 @@ proc typeAllowedAux(marker: var TIntSet, typ: PType, kind: TSymKind): bool =
result = kind == skParam result = kind == skParam
of tyGenericInst, tyDistinct: of tyGenericInst, tyDistinct:
result = typeAllowedAux(marker, lastSon(t), kind) result = typeAllowedAux(marker, lastSon(t), kind)
of tyRange: of tyRange:
result = skipTypes(t.sons[0], abstractInst-{tyTypeDesc}).kind in result = skipTypes(t.sons[0], abstractInst-{tyTypeDesc}).kind in
{tyChar, tyEnum, tyInt..tyFloat128} {tyChar, tyEnum, tyInt..tyUInt64}
of tyOpenArray, tyVarargs: of tyOpenArray, tyVarargs:
result = (kind == skParam) and typeAllowedAux(marker, t.sons[0], skVar) result = (kind == skParam) and typeAllowedAux(marker, t.sons[0], skVar)
of tySequence: of tySequence:

View file

@ -79,7 +79,9 @@ template decodeBx(k: expr) {.immediate, dirty.} =
let rbx = instr.regBx - wordExcess let rbx = instr.regBx - wordExcess
ensureKind(k) ensureKind(k)
proc compile(c: PCtx, s: PSym): int = vmgen.genProc(c, s) proc compile(c: PCtx, s: PSym): int =
result = vmgen.genProc(c, s)
c.echoCode
proc myreset(n: PNode) = proc myreset(n: PNode) =
when defined(system.reset): when defined(system.reset):
@ -197,14 +199,10 @@ proc execute(c: PCtx, start: int) =
of opcYldYoid: assert false of opcYldYoid: assert false
of opcYldVal: assert false of opcYldVal: assert false
of opcAsgnInt: of opcAsgnInt:
echo ra, " ", instr.regB, " ", regs.len, tos.prc.name.s
decodeB(nkIntLit) decodeB(nkIntLit)
regs[ra].intVal = regs[rb].intVal regs[ra].intVal = regs[rb].intVal
of opcAsgnStr: of opcAsgnStr:
decodeB(nkStrLit) decodeB(nkStrLit)
debug regs[rb]
echo rb
Message(c.debug[pc], warnUser, " here")
regs[ra].strVal = regs[rb].strVal regs[ra].strVal = regs[rb].strVal
of opcAsgnFloat: of opcAsgnFloat:
decodeB(nkFloatLit) decodeB(nkFloatLit)

View file

@ -25,12 +25,17 @@ proc codeListing(c: PCtx, result: var string) =
result.addf("\t$#\tr$#, r$#, r$#", ($opc).substr(3), x.regA, result.addf("\t$#\tr$#, r$#, r$#", ($opc).substr(3), x.regA,
x.regB, x.regC) x.regB, x.regC)
else: else:
result.addf("\t$#\tr$#, r$#", ($opc).substr(3), x.regA, x.regBx) result.addf("\t$#\tr$#, r$#", ($opc).substr(3), x.regA, x.regBx-wordExcess)
result.add(" #") result.add("\t#")
result.add(toFileLine(c.debug[i])) result.add(toFileLine(c.debug[i]))
result.add("\n") result.add("\n")
inc i inc i
proc echoCode*(c: PCtx) =
var buf = ""
codeListing(c, buf)
echo buf
proc gABC(ctx: PCtx; n: PNode; opc: TOpcode; a, b, c: TRegister = 0) = proc gABC(ctx: PCtx; n: PNode; opc: TOpcode; a, b, c: TRegister = 0) =
assert opc.ord < 255 assert opc.ord < 255
let ins = (opc.uint32 or (a.uint32 shl 8'u32) or let ins = (opc.uint32 or (a.uint32 shl 8'u32) or
@ -40,19 +45,22 @@ proc gABC(ctx: PCtx; n: PNode; opc: TOpcode; a, b, c: TRegister = 0) =
ctx.debug.add(n.info) ctx.debug.add(n.info)
proc gABI(c: PCtx; n: PNode; opc: TOpcode; a, b: TRegister; imm: biggestInt) = proc gABI(c: PCtx; n: PNode; opc: TOpcode; a, b: TRegister; imm: biggestInt) =
let ins = (opc.ord or a shl 8 or b shl 16 or (imm+byteExcess) shl 24).TInstr let ins = (opc.uint32 or (a.uint32 shl 8'u32) or
(b.uint32 shl 16'u32) or
(imm+byteExcess).uint32 shl 24'u32).TInstr
c.code.add(ins) c.code.add(ins)
c.debug.add(n.info) c.debug.add(n.info)
proc gABx(c: PCtx; n: PNode; opc: TOpcode; a: TRegister = 0; bx: int) = proc gABx(c: PCtx; n: PNode; opc: TOpcode; a: TRegister = 0; bx: int) =
let ins = (opc.ord or a shl 8 or (bx+wordExcess) shl 16).TInstr let ins = (opc.uint32 or a.uint32 shl 8'u32 or
(bx+wordExcess).uint32 shl 16'u32).TInstr
c.code.add(ins) c.code.add(ins)
c.debug.add(n.info) c.debug.add(n.info)
proc xjmp(c: PCtx; n: PNode; opc: TOpcode; a: TRegister = 0): TPosition = proc xjmp(c: PCtx; n: PNode; opc: TOpcode; a: TRegister = 0): TPosition =
#assert opc in {opcJmp, opcFJmp, opcTJmp} #assert opc in {opcJmp, opcFJmp, opcTJmp}
gABx(c, n, opc, a, 0)
result = TPosition(c.code.len) result = TPosition(c.code.len)
gABx(c, n, opc, a, 0)
proc genLabel(c: PCtx): TPosition = proc genLabel(c: PCtx): TPosition =
result = TPosition(c.code.len) result = TPosition(c.code.len)
@ -71,7 +79,8 @@ proc patch(c: PCtx, p: TPosition) =
InternalAssert(-0x7fff < diff and diff < 0x7fff) InternalAssert(-0x7fff < diff and diff < 0x7fff)
let oldInstr = c.code[p] let oldInstr = c.code[p]
# opcode and regA stay the same: # opcode and regA stay the same:
c.code[p] = ((oldInstr.int and 0xffff) or (diff+wordExcess)).TInstr c.code[p] = ((oldInstr.uint32 and 0xffff'u32) or
uint32(diff+wordExcess) shr 16'u32).TInstr
proc getSlotKind(t: PType): TSlotKind = proc getSlotKind(t: PType): TSlotKind =
case t.skipTypes(abstractRange).kind case t.skipTypes(abstractRange).kind
@ -704,7 +713,7 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
let dest = c.genx(le.sons[0]) let dest = c.genx(le.sons[0])
let idx = c.genx(le.sons[1]) let idx = c.genx(le.sons[1])
let tmp = c.genx(ri) let tmp = c.genx(ri)
if le.typ.skipTypes(abstractVarRange).kind in {tyString, tyCString}: if le.sons[0].typ.skipTypes(abstractVarRange).kind in {tyString, tyCString}:
c.gABC(le, opcWrStrIdx, dest, idx, tmp) c.gABC(le, opcWrStrIdx, dest, idx, tmp)
else: else:
c.gABC(le, whichAsgnOpc(le, opcWrArr), dest, idx, tmp) c.gABC(le, whichAsgnOpc(le, opcWrArr), dest, idx, tmp)
@ -820,7 +829,6 @@ proc setSlot(c: PCtx; v: PSym) =
v.position = c.prc.maxSlots v.position = c.prc.maxSlots
c.prc.slots[v.position] = (inUse: true, kind: slotFixed) c.prc.slots[v.position] = (inUse: true, kind: slotFixed)
inc c.prc.maxSlots inc c.prc.maxSlots
echo v.name.s, " has position ", v.position
proc genVarSection(c: PCtx; n: PNode) = proc genVarSection(c: PCtx; n: PNode) =
for a in n: for a in n:

View file

@ -429,11 +429,17 @@ proc newStmtList*(stmts: varargs[PNimrodNode]): PNimrodNode {.compileTime.}=
proc newBlockStmt*(label, body: PNimrodNode): PNimrodNode {.compileTime.} = proc newBlockStmt*(label, body: PNimrodNode): PNimrodNode {.compileTime.} =
## Create a new block statement with label ## Create a new block statement with label
return newNimNode(nnkBlockStmt).add(label, body) return newNimNode(nnkBlockStmt).add(label, body)
proc newBlockStmt*(body: PNimrodNode): PNimrodNode {.compiletime.} = proc newBlockStmt*(body: PNimrodNode): PNimrodNode {.compiletime.} =
## Create a new block: stmt ## Create a new block: stmt
return newNimNode(nnkBlockStmt).add(newEmptyNode(), body) return newNimNode(nnkBlockStmt).add(newEmptyNode(), body)
proc newLetStmt*(name, value: PNimrodNode): PNimrodNode{.compiletime.} = proc newVarStmt*(name, value: PNimrodNode): PNimrodNode {.compiletime.} =
## Create a new var stmt
return newNimNode(nnkVarSection).add(
newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value))
proc newLetStmt*(name, value: PNimrodNode): PNimrodNode {.compiletime.} =
## Create a new let stmt ## Create a new let stmt
return newNimNode(nnkLetSection).add( return newNimNode(nnkLetSection).add(
newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value)) newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value))
@ -484,6 +490,22 @@ proc newProc*(name = newEmptyNode(); params: openarray[PNimrodNode] = [];
newEmptyNode(), newEmptyNode(),
body) body)
proc newIfStmt*(branches: varargs[tuple[cond, body: PNimrodNode]]):
PNimrodNode {.compiletime.} =
## Constructor for ``if`` statements.
##
## .. code-block:: nimrod
##
## newIfStmt(
## (Ident, StmtList),
## ...
## )
##
result = newNimNode(nnkIfStmt)
for i in branches:
result.add(newNimNode(nnkElifBranch).add(i.cond, i.body))
proc copyChildrenTo*(src, dest: PNimrodNode) {.compileTime.}= proc copyChildrenTo*(src, dest: PNimrodNode) {.compileTime.}=
## Copy all children from `src` to `dest` ## Copy all children from `src` to `dest`
for i in 0 .. < src.len: for i in 0 .. < src.len: