ale icon indicating copy to clipboard operation
ale copied to clipboard

Error while extending Ale: "undefined: encoder.Type"

Open bentxt opened this issue 2 years ago • 2 comments

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

bentxt avatar Feb 24 '22 00:02 bentxt

Or is https://www.ale-lang.org/ffi/ now the way to extend?

bentxt avatar Feb 24 '22 00:02 bentxt

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.

kode4food avatar May 05 '22 09:05 kode4food