Skip to content

Instantly share code, notes, and snippets.

@mflamer
Created November 27, 2013 21:29
Show Gist options
  • Save mflamer/7683587 to your computer and use it in GitHub Desktop.
Save mflamer/7683587 to your computer and use it in GitHub Desktop.
proc enumConstructor(c: PContext, head: PNode): PNode =
var sym = lookUp(c, head.sons[0])
var val = lookUp(c, head.sons[1])
result = newNodeI(nkInfix, head.info)
result.addSon(newIdentNode(getIdent("or"), head.info))
result.addSon(newIntNode(nkIntLit, sym.position))
var x = newNodeIT(nkCast, head.info, getSysType(tyInt))
x.addSon(newNodeIT(nkType, head.info, getSysType(tyInt)))
var y = newNodeIT(nkAddr, head.info, x.typ)
y.addSon(newSymNode(val, head.info))
x.addSon(y)
result.addSon(x)
result = semExpr(c, result)
result.typ = sym.typ
result.typ.newSons(1)
result.typ.sons[0] = sym.ast.sym.typ
@mflamer
Copy link
Author

mflamer commented Nov 27, 2013

As of now this proc assumes the x in Just(x) is a sym we can take the addr of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment