Commit Graph

354 Commits

Author SHA1 Message Date
Marc Vertes
0bbdd37e55 fix: correct var creation from type convert (#172) 2019-04-25 10:56:55 +02:00
Marc Vertes
e8dfded66b fix: correct convert nil to type pointer (#166) 2019-04-23 11:04:47 +02:00
Marc Vertes
37f93f0392 fix: correct embedded method handling on hybrid struct (#162) 2019-04-19 18:30:04 +02:00
Marc Vertes
800ad0e557 fix: correct assign nil value to a variable (#164) 2019-04-19 18:15:02 +02:00
Marc Vertes
378252166b fix: correct assign from function call (#155)
The following changes should fix real and potential  problems
regarding how variables are set from function return values.

In assign from call expressions, Values in caller frame are now
directly assigned from function calls (call(), binCall() or builtins).
The assignement is performed with reflect Set methods or variants,
instead of "=" operator, to enforce runtime type checks.

The assignX() and assignX2() builtins are now removed in favor of
above method.

The representation of nil for pointer on struct has been fixed.

The identification of channel is fixed in for-range channel expression.
2019-04-16 15:22:17 +02:00
Marc Vertes
68e25cf68e fix: wrong returned type in define from function call in global context (#148) 2019-04-02 16:05:39 +02:00
Marc Vertes
e766c272ed fix: handle append a string to a byte array (#133) 2019-03-22 10:27:02 +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
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
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
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
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
ef83e43bd7 feat: complete handling of switch case statements (#88) 2019-02-11 18:42:00 +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
e347d35c24 fix: correct handling of sparse values in struct of implicit types (#73) 2019-02-01 14:51:17 +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
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
63732d4326 fix: set type correctly for variable declaration with assignment (#59)
Do not ignore type node when used in a variable declaration with assign.
The source node in a assign node can be the 2nd or the 3rd (the 2nd being the type).
2019-01-28 16:00:15 +01:00
Marc Vertes
5c79a97543 feat: add support for comparison of multiple types (#42)
The code for comparison operators is now generated by genop.
The support for multiple type has been added.
Missing operators <= and >= are now implemented.
2019-01-24 19:13:30 +01:00
Marc Vertes
9c310f12ed feat: add multiple type support for inc, dec (#39) 2019-01-24 11:50:32 +01:00
Marc Vertes
fe8c5191cd fix: implement missing defer of binary method (#33)
If the function to defer is a method of a binary object, the method
function must be resolved during defer. All other cases are already
handled.
2019-01-23 14:30:24 +01:00
Ludovic Fernandez
ff4e9b1918 fix: typo. (#31) 2019-01-23 09:50:44 +01:00
Marc Vertes
2619434b64 feat: Add support for missing assign operators (#30) 2019-01-22 19:08:15 +01:00
Marc Vertes
08f4aabdc0 feat: generate operator functions (#25)
Add `cmd/genop` program to generate operator functions in `interp/op.go`.

For each operator, determine its type, handle argument types conversion if necessary.

Arithmetic operators are added for now. Assign and comparison operators coming in a next commit.
2019-01-22 14:10:28 +01:00
Marc Vertes
2ef097e334 feat: better error handling in type parsing (#24)
When parsing types, instead of panic, set proper error and diagnostic with source location.
Propagate errors correctly.
2019-01-21 22:03:40 +01:00
Marc Vertes
015bff1599 feat: handle recover builtin (#13)
The recovered state is stored in `Frame`, and captured in `runCfg()`.
`assign()` has been modified to set handle `interface{}` type (not
possible with `reflect`.
2019-01-17 21:15:10 +01:00
Marc Vertes
098829d316 style: fix warnings from golangci-lint printed by make check (#11)
* style: fix warnings from golangci-lint printed by `make check`
* style: err assign in if block when possible. Better use of switch/case
* style: err assign in if block when possible
2019-01-16 18:59:24 +01:00
Marc Vertes
7987a97847 feat(ast): handle defer statement (#8) 2019-01-15 12:33:02 +01:00
Marc Vertes
bd15f88be6 feat: add support for select statement (#5)
* ast: improve error handling
* ast: handle select
* dyngo: set filename of executed script
* cfg: improve error reporting
* Implement select for receiving channels
* feat(select): add support for sending channels in case clauses
* test: improve tests on select
* feat(select): add support for "default" case
2019-01-09 17:45:38 +01:00
Fernandez Ludovic
3c00ca4469 fix: quick review. 2019-01-07 11:35:12 +01:00
Marc Vertes
27cbeef38d Methods created in the interpreter can now be used by runtime 2018-12-19 15:10:26 +01:00
Marc Vertes
6a397e2294 Fix golint warnings 2018-12-07 17:37:58 +01:00
Marc Vertes
ea07c12f56 Support incremental parse and eval, and interactive mode 2018-12-07 17:16:11 +01:00
Marc Vertes
6b013ffd35 Simplify export to runtime 2018-12-04 15:14:02 +01:00
Marc Vertes
e508591277 Compute frame types for binary wrapper around closures 2018-12-03 12:05:42 +01:00