Welcome to this year's seventh issue of Niteration, the newsletter for the Nit project.
Combined Changes for June 2015
Have contributed (or co-authored patches): Alexis Laferrière, Jean Privat, Alexandre Terrasa, Lucas Bajolet, Romain Chanoir, Julien Pagès, Renata Carvalho, Anis Boubaker, Arthur Delamare, Mehdi Ait Younes, Herve Matysiak, Simon Zeni, Istvan Szalai and Jean-Philippe Caissy.
This month, some psychological figures where exploded
The first Nit Coding Party was held at UQAM, on June, 10. 13 participants, including first-time contributors, met up together to write 36 pull requests for tasks of RosettaCode
We introduced an FFI for the interpreter. This is a first draft/proof of concept to support the light FFI and a few more features, more work is needed to implement the full FFI and support for other languages.
When the interpreter has to execute an extern method, it compiles all the extern code of the modules into an external native shared library (.so). Then the interpreter dynamically loads the module, and invokes the C implementation function. The handle to the library is cached so that a module is compiled once per execution.
The current version is limited to the light FFI with a few more features. So there are extern methods, native type support and extern classes but does not support callbacks.
The interpreter can now run 7 out of the 24 tests for the FFI with C.
This version was kept "simple" by design, it lacks some not-so-hard to implement features as well as portability concerns:
The design was inspired by other interpreters and VM-based languages. The JNI expects the user to manually compile the extern code into a native shared library before executing the Java code. This FFI automates the same process.
NativeString
to char *
de34fbbLast one was Fri Feb 6, five months ago
This generation includes a lot of new things and bug fixes that are now usable in the compiler and the standard library.
We also removed all remaining deprecated reference to nitg
. The renaming of nitg
to nitc
and the deprecation of nitg
was done Wed Dec 10 so 6 month ago. cf 1000
As a new addition to the parser, as requested in [!issue 1261], literal floating-point values in exponent notation.
Literal strings used with to_re
are checked in order to find syntax errors in the regular expression. The question about a specific literal regular expression notation is still open.
This PR introduces better error management to the deserialization phase, the abstract engine and the JSON implementation. Deserialization of a malformed JSON string or a JSON serialized object from a different program version does not crash the program anymore, it will instead raise errors. When errors are raised, the deserialized object may be inconsistent with uninitialized attribute. Depending on the context, the object may have to be discarded or, usually with the user consent, it can be used with possible fatal failures later.
This PR also lightens the JSON format expected by the deserializer. This allow for nicer custom creation of Nit objects from JSON. For example, given a Opportunity-like Web app using the Nit class MeetupConfig
declared like so:
class MeetupConfig
serialize
var description: String
var max_participants: nullable Int
var answers: Array[FlatString]
end
On the client-side JavaScript code, one can create a JSON object that will be converted to a Nit instance of MeetupConfig
by the JSON deserialization services:
{"__class": "MeetupConfig", "description": "My Awesome Meetup",
"max_participants": null, "answers": ["Pepperoni", "Chicken"]}
A big set of loosely coupled but related changes on the annotations on attributes and methods. Here is a summary of the changes on the user-side:
autoinit
in interfaces.autoinit
is understood on attributes and is the default on value-less concrete attribute.Abstract attributes are noautoinit
by default, if autoinit
is given, it is applied on the setter. This way abstract attributes are basically just a couple of getter-setter.
Merge: Attribute and autoinit annotations 04a9a35
Separate compilation implies that a module is compiled independently of its clients. This point ensures that the recompilation of programs is fast since only modified modules need to be recompiled and that modules used by multiples clients need to be compiled only once.
Unfortunately, right now an already compiled module still needs to be fully compiled in C on each compilation (avoiding doing it is a very complex matter). Fortunately, most of the compilation time is spend by the C compiler and this time is safely decimated by ccache.
However, the thing is that some modules are imported by programs (thus provide declarations, introductions, importations) but are only made of method definitions that will never be executed by the program. Such a module is called a dead module and our static analysis RTA can approximate them. So, now, the generation of C code for such a module is skipped (and its associated C compilation, obviously)
This will benefit mostly for small programs that import standard and other libraries but only use a small portion of them. Eg: programs in tests/
or in examples/rossetacode
.
For numbers, let's try with time ./tests.sh ../examples/rosettacode/*.nit
to test the 32 (currently) programs.
after: 21s
Merge: Do not compile dead modules b1fff49
loop
Warn useless do block, like
loop do
print 1
end
This improve the robustness of tools when given --keep-going. Tools like nitpick, that have --keep-going by default, are more robust and collect more errors.
Moreover, the compiler can now compile simple programs with instructions that fail during the typing phase (most errors like unknown method or bad type).
These instructions are compiled with a run time error instead so the program is still expected to behave in an reliable way.
print 1
fail now
print 2
$ nitc kg.nit --keep-going
kg.nit:2,1--4: Error: method or variable `fail` unknown in `Sys`.
$ ./kg
1
Runtime error: FATAL: bad statement executed. (kg.nit:1)
One usage would be to force c_src
to compile things even if it lags behind.
Most detection of the availability of libunwind and the flags to use is moved at the C compilation time (in the Makefile) instead of the Nit compilation time.
Moreover, if libunwind is not available, then stacktraces are just disabled (instead of aborting).
The main advantage is that the generated C is more portable and can be compiled in a different system. Thus, this will help cross-compilation and should even enable the bootstrap on systems lacking libunwind, like Raspbian.
The option --stacktrace
is also replaced with a simpler --no-stacktrace
for people that want to disable it completely at C-compile time.
Since we plan on conforming with UTF-8, chars can no longer be of C char type, these PR changes the internal representation of a Char to become capable of holding an arbitrary Unicode code point. The separation for Char and Byte is still in progress, stay tuned.
char*
3a1e5caIn v0.7.5, the string module is over 2500 loc long.
For the mental health of the maintainer(s), it was getting too big to understand what was going on in it. So, we introduced the text group in standard, and string is split in several modules inside of it:
ropes: Rope-based strings
Merge: Removed intern dependencies from abstract to flat strings 0f9fbcb
The default to_s
on collections in now updated.
Before: [1, 2, 3].to_s == "123"
After: [1, 2, 3].to_s == "[1,2,3]"
The main issue is for code that used to_s
on array to get a fast concatenation. Those should now use plain_to_s
(or join("")
).
Changes:
import curl
var mail = new CurlMail("sen...@example.org", ["t...@example.org"], cc=["b...@example.org"])
mail.subject = "Hello From My Nit Program"
mail.body = "<h1>Here you can write HTML stuff.</h1>"
mail.headers_body["Content-Type:"] = """text/html; charset="UTF-8""""
mail.headers_body["Content-Transfer-Encoding:"] = "quoted-printable"
# Set mail server
var error = mail.set_outgoing_server("smtps://smtp.example.org:465",
"us...@example.org", "mypassword")
assert error == null
# Send
error = mail.execute
assert error == null
As Nit programmers, we might have to parse XML sometimes for one use or another.
We already had a SAX parser in library for the cases when one wanted to parse a long XML document in a memory-conscious way, often at the expense of the simplicity of the end-program.
This PR adds a very simple DOM parser that will need to be improved and made more robust later, but which right now does the basics and should parse valid xml documents. There is still a long way to get a full spec-compliant XML parser, but this is one base.
simplify_path
behavior for path starting with .
. 4c6f0ccOne day, a package manager will simplify the installation and the maintenance of third-party projects, libraries and programs in Nit, so that import foo
will import the project foo
if installed.
Nowadys, contrib
is used as a placeholder for some independent projects that are not mainly a library (or borderline). However, the nature of the Nit language, especially the refinement of class blurs the difference between libraries and programs and makes it conceivable to extend an existing program by refining it (or just reusing its base libraries). However, import foo
will not work if foo is in contrib, this issue has two current workarounds:
-I
with some relative path location in the Makefile, that is not practical because it should be used on each tools thus broke basic manual commands (like nitc on the command line) and automatic commands (like vim+nitpick).nitiwiki
The easy solution to solve this issue is to add contrib
to the libpath.
There is now a partial i18n support to Opportunity with a french translation. Most strings from the UI are covered but not the error messages.
There are also templates for the Opportunity meetup creation page. The default software provides: 4 kinds of pizzas, 5 days work week and 7 days week. The software customized for xymus.net also provides: pizzas special LATECE and meeting hours for UQAM Sciences.
Try it at http://xymus.net/opportunity/
Some fixes for nitiwiki in prevision for the nitlanguage.org site migration.
Feature summary:
root_url
.Try the beta at http://nitlanguage.org/beta/
friendz is updated to use the new mnit abstract sound system. A placebo implementation is also provided for linux.
Small features and bugfixes on tools. Nothing fundamental for the end user this month.
lib/markdown
52ef622Some internal things and bugfixes for the developers of the compiler and other nit tools
Some improvement in the tests/ directory with safer test execution and configurability