Skip to content

Commit

Permalink
rearranging dealloc arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Jul 31, 2021
1 parent 7a863c9 commit b957f99
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
11 changes: 6 additions & 5 deletions cps.nim
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ proc alloc*[T: Continuation](root: typedesc[T]; c: typedesc): c {.used, inline.}
## allocation.
new c

template dealloc*[T: Continuation](t: typedesc[T];
c: sink Continuation) {.used.} =
## Reimplement this symbol to customize continuation
## deallocation.
discard
proc dealloc*[T: Continuation](c: sink T; E: typedesc[T]): E {.used, inline.} =
## Reimplement this symbol to customize continuation deallocation;
## `c` is the continuation to be deallocated, while `E` is the type of
## its environment. This procedure should generally return `nil`, as
## its result may be assigned to another continuation reference.
nil

{.push experimental: "callOperator".}
template `()`(c: Continuation): untyped {.used.} =
Expand Down
6 changes: 2 additions & 4 deletions cps/hooks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ proc hook*(hook: static[Hook]; a, b: NormNode): NormNode =
NormNode newNilLit()
of Dealloc:
# dealloc(env_234234, continuation)
newStmtList [
Dealloc.entrace(a, b, newCall(hook.sym, a, b)),
NormNode newNilLit()
]
Dealloc.entrace a, b:
newCall(hook.sym, a, b)
else:
b.errorAst "the " & $hook & " hook doesn't take two arguments"
2 changes: 1 addition & 1 deletion cps/returns.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ proc terminator*(c: Name; T: NormNode): NormNode =
## or simply set the fn to nil and return the continuation.
let coop = NimNode hook(Coop, asName"result")
let pass = NimNode hook(Pass, c, c.dot "mom")
let dealloc = NimNode hook(Dealloc, T, c)
let dealloc = NimNode hook(Dealloc, c, T)
let c = NimNode c
NormNode:
quote:
Expand Down
4 changes: 2 additions & 2 deletions tests/thooks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ suite "hooks":
block:
## custom continuation deallocators can nil the continuation
shouldRun 4:
proc dealloc[T: Cont](t: typedesc; c: sink T) =
proc dealloc[T: Cont](c: sink T; E: typedesc[T]): E =
ran()
c = nil

Expand All @@ -140,7 +140,7 @@ suite "hooks":
block:
## custom continuation deallocators work with whelp
shouldRun 4:
proc dealloc[T: Cont](t: typedesc; c: sink T) =
proc dealloc[T: Cont](c: sink T; E: typedesc[T]): E =
ran()
c = nil

Expand Down

0 comments on commit b957f99

Please sign in to comment.