Merge: transform loops
authorJean Privat <jean@pryen.org>
Wed, 15 Oct 2014 20:15:47 +0000 (16:15 -0400)
committerJean Privat <jean@pryen.org>
Wed, 15 Oct 2014 20:15:47 +0000 (16:15 -0400)
In order to activate more optimizations and simplify code generators and analysis, the `while` and `for` loops must be transformed into simpler forms (in fact in complex forms but with simpler elements)

However, to do such a transformation, the escaping mechanism (break/continue/goto) must be rewrote.
Previously, for each loop control structure (loop for, while), a single EscapeMark was generated and breaks and continues are associated to the same mark, even if they branch in distinct points (so each escapemark had 2 branching mechanisms)
Now, with the first commits, two escapemarks are generated for each loop control structure, and breaks and continues are associated to a different one. The advantage is that each mark only have a single branching mechanism and that once associated to their mark, there is no need to distinguish break and continue (both become simple gotos).

The transformations of loops can be then implemented.

The `while`

~~~
while cond do block
~~~

is transformed into

~~~
loop if cond then block else break
~~~

and `for`

~~~
for i in col do block
~~~

is transformed into

~~~
var it = col.iterator
loop
   if it.is_ok then
      var i = it.item
      do block
      # ^ `continue` in the block it attached to the `do`
      # this is why the transformation of escape-marks where needed in fact.
      # and break is associated to the main loop
      it.next
   else
      break
   end
end
it.finish
~~~

Note that these transformations are basically what is currently implemented in rta, niti and nitg. Except that, now with a single transformation point, those three workers does not need to do their own transformation and basically can just rely on the one done on the AST level.

Pull-Request: #818
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

48 files changed:
lib/console.nit
lib/mnit/mnit_injected_input.nit
lib/nitcorn/http_request.nit
lib/opts.nit
src/astbuilder.nit
src/compiler/abstract_compiler.nit
src/compiler/android_annotations.nit
src/compiler/coloring.nit
src/compiler/compiler_ffi.nit
src/compiler/global_compiler.nit
src/compiler/separate_compiler.nit
src/compiler/separate_erasure_compiler.nit
src/doc/doc_model.nit
src/ffi/java.nit
src/highlight.nit
src/interpreter/debugger.nit
src/interpreter/naive_interpreter.nit
src/metrics/tables_metrics.nit
src/mixin.nit [new file with mode: 0644]
src/model/model.nit
src/model_utils.nit
src/modelbuilder.nit
src/modelize/modelize_class.nit
src/modelize/modelize_property.nit
src/neo.nit
src/nit.nit
src/nitpretty.nit
src/nitserial.nit
src/parser/parser_work.nit
src/rapid_type_analysis.nit
src/semantize/auto_super_init.nit
src/semantize/typing.nit
src/testing/testing_doc.nit
src/toolcontext.nit
src/vm.nit
tests/nit.args
tests/nitg.args
tests/niti.skip
tests/sav/base_eq_null_notnull.res
tests/sav/base_var_type_evolution_null3.res
tests/sav/base_var_type_evolution_null3_alt1.res
tests/sav/nit_args4.res [new file with mode: 0644]
tests/sav/nitg_args8.res [new file with mode: 0644]
tests/sav/niti/error_needed_method_alt3.res [deleted file]
tests/sav/niti/error_needed_method_alt4.res
tests/sav/test_define.res [new file with mode: 0644]
tests/test_define.nit [new file with mode: 0644]
tests/test_jvm.nit

index e6a129f..04dcb6e 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Simple numerical statistical analysis and presentation
+# Defines some ANSI Terminal Control Escape Sequences.
 module console
 
-# Redef String class to add a function to color the string
-redef class String
-       private fun add_escape_char(escapechar: String): String do
-               return "{escapechar}{self}{esc}[0m"
+# A ANSI/VT100 escape sequence.
+abstract class TermEscape
+       # The US-ASCII ESC character.
+       protected fun esc: Char do return 27.ascii
+end
+
+# ANSI/VT100 code to switch character attributes (SGR).
+#
+# By default, resets everything to the terminal’s defaults.
+#
+# Note:
+#
+# The escape sequence inserted at the end of the string by terminal-related
+# methods of `String` resets all character attributes to the terminal’s
+# defaults. So, when combining format `a` and `b`, something like
+# `("foo".a + " bar").b` will not work as expected, but `"foo".a.b + " bar".b`
+# will. You may also use `TermCharFormat` (this class).
+#
+# Usage example:
+#
+#     print "{(new TermCharFormat).yellow_fg.bold}a{(new TermCharFormat).yellow_fg}b{new TermCharFormat}"
+class TermCharFormat
+       super TermEscape
+
+       private var attributes: Array[String] = new Array[String]
+
+       # Copies the attributes from the specified format.
+       init from(format: TermCharFormat) do
+               attributes.add_all(format.attributes)
        end
 
-       private fun esc: Char do return 27.ascii
-       fun gray: String do return add_escape_char("{esc}[30m")
-       fun red: String do return add_escape_char("{esc}[31m")
-       fun green: String do return add_escape_char("{esc}[32m")
-       fun yellow: String do return add_escape_char("{esc}[33m")
-       fun blue: String do return add_escape_char("{esc}[34m")
-       fun purple: String do return add_escape_char("{esc}[35m")
-       fun cyan: String do return add_escape_char("{esc}[36m")
-       fun light_gray: String do return add_escape_char("{esc}[37m")
-       fun bold: String do return add_escape_char("{esc}[1m")
-       fun underline: String do return add_escape_char("{esc}[4m")
+       redef fun to_s: String do return "{esc}[{attributes.join(";")}m"
+
+       # Apply the specified SGR and return `self`.
+       private fun apply(sgr: String): TermCharFormat do
+               attributes.add(sgr)
+               return self
+       end
+
+       # Apply normal (default) format and return `self`.
+       fun default: TermCharFormat do return apply("0")
+
+       # Apply bold weight and return `self`.
+       fun bold: TermCharFormat do return apply("1")
+
+       # Apply underlining and return `self`.
+       fun underline: TermCharFormat do return apply("4")
+
+       # Apply blinking or bold weight and return `self`.
+       fun blink: TermCharFormat do return apply("5")
+
+       # Apply reverse video and return `self`.
+       fun inverse: TermCharFormat do return apply("7")
+
+       # Apply normal weight and return `self`.
+       fun normal_weight: TermCharFormat do return apply("22")
+
+       # Add the attribute that disable inderlining and return `self`.
+       fun not_underlined: TermCharFormat do return apply("24")
+
+       # Add the attribute that disable blinking and return `self`.
+       fun steady: TermCharFormat do return apply("25")
+
+       # Add the attribute that disable reverse video and return `self`.
+       fun positive: TermCharFormat do return apply("27")
+
+       # Apply a black foreground and return `self`.
+       fun black_fg: TermCharFormat do return apply("30")
+
+       # Apply a red foreground and return `self`.
+       fun red_fg: TermCharFormat do return apply("31")
+
+       # Apply a green foreground and return `self`.
+       fun green_fg: TermCharFormat do return apply("32")
+
+       # Apply a yellow foreground and return `self`.
+       fun yellow_fg: TermCharFormat do return apply("33")
+
+       # Apply a blue foreground and return `self`.
+       fun blue_fg: TermCharFormat do return apply("34")
+
+       # Apply a mangenta foreground and return `self`.
+       fun magenta_fg: TermCharFormat do return apply("35")
+
+       # Apply a cyan foreground and return `self`.
+       fun cyan_fg: TermCharFormat do return apply("36")
+
+       # Apply a white foreground and return `self`.
+       fun white_fg: TermCharFormat do return apply("37")
+
+       # Apply the default foreground and return `self`.
+       fun default_fg: TermCharFormat do return apply("39")
+
+       # Apply a black backgroud and return `self`.
+       fun black_bg: TermCharFormat do return apply("40")
+
+       # Apply a red backgroud and return `self`.
+       fun red_bg: TermCharFormat do return apply("41")
+
+       # Apply a green backgroud and return `self`.
+       fun green_bg: TermCharFormat do return apply("42")
+
+       # Apply a yellow backgroud and return `self`.
+       fun yellow_bg: TermCharFormat do return apply("43")
+
+       # Apply a blue backgroud and return `self`.
+       fun blue_bg: TermCharFormat do return apply("44")
+
+       # Apply a mangenta backgroud and return `self`.
+       fun magenta_bg: TermCharFormat do return apply("45")
+
+       # Apply a cyan backgroud and return `self`.
+       fun cyan_bg: TermCharFormat do return apply("46")
+
+       # Apply a white backgroud and return `self`.
+       fun white_bg: TermCharFormat do return apply("47")
+
+       # Apply the default backgroud and return `self`.
+       fun default_bg: TermCharFormat do return apply("49")
 end
 
+# Redefine the `String` class to add functions to color the string.
+redef class String
+       private fun apply_format(f: TermCharFormat): String do
+               return "{f}{self}{normal}"
+       end
+
+       private fun normal: TermCharFormat do return new TermCharFormat
+
+       # Make the text appear in dark gray (or black) in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun gray: String do return apply_format(normal.black_fg)
+
+       # Make the text appear in red in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun red: String do return apply_format(normal.red_fg)
+
+       # Make the text appear in green in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun green: String do return apply_format(normal.green_fg)
+
+       # Make the text appear in yellow in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun yellow: String do return apply_format(normal.yellow_fg)
+
+       # Make the text appear in blue in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun blue: String do return apply_format(normal.blue_fg)
+
+       # Make the text appear in mangenta in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun purple: String do return apply_format(normal.magenta_fg)
+
+       # Make the text appear in cyan in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun cyan: String do return apply_format(normal.cyan_fg)
+
+       # Make the text appear in light gray (or white) in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun light_gray: String do return apply_format(normal.white_fg)
+
+       # Make the text appear in bold in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun bold: String do return apply_format(normal.bold)
+
+       # Make the text underlined in a ANSI/VT100 terminal.
+       #
+       # WARNING: SEE: `TermCharFormat`
+       fun underline: String do return apply_format(normal.underline)
+end
index c590a85..4ed9664 100644 (file)
@@ -76,12 +76,12 @@ redef class App
        redef fun setup
        do
                var env = "MNIT_SRAND".environ
