nit.git
9 years agosrc: improve messages (and sometime location) of errors and warnings
Jean Privat [Wed, 15 Apr 2015 01:14:56 +0000 (08:14 +0700)]
src: improve messages (and sometime location) of errors and warnings

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodel: add `MClass::signature_to_s` to use in messages.
Jean Privat [Tue, 14 Apr 2015 10:07:29 +0000 (17:07 +0700)]
model: add `MClass::signature_to_s` to use in messages.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: identify the node associated to method name
Jean Privat [Thu, 9 Apr 2015 12:40:28 +0000 (19:40 +0700)]
typing: identify the node associated to method name

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoMerge: Fix type adaptation when there is loops
Jean Privat [Tue, 14 Apr 2015 09:33:40 +0000 (16:33 +0700)]
Merge: Fix type adaptation when there is loops

Basically one of the oldest bug of Nit.

The point of adaptive typing is that the static types of variables follows the static types of the assigned values, type tests and comparison to null.
This is a great feature of the language but was buggy because loops where not taken in account (old TODO), until the present PR.

The basic idea is just to track if a type adaptation occurs, if yes replay the whole typing phase.
The immediate drawback is that now typing require 2 passes most of the time, and sometime more.

This PR was a roller-coaster of emotions to develop since a lot a surprise issues were discovered.

* bug in flow that give me hours of despair.
* duplication of error messages; because multiple passes.
* premature warning/error messages; because some error conditions on types are detected at the first pass but a second pass find it is fine in fact... but too late the error message was printed.
* almost work at the first time (modulo the previous issues)
* only two bugs found in the whole code, quite impressive, and one of them is not a real bug but an autocast issue.

The issue about error duplication and premature errors is only workadounded (or fixme) in most places.
But proper solutions will be required in future PR.

close #647 and close #86, then reopen it again, then reclose it.

Pull-Request: #1257
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Intern new
Jean Privat [Tue, 14 Apr 2015 09:33:32 +0000 (16:33 +0700)]
Merge: Intern new

A small short PR that enables a `new`-factory to instantiate itself.

previously there was no way to do that. The following code will stack-overflow:

~~~nit
class A
   new do
      var res = new A
      res.do_thigns
      return res
   end
end
var a = new A # infinite recursion of `new A`
~~~

Note: this is a very bad example as what is done in the previous `new` should be done in an `init` instead since it is related to the initialization of the object. A `new` factory should be exclusively used for some factory-concern like returning a more specialized object or returning an already existing object.

With this PR, the primitive constructor is available and is called `intern`, as the annotation that indicates things that cannot be programmed in Nit but are provided by the execution engine.

So in the previous example, just use this primitive constructor instead of doing a recursive call:

~~~
      var res = new A.intern
~~~

This intern constructor just do the allocation and the initialization of attributes with default values.
`init` is not called.

Maybe it should not do the initialization of attributes neither but if I skip them, there is no way for the programmer to ask for them manually. whereas `init` in not automatically called but can be called manually.

note: this PR is a small step toward the conclusion of the constructor saga, more will come soon (I hope)

Pull-Request: #1252
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agoMerge: Improved parallelization phase
Jean Privat [Tue, 14 Apr 2015 09:33:22 +0000 (16:33 +0700)]
Merge: Improved parallelization phase

The "threaded" annotation now supports functions with parameters !

Still need to check for eventual self calls in the body of the annotated function

Pull-Request: #1255
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

9 years agoMerge: Make the generated iOS project compilable in the XCode GUI
Jean Privat [Tue, 14 Apr 2015 09:32:55 +0000 (16:32 +0700)]
Merge: Make the generated iOS project compilable in the XCode GUI

I originally incorporated the test project in the generated XCode workspace thinking that we could use it somehow. But it duplicates services from nitunits and it would be much more complex to use.

I remove the test project now because it is incomplete and raise errors from the XCode GUI.

Pull-Request: #1254
Reviewed-by: ArthurDelamare <arthur.delamare@viacesi.fr>
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

9 years agoMerge: Vim plugin fixes and make Nitdoc a command with search capabilities
Jean Privat [Tue, 14 Apr 2015 09:32:40 +0000 (16:32 +0700)]
Merge: Vim plugin fixes and make Nitdoc a command with search capabilities

You can now use Nitdoc as a command in Vim.

* Search the doc for the word under the cursor with `:Nitdoc`
* Display the doc of the `String` class (followed by all docs using the word "String", case-insensitive) with `:Nitdoc String`
* Display the doc of `Int::%` with `:Nitdoc modulo`
* Search for a string of words (in the given order) with `:Nitdoc not null`

Some query can produce quite a lot results. `:Nitdoc the` will fill the preview window with 33 379 lines of doc, but there no noticeable delay.

### Bonus tip!

Navigate in the doc by moving the cursor above a word in the preview window and using ctrl-D (or `:Nitdoc`), exactly as you would do in Nit code.

Pull-Request: #1256
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agotests: add base_adaptive_loop*.nit
Jean Privat [Sun, 12 Apr 2015 04:14:58 +0000 (11:14 +0700)]
tests: add base_adaptive_loop*.nit

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: update sav for existing tests
Jean Privat [Sat, 11 Apr 2015 17:14:40 +0000 (00:14 +0700)]
tests: update sav for existing tests

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotoolcontext: avoid duplicated messages
Jean Privat [Sat, 11 Apr 2015 17:13:56 +0000 (00:13 +0700)]
toolcontext: avoid duplicated messages

This is just a workaround to limit repeated errors message because of
adapting typing

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/ai/backtrack: add a missing assert
Jean Privat [Sat, 11 Apr 2015 17:12:50 +0000 (00:12 +0700)]
lib/ai/backtrack: add a missing assert

or else the possible null will loop and cause errors.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/a_star: avoid bad autocast
Jean Privat [Sat, 11 Apr 2015 17:11:40 +0000 (00:11 +0700)]
lib/a_star: avoid bad autocast

Seriously, this one case might be a strong argument against autocasts

~~~
frontier_node = frontier_node.best_source.as(not null)
~~~

is auto-casted as

~~~
frontier_node = frontier_node.best_source.as(not null).as(N)
~~~

bun since the N is `nullable Node`, the not-null information was lost in the
cast.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agocompiler: consider untyped expressions and statement as dead code
Jean Privat [Sun, 12 Apr 2015 04:13:24 +0000 (11:13 +0700)]
compiler: consider untyped expressions and statement as dead code

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: handle `a == null` when `a` is null
Jean Privat [Sat, 11 Apr 2015 17:09:04 +0000 (00:09 +0700)]
typing: handle `a == null` when `a` is null

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: shortcut `get_variable` on never-adapted variables
Jean Privat [Sat, 11 Apr 2015 17:07:41 +0000 (00:07 +0700)]
typing: shortcut `get_variable` on never-adapted variables

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomisc/vim: inform the user when no results are found
Alexis Laferrière [Mon, 13 Apr 2015 03:52:34 +0000 (23:52 -0400)]
misc/vim: inform the user when no results are found

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agomisc/vim: update README file
Alexis Laferrière [Sat, 11 Apr 2015 14:21:51 +0000 (10:21 -0400)]
misc/vim: update README file

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agotyping: ensure monotony on literal arrays
Jean Privat [Sat, 11 Apr 2015 17:06:45 +0000 (00:06 +0700)]
typing: ensure monotony on literal arrays

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: revisit on type-adaptation, until there is no more adaptation
Jean Privat [Sat, 11 Apr 2015 17:06:06 +0000 (00:06 +0700)]
typing: revisit on type-adaptation, until there is no more adaptation

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: mark variable dirty on type_adaptation
Jean Privat [Sat, 11 Apr 2015 17:04:16 +0000 (00:04 +0700)]
typing: mark variable dirty on type_adaptation

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: compute FlowContext::collect_types without recursion
Jean Privat [Sat, 11 Apr 2015 17:00:09 +0000 (00:00 +0700)]
typing: compute FlowContext::collect_types without recursion

So this avoid infinite recursion on loops

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: remove cache in FlowContext
Jean Privat [Sat, 11 Apr 2015 16:55:07 +0000 (23:55 +0700)]
typing: remove cache in FlowContext

Because type adaptation require recomputation on loops

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoflow: improve dot-rendering for debugging
Jean Privat [Sat, 11 Apr 2015 16:52:46 +0000 (23:52 +0700)]
flow: improve dot-rendering for debugging

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoflow: fix loop links on continue
Jean Privat [Sat, 11 Apr 2015 16:52:01 +0000 (23:52 +0700)]
flow: fix loop links on continue

Targets the begin of the block

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomisc/vim: delete the first empty line of the preview window on Nitdoc command
Alexis Laferrière [Sat, 11 Apr 2015 14:32:45 +0000 (10:32 -0400)]
misc/vim: delete the first empty line of the preview window on Nitdoc command

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agomisc/vim: the Nitdoc command search with priorities
Alexis Laferrière [Sat, 11 Apr 2015 14:12:30 +0000 (10:12 -0400)]
misc/vim: the Nitdoc command search with priorities

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agomisc/vim: make Nitdoc a command
Alexis Laferrière [Sat, 11 Apr 2015 13:41:21 +0000 (09:41 -0400)]
misc/vim: make Nitdoc a command

Use this vim command to show the doc of any entities `:Nitdoc Object`.

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agomisc/vim: fix omnifunc order of results found in the long doc
Alexis Laferrière [Sat, 11 Apr 2015 14:11:00 +0000 (10:11 -0400)]
misc/vim: fix omnifunc order of results found in the long doc

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agomisc/vim: make private functions local to the script
Alexis Laferrière [Sat, 11 Apr 2015 14:10:15 +0000 (10:10 -0400)]
misc/vim: make private functions local to the script

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agonitc/ios: use a camel case version of app namespace for some version of XCode
Alexis Laferrière [Fri, 10 Apr 2015 19:09:29 +0000 (15:09 -0400)]
nitc/ios: use a camel case version of app namespace for some version of XCode

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agonitc/ios: remove all testing related entities from the xcode project
Alexis Laferrière [Fri, 10 Apr 2015 17:21:10 +0000 (13:21 -0400)]
nitc/ios: remove all testing related entities from the xcode project

Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agoMerge: Sys is top
Jean Privat [Fri, 10 Apr 2015 15:19:40 +0000 (22:19 +0700)]
Merge: Sys is top

And when I say *top* I mean *great*. But I also mean *top* in fact.

The idea is to move the top-level methods (those defined outside classes) from Object to Sys.
While this is a cosmetic move, it has a lot of benefits:

* top-level methods get a real meaningful receiver: the current system. It is meaningful both on the declaration side and the call side.
* no more need to distinguish the concept of top-level methods with their rules and semantic, so this simplify the language with one less thing (almost, see bellow)
* self is now usable in top-level methods, not that useful now because it is `sys`, a singleton, but this allow some kind of inheritance if you add super-classes to Sys.
* no more name conflicts between a standard class method and a top-level method
* no more useless slots in table of classes for crazy methods defined in Object and never redefined
* close #461 and close #1081 by making them irrelevant
* Let us see a bright future where the singleton Sys become a multiton and allow specific isolation of computation. Specific Sys will then be active objects (threads, computation node, actors, whatever) isolated with their own specific cloud of objects and efficient lock-less concurrency, dedicated memory model (realtime?), and why not transparent distribution

There is still two drawbacks

* what is the status of `sys` that represent the current `Sys`? I hard-coded it to stay a method in Object. One way to solve the probem is to make it a keyword (like `self`)
* when doing `foo(x)`, first this tries `self.foo(x)` then `sys.foo(x)` thus this is some additional rule of the language.

Pull-Request: #1249
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

9 years agoMerge: Robust IO
Jean Privat [Fri, 10 Apr 2015 11:27:53 +0000 (18:27 +0700)]
Merge: Robust IO

Some cleanup on lib/standard/file.nit
Especially close #755

There is still some work to do and question to answer from an API point of view.

Pull-Request: #1246
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: miniclean quadtrees
Jean Privat [Fri, 10 Apr 2015 11:27:45 +0000 (18:27 +0700)]
Merge: miniclean quadtrees

Still a lot of warning remains...

Pull-Request: #1251
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agotests: remove fixme sav/nitg-g/fixme/test_deriving_alt1.res
Jean Privat [Fri, 10 Apr 2015 10:31:17 +0000 (17:31 +0700)]
tests: remove fixme sav/nitg-g/fixme/test_deriving_alt1.res

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: ffi use `Sys_` instead of `Object_` prefix
Jean Privat [Wed, 8 Apr 2015 13:53:37 +0000 (20:53 +0700)]
tests: ffi use `Sys_` instead of `Object_` prefix

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: update tests results related to top-level or Object->Sys
Jean Privat [Wed, 8 Apr 2015 13:53:03 +0000 (20:53 +0700)]
tests: update tests results related to top-level or Object->Sys

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agocode: remove `protected` from top-level methods (now in sys)
Jean Privat [Wed, 8 Apr 2015 15:51:44 +0000 (22:51 +0700)]
code: remove `protected` from top-level methods (now in sys)

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: remove most top-level things
Jean Privat [Wed, 8 Apr 2015 13:51:31 +0000 (20:51 +0700)]
typing: remove most top-level things

only kept for `new` factories and `sys` (for the moment)

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/md5: do not import `print` in FFI
Jean Privat [Wed, 8 Apr 2015 13:50:04 +0000 (20:50 +0700)]
lib/md5: do not import `print` in FFI

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomixin: look for top-level methods in `Sys`.
Jean Privat [Wed, 8 Apr 2015 13:15:03 +0000 (20:15 +0700)]
mixin: look for top-level methods in `Sys`.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodelize_classes: top-level methods are defined in Sys, not Object
Jean Privat [Wed, 8 Apr 2015 13:14:19 +0000 (20:14 +0700)]
modelize_classes: top-level methods are defined in Sys, not Object

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoengines: implement special fall-back to sys
Jean Privat [Wed, 8 Apr 2015 13:11:35 +0000 (20:11 +0700)]
engines: implement special fall-back to sys

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: look for method in `sys` when they are not in `self`
Jean Privat [Wed, 8 Apr 2015 13:10:54 +0000 (20:10 +0700)]
typing: look for method in `sys` when they are not in `self`

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodelize classes: process AStdClassdef before
Jean Privat [Wed, 8 Apr 2015 10:18:00 +0000 (17:18 +0700)]
modelize classes: process AStdClassdef before

So that non-AStdClassdef classes can be attached to existing ones if any

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoniti: implements native `chdir` and `mkdir` with a return value
Jean Privat [Fri, 10 Apr 2015 10:09:18 +0000 (17:09 +0700)]
niti: implements native `chdir` and `mkdir` with a return value

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: add base_new_intern.nit
Jean Privat [Fri, 10 Apr 2015 05:20:58 +0000 (12:20 +0700)]
tests: add base_new_intern.nit

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: `intern` is used to refer to the plain vanilla constructor
Jean Privat [Fri, 10 Apr 2015 05:16:03 +0000 (12:16 +0700)]
typing: `intern` is used to refer to the plain vanilla constructor

It is used to implement specific factories inside classes

~~~
class A
   new do
      var res = new A.intern
      res.do_things
      return res
   end
end
~~~

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoengines: ANewExpr just return the plain instance if no callsite
Jean Privat [Fri, 10 Apr 2015 05:13:39 +0000 (12:13 +0700)]
engines: ANewExpr just return the plain instance if no callsite

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: update sav related to ligne changes in kernel
Jean Privat [Thu, 9 Apr 2015 14:50:55 +0000 (21:50 +0700)]
tests: update sav related to ligne changes in kernel

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agocontrib/nitester: no more free to call
Jean Privat [Thu, 9 Apr 2015 14:50:27 +0000 (21:50 +0700)]
contrib/nitester: no more free to call

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib: move errno and strerror to legacy FFI
Jean Privat [Mon, 6 Apr 2015 15:24:20 +0000 (22:24 +0700)]
lib: move errno and strerror to legacy FFI

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/file: once some global constants
Jean Privat [Mon, 6 Apr 2015 15:10:17 +0000 (22:10 +0700)]
lib/file: once some global constants

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/file: some methods return a nullable Error on error
Jean Privat [Mon, 6 Apr 2015 15:09:55 +0000 (22:09 +0700)]
lib/file: some methods return a nullable Error on error

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/file: String::files does not exist on error
Jean Privat [Mon, 6 Apr 2015 15:08:52 +0000 (22:08 +0700)]
lib/file: String::files does not exist on error

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/file: remove useless protected for top-level methods
Jean Privat [Mon, 6 Apr 2015 15:07:30 +0000 (22:07 +0700)]
lib/file: remove useless protected for top-level methods

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/file: expose FileStat instead of NativeFileStat
Jean Privat [Mon, 6 Apr 2015 15:06:59 +0000 (22:06 +0700)]
lib/file: expose FileStat instead of NativeFileStat

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoquatree: cleaup indentation
Jean Privat [Thu, 9 Apr 2015 13:30:54 +0000 (20:30 +0700)]
quatree: cleaup indentation

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoquadtree: use new constructors
Jean Privat [Thu, 9 Apr 2015 13:30:39 +0000 (20:30 +0700)]
quadtree: use new constructors

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoMerge: Misc AST
Jean Privat [Thu, 9 Apr 2015 05:24:43 +0000 (12:24 +0700)]
Merge: Misc AST

