X-Git-Url: http://nitlanguage.org diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 4c7987e..ddd7323 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1036,8 +1036,8 @@ abstract class AbstractCompilerVisitor # The current visited AST node var current_node: nullable ANode = null is writable - # The current `Frame` - var frame: nullable Frame = null is writable + # The current `StaticFrame` + var frame: nullable StaticFrame = null is writable # Alias for self.compiler.mainmodule.object_type fun object_type: MClassType do return self.compiler.mainmodule.object_type @@ -1534,6 +1534,15 @@ abstract class AbstractCompilerVisitor fun stmt(nexpr: nullable AExpr) do if nexpr == null then return + + var narray = nexpr.comprehension + if narray != null then + var recv = frame.comprehension.as(not null) + var val = expr(nexpr, narray.element_mtype) + compile_callsite(narray.push_callsite.as(not null), [recv, val]) + return + end + var old = self.current_node self.current_node = nexpr nexpr.stmt(self) @@ -1656,8 +1665,8 @@ class RuntimeVariable end end -# A frame correspond to a visited property in a `GlobalCompilerVisitor` -class Frame +# The static context of a visited property in a `AbstractCompilerVisitor` +class StaticFrame type VISITOR: AbstractCompilerVisitor @@ -1683,6 +1692,9 @@ class Frame # Labels associated to a each escapemarks. # Because of inlinings, escape-marks must be associated to their context (the frame) private var escapemark_names = new HashMap[EscapeMark, String] + + # The array comprehension currently filled, if any + private var comprehension: nullable RuntimeVariable = null end redef class MType @@ -2199,6 +2211,8 @@ redef class AMethPropdef end redef class AAttrPropdef + redef fun can_inline: Bool do return not is_lazy + redef fun compile_to_c(v, mpropdef, arguments) do if mpropdef == mreadpropdef then @@ -2257,7 +2271,7 @@ redef class AAttrPropdef var oldnode = v.current_node v.current_node = self var old_frame = v.frame - var frame = new Frame(v, self.mpropdef.as(not null), recv.mcasttype.as_notnullable.as(MClassType), [recv]) + var frame = new StaticFrame(v, self.mpropdef.as(not null), recv.mcasttype.as_notnullable.as(MClassType), [recv]) v.frame = frame var value @@ -2296,7 +2310,7 @@ redef class AAttrPropdef var oldnode = v.current_node v.current_node = self var old_frame = v.frame - var frame = new Frame(v, self.mpropdef.as(not null), recv.mtype.as(MClassType), [recv]) + var frame = new StaticFrame(v, self.mpropdef.as(not null), recv.mtype.as(MClassType), [recv]) v.frame = frame # Force read to check the initialization v.read_attribute(self.mpropdef.mproperty, recv) @@ -2652,11 +2666,16 @@ redef class AArrayExpr do var mtype = self.element_mtype.as(not null) var array = new Array[RuntimeVariable] + var res = v.array_instance(array, mtype) + + var old_comprehension = v.frame.comprehension + v.frame.comprehension = res for nexpr in self.n_exprs do - var i = v.expr(nexpr, mtype) - array.add(i) + v.stmt(nexpr) end - return v.array_instance(array, mtype) + v.frame.comprehension = old_comprehension + + return res end end