nit.git
9 years agocontrib: intro header_keeper, a cog in the toolchains to generate FFI bindings
Alexis Laferrière [Thu, 19 Mar 2015 15:04:12 +0000 (11:04 -0400)]
contrib: intro header_keeper, a cog in the toolchains to generate FFI bindings

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

9 years agoMerge: contrib/opportunity: prevent null receiver error
Jean Privat [Thu, 19 Mar 2015 05:42:25 +0000 (12:42 +0700)]
Merge: contrib/opportunity: prevent null receiver error

This error crashed the server 52 times in the last month.

Opportunity on xymus.net has already been updated.

Thanks to @isra17 and @ageei exec members for forging broken requests and revealing this problem.

Pull-Request: #1209
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Jean Privat <jean@pryen.org>

9 years agoMerge: Intro NitActivity an Android entry point in pure Nit, Java, and C (almost...
Jean Privat [Thu, 19 Mar 2015 05:42:17 +0000 (12:42 +0700)]
Merge: Intro NitActivity an Android entry point in pure Nit, Java, and C (almost no NDK)

This PR could be described in 3 steps.

* Clean up lib/android and move up `dalvik` in the module hierarchy.
* Intro NitActivity.java (the most important commit)
* Update calculator (only) to use the new NitActivity with all its perks.

See the doc of the nit_activity module for the details on the polyglot implementation, copied hre for your convenience:

This module is implemented in 3 languages:

* The Java code, in `NitActivity.java` acts as the entry point registered
   to the Android OS. It relays most of the Android callbacks to C.
   In theory, there may be more than one instance of `NitActivity` alive at
   a given time. They hold a reference to the corresponding Nit `Activity`
   in the attribute `nitActivity`.

* The C code is defined in the top part of this source file. It acts as a
   glue between Java and Nit by relaying calls between both languages.
   It keeps a global variables reference to the Java VM and the Nit `App`.

* The Nit code defines the `Activity` class with the callbacks from Android.
   The callback methods should be redefined by user modules.

Pull-Request: #1208
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Jean Privat <jean@pryen.org>

9 years agocontrib/opportunity: prevent null receiver error
Alexis Laferrière [Wed, 18 Mar 2015 18:57:24 +0000 (14:57 -0400)]
contrib/opportunity: prevent null receiver error

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

9 years agolib/jvm: fix missing import
Alexis Laferrière [Tue, 17 Mar 2015 21:11:54 +0000 (17:11 -0400)]
lib/jvm: fix missing import

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

9 years agoexamples/calculator: save and load state on request
Alexis Laferrière [Tue, 17 Mar 2015 18:25:41 +0000 (14:25 -0400)]
examples/calculator: save and load state on request

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

9 years agoexamples/calculator: add services to save and load from Json
Alexis Laferrière [Mon, 26 Jan 2015 01:36:43 +0000 (20:36 -0500)]
examples/calculator: add services to save and load from Json

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

9 years agoexamples/calculator: update Android UI to latest API
Alexis Laferrière [Mon, 26 Jan 2015 11:58:56 +0000 (06:58 -0500)]
examples/calculator: update Android UI to latest API

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

9 years agoexamples/calculator: use the new nit_activity
Alexis Laferrière [Tue, 17 Mar 2015 17:01:16 +0000 (13:01 -0400)]
examples/calculator: use the new nit_activity

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

9 years agoexamples/calculator: Makefile defines the `android-install` rule
Alexis Laferrière [Mon, 16 Mar 2015 18:30:02 +0000 (14:30 -0400)]
examples/calculator: Makefile defines the `android-install` rule

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

9 years agolib/android: update `ui` to use NitActivity and be on the UI thread
Alexis Laferrière [Tue, 27 Jan 2015 22:32:12 +0000 (17:32 -0500)]
lib/android: update `ui` to use NitActivity and be on the UI thread

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

9 years agolib/android: remove popup hack in `ui`
Alexis Laferrière [Mon, 26 Jan 2015 11:04:10 +0000 (06:04 -0500)]
lib/android: remove popup hack in `ui`

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

9 years agolib/android: intro our very own NitActivity
Alexis Laferrière [Sun, 3 Aug 2014 00:09:47 +0000 (20:09 -0400)]
lib/android: intro our very own NitActivity

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

9 years agoMerge: Optimize variable access in the nitvm
Jean Privat [Wed, 18 Mar 2015 09:21:09 +0000 (16:21 +0700)]
Merge: Optimize variable access in the nitvm

The first commit change the way variables are accessed in the vm.

For each method or attribute block (to init them), we recursively go into the AST to find each variable declaration in order to give them a fixed position (in the environment).
This is a small recursion since we only need to go deeper for block constructions.

During execution, the access are made by using this position instead of using the old ```HashMap[Variable, Instance]``` of the interpreter.

The second commit completely replace the frames of the interpreter to avoid allocation of these hashmaps in the virtual machine, the commit is pretty verbose but this is mainly code from the interpreter.

The overall gain is good since the vm is now faster than the interpreter :)

For the small benchmark ```nitvm src/nit.nit tests/base_simple3.nit```, we have 2.9 seconds with nitvm before.
Now, nitvm take 2.67 seconds, 2.83 for niti: 8% better.
The overall gain on a few benchmarks I made are between 5% and little more than 10% but always positive.

Pro: faster
Con: work will be required to maintain the two engines...

Pull-Request: #1184
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: lib/string: `Int::to_s` shortcuts 0 and 1
Jean Privat [Wed, 18 Mar 2015 05:41:48 +0000 (12:41 +0700)]
Merge: lib/string: `Int::to_s` shortcuts 0 and 1

Valgrid said it is used a lot.

So I mixed (`-m`) nitc with the following module

~~~nit
import counter

redef class Int
redef fun to_s
do
sys.itos_cpt.inc(self)
return super
end
end

redef class Sys
var itos_cpt = new Counter[Int]
redef fun run
do
super
itos_cpt.print_summary
itos_cpt.print_elements(10)
end
end
~~~

The result shows that `0` and `1` are the top `to_s`-ized numbers.

~~~
  0: 13554 (9.29%)
  1: 10012 (6.86%)
  2: 5671 (3.88%)
~~~

So I just shortcut-them to reduce allocations.

With nitc/nitc/nitc:
before: 0m6.756s
after: 0m6.632s (-2%)

Pull-Request: #1207
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Enable tagging of primitive types
Jean Privat [Wed, 18 Mar 2015 05:41:34 +0000 (12:41 +0700)]
Merge: Enable tagging of primitive types

Another old optimization since it was present in PRM, the Australopithecus compiler.

This PR bring back tagging of the primitives types Int, Bool and Char.

Previously, all primitive types where boxed.
It means that when a Bool, or any primitive object, must be manipulated in a polymorphic way (i.e. as an Object in a `val*`), a small box is allocated that contain the value and the reference (the `val*`) points to the box.
The boxes use the layout of real objects (with a pointer to the class table and everything) so that boxes are compatible with the various implementation of OO mechanism, eg `obj->class->vtf[METHODID]` to implement a method invocation.

Basically boxes work like Java auxiliary classes (eg. `Integer`) except that they are fully transparent for the user and, more important, a implementation detail unrelated to the specification of the language.
Therefore, one can provide a different implementation, like tagging, without worrying about breaking the specification and existing programs.

The principle of tagging is that `val*` values are overloaded to store primitive value in addition to genuine pointers to allocated object.
The two low bits of the `val*` (so 4 combinations) is used to distinguish if the value is a real pointer (in this case, bits are 00) or one of the masqueraded common type (Int, Bool and Char).
If it is a pointer there is nothing to do and the value can be used as is.
If it is a primitive value, then the real value is stored in the remaining bits (but shifted).
The trick works because allocated objects are aligned so that pointer of genuine allocated object have always their last two bits at 00.

The advantage of tagging is that this reduces the cost of manipulating primitive values in a polymorphic way, especially this reduce the numerous allocations of short lived boxes that is slow to do and increase the workload of the GC.
By comparison, with tagging, masquerading a Bool as a `val*` is easily done with few bit-to-bit operations.

Unfortunately, tagging is not a panacea since `val*` is not always a real pointer and require specific and additional protection to avoid doing `obj->class` in the case of `obj` is in fact a tagged value.
Therefore tagging add a minimal but systematic overhead to OO mechanisms like calls, type tests and equality tests.

After quick tests, the numbers are encouraging.

For nitc/nitc/nitc:
before: 0m6.796s
after: 0m6.452s (-5%, not that bad)

Benches where run and tagging was either comparable or better than systematic boxing:

![](https://cloud.githubusercontent.com/assets/135828/6656784/b5a38698-cb67-11e4-96a4-c46f7df2331f.png)

Especially `lib/ai/examples/queens.nit` get the best of it with a -20% improvement.
That make sense because it use arrays of integers to model the states of the n-queen problem. And unfortunately arrays are implemented in a homogeneous way where elements are always polymorphic `val*` values.
Once generics and collections are implemented in an heterogeneous way for primitive types, the benefit of tagging should be reevaluated.

Note: funnily, the main commit of the series, the one that implements tagging, is only made of insertions of lines (no deletion or changes) and it only modifies a single file.

Pull-Request: #1206
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Derive all the things
Jean Privat [Wed, 18 Mar 2015 05:41:23 +0000 (12:41 +0700)]
Merge: Derive all the things

This PR is crazy and inspired by https://github.com/privat/nit/pull/1202#discussion_r26359435
Basically, you will find here some hackish user-level pseudo meta-programming with optional unsafe support from the execution engines trough injection of code in the AST.

The idea is a generalization (and a basic simplification) of the approach or @xymus for serialization.
If fact, there is 2 level of generalizations.

In the compiler, a new phase `deriving` offers a static deriving mechanism. For instance, the annotation `auto_inspect` will implements the `inspect` method with a simple recursive inspection of attributes.

In the standard library, a new module `deriving` offers a general mechanism with a new standard `derive_to_map` method that is expected to dump attributes in a simple HashMap.

This basic low-level method is used to provide user-defined deriving methods.
For instance, the module provide basic derived implementation of `==`, `to_s` and `hash` in pure Nit at the user-level.

Moreover, the compiler phase `deriving` is extended to provide `auto_derive` that statically implements `derive_to_map`

Here an example from the code:

~~~nit
class A
   auto_derive
   super DeriveToS
   var an_int: Int
   var a_string: String
end

var a = new A(5, "five")
assert a.to_s == "an_int:5; a_string:five"
~~~

Pull-Request: #1204
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Nitunit works with groups and markdown files
Jean Privat [Wed, 18 Mar 2015 05:41:01 +0000 (12:41 +0700)]
Merge: Nitunit works with groups and markdown files

A lot of work but quite straightforward. Nit can be a really nice language when doing maintenance of old code.

The first part ot the PR updates the nitdoc to test documentation of groups (as requested by #1201)
The second part of the PR (I planned to do 2 PR but the second was more easy to do than expected) makes that nitunit can also process sand-alone markdown files (documentation, wiki pages, etc.).

Example:

~~~
-- foo/
   |-- README.md
   `-- foo.nit
~~~

~~~sh
# to test all entities of a module (classes, methods, etc.)
$ nitunit foo/foo.nit
# to test all entities of a group (the group and all its modules)
$ nitunit foo
# to test a given markdown file
$ nitunit foo/README.md
~~~

Close: #1201

Pull-Request: #1203
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

9 years agoMerge: Document Nit Serialization
Jean Privat [Wed, 18 Mar 2015 05:40:51 +0000 (12:40 +0700)]
Merge: Document Nit Serialization

The Nit serialization system did not have any documentation. This is the base to a better documentation.

In a next PR I may make more services of the serializers private. Implementations, such as json_serialization, will need to intrude import serialization. However, the end-user will only see the basic services.

Pull-Request: #1202
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Philippe Pépos Petitclerc <>
Reviewed-by: Frédéric Vachon <fredvac@gmail.com>

9 years agobenches: add --no-tag-primitive
Jean Privat [Sun, 15 Mar 2015 14:35:43 +0000 (21:35 +0700)]
benches: add --no-tag-primitive

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

9 years agoman: document --no-tag-primitive
Jean Privat [Sun, 15 Mar 2015 15:11:19 +0000 (22:11 +0700)]
man: document --no-tag-primitive

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

9 years agoerrasurecomp: disable tagging of primitives to not break the tests
Jean Privat [Sun, 15 Mar 2015 15:03:13 +0000 (22:03 +0700)]
errasurecomp: disable tagging of primitives to not break the tests

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

9 years agosepcomp: implement tagging of primitive types
Jean Privat [Sun, 15 Mar 2015 15:02:00 +0000 (22:02 +0700)]
sepcomp: implement tagging of primitive types

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

9 years agosepcomp: introduce `class_info` to protect the access to the class struct
Jean Privat [Sun, 15 Mar 2015 14:53:08 +0000 (21:53 +0700)]
sepcomp: introduce `class_info` to protect the access to the class struct

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

9 years agotests: add test_deriving
Jean Privat [Sun, 15 Mar 2015 05:55:21 +0000 (12:55 +0700)]
tests: add test_deriving

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

9 years agolib/deriving: new module `deriving` with basic interfaces
Jean Privat [Sat, 14 Mar 2015 15:46:56 +0000 (22:46 +0700)]
lib/deriving: new module `deriving` with basic interfaces

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

9 years agofrontend: new phase `deriving` to derive things
Jean Privat [Sat, 14 Mar 2015 14:22:43 +0000 (21:22 +0700)]
frontend: new phase `deriving` to derive things

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

9 years agoneo: save location of mdoc objects
Jean Privat [Sat, 14 Mar 2015 08:43:58 +0000 (15:43 +0700)]
neo: save location of mdoc objects

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

9 years agoman: update documentation of nitunit with groups and markdown files
Jean Privat [Sat, 14 Mar 2015 06:45:22 +0000 (13:45 +0700)]
man: update documentation of nitunit with groups and markdown files

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

9 years agotests: add test_nitunit_md.md to test nitdoc with markdown file
Jean Privat [Sat, 14 Mar 2015 06:36:36 +0000 (13:36 +0700)]
tests: add test_nitunit_md.md to test nitdoc with markdown file

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

9 years agonitunit: can work with markdown files in parameters
Jean Privat [Sat, 14 Mar 2015 06:38:19 +0000 (13:38 +0700)]
nitunit: can work with markdown files in parameters

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

9 years agoloader: add `filter_nit_source` to help tools to manage non-nit arguments on their...
Jean Privat [Sat, 14 Mar 2015 06:35:05 +0000 (13:35 +0700)]
loader: add `filter_nit_source` to help tools to manage non-nit arguments on their command line

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

9 years agoloader: `load_module` error message distinguish non-existing file from invalid file
Jean Privat [Sat, 14 Mar 2015 06:34:20 +0000 (13:34 +0700)]
loader: `load_module` error message distinguish non-existing file from invalid file

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

9 years agoloader: can load a markdown file as a MDoc
Jean Privat [Sat, 14 Mar 2015 06:38:01 +0000 (13:38 +0700)]
loader: can load a markdown file as a MDoc

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

9 years agotests: add test_nitunit3 for nitunit on groups
Jean Privat [Sat, 14 Mar 2015 05:25:18 +0000 (12:25 +0700)]
tests: add test_nitunit3 for nitunit on groups

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

9 years agonitunit: run nitunits for documentation of groups
Jean Privat [Sat, 14 Mar 2015 05:21:09 +0000 (12:21 +0700)]
nitunit: run nitunits for documentation of groups

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

9 years agonitunit: work with `mdoc` instead of `ndoc`
Jean Privat [Sat, 14 Mar 2015 05:19:34 +0000 (12:19 +0700)]
nitunit: work with `mdoc` instead of `ndoc`

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

9 years agonitunit: `NitUnitExecutor::mmodule` can be null
Jean Privat [Sat, 14 Mar 2015 05:18:36 +0000 (12:18 +0700)]
nitunit: `NitUnitExecutor::mmodule` can be null

Standard is then implicitly imported

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

9 years agonitunit: factorize file creation and compilation for docunits
Jean Privat [Sat, 14 Mar 2015 05:16:41 +0000 (12:16 +0700)]
nitunit: factorize file creation and compilation for docunits

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

9 years agoandroid: declare Activities for the manifest in an annotation
Alexis Laferrière [Mon, 16 Mar 2015 18:11:49 +0000 (14:11 -0400)]
android: declare Activities for the manifest in an annotation

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

9 years agolib/android: the dalvik module is higher in the importation hierarchy
Alexis Laferrière [Mon, 16 Mar 2015 19:07:03 +0000 (15:07 -0400)]
lib/android: the dalvik module is higher in the importation hierarchy

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

9 years agolib/android: fix typos in the dalvik module
Alexis Laferrière [Mon, 16 Mar 2015 20:07:27 +0000 (16:07 -0400)]
lib/android: fix typos in the dalvik module

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

9 years agolib/android: clean up whitespaces in native_app_glue
Alexis Laferrière [Mon, 16 Mar 2015 20:00:54 +0000 (16:00 -0400)]
lib/android: clean up whitespaces in native_app_glue

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

9 years agolib/jvm: clean up, add doc and make private stuff private
Alexis Laferrière [Tue, 17 Mar 2015 15:14:03 +0000 (11:14 -0400)]
lib/jvm: clean up, add doc and make private stuff private

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

9 years agolib/string: `Int::to_s` shortcuts 0 and 1
Jean Privat [Mon, 16 Mar 2015 02:10:27 +0000 (09:10 +0700)]
lib/string: `Int::to_s` shortcuts 0 and 1

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

9 years agotests: update expected errors in serialization tests
Alexis Laferrière [Sat, 14 Mar 2015 15:26:25 +0000 (11:26 -0400)]
tests: update expected errors in serialization tests

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

9 years agotests: Object is an interface
Jean Privat [Sun, 15 Mar 2015 07:09:16 +0000 (14:09 +0700)]
tests: Object is an interface

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

9 years agonitvm: The interpreter and the vm have each their own specialized frames
Julien Pagès [Fri, 13 Mar 2015 15:54:18 +0000 (16:54 +0100)]
nitvm: The interpreter and the vm have each their own specialized frames

The class Frame is now abstract

Signed-off-by: Julien Pagès <julien.projet@gmail.com>

9 years agoniti: Introduce a method to create and initialize a Frame
Julien Pagès [Fri, 13 Mar 2015 15:51:08 +0000 (16:51 +0100)]
niti: Introduce a method to create and initialize a Frame

Signed-off-by: Julien Pagès <julien.projet@gmail.com>

9 years agoniti: Introduce and use a virtual type for the frames
Julien Pagès [Fri, 13 Mar 2015 15:46:46 +0000 (16:46 +0100)]
niti: Introduce and use a virtual type for the frames

Signed-off-by: Julien Pagès <julien.projet@gmail.com>

9 years agonitvm: The local variables are numbered
Julien Pagès [Tue, 10 Feb 2015 16:08:19 +0000 (17:08 +0100)]
nitvm: The local variables are numbered

The access to them is made by their position in this array

Signed-off-by: Julien Pagès <julien.projet@gmail.com>

9 years agoMerge: Better Vim documentation on classes (with special attention to the doc of...
Jean Privat [Sun, 15 Mar 2015 02:30:43 +0000 (09:30 +0700)]
Merge: Better Vim documentation on classes (with special attention to the doc of Container)

Calling Nitdoc() or Ctrl-D on the word `Container` will now display the following in the preview window.

~~~
# standard::Container[standard::Container::E]

A collection that contains only one item.

Used to pass arguments by reference.

Also used when one want to give a single element when a full
collection is expected

## Class hierarchy
* Direct super classes: Collection
* All super classes: Collection, Object
* Direct sub classes: ListNode
* All sub classes: ListNode

## Properties
+ count(item: E): Int  # How many occurrences of `item` are in the collection?
+ first: E  # Return the first item of the collection
+ has(item: E): Bool  # Is `item` in the collection ?
+ has_all(other: Collection[E]): Bool  # Does the collection contain at least each element of `other`?
+ has_exactly(other: Collection[E]): Bool  # Does the collection contain exactly all the elements of `other`?
+ has_only(item: E): Bool  # Is the collection contain only `item`?
+ is_empty: Bool  # Is there no item in the collection?
+ item: E  # The stored item
+ item=(item: E)  # The stored item
+ iterator: Iterator[E]  # Get a new iterator on the collection.
+ join(sep: Text): String  # Concatenate and separate each elements with `sep`.
+ length: Int  # Number of items in the collection.
+ rand: E  # Return a random element form the collection
+ to_a: Array[E]  # Build a new array from a collection
~~~

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

9 years agolib/json_serialization: clean up
Alexis Laferrière [Wed, 11 Mar 2015 23:48:25 +0000 (19:48 -0400)]
lib/json_serialization: clean up

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

9 years agolib/serialization: make `serialize_reference` protected
Alexis Laferrière [Wed, 11 Mar 2015 23:48:11 +0000 (19:48 -0400)]
lib/serialization: make `serialize_reference` protected

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

serial_ref

9 years agolib/serialization: revamp documentation of default module
Alexis Laferrière [Wed, 11 Mar 2015 23:44:41 +0000 (19:44 -0400)]
lib/serialization: revamp documentation of default module

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

9 years agolib/serialization: add README.md
Alexis Laferrière [Wed, 11 Mar 2015 20:37:44 +0000 (16:37 -0400)]
lib/serialization: add README.md

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

9 years agolib/serialization: make into a group
Alexis Laferrière [Wed, 11 Mar 2015 17:25:16 +0000 (13:25 -0400)]
lib/serialization: make into a group

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

9 years agolib/standard: forgot to provide `Map::hash` when `Map::==` was implemented
Jean Privat [Sat, 14 Mar 2015 14:19:02 +0000 (21:19 +0700)]
lib/standard: forgot to provide `Map::hash` when `Map::==` was implemented

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

9 years agomodel: add `MDoc::location`
Jean Privat [Sat, 14 Mar 2015 05:13:53 +0000 (12:13 +0700)]
model: add `MDoc::location`

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

9 years agolocation: handle `Loation::line_start` of 0 as a special case for the full file
Jean Privat [Sat, 14 Mar 2015 05:13:08 +0000 (12:13 +0700)]
location: handle `Loation::line_start` of 0 as a special case for the full file

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

9 years agoMerge: lib/noise: fix gradient_vector to return a unit vector
Jean Privat [Thu, 12 Mar 2015 05:59:10 +0000 (12:59 +0700)]
Merge: lib/noise: fix gradient_vector to return a unit vector

This was an error in the previous implementation. It will now produce noise with a better/greater amplitude so they are... noisier.

The sample result of InterpolatedNoise shows that it now uses the full amplitude, from 0 to f. The sample result of PerlinNoise uses 1 to d, which is a reasonable portion of the full amplitude of 16 considering that it uses only 4 layers and thus the real amplitude is of 15 (8+4+2+1).

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

9 years agoMerge: tests: add bench_strfib.nit
Jean Privat [Thu, 12 Mar 2015 05:59:00 +0000 (12:59 +0700)]
Merge: tests: add bench_strfib.nit

A simple program that recursively build and concatenate strings.

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

9 years agoMerge: mnit tileset and numbers
Jean Privat [Thu, 12 Mar 2015 05:58:53 +0000 (12:58 +0700)]
Merge: mnit tileset and numbers

Features from WBTW, used mainly to set the size of in-game hints and events boxes.

These modules are for Mnit but will be ported to Gamnit someday...

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

9 years agolib/noise: fix gradient_vector to return a unit vector
Alexis Laferrière [Wed, 11 Mar 2015 14:14:10 +0000 (10:14 -0400)]
lib/noise: fix gradient_vector to return a unit vector

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

9 years agolib/numbers: remove `NumberImages` constructors for spec and to make it public
Alexis Laferrière [Sun, 11 May 2014 00:49:57 +0000 (20:49 -0400)]
lib/numbers: remove `NumberImages` constructors for spec and to make it public

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

9 years agolib/tileset: fix typos in doc
Alexis Laferrière [Tue, 10 Mar 2015 21:21:23 +0000 (17:21 -0400)]
lib/tileset: fix typos in doc

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

9 years agolib/tileset: intro `TileSetFont::text_width`
Alexis Laferrière [Mon, 17 Nov 2014 17:59:49 +0000 (12:59 -0500)]
lib/tileset: intro `TileSetFont::text_width`

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

9 years agolib/tileset: intro `TileSetFont::text_height`
Alexis Laferrière [Mon, 17 Nov 2014 15:33:18 +0000 (10:33 -0500)]
lib/tileset: intro `TileSetFont::text_height`

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

9 years agolib/tileset: intro `TileSetFont::advance`
Alexis Laferrière [Mon, 25 Aug 2014 19:31:29 +0000 (15:31 -0400)]
lib/tileset: intro `TileSetFont::advance`

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

9 years agotests: add bench_strfib.nit
Jean Privat [Wed, 11 Mar 2015 01:01:48 +0000 (08:01 +0700)]
tests: add bench_strfib.nit

A simple program that recursively build and concatenate strings.

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

9 years agoMerge: Noise generators: Perlin and interpolated
Jean Privat [Tue, 10 Mar 2015 23:38:32 +0000 (06:38 +0700)]
Merge: Noise generators: Perlin and interpolated

Intro the PerlinNoise generator and the underlying (but independent) InterpolatedNoise, with some related services.

The rosetta code Perlin noise example (in 3D) is for comparison to my implementation in `lib/noise.nit` in (2D). We do not get the expected result with this implementation, 0.13691995878400010 vs 0.13691995878400012. It may be an error in the implementation of `Float.to_precision`... this will require further investigation.

The optimized `SequenceRead::rand` is a bonus! it is not used in this PR.

Pull-Request: #1194
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

9 years agovim autocomplete: fix `MDoc` used for classes
Alexis Laferrière [Tue, 10 Mar 2015 20:01:32 +0000 (16:01 -0400)]
vim autocomplete: fix `MDoc` used for classes

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

9 years agovim autocomplete: doc of classes list properties and class hierarchy
Alexis Laferrière [Mon, 9 Mar 2015 19:43:17 +0000 (15:43 -0400)]
vim autocomplete: doc of classes list properties and class hierarchy

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

9 years agovim autocomplete: rename `write_to_stream` to `write_doc` with more arguments
Alexis Laferrière [Tue, 10 Mar 2015 19:59:42 +0000 (15:59 -0400)]
vim autocomplete: rename `write_to_stream` to `write_doc` with more arguments

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

9 years agosrc/model: remove extra } from `MGenericType::to_s`
Alexis Laferrière [Tue, 10 Mar 2015 19:58:51 +0000 (15:58 -0400)]
src/model: remove extra } from `MGenericType::to_s`

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

9 years agolib/collection: fix doc of the popular `Container`
Alexis Laferrière [Tue, 10 Mar 2015 19:58:24 +0000 (15:58 -0400)]
lib/collection: fix doc of the popular `Container`

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

9 years agomisc/vim: nitdoc function search for a precise word
Alexis Laferrière [Tue, 10 Mar 2015 19:58:00 +0000 (15:58 -0400)]
misc/vim: nitdoc function search for a precise word

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

9 years agoMerge: Abstract attribute
Jean Privat [Tue, 10 Mar 2015 13:51:12 +0000 (20:51 +0700)]
Merge: Abstract attribute

Add the annotation `abstract` on attributes.

It is just a syntactic sugar to define a couple of abstract getter-setters with a shared documentation without an associated slot in the instance so it can be used in interfaces.

~~~nit
interface Foo
var a: Object is abstract
end

class Bar
super Foo
         # A concrete attribute that redefine the abstract one
redef var a
end

class Baz
super Foo
var real_a: Object
         # A pair of concrete methods that redefine the abstract attribute
redef fun a do return real_a
redef fun a=(x) do real_a = x
end
~~~

The visibility rules are unchanged with regard to concrete attributes, so by default the writer is private.

Needed cleaning (and a bugfix) are included in the PR

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

9 years agoMerge: Faster buffers
Jean Privat [Tue, 10 Mar 2015 13:51:03 +0000 (20:51 +0700)]
Merge: Faster buffers

Make flatbuffers a little faster on substrings

for nitc/nitc/nitc
before: 0m7.168s
after: 0m7.068s (-1.4%)

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

9 years agolib/stream: BufferedReader return the buffer if less than asked to read
Jean Privat [Fri, 6 Mar 2015 13:09:05 +0000 (20:09 +0700)]
lib/stream: BufferedReader return the buffer if less than asked to read

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

9 years agolib/string: faster substring for FlatBuffer
Jean Privat [Fri, 6 Mar 2015 13:00:48 +0000 (20:00 +0700)]
lib/string: faster substring for FlatBuffer

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

9 years agolib/string: document FlatString::with_infos
Jean Privat [Mon, 9 Mar 2015 01:37:38 +0000 (08:37 +0700)]
lib/string: document FlatString::with_infos

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

9 years agoMerge: Serialization phase skips abstract classes and add depth option to nitserial
Jean Privat [Tue, 10 Mar 2015 10:10:38 +0000 (17:10 +0700)]
Merge: Serialization phase skips abstract classes and add depth option to nitserial

This is a minor fix and new feature for the serialization support.

* Prevents bug where the serialization phase create constructors for abstract classes.
* Nitserial generates the generics support code for different depths: single module, group or project.

Note that the serialization does not support fully the new constructors. But it can still be used on small classes that do not use any "fancy" constructor features.

Pull-Request: #1193
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Jean Privat <jean@pryen.org>

9 years agoMerge: Vim autocomplete search in doc and 2 new useful Vim functions
Jean Privat [Tue, 10 Mar 2015 10:10:31 +0000 (17:10 +0700)]
Merge: Vim autocomplete search in doc and 2 new useful Vim functions

* The omnifunc for Nit search for autocomplete suggestions in the doc. So if you write `12.modulo`, then hit `Ctrl-X Ctrl-O` (launching the omnifunc), it will suggest `%` to replace the `modulo` part. This is useful when guessing the name of the wanted entity.

* The Nitdoc function can be mapped to `Ctrl-D` to show the doc associated to the word under the cursor. There is still no semantic analysis here, so it will list all possible docs.

* The NitGitGrep function can be mapped to `Ctrl-G` to find instances of the word under the cursor in the currect directory using `git grep`. It will first try to display any definitions and then its uses. This one is a bit trickier to use, but it can be very useful.

----
Bonus hint! You can select the size of the preview window to 5 lines with `set previewheight=5` (@Morriar)

Pull-Request: #1192
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Jean Privat <jean@pryen.org>

9 years agoexamples: add the Perlin noise Rosetta code example
Alexis Laferrière [Fri, 6 Mar 2015 21:07:38 +0000 (16:07 -0500)]
examples: add the Perlin noise Rosetta code example

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

9 years agolib: intro 2 noise generators
Alexis Laferrière [Thu, 5 Mar 2015 19:14:37 +0000 (14:14 -0500)]
lib: intro 2 noise generators

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

9 years agonitserial: add depth option
Alexis Laferrière [Sun, 16 Nov 2014 01:26:46 +0000 (20:26 -0500)]
nitserial: add depth option

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

9 years agolib: intro `Float::log_base`
Alexis Laferrière [Mon, 9 Mar 2015 20:53:41 +0000 (16:53 -0400)]
lib: intro `Float::log_base`

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

9 years agolib: intro `Float.lerp` for simple linear interpolation
Alexis Laferrière [Wed, 4 Mar 2015 02:01:52 +0000 (21:01 -0500)]
lib: intro `Float.lerp` for simple linear interpolation

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

9 years agolib: add an optimized `SequenceRead[E].rand`
Alexis Laferrière [Wed, 4 Mar 2015 02:00:35 +0000 (21:00 -0500)]
lib: add an optimized `SequenceRead[E].rand`

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

9 years agonitserial: do not generate constructors for abstract classes
Alexis Laferrière [Sun, 16 Nov 2014 01:57:17 +0000 (20:57 -0500)]
nitserial: do not generate constructors for abstract classes

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

9 years agomisc/vim: search in synopsis and full doc for matches
Alexis Laferrière [Mon, 9 Mar 2015 17:36:29 +0000 (13:36 -0400)]
misc/vim: search in synopsis and full doc for matches

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

9 years agomisc/vim: use case insensitive search for entity names
Alexis Laferrière [Wed, 4 Mar 2015 02:47:05 +0000 (21:47 -0500)]
misc/vim: use case insensitive search for entity names

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

9 years agovim autocomplete: always write generated doc to metadata files
Alexis Laferrière [Sun, 8 Mar 2015 00:10:00 +0000 (19:10 -0500)]
vim autocomplete: always write generated doc to metadata files

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

9 years agomisc/vim: add a function to search for instances of the word under the cursor
Alexis Laferrière [Sun, 8 Mar 2015 00:09:09 +0000 (19:09 -0500)]
misc/vim: add a function to search for instances of the word under the cursor

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

9 years agomisc/vim: add a function to show the doc of the entity under the cursor
Alexis Laferrière [Sat, 7 Mar 2015 04:21:55 +0000 (23:21 -0500)]
misc/vim: add a function to show the doc of the entity under the cursor

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

9 years agomisc/vim: extract the service to find metadata files from the omnifunc
Alexis Laferrière [Sat, 7 Mar 2015 04:21:05 +0000 (23:21 -0500)]
misc/vim: extract the service to find metadata files from the omnifunc

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

9 years agoMerge: Optimize nitc
Jean Privat [Sat, 7 Mar 2015 05:17:35 +0000 (12:17 +0700)]
Merge: Optimize nitc

Some minor optimizations after looking at reports of valgrind.

Pull-Request: #1191
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agoMerge: Reuse Array Iterators
Jean Privat [Sat, 7 Mar 2015 05:17:28 +0000 (12:17 +0700)]
Merge: Reuse Array Iterators

on nitc/nitc/nit this reduce a lot the number of allocated iterators.

before:

* 0m7.168s
* 2,706,498 new ArrayIterator
* the second most allocated class (after NativeArray)

after:

* 0m7.060s (-1.5%)
* 785,781 new ArrayIterator (-70%)
* the 7th most allocated class

Pull-Request: #1190
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

9 years agoMerge: More lazyness in standard
Jean Privat [Sat, 7 Mar 2015 05:17:21 +0000 (12:17 +0700)]
Merge: More lazyness in standard

Make lazy some attributes of often used classes. So that the attribute creation cost only when they are really used.

More impact that initially imagined:

for nitc/nitc/nitc
before: 7.188
after: 7.008 (-2.5%)

Pull-Request: #1188
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>