91 Commits

Author SHA1 Message Date
Gaith Hallak
a4d1479cc5 Add fann type and to_fann fun 2023-06-09 13:17:04 +03:00
Gaith Hallak
7b6eba5319
Introduce contract-level compile-time constants (#432)
* Allow compile-time constants as toplevel declarations

* Remove the test that fails on toplevel consts

* Warn when shadowing a constant

* Allow records to be used as compile time constants

* Allow data constructors in compile-time constants

* Disable some warnings for toplevel constants

Since variables and functions cannot be used in the definition of
a compile time constants, the following warnings are not going to be
reported:

* Used/Unused variable
* Used/Unused function

* Do not reverse constants declarations

* Add tests for all valid expressions

* Add test for accessing const from namespace

* Revert "Do not reverse constants declarations"

This reverts commit c4647fadacd134866e4be9c2ab4b0d54870a35fd.

* Add test for assigining constant to a constant

* Show empty map or record error when assigning to const

* Report all invalid constant expressions before fail

* Allow accessing records fields in toplevel consts

* Undo a mistake

* Add test for warning on const shadowing

* Show error message when using pattern matching for consts

* Remove unused error

* Ban toplevel constants in contract interfaces

* Varibles rename

* Change the error message for invalid_const_id

* Make constants public in namespaces and private in contracts

* Add a warning about unused constants in contracts

* Use ban_when_const for function applications

* Test for qualified access of constants in functions

* Add failing tests

* Add test for the unused const warning

* Update CHANGELOG

* Update all_syntax test file

* Treat expr and type inside bound as bound

* Allow typed ids to be used for constants

* List valid exprs in the error message for invalid exprs

* Fix tests

* Update the docs about constants

* Update syntax docs

* Check validity of const exprs in a separate functions

* Call both resolve_const and resolve_fun from resolve_var
2023-04-12 14:20:41 +03:00
Gaith Hallak
09638daa90
Return mapping from variables to registers in fate compilation (#411)
* Return mapping from variables to registers

* Fix dialyzer issues

* Record real names

* Report saved fresh names as part of fcode env

* Undo whitespace changes

* Fix dialyzer warnings

* Formatting fix

* Use function names as strings

* Manually handle making function names

* Update CHANGELOG

* Make variables registers optional

* Update docs about the new flag

* Remove empty saved_fresh_names map from fcode env
2022-10-25 09:42:02 +03:00
Gaith Hallak
c1c169273c
Add options to enable/disable certain optimizations (#409)
* Add flags to enable/disable specific optimizations

* Fix typos

* Enable/disable scode optimization

* Update CHANGELOG.md

* Remove optimize_all option
2022-08-30 10:14:46 +03:00
Gaith Hallak
c98ea25e8b
Fix: Get the type of Chain.create() from its application (#407)
* Get the type of Chain.create() from its application

* Add test contract

* Update CHANGELOG.md

* Update the tests

* Update tests again
2022-08-03 22:24:22 +02:00
Gaith Hallak
381a7c98cd
Handle all user generated code errors in the type checker (#394)
* Move the missing_definition error to the type checker

* Move the parameterised_event and parameterised_state errors to the type checker

* Remove check_state_and_event_types from ast_to_fcode

* Move missing_init_function to the type checker

* Remove the code error last_declaration_must_be_main_contract

* Expand the tests for missing init function

* Remove found_void error

* Move the higher order entrypoint error to type checker

* Move invalid_aens_resolve_type error to type checker

* Add more tests for AENS.resolve

* Add test for AENS.resolve with using

* Move invalid_oracle_type error to type checker

* Move old code errors tests to compilable_contracts

* Remove the file aeso_code_errors.erl

* Add comment about state type
2022-07-25 19:48:46 +04:00
Radosław Rowicki
4bec4e5107
Added support for EXIT op (#397)
* EXIT op

* changelog

* docs

* Update CHANGELOG.md
2022-07-08 15:56:29 +02:00
Gaith Hallak
e46226a693
Polymorphism support (#357)
* Add polymorphism to syntax tree and parser

* Add polymorphism to infer types

* Fix pretty printing

* Add new tests and fix old tests

* Fix the comparison between unit and empty tuple

* Report undefined interface errors before checking implemented interfaces

* Add test for implementing multiple interfaces

* Add test for implementing two interfaces with entrypoints of same names and different types

* Add tests for interfaces implementing interfaces

* Draft: Add variance switching

* Revert "Draft: Add variance switching"

This reverts commit 92dc6ac169cfbff447ed59de04994f564876b3fb.

* Add variance switching

* Fix broken tests

* Fix broken abi tests

* Add tests for variance switching

* Fix tests after rebase

* Variance switching for custom datatypes

* Fix dialyzer warning

* Add testing for custom types variance switching

* Make opposite_variance a separate function

* Make is_subtype/4 a separate function

* Fix warning

* Mark tvars as invariant

* Add type_vars_uvar ets table to ets_tables()

* Don't destroy and recreate type errors table when not needed

* Fixes from the reviews

* Use is_list to check if a var is a list

* Compare named args in fun_t

* Test only for covariance and contravariance

* Remove arrows_in_type and use infer_type_vars_variance instead

* Add tests for option and type aliases

* Fix previous commit

* Rename check_implemented_interfaces_recursive to check_implemented_interfaces1

* Make interfaces declare functions from extended interfaces

* Restore test.aes

* Add test for variance switching in records

* Enable variance switching for record types

* Handle builtin types type variables separately

* Add tests for oracles and oracle queries

* Replace compare_types with non-throwing version of unify

* Add the context to unification error

* Test variance switching for bivariant records

* Give clear names to the records in records variance switching test

* Handle comments about polymorphism_variance_switching.aes

* Rename datatypes in custom types variance switching test for readability

* Change the variance of the oracle_query type vars

* Add test for accessing maps with the wrong type

* Default to invariant when the variance of the type vars is unknown

* Rename test files to have common prefix

* Rename functions in variance switching tests for readability

* Fix variance inference

* Eliminate redundant tests

* Test all cases for bivariant
2022-06-17 13:09:07 +04:00
Radosław Rowicki
0af45dfd19
Deprecate AEVM (#375)
* Deprecate AEVM

* Fix test, changelog

* Restore old rebar

* rebar lock fix

* undo export

Co-authored-by: Gaith Hallak <gaithhallak@gmail.com>

* undo export

Co-authored-by: Gaith Hallak <gaithhallak@gmail.com>

* Solve GH suggestions

* Fix the docs

* update docs

* Remove unused tests

* undo weird change

Co-authored-by: Gaith Hallak <gaithhallak@gmail.com>
2022-05-10 15:33:59 +02:00
Gaith Hallak
74aff5401b
Introduce pipe operator |> (#371)
* Add pipe operator

* Add tests

* Update docs and CHANGELOG
2022-04-12 12:40:32 +03:00
Gaith Hallak
a982f25262
Pattern guards for functions and switch statements (#339)
* Add case guards to parser

* Add pattern guards to infer types and fcode generation

* Add functions guards

* Add test for patterns guards

* Update docs

* Update CHANGELOG.md

* Remove stateful context from Env for guards

* Elaborate on guards

* Add failing test for stateful pattern guards

* Implement multiple guards

* Fix tests

* Disable aevm related tests

* Split the sentence before if and otherwise

* Fix type in docs

* Implement multiple exprs in the same guard

* Fix pretty printing

* Change tests to include multiple guards

* Add test for non-boolean guards

* Desugar clauses with guards

* Fix incomplete patterns bug

* Fix docs

* Compile to icode when no guards are used

* Revert "Disable aevm related tests"

This reverts commit e828099bd97dffe11438f2e48f3a92ce3641e85b.
2021-10-20 11:04:00 +03:00
Hans Svensson
6d79d2d558
GH344 - Add builtin types in decoder (#345)
* Only use basic types in type_env

* Add builtin types to the calldata/result decoder for FATE
2021-09-30 19:11:00 +02:00
Gaith Hallak
e8a171dc45
Allow assigning patterns to variables (#336)
* Change syntax tree and parser

* Add assign pattern to type inference

* Use check_expr instead of hard-coded type

* Add fcode generation for assign pattern

* Implement rename_spat for assign pattern

* Add tests

* Update CHANGELOG.md

* Update docs and changelog

* Add letpat to aeso_syntax_utils:fold

* Use Plus instead of Scoped
2021-09-11 16:18:30 +02:00
Ulf Norell
d07b321b25 Fix #324: bug when compiling default init in the presence of child contracts 2021-07-05 09:29:43 +02:00
Radosław Rowicki
e8b32a6875
Call.fee (#313)
* Call.fee

* nice align
2021-05-24 14:30:57 +02:00
Radosław Rowicki
1d9f59fec3
Contract factories and bytecode introspection (#305)
* Support for CREATE, CLONE and BYTECODE_HASH

* Add missing files

* Pushed the clone example through the typechecker

* CLONE compiles

* Fix dependent type in CLONE

* Bytecode hash fixes

* Refactor

* Refactor 2

* move some logic away

* Fixed some error messages. Type inference of child contract still does some random shit\n(mistakes arguments with result type)

* CREATE sometimes compiles and sometimes not

* Fix some scoping/constraint issues

* works, needs cleanup

* cleanup

* Fix some tests. Remove optimization of singleton tuples

* Fix default argument for clone

* Cleanup

* CHANGELOG

* Mention void type

* Address review, fix some dialyzer errors

* Please dialyzer

* Fix failing tests

* Write negative tests

* Docs

* TOC

* missing 'the'

* missing 'the'

* missing 'the'

* missing 'the'

* mention pre-fund

* format

* pre-fund clarification

* format

* Grammar in docs
2021-05-18 12:21:57 +02:00
radrow
ad78f440d9 Merge lima 2020-04-02 15:32:26 +02:00
Radosław Rowicki
4f554acee6
Fix error messages for some illegal constructions, fix absolute path includes (#251)
* Updated tests, banned type decls and toplevel letvals

* Properly ban nested contracts

* Fix including by path

* Fix error message test

* Fix prettpr attr display. Make dialyzer happy

* More tests

* Fixed type printing

* Updated docs
2020-03-30 14:52:16 +02:00
Ulf Norell
fe2d93ea8a Compile protected calls to CALL_PGR 2020-03-02 11:35:55 +01:00
Ulf Norell
ecbc15db1b Add 'protected' named argument to remote calls
If protected = true, the return type is wrapped in an option() which comes back
None if the remote call fails for any reason.
2020-03-02 08:51:33 +01:00
Hans Svensson
a38a365181 Change Char.to_lower/upper into String.to_lower/upper 2020-02-26 14:15:49 +01:00
Hans Svensson
b9acf24dca Make String.aes a stdlib + add more string functions
This means moving the FATE operations to StringInternal and adding to/from_list (and Char.to/from_int
+ Char.to_upper/lower).
2020-02-21 09:45:11 +01:00
Hans Svensson
bbc8555331 Auth.tx implementation and types
The arities field of the Chain.base_tx constructor is 22 integers long... This isn't very pretty but
that is the design we've chosen.
2020-02-11 10:00:46 +01:00
Hans Svensson
c3426f0e65 Add AENS.lookup
Also move Pointee-constructors inside AENS namespace.
2020-02-03 12:52:00 +01:00
Hans Svensson
db01e237c1 Add Oracle.expiry 2020-02-03 12:24:27 +01:00
Hans Svensson
d821de6381 Merge 'origin/lima' into 'origin/master' 2020-01-15 15:03:11 +01:00
Ulf Norell
4d4a14a9ab
GH-196 pattern matching lhs (#210)
* Allow block with separate type signature and definition of a function

For instance,
```
function
  add : (int, int) => int
  add(x, y) = x + y
```

cc #196

* Allow pattern matching in left-hand sides

* Changelog

* Fix type spec

* partial case-on-constructor

* Changelog for pattern-matching lets
2020-01-15 09:41:03 +01:00
Hans Svensson
cf1072140e Merge 'origin/lima' into merge_lima_to_master 2019-12-19 15:09:48 +01:00
Ulf Norell
b51a79b5e1 Allow patterns in lets and list comprehension binds 2019-12-16 17:04:49 +01:00
Ulf Norell
a403a9d227 Unbox singleton tuples and records 2019-12-10 12:24:05 +01:00
Hans Svensson
1c24a700dc Add BLS12-381 operations (to FATE) 2019-11-27 10:57:24 +01:00
Ulf Norell
bb1a45c557 Improve case-on-constructor optimisation 2019-11-26 13:10:58 +01:00
Ulf Norell
0a22c7a34a More let-floating 2019-11-26 13:10:58 +01:00
Ulf Norell
c8153f94a6 More aggressive freshening to avoid shadowing issues 2019-11-26 13:10:58 +01:00
Ulf Norell
63d51baaa3 Dialyzer issues 2019-11-26 13:10:58 +01:00
Ulf Norell
cb045b0256 whitespace 2019-11-26 13:10:58 +01:00
Ulf Norell
c84064da7f Inline local functions and simplify case-on-constructor 2019-11-26 13:10:58 +01:00
Ulf Norell
6c3932b10c Flattened state layout
... with necessary optimizations.
2019-11-26 13:10:56 +01:00
Ulf Norell
a8119f1219 Track state layout
... but only default layout still.
2019-11-26 13:10:04 +01:00
Ulf Norell
d0fdd06d66 Change get_state and set_state fcode primitives to take a register 2019-11-26 13:10:04 +01:00
Ulf Norell
e645a8d034 Optimize before lambda lifting
(lambdas are either in dead code or not dead, so dead code elimination won't be affected)
2019-11-26 13:10:04 +01:00
Ulf Norell
499e2f8200 Handle records and type aliases correctly in fcode 2019-11-26 13:10:04 +01:00
skkw
126e04ae42 support for AENS.update call 2019-11-12 14:27:46 +01:00
Ulf Norell
5fc6e18cd2 Add Address.to_contract
Casts an address to a (any) contract type.
2019-09-30 14:47:05 +02:00
Ulf Norell
3ea8470dc8 Compile Bytes.concat and split to FATE 2019-09-09 18:40:45 +02:00
Ulf Norell
157ffbf9e2 Fix bug with unapplied builtins taking typerep arguments
(Oracle builtins and AENS.resolve)
2019-09-04 10:20:04 +02:00
Ulf Norell
602e99512f Fail gracefully on higher-order state in AEVM and accept it in FATE 2019-09-03 17:24:40 +02:00
Ulf Norell
0b56691533 Tell dialyzer to bugger off 2019-09-03 14:36:36 +02:00
Ulf Norell
30de1db163 More code errors 2019-09-03 14:35:13 +02:00
Ulf Norell
510935d945 Framework and tests for code generation (icode/fcode) errors 2019-09-03 14:35:13 +02:00