Return a possible value
NOTE: Do not call this method directly, but use v.expr
This method is here to be implemented by subclasses.
# Evaluate the node as a possible expression.
# Return a possible value
# NOTE: Do not call this method directly, but use `v.expr`
# This method is here to be implemented by subclasses.
protected fun expr(v: NaiveInterpreter): nullable Instance
do
fatal(v, "NOT YET IMPLEMENTED expr {class_name}")
abort
end
src/interpreter/naive_interpreter.nit:1670,2--1678,4
redef fun expr(v)
do
if value isa Int then return v.int_instance(value.as(Int))
if value isa Byte then return v.byte_instance(value.as(Byte))
if value isa Int8 then return v.int8_instance(value.as(Int8))
if value isa Int16 then return v.int16_instance(value.as(Int16))
if value isa UInt16 then return v.uint16_instance(value.as(UInt16))
if value isa Int32 then return v.int32_instance(value.as(Int32))
if value isa UInt32 then return v.uint32_instance(value.as(UInt32))
return null
end
src/interpreter/naive_interpreter.nit:2033,2--2043,4
redef fun expr(v)
do
var val = new Array[Instance]
var old_comprehension = v.frame.comprehension
v.frame.comprehension = val
for nexpr in self.n_exprs do
if nexpr isa AForExpr then
v.stmt(nexpr)
else
var i = v.expr(nexpr)
if i == null then return null
val.add(i)
end
end
v.frame.comprehension = old_comprehension
var mtype = v.unanchor_type(self.mtype.as(not null)).as(MClassType)
var elttype = mtype.arguments.first
return v.array_instance(val, elttype)
end
src/interpreter/naive_interpreter.nit:2064,2--2082,4
redef fun expr(v)
do
return v.null_instance
end
src/interpreter/naive_interpreter.nit:2215,2--2218,4
redef fun expr(v)
do
var recv = v.expr(self.n_expr)
if recv == null then return null
# Safe call shortcut if recv is null
if is_safe and recv.is_null then
return recv
end
var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.raw_arguments)
if args == null then return null
var res = v.callsite(callsite, args)
return res
end
src/interpreter/naive_interpreter.nit:2279,2--2293,4
redef fun expr(v)
do
var recv = v.frame.arguments.first
var callsite = self.callsite
if callsite != null then
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])
end
else
args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
if args == null then return null
end
# Super init call
var res = v.callsite(callsite, args)
return res
end
# Standard call-next-method
var mpropdef = self.mpropdef
mpropdef = mpropdef.lookup_next_definition(v.mainmodule, recv.mtype)
var args
if self.n_args.n_exprs.is_empty then
args = v.frame.arguments
else
args = v.varargize(mpropdef, signaturemap, recv, self.n_args.n_exprs)
if args == null then return null
end
var res = v.call(mpropdef, args)
return res
end
src/interpreter/naive_interpreter.nit:2334,2--2371,4
redef fun expr(v)
do
var mtype = v.unanchor_type(self.recvtype.as(not null))
var recv: Instance = new MutableInstance(mtype)
v.init_instance(recv)
var callsite = self.callsite
if callsite == null then return recv
var args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
if args == null then return null
var res2 = v.callsite(callsite, args)
if res2 != null then
#self.debug("got {res2} from {mproperty}. drop {recv}")
return res2
end
return recv
end
src/interpreter/naive_interpreter.nit:2375,2--2391,4
redef fun expr(v)
do
var e1 = v.expr(self.n_expr)
if e1 == null then return null
var e2 = v.expr(self.n_expr2)
if e2 == null then return null
var mtype = v.unanchor_type(self.mtype.as(not null))
var res = new MutableInstance(mtype)
v.init_instance(res)
v.callsite(init_callsite, [res, e1, e2])
return res
end
src/interpreter/naive_interpreter.nit:2171,2--2182,4
redef fun expr(v)
do
var e1 = v.expr(self.n_expr)
if e1 == null then return null
var e2 = v.expr(self.n_expr2)
if e2 == null then return null
var mtype = v.unanchor_type(self.mtype.as(not null))
var res = new MutableInstance(mtype)
v.init_instance(res)
v.callsite(init_callsite, [res, e1, e2])
return res
end
src/interpreter/naive_interpreter.nit:2186,2--2197,4
redef fun expr(v)
do
return v.bool_instance(true)
end
src/interpreter/naive_interpreter.nit:2201,2--2204,4
redef fun expr(v)
do
return v.bool_instance(false)
end
src/interpreter/naive_interpreter.nit:2208,2--2211,4
redef fun expr(v)
do
# TODO : a workaround for now
if not v isa VirtualMachine then return super
var recv = v.expr(self.n_expr)
if recv == null then return null
optimize(v, recv.mtype, self.cast_type.as(not null))
var mtype = v.unanchor_type(self.cast_type.as(not null))
# If this test can be optimized, directly call appropriate subtyping methods
if status == 1 and recv.mtype isa MClassType then
# Direct access
return v.bool_instance(v.inter_is_subtype_sst(id, position, recv.mtype.as(MClassType).mclass.vtable.internal_vtable))
else if status == 2 and recv.mtype isa MClassType then
# Perfect hashing
return v.bool_instance(v.inter_is_subtype_ph(id, recv.vtable.mask, recv.mtype.as(MClassType).mclass.vtable.internal_vtable))
else
# Use the slow path (default)
return v.bool_instance(v.is_subtype(recv.mtype, mtype))
end
end
src/vm/vm_optimizations.nit:206,2--228,4
redef fun expr(v)
do
var i = v.expr(self.n_expr)
if i == null then return null
var mtype = self.mtype.as(not null)
var amtype = v.unanchor_type(mtype)
if not v.is_subtype(i.mtype, amtype) then
fatal(v, "Cast failed. Expected `{amtype}`, got `{i.mtype}`")
end
return i
end
src/interpreter/naive_interpreter.nit:2232,2--2242,4
redef fun expr(v)
do
# TODO : a workaround for now
if not v isa VirtualMachine then return super
var recv = v.expr(self.n_expr)
if recv == null then return null
optimize(v, recv.mtype, self.mtype.as(not null))
var mtype = self.mtype.as(not null)
var amtype = v.unanchor_type(mtype)
var res: Bool
if status == 1 and recv.mtype isa MClassType then
# Direct access
res = v.inter_is_subtype_sst(id, position, recv.mtype.as(MClassType).mclass.vtable.internal_vtable)
else if status == 2 and recv.mtype isa MClassType then
# Perfect hashing
res = v.inter_is_subtype_ph(id, recv.vtable.mask, recv.mtype.as(MClassType).mclass.vtable.internal_vtable)
else
# Use the slow path (default)
res = v.is_subtype(recv.mtype, amtype)
end
if not res then
fatal(v, "Cast failed. Expected `{amtype}`, got `{recv.mtype}`")
end
return recv
end
src/vm/vm_optimizations.nit:271,2--300,4
redef fun expr(v)
do
# TODO : a workaround for now
if not v isa VirtualMachine then return super
var recv = v.expr(self.n_expr)
if recv == null then return null
if recv.mtype isa MNullType then fatal(v, "Receiver is null")
var mproperty = self.mproperty.as(not null)
assert recv isa MutableInstance
if status == 0 then optimize(mproperty, recv)
var i: Instance
if status == 1 then
# SST
i = v.read_attribute_sst(recv.internal_attributes, offset)
else
# PH
i = v.read_attribute_ph(recv.internal_attributes, recv.vtable.internal_vtable, recv.vtable.mask, id, offset)
end
# If we get a `MInit` value, throw an error
if i == v.initialization_value then
v.fatal("Uninitialized attribute {mproperty.name}")
abort
end
#TODO : we need recompilations here
status = 0
return i
end
src/vm/vm_optimizations.nit:91,2--123,4
redef fun expr(v) do return v.string_instance(value)
src/interpreter/naive_interpreter.nit:2123,2--53
redef fun expr(v)
do
var array = new Array[Instance]
for nexpr in n_exprs do
var i = v.expr(nexpr)
if i == null then return null
array.add(i)
end
var i = v.array_instance(array, v.mainmodule.object_type)
var res = v.send(v.force_get_primitive_method("plain_to_s", i.mtype), [i])
assert res != null
if is_re then res = make_re(v, res)
return res
end
src/interpreter/naive_interpreter.nit:2154,2--2167,4
redef fun expr(v)
do
var recv = v.expr(self.n_expr)
if recv == null then return null
var mtype = self.mtype
assert mtype != null
# In case we are in generic class where formal parameter can not
# be resolved.
var mtype2 = v.unanchor_type(mtype)
var inst = new CallrefInstance(mtype2, recv, callsite.as(not null))
return inst
end
src/interpreter/naive_interpreter.nit:2297,2--2308,4
redef fun expr(v) do
var s = v.string_instance(value)
if is_string then return s
if is_bytestring then
var ns = v.c_string_instance_from_ns(bytes.items, bytes.length)
var ln = v.int_instance(bytes.length)
var prop = to_bytes_with_copy
assert prop != null
var res = v.callsite(prop, [ns, ln])
if res == null then
print "Cannot call property `to_bytes` on {self}"
abort
end
s = res
else if is_re then
var res = make_re(v, s)
assert res != null
s = res
else
print "Unimplemented prefix or suffix for {self}"
abort
end
return s
end
src/interpreter/naive_interpreter.nit:2127,2--2150,4