v.add("signal(SIGINT, sig_handler);")
v.add("signal(SIGTERM, sig_handler);")
v.add("signal(SIGSEGV, sig_handler);")
- v.add("signal(SIGPIPE, sig_handler);")
+ v.add("signal(SIGPIPE, SIG_IGN);")
v.add("glob_argc = argc; glob_argv = argv;")
v.add("initialize_gc_option();")
if nexpr == null then return
if nexpr.mtype == null and not nexpr.is_typed then
# Untyped expression.
- # Might mean dead code
- # So just return
+ # Might mean dead code or invalid code
+ # so aborts
+ add_abort("FATAL: bad statement executed.")
return
end
# `mtype` is the expected return type, pass null if no specific type is expected.
fun expr(nexpr: AExpr, mtype: nullable MType): RuntimeVariable
do
- if nexpr.mtype == null then
+ var old = self.current_node
+ self.current_node = nexpr
+
+ var res = null
+ if nexpr.mtype != null then
+ res = nexpr.expr(self)
+ end
+
+ if res == null then
# Untyped expression.
- # Might mean dead code
- # so return a placebo result
+ # Might mean dead code or invalid code.
+ # so aborts
+ add_abort("FATAL: bad expression executed.")
+ # and return a placebo result to please the C compiler
if mtype == null then mtype = compiler.mainmodule.object_type
- return new_var(mtype)
+ res = new_var(mtype)
+
+ self.current_node = old
+ return res
end
- var old = self.current_node
- self.current_node = nexpr
- var res = nexpr.expr(self).as(not null)
+
if mtype != null then
mtype = self.anchor(mtype)
res = self.autobox(res, mtype)
else if mclass.name == "Byte" then
return "unsigned char"
else if mclass.name == "NativeString" then
- return "unsigned char*"
+ return "char*"
else if mclass.name == "NativeArray" then
return "val*"
else
end
else if cname == "NativeString" then
if pname == "[]" then
- v.ret(v.new_expr("(uint32_t){arguments[0]}[{arguments[1]}]", ret.as(not null)))
+ v.ret(v.new_expr("(unsigned char)((int){arguments[0]}[{arguments[1]}])", ret.as(not null)))
return true
else if pname == "[]=" then
v.add("{arguments[0]}[{arguments[1]}]=(unsigned char){arguments[2]};")
v.ret(v.new_expr("{arguments[0]} + {arguments[1]}", ret.as(not null)))
return true
else if pname == "new" then
- v.ret(v.new_expr("(unsigned char*)nit_alloc({arguments[1]})", ret.as(not null)))
+ v.ret(v.new_expr("(char*)nit_alloc({arguments[1]})", ret.as(not null)))
return true
end
else if cname == "NativeArray" then
v.ret(v.new_expr("glob_sys", ret.as(not null)))
return true
else if pname == "calloc_string" then
- v.ret(v.new_expr("(unsigned char*)nit_alloc({arguments[1]})", ret.as(not null)))
+ v.ret(v.new_expr("(char*)nit_alloc({arguments[1]})", ret.as(not null)))
return true
else if pname == "calloc_array" then
v.calloc_array(ret.as(not null), arguments)
var res
if is_lazy then
var set
- var ret = self.mpropdef.static_mtype
+ var ret = self.mtype
var useiset = not ret.is_c_primitive and not ret isa MNullableType
var guard = self.mlazypropdef.mproperty
if useiset 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 ret = self.mtype
var useiset = not ret.is_c_primitive and not ret isa MNullableType
if not useiset then
v.write_attribute(self.mlazypropdef.mproperty, arguments.first, v.bool_instance(true))
var oldnode = v.current_node
v.current_node = self
var old_frame = v.frame
- var frame = new StaticFrame(v, self.mpropdef.as(not null), recv.mcasttype.undecorate.as(MClassType), [recv])
+ var frame = new StaticFrame(v, self.mreadpropdef.as(not null), recv.mcasttype.undecorate.as(MClassType), [recv])
v.frame = frame
var value
- var mtype = self.mpropdef.static_mtype
+ var mtype = self.mtype
assert mtype != null
var nexpr = self.n_expr
redef fun expr(v)
do
var i = v.expr(self.n_expr, null)
- return v.type_test(i, self.cast_type.as(not null), "isa")
+ var cast_type = self.cast_type
+ if cast_type == null then return null # no-no on broken node
+ return v.type_test(i, cast_type, "isa")
end
end