ale
ale copied to clipboard
Error while extending Ale: "undefined: encoder.Type"
Hi, This is a late night experiment with Ale, initiated by the blog post https://www.ale-lang.org/extending/
Here's what I (have been told. to) do
import "github.com/kode4food/ale/compiler/encoder"
import "github.com/kode4food/ale/compiler/generate"
import "github.com/kode4food/ale/data"
import "github.com/kode4food/ale/runtime/isa"
func FastAdd(e encoder.Type, args ...data.Value) {
e.Emit(isa.Zero) // step 1
for _, arg := range args {
generate.Value(e, arg) // step 2
e.Emit(isa.Add) // step 3
}
}
// step4 -- somewhere else
env.GetRoot().Declare("fast+").Bind(encoder.Call(FastAdd))
And heres the error I get:
lab.go:12:16: undefined: encoder.Type
lab.go:34:52: cannot convert FastAdd (type func(<T>, ...data.Value)) to type encoder.Call
Or is https://www.ale-lang.org/ffi/ now the way to extend?
Hi, so sorry about taking so long to get back to you. I never got a notification about this issue.
The problem is that I renamed Type to Encoder at some point, but forgot to update the blog post.
That's my bad, sorry. Will go and update the blog article now.
The FFI interface will make it easier to take Go types and use them from Ale, but it won't allow you to extend at the compiler level, which should almost never be necessary. Because FFI is using reflection, it will definitely be slower than the encoder interface.