Various small improvements on the ast side.

The main improvement is the lower consumption of Location instances.
Before: 681k where created; for 174MIr
After:  472k are created (-30%); for 120MIr (-31%)
However, the final impact should be negligible.

Other changes are related to error messages in order to have them more useful in other context.
As a proof of concept, nitlight can show some warnings and errors in the generated HTML.
There is still issue, especially: how to display them property. Currently they are in a popupable dropdown boxes, but the with is too small and nested info boxes show unreadable stacked  things.

Eg, for `return new Foo[nullable Bar]`, how can I show

* information on the classes Foo and Bar
* error on the whole `nullable Bar` because Foo is in fact not generic
* error on the whole `new Foo[nullable Bar]` because in fact we are in a procedure, so no return value is expected

Pull-Request: #1248
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: new `with` statement
Jean Privat [Thu, 9 Apr 2015 05:24:37 +0000 (12:24 +0700)]
Merge: new `with` statement

Introduce the `with` statement that is analogous to the `with` of Python or the `uning` of C#.

~~~nit
with x = something do
   x.work
end
~~~

That is equivalent with

~~~nit
do
   var x = something
   x.start
   x.work
   x.finish
end
~~~

Note that an alternative syntax, without the local variable exists:

~~~nit
with something do
   work
end
~~~

that is used when we want some automatic control or whatever. Eg resource allocation or critical section.

~~~nit
do
   var tmp = something
   tmp.start
   work
   tmp.stop
end
~~~

Most real-world examples could be

~~~nit
with file = path.create do
   file.write("Bla")
end
~~~

and

~~~nit
with a_mutex do
   work
end
~~~

## Names

I reused the `finish` method from Iterator.
I introduced the antonym `start` for the other side.

Note that the `start` is important because it helps the object to know it has to prepare itself for a `finish`.

I did not introduce an interface, mainly because I have no idea for a name. C# names it `IDisposable` and the `finish` method is called `Dispose`. There is no `start` because C# designers are lunatic sometime.

In python there is no interface (obviously) and the method are called
`__enter__` and `__exit__` because Python likes identifiers that resemble words eaten by boas.
Note that the returned variable is not the original expression but the result of `__enter__`.
With the Python semantic, but the Nit syntax, the first example will be equivalent to

~~~nit
do
   var tmp = something
   var x = tmp.start
   x.work
   x.finish
end
~~~

I am not sure of the benefits of the additional complexity, but the the more I thing about it the more I think this could be useful, ex for the control case the `start` can return the handler to `finish`.

The issue is that proposed syntax: `with x = something` does not make sense (because `tmp=something` and `x=tmp.start`) thus should be replaced with something else; Python uses `with something as x:` that we can reuse but I do not want because it is ugly.

An other alternative I tough of was to reuse the `for` keyword. but It is convoluted.
The two previous real world examples will then be

~~~nit
for file = path.create do
   file.write("Bla")
end
~~~

and

~~~nit
for a_mutex do
   work
end
~~~

Pull-Request: #1243
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Etienne M. Gagnon <egagnon@j-meg.com>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

