Skip to content

Instantly share code, notes, and snippets.

@tylereaves
Created December 2, 2013 15:13
Show Gist options
  • Save tylereaves/7750953 to your computer and use it in GitHub Desktop.
Save tylereaves/7750953 to your computer and use it in GitHub Desktop.
type
PNode = ref TNode
TNode = object
variant
of nkInt: val: int
of nkFloat: val: float
of nkString: val: string
of nkAdd, nkSub:
leftOp, rightOp: PNode
of nkIf:
condition, thenPart, elsePart: PNode
# create a new case object:
var n = nkIf(condition: nil)
# accessing n.thenPart is valid because the ``nkIf`` branch is active:
n.thenPart = nkFloat(val: 2.0)
var x = PNode(nkAdd(leftOp: PNode(nkInt(val: 4)),
rightOp: PNode(nkInt(val: 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment