Skip to content

Commit 5a1507c

Browse files
authored
cfg rewrite (#1083)
1 parent 6008dc1 commit 5a1507c

File tree

12 files changed

+659
-542
lines changed

12 files changed

+659
-542
lines changed

lib/std/memfiles.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ proc open*(filename: string, mode: FileMode = fmRead,
170170
if result.mem == nil:
171171
fail(osLastError(), "error mapping view")
172172

173-
var hi, low: int32
174-
low = getFileSize(result.fHandle, addr(hi))
173+
var hi {.noinit.}: int32
174+
let low = getFileSize(result.fHandle, addr(hi))
175175
if low == INVALID_FILE_SIZE:
176176
fail(osLastError(), "error getting file size")
177177
else:
@@ -235,7 +235,7 @@ proc close*(f: var MemFile) =
235235
## file system, if `f` was opened with write access.
236236

237237
var error = false
238-
var lastErr: OSErrorCode
238+
var lastErr {.noinit.}: OSErrorCode
239239

240240
when defined(windows):
241241
if f.wasOpened:

lib/std/parseutils.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ proc parseBiggestFloat*(s: openArray[char]; number: var BiggestFloat): int {.
243243
return i
244244

245245
# if failed: slow path with strtod.
246-
var t: array[500, char] # flaviu says: 325 is the longest reasonable literal
246+
var t {.noinit.}: array[500, char] # flaviu says: 325 is the longest reasonable literal
247247
var ti = 0
248248
let maxlen = t.len - 1 - "e+000".len # reserve enough space for exponent
249249

src/nimony/contracts.nim

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ proc checkReq(c: var Context; paramMap: Table[SymId, int]; req, call: Cursor): P
214214
else:
215215
result = Unprovable
216216

217+
proc analyseCall(c: var Context; n: var Cursor)
218+
217219
proc analyseExpr(c: var Context; pc: var Cursor) =
220+
#echo "analyseExpr ", toString(pc, false)
218221
var nested = 0
219222
while true:
220223
case pc.kind
@@ -236,8 +239,11 @@ proc analyseExpr(c: var Context; pc: var Cursor) =
236239
dec nested
237240
inc pc
238241
of ParLe:
239-
inc nested
240-
inc pc
242+
if pc.exprKind in CallKinds:
243+
analyseCall c, pc
244+
else:
245+
inc nested
246+
inc pc
241247
if nested == 0: break
242248

243249
proc analyseCallArgs(c: var Context; n: var Cursor) =
@@ -567,7 +573,7 @@ proc traverseBasicBlock(c: var Context; pc: Cursor): Continuation =
567573
var nested = 0
568574
var pc = pc
569575
while true:
570-
#echo "PC IS: ", pc.kind
576+
#echo "Instruction is ", toString(pc, false)
571577
case pc.kind
572578
of GotoInstr:
573579
# Every goto intruction leaves the basic block.
@@ -632,12 +638,21 @@ proc traverseBasicBlock(c: var Context; pc: Cursor): Continuation =
632638
analyseCall c, pc
633639
skip pc
634640
skipParRi pc
635-
elif pc.exprKind == PragmaxX:
636-
inc pc
637-
skip pc # pragmas
638-
inc nested
639641
else:
640-
raiseAssert "BUG: unknown statement: " & toString(pc, false)
642+
case pc.exprKind
643+
of PragmaxX:
644+
inc pc
645+
skip pc # pragmas
646+
inc nested
647+
of DestroyX, CopyX, WasMovedX, SinkhX, TraceX:
648+
inc pc
649+
analyseExpr c, pc
650+
# don't assume arity here
651+
while pc.kind != ParRi:
652+
analyseExpr c, pc
653+
skipParRi pc
654+
else:
655+
raiseAssert "BUG: unknown statement: " & toString(pc, false)
641656
of DiscardS, YldS:
642657
inc pc
643658
analyseExpr c, pc
@@ -757,15 +772,14 @@ proc traverseProc(c: var Context; n: var Cursor) =
757772
inc n
758773
elif n.kind == ParRi:
759774
dec nested
760-
if nested == 0: break
761775
inc n
776+
if nested == 0: break
762777
else:
763778
inc n
764779
if nested == 0: break
765-
skipParRi n
766780
else:
767781
skip n # body
768-
skipParRi n
782+
skipParRi n # proc decl end
769783

770784
proc traverseToplevel(c: var Context; n: var Cursor) =
771785
case n.stmtKind

0 commit comments

Comments
 (0)