Skip to content

Commit

Permalink
WIP: hexer can transform string case statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Feb 11, 2025
1 parent b56b1e9 commit 559f9a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/hexer/nifcgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import std / [hashes, os, tables, sets, assertions]
include nifprelude
import typekeys
import ".." / nimony / [nimony_model, programs, typenav, expreval, xints, decls, builtintypes, sizeof]
import basics, pipeline
from ".." / nimony / sigmatch import isSomeStringType
import basics, pipeline, stringcases


proc setOwner(e: var EContext; newOwner: SymId): SymId =
Expand Down Expand Up @@ -1130,7 +1131,19 @@ proc traverseIf(e: var EContext; c: var Cursor) =
wantParRi e, c
wantParRi e, c

proc traverseStringCase(e: var EContext; c: var Cursor): bool =
var n = c
inc n
let selectorType = getType(e.typeCache, c)
if isSomeStringType(selectorType):
transformStringCase(e, c)
result = true
else:
result = false

proc traverseCase(e: var EContext; c: var Cursor) =
if traverseStringCase(e, c):
return
e.dest.add c
inc c
traverseExpr e, c
Expand Down
17 changes: 17 additions & 0 deletions src/hexer/stringcases.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
#
# Hexer Compiler
# (c) Copyright 2025 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#

include ".." / lib / nifprelude
import basics

## Transforms string `case` statements to decision trees.

proc transformStringCase*(e: var EContext; c: var Cursor) =
discard

0 comments on commit 559f9a4

Please sign in to comment.