2016-07-28 19:57:17 +00:00
|
|
|
package expr
|
|
|
|
|
2016-08-05 18:34:17 +00:00
|
|
|
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{
|
2016-08-05 18:34:17 +00:00
|
|
|
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
|
|
|
}
|
2016-08-05 18:34:17 +00:00
|
|
|
return a, true
|
2016-07-29 00:39:18 +00:00
|
|
|
},
|
2016-07-28 19:57:17 +00:00
|
|
|
},
|
|
|
|
}
|