redef class ITypeCheck
redef fun dump_intern(icd)
do
- return "CHECKTYPE {icd.register(expr)} isa {stype}"
+ return "CHECKTYPE {icd.register(expr2)} isa {stype}"
end
end
# FIXME handle formaltypes
v.add_location(location)
var g = stype.local_class.global
- var recv = v.register(expr)
+ var recv = v.register(expr2)
var w = new_result(v)
w.add("TAG_Bool(")
- if expr.stype.is_nullable then
+ if expr2.stype.is_nullable then
if stype.is_nullable then
w.add("(")
w.add(recv)
w.add("==NIT_NULL) || ")
- else if stype.as_nullable == expr.stype then
+ else if stype.as_nullable == expr2.stype then
w.add(recv)
w.add("!=NIT_NULL)")
return
end
# A type check
-# expr is the expression checked
+# expr1 is the type reciever (self)
+# expr2 is the expression checked
class ITypeCheck
- super ICode1
+ super ICode2
# The static type checkes to
readable var _stype: MMType
- init(e: IRegister, t: MMType)
+ init(e1, e2: IRegister, t: MMType)
do
- super(e)
+ super(e1, e2)
_stype = t
end
# Add a type cast (ITypeCheck + IAbort) in the current icode sequence
fun add_type_cast(e: IRegister, stype: MMType)
do
- var c = expr(new ITypeCheck(e, stype), mmmodule.type_bool)
+ var c = expr(new ITypeCheck(iroutine.params.first, e, stype), mmmodule.type_bool)
var iif = new IIf(c)
stmt(iif)
var old_seq = seq
redef class ITypeCheck
redef fun inner_dup_with(d)
do
- return new ITypeCheck(d.dup_ireg(expr), stype)
+ return new ITypeCheck(d.dup_ireg(expr1), d.dup_ireg(expr2), stype)
end
end
# The method associated to the iroutine (if any)
readable var _method: nullable MMMethod
+ # The register of self (if any)
+ var selfreg: nullable IRegister writable
+
init(visitor: AbsSyntaxVisitor, r: IRoutine, m: nullable MMMethod)
do
super(visitor.mmmodule, r)
var params = v.iroutine.params.to_a
var selfreg = v.variable(self_var)
v.stmt(new IMove(selfreg, params[0]))
+ v.selfreg = selfreg
params.shift
var orig_meth: MMLocalProperty = method.global.intro
if n_block != null then
v.generate_stmt(n_block)
end
+ v.selfreg = null
end
end
redef fun generate_icode(v)
do
var e = v.generate_expr(n_expr)
- return v.expr(new ITypeCheck(e, n_type.stype), stype)
+ return v.expr(new ITypeCheck(v.selfreg.as(not null), e, n_type.stype), stype)
end
end