ginger/expr/macros.go

24 lines
583 B
Go
Raw Normal View History

2016-07-28 19:57:17 +00:00
package expr
import "llvm.org/llvm/bindings/go/llvm"
2016-07-28 19:57:17 +00:00
2016-07-29 00:39:18 +00:00
// RootCtx describes what's available to *all* contexts, and is what all
// contexts should have as the root parent in the tree
var RootCtx = &Ctx{
Macros: map[Macro]MacroFn{
"add": func(ctx *Ctx, lctx LLVMCtx, e Expr) (llvm.Value, bool) {
tup := e.Actual.(Tuple)
buildInt := func(e Expr) llvm.Value {
return lctx.B.CreateLoad(e.Actual.(Int).build(lctx), "")
}
a := buildInt(tup[0])
for i := range tup[1:] {
b := buildInt(tup[i+1])
a = lctx.B.CreateAdd(a, b, "")
2016-07-29 00:39:18 +00:00
}
return a, true
2016-07-29 00:39:18 +00:00
},
2016-07-28 19:57:17 +00:00
},
}