Skip to content

Commit

Permalink
Adjust for nnkCallKinds == CallNodes (#296)
Browse files Browse the repository at this point in the history
* Cheap guard adjustment

* See what CI thinks of this

* I believe these should be kept `nnkCallKinds`

* Use const instead of `(CallNodes - {nnkHiddenCallConv})`

* Remove guard as we're using a custom const now

---------

Co-authored-by: Smooth Operator <[email protected]>
  • Loading branch information
Gruruya and disruptek authored May 26, 2023
1 parent a89974c commit 0fe6a21
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cps.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ proc doWhelp(n: NormNode; args: seq[NormNode]): Call =
template whelpIt*(input: typed; body: untyped): untyped =
## Instantiate the given continuation call and inject `it` in the body.
var n = normalizeCall input
if n.kind in nnkCallKinds:
if n.kind in NormalCallNodes:
var it {.inject.} = doWhelp(n[0], n[1..^1])
body
NimNode it
Expand Down
2 changes: 1 addition & 1 deletion cps/hooks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ proc abbreviation(n: NimNode): NimNode =
n.name
of nnkSym, nnkIdent, nnkDotExpr:
n
of nnkCallKinds:
of NormalCallNodes:
n[0]
else:
n.errorAst "dunno how to abbreviate " & $n.kind
Expand Down
5 changes: 3 additions & 2 deletions cps/normalizedast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ from std/sequtils import anyIt, toSeq
from std/typetraits import distinctBase

from cps/rewrites import NormNode, normalizingRewrites, replace,
desym, resym, childCallToRecoverResult
desym, resym, childCallToRecoverResult,
NormalCallNodes

const
NilNormNode* = nil.NormNode
NilNimNode* = nil.NimNode

export NormNode
export NormNode, NormalCallNodes

# # Structure of the Module
# * distinct types representing normalized/transformed variants of distinct AST
Expand Down
2 changes: 1 addition & 1 deletion cps/returns.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ proc makeReturn*(contType: Name; n: NormNode): NormNode =
## generate a `return` of the node if it doesn't already contain a return
if n.firstReturn.isNil:
let toAdd =
if n.kind in nnkCallKinds:
if n.kind in NormalCallNodes:
n # what we're saying here is, don't hook Coop on magics
else:
Coop.hook:
Expand Down
8 changes: 5 additions & 3 deletions cps/rewrites.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type
## a normalized node, but this should not be useed directly, use a
## specialized type instead, see the `normalizedast` module.

const NormalCallNodes* = CallNodes - {nnkHiddenCallConv}

converter normNodeToNimNode(n: NormNode): NimNode =
## scope a converter to this module so it doesn't leak but we keep our sanity
## in `filter`, `normalizingRewrites`, etc below.
Expand Down Expand Up @@ -68,11 +70,11 @@ proc desym*(n: NimNode): NimNode =

proc childCallToRecoverResult*(n: NimNode; sym: NimNode; field: NimNode): NimNode =
## this is used to rewrite continuation calls into their results
if sym.kind notin nnkCallKinds:
if sym.kind notin NormalCallNodes:
raise Defect.newException: "resymCall is for calls, not " & $sym.kind
proc resymify(n: NimNode): NimNode =
case n.kind
of nnkCallKinds:
of NormalCallNodes:
if n == sym:
result = field
else:
Expand Down Expand Up @@ -358,7 +360,7 @@ proc workaroundRewrites(n: NimNode): NimNode =
proc workaroundSigmatchSkip(n: NimNode): NimNode =
## `sigmatch` skips any call nodes whose parameters have a type attached.
## We rewrites all call nodes to remove this data.
if n.kind in nnkCallKinds:
if n.kind in NormalCallNodes:
# We recreate the nodes here, to set their .typ to nil
# so that sigmatch doesn't decide to skip it
result = newNimNode(n.kind, n)
Expand Down
4 changes: 2 additions & 2 deletions cps/spec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ proc pragmaArgument*(n: NormNode; s: string): NormNode =
discard
if result.isNil:
result = n.errorAst "failed to find expected " & s & " form"
of nnkCallKinds:
of NormalCallNodes:
result = pragmaArgument(asCall(n).impl, s)
else:
result = n.errorAst "unsupported pragmaArgument target: " & $n.kind
Expand All @@ -355,7 +355,7 @@ proc bootstrapSymbol*(n: NimNode): NormNode =
## find the return type of the bootstrap
let n = NormNode n
case n.kind
of nnkCallKinds:
of NormalCallNodes:
bootstrapSymbol n[0]
of nnkSym:
bootstrapSymbol n.getImpl
Expand Down
3 changes: 0 additions & 3 deletions cps/transform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ export Continuation, ContinuationProc, cpsCall, cpsMustJump

#{.experimental: "strictNotNil".}

when CallNodes - {nnkHiddenCallConv} != nnkCallKinds:
{.error: "i'm afraid of what you may have become".}

proc annotate(parent: var Env; n: NormNode): NormNode

proc makeContProc(name, cont, contType: Name; source: NimNode): ProcDef =
Expand Down

0 comments on commit 0fe6a21

Please sign in to comment.