if main_init != null then
v.send(main_init, [glob_sys])
end
- var main_method = mainmodule.try_get_primitive_method("main", main_type.mclass)
+ var main_method = mainmodule.try_get_primitive_method("run", main_type.mclass) or else
+ mainmodule.try_get_primitive_method("main", main_type.mclass)
if main_method != null then
v.send(main_method, [glob_sys])
end
redef class AAttrPropdef
redef fun compile_to_c(v, mpropdef, arguments)
do
- if arguments.length == 1 then
- var res = v.read_attribute(self.mpropdef.mproperty, arguments.first)
+ if mpropdef == mreadpropdef then
+ assert arguments.length == 1
+ var res
+ if is_lazy then
+ var nexpr = n_expr
+ assert nexpr != null
+ var set
+ var ret = self.mpropdef.static_mtype
+ var useiset = ret.ctype == "val*" and not ret isa MNullableType
+ var guard = self.mlazypropdef.mproperty
+ if useiset then
+ set = v.isset_attribute(self.mpropdef.mproperty, arguments.first)
+ else
+ set = v.read_attribute(guard, arguments.first)
+ end
+ v.add("if(likely({set})) \{")
+ res = v.read_attribute(self.mpropdef.mproperty, arguments.first)
+ v.add("\} else \{")
+ var value = v.expr(nexpr, self.mpropdef.static_mtype)
+ v.write_attribute(self.mpropdef.mproperty, arguments.first, value)
+ v.assign(res, value)
+ if not useiset then
+ var true_v = v.new_expr("1", v.bool_type)
+ v.write_attribute(guard, arguments.first, true_v)
+ end
+ v.add("\}")
+ else
+ res = v.read_attribute(self.mpropdef.mproperty, arguments.first)
+ end
v.assign(v.frame.returnvar.as(not null), res)
- else
+ else if mpropdef == mwritepropdef then
+ assert arguments.length == 2
v.write_attribute(self.mpropdef.mproperty, arguments.first, arguments[1])
+ if is_lazy then
+ var ret = self.mpropdef.static_mtype
+ var useiset = ret.ctype == "val*" and not ret isa MNullableType
+ if not useiset then
+ v.write_attribute(self.mlazypropdef.mproperty, arguments.first, v.new_expr("1", v.bool_type))
+ end
+ end
+ else
+ abort
end
end
fun init_expr(v: AbstractCompilerVisitor, recv: RuntimeVariable)
do
var nexpr = self.n_expr
- if nexpr != null then
+ if nexpr != null and not is_lazy then
var oldnode = v.current_node
v.current_node = self
var old_frame = v.frame
var i = 1
# Collect undefined attributes
for npropdef in self.n_propdefs do
- if npropdef isa AAttrPropdef and npropdef.n_expr == null then
+ if npropdef isa AAttrPropdef and npropdef.n_expr == null and not npropdef.noinit then
v.write_attribute(npropdef.mpropdef.mproperty, recv, arguments[i])
i += 1
end
# Shortcut on explicit range
# Avoid the instantiation of the range and the iterator
var nexpr = self.n_expr
- if self.variables.length == 1 and nexpr isa AOrangeExpr and not v.compiler.modelbuilder.toolcontext.opt_no_shortcut_range.value then
+ if self.variables.length == 1 and nexpr isa ARangeExpr and not v.compiler.modelbuilder.toolcontext.opt_no_shortcut_range.value then
var from = v.expr(nexpr.n_expr, null)
var to = v.expr(nexpr.n_expr2, null)
var variable = v.variable(variables.first)
+ var one = v.new_expr("1", v.get_class("Int").mclass_type)
v.assign(variable, from)
v.add("for(;;) \{ /* shortcut range */")
- var ok = v.send(v.get_property("<", variable.mtype), [variable, to])
+ var ok
+ if nexpr isa AOrangeExpr then
+ ok = v.send(v.get_property("<", variable.mtype), [variable, to])
+ else
+ ok = v.send(v.get_property("<=", variable.mtype), [variable, to])
+ end
assert ok != null
v.add("if(!{ok}) break;")
v.stmt(self.n_block)
v.add("CONTINUE_{v.escapemark_name(escapemark)}: (void)0;")
- var succ = v.send(v.get_property("succ", variable.mtype), [variable])
+ var succ = v.send(v.get_property("successor", variable.mtype), [variable, one])
assert succ != null
v.assign(variable, succ)
v.add("\}")