Alexis Laferrière [Thu, 15 Jan 2015 16:03:52 +0000 (11:03 -0500)]
lib: intro the iOS library
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Fri, 27 Mar 2015 16:39:25 +0000 (12:39 -0400)]
nitc: support compiling for the iOS platform
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Alexis Laferrière [Sat, 28 Mar 2015 17:58:27 +0000 (13:58 -0400)]
nitc: `Toolchain` keeps the compiler as an attribute
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Sat, 28 Mar 2015 01:39:53 +0000 (08:39 +0700)]
Merge: Fast benches
Last week benches shows some failures on some options due to recent commits.
This PR add a `--fast --fast` option that test only `hello_world` so it could be used in continuous integration to test the various meaningful combination of compiling options.
Moreover, the script is simplified to be more simple to use and extends with new options or combination of options,
Pull-Request: #1217
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Sat, 28 Mar 2015 01:34:45 +0000 (08:34 +0700)]
Merge: Fast super strings
Superstrings, like "a{b}c", are managed in the AST as a special group of sub-expression nodes that are either literal string parts or standard expressions.
The previous example is basically `["a", b, "c"]`
Previously, the compilation of super-strings was direct: the values are grouped in an array and `to_s` is called on it.
So in fact `"a{b}c"` was compiled as `["a", b, "c"].to_s`.
This basic implementation is simple and correct. But it has some drawbacks:
* a new Array[Object] (and a NativeArray[Object]) is allocated each time the super-string is evaluated.
* all elements are to_s-ized in `Array::to_s`, even the literal parts.
* an additional NativeArray[String] is allocated in `Array:to_s` to do the fast concatenation.
Because of the numerous allocations, superstrings caused a lot of work to the GC.
This PR provides a better, but more complex implementation:
* instead of an Array[Object], a NativeArray[String] is directly build and a fast concatenation `native_to_s` is invoked.
* the allocated NativeArray is cached in a static variable so it can be reused in next evaluation.
* the literal string parts are stored in the native array as is, and only once just after the allocation of the native array.
Results for nitc/nitc/nitc:
before: 0m6.076s
after: 0m5.512s (-9% not bad!)
Pull-Request: #1219
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Sat, 28 Mar 2015 01:29:12 +0000 (08:29 +0700)]
Merge: lib/std/file: do not flush on each write
Flushing for each small element of an output made things too slow.
real (not user) time for nitc/nitc/nitc:
before: 0m7.373s
after: 0m5.901s (-20%)
Pull-Request: #1216
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Sat, 28 Mar 2015 01:26:29 +0000 (08:26 +0700)]
Merge: Some cleaning in vm files
This small PR creates a directory for all vm files and a unique entry point.
Signed-off-by: Julien Pagès <julien.projet@gmail.com>
Pull-Request: #1221
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 28 Mar 2015 01:23:37 +0000 (08:23 +0700)]
Merge: nitc: fix closing manifest writer, should fix bug on #1216
Pull-Request: #1220
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 28 Mar 2015 01:16:36 +0000 (08:16 +0700)]
tests: remove sav/nitg-e/error_needed_method_alt4.res since behavior is fixed
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Tue, 24 Mar 2015 00:24:12 +0000 (07:24 +0700)]
Merge: Fix --no-union-attributes
--no-union-attributes was broken since the tagging of primitive. This PR fix it.
Pull-Request: #1218
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Jean Privat [Sat, 21 Mar 2015 15:41:06 +0000 (22:41 +0700)]
compiler: prefill the native array with the literal string parts
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 15:40:01 +0000 (22:40 +0700)]
compiler: `ASuperstringExpr` store the native array in a static variable
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 15:38:19 +0000 (22:38 +0700)]
compiler: compile ASuperstringExpr using `native_to_s`
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 15:35:50 +0000 (22:35 +0700)]
lib: introduce `NativeArray::native_to_s`
Signed-off-by: Jean Privat <jean@pryen.org>
Alexis Laferrière [Mon, 23 Mar 2015 18:03:12 +0000 (14:03 -0400)]
nitc: fix closing manifest writer when done for #1216
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
Julien Pagès [Mon, 16 Mar 2015 12:23:03 +0000 (13:23 +0100)]
nitvm: Creation of a directory vm/ for the vm files
Signed-off-by: Julien Pagès <julien.projet@gmail.com>
Jean Privat [Sat, 21 Mar 2015 15:35:11 +0000 (22:35 +0700)]
compiler: add native_array_get and native_array_set
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 14:17:30 +0000 (21:17 +0700)]
lib/string_exp: initialize an uninitialized attribute
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 14:16:26 +0000 (21:16 +0700)]
sepcomp: initialize lazy guards to 'false' if opt_no_union_attribute.
Otherwise the guard is let at `NULL` (aka uninitialized) and will
ironically fail at runtime because the lazy guard is not initialized.
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 14:00:24 +0000 (21:00 +0700)]
sepcomp: isset is implemented on tagged attributes
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 13:58:55 +0000 (20:58 +0700)]
sepcomp: tag values when storing it with opt_no_union_attribute
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 15:16:18 +0000 (22:16 +0700)]
Merge: compiler: introduce and use `MType::is_c_primitive`
Thus remove all comparaison to "val*" in the code, this is cleaner.
Pull-Request: #1214
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Mon, 23 Mar 2015 15:16:10 +0000 (22:16 +0700)]
Merge: Simplify management of primitive types
Add direct methods to access primitive types
Simplify and improve the generation of primitive values in the compiler.
More (and improved) `*_instance` methods are now available in AbstractCompilerVisitor.
One of the point is the simplification of the generated C so that less local variables are generated, maybe this will also help the C compiler to work faster.
Pull-Request: #1213
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Jean Privat [Mon, 23 Mar 2015 10:34:36 +0000 (17:34 +0700)]
bench_engines: put all at the end
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 10:29:47 +0000 (17:29 +0700)]
bench_engine: refactor most tests in a single function
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 14:30:34 +0000 (21:30 +0700)]
compiler: introduce and use `MType::is_c_primitive`
Thus remove all comparison to "val*" in the code, this is cleaner.
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 13:01:03 +0000 (20:01 +0700)]
lib/std/exec: remove write buffon on pipes
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 09:55:42 +0000 (16:55 +0700)]
bench_engines: add --fast --fast to just check the compiler
It will be included in CI tests to prevent breaking benches.
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 09:54:16 +0000 (16:54 +0700)]
bench_engine: silent clean
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Mon, 23 Mar 2015 07:43:13 +0000 (14:43 +0700)]
lib/std/file: no not flush on each write
Flushing for each small element of an output made things too slow.
real (not user) time for nitc/nitc/nitc:
before: 0m7.373s
after: 0m5.901s (-20%)
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 05:21:03 +0000 (12:21 +0700)]
compiler: introduce and use char_instance, float_instance and null_instance
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 05:04:47 +0000 (12:04 +0700)]
compiler: `int_instance` and `bool_instance` return a inlined runtimevariable
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 05:02:13 +0000 (12:02 +0700)]
compiler: use `bool_instance` and `int_instance` when possible
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 14:25:25 +0000 (21:25 +0700)]
model: provide direct methods to access primitive types
This avoid that each module re-search class by their names
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 06:13:27 +0000 (13:13 +0700)]
Merge: compiler: improve `poset_from_mtypes` used for type coloring.
Instead of doing the full matrix mtypes X cast_types, a grouping is done by the base classes of the types so that we compare only types whose base classes are in inheritance.
For nitc/nitc/nitc the result is not that bad:
before:
0m6.584s
17.605 GIr
time passed in poset_from_mtypes: 26.01% (4.579 GIr)
now:
0m5.880s (-10%)
15.088 GIr (-14%)
time passed in poset_from_mtypes: 11.72% (1.768 GIr)
In the best condition, I can now expect to compile in less than 6s.
Note that coloring is still a MAJOR issue in term of compile time since 1/4 of the Ir are used to compute coloration.
* type_coloring: 17.23%
* property_coloring: 9.35%
Pull-Request: #1212
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Jean Privat [Sat, 21 Mar 2015 06:13:05 +0000 (13:13 +0700)]
Merge: Handle signal
This PR improves slightly the handling of signal by providing better defaults.
A side effect is that this close #754
Pull-Request: #1211
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Jean Privat [Sat, 21 Mar 2015 06:12:59 +0000 (13:12 +0700)]
Merge: contrib/header_keeper: a cog in the toolchains to generate FFI wrapper for C-like languages
This is needed by @Tagachi for the Objective-C wrapper.
Once again, everything is in the doc:
### Filters preprocessed C-like header files to remove included files
This tool is used in the process of parsing header files to extract
information on the declared services (the functions and structures).
This information is then used to generate bindings for Nit code
to access these services.
The C preprocessor extends macros, inline files marked with `#include`,
and more. This tool acts after the C preprocessor, in a way to keep
everything but the included files. It searches for line pragmas
to identify the source of each line. The result is printed to stdout.
Typical usage on the output of `gcc -E` (it would be the same with `clang`):
~~~
gcc -E /usr/include/SDL/SDL_image.h | header_keeper SDL_image.h > preprocessed_header.h
~~~
This module can also be used as a library. The main service is the method `header_keeper`.
Pull-Request: #1210
Reviewed-by: ArthurDelamare <>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Ait younes Mehdi Adel <overpex@gmail.com>
Jean Privat [Fri, 20 Mar 2015 06:56:15 +0000 (13:56 +0700)]
sepcomp: rename `compile_resolution_tables` as `compute_resolution_tables`
because there is no C generation, only abstract data-structures.
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Fri, 20 Mar 2015 06:48:22 +0000 (13:48 +0700)]
sepcomp: `do_type_coloring` can work directly with RTA results
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Fri, 20 Mar 2015 06:13:33 +0000 (13:13 +0700)]
sepcomp: add a missing undead type
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Fri, 20 Mar 2015 05:14:30 +0000 (12:14 +0700)]
compiler: improve `poset_from_mtypes` used for type coloring.
Instead of doing the full matrix mtypes X cast_types, a grouping is done by the base classes of the types so that we compare only types whose base classes are in inheritance.
For nitc/nitc/nitc the result is not that bad:
before:
0m6.584s
17.605 GIr
time passed in poset_from_mtypes: 26.01% (4.579 GIr)
now:
0m5.880s (-10%)
15.088 GIr (-14%)
time passed in poset_from_mtypes: 11.72% (1.768 GIr)
In the best condition, I can now expect to compile in less than 6s.
Note that coloring is still a MAJOR issue in term of compile time since 1/4 of the Ir are used to compute coloration.
* type_coloring: 17.23%
* property_coloring: 9.35%
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Fri, 20 Mar 2015 02:01:49 +0000 (09:01 +0700)]
lib/std/exec: `signal` will forward ^C (SIGINT) to the main program
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Fri, 20 Mar 2015 01:55:58 +0000 (08:55 +0700)]
comp: forward signals instead of exiting
Exit status of process distinguishes normal termination `WIFEXITED`
and signal-caused termination `WIFSIGNALED`.
Shells and other commands use this information to handle sub-commands.
Therefore, compiled programs should not, by default, terminate
their signal handler by an `exit` but should rethrow the original signal.
Signed-off-by: Jean Privat <jean@pryen.org>
Jean Privat [Sat, 21 Mar 2015 03:05:37 +0000 (10:05 +0700)]
compiler: rename `show_backtrace` as `fatal_exit`
Signed-off-by: Jean Privat <jean@pryen.org>
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>
Jean Privat [Thu, 19 Mar 2015 05:42:38 +0000 (12:42 +0700)]
Merge: lib: add `meta` as a user-level empty shell for meta-classes
Cleaning from old branches: a small useless meta-level.
The lib define meta-objects as some kind of multiton so you have a specific object to represent each class in the runtime-system (in fact each types because of genericity).
You can even define complex meta-deep hierarchy of meta-classes (with meta-loops).
The only issue is that these meta-objects are empty so basically useless (and meta-useless).
Pull-Request: #1205
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
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>
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>
Jean Privat [Thu, 19 Mar 2015 05:40:42 +0000 (12:40 +0700)]
lib: add `meta` as a user-level empty shell for meta-classes
Signed-off-by: Jean Privat <jean@pryen.org>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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