9 years agotests: update nitlight and test_parser
Jean Privat [Wed, 8 Apr 2015 14:39:22 +0000 (21:39 +0700)]
tests: update nitlight and test_parser

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agohightlight: remove two asserts that make #1247 crashes
Jean Privat [Wed, 8 Apr 2015 14:36:59 +0000 (21:36 +0700)]
hightlight: remove two asserts that make #1247 crashes

the result is still buggy but things keep-going

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotest_parser: add option `-x` to output XML
Jean Privat [Wed, 8 Apr 2015 05:29:24 +0000 (12:29 +0700)]
test_parser: add option `-x` to output XML

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agohighlight: add infoboxes with messages
Jean Privat [Wed, 8 Apr 2015 05:22:11 +0000 (12:22 +0700)]
highlight: add infoboxes with messages

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agohighlight: factorize the creation of tags
Jean Privat [Wed, 8 Apr 2015 05:21:31 +0000 (12:21 +0700)]
highlight: factorize the creation of tags

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotoolcontext: error methods return the messages, to add information
Jean Privat [Wed, 8 Apr 2015 05:08:41 +0000 (12:08 +0700)]
toolcontext: error methods return the messages, to add information

unused yet.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotoolcontext: attach errors message to their location
Jean Privat [Wed, 8 Apr 2015 16:10:42 +0000 (23:10 +0700)]
toolcontext: attach errors message to their location

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoparser: reuse child location when possible
Jean Privat [Wed, 8 Apr 2015 05:01:07 +0000 (12:01 +0700)]
parser: reuse child location when possible

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolexer: do not create useless location (for whitespaces)
Jean Privat [Wed, 8 Apr 2015 05:00:20 +0000 (12:00 +0700)]
lexer: do not create useless location (for whitespaces)

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoMerge: Parallelization phase introduction
Jean Privat [Wed, 8 Apr 2015 01:03:25 +0000 (08:03 +0700)]
Merge: Parallelization phase introduction

Introduces the begining of the parallelization in Nit !

For now, only accepts the "threaded" annotation on methods without return value and without parameters.

Coming next :
Parametrized methods,
methods with return value,
for loops.

Pull-Request: #1247
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Not null types
Jean Privat [Wed, 8 Apr 2015 01:01:49 +0000 (08:01 +0700)]
Merge: Not null types

In order to fix #86 and #1238 some preliminary work to solve remaining issues with the type system is needed. This PR is a step toward this goal.

This introduce not-null types, that is a modifier to indicate that a type cannot contain null.
Basically, this new modifier is almost useless because it is the semantic of all the types (except obviously null and nullable things). Except in one case: when one adapts a formal type whose bound is nullable.

Before the PR, the semantic was the following

~~~nit
class A[E: nullable Object]
   fun foo(e: E, o: nullable Object) do
      var o2 = o.as(not null) # the static type of o2 is `Object`
      print o2 # OK
      var e2 = e.as(not null) # the static type of e2 is still `E` because there is no `nullable` to remove
      print e2 # Error: expected Object, got E
   end
end
~~~

Obviously, the issue was not that important because people managed to program complex things in Nit and I do not remember getting some complain about that particular issue. For the rare cases of this unexpected behavior, a workaround was possible: to cast on the non-nullable bound

~~~nit
   var e2 = e.as(Object)
   print e2 # OK
~~~

Nevertheless, the behavior was still buggy since type information was lost and not POLA. Moreover, `!= null` and `or else` did not have a workaround.

So, this PR introduces a special new type-modifier for this case so that everything become sensible.

~~~nit
      var e2 = e.as(not null) # the static type of e2 is now `not null E`
      print e2 # OK
~~~

Moreover, a lot of local refactorisation was done in model.nit and typing.nit to clean and harmonize the code. So that independently of the new notnull modifier, the code is cleaner, some bugs where removed and some small features added, especially the detection of useless `or else`.

Last, but not least, the `not null` thing is only an internal modifier and is not usable as a syntactic type construction (the grammar and the AST is unchanged); `not null` can however be shown to the programmer in messages.

~~~nit
      var e2 = e.as(not null) # the static type of e2 is now `not null E`
      var e3 = e2.as(not null) # << Warning: expression is not null, since it is a `not null E` >>
~~~

