This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* return a closure that computes x + y when executed */ | |
func compile_add(x Closure, y Closure) -> Closure { | |
if (x.Type == y.Type) { | |
switch (x.Type) { | |
case types.Int: | |
/* both closures actually return an int, downcast them */ | |
var xe = type_cast(x, func () -> int) | |
var ye = type_cast(y, func () -> int) | |
/* create a closure that calls xe() and ye() and returns their sum */ | |
return func () -> int { |