-               if env != null and env != "" then
+               if env != "" then
                        srand_from(env.to_i)
                end
 
                var input = "MNIT_READ_INPUT".environ
-               if input != null and input != "" then
+               if input != "" then
                        injected_input_stream = new IFStream.open(input)
                        print "GET injected_input_stream {input}"
                end
index c52a4a5..47e6823 100644 (file)
@@ -149,10 +149,6 @@ class HttpRequestParser
                                var parts = line.split_once_on('=')
                                if parts.length > 1 then
                                        var decoded = parts[1].replace('+', " ").from_percent_encoding
-                                       if decoded == null then
-                                               print "decode error"
-                                               continue
-                                       end
                                        http_request.post_args[parts[0]] = decoded
                                        http_request.all_args[parts[0]] = decoded
                                else
index a1bffc1..c088325 100644 (file)
@@ -194,11 +194,7 @@ class OptionEnum
 
        redef fun pretty_default
        do
-               if default_value != null then
-                       return " ({values[default_value]})"
-               else
-                       return ""
-               end
+               return " ({values[default_value]})"
        end
 end
 
index fd2e22e..630c1c0 100644 (file)
@@ -289,7 +289,6 @@ redef class ACallExpr
                if args != null then
                        self.n_args.n_exprs.add_all(args)
                end
-               var mtype = recv.mtype.as(not null)
                self.callsite = callsite
                self.mtype = callsite.msignature.return_mtype
                self.is_typed = true
index 2897ed9..f111e0d 100644 (file)
@@ -22,45 +22,46 @@ import semantize
 import platform
 import c_tools
 private import annotation
+import mixin
 
 # Add compiling options
 redef class ToolContext
        # --output
-       var opt_output: OptionString = new OptionString("Output file", "-o", "--output")
+       var opt_output = new OptionString("Output file", "-o", "--output")
        # --dir
-       var opt_dir: OptionString = new OptionString("Output directory", "--dir")
+       var opt_dir = new OptionString("Output directory", "--dir")
        # --no-cc
-       var opt_no_cc: OptionBool = new OptionBool("Do not invoke C compiler", "--no-cc")
+       var opt_no_cc = new OptionBool("Do not invoke C compiler", "--no-cc")
        # --no-main
-       var opt_no_main: OptionBool = new OptionBool("Do not generate main entry point", "--no-main")
+       var opt_no_main = new OptionBool("Do not generate main entry point", "--no-main")
        # --cc-paths
-       var opt_cc_path: OptionArray = new OptionArray("Set include path for C header files (may be used more than once)", "--cc-path")
+       var opt_cc_path = new OptionArray("Set include path for C header files (may be used more than once)", "--cc-path")
        # --make-flags
-       var opt_make_flags: OptionString = new OptionString("Additional options to make", "--make-flags")
+       var opt_make_flags = new OptionString("Additional options to make", "--make-flags")
        # --compile-dir
-       var opt_compile_dir: OptionString = new OptionString("Directory used to generate temporary files", "--compile-dir")
+       var opt_compile_dir = new OptionString("Directory used to generate temporary files", "--compile-dir")
        # --hardening
-       var opt_hardening: OptionBool = new OptionBool("Generate contracts in the C code against bugs in the compiler", "--hardening")
+       var opt_hardening = new OptionBool("Generate contracts in the C code against bugs in the compiler", "--hardening")
        # --no-check-covariance
-       var opt_no_check_covariance: OptionBool = new OptionBool("Disable type tests of covariant parameters (dangerous)", "--no-check-covariance")
+       var opt_no_check_covariance = new OptionBool("Disable type tests of covariant parameters (dangerous)", "--no-check-covariance")
        # --no-check-attr-isset
-       var opt_no_check_attr_isset: OptionBool = new OptionBool("Disable isset tests before each attribute access (dangerous)", "--no-check-attr-isset")
+       var opt_no_check_attr_isset = new OptionBool("Disable isset tests before each attribute access (dangerous)", "--no-check-attr-isset")
        # --no-check-assert
-       var opt_no_check_assert: OptionBool = new OptionBool("Disable the evaluation of explicit 'assert' and 'as' (dangerous)", "--no-check-assert")
+       var opt_no_check_assert = new OptionBool("Disable the evaluation of explicit 'assert' and 'as' (dangerous)", "--no-check-assert")
        # --no-check-autocast
-       var opt_no_check_autocast: OptionBool = new OptionBool("Disable implicit casts on unsafe expression usage (dangerous)", "--no-check-autocast")
+       var opt_no_check_autocast = new OptionBool("Disable implicit casts on unsafe expression usage (dangerous)", "--no-check-autocast")
        # --no-check-null
-       var opt_no_check_null: OptionBool = new OptionBool("Disable tests of null receiver (dangerous)", "--no-check-null")
+       var opt_no_check_null = new OptionBool("Disable tests of null receiver (dangerous)", "--no-check-null")
        # --no-check-all
-       var opt_no_check_all: OptionBool = new OptionBool("Disable all tests (dangerous)", "--no-check-all")
+       var opt_no_check_all = new OptionBool("Disable all tests (dangerous)", "--no-check-all")
        # --typing-test-metrics
-       var opt_typing_test_metrics: OptionBool = new OptionBool("Enable static and dynamic count of all type tests", "--typing-test-metrics")
+       var opt_typing_test_metrics = new OptionBool("Enable static and dynamic count of all type tests", "--typing-test-metrics")
        # --invocation-metrics
-       var opt_invocation_metrics: OptionBool = new OptionBool("Enable static and dynamic count of all method invocations", "--invocation-metrics")
+       var opt_invocation_metrics = new OptionBool("Enable static and dynamic count of all method invocations", "--invocation-metrics")
        # --isset-checks-metrics
-       var opt_isset_checks_metrics: OptionBool = new OptionBool("Enable static and dynamic count of isset checks before attributes access", "--isset-checks-metrics")
+       var opt_isset_checks_metrics = new OptionBool("Enable static and dynamic count of isset checks before attributes access", "--isset-checks-metrics")
        # --stacktrace
-       var opt_stacktrace: OptionString = new OptionString("Control the generation of stack traces", "--stacktrace")
+       var opt_stacktrace = new OptionString("Control the generation of stack traces", "--stacktrace")
        # --no-gcc-directives
        var opt_no_gcc_directive = new OptionArray("Disable a advanced gcc directives for optimization", "--no-gcc-directive")
        # --release
@@ -179,7 +180,6 @@ class MakefileToolchain
        do
                gather_cc_paths
 
-               var mainmodule = compiler.mainmodule
                var compile_dir = compile_dir
 
                # Generate the .h and .c files
@@ -227,7 +227,6 @@ class MakefileToolchain
                compiler.files_to_copy.add "{cc_paths.first}/gc_chooser.h"
 
                # FFI
-               var m2m = toolcontext.modelbuilder.mmodule2nmodule
                for m in compiler.mainmodule.in_importation.greaters do
                        compiler.finalize_ffi_for_module(m)
                end
@@ -308,7 +307,16 @@ class MakefileToolchain
 
        fun makefile_name(mainmodule: MModule): String do return "{mainmodule.name}.mk"
 
-       fun default_outname(mainmodule: MModule): String do return mainmodule.name
+       fun default_outname(mainmodule: MModule): String
+       do
+               # Search a non fictive module
+               var res = mainmodule.name
+               while mainmodule.is_fictive do
+                       mainmodule = mainmodule.in_importation.direct_greaters.first
+                       res = mainmodule.name
+               end
+               return res
+       end
 
        # Combine options and platform informations to get the final path of the outfile
        fun outfile(mainmodule: MModule): String
@@ -340,7 +348,6 @@ class MakefileToolchain
                end
 
                var linker_options = new HashSet[String]
-               var m2m = toolcontext.modelbuilder.mmodule2nmodule
                for m in mainmodule.in_importation.greaters do
                        var libs = m.collect_linker_libs
                        if libs != null then linker_options.add_all(libs)
@@ -448,7 +455,7 @@ abstract class AbstractCompiler
        # The real main module of the program
        var realmainmodule: MModule
 
-       # The modeulbuilder used to know the model and the AST
+       # The modelbuilder used to know the model and the AST
        var modelbuilder: ModelBuilder is protected writable
 
        # Is hardening asked? (see --hardening)
@@ -472,7 +479,7 @@ abstract class AbstractCompiler
 
        # The list of all associated files
        # Used to generate .c files
-       var files: List[CodeFile] = new List[CodeFile]
+       var files = new List[CodeFile]
 
        # Initialize a visitor specific for a compiler engine
        fun new_visitor: VISITOR is abstract
@@ -539,8 +546,6 @@ abstract class AbstractCompiler
        # Compile C headers
        # This method call compile_header_strucs method that has to be refined
        fun compile_header do
-               var v = self.header
-               var toolctx = modelbuilder.toolcontext
                self.header.add_decl("#include <stdlib.h>")
                self.header.add_decl("#include <stdio.h>")
                self.header.add_decl("#include <string.h>")
@@ -889,6 +894,7 @@ extern void nitni_global_ref_decr( struct nitni_ref *ref ) {
                var cds = mtype.collect_mclassdefs(self.mainmodule).to_a
                self.mainmodule.linearize_mclassdefs(cds)
                for cd in cds do
+                       if not self.modelbuilder.mclassdef2nclassdef.has_key(cd) then continue
                        var n = self.modelbuilder.mclassdef2nclassdef[cd]
                        for npropdef in n.n_propdefs do
                                if npropdef isa AAttrPropdef then
@@ -904,6 +910,7 @@ extern void nitni_global_ref_decr( struct nitni_ref *ref ) {
                var cds = mtype.collect_mclassdefs(self.mainmodule).to_a
                self.mainmodule.linearize_mclassdefs(cds)
                for cd in cds do
+                       if not self.modelbuilder.mclassdef2nclassdef.has_key(cd) then continue
                        var n = self.modelbuilder.mclassdef2nclassdef[cd]
                        for npropdef in n.n_propdefs do
                                if npropdef isa AAttrPropdef then
@@ -1042,7 +1049,7 @@ abstract class AbstractCompilerVisitor
        fun get_property(name: String, recv: MType): MMethod
        do
                assert recv isa MClassType
-               return self.compiler.modelbuilder.force_get_primitive_method(self.current_node.as(not null), name, recv.mclass, self.compiler.mainmodule)
+               return self.compiler.modelbuilder.force_get_primitive_method(self.current_node, name, recv.mclass, self.compiler.mainmodule)
        end
 
        fun compile_callsite(callsite: CallSite, arguments: Array[RuntimeVariable]): nullable RuntimeVariable
@@ -1215,7 +1222,7 @@ abstract class AbstractCompilerVisitor
 
        # Checks
 
-       # Add a check and an abort for a null reciever if needed
+       # Add a check and an abort for a null receiver if needed
        fun check_recv_notnull(recv: RuntimeVariable)
        do
                if self.compiler.modelbuilder.toolcontext.opt_no_check_null.value then return
@@ -1230,7 +1237,7 @@ abstract class AbstractCompilerVisitor
 
        # Names handling
 
-       private var names: HashSet[String] = new HashSet[String]
+       private var names = new HashSet[String]
        private var last: Int = 0
 
        # Return a new name based on `s` and unique in the visitor
@@ -1280,7 +1287,7 @@ abstract class AbstractCompilerVisitor
 
        # Variables handling
 
-       protected var variables: HashMap[Variable, RuntimeVariable] = new HashMap[Variable, RuntimeVariable]
+       protected var variables = new HashMap[Variable, RuntimeVariable]
 
        # Return the local runtime_variable associated to a Nit local variable
        fun variable(variable: Variable): RuntimeVariable
@@ -1359,6 +1366,18 @@ abstract class AbstractCompilerVisitor
                return res
        end
 
+       # Generate an integer value
+       fun bool_instance(value: Bool): RuntimeVariable
+       do
+               var res = self.new_var(self.get_class("Bool").mclass_type)
+               if value then
+                       self.add("{res} = 1;")
+               else
+                       self.add("{res} = 0;")
+               end
+               return res
+       end
+
        # Generate a string value
        fun string_instance(string: String): RuntimeVariable
        do
@@ -1379,6 +1398,19 @@ abstract class AbstractCompilerVisitor
                return res
        end
 
+       fun value_instance(object: Object): RuntimeVariable
+       do
+               if object isa Int then
+                       return int_instance(object)
+               else if object isa Bool then
+                       return bool_instance(object)
+               else if object isa String then
+                       return string_instance(object)
+               else
+                       abort
+               end
+       end
+
        # Generate an array value
        fun array_instance(array: Array[RuntimeVariable], elttype: MType): RuntimeVariable is abstract
 
@@ -1819,6 +1851,7 @@ redef class MMethodDef
        fun compile_inside_to_c(v: VISITOR, arguments: Array[RuntimeVariable]): nullable RuntimeVariable
        do
                var modelbuilder = v.compiler.modelbuilder
+               var val = constant_value
                if modelbuilder.mpropdef2npropdef.has_key(self) then
                        var npropdef = modelbuilder.mpropdef2npropdef[self]
                        var oldnode = v.current_node
@@ -1833,6 +1866,8 @@ redef class MMethodDef
                        self.compile_parameter_check(v, arguments)
                        nclassdef.compile_to_c(v, self, arguments)
                        v.current_node = oldnode
+               else if val != null then
+                       v.ret(v.value_instance(val))
                else
                        abort
                end
@@ -2714,7 +2749,7 @@ redef class ACrangeExpr
                var i2 = v.expr(self.n_expr2, null)
                var mtype = self.mtype.as(MClassType)
                var res = v.init_instance(mtype)
-               var it = v.compile_callsite(init_callsite.as(not null), [res, i1, i2])
+               v.compile_callsite(init_callsite.as(not null), [res, i1, i2])
                return res
        end
 end
@@ -2726,7 +2761,7 @@ redef class AOrangeExpr
                var i2 = v.expr(self.n_expr2, null)
                var mtype = self.mtype.as(MClassType)
                var res = v.init_instance(mtype)
-               var it = v.compile_callsite(init_callsite.as(not null), [res, i1, i2])
+               v.compile_callsite(init_callsite.as(not null), [res, i1, i2])
                return res
        end
 end
@@ -2992,9 +3027,6 @@ end
 # Create a tool context to handle options and paths
 var toolcontext = new ToolContext
 
-var opt_mixins = new OptionArray("Additionals module to min-in", "-m")
-toolcontext.option_context.add_option(opt_mixins)
-
 toolcontext.tooldescription = "Usage: nitg [OPTION]... file.nit...\nCompiles Nit programs."
 
 # We do not add other options, so process them now!
@@ -3013,7 +3045,6 @@ end
 
 # Here we load an process all modules passed on the command line
 var mmodules = modelbuilder.parse(arguments)
-var mixins = modelbuilder.parse(opt_mixins.value)
 
 if mmodules.is_empty then return
 modelbuilder.run_phases
@@ -3021,8 +3052,5 @@ modelbuilder.run_phases
 for mmodule in mmodules do
        toolcontext.info("*** PROCESS {mmodule} ***", 1)
        var ms = [mmodule]
-       if not mixins.is_empty then
-               ms.add_all mixins
-       end
        toolcontext.run_global_phases(ms)
 end
index a6fc4e2..cc24d6e 100644 (file)
@@ -125,11 +125,9 @@ redef class AAnnotation
        # revision number. If the working tree is dirty, it will append another field with "d" for dirty.
        private fun as_version(modelbuilder: ModelBuilder): String
        do
-               var annotation_name = n_atid.n_id.text
                var version_fields = new Array[Object]
 
                var args = n_args
-               var platform_name
                if args.length < 1 then
                        modelbuilder.error(self, "Annotation error: \"{name}\" expects at least a single argument.")
                        return ""
index ed9b466..e447080 100644 (file)
@@ -279,8 +279,6 @@ class BucketsColorer[H: Object, E: Object]
        private var colors = new HashMap[E, Int]
        private var conflicts = new HashMap[E, Set[E]]
 
-       init do end
-
        # Start bucket coloring
        fun colorize(buckets: Map[H, Set[E]]): Map[E, Int] do
                compute_conflicts(buckets)
index 37689d8..e9c740a 100644 (file)
@@ -82,7 +82,7 @@ extern void nitni_global_ref_decr(void*);
                return res
        end
 
-       private var compiled_callbacks: Array[NitniCallback] = new Array[NitniCallback]
+       private var compiled_callbacks = new Array[NitniCallback]
 
        # Returns true if callbacks has yet to be generated and register it as being generated
        private fun check_callback_compilation(cb: NitniCallback): Bool
@@ -98,7 +98,6 @@ redef class AMethPropdef
        do
                var mmodule = mpropdef.mclassdef.mmodule
                var mainmodule = v.compiler.mainmodule
-               var amainmodule = v.compiler.modelbuilder.mmodule2nmodule[mainmodule]
                var amodule = v.compiler.modelbuilder.mmodule2nmodule[mmodule]
                var mclass_type = mpropdef.mclassdef.bound_mtype
 
@@ -428,7 +427,6 @@ redef class MExplicitSuper
                var mproperty = from.mproperty
                assert mproperty isa MMethod
                var mclass_type = from.mclassdef.mclass.mclass_type
-               var mmodule = from.mclassdef.mmodule
 
                # In nitni files, declare internal function as extern
                var internal_csignature = mproperty.build_csignature(mclass_type, v.compiler.mainmodule, "___super", long_signature, internal_call_context)
index 2196071..b8eef9b 100644 (file)
@@ -342,7 +342,7 @@ class GlobalCompilerVisitor
 
                var valtype = value.mtype.as(MClassType)
                var res = self.new_var(mtype)
-               if compiler.runtime_type_analysis != null and not compiler.runtime_type_analysis.live_types.has(value.mtype.as(MClassType)) then
+               if not compiler.runtime_type_analysis.live_types.has(value.mtype.as(MClassType)) then
                        self.add("/*no boxing of {value.mtype}: {value.mtype} is not live! */")
                        self.add("PRINT_ERROR(\"Dead code executed!\\n\"); show_backtrace(1);")
                        return res
index 8c400f9..7eed804 100644 (file)
@@ -22,19 +22,19 @@ import rapid_type_analysis
 # Add separate compiler specific options
 redef class ToolContext
        # --separate
-       var opt_separate: OptionBool = new OptionBool("Use separate compilation", "--separate")
+       var opt_separate = new OptionBool("Use separate compilation", "--separate")
        # --no-inline-intern
-       var opt_no_inline_intern: OptionBool = new OptionBool("Do not inline call to intern methods", "--no-inline-intern")
+       var opt_no_inline_intern = new OptionBool("Do not inline call to intern methods", "--no-inline-intern")
        # --no-union-attribute
-       var opt_no_union_attribute: OptionBool = new OptionBool("Put primitive attibutes in a box instead of an union", "--no-union-attribute")
+       var opt_no_union_attribute = new OptionBool("Put primitive attibutes in a box instead of an union", "--no-union-attribute")
        # --no-shortcut-equate
-       var opt_no_shortcut_equate: OptionBool = new OptionBool("Always call == in a polymorphic way", "--no-shortcut-equal")
+       var opt_no_shortcut_equate = new OptionBool("Always call == in a polymorphic way", "--no-shortcut-equal")
        # --inline-coloring-numbers
-       var opt_inline_coloring_numbers: OptionBool = new OptionBool("Inline colors and ids (semi-global)", "--inline-coloring-numbers")
+       var opt_inline_coloring_numbers = new OptionBool("Inline colors and ids (semi-global)", "--inline-coloring-numbers")
        # --inline-some-methods
-       var opt_inline_some_methods: OptionBool = new OptionBool("Allow the separate compiler to inline some methods (semi-global)", "--inline-some-methods")
+       var opt_inline_some_methods = new OptionBool("Allow the separate compiler to inline some methods (semi-global)", "--inline-some-methods")
        # --direct-call-monomorph
-       var opt_direct_call_monomorph: OptionBool = new OptionBool("Allow the separate compiler to direct call monomorph sites (semi-global)", "--direct-call-monomorph")
+       var opt_direct_call_monomorph = new OptionBool("Allow the separate compiler to direct call monomorph sites (semi-global)", "--direct-call-monomorph")
        # --skip-dead-methods
        var opt_skip_dead_methods = new OptionBool("Do not compile dead methods (semi-global)", "--skip-dead-methods")
        # --semi-global
@@ -42,7 +42,7 @@ redef class ToolContext
        # --no-colo-dead-methods
        var opt_colo_dead_methods = new OptionBool("Force colorization of dead methods", "--colo-dead-methods")
        # --tables-metrics
-       var opt_tables_metrics: OptionBool = new OptionBool("Enable static size measuring of tables used for vft, typing and resolution", "--tables-metrics")
+       var opt_tables_metrics = new OptionBool("Enable static size measuring of tables used for vft, typing and resolution", "--tables-metrics")
 
        redef init
        do
@@ -963,7 +963,6 @@ class SeparateCompilerVisitor
        redef fun unbox_signature_extern(m, args)
        do
                var msignature = m.msignature.resolve_for(m.mclassdef.bound_mtype, m.mclassdef.bound_mtype, m.mclassdef.mmodule, true)
-               var recv = args.first
                if not m.mproperty.is_init and m.is_extern then
                        args.first = self.unbox_extern(args.first, m.mclassdef.mclass.mclass_type)
                end
@@ -1063,7 +1062,6 @@ class SeparateCompilerVisitor
        redef fun compile_callsite(callsite, args)
        do
                var rta = compiler.runtime_type_analysis
-               var recv = args.first.mtype
                var mmethod = callsite.mproperty
                # TODO: Inlining of new-style constructors
                if compiler.modelbuilder.toolcontext.opt_direct_call_monomorph.value and rta != null and not mmethod.is_root_init then
index af3a43c..c23476d 100644 (file)
@@ -20,11 +20,11 @@ intrude import separate_compiler
 # Add separate erased compiler specific options
 redef class ToolContext
        # --erasure
-       var opt_erasure: OptionBool = new OptionBool("Erase generic types", "--erasure")
+       var opt_erasure = new OptionBool("Erase generic types", "--erasure")
        # --rta
        var opt_rta = new OptionBool("Activate RTA (implicit with --global and --separate)", "--rta")
        # --no-check-erasure-cast
-       var opt_no_check_erasure_cast: OptionBool = new OptionBool("Disable implicit casts on unsafe return with erasure-typing policy (dangerous)", "--no-check-erasure-cast")
+       var opt_no_check_erasure_cast = new OptionBool("Disable implicit casts on unsafe return with erasure-typing policy (dangerous)", "--no-check-erasure-cast")
 
        redef init
        do
@@ -549,7 +549,6 @@ class SeparateErasureCompilerVisitor
                end
 
                var class_ptr
-               var type_table
                if value.mtype.ctype == "val*" then
                        class_ptr = "{value}->class->"
                else
index f13d69f..41386d2 100644 (file)
@@ -190,12 +190,8 @@ redef class MGroup
 
        redef fun tpl_namespace do
                var tpl = new Template
-               if mproject != null then
-                       tpl.add mproject.tpl_namespace
-               else if parent != null then
-                       tpl.add parent.tpl_namespace
-               end
-               if mproject != null and mproject.root != self then
+               tpl.add mproject.tpl_namespace
+               if mproject.root != self then
                        tpl.add "::"
                        tpl.add tpl_link
                end
index 7be54ce..49a880b 100644 (file)
@@ -96,7 +96,6 @@ class JavaLanguage
 
                var jni_signature_alt
                var return_type
-               var c_return_type
                var params = new Array[String]
                params.add "nit_ffi_jni_env"
                params.add "java_class"
@@ -105,19 +104,16 @@ class JavaLanguage
                if mproperty.is_init then
                        jni_signature_alt = mclass_type.jni_signature_alt
                        return_type = mclass_type
-                       c_return_type = mclass_type.cname
                else
                        params.add "recv"
                        if signature.return_mtype != null then
                                var ret_mtype = signature.return_mtype
                                ret_mtype = ret_mtype.resolve_for(mclass_type, mclass_type, mmodule, true)
                                return_type = signature.return_mtype
-                               c_return_type = mclass_type.cname
                                jni_signature_alt = return_type.jni_signature_alt
                        else
                                jni_signature_alt = "Void"
                                return_type = null
-                               c_return_type = null
                        end
                end
 
@@ -262,16 +258,15 @@ redef class AMethPropdef
                end
        end
 
-       # Insert additionnal explicit calls to get the current `JNIEnv`
+       # Insert additional explicit calls to get the current `JNIEnv`
        #
        # This forces declaration of callbacks to Nit. The callbacks will be available in Java
        # but will be used mainly by the FFI itself.
        #
-       # The developper can aso customize the JNIEnv used by the FFI by redefing `Sys::jni_env`.
+       # The developer can also customize the JNIEnv used by the FFI by redefining `Sys::jni_env`.
        private fun insert_artificial_callbacks(toolcontext: ToolContext)
        do
                var fcc = foreign_callbacks
-               assert fcc != null
 
                var modelbuilder = toolcontext.modelbuilder
                var mmodule = mpropdef.mclassdef.mmodule
@@ -450,7 +445,7 @@ redef class MType
        # Type name in Java
        #
        # * Primitives common to both languages use their Java primitive type
-       # * Nit extern Java classes are reprensented by their full Java type
+       # * Nit extern Java classes are represented by their full Java type
        # * Other Nit objects are represented by `int` in Java. It holds the
        #       pointer to the underlying C structure.
        #       TODO create static Java types to store and hide the pointer
@@ -502,7 +497,6 @@ redef class MClassType
        do
                var ftype = mclass.ftype
                if ftype isa ForeignJavaType then
-                       var ori_jni_type = jni_type
                        var jni_type = ftype.java_type.
                                replace('.', "/").replace(' ', "").replace('\n', "")
 
index 06075b4..fe5375c 100644 (file)
@@ -52,7 +52,6 @@ class HighlightVisitor
        do
                var stack2 = new Array[HTMLTag]
                var stack = new Array[Prod]
-               var closes = new Array[Prod]
                var line = 0
                var c: nullable Token = first_token
                var hv = new HighlightVisitor
@@ -932,4 +931,3 @@ redef class AExpr
                return t.infobox(v)
        end
 end
-
index 586c04c..b242141 100644 (file)
@@ -120,9 +120,9 @@ redef class ToolContext
        end
 
        # -d
-       var opt_debugger_mode: OptionBool = new OptionBool("Launches the target program with the debugger attached to it", "-d")
+       var opt_debugger_mode = new OptionBool("Launches the target program with the debugger attached to it", "-d")
        # -c
-       var opt_debugger_autorun: OptionBool = new OptionBool("Launches the target program with the interpreter, such as when the program fails, the debugging prompt is summoned", "-c")
+       var opt_debugger_autorun = new OptionBool("Launches the target program with the interpreter, such as when the program fails, the debugging prompt is summoned", "-c")
 
        redef init
        do
@@ -324,7 +324,6 @@ class Debugger
                        var mmod = e.mmodule
                        if mmod != null then
                                self.mainmodule = mmod
-                               var local_classdefs = mmod.mclassdefs
                                var sys_type = mmod.sys_type
                                if sys_type == null then
                                        print "Fatal error, cannot find Class Sys !\nAborting"
@@ -399,7 +398,6 @@ class Debugger
                var identifiers_in_instruction = get_identifiers_in_current_instruction(n.location.text)
 
                for i in identifiers_in_instruction do
-                       var variable = seek_variable(i, frame)
                        for j in self.traces do
                                if j.is_variable_traced_in_frame(i, frame) then
                                        n.debug("Traced variable {i} used")
@@ -588,8 +586,6 @@ class Debugger
                if parts_of_command[1] == "*" then
                        var map_of_instances = frame.map
 
-                       var keys = map_of_instances.iterator
-
                        var self_var = seek_variable("self", frame)
                        print "self: {self_var.to_s}"
 
@@ -832,14 +828,12 @@ class Debugger
 
                var trigger_char_escape = false
                var trigger_string_escape = false
-               var trigger_concat_in_string = false
 
                for i in instruction.chars do
                        if trigger_char_escape then
                                if i == '\'' then trigger_char_escape = false
                        else if trigger_string_escape then
                                if i == '{' then
-                                       trigger_concat_in_string = true
                                        trigger_string_escape = false
                                else if i == '\"' then trigger_string_escape = false
                        else
@@ -857,7 +851,6 @@ class Debugger
                                else if i == '\"' then
                                        trigger_string_escape = true
                                else if i == '}' then
-                                       trigger_concat_in_string = false
                                        trigger_string_escape = true
                                else
                                        if instruction_buffer.length > 0 and not instruction_buffer.is_numeric and not (instruction_buffer.chars[0] >= 'A' and instruction_buffer.chars[0] <= 'Z') then result_array.push(instruction_buffer.to_s)
@@ -1084,8 +1077,6 @@ class Debugger
        do
                var collection_length_attribute = get_attribute_in_mutable_instance(collection, "length")
 
-               var real_collection_length: nullable Int = null
-
                if collection_length_attribute != null then
                        var primitive_length_instance = collection.attributes[collection_length_attribute]
                        if primitive_length_instance isa PrimitiveInstance[Int] then
index f557227..a04ec83 100644 (file)
@@ -20,10 +20,11 @@ module naive_interpreter
 import literal
 import semantize
 private import parser::tables
+import mixin
 
 redef class ToolContext
        # --discover-call-trace
-       var opt_discover_call_trace: OptionBool = new OptionBool("Trace calls of the first invocation of a method", "--discover-call-trace")
+       var opt_discover_call_trace = new OptionBool("Trace calls of the first invocation of a method", "--discover-call-trace")
 
        redef init
        do
@@ -57,7 +58,7 @@ class NaiveInterpreter
        # The modelbuilder that know the AST and its associations with the model
        var modelbuilder: ModelBuilder
 
-       # The main moduleof the program (used to lookup methoda
+       # The main module of the program (used to lookup method)
        var mainmodule: MModule
 
        # The command line arguments of the interpreted program
@@ -65,6 +66,7 @@ class NaiveInterpreter
        # arguments[1] is the first argument
        var arguments: Array[String]
 
+       # The main Sys instance
        var mainobj: nullable Instance
 
        init(modelbuilder: ModelBuilder, mainmodule: MModule, arguments: Array[String])
@@ -208,13 +210,13 @@ class NaiveInterpreter
                return new PrimitiveInstance[Float](ic.mclass_type, val)
        end
 
-       # The unique intance of the `true` value.
+       # The unique instance of the `true` value.
        var true_instance: Instance
 
-       # The unique intance of the `false` value.
+       # The unique instance of the `false` value.
        var false_instance: Instance
 
-       # The unique intance of the `null` value.
+       # The unique instance of the `null` value.
        var null_instance: Instance
 
        # Return a new array made of `values`.
@@ -230,6 +232,19 @@ class NaiveInterpreter
                return res
        end
 
+       fun value_instance(object: Object): Instance
+       do
+               if object isa Int then
+                       return int_instance(object)
+               else if object isa Bool then
+                       return bool_instance(object)
+               else if object isa String then
+                       return string_instance(object)
+               else
+                       abort
+               end
+       end
+
        # Return a new native string initialized with `txt`
        fun native_string_instance(txt: String): Instance
        do
@@ -239,13 +254,22 @@ class NaiveInterpreter
                return new PrimitiveInstance[Buffer](ic.mclass_type, val)
        end
 
+       # Return a new String instance for `txt`
+       fun string_instance(txt: String): Instance
+       do
+               var nat = native_string_instance(txt)
+               var res = self.send(self.force_get_primitive_method("to_s_with_length", nat.mtype), [nat, self.int_instance(txt.length)])
+               assert res != null
+               return res
+       end
+
        # The current frame used to store local variables of the current method executed
        fun frame: Frame do return frames.first
 
        # The stack of all frames. The first one is the current one.
-       var frames: List[Frame] = new List[Frame]
+       var frames = new List[Frame]
 
-       # Return a stack stace. One line per function
+       # Return a stack trace. One line per function
        fun stack_trace: String
        do
                var b = new FlatBuffer
@@ -292,7 +316,7 @@ class NaiveInterpreter
                f.map[v] = value
        end
 
-       # Store known method, used to trace methods as thez are reached
+       # Store known methods, used to trace methods as they are reached
        var discover_call_trace: Set[MMethodDef] = new HashSet[MMethodDef]
 
        # Common code for calls to injected methods and normal methods
@@ -327,8 +351,8 @@ class NaiveInterpreter
        end
 
        # Execute `mpropdef` for a `args` (where `args[0]` is the receiver).
-       # Return a falue if `mpropdef` is a function, or null if it is a procedure.
-       # The call is direct/static. There is no message-seding/late-binding.
+       # Return a value if `mpropdef` is a function, or null if it is a procedure.
+       # The call is direct/static. There is no message-sending/late-binding.
        fun call(mpropdef: MMethodDef, args: Array[Instance]): nullable Instance
        do
                args = call_commons(mpropdef, args)
@@ -349,6 +373,7 @@ class NaiveInterpreter
 
                # Look for the AST node that implements the property
                var mproperty = mpropdef.mproperty
+               var val = mpropdef.constant_value
                if self.modelbuilder.mpropdef2npropdef.has_key(mpropdef) then
                        var npropdef = self.modelbuilder.mpropdef2npropdef[mpropdef]
                        self.parameter_check(npropdef, mpropdef, args)
@@ -357,6 +382,8 @@ class NaiveInterpreter
                        var nclassdef = self.modelbuilder.mclassdef2nclassdef[mpropdef.mclassdef]
                        self.parameter_check(nclassdef, mpropdef, args)
                        return nclassdef.call(self, mpropdef, args)
+               else if val != null then
+                       return value_instance(val)
                else
                        fatal("Fatal Error: method {mpropdef} not found in the AST")
                        abort
@@ -401,7 +428,7 @@ class NaiveInterpreter
        end
 
        # Execute a full `callsite` for given `args`
-       # Use this method, instead of `send` to execute and control the aditionnal behavior of the call-sites
+       # Use this method, instead of `send` to execute and control the additional behavior of the call-sites
        fun callsite(callsite: nullable CallSite, arguments: Array[Instance]): nullable Instance
        do
                var initializers = callsite.mpropdef.initializers
@@ -430,8 +457,8 @@ class NaiveInterpreter
        end
 
        # Execute `mproperty` for a `args` (where `args[0]` is the receiver).
-       # Return a falue if `mproperty` is a function, or null if it is a procedure.
-       # The call is polimotphic. There is a message-seding/late-bindng according to te receiver (args[0]).
+       # Return a value if `mproperty` is a function, or null if it is a procedure.
+       # The call is polymorphic. There is a message-sending/late-binding according to the receiver (args[0]).
        fun send(mproperty: MMethod, args: Array[Instance]): nullable Instance
        do
                var recv = args.first
@@ -478,6 +505,7 @@ class NaiveInterpreter
                var cds = mtype.collect_mclassdefs(self.mainmodule).to_a
                self.mainmodule.linearize_mclassdefs(cds)
                for cd in cds do
+                       if not self.modelbuilder.mclassdef2nclassdef.has_key(cd) then continue
                        var n = self.modelbuilder.mclassdef2nclassdef[cd]
                        for npropdef in n.n_propdefs do
                                if npropdef isa AAttrPropdef then
@@ -490,7 +518,7 @@ class NaiveInterpreter
                return res
        end
 
-       var collect_attr_propdef_cache = new HashMap[MType, Array[AAttrPropdef]]
+       private var collect_attr_propdef_cache = new HashMap[MType, Array[AAttrPropdef]]
 
        # Fill the initial values of the newly created instance `recv`.
        # `recv.mtype` is used to know what must be filled.
@@ -726,14 +754,14 @@ redef class AMethPropdef
                        var txt = recv.mtype.to_s
                        return v.native_string_instance(txt)
                else if pname == "==" then
-                       # == is correclt redefined for instances
+                       # == is correctly redefined for instances
                        return v.bool_instance(args[0] == args[1])
                else if pname == "!=" then
                        return v.bool_instance(args[0] != args[1])
                else if pname == "is_same_type" then
                        return v.bool_instance(args[0].mtype == args[1].mtype)
                else if pname == "is_same_instance" then
-                       return v.bool_instance(args[1] != null and args[0].eq_is(args[1]))
+                       return v.bool_instance(args[0].eq_is(args[1]))
                else if pname == "exit" then
                        exit(args[1].to_i)
                        abort
@@ -1434,9 +1462,7 @@ redef class AStringFormExpr
        redef fun expr(v)
        do
                var txt = self.value.as(not null)
-               var nat = v.native_string_instance(txt)
-               var res = v.send(v.force_get_primitive_method("to_s", nat.mtype), [nat]).as(not null)
-               return res
+               return v.string_instance(txt)
        end
 end
 
@@ -1536,7 +1562,6 @@ redef class AAsNotnullExpr
        do
                var i = v.expr(self.n_expr)
                if i == null then return null
-               var mtype = v.unanchor_type(self.mtype.as(not null))
                if i.mtype isa MNullType then
                        fatal(v, "Cast failed")
                end
@@ -1621,7 +1646,7 @@ redef class ASuperExpr
 
                var callsite = self.callsite
                if callsite != null then
-                       # Add additionnals arguments for the super init call
+                       # Add additional arguments for the super init call
                        if args.length == 1 then
                                for i in [0..callsite.msignature.arity[ do
                                        args.add(v.frame.arguments[i+1])
@@ -1636,7 +1661,7 @@ redef class ASuperExpr
                        args = v.frame.arguments
                end
 
-               # stantard call-next-method
+               # standard call-next-method
                var mpropdef = self.mpropdef
                mpropdef = mpropdef.lookup_next_definition(v.mainmodule, recv.mtype)
                var res = v.call_without_varargs(mpropdef, args)
index 664415a..eac5853 100644 (file)
@@ -35,8 +35,6 @@ end
 # Print class tables metrics for the classes of the program main
 fun compute_tables_metrics(main: MModule)
 do
-       var model = main.model
-
        var nc = 0 # Number of runtime classes
        var nl = 0 # Number of usages of class definitions (a class definition can be used more than once)
        var nhp = 0 # Number of usages of properties (a property can be used more than once)
diff --git a/src/mixin.nit b/src/mixin.nit
new file mode 100644 (file)
index 0000000..94d0c32
--- /dev/null
@@ -0,0 +1,110 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Loading and additional module refinements at link-time.
+#
+# Used to factorize some code used by the engines.
+module mixin
+
+import modelbuilder
+
+redef class ToolContext
+       # --mixin
+       var opt_mixins = new OptionArray("Additionals module to min-in", "-m", "--mixin")
+       # --define
+       var opt_defines = new OptionArray("Define a specific property", "-D", "--define")
+
+       redef init
+       do
+               super
+               option_context.add_option(opt_mixins, opt_defines)
+       end
+
+       redef fun make_main_module(mmodules)
+       do
+               var mixins = opt_mixins.value
+               if not mixins.is_empty then
+                       mmodules.add_all modelbuilder.parse(opt_mixins.value)
+                       modelbuilder.run_phases
+               end
+
+               var mainmodule = super
+
+               var defines = opt_defines.value
+               if not defines.is_empty then
+                       var location = mainmodule.location
+                       var model = mainmodule.model
+
+                       if mainmodule == mmodules.first then
+                               mainmodule = new MModule(model, null, mainmodule.name + "-d", location)
+                               mainmodule.set_imported_mmodules(mmodules)
+                               mainmodule.is_fictive = true
+                       end
+
+                       var recv = mainmodule.object_type
+                       var mclassdef = new MClassDef(mainmodule, recv, location)
+                       mclassdef.add_in_hierarchy
+
+                       for define in defines do
+                               var spl = define.split_once_on('=')
+                               var name = spl.first
+                               var val = null
+                               if spl.length > 1 then val = spl[1]
+                               var prop = mainmodule.try_get_primitive_method(name, recv.mclass)
+                               if prop == null then
+                                       error(null, "Error: --define: no top-level function `{name}`")
+                                       continue
+                               end
+                               var ret = prop.intro.msignature.return_mtype
+                               var v
+                               if ret == null then
+                                       error(null, "Error: --define: Method `{prop}` is not a function")
+                                       continue
+                               else if ret.to_s == "Bool" then
+                                       if val == null or val == "true" then
+                                               v = true
+                                       else if val == "false" then
+                                               v = false
+                                       else
+                                               error(null, "Error: --define: Method `{prop}` need a Bool.")
+                                               continue
+                                       end
+                               else if ret.to_s == "Int" then
+                                       if val != null and val.is_numeric then
+                                               v = val.to_i
+                                       else
+                                               error(null, "Error: --define: Method `{prop}` need a Int.")
+                                               continue
+                                       end
+                               else if ret.to_s == "String" then
+                                       if val != null then
+                                               v = val
+                                       else
+                                               error(null, "Error: --define: Method `{prop}` need a String.")
+                                               continue
+                                       end
+                               else
+                                       error(null, "Error: --define: Method `{prop}` return an unmanaged type {ret}.")
+                                       continue
+                               end
+                               var pd = new MMethodDef(mclassdef, prop, location)
+                               pd.msignature = prop.intro.msignature
+                               pd.constant_value = v
+                       end
+                       check_errors
+               end
+
+               return mainmodule
+       end
+end
index eab60f7..f26eb2e 100644 (file)
@@ -1977,6 +1977,16 @@ class MMethodDef
 
        # Is the method definition extern?
        var is_extern = false is writable
+
+       # An optional constant value returned in functions.
+       #
+       # Only some specific primitife value are accepted by engines.
+       # Is used when there is no better implementation available.
+       #
+       # Currently used only for the implementation of the `--define`
+       # command-line option.
+       # SEE: module `mixin`.
+       var constant_value: nullable Object = null is writable
 end
 
 # A local definition of an attribute
index 3153274..9297793 100644 (file)
@@ -528,7 +528,6 @@ class MEntityNameSorter
        super Comparator
        redef type COMPARED: MEntity
        redef fun compare(a, b) do return a.name <=> b.name
-       init do end
 end
 
 # Sort MConcerns based on the module importation hierarchy ranking
@@ -544,8 +543,6 @@ class MConcernRankSorter
        super Comparator
        redef type COMPARED: MConcern
 
-       init do end
-
        redef fun compare(a, b) do
                if a.concern_rank == b.concern_rank then
                        return a.name <=> b.name
index d702369..30a0617 100644 (file)
@@ -53,8 +53,8 @@ redef class ToolContext
 
        private var modelbuilder_real: nullable ModelBuilder = null
 
-       # Run `process_mainmodule` on all phases
-       fun run_global_phases(mmodules: Array[MModule])
+       # Combine module to make a single one if required.
+       fun make_main_module(mmodules: Array[MModule]): MModule
        do
                assert not mmodules.is_empty
                var mainmodule
@@ -62,10 +62,17 @@ redef class ToolContext
                        mainmodule = mmodules.first
                else
                        # We need a main module, so we build it by importing all modules
-                       mainmodule = new MModule(modelbuilder.model, null, mmodules.first.name, new Location(mmodules.first.location.file, 0, 0, 0, 0))
+                       mainmodule = new MModule(modelbuilder.model, null, mmodules.first.name + "-m", new Location(mmodules.first.location.file, 0, 0, 0, 0))
                        mainmodule.is_fictive = true
                        mainmodule.set_imported_mmodules(mmodules)
                end
+               return mainmodule
+       end
+
+       # Run `process_mainmodule` on all phases
+       fun run_global_phases(mmodules: Array[MModule])
+       do
+               var mainmodule = make_main_module(mmodules)
                for phase in phases_list do
                        if phase.disabled then continue
                        phase.process_mainmodule(mainmodule, mmodules)
@@ -738,11 +745,13 @@ class ModelBuilder
        end
 
        # Force to get the primitive method named `name` on the type `recv` or do a fatal error on `n`
-       fun force_get_primitive_method(n: ANode, name: String, recv: MClass, mmodule: MModule): MMethod
+       fun force_get_primitive_method(n: nullable ANode, name: String, recv: MClass, mmodule: MModule): MMethod
        do
                var res = mmodule.try_get_primitive_method(name, recv)
                if res == null then
-                       self.toolcontext.fatal_error(n.hot_location, "Fatal Error: {recv} must have a property named {name}.")
+                       var l = null
+                       if n != null then l = n.hot_location
+                       self.toolcontext.fatal_error(l, "Fatal Error: {recv} must have a property named {name}.")
                        abort
                end
                return res
index 2a5e9fb..441a6c2 100644 (file)
@@ -258,7 +258,6 @@ redef class ModelBuilder
        private fun check_supertypes(nmodule: AModule, nclassdef: AClassdef)
        do
                var mmodule = nmodule.mmodule.as(not null)
-               var objectclass = try_get_mclass_by_name(nmodule, mmodule, "Object")
                var mclass = nclassdef.mclass.as(not null)
                var mclassdef = nclassdef.mclassdef.as(not null)
 
@@ -410,7 +409,7 @@ redef class ModelBuilder
 
        # Register the nclassdef associated to each mclassdef
        # FIXME: why not refine the `MClassDef` class with a nullable attribute?
-       var mclassdef2nclassdef: HashMap[MClassDef, AClassdef] = new HashMap[MClassDef, AClassdef]
+       var mclassdef2nclassdef = new HashMap[MClassDef, AClassdef]
 
        # Return the static type associated to the node `ntype`.
        # `mmodule` and `mclassdef` is the context where the call is made (used to understand formal types)
index cbcae54..bb4d2cd 100644 (file)
@@ -38,7 +38,7 @@ end
 redef class ModelBuilder
        # Register the npropdef associated to each mpropdef
        # FIXME: why not refine the `MPropDef` class with a nullable attribute?
-       var mpropdef2npropdef: HashMap[MPropDef, APropdef] = new HashMap[MPropDef, APropdef]
+       var mpropdef2npropdef = new HashMap[MPropDef, APropdef]
 
        # Build the properties of `nclassdef`.
        # REQUIRE: all superclasses are built.
@@ -244,7 +244,7 @@ redef class ModelBuilder
                # Extract visibility information of the main part of `mtype`
                # It is a case-by case
                var vis_type: nullable MVisibility = null # The own visibility of the type
-               var mmodule_type: nullable MModule = null # The origial module of the type
+               var mmodule_type: nullable MModule = null # The original module of the type
                mtype = mtype.as_notnullable
                if mtype isa MClassType then
                        vis_type = mtype.mclass.visibility
@@ -291,7 +291,7 @@ redef class MPropDef
 end
 
 redef class AClassdef
-       var build_properties_is_done: Bool = false
+       var build_properties_is_done = false
 
        # The free init (implicitely constructed by the class if required)
        var mfree_init: nullable MMethodDef = null
@@ -474,7 +474,7 @@ redef class ASignature
                var ntype = self.n_type
                if ntype != null then
                        self.ret_type = modelbuilder.resolve_mtype(mmodule, mclassdef, ntype)
-                       if self.ret_type == null then return false # Skip errir
+                       if self.ret_type == null then return false # Skip error
                end
 
                self.is_visited = true
@@ -762,12 +762,12 @@ redef class AAttrPropdef
        # Is the node tagged `noinit`?
        var noinit = false
 
-       # Is the node taggeg lazy?
+       # Is the node tagged lazy?
        var is_lazy = false
 
-       # The guard associated to a lasy attribute.
+       # The guard associated to a lazy attribute.
        # Because some engines does not have a working `isset`,
-       # this additionnal attribute is used to guard the lazy initialization.
+       # this additional attribute is used to guard the lazy initialization.
        # TODO: to remove once isset is correctly implemented
        var mlazypropdef: nullable MAttributeDef
 
@@ -874,7 +874,7 @@ redef class AAttrPropdef
        redef fun build_signature(modelbuilder)
        do
                var mpropdef = self.mpropdef
-               if mpropdef == null then return # Error thus skiped
+               if mpropdef == null then return # Error thus skipped
                var mclassdef = mpropdef.mclassdef
                var mmodule = mclassdef.mmodule
                var mtype: nullable MType = null
@@ -887,10 +887,10 @@ redef class AAttrPropdef
                        if mtype == null then return
                end
 
-               # Inherit the type from the getter (usually an abstact getter)
+               # Inherit the type from the getter (usually an abstract getter)
                if mtype == null and mreadpropdef != null and not mreadpropdef.is_intro then
                        var msignature = mreadpropdef.mproperty.intro.msignature
-                       if msignature == null then return # Error, thus skiped
+                       if msignature == null then return # Error, thus skipped
                        mtype = msignature.return_mtype
                end
 
@@ -962,12 +962,10 @@ redef class AAttrPropdef
        redef fun check_signature(modelbuilder)
        do
                var mpropdef = self.mpropdef
-               if mpropdef == null then return # Error thus skiped
-               var mclassdef = mpropdef.mclassdef
-               var mmodule = mclassdef.mmodule
+               if mpropdef == null then return # Error thus skipped
                var ntype = self.n_type
                var mtype = self.mpropdef.static_mtype
-               if mtype == null then return # Error thus skiped
+               if mtype == null then return # Error thus skipped
 
                # Lookup for signature in the precursor
                # FIXME all precursors should be considered
@@ -1090,7 +1088,7 @@ redef class ATypePropdef
        redef fun build_signature(modelbuilder)
        do
                var mpropdef = self.mpropdef
-               if mpropdef == null then return # Error thus skiped
+               if mpropdef == null then return # Error thus skipped
                var mclassdef = mpropdef.mclassdef
                var mmodule = mclassdef.mmodule
                var mtype: nullable MType = null
@@ -1106,10 +1104,10 @@ redef class ATypePropdef
        redef fun check_signature(modelbuilder)
        do
                var mpropdef = self.mpropdef
-               if mpropdef == null then return # Error thus skiped
+               if mpropdef == null then return # Error thus skipped
 
                var bound = self.mpropdef.bound
-               if bound == null then return # Error thus skiped
+               if bound == null then return # Error thus skipped
 
                modelbuilder.check_visibility(n_type, bound, mpropdef)
 
index b44d034..a45c91c 100644 (file)
@@ -446,7 +446,6 @@ class NeoModel
                node.labels.add "MModule"
                node["full_name"] = mmodule.full_name
                node["location"] = mmodule.location.to_s
-               var mgroup = mmodule.mgroup
                for parent in mmodule.in_importation.direct_greaters do
                        node.out_edges.add(new NeoEdge(node, "IMPORTS", to_node(parent)))
                end
index 24bb00e..9a95194 100644 (file)
@@ -27,10 +27,9 @@ toolcontext.tooldescription = "Usage: nit [OPTION]... <file.nit>...\nInterprets
 # Add an option "-o" to enable compatibilit with the tests.sh script
 var opt = new OptionString("compatibility (does noting)", "-o")
 toolcontext.option_context.add_option(opt)
-var opt_mixins = new OptionArray("Additionals module to min-in", "-m")
 var opt_eval = new OptionBool("Specifies the program from command-line", "-e")
 var opt_loop = new OptionBool("Repeatedly run the program for each line in file-name arguments", "-n")
-toolcontext.option_context.add_option(opt_mixins, opt_eval, opt_loop)
+toolcontext.option_context.add_option(opt_eval, opt_loop)
 # We do not add other options, so process them now!
 toolcontext.process_options(args)
 
@@ -66,20 +65,11 @@ else
        mmodules = modelbuilder.parse([progname])
 end
 
-mmodules.add_all modelbuilder.parse(opt_mixins.value)
 modelbuilder.run_phases
 
 if toolcontext.opt_only_metamodel.value then exit(0)
 
-var mainmodule: nullable MModule
-
-# Here we launch the interpreter on the main module
-if mmodules.length == 1 then
-       mainmodule = mmodules.first
-else
-       mainmodule = new MModule(model, null, mmodules.first.name, mmodules.first.location)
-       mainmodule.set_imported_mmodules(mmodules)
-end
+var mainmodule = toolcontext.make_main_module(mmodules)
 
 var self_mm = mainmodule
 var self_args = arguments
index e7a733a..e43ff7f 100644 (file)
@@ -2252,7 +2252,6 @@ end
 
 redef class ASuperstringExpr
        redef fun accept_pretty_printer(v) do
-               var force_inline = self.force_inline
                for n_expr in n_exprs do v.visit n_expr
        end
 
index 5ad0aed..2fd0f82 100644 (file)
@@ -53,7 +53,7 @@ class NitModule
                if header != null then add header
 
                var name = name
-               if name != null then add "module {name}\n\n"
+               add "module {name}\n\n"
 
                for i in imports do add "import {i}\n"
                add "\n"
index 7daee0f..b60ed2e 100644 (file)
@@ -237,8 +237,6 @@ private class ComputeProdLocationVisitor
                        end
                end
        end
-
-       init do end
 end
 
 # Each reduce action has its own class, this one is the root of the hierarchy.
index 6ce94cb..897d7b7 100644 (file)
@@ -244,6 +244,9 @@ class RapidTypeAnalysis
                                        if mmethoddef.mproperty.is_root_init and not mmethoddef.is_intro then
                                                self.add_super_send(v.receiver, mmethoddef)
                                        end
+                               else if mmethoddef.constant_value != null then
+                                       # Make the return type live
+                                       v.add_type(mmethoddef.msignature.return_mtype.as(MClassType))
                                else
                                        abort
                                end
index 95b2acb..25874e2 100644 (file)
@@ -32,10 +32,6 @@ end
 
 private class AutoSuperInitVisitor
        super Visitor
-       init
-       do
-       end
-
        redef fun visit(n)
        do
                n.accept_auto_super_init(self)
@@ -210,7 +206,6 @@ redef class ASendExpr
        redef fun accept_auto_super_init(v)
        do
                var mproperty = self.callsite.mproperty
-               if mproperty == null then return
                if mproperty.is_init then
                        v.has_explicit_super_init = self
                end
index bd63c0f..5c9adeb 100644 (file)
@@ -47,7 +47,7 @@ private class TypeVisitor
        # The analyzed property
        var mpropdef: nullable MPropDef
 
-       var selfvariable: Variable = new Variable("self")
+       var selfvariable = new Variable("self")
 
        # Is `self` use restricted?
        # * no explicit `self`
@@ -195,6 +195,40 @@ private class TypeVisitor
                return sup
        end
 
+       # Special verification on != and == for null
+       # Return true
+       fun null_test(anode: ABinopExpr)
+       do
+               var mtype = anode.n_expr.mtype
+               var mtype2 = anode.n_expr2.mtype
+
+               if mtype == null or mtype2 == null then return
+
+               if not mtype2 isa MNullType then return
+
+               # Check of useless null
+               if not mtype isa MNullableType then
+                       if not anchor_to(mtype) isa MNullableType then
+                               modelbuilder.warning(anode, "useless-null-test", "Warning: expression is not null, since it is a `{mtype}`.")
+                       end
+                       return
+               end
+
+               # Check for type adaptation
+               var variable = anode.n_expr.its_variable
+               if variable == null then return
+
+               if anode isa AEqExpr then
+                       anode.after_flow_context.when_true.set_var(variable, mtype2)
+                       anode.after_flow_context.when_false.set_var(variable, mtype.mtype)
+               else if anode isa ANeExpr then
+                       anode.after_flow_context.when_false.set_var(variable, mtype2)
+                       anode.after_flow_context.when_true.set_var(variable, mtype.mtype)
+               else
+                       abort
+               end
+       end
+
        fun try_get_mproperty_by_name2(anode: ANode, mtype: MType, name: String): nullable MProperty
        do
                return self.modelbuilder.try_get_mproperty_by_name2(anode, mmodule, mtype, name)
@@ -395,7 +429,6 @@ private class TypeVisitor
        fun merge_types(node: ANode, col: Array[nullable MType]): nullable MType
        do
                if col.length == 1 then return col.first
-               var res = new Array[nullable MType]
                for t1 in col do
                        if t1 == null then continue # return null
                        var found = true
@@ -461,8 +494,8 @@ end
 
 redef class FlowContext
        # Store changes of types because of type evolution
-       private var vars: HashMap[Variable, nullable MType] = new HashMap[Variable, nullable MType]
-       private var cache: HashMap[Variable, nullable Array[nullable MType]] = new HashMap[Variable, nullable Array[nullable MType]]
+       private var vars = new HashMap[Variable, nullable MType]
+       private var cache = new HashMap[Variable, nullable Array[nullable MType]]
 
        # Adapt the variable to a static type
        # Warning1: do not modify vars directly.
@@ -747,7 +780,7 @@ redef class AContinueExpr
        do
                var nexpr = self.n_expr
                if nexpr != null then
-                       var mtype = v.visit_expr(nexpr)
+                       v.visit_expr(nexpr)
                end
                self.is_typed = true
        end
@@ -758,7 +791,7 @@ redef class ABreakExpr
        do
                var nexpr = self.n_expr
                if nexpr != null then
-                       var mtype = v.visit_expr(nexpr)
+                       v.visit_expr(nexpr)
                end
                self.is_typed = true
        end
@@ -771,9 +804,9 @@ redef class AReturnExpr
                var ret_type = v.mpropdef.as(MMethodDef).msignature.return_mtype
                if nexpr != null then
                        if ret_type != null then
-                               var mtype = v.visit_expr_subtype(nexpr, ret_type)
+                               v.visit_expr_subtype(nexpr, ret_type)
                        else
-                               var mtype = v.visit_expr(nexpr)
+                               v.visit_expr(nexpr)
                                v.error(self, "Error: Return with value in a procedure.")
                        end
                else if ret_type != null then
@@ -1223,9 +1256,9 @@ redef class AIsaExpr
 
                var variable = self.n_expr.its_variable
                if variable != null then
-                       var orig = self.n_expr.mtype
-                       var from = if orig != null then orig.to_s else "invalid"
-                       var to = if mtype != null then mtype.to_s else "invalid"
+                       #var orig = self.n_expr.mtype
+                       #var from = if orig != null then orig.to_s else "invalid"
+                       #var to = if mtype != null then mtype.to_s else "invalid"
                        #debug("adapt {variable}: {from} -> {to}")
                        self.after_flow_context.when_true.set_var(variable, mtype)
                end
@@ -1352,16 +1385,7 @@ redef class AEqExpr
        redef fun accept_typing(v)
        do
                super
-
-               var variable = self.n_expr.its_variable
-               if variable == null then return
-               var mtype = self.n_expr2.mtype
-               if not mtype isa MNullType then return
-               var vartype = v.get_variable(self, variable)
-               if not vartype isa MNullableType then return
-               self.after_flow_context.when_true.set_var(variable, mtype)
-               self.after_flow_context.when_false.set_var(variable, vartype.mtype)
-               #debug("adapt {variable}:{vartype} ; true->{mtype} false->{vartype.mtype}")
+               v.null_test(self)
        end
 end
 redef class ANeExpr
@@ -1369,16 +1393,7 @@ redef class ANeExpr
        redef fun accept_typing(v)
        do
                super
-
-               var variable = self.n_expr.its_variable
-               if variable == null then return
-               var mtype = self.n_expr2.mtype
-               if not mtype isa MNullType then return
-               var vartype = v.get_variable(self, variable)
-               if not vartype isa MNullableType then return
-               self.after_flow_context.when_false.set_var(variable, mtype)
-               self.after_flow_context.when_true.set_var(variable, vartype.mtype)
-               #debug("adapt {variable}:{vartype} ; true->{vartype.mtype} false->{mtype}")
+               v.null_test(self)
        end
 end
 redef class ALtExpr
index f543a2b..566e014 100644 (file)
@@ -200,7 +200,6 @@ redef class ModelBuilder
                if not mmodule2nmodule.has_key(mmodule) then return ts
 
                var nmodule = mmodule2nmodule[mmodule]
-               assert nmodule != null
 
                # usualy, only the original module must be imported in the unit test.
                var o = mmodule
index 893a843..05c88fb 100644 (file)
@@ -438,7 +438,7 @@ class BashCompletion
                addn "  COMPREPLY=()"
                addn "  cur=\"$\{COMP_WORDS[COMP_CWORD]\}\""
                addn "  prev=\"$\{COMP_WORDS[COMP_CWORD-1]\}\""
-               if option_names != null then
+               if not option_names.is_empty then
                        addn "  opts=\"{option_names.join(" ")}\""
                        addn "  if [[ $\{cur\} == -* ]] ; then"
                        addn "          COMPREPLY=( $(compgen -W \"$\{opts\}\" -- $\{cur\}) )"
index 0779a6a..3807ab7 100644 (file)
@@ -106,7 +106,6 @@ class VirtualMachine super NaiveInterpreter
                # Sub can be discovered inside a Generic type during the subtyping test
                if not sub.mclass.loaded then create_class(sub.mclass)
 
-               if anchor == null then anchor = sub
                if sup isa MGenericType then
                        var sub2 = sub.supertype_to(mainmodule, anchor, sup.mclass)
                        assert sub2.mclass == sup.mclass
index 3011fc1..0c14c1c 100644 (file)
@@ -1,3 +1,4 @@
 --log --log-dir out/test_nitc_logs ../examples/hello_world.nit
 base_simple3.nit
 -m test_mixin.nit ../examples/hello_world.nit
+test_define.nit -D text=hello -D num=42 -D flag
index 3b38c54..6a47146 100644 (file)
@@ -5,3 +5,4 @@
 --global ../examples/hello_world.nit -m test_mixin.nit -o out/nitg-hello_world_mixed ; out/nitg-hello_world_mixed
 --separate ../examples/hello_world.nit -m test_mixin.nit -o out/nitgs-hello_world_mixed ; out/nitgs-hello_world_mixed
 base_simple_import.nit base_simple.nit --dir out/ ; out/base_simple ; out/base_simple_import
+test_define.nit -D text=hello -D num=42 -D flag --dir out/ ; out/test_define
index c052cff..baf5b76 100644 (file)
@@ -5,6 +5,7 @@ shoot_logic
 bench_
 nit_args1
 nit_args3
+nit_args4
 nitvm_args1
 nitvm_args3
 nitc_args1
@@ -12,6 +13,7 @@ nitg_args1
 nitg_args3
 nitg_args5
 nitg_args6
+nitg_args8
 test_markdown_args1
 pep8analysis
 nitcc_parser_gen
index 41a85bf..b4226bc 100644 (file)
@@ -1,3 +1,5 @@
+base_eq_null_notnull.nit:36,6--14: Warning: expression is not null, since it is a `A`.
+base_eq_null_notnull.nit:43,2--10: Warning: expression is not null, since it is a `A`.
 true
 true
 true
index a556a0a..46069e8 100644 (file)
@@ -1,3 +1,4 @@
+base_var_type_evolution_null3.nit:52,5--13: Warning: expression is not null, since it is a `Object`.
 1
 1
 5
index a556a0a..a10a5e3 100644 (file)
@@ -1,3 +1,4 @@
+alt/base_var_type_evolution_null3_alt1.nit:52,5--13: Warning: expression is not null, since it is a `Object`.
 1
 1
 5
diff --git a/tests/sav/nit_args4.res b/tests/sav/nit_args4.res
new file mode 100644 (file)
index 0000000..483d841
--- /dev/null
@@ -0,0 +1,3 @@
+hello
+42
+true
diff --git a/tests/sav/nitg_args8.res b/tests/sav/nitg_args8.res
new file mode 100644 (file)
index 0000000..483d841
--- /dev/null
@@ -0,0 +1,3 @@
+hello
+42
+true
diff --git a/tests/sav/niti/error_needed_method_alt3.res b/tests/sav/niti/error_needed_method_alt3.res
deleted file mode 100644 (file)
index 34dd8c9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-alt/error_needed_method_alt3.nit:48,9--13: Fatal Error: NativeString must have a property named to_s.
index 4daa384..d1e2d76 100644 (file)
@@ -1 +1 @@
-alt/error_needed_method_alt4.nit:49,10--14: Fatal Error: NativeString must have a property named to_s.
+alt/error_needed_method_alt4.nit:49,10--14: Fatal Error: NativeString must have a property named to_s_with_length.
diff --git a/tests/sav/test_define.res b/tests/sav/test_define.res
new file mode 100644 (file)
index 0000000..8d40171
--- /dev/null
@@ -0,0 +1,3 @@
+some text
+1
+false
diff --git a/tests/test_define.nit b/tests/test_define.nit
new file mode 100644 (file)
index 0000000..4b8ebc7
--- /dev/null
@@ -0,0 +1,20 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+fun text: String do return "some text"
+fun num: Int do return 1
+fun flag: Bool do return false
+print text
+print num
+print flag
index b070f63..8b49b8b 100644 (file)
@@ -128,15 +128,10 @@ if test.address_is_null then env.print_error("object test not initialized")
 
 # Retrieve field value with field ids
 var v_bool = env.get_boolean_field(test, f_bool)
-if v_bool == null then env.print_error("vbool not found")
 var v_char = env.get_char_field(test, f_char)
-if v_char == null then env.print_error("vchar not found")
 var v_i = env.get_int_field(test, f_i)
-if v_i == null then env.print_error("vi not found")
 var v_f = env.get_float_field(test, f_f)
-if v_f == null then env.print_error("vf not found")
 var v_test1 = env.get_object_field(test, f_test)
-if v_test1 == null then env.print_error("vtest1 not found")
 
 # Set the new values for the fields
 env.set_boolean_field(test, f_bool, true)
@@ -151,7 +146,6 @@ v_char = env.call_char_method(test, m_char, null)
 v_i = env.call_int_method(test, m_i, null)
 v_f = env.call_float_method(test, m_f, null)
 var v_test2 = env.call_object_method(test, m_test, null)
-if v_test2 == null then env.print_error("vtest2 not found")
 
 # assert the values of the fields
 print v_bool