Skip to content

Commit

Permalink
tweaks to better support cps on embedded (#318)
Browse files Browse the repository at this point in the history
* swap doAssert for macros.error

* allow omission of cpsWriteLine
  • Loading branch information
disruptek authored Feb 15, 2024
1 parent 0441782 commit 7cb9fcb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cps/normalizedast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,11 @@ iterator indexNamePairs*(n: VarLetTuple): (int, Name) =

proc newVarLetIdentDef*(kind: NimNodeKind, i: IdentDef): VarLetIdentDef =
## create a new VarLetIdentDef
doAssert kind in {nnkLetSection, nnkVarSection},
"kind must be nnkLetSection nnkVarSection, got: " & repr(kind)
newTree(kind, i).VarLetIdentDef
if kind notin {nnkLetSection, nnkVarSection}:
error "kind must be nnkLetSection nnkVarSection, got: " & repr(kind)
else:
result = newTree(kind, i).VarLetIdentDef

proc newVarLetIdentDef*(kind: NimNodeKind, name: Name,
typ: TypeExprLike, val: NimNode): VarLetIdentDef =
## create a new VarLetIdentDef
Expand Down
4 changes: 3 additions & 1 deletion cps/spec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,12 @@ when defined(js):
template cpsWriteLine(s: string): untyped =
## javascript emission of traceback
console.error s
else:
elif cpsTraceDeque or cpsStackFrames:
template cpsWriteLine(s: string): untyped =
## non-javascript emission of traceback
stdmsg().writeLine line
else:
template cpsWriteLine(s: string): untyped = discard

proc writeStackFramesImpl(c: Continuation) =
for line in c.renderStackFramesImpl.items:
Expand Down

0 comments on commit 7cb9fcb

Please sign in to comment.