Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Nov 16, 2020
1 parent cb234ba commit 3e9c95c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

- Added `nim --eval:cmd` to evaluate a command directly, see `nim --help`.

- VM now supports `addr(mystring[ind])` (index + index assignment)


## Tool changes
Expand Down
20 changes: 5 additions & 15 deletions compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import

from semfold import leValueConv, ordinalValToString
from evaltempl import evalTemplate
import magicsys
from magicsys import getSysType

const
traceCode = defined(nimVMDebug)

Expand Down Expand Up @@ -678,34 +679,23 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
regs[ra].intVal = s[idx].ord
else:
stackTrace(c, tos, pc, formatErrorIndexBound(idx, s.len-1))
of opcLdStrIdxAddr: # like opcLdArrAddr
# a = addr(b[c])
# xxx factor
# decodeBC(rkNodeAddr)
# decodeBC(rkInt) # xxx rkPtrInt ?
of opcLdStrIdxAddr:
# a = addr(b[c]); similar to opcLdArrAddr
decodeBC(rkNode)
# dbg regs[ra].typ
if regs[rc].intVal > high(int):
stackTrace(c, tos, pc, formatErrorIndexBound(regs[rc].intVal, high(int)))
let idx = regs[rc].intVal.int
let s = regs[rb].node.strVal.addr # or `byaddr`
if idx <% s[].len:
# regs[ra].intVal = cast[int](s[][idx].addr)
# `makePtrType` not accessible from vm.nim
let typ = newType(tyPtr, nextId c.idgen, c.module.owner)
# let typ = newType(tyPtr, nextId c.idgen, getCurrOwner(c))
typ.add getSysType(c.graph, c.debug[pc], tyChar)
# let typ = makePtrType(c, getSysType(c.graph, c.debug[pc], tyChar))
let node = newNodeIT(nkIntLit, c.debug[pc], typ) # xxx nkPtrLit
# let node = newNode(nkIntLit) # xxx nkPtrLit
# xxx info
# node.intVal = cast[ptr int](node.intVal)[]
node.intVal = cast[int](s[][idx].addr)
node.flags.incl nfIsPtr
# node.intVal = cast[int](s[][idx].addr)
regs[ra].node = node
else:
stackTrace(c, tos, pc, formatErrorIndexBound(idx, s[].len-1))

of opcWrArr:
# a[b] = c
decodeBC(rkNode)
Expand Down

0 comments on commit 3e9c95c

Please sign in to comment.