Skip to content

Instantly share code, notes, and snippets.

@wecing
Last active August 29, 2015 13:56
Show Gist options
  • Save wecing/9127867 to your computer and use it in GitHub Desktop.
Save wecing/9127867 to your computer and use it in GitHub Desktop.
assembly level closure implementation (inspired by upvalues)
def f1():
x = 1
def f2():
y = 2
def f3():
return x+y
return f3
return f2
f1:
x = new Integer(1)
f2 = ([(&x, null)], f1$f2)
...
f2[0][0][1] = new (void*)
*f2[0][0][1] = x
f2[0][0][0] = &f2[0][0][1]
f1$f2:
y = new Integer(2)
f3 = ([arg0[0], (&y, null)], f1$f2$f3) # arg0 is the closure list
...
f3[0][1][1] = new (void*)
*f3[0][1][1] = y
f3[0][1][0] = &f3[0][1][1]
return f3
f1$f2$f3:
return *arg0[0][0] + *arg0[1][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment