* fix: make interpreter methods discoverable by runtime
When generating an interface wrapper, lookup existing wrappers by method
to get the one with the biggest set of methods implemented by interpreter.
A string method is also added to wrappers, in order to provide a string
representation of the interpreter value rather than the wrapper itself
(at least for %s and %v verbs).
This allows the runtime to pickup an interpreter method automatically
even if the conversion to the interface is not specified in the script. As
in Go spec, it is enough for the type to implement the required methods.
A current limitation is that only single wrappers can be instantiated,
not allowing to compose interfaces.
This limitation can be removed when the Go reflect issue
https://github.com/golang/go/issues/15924 is fixed.
Fixes#435.
* test: add a simpler test
* fix: detect default comm clause in select from AST
The heuristic to distinguish a default comm clause was too weak.
Make it robust by using AST.
Fixes#646.
* rename test to avoid conflict
* fix: perform send channel action for select
The CFG was wrong for select send comm clauses. If an init operation
on channel was required (like a derefence, index operation, ...) it
was skipped. The bug was invisible in case of a local var channel.
A send channel init operation consist to prepare both the data to
send (right subtree of send AST) and the channel itself (left
subtree of send AST). All channel init operation must be performed
prior to call select.
Fixes#647.
* doc: fix comment
* invert test to continue early
please note that this also changes the logic a little bit, since the
line that was:
if pn != nil {
now implictly becomes:
if an != nil && pn != nil {
(which I think is actually more correct).
* explicit chaining of init actions in select
* explicit chaining of init actions in select
Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
* fix: finish support of type assertions which was incomplete
TypeAssert was optimistically returning ok without verifying that
value could be converted to the required interface (in case of
type assert of an interface type), or not checking the type in
all conditions. There is now a working implements method for itype.
Fixes#640.
* style: appease lint
* fix: remove useless code block
* doc: improve comments
* avoid test conflict
* interp: detect local redecleration
Fixes#666
* make make check happy
* fix typo in filenames, add them to the exclusion list
Co-authored-by: Marc Vertes <mvertes@free.fr>
* fix: use interface wrappers to expose interface values to runtime
If a value is assigned to, or returned as, a binary interface,
then use the interface wrapper generator to convert the value
accordingly.
Fixes#630.
* test: rename NewFoo in Foo
* test: rename NewFoo in Foo
* fix: improve branch flow to reduce indentation
* fix: correct iterator in map range on binary values
The map range iterator was not initialized correctly for values
originating from runtime.
Fixes#641.
* test: deterministic output for map28.go