if initprop != null then
interpreter.send(initprop, [mainobj])
end
- interpreter.check_init_instance(mainobj)
var mainprop = mainmodule.try_get_primitive_method("main", sys_type.mclass)
if mainprop != null then
interpreter.send(mainprop, [mainobj])
var res = new MutableInstance(mtype)
self.init_instance(res)
self.send(self.force_get_primitive_method("with_native", mtype), [res, nat, self.int_instance(values.length)])
- self.check_init_instance(res)
return res
end
# Store known method, used to trace methods as thez are reached
var discover_call_trace: Set[MMethodDef] = new HashSet[MMethodDef]
- # Execute `mpropdef` for a `args` (where `args[0]` is the receiver).
- # Return a falue if `mpropdef` is a function, or null if it is a procedure.
- # The call is direct/static. There is no message-seding/late-binding.
- fun call(mpropdef: MMethodDef, args: Array[Instance]): nullable Instance
+ # Common code for calls to injected methods and normal methods
+ fun call_commons(mpropdef: MMethodDef, args: Array[Instance]): Array[Instance]
do
var vararg_rank = mpropdef.msignature.vararg_rank
if vararg_rank >= 0 then
args.add(rawargs[i+1])
end
end
+ return args
+ end
+
+ # Execute `mpropdef` for a `args` (where `args[0]` is the receiver).
+ # Return a falue if `mpropdef` is a function, or null if it is a procedure.
+ # The call is direct/static. There is no message-seding/late-binding.
+ fun call(mpropdef: MMethodDef, args: Array[Instance]): nullable Instance
+ do
+ args = call_commons(mpropdef, args)
return call_without_varargs(mpropdef, args)
end
end
end
- # Execute `mproperty` for a `args` (where `args[0]` is the receiver).
- # Return a falue if `mproperty` is a function, or null if it is a procedure.
- # The call is polimotphic. There is a message-seding/late-bindng according to te receiver (args[0]).
- fun send(mproperty: MMethod, args: Array[Instance]): nullable Instance
+ # Common code for runtime injected calls and normal calls
+ fun send_commons(mproperty: MMethod, args: Array[Instance], mtype: MType): nullable Instance
do
- var recv = args.first
- var mtype = recv.mtype
if mtype isa MNullType then
if mproperty.name == "==" then
return self.bool_instance(args[0] == args[1])
end
#fatal("Reciever is null. {mproperty}. {args.join(" ")} {self.frame.current_node.class_name}")
fatal("Reciever is null")
- abort
end
+ return null
+ end
+
+ # Execute `mproperty` for a `args` (where `args[0]` is the receiver).
+ # Return a falue if `mproperty` is a function, or null if it is a procedure.
+ # The call is polimotphic. There is a message-seding/late-bindng according to te receiver (args[0]).
+ fun send(mproperty: MMethod, args: Array[Instance]): nullable Instance
+ do
+ var recv = args.first
+ var mtype = recv.mtype
+ var ret = send_commons(mproperty, args, mtype)
+ if ret != null then return ret
var propdef = mproperty.lookup_first_definition(self.mainmodule, mtype)
return self.call(propdef, args)
end
end
end
- # Check that non nullable attributes of `recv` are correctly initialized.
- # This function is used as the last instruction of a new
- fun check_init_instance(recv: Instance)
- do
- if not recv isa MutableInstance then return
- for npropdef in collect_attr_propdef(recv.mtype) do
- if npropdef.n_expr == null then
- # Force read to check the initialization
- self.read_attribute(npropdef.mpropdef.mproperty, recv)
- end
- end
- end
-
# This function determine the correct type according the reciever of the current definition (self).
fun unanchor_type(mtype: MType): MType
do
fun is_true: Bool do abort
# Return true if `self` IS `o` (using the Nit semantic of is)
- fun eq_is(o: Instance): Bool do return self is o
+ fun eq_is(o: Instance): Bool do return self.is_same_instance(o)
# Human readable object identity "Type#number"
redef fun to_s do return "{mtype}"
redef fun eq_is(o)
do
if not o isa PrimitiveInstance[Object] then return false
- return self.val is o.val
+ return self.val.is_same_instance(o.val)
end
redef fun to_s do return "{mtype}#{val.object_id}({val})"
end
redef class AConcreteMethPropdef
+
redef fun call(v, mpropdef, args)
do
var f = new Frame(self, self.mpropdef.as(not null), args)
+ call_commons(v, mpropdef, args, f)
+ v.frames.shift
+ if v.returnmark == f then
+ v.returnmark = null
+ var res = v.escapevalue
+ v.escapevalue = null
+ return res
+ end
+ return null
+ end
+
+ private fun call_commons(v: NaiveInterpreter, mpropdef: MMethodDef, args: Array[Instance], f: Frame)
+ do
for i in [0..mpropdef.msignature.arity[ do
var variable = self.n_signature.n_params[i].variable
assert variable != null
end
v.stmt(self.n_block)
- v.frames.shift
- if v.returnmark == f then
- v.returnmark = null
- var res = v.escapevalue
- v.escapevalue = null
- return res
- end
- return null
end
end
return v.bool_instance(args[0] != args[1])
else if pname == "is_same_type" then
return v.bool_instance(args[0].mtype == args[1].mtype)
+ else if pname == "is_same_instance" then
+ return v.bool_instance(args[1] != null and args[0].eq_is(args[1]))
else if pname == "exit" then
exit(args[1].to_i)
abort
else if pname == "file_chdir" then
recvval.to_s.chdir
return null
+ else if pname == "file_realpath" then
+ return v.native_string_instance(recvval.to_s.realpath)
else if pname == "get_environ" then
var txt = recvval.to_s.environ
return v.native_string_instance(txt)
end
end
-redef class AEeExpr
- redef fun expr(v)
- do
- var i = v.expr(self.n_expr)
- if i == null then return null
- var i2 = v.expr(self.n_expr2)
- if i2 == null then return null
- return v.bool_instance(i.eq_is(i2))
- end
-end
-
redef class AIntExpr
redef fun expr(v)
do
var res = new MutableInstance(mtype)
v.init_instance(res)
v.send(v.force_get_primitive_method("init", mtype), [res, e1, e2])
- v.check_init_instance(res)
return res
end
end
var res = new MutableInstance(mtype)
v.init_instance(res)
v.send(v.force_get_primitive_method("without_last", mtype), [res, e1, e2])
- v.check_init_instance(res)
return res
end
end
#self.debug("got {res2} from {mproperty}. drop {recv}")
return res2
end
- v.check_init_instance(recv)
return recv
end
end