Louis-Vincent Boudreault [Thu, 12 Sep 2019 15:14:05 +0000 (11:14 -0400)]
Callref expressions support for Erasure Compiler
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Louis-Vincent Boudreault [Thu, 12 Sep 2019 15:10:06 +0000 (11:10 -0400)]
Callref expressions support for Global Compiler
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Louis-Vincent Boudreault [Thu, 12 Sep 2019 15:01:50 +0000 (11:01 -0400)]
Callref expression support for Separate Compiler.
- Added test case in `src/compiler/test_callref.nit`
- Updated the API of `AbstractCompiler` to support routine reference
call and instantiation services.
- Implemented routine reference (callrefs) handling for separate
compiler
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Louis-Vincent Boudreault [Wed, 11 Sep 2019 17:08:45 +0000 (13:08 -0400)]
Callref expression support for the interpreter
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Jean Privat [Wed, 2 Oct 2019 18:38:19 +0000 (14:38 -0400)]
Merge: nitunit the manual
Since the manual is now back in the repository, just use niunit to check the example.
Some examples needed to be updated
* renaming things to avoid conflicts
* using real expression and statements (and not placeholders)
* add `nitish` for example with explicit static or dynamic errors
Pull-Request: #2795
Jean Privat [Wed, 2 Oct 2019 18:38:15 +0000 (14:38 -0400)]
Merge: contracts: fix usage of contract with `--erasure`
Moving the check if a contract is needed in the visitor to avoid the property creation without definition.
Pull-Request: #2798
Florian Deljarry [Tue, 1 Oct 2019 19:37:52 +0000 (15:37 -0400)]
contracts: fix usage of contract with `--erasure`
Moving the check if a contract is needed in the visitor to avoid the property creation without definition.
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Jean Privat [Mon, 30 Sep 2019 19:51:53 +0000 (15:51 -0400)]
manual: add nitish and avoid name conflicts
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 30 Sep 2019 19:51:26 +0000 (15:51 -0400)]
manual: fix float comparaison and print
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Fri, 27 Sep 2019 12:53:55 +0000 (08:53 -0400)]
manual: fix examples to be nitunitables
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 30 Sep 2019 19:00:39 +0000 (15:00 -0400)]
Merge: Contract: bug fix
This pr fix the bug when the contract is apply with generic or virtual type.
Pull-Request: #2794
Florian Deljarry [Mon, 30 Sep 2019 15:48:33 +0000 (11:48 -0400)]
tests: Add tests for generic and virtual types
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Mon, 30 Sep 2019 02:17:53 +0000 (22:17 -0400)]
src/contracts: Fix contracts on virtual and generic type
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Jean Privat [Fri, 27 Sep 2019 12:54:46 +0000 (08:54 -0400)]
Merge: Contract implementation
# Contract.
This pr is a copy of #2747 with some modifications. It has a dependency with the #2779 and #2788.
Adding programming by contract (Design by contract) in Nit language. Contracts works with nit annotations. I decided to cut the contract pr in a smaller part to facilitate reviewing (some feature are not available on it, see section futur feature).
## Annotations
To define a new contract you need to use the corresponding annotation. For example it's possible to define a contract that x parameter must be strictly greater than 5. To do it would be necessary to define the contract in the following way `expects(x > 5)`. All expressions returning a boolean (comparison...) can be used as a condition.
Three annotations were added:
- `expects` to indicate the conditions need to the execution of the methods
- `ensures` to indicate the conditions of guarantee at the end of the execution of the methods
- `no_contract` to remove the inherited contract
This syntaxe is choose because in the next version of c++ (20) (see [P1369](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1369r0.pdf) for a overview) the contract will be define with the keywords expects and ensures. So I think it would be interesting to keep the same principle. But if all nit developper prefer to use `require` and `ensure` it's fine to change it.
## Method contract (ensures, expects)
For each method it's possible to define preconditions (`expects`) and post-conditions (`ensures`). If the call of the method satisfies the prerequisites (`expects`) of the method, the caller may assume that the return conditions (`ensures`) will be satisfied.
The method contracts can access all the parameters of the method as well as the set of attributes/methods visible in the context of the method. i.e the set of parameters and the set of methods and attributes of the current class can be used (attributes declare locally in the method can not be used). For post-conditions (ensures) the `result` attribute has been added to perform a check on the return value of the method. Currently it's not possible to refer an old value in a ensures (exemple old(length) == length + 1).
## Process
### Building contract phase
A phase is executed to check all the methods. This check is done to know if:
- The method is annotated (redefined or not)
- The method is a redefinition of a method already having a contract (i.e a method that does not add any new conditions to the existing contract).
When a contract is detected the code is `extended` to add the verification features. Two methods are created. The first method is the contract face. Its goal is to provide the call of the contract verification and the call of the original method. With this strategy, the original code of the method is preserved. The second created method is for the contract verification.
#### Exemple
##### Expect:
```nit
class MyClass
fun foo(x: Int)
is
expects(x > 0)
do
[...]
end
end
```
Representation of the compiled class
```nit
class MyClass
fun foo(x: Int)
is
expects(x > 0)
do
[...]
end
fun _contract_foo(x: Int)
do
_expects_foo(x)
foo(x)
end
fun _expects_foo(x: Int)
do
assert x > 0
end
end
```
##### Ensure:
```nit
class MyClass
fun foo(x: Int): Bool
is
ensures(result == true)
do
[...]
return true
end
end
```
Representation of the compiled class
```nit
class MyClass
fun foo(x: Int): Bool
is
ensures(result == true)
do
[...]
return result
end
fun _contract_foo(x: Intl): Bool
do
var result = foo(x)
_ensures_foo(x, result)
return result
end
fun _ensures_foo(x: Int, result: Bool)
do
assert result == true
end
end
```
## Inheritance
Contracts support redefinition and adding condition. Note that when a contract is define in a parent class, it's no longer possible to remove this contract on all the classes that inherit or redefine them. They only need to be increased according to different subtyping rules.
All preconditions (expects) can be weakened. i.e it's possible to provide a new alternative to validate the contract. This corresponds to the use of a logical OR between the old and the new conditions.
All post-conditions (ensure) can be consolidate. i.e the new condition of the contract will provide a new guarantee to the user of the method. This rule can be translates into a logical AND between the old and the new conditions.
### Exemple
#### Expect
```nit
class SubMyClass
super MyClass
redef fun foo(x: Int)
is
expects(x > 0, x == 0)
do
[...]
end
redef fun _expects_foo(x: Int)
do
if x == 0 then return
super(x)
end
redef fun _contract_foo(x: Int)
do
_expects_foo
super(x)
end
end
```
#### Ensure
```nit
class SubMyClass
super MyClass
redef fun foo(x: Int): Bool
is
ensures(result == true, x > 0)
do
[...]
end
redef fun _ensures_foo(x: Int, result: Bool)
do
super
assert super(x, result)
end
redef fun _contract_foo(x: Int, result: Bool): Bool
do
var result = super
_ensures_foo(x, result)
return result
end
end
```
Summary
| Annotation | Inheritance condition type |
| ------------- | -------------|
| expects | and |
| ensures | or |
## Invocation
All calls to contract methods are intercepted to call the contract version. For the moment the contracts are systematically called, whether it's an internal or external call. Only calls to super do not execute the contracts.
This part is subject to evolution with a parameter to activate or not the internal call verification.
## Building
Since contracts are expensive in resource, several levels of use have been defined based on the needed verification:
- No contract: all contracts are disable (option `--no-contract`).
- Default: By default the contracts can be defined as "semi-global". I.E. All contracts (ensures, expects)used in the main package are enabled, the expects contracts are enabled (ensures contracts are disable) in direct imported package. Other indirected imported package doesn't have active contract.
- Full contract: Contracts are enable (ensures, expects) on all classes (option `--full-contract`).
## Future work
This pr has been simplified to facilitate the reviewing.
Future features:
- Support class invariant contracts
- Ability to put contracts on auto-getters and setter
- Detection of query or command to avoid the contract to change the object state (this functionality will probably be an advice because it's difficult to define if a method has no side effect.)
- `Old` support for the ensures contract to refer at the same value during the expects condition
Some pr will follow to use the contacts directly in the lib (collection...).
### Note
Currently the syntax of contracts is strict, only comparisons and method calls returning bouleans can be used. Indeed the arguments passed to the annotation of contract are directly used for assert. A solution would be given a more open syntax for more complex contracts instead of using a method. But this would cause problems in the syntax of annotations. If you have any suggestion don't hesitate. An issue is available to talk about the potential syntax. (#1340)
Pull-Request: #2790
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 26 Sep 2019 19:57:35 +0000 (15:57 -0400)]
manual: CI check with nitunit
Signed-off-by: Jean Privat <jean@pryen.org>
Florian Deljarry [Wed, 29 May 2019 20:49:55 +0000 (16:49 -0400)]
src/toolcontext: Provide contract options
`--no-contract` option to disable the contracts usage
`--full-contract` option to enable the contracts usage in all classes
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Wed, 29 May 2019 20:04:06 +0000 (16:04 -0400)]
share/man/nitc: Adding the man explication to disable contracts
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Fri, 19 Apr 2019 21:41:23 +0000 (17:41 -0400)]
contracts: Adding all contract generation mechanism
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Sat, 27 Apr 2019 21:46:35 +0000 (17:46 -0400)]
tests: adding contract testing files
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Jean Privat [Mon, 16 Sep 2019 14:34:36 +0000 (10:34 -0400)]
Merge: astbuilder: First implementation of clonable for ast nodes
## Astbuilder
- Now all the nodes of the ast is cloneable. Currently just a part of node have an implemented clone method.If we clone a node by default (not implemented) the program abort and print the following message: `The clone method is not implemented for ATestNode class.`. Currently the library is in **test** phase. You can have "maybe" some bug with the clone.
- Add a method to make the creation of a callsite easier.
## Futur work
Currently i am working on a test to make sure the result clone is the same as the original.
Pull-Request: #2779
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 16 Sep 2019 14:34:31 +0000 (10:34 -0400)]
Merge: Callref types
Extended the functional type hierarchy to include RoutineRef type (aka function pointer).
Added type resolution on callref expression :
```
import functional
fun toto(x: Int) do print x
var x = &toto
assert x isa ProcRef1[Int]
```
Pull-Request: #2791
Louis-Vincent Boudreault [Tue, 27 Aug 2019 19:17:48 +0000 (15:17 -0400)]
typing: Added typing resolution for `ACallrefExpr`
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Florian Deljarry [Wed, 28 Aug 2019 13:41:16 +0000 (09:41 -0400)]
tests: Add test_astbuilder to the skip list of nitcg niti nitvm
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Mon, 26 Aug 2019 21:05:20 +0000 (17:05 -0400)]
test_astbuilder: Add a testing tool for the astbuilder
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Tue, 13 Aug 2019 16:46:35 +0000 (12:46 -0400)]
astbuilder: First implementation of clonable for ast nodes
Add implementation of `clone` method for the ast nodes.
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Jean Privat [Thu, 5 Sep 2019 19:54:04 +0000 (15:54 -0400)]
Merge: Can comment annotations
This was hard but the solution is easier than expected.
Annotations accepted documentation comments but other comments were refused. This should allow all configuration of comments.
close #2786
Pull-Request: #2789
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Thu, 5 Sep 2019 19:53:59 +0000 (15:53 -0400)]
Merge: model: Add `mpackage` importation hierarchy
Added a `mpackage_importation_hierarchy` graph to keep the hierarchy of packages. The packages relations are defined when the `set_imported_mmodules` is called.
This pr is related to the programming by contract. The objective is to determine when the use of a contract is necessary in a given context.
Note in this graph all the packages are in relation with themself.
example for all nitc package hierarchy :
![](https://sendeyo.com/up/d/
514e168e33)
This pr has a dependency with the #2784
Pull-Request: #2788
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Thu, 5 Sep 2019 19:53:49 +0000 (15:53 -0400)]
Merge: Functional api
The functional API provides a type hierarchy for functional types, new `Iterator` services (like pipeline)
and in place `Map` manipulation through `Entry` API.
Pull-Request: #2759
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Florian Deljarry [Sun, 26 May 2019 17:17:09 +0000 (13:17 -0400)]
check_annotation: adding no_contract
Adding option to remove contract on a specific annotated method
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Thu, 25 Apr 2019 20:24:03 +0000 (16:24 -0400)]
check_annotation: Adding ensures annotation
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Fri, 19 Apr 2019 21:39:24 +0000 (17:39 -0400)]
check_annotation: Adding expects annotation
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Fri, 19 Apr 2019 21:38:42 +0000 (17:38 -0400)]
code_gen: Adding contracts phase
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Fri, 19 Apr 2019 21:32:27 +0000 (17:32 -0400)]
scope: Adding variable verification
If the variable already exists it will be used
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Fri, 19 Apr 2019 21:25:02 +0000 (17:25 -0400)]
modelize_property: Adding unsafe method to register an mpropdef
Add method to register an MPropDef with an APropdef without verification
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Louis-Vincent Boudreault [Tue, 27 Aug 2019 19:00:28 +0000 (15:00 -0400)]
functional: Added universal types to callref
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Louis-Vincent Boudreault [Fri, 5 Jul 2019 14:02:18 +0000 (10:02 -0400)]
functional: Added functional lib
- New types hierarchy to manage functions.
- New Pipeline-like API for `Iterator` based on functional type.
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Florian Deljarry [Wed, 28 Aug 2019 02:38:53 +0000 (22:38 -0400)]
nitweb: Update to use packages importation graph
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Wed, 28 Aug 2019 01:56:10 +0000 (21:56 -0400)]
nitdoc: Update to use packages importation graph
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Wed, 28 Aug 2019 01:12:32 +0000 (21:12 -0400)]
test_commands_catalog: Update to use packages importation graph
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Tue, 27 Aug 2019 23:41:22 +0000 (19:41 -0400)]
doc/static_structure: Update package importation graph
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Tue, 27 Aug 2019 21:17:29 +0000 (17:17 -0400)]
nitx: Remove the construction of packages importation graph
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Mon, 26 Aug 2019 15:07:18 +0000 (11:07 -0400)]
nitcatalog: Update to use the package graph
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Mon, 26 Aug 2019 15:04:20 +0000 (11:04 -0400)]
catalog: Update to use the package graph
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Mon, 26 Aug 2019 14:56:13 +0000 (10:56 -0400)]
digraph: Add feature to get all successors and predecessors
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Sat, 17 Aug 2019 17:40:54 +0000 (13:40 -0400)]
mmodule: Added support of package importation
Now when the imported `mmodules` is added to the `mmodule_importation_hierarchy`,
the `mmodules` package it's also added to `mpackage_importation_hierarchy`.
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Sat, 17 Aug 2019 17:34:29 +0000 (13:34 -0400)]
mpackage: Add `mpackage` importation graph
Add the attribute `mpackage_importation_graph`. Each package is in relation with itself.
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Jean Privat [Mon, 26 Aug 2019 21:09:44 +0000 (17:09 -0400)]
tests: add comments in syntax_annotations2.nit
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 26 Aug 2019 21:05:20 +0000 (17:05 -0400)]
parser: regenerate with comments in line annotations
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 26 Aug 2019 21:04:57 +0000 (17:04 -0400)]
grammar: enable full comments in line annotations (is ... end)
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 26 Aug 2019 15:22:34 +0000 (11:22 -0400)]
Merge: digraph: Implementation of a reflexive directed graph
Add the implementation of a reflexive directed graph. Added element is in relation with itself (ie if the graph has `u` node is implies `self.has_arc(u,u) == true`)
Pull-Request: #2784
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Fri, 23 Aug 2019 13:25:28 +0000 (09:25 -0400)]
Merge: Proposal for lambda expression syntax
This extends the Nit syntax with lambdas expressions.
Lambdas are basically anonymous functions, so just accept functions without a name as expressions.
~~~nit
var x = fun(i: Int): Int do
return i + 1
end
# or on a single line
var x = fun(i: Int): Int do return i + 1 end
~~~
`fun`, `do` and `end` are mandatory, the rest is optional
~~~nit
var x = fun do end
~~~
The main weirdness is the mandatory `end` that makes the following invalid
~~~nit
# invalid:
var x = (fun(i: Int): Int do return i + 1) # missing `end`, unexpected `)`
~~~
There is no semantic yet, nor implementation, this might come in some future PR
Pull-Request: #2758
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Fri, 23 Aug 2019 13:25:26 +0000 (09:25 -0400)]
Merge: Wrapper of ICU's UTF-16 encoded strings and conversion
### `u16_string` module
This module is meant to ease the use of complex string operations provided by the ICU library. The module provides a wrapper for ICU's string structure : `UChar *` as well as conversion fucntions to/from `String` and `CString`
### Remarks
- In order to convert a `String` to a `U16String`, the string must be converted to a `CString` first. Since `CString`'s are null temrinated, `U16String`'s also have to be null terminated and cannot have embedded termination characters.
- I am having some issues with DocUnits blocs thus there are no tests in the comments at the moment.
- I added an other `new` operator to the `CString` class which only returns a `null` string
Pull-Request: #2773
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Fri, 23 Aug 2019 13:25:22 +0000 (09:25 -0400)]
Merge: Adding a Windows build test
In parallel, a new Gitlab Runner tagged "windows" was added. This new test only builds the project.
Pull-Request: #2776
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Fri, 23 Aug 2019 13:25:19 +0000 (09:25 -0400)]
Merge: Abstract_text: Add a method to get string representation of float in scientific notation
Add a method `to_se` to get the string representation of float in scientific notation.
```
123.45.to_se == "1.2345e+02"
0.001234.to_se == "1.234e-03"
10860460000.0.to_se == "1.086046e+10"
```
The to_se method have a precision between 1 to 6 max decimal. The precision is adapted in function of the number.
Add a `to_precision_size_with_format` and `to_precision_fill_with_format` method to get the representation in a specific given format
Pull-Request: #2785
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Jean Privat <jean@pryen.org>
Florian Deljarry [Fri, 16 Aug 2019 20:56:58 +0000 (16:56 -0400)]
digraph: Implementation of a reflexive directed graph
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Sun, 18 Aug 2019 20:24:47 +0000 (16:24 -0400)]
abstract_text: Refactorisation of the to_s method
Split the code of the `to_s` for use this in the `to_sci`. Now all conversion method uses the `to_precision_size_with_format` and `to_precision_fill_with_format`
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Sun, 18 Aug 2019 20:17:01 +0000 (16:17 -0400)]
abstract_text: Add the `to_sci` to get the string representation of a float in scientific notation
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Ana Daouda [Tue, 20 Aug 2019 16:04:01 +0000 (12:04 -0400)]
.gitlab-ci.yml: adding a Windows build test
Signed-off-by: Ana Daouda <anadaouda@gmail.com>
Ana Daouda [Fri, 16 Aug 2019 20:17:03 +0000 (16:17 -0400)]
lib/core/text: Wrapper of ICU's UTF-16 encoded strings and conversion
Signed-off-by: Ana Daouda <anadaouda@gmail.com>
Jean Privat [Mon, 19 Aug 2019 18:43:08 +0000 (14:43 -0400)]
Merge: mongodb: Fixed failing test for `aggregate` method.
The test assumed the query would return in some order when it is not.
Added a "$sort" stage to the pipeline to avoid miss index asserts.
This PR fixed gitlab-ci test pipeline.
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Pull-Request: #2783
Jean Privat [Mon, 19 Aug 2019 18:43:04 +0000 (14:43 -0400)]
Merge: compiler: Refactored `AbstractRuntimeFunction`
Removed duplicate code across all the compiler and made
`AbstractRuntimeFunction` implement Template Design pattern.
This allows for better code reuse and easier customization.
Removed the notion of "virtual function" and unified it with the concept
of thunk function. A thunk is an intermediary function between a caller
and a callee whose purpose is to compute thing before or after the
callee gets invoke. Currently, the only usages of thunks are to do conversions (casting)
before calling the actual callee. Thunks can be created by inheriting
`abstract_compiler::ThunkFunction` which provides a default
implementation. Furthermore, this class simplify the old code of
`SeparateRuntimeFunction` by replacing `if` with actual polymorphism.
Finally, thunks will be used to implement callref mechanics.
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Pull-Request: #2782
Jean Privat [Mon, 8 Jul 2019 19:08:57 +0000 (15:08 -0400)]
tests: update error message of test_parser_args7.res
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 4 Jul 2019 19:36:10 +0000 (15:36 -0400)]
tests: add syntax_lambda to check various forms
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 4 Jul 2019 19:35:00 +0000 (15:35 -0400)]
parser: regenerate with lambda
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 4 Jul 2019 19:34:29 +0000 (15:34 -0400)]
syntax: add lambda construction with the fun keyword
Signed-off-by: Jean Privat <jean@pryen.org>
Louis-Vincent Boudreault [Fri, 16 Aug 2019 13:56:36 +0000 (09:56 -0400)]
mongodb: Fixed failing test for `aggregate` method.
The test assumed the query would return in some order when it is not.
Added a "$sort" stage to the pipeline to avoid miss index asserts.
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Louis-Vincent Boudreault [Thu, 15 Aug 2019 19:22:24 +0000 (15:22 -0400)]
compiler: Refactor `AbstractRuntimeFunction`
Removed duplicate code across all the compiler and made
`AbstractRuntimeFunction` implement Template Design pattern.
This allow for better code reuse and easier to customization.
Removed the notion of "virtual function" and unified it with the concept
of thunk function. A thunk is an intermediary function between a caller
and a callee whose purpose is to compute thing before or after the
callee gets invoke. Currently, the only usages of thunks is to do conversion (casting)
before calling the actual callee. Thunks can be created by inheriting
`abstract_compiler::ThunkFunction` which provides a default
implementation. Furthermore, this class simplify the old code of
`SeparateRuntimeFunction` by replacing `if` with actual polymorphism.
Finally, thunks will be used to implement callref mechanics.
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Jean Privat [Wed, 14 Aug 2019 15:23:30 +0000 (11:23 -0400)]
Merge: abstract_compiler: Replace the use of `n_float` by the `value`
## Added methods
Add a little improvement of the abstract_compiler to generate a Float value by the usage of the `value` and not the `n_float`.
Add the float conversion in exponential hexadecimal notation.
```
assert 12.345.to_hexa_exponential_notation == "0x1.8b0a3d70a3d71p+3"
assert 12.345.to_hexa_exponential_notation.to_f == 12.345
```
## Future work
Take into account the scientific notation for the display.
Pull-Request: #2778
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Wed, 14 Aug 2019 15:22:30 +0000 (11:22 -0400)]
Merge: MModule: new method `add_mclassdef` to avoid incoherent cache state.
Currently, the constructor of `MClassDef` would directly add itself in the `MModule`, like so:
`mmodule.mclassdefs.add(self)`. However, this could out of date `MModule:flatten_mclass_hierarchy`.
If we want better support for model manipulation after all the semantic phases, we need more logic when adding a new `MClassDef` in the hierarchy.
Moreover, this allows better protection since `MClassDef` no longer needs to know `mmodule.mclassdefs`.
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Pull-Request: #2777
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Wed, 14 Aug 2019 15:22:26 +0000 (11:22 -0400)]
Merge: Callref syntax
Note: I forgot to independently PR the syntax for callrefs (used by #2774), so here it is.
Introduce the `&` syntax to capture and reference calls.
This is used to provide a simple *function pointer* construction that will be used later to implement full lambdas. However, this is not expected to be used by lambda programmers :)
```nit
var ref = &recv.foo
```
Currently, the syntax is analogous to a simple call (recv.foo) with a prefix `&`.
On chains, only the last call is captured (`.` have a higer precedence than `&`)
```nit
var r = &foo.bar.baz
# is equivalent with
var x = foo.bar
var r = &x.baz
```
Since the syntax is analogous to a call (except the &), there is always a receiver (including the implicit self or sys) and arguments are accepted by the parser.
```nit
var r = &foo
# is equivalent with
var r = &self.foo
```
There is no clear syntax proposal to avoid the capture of a receiver since a receiver is statically expected to resolve the method name.
Pull-Request: #2775
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Wed, 14 Aug 2019 15:22:21 +0000 (11:22 -0400)]
Merge: fix nitcc assert failure and nitcc continuous integration
Since #2573, some nitcc tests failed on a self-check (because the trim function did not correctly remove tags on trimmed nodes).
The bug was benign and easily fixable, but the subversion of the expectation was that the script kind of forgot about correctly reporting the error (an error message was printed but a success error code was returned). So the whole CI job was a success as failed tests where unreported.
Reported-by: Florian Deljarry <deljarry.florian@gmail.com>
Pull-Request: #2772
Florian Deljarry [Mon, 12 Aug 2019 20:15:24 +0000 (16:15 -0400)]
text/abstract_text: Adds the float conversion in exponential hexadecimal notation
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Tue, 13 Aug 2019 16:13:30 +0000 (12:13 -0400)]
astbuilder: Add a `create_callsite` method
Add a `create_callsite` method to facilitate the construction of callsite.
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Florian Deljarry [Tue, 13 Aug 2019 15:49:46 +0000 (11:49 -0400)]
astbuilder: Make the construction of the `AMethPropdef` more generic
Change the MMethodDef to nullable MMethodDef to reduce model dependency.
Change the APublicVisibility to AVisibility to be able to create private or protected method.
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Jean Privat [Tue, 9 Jul 2019 15:11:03 +0000 (11:11 -0400)]
tests: add syntax_callref.nit
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Jul 2019 15:11:18 +0000 (11:11 -0400)]
typing: stub to handle callrefs
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Jul 2019 15:10:23 +0000 (11:10 -0400)]
scope: refuse `&x` where x is a local variable
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Jul 2019 15:09:49 +0000 (11:09 -0400)]
parser: regenerate with callrefs
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 9 Jul 2019 15:09:29 +0000 (11:09 -0400)]
syntax: add call reference (funref+recv capture) `&x.foo`
Signed-off-by: Jean Privat <jean@pryen.org>
Florian Deljarry [Mon, 12 Aug 2019 20:22:11 +0000 (16:22 -0400)]
abstract_compiler: Replace the use of `n_float` by the `value`
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
Louis-Vincent Boudreault [Mon, 12 Aug 2019 13:42:55 +0000 (09:42 -0400)]
MModule: new method `add_mclassdef` to avoid incoherent cache state.
Signed-off-by: Louis-Vincent Boudreault <lv.boudreault95@gmail.com>
Jean Privat [Fri, 19 Jul 2019 00:59:11 +0000 (20:59 -0400)]
CI: nitunit_some skips contrib since some code might be generated
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 18 Jul 2019 18:39:57 +0000 (14:39 -0400)]
Merge: Safe call operator
A long time ago, there was a proposal to have a safe call operator in Nit #1274 `x?.foo` that executes the call if `x` is not null and returns null otherwise (instead of aborting).
This was refused because at the time, the syntax `x?.foo` was considered weird and not POLA.
Moreover, what was proposed was a more general version of the concept that could be used everywhere, not only as a receiver that made the semantic quite complex and even less POLA.
Nowadays, most languages have adopted it https://en.wikipedia.org/wiki/Safe_navigation_operator so the syntax and behavior is not as weird as before.
This operator is nice in the context of Nit with nullable types since if avoids to use chained `if x != null then x.foo` and plays nicely with the type system.
Currently, only explicit dotted calls are handled; e.g. `x?.foo`, I'm not sure if something should be done with other call constructions like `x + y` or `x[y]`.
Pull-Request: #2761
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Thu, 18 Jul 2019 18:08:18 +0000 (14:08 -0400)]
nitcc: tests script return non-zero on failure (print is not enough)
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Thu, 18 Jul 2019 18:06:52 +0000 (14:06 -0400)]
nitcc: trim also remove tags on bad states
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 15 Jul 2019 15:08:16 +0000 (11:08 -0400)]
Merge: ci: generate metrics output in an artifact file
Results for nitmetrics should be easily available.
Pull-Request: #2771
Jean Privat [Mon, 15 Jul 2019 15:08:12 +0000 (11:08 -0400)]
Merge: fix ci nitunit some
When there is no change in watched nit files, the job `nitunit_some` failed.
Pull-Request: #2770
Jean Privat [Mon, 15 Jul 2019 15:08:09 +0000 (11:08 -0400)]
Merge: Introduce `test_frontend`
Sometimes we need to test things related to a model and it's not easy to do this with NitUnit since creating
a model by hand is tedious.
With the `TestModel` abstract suite it's easier:
```nit
module my_test is test
import test_frontend
class MyTest
super TestModel
test
redef var test_src = "path/to/files"
fun my_test is test do
assert test_model.mmodules.length == 1
end
end
```
Pull-Request: #2769
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 15 Jul 2019 15:08:04 +0000 (11:08 -0400)]
Merge: doc: Rename `synopsys` into `synopsis`
Typo found in a lot of places ported since the very first `nitdoc` version I think.
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Pull-Request: #2768
Jean Privat [Mon, 15 Jul 2019 15:08:00 +0000 (11:08 -0400)]
Merge: metrics: ReadmeMetrics uses markdown2
Some leftovers introducing the new markdown parser.
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Pull-Request: #2767
Jean Privat [Mon, 15 Jul 2019 15:07:57 +0000 (11:07 -0400)]
Merge: Update basic requirements and document them
Since #2615 we broke the initial build according to the documentation since nitpm (picnit) requires libcurl.
To minimize the number of doc to update I just moved `nitpm` to the "more" set of tools and documented their requirements.
I also added a CI job to avoid future failures (note: I'm not sure how to adapt it on other docker-less platforms).
Pull-Request: #2766
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Mon, 15 Jul 2019 15:07:28 +0000 (11:07 -0400)]
Merge: Move back manual to the main repo
The manual is slowly bit rotting in the wiki (the disclaimer in http://nitlanguage.org/manual/ and the link to the very old issue #761 is not a nice thing to have).
The idea is to move back the documentation in the main repository so that PR that enhance the language should also update the manual.
We could add checks to ensure that new AST element or annotations implies some update in the manual.
It is what is currently done with the manpages of the tools, and they are quite complete and up to date.
Pull-Request: #2762
Jean Privat [Mon, 15 Jul 2019 15:07:24 +0000 (11:07 -0400)]
Merge: Clean old projects from `contrib`
This PR removes 3 old projects from `contrib` that are no more used nor interesting:
* `neo_doxygen`
* `refund`
* `wiringPi`
222 files and 25k LOC less :D
Pull-Request: #2764
Jean Privat [Mon, 15 Jul 2019 15:07:20 +0000 (11:07 -0400)]
Merge: github: Summer cleaning
Some cleaning to the `github` lib.
Most interesting changes:
* kill `github_curl` and migrate clients (`github_merge`, `github_search_for_jni`)
* clean deserialization process heuristics for something more robust and readable (but a bit slower)
* array pagination
* kill `GithubEntity`
* remove ISO date methods
* mock testing for `github::wallet`
* `wallet` uses a `Logger`
This PR can be read commit by commit.
Pull-Request: #2765
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 15 Jul 2019 15:05:18 +0000 (11:05 -0400)]
ci: generate metrics output in an artifact file
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 15 Jul 2019 13:57:59 +0000 (09:57 -0400)]
tests: error_syntax errors on `? now
Signed-off-by: Jean Privat <jean@pryen.org>
Alexandre Terrasa [Sun, 14 Jul 2019 18:42:00 +0000 (14:42 -0400)]
indexing: Use `test_frontend`
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Sun, 14 Jul 2019 18:41:38 +0000 (14:41 -0400)]
doc: Commands tests use `test_frontend`
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Sun, 14 Jul 2019 18:01:30 +0000 (14:01 -0400)]
frontend: Introduce `test_frontend` to easily test model related code
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
Alexandre Terrasa [Sun, 14 Jul 2019 16:55:45 +0000 (12:55 -0400)]
doc: Rename `synopsys` into `synopsis`
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>