I could easily add `not null` as a specific syntactic construction since everything internally is ready. but 1. does this worth it?. 2. I do not want to conflict with #1243 that also change the grammar.
As an example, is it useful to write the following? (currently refused but very easy to add after this PR)

~~~nit
class A[E: nullable Object]
   fun foo(e: not null E): not null E do
      var x = e.to_s # no null pointer exception
      # ...
      return e
   end
end

var a = new A[nullable Int]
var i = a.foo(5)
~~~

Pull-Request: #1244
Reviewed-by: Etienne M. Gagnon <egagnon@j-meg.com>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Improve checking of virtual types
Jean Privat [Wed, 8 Apr 2015 01:01:15 +0000 (08:01 +0700)]
Merge: Improve checking of virtual types

This PR does 2 things to avoid runtime errors during nitc. Invalid programs that crashed the compiler now display errors messages.

* improve the static detection of loops in virtual types.
* consider types in the signatures of properties to be fragile since they contains potentially bad virtual types.

If merged with #1241 then nitpick can process the whole tests directory without crashing (impressive, since there is 1584 border-case files).
~~~
$ ./nitpick ../tests/*.nit ../tests/alt/*.nit -I ../lib/standard/ -I ../lib/standard/collection/
[... lots of errors ...]
Errors: 1766. Warnings: 195.
~~~

Pull-Request: #1245
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Clean benches
Jean Privat [Wed, 8 Apr 2015 01:01:07 +0000 (08:01 +0700)]
Merge: Clean benches

Some janitoring in the benchmarks directory

Pull-Request: #1242
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Robust keep-going
Jean Privat [Wed, 8 Apr 2015 01:00:53 +0000 (08:00 +0700)]
Merge: Robust keep-going

Detection and resolution of crashes or irrelevant error messages with tools that keeps going (eg. nitpick).

Historically, the compiler just exited at the end on a step when an error occured. The ToolContext#keep_going flag disable this automatic exit and was introduced for tool that are expected to be launched on broken code: nitpick and nitlight. However most parts of the code expected that:

* the previous steps where completed successfully, and expected information where available and correct.
* they are that special important snowflake can just exit the whole program when they are unhappy.

These rules can make sense for a compiler but are to strict for most SE tools that need to work (or continue working) when some random module contain an error.
Thus this PR improve the robustness of various parts of the code for the keep-going case so that we do not exit or crash before having processed all the modules.

With this PR, the following command does not crash anymore:

~~~
$ nitpick `nitls -rps ../lib ../contrib ../examples`
[...]
Errors: 10. Warnings: 31.
~~~

Note that `nitpick ../tests` still crashes. There is ugly errors hard to recover from in this directory.

Maybe, one day most of the tools can be made keep going by default.

Pull-Request: #1241
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Etienne M. Gagnon <egagnon@j-meg.com>

9 years agosrc/hightlight: hightlight and do not crash on MNotNullType
Jean Privat [Tue, 7 Apr 2015 10:37:36 +0000 (17:37 +0700)]
src/hightlight: hightlight and do not crash on MNotNullType

Also add MNullType that where missing.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: add base_not_null.nit and base_notnull_lit.nit
Jean Privat [Sat, 4 Apr 2015 15:50:58 +0000 (22:50 +0700)]
tests: add base_not_null.nit and base_notnull_lit.nit

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agocode: remove useless `or else` now that they are detected
Jean Privat [Sat, 4 Apr 2015 15:46:56 +0000 (22:46 +0700)]
code: remove useless `or else` now that they are detected

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: update test_new_native_alt1.res because line change in array :(
Jean Privat [Sat, 4 Apr 2015 15:38:26 +0000 (22:38 +0700)]
tests: update test_new_native_alt1.res because line change in array :(

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: update because resolved types are in error messages
Jean Privat [Sat, 4 Apr 2015 15:37:56 +0000 (22:37 +0700)]
tests: update because resolved types are in error messages

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: on type error, also indicate the resolved type
Jean Privat [Sat, 4 Apr 2015 15:36:53 +0000 (22:36 +0700)]
typing: on type error, also indicate the resolved type

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoUpdate tests error message on null adaptation and tests
Jean Privat [Sat, 4 Apr 2015 15:04:55 +0000 (22:04 +0700)]
Update tests error message on null adaptation and tests

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/array: suppress a warning to be compatible with the bootstrap
Jean Privat [Sat, 4 Apr 2015 13:36:44 +0000 (20:36 +0700)]
lib/array: suppress a warning to be compatible with the bootstrap

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodel: rename `as_notnullable` to `undecorate`
Jean Privat [Sat, 4 Apr 2015 13:35:41 +0000 (20:35 +0700)]
model: rename `as_notnullable` to `undecorate`

The behavior is to remove the decoration, and `as_notnullabe` is not
the best name to undecorate a `MNotNullType`

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotyping: add `check_can_be_null` to fix and factorize as_notnull transformations
Jean Privat [Sat, 4 Apr 2015 13:31:11 +0000 (20:31 +0700)]
typing: add `check_can_be_null` to fix and factorize as_notnull transformations

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodel: add new type `MNotNullType` to force that null is excluded from a type.
Jean Privat [Sat, 4 Apr 2015 13:29:08 +0000 (20:29 +0700)]
model: add new type `MNotNullType` to force that null is excluded from a type.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: update sav/base_virtual_type7.res
Jean Privat [Mon, 6 Apr 2015 08:22:54 +0000 (15:22 +0700)]
tests: update sav/base_virtual_type7.res

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: add error_virtual_type.nit and error_virtual_type2.nit
Jean Privat [Mon, 6 Apr 2015 08:19:43 +0000 (15:19 +0700)]
tests: add error_virtual_type.nit and error_virtual_type2.nit

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/file: add some doc and nitunits
Jean Privat [Mon, 6 Apr 2015 15:06:00 +0000 (22:06 +0700)]
lib/file: add some doc and nitunits

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agoclib/gc_chooser: add a default for a switch to silent a warning
Jean Privat [Mon, 6 Apr 2015 14:40:53 +0000 (21:40 +0700)]
clib/gc_chooser: add a default for a switch to silent a warning

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodelize_property: improve the search of circularity for virtual types
Jean Privat [Mon, 6 Apr 2015 08:17:00 +0000 (15:17 +0700)]
modelize_property: improve the search of circularity for virtual types

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodelize_property: use resolve_mtype_unchecked during build_signature
Jean Privat [Mon, 6 Apr 2015 05:10:29 +0000 (12:10 +0700)]
modelize_property: use resolve_mtype_unchecked during build_signature

Signature can contain illegal type made of virtual types.
But at this point, the virtual types are not yet validated.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodelize_property: remove unused ASignature::build_signature
Jean Privat [Mon, 6 Apr 2015 08:11:24 +0000 (15:11 +0700)]
modelize_property: remove unused ASignature::build_signature

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agolib/ai: remove randomness in puzzle so benches can compare sanely
Jean Privat [Sat, 4 Apr 2015 21:43:32 +0000 (04:43 +0700)]
lib/ai: remove randomness in puzzle so benches can compare sanely

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodel: extract a common proxy from MNullableType
Jean Privat [Sat, 4 Apr 2015 10:34:05 +0000 (17:34 +0700)]
model: extract a common proxy from MNullableType

This will simplify the creation of future proxys/decorations for types.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agosrc: use MFormalType for type checks when it makes sense
Jean Privat [Sat, 4 Apr 2015 09:57:09 +0000 (16:57 +0700)]
src: use MFormalType for type checks when it makes sense

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agomodel: introduce MFormalType as a superclass of MVirtualType and MParameterType
Jean Privat [Sat, 4 Apr 2015 09:56:12 +0000 (16:56 +0700)]
model: introduce MFormalType as a superclass of MVirtualType and MParameterType

Strangely enough, they do not have common methods yet.
It is why a super-class was never introduced.

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agotests: add base_with.nit
Jean Privat [Mon, 30 Mar 2015 12:02:55 +0000 (19:02 +0700)]
tests: add base_with.nit

Signed-off-by: Jean Privat <jean@pryen.org>

9 years agocode: rename identifiers `with` since it is a keyword now
Jean Privat [Mon, 30 Mar 2015 03:07:15 +0000 (10:07 +0700)]
code: rename identifiers `with` since it is a keyword now

Signed-off-by: Jean Privat <jean@pryen.org>