fun compile_callsite(callsite: CallSite, arguments: Array[RuntimeVariable]): nullable RuntimeVariable
do
+ if callsite.is_broken then return null
var initializers = callsite.mpropdef.initializers
if not initializers.is_empty then
var recv = arguments.first
do
var t = mmodule.char_type
- if value.ascii < 128 then
+ if value.code_point < 128 then
return new RuntimeVariable("'{value.to_s.escape_to_c}'", t, t)
else
- return new RuntimeVariable("{value.ascii}", t, t)
+ return new RuntimeVariable("{value.code_point}", t, t)
end
end
var native_mtype = mmodule.native_string_type
var nat = self.new_var(native_mtype)
self.add("{nat} = \"{string.escape_to_c}\";")
- var length = self.int_instance(string.bytelen)
- self.add("{res} = {self.send(self.get_property("to_s_with_length", native_mtype), [nat, length]).as(not null)};")
+ var bytelen = self.int_instance(string.bytelen)
+ var unilen = self.int_instance(string.length)
+ self.add("{res} = {self.send(self.get_property("to_s_full", native_mtype), [nat, bytelen, unilen]).as(not null)};")
self.add("{name} = {res};")
self.add("\}")
return res
fun stmt(nexpr: nullable AExpr)
do
if nexpr == null then return
- if nexpr.mtype == null and not nexpr.is_typed then
+ if nexpr.is_broken then
# Untyped expression.
# Might mean dead code or invalid code
# so aborts
do
if v.compiler.modelbuilder.toolcontext.opt_no_check_covariance.value then return
+ var msignature = self.msignature.as(not null)
+
for i in [0..msignature.arity[ do
# skip test for vararg since the array is instantiated with the correct polymorphic type
if msignature.vararg_rank == i then continue
if not origmtype.need_anchor then continue
# get the parameter type
- var mtype = self.msignature.mparameters[i].mtype
+ var mtype = msignature.mparameters[i].mtype
# generate the cast
# note that v decides if and how to implements the cast
- v.add("/* Covariant cast for argument {i} ({self.msignature.mparameters[i].name}) {arguments[i+1].inspect} isa {mtype} */")
+ v.add("/* Covariant cast for argument {i} ({msignature.mparameters[i].name}) {arguments[i+1].inspect} isa {mtype} */")
v.add_cast(arguments[i+1], mtype, "covariance")
end
end
else if pname == "to_b" then
v.ret(v.new_expr("(unsigned char){arguments[0]}", ret.as(not null)))
return true
- else if pname == "ascii" then
- v.ret(v.new_expr("(uint32_t){arguments[0]}", ret.as(not null)))
- return true
end
else if cname == "Char" then
if pname == "object_id" then
else if pname == "to_i" then
v.ret(v.new_expr("{arguments[0]}-'0'", ret.as(not null)))
return true
- else if pname == "ascii" then
- v.ret(v.new_expr("(long){arguments[0]}", ret.as(not null)))
- return true
end
else if cname == "Byte" then
if pname == "output" then
else if pname == "to_u32" then
v.ret(v.new_expr("(uint32_t){arguments[0]}", ret.as(not null)))
return true
- else if pname == "ascii" then
- v.ret(v.new_expr("{arguments[0]}", ret.as(not null)))
- return true
end
else if cname == "Bool" then
if pname == "output" then
else if pname == "to_f" then
v.ret(v.new_expr("(double){arguments[0]}", ret.as(not null)))
return true
- else if pname == "ascii" then
- v.ret(v.new_expr("{arguments[0]}", ret.as(not null)))
- return true
else if pname == "&" then
v.ret(v.new_expr("{arguments[0]} & {arguments[1]}", ret.as(not null)))
return true
else if pname == "unary ~" then
v.ret(v.new_expr("~{arguments[0]}", ret.as(not null)))
return true
- else if pname == "ascii" then
- v.ret(v.new_expr("{arguments[0]}", ret.as(not null)))
- return true
end
else if cname == "UInt16" then
if pname == "output" then
else if pname == "unary ~" then
v.ret(v.new_expr("~{arguments[0]}", ret.as(not null)))
return true
- else if pname == "ascii" then
- v.ret(v.new_expr("{arguments[0]}", ret.as(not null)))
- return true
end
else if cname == "Int32" then
if pname == "output" then
else if pname == "unary ~" then
v.ret(v.new_expr("~{arguments[0]}", ret.as(not null)))
return true
- else if pname == "ascii" then
- v.ret(v.new_expr("{arguments[0]}", ret.as(not null)))
- return true
end
else if cname == "UInt32" then
if pname == "output" then
else if pname == "unary ~" then
v.ret(v.new_expr("~{arguments[0]}", ret.as(not null)))
return true
- else if pname == "ascii" then
- v.ret(v.new_expr("{arguments[0]}", ret.as(not null)))
- return true
end
end
if pname == "exit" then
redef class AForExpr
redef fun stmt(v)
do
- var cl = v.expr(self.n_expr, null)
- var it_meth = self.method_iterator
- assert it_meth != null
- var it = v.compile_callsite(it_meth, [cl])
- assert it != null
+ for g in n_groups do
+ var cl = v.expr(g.n_expr, null)
+ var it_meth = g.method_iterator
+ assert it_meth != null
+ var it = v.compile_callsite(it_meth, [cl])
+ assert it != null
+ g.it = it
+ end
v.add("for(;;) \{")
- var isok_meth = self.method_is_ok
- assert isok_meth != null
- var ok = v.compile_callsite(isok_meth, [it])
- assert ok != null
- v.add("if(!{ok}) break;")
- if self.variables.length == 1 then
- var item_meth = self.method_item
- assert item_meth != null
- var i = v.compile_callsite(item_meth, [it])
- assert i != null
- v.assign(v.variable(variables.first), i)
- else if self.variables.length == 2 then
- var key_meth = self.method_key
- assert key_meth != null
- var i = v.compile_callsite(key_meth, [it])
- assert i != null
- v.assign(v.variable(variables[0]), i)
- var item_meth = self.method_item
- assert item_meth != null
- i = v.compile_callsite(item_meth, [it])
- assert i != null
- v.assign(v.variable(variables[1]), i)
- else
- abort
+ for g in n_groups do
+ var it = g.it
+ var isok_meth = g.method_is_ok
+ assert isok_meth != null
+ var ok = v.compile_callsite(isok_meth, [it])
+ assert ok != null
+ v.add("if(!{ok}) break;")
+ if g.variables.length == 1 then
+ var item_meth = g.method_item
+ assert item_meth != null
+ var i = v.compile_callsite(item_meth, [it])
+ assert i != null
+ v.assign(v.variable(g.variables.first), i)
+ else if g.variables.length == 2 then
+ var key_meth = g.method_key
+ assert key_meth != null
+ var i = v.compile_callsite(key_meth, [it])
+ assert i != null
+ v.assign(v.variable(g.variables[0]), i)
+ var item_meth = g.method_item
+ assert item_meth != null
+ i = v.compile_callsite(item_meth, [it])
+ assert i != null
+ v.assign(v.variable(g.variables[1]), i)
+ else
+ abort
+ end
end
v.stmt(self.n_block)
v.add_escape_label(continue_mark)
- var next_meth = self.method_next
- assert next_meth != null
- v.compile_callsite(next_meth, [it])
+ for g in n_groups do
+ var next_meth = g.method_next
+ assert next_meth != null
+ v.compile_callsite(next_meth, [g.it])
+ end
v.add("\}")
v.add_escape_label(break_mark)
- var method_finish = self.method_finish
- if method_finish != null then
- # TODO: Find a way to call this also in long escape (e.g. return)
- v.compile_callsite(method_finish, [it])
+ for g in n_groups do
+ var method_finish = g.method_finish
+ if method_finish != null then
+ # TODO: Find a way to call this also in long escape (e.g. return)
+ v.compile_callsite(method_finish, [g.it])
+ end
end
end
end
+redef class AForGroup
+ # C variable representing the iterator
+ private var it: RuntimeVariable is noinit
+end
+
redef class AAssertExpr
redef fun stmt(v)
do
do
var recv = v.expr(self.n_expr, null)
var callsite = self.callsite.as(not null)
+ if callsite.is_broken then return null
var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.raw_arguments)
return v.compile_callsite(callsite, args)
end
do
var recv = v.expr(self.n_expr, null)
var callsite = self.callsite.as(not null)
+ if callsite.is_broken then return
var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.raw_arguments)
var value = v.expr(self.n_value, null)
redef class ASuperExpr
redef fun expr(v)
do
- var recv = v.frame.arguments.first
+ var frame = v.frame.as(not null)
+ var recv = frame.arguments.first
var callsite = self.callsite
if callsite != null then
+ if callsite.is_broken then return null
var args
if self.n_args.n_exprs.is_empty then
# Add automatic arguments for the super init call
args = [recv]
for i in [0..callsite.msignature.arity[ do
- args.add(v.frame.arguments[i+1])
+ args.add(frame.arguments[i+1])
end
else
args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
var args
if self.n_args.n_exprs.is_empty then
- args = v.frame.arguments
+ args = frame.arguments
else
args = v.varargize(mpropdef, signaturemap, recv, self.n_args.n_exprs)
end
var callsite = self.callsite
if callsite == null then return recv
+ if callsite.is_broken then return null
var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
var res2 = v.compile_callsite(callsite, args)
# Here we load an process all modules passed on the command line
var mmodules = modelbuilder.parse(arguments)
-if mmodules.is_empty then return
+if mmodules.is_empty then
+ toolcontext.check_errors
+ toolcontext.errors_info
+ if toolcontext.error_count > 0 then exit(1) else exit(0)
+end
+
modelbuilder.run_phases
for mmodule in mmodules do