Skip to content

Commit

Permalink
port discriminator bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Jul 31, 2021
1 parent e2b81bd commit f97b1fb
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions frosty.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ type
Read = "deserialize"
Write = "serialize"

proc operation(n: NimNode): Op =
case n.kind
of nnkSym, nnkIdent, nnkOpenSymChoice:
case repr(n)
of "serialize": result = Write
of "deserialize" : result = Read
else: error"unrecognized operation"
of CallNodes:
result = operation n[0]
else: error "unrecognized input: " & treeRepr(n)

proc serialize[T](s: var Serializer; o: ref T)
proc deserialize[T](s: var Serializer; o: var ref T)
proc forObject(s, o, tipe: NimNode; call: NimNode): NimNode
Expand Down Expand Up @@ -79,10 +90,15 @@ proc eachField(n, s, o: NimNode; call: NimNode): NimNode =
of nnkRecCase:
let kind = node[0][0]
result.insert 0:
genAst(call, s, o, kind, temp = nskTemp.genSym"kind", tipe = node[0][1]):
var temp: tipe
call(s, temp)
o.kind = temp
case call.operation
of Read:
genAst(call, s, o, kind,
temp = nskTemp.genSym"kind", tipe = node[0][1]):
var temp: tipe
call(s, temp)
o.kind = temp
of Write:
newCall(call, s, o.dot kind)
let kase = nnkCaseStmt.newTree(o.dot kind)
for branch in node[1 .. ^1]: # skip discriminator
let clone = copyNimNode branch
Expand Down

0 comments on commit f97b1fb

Please sign in to comment.