Commit Graph

431 Commits

Author SHA1 Message Date
Marc Vertes
d055747bef chore: run _test/*.go as tests, not examples (#134) 2019-03-28 17:38:51 +01:00
Marc Vertes
47faed9853 refactor: package is a symbol kind (#142) 2019-03-22 10:44:06 +01:00
Marc Vertes
cac2a2c547 refactor: define fset in Interpreter rather than Node struct (#141) 2019-03-22 10:34:52 +01:00
Marc Vertes
e766c272ed fix: handle append a string to a byte array (#133) 2019-03-22 10:27:02 +01:00
Marc Vertes
3616fb1b82 fix: handle method as function expression (#132) 2019-03-22 10:17:33 +01:00
Fernandez Ludovic
12b608b625 chore: rename to yaegi. 2019-03-20 10:15:35 +01:00
Marc Vertes
fa5b30d568 feat: add support for labeled statements (#123) 2019-03-20 10:04:00 +01:00
Ludovic Fernandez
7e07a183ed chore: support go1.11 and go 1.12. (#130)
* feat: support go1.11 and go 1.12.

* chore: generate.

* fix: build constraint.

* exclude importer.For

* generate go 1.11
2019-03-19 22:08:17 +01:00
Marc Vertes
53cdd0f2b0 fix: support aliased types for composite literal expressions (#129) 2019-03-19 14:57:04 +01:00
Marc Vertes
68d7890775 feat: add support for builtins complex, real and imag (#128) 2019-03-19 13:41:34 +01:00
Marc Vertes
8717f1ef4b fix: correct append with variadic parameters and spread array (#124)
* fix: correct append with variadic parameters and spread array
* feat: add print builtin
2019-03-19 12:25:04 +01:00
Marc Vertes
70fab221de feat: add support for builtin delete (#127) 2019-03-19 12:14:44 +01:00
Marc Vertes
b8927e3ca6 feat: add support for builtin copy (#126) 2019-03-19 01:19:43 +01:00
Marc Vertes
a1bfe7c989 feat: add support for builtin new (#125) 2019-03-19 01:12:25 +01:00
Marc Vertes
6a546062c1 fix: handle status in chan received when used in select (#122)
Also do not skip related tests
2019-03-17 17:36:58 +01:00
Marc Vertes
c773ad81d0 fix: return values of binary calls were not passed in nested calls (#121) 2019-03-17 15:51:28 +01:00
Marc Vertes
1ccc36a690 feat: implement support of 'for x := range channel' expression (#119) 2019-03-16 18:36:44 +01:00
Marc Vertes
839987c4cf feat: add support for 'msg, ok := <-channel' expression (#117) 2019-03-16 17:50:23 +01:00
Marc Vertes
842d22a8c2 feat: type checking for binary operators (#116)
Catch illegal combinations for all binary operators.
Memoize type conversion to reflect.type.
Add some unit tests for arithmetic and assign operations.
2019-03-15 09:34:01 +01:00
Marc Vertes
5a10046944 feat: simplify Use() (#115)
Change API from
func Use(val libValueMap, typ libTypeMap)
to
func Use(val libValueMap)
2019-03-13 12:24:59 +01:00
Marc Vertes
6657e9a18b feat: add support for named output variables (#113)
* feat: add support for named output variables

Function output parameters are located at the start of the function
frame, uninitialized, as they could be only set through return
statements.

Supporting named output variables requires to:

- identify and allocate symbols corresponding to output names:
  done at ident parsing, with the funcRet() helper,

- compute the location of output name in the frame:
  done with retRank() helper,

- initialize the frame entry with the zero value of symbol type,
  as the symbol can be accessed and written at multiple times,
  and return not setting the variable (opposite to unnamed).
  Done with frameType() helper, which now takes into account
  output parameters.

* refactor: simplify memory management

Perform function frame analysis at pre-order, instead of post-order, to
initialize memory frame, and track value types. Remove all operation
involving unitialized types. Frame memory layout is now build
incrementally, instead of having to perform dedicated tree walks on AST.
2019-03-12 19:58:02 +01:00
Marc Vertes
22a6d011f4 fix: handle method on interface type objects (#112)
Define a new Method action to detect method calls on interface types.
In this case the receiver is resolved from a dynamic type rather than a static one.

Handle method calls where receiver is a pointer.

In typeAssert, always return an interface value with the concrete type, to fix method lookup on interface objects.

Add relevant tests.
2019-03-04 18:51:48 +01:00
Marc Vertes
80f20189b4 test: refactor eval tests (#111)
evalCheck is renamed in eval.

Add testCase struct to describe test cases. A "pre" function can be
invoked prior to run the eval script which generate the result.

A runTests function executes all tests in a testCase array.  Parallel
sub-tests execution  is disabled, as simultaneous compile operations
in the same interpreter context is not yet safe.

Many simple tests can now be describe in one-liners.
2019-02-27 13:29:27 +01:00
Marc Vertes
f60fe68471 feat: wrapper to allow interpreter values to satisfy Go interfaces (#107)
A Wrap represents the wrapper which allows objects created by the
interpreter to satify Go interfaces (despite limitations in reflect
which forbid dynamic method creation).

All the struct fields are functions, where the fied name corresponds
to the method name prefixed by "Do". The function signature must
be the same as the interface one.

A corresponding Wrap method Xyz which satisfies the interface must
exist and must invoke the DoXyz function.

To be usable, the interpreter should return a Wrap instance with
the relevant function fields filled. The application can then invoke
methods on it.  The method calls will be forwarded to the interpreter.

Only the Wrap type definition needs to be exported to the interpreter
(not the interfaces and methods definitions)

A complete working example test is provided, and necessary corrections
in binary struct fields as functions.
2019-02-26 14:31:59 +01:00
Marc Vertes
e081b7a86b fix: correct handling of strings in comparison operators (#110)
Add an iString() type helper function, and use it to define the correct
conversion value prior to compare. The correction is to be applied to all
comparison operators, so regenerate op.go.
2019-02-26 13:14:08 +01:00
Marc Vertes
005a3cf93c fix: catch mismatched types in binary operator expressions (#109)
The types of operands are checked prior to generate closures.

- test: improve evalCheck() to check against expected output and/or expected errors.
2019-02-26 11:08:57 +01:00
Marc Vertes
0fb2370c33 fix: handle type for unary expression (#108) 2019-02-25 15:38:48 +01:00
Marc Vertes
c8693ba672 fix: handle interspersed key-value expressions in literal array (#105) 2019-02-25 15:28:34 +01:00
Marc Vertes
2ef6e459e3 feat: support func fields in literal struct (#103)
* test: make select2 deterministic
2019-02-22 15:44:36 +01:00
Marc Vertes
99fe292e66 fix: make sure type is correctly computed when returning nil (#104) 2019-02-22 15:09:08 +01:00
Marc Vertes
84baf50370 feat: handle literal composite for struct of imported binary type (#101)
A compositeBin function is added to handle the case of binary type.
2019-02-22 00:19:16 +01:00
Marc Vertes
abe384a765 fix: correct handling of func in struct fields (#99)
Wrap functions in struct fields in `reflect.Value` to have a consistent
representation of function inside and outside the interpreter.

Teach assign to wrap a function node if destination is reflect.Value

The same needs to be done for composite literal, in a next commit.
2019-02-21 14:03:28 +01:00
Marc Vertes
80527bb903 fix: correct handling of struct init from sparse composite (#98)
The field index computed from the key value expression in sparse
composite literal was stored in `node.findex`, corrupting the memory
allocation. It is now stored in a local variable for immediate use.
2019-02-21 11:26:27 +01:00
Marc Vertes
32e0be8b4e fix: improve use of explicit nil (#96)
Type category `UnsetT` is renamed in `NilT`.
Catch invalid use of untyped nil in `:=` expression.
Convert nil to output parameter type when used in `return` expression.
Improve and add relevant unit tests.
2019-02-20 15:44:44 +01:00
Marc Vertes
5677e0501e fix: correct propagation of values during eval (#95)
Eval returns the value of the root node of AST, so ensure
that node values are propagated back to ExprStmt and BlockStmt,
which should be sufficient to handle evaluation of simple
statements.
2019-02-19 14:51:44 +01:00
Fernandez Ludovic
bd03b47c06 doc: add CI badge. 2019-02-17 01:50:34 +01:00
Marc Vertes
ef83e43bd7 feat: complete handling of switch case statements (#88) 2019-02-11 18:42:00 +01:00
Marc Vertes
6d21cefe75 fix: allow imported binary variables to be set (#85)
Change the way imported binary variables are imported, from
`reflect.ValueOf(val)` to `reflect.ValueOf(&val).Elem()`, to allow these
variables to be set from the interpreter.
Regenerate stdlib packages accordingly.
Ensure that binary value is forwarded if it exists.
Add tests.
2019-02-07 15:41:22 +01:00
Marc Vertes
a99fb98f84 fix: append() was not returning a type (#84)
append() now returns the underlying array type.
Method lookup was skipped for selector expression on arrays.
Pointer expression was incorrectly parsed as a dereference instead of
type expression.
2019-02-06 14:50:37 +01:00
Marc Vertes
17fa77c693 fix: implement handling of interface types (#80)
Methods are now resolved correctly on interface objects.
2019-02-06 10:21:25 +01:00
Marc Vertes
18330ad7f9 fix: function created by reflect.MakeFunc using closure had wrong type (#75)
Call genNodeWrapper on interpreted function returned by a closure,
itself being wrapped, to ensure that the function can be called from
binary, no matter the level of nesting closures.
2019-02-03 15:38:21 +01:00
Marc Vertes
6fc6560af3 fix: handle name import of src packages (#74)
Rename the package scope from internal package name to alias name.
Detect different packages in the same directory (forbidden by spec).
Update example to test named import.
2019-02-02 14:18:09 +01:00
Marc Vertes
e347d35c24 fix: correct handling of sparse values in struct of implicit types (#73) 2019-02-01 14:51:17 +01:00
Ludovic Fernandez
27a338d84a fix: recursively search for packages. (#72) 2019-02-01 11:47:41 +01:00
Marc Vertes
1245e29a11 fix: handle implicit array types in composite litteral expressions (#66)
At CFG, in pre-order processing, determine the correct type of CompositeLitExpr from its first child (if it's a type) or from the ancestor node.
Make sure The type is propagated to children so the algorithm works recursively.

Fix also the isType() method to handle case of imported types,
either from source or binary packages.
2019-02-01 10:44:18 +01:00
Ludovic Fernandez
5ac3a6f92d refactor: speedup tests. (#68) 2019-01-30 22:00:02 +01:00
Marc Vertes
83bc9c5f05 fix: correct wireChild() in case of interleaving of var and func declarations (#65) 2019-01-29 20:51:25 +01:00
Marc Vertes
49c8c905d2 fix: ensure type computation in ValueSpec statement (#64)
Use nodeType in global var declaration to infer the type,
otherwise it may not be set properly, and failure will occur at use of variable.
2019-01-29 13:39:34 +01:00
Ludovic Fernandez
2059d58b0e test: add more tests. (#63) 2019-01-29 13:21:47 +01:00
Marc Vertes
0ab97e661f fix: correct type setting for rune characters (#61) 2019-01-28 16:33:48 +01:00