implemented write access to s[i] for macros

This commit is contained in:
Araq 2011-06-21 00:47:58 +02:00
commit cfb107f346
4 changed files with 51 additions and 25 deletions

View file

@ -355,25 +355,40 @@ proc evalFieldAccess(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
result = emptyNode result = emptyNode
proc evalAsgn(c: PEvalContext, n: PNode): PNode = proc evalAsgn(c: PEvalContext, n: PNode): PNode =
result = evalAux(c, n.sons[0], {efLValue}) var a = n.sons[0]
if isSpecial(result): return if a.kind == nkBracketExpr and a.sons[0].typ.kind in {tyString, tyCString}:
var x = result result = evalAux(c, a.sons[0], {efLValue})
result = evalAux(c, n.sons[1], {}) if isSpecial(result): return
if isSpecial(result): return var x = result
myreset(x) result = evalAux(c, a.sons[1], {})
x.kind = result.kind if isSpecial(result): return
x.typ = result.typ var idx = getOrdValue(result)
case x.kind
of nkCharLit..nkInt64Lit: result = evalAux(c, n.sons[1], {})
x.intVal = result.intVal if isSpecial(result): return
of nkFloatLit..nkFloat64Lit: if result.kind != nkCharLit: InternalError(n.info, "no character")
x.floatVal = result.floatVal
of nkStrLit..nkTripleStrLit: if (idx >= 0) and (idx < len(x.strVal)):
x.strVal = result.strVal x.strVal[int(idx)] = chr(int(result.intVal))
else: else:
if not (x.kind in {nkEmpty..nkNilLit}): stackTrace(c, n, errIndexOutOfBounds)
discardSons(x) else:
for i in countup(0, sonsLen(result) - 1): addSon(x, result.sons[i]) result = evalAux(c, n.sons[0], {efLValue})
if isSpecial(result): return
var x = result
result = evalAux(c, n.sons[1], {})
if isSpecial(result): return
myreset(x)
x.kind = result.kind
x.typ = result.typ
case x.kind
of nkCharLit..nkInt64Lit: x.intVal = result.intVal
of nkFloatLit..nkFloat64Lit: x.floatVal = result.floatVal
of nkStrLit..nkTripleStrLit: x.strVal = result.strVal
else:
if not (x.kind in {nkEmpty..nkNilLit}):
discardSons(x)
for i in countup(0, sonsLen(result) - 1): addSon(x, result.sons[i])
result = emptyNode result = emptyNode
assert result.kind == nkEmpty assert result.kind == nkEmpty

View file

@ -40,7 +40,7 @@ proc merge[T](a, b: var openArray[T], lo, m, hi: int,
cmp: proc (x, y: T): int, order: TSortOrder) = cmp: proc (x, y: T): int, order: TSortOrder) =
template `<-` (a, b: expr) = template `<-` (a, b: expr) =
when onlySafeCode: when onlySafeCode:
a = b shallowCopy(a, b)
else: else:
copyMem(addr(a), addr(b), sizeof(T)) copyMem(addr(a), addr(b), sizeof(T))
# optimization: If max(left) <= min(right) there is nothing to do! # optimization: If max(left) <= min(right) there is nothing to do!
@ -54,7 +54,7 @@ proc merge[T](a, b: var openArray[T], lo, m, hi: int,
when onlySafeCode: when onlySafeCode:
var bb = 0 var bb = 0
while j <= m: while j <= m:
b[bb] = a[j] b[bb] <- a[j]
inc(bb) inc(bb)
inc(j) inc(j)
else: else:
@ -74,7 +74,7 @@ proc merge[T](a, b: var openArray[T], lo, m, hi: int,
# copy rest of b: # copy rest of b:
when onlySafeCode: when onlySafeCode:
while k < j: while k < j:
a[k] = b[i] a[k] <- b[i]
inc(k) inc(k)
inc(i) inc(i)
else: else:

View file

@ -475,9 +475,9 @@ elif not defined(useNimRtl):
result.exitCode = -3 # for ``waitForExit`` result.exitCode = -3 # for ``waitForExit``
if pipe(p_stdin) != 0'i32 or pipe(p_stdout) != 0'i32 or if pipe(p_stdin) != 0'i32 or pipe(p_stdout) != 0'i32 or
pipe(p_stderr) != 0'i32: pipe(p_stderr) != 0'i32:
OSError("failed to create a pipe") OSError()
var Pid = fork() var Pid = fork()
if Pid < 0: OSError("failed to fork process") if Pid < 0: OSError()
if pid == 0: if pid == 0:
## child process: ## child process:

View file

@ -1,6 +1,5 @@
High priority (version 0.8.12) High priority (version 0.8.12)
============================== ==============================
* implement write access to ``s[i]`` for macros
* implement message passing built-ins * implement message passing built-ins
* add --deadlock_prevention:on|off switch? timeout for locks? * add --deadlock_prevention:on|off switch? timeout for locks?
* built-in serialization * built-in serialization
@ -20,6 +19,18 @@ version 0.9.0
- fix overloading resolution - fix overloading resolution
- make ^ available as operator - make ^ available as operator
- implement closures; implement proper coroutines - implement closures; implement proper coroutines
- rethink comment syntax; people want::
type
TConfig* = object
limit*: int
outFile*: string
# Regex patterns to ignore. TLogEntry field -> regex pattern
# If this matches, the request will NOT be shown.
ignoreRe*: TTable[string, string]
I think a good compromise is to define positions for the docgen in the
grammar and ignore other comments everywhere.
Bugs Bugs
---- ----