Skip to content

Commit

Permalink
codegen: use stamp instead of quote on NimSkull
Browse files Browse the repository at this point in the history
NimSkull's `quote` is now a proper quasi-quoting operator and will not
perform template-like binding or gensym. This behavior is now moved to
the `stamp` macro.

This commit replaces `quote` with `stamp` on NimSkull where applicable.
  • Loading branch information
alaviss authored and zevv committed Aug 22, 2024
1 parent bb0ce63 commit d8306be
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/npeg/codegen.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import macros
import macros except quote, stamp
import strutils
import tables
import npeg/[common,patt,stack,capture]
Expand Down Expand Up @@ -40,6 +40,12 @@ type
else:
fn_run*: proc(ms: var MatchState[S], s: openArray[S], u: var T): MatchResult[S]

when declared(macros.stamp): # nimskull
template quote(body: untyped): NimNode =
macros.stamp(body)
else:
template quote(body: untyped): NimNode =
macros.quote(body)

# This macro translates `$1`.. into `capture[1].s`.. and `@1` into `capture[1].si`
# for use in code block captures. The source nimnode lineinfo is recursively
Expand Down Expand Up @@ -394,7 +400,7 @@ proc genCode*(program: Program, sType, uType, uId: NimNode): NimNode =
push(result.precStack, 0)


proc fn_run(`ms`: var MatchState, `s`: openArray[`sType`], `uId`: var `uType`): MatchResult {.gensym.} =
proc fn_run(`ms`: var MatchState[`sType`], `s`: openArray[`sType`], `uId`: var `uType`): MatchResult[`sType`] {.gensym.} =

# Create local instances of performance-critical MatchState vars, this
# saves a dereference on each access
Expand Down Expand Up @@ -446,5 +452,5 @@ proc genCode*(program: Program, sType, uType, uId: NimNode): NimNode =
result[0].addPragma(ident("gcsafe"))

when npegExpand:
echo result.repr
echo repr result

0 comments on commit d8306be

Please sign in to comment.