From: Jean Privat Date: Sat, 11 Oct 2014 12:24:15 +0000 (-0400) Subject: Merge: new option --define X-Git-Tag: v0.6.10~34 X-Git-Url: http://nitlanguage.org Merge: new option --define It is standard in compiled programs to be able to setup some program configuration at compile-time. Eg. C compilers accept a command-line option `-D` to define macros that will be used inside programs. It is useful for configuring some string (like `-D PREFIX=/opt/nit/`, or `-D PORT=8081`) or activate some parts (conditional compilation, eg `-D WITH_SSL`). This PR brings an equivalent capability to Nit engines through the new `-D` (`--define`) option. The design behind the -D it to enable specific refinement of top-level functions at link-time. Thus, basically ~~~sh $ cat my_foo.nit import foo redef fun prefix do return "/opt/nit/" $ nitg my_foo.nit ~~~ can be simplified into ~~~sh $ nitg foo.nit -D prefix=/opt/nit/ ~~~ Like `-m`, the `-D` creates a fictive module that refines the main module of the program. `-D` also use the return type of the refined method to know how to interpret the text of the value. Currently only Int, String and Bool is supported. ~~~nit module foo fun str: String do return "test" fun num: Int do return 1 fun flag: Bool do return false print str print num print flag ~~~ ~~~sh $ nitg foo.nit $ ./foo test 1 false $ nitg foo.nit -D str=hello -D num=42 -D flag $ ./foo hello 42 true ~~~ The code of the PR is quite straightforward and show again that the new model is quite robust. As usual, the first commits are some cleanup. The fun stuff is in the latter commits. Pull-Request: #815 Reviewed-by: Lucas Bajolet Reviewed-by: Alexandre Terrasa --- ff3bde9e1cd0e92d08166fc17373f6680c495f28