X-Git-Url: http://nitlanguage.org diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 064395d..5cc3892 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -72,10 +72,12 @@ class NaiveInterpreter init do - self.true_instance = new PrimitiveInstance[Bool](mainmodule.bool_type, true) - init_instance_primitive(self.true_instance) - self.false_instance = new PrimitiveInstance[Bool](mainmodule.bool_type, false) - init_instance_primitive(self.false_instance) + if mainmodule.model.get_mclasses_by_name("Bool") != null then + self.true_instance = new PrimitiveInstance[Bool](mainmodule.bool_type, true) + init_instance_primitive(self.true_instance) + self.false_instance = new PrimitiveInstance[Bool](mainmodule.bool_type, false) + init_instance_primitive(self.false_instance) + end self.null_instance = new PrimitiveInstance[nullable Object](mainmodule.model.null_type, null) end @@ -171,14 +173,20 @@ class NaiveInterpreter # If `n` cannot be evaluated, then aborts. fun stmt(n: nullable AExpr) do - if n != null then - var frame = self.frame - var old = frame.current_node - frame.current_node = n - #n.debug("Execute stmt") - n.stmt(self) - frame.current_node = old + if n == null then return + + if n.comprehension != null then + var comprehension = frame.comprehension.as(not null) + var i = expr(n) + if i != null then comprehension.add(i) + return end + + var frame = self.frame + var old = frame.current_node + frame.current_node = n + n.stmt(self) + frame.current_node = old end # Map used to store values of nodes that must be evaluated once in the system (`AOnceExpr`) @@ -450,7 +458,7 @@ class NaiveInterpreter fun send_commons(mproperty: MMethod, args: Array[Instance], mtype: MType): nullable Instance do if mtype isa MNullType then - if mproperty.name == "==" then + if mproperty.name == "==" or mproperty.name == "is_same_instance" then return self.bool_instance(args[0] == args[1]) else if mproperty.name == "!=" then return self.bool_instance(args[0] != args[1]) @@ -662,6 +670,7 @@ class Frame var arguments: Array[Instance] # Mapping between a variable and the current value private var map: Map[Variable, Instance] = new HashMap[Variable, Instance] + var comprehension: nullable Array[Instance] = null end redef class ANode @@ -1530,11 +1539,18 @@ redef class AArrayExpr redef fun expr(v) do var val = new Array[Instance] - for nexpr in self.n_exprs.n_exprs do - var i = v.expr(nexpr) - if i == null then return null - val.add(i) + var old_comprehension = v.frame.comprehension + v.frame.comprehension = val + for nexpr in self.n_exprs do + if nexpr isa AForExpr then + v.stmt(nexpr) + else + var i = v.expr(nexpr) + if i == null then return null + val.add(i) + end end + v.frame.comprehension = old_comprehension var mtype = v.unanchor_type(self.mtype.as(not null)).as(MClassType) var elttype = mtype.arguments.first return v.array_instance(val, elttype)