nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
syntax: 'meth' -> 'fun', 'attr' -> 'var'
[nit.git]
/
src
/
compiling
/
compiling_methods.nit
diff --git
a/src/compiling/compiling_methods.nit
b/src/compiling/compiling_methods.nit
index
1c6cee0
..
ef6f9e1
100644
(file)
--- a/
src/compiling/compiling_methods.nit
+++ b/
src/compiling/compiling_methods.nit
@@
-22,7
+22,7
@@
private import syntax
redef class CompilerVisitor
# Compile a statment node
redef class CompilerVisitor
# Compile a statment node
- meth compile_stmt(n: PExpr)
+ fun compile_stmt(n: nullable PExpr)
do
if n == null then return
#add_instr("/* Compile stmt {n.locate} */")
do
if n == null then return
#add_instr("/* Compile stmt {n.locate} */")
@@
-33,7
+33,7
@@
redef class CompilerVisitor
end
# Compile is expression node
end
# Compile is expression node
- meth compile_expr(n: PExpr): String
+ fun compile_expr(n: PExpr): String
do
#add_instr("/* Compile expr {n.locate} */")
var i = cfc._variable_index
do
#add_instr("/* Compile expr {n.locate} */")
var i = cfc._variable_index
@@
-48,7
+48,7
@@
redef class CompilerVisitor
end
# Ensure that a c expression is a var
end
# Ensure that a c expression is a var
- meth ensure_var(s: String, comment: String): String
+ fun ensure_var(s: String, comment: String): String
do
if cfc.is_valid_variable(s) then
add_instr("/* Ensure var {s}: {comment}*/")
do
if cfc.is_valid_variable(s) then
add_instr("/* Ensure var {s}: {comment}*/")
@@
-60,22
+60,22
@@
redef class CompilerVisitor
end
# Add a assignment between a variable and an expression
end
# Add a assignment between a variable and an expression
- meth add_assignment(v: String, s: String)
+ fun add_assignment(v: String, s: String)
do
if v != s then
add_instr("{v} = {s};")
end
end
do
if v != s then
add_instr("{v} = {s};")
end
end
- readable writable attr _cfc: CFunctionContext
+ readable writable var _cfc: nullable CFunctionContext
- readable writable attr _nmc: NitMethodContext
+ readable writable var _nmc: nullable NitMethodContext
# C outputs written outside the current C function.
# C outputs written outside the current C function.
- readable writable attr _out_contexts: Array[CContext] = new Array[CContext]
+ readable writable var _out_contexts: Array[CContext] = new Array[CContext]
# Generate an fprintf to display an error location
# Generate an fprintf to display an error location
- meth printf_locate_error(node: PNode): String
+ fun printf_locate_error(node: PNode): String
do
var s = new Buffer.from("fprintf(stderr, \"")
if nmc != null then s.append(" in %s")
do
var s = new Buffer.from("fprintf(stderr, \"")
if nmc != null then s.append(" in %s")
@@
-85,7
+85,7
@@
redef class CompilerVisitor
return s.to_s
end
return s.to_s
end
- meth invoke_super_init_calls_after(start_prop: MMMethod)
+ fun invoke_super_init_calls_after(start_prop: nullable MMMethod)
do
var n = nmc.method.node
assert n isa AConcreteInitPropdef
do
var n = nmc.method.node
assert n isa AConcreteInitPropdef
@@
-107,7
+107,7
@@
redef class CompilerVisitor
end
j += 1
end
end
j += 1
end
- var stop_prop: MMMethod = null
+ var stop_prop: nullable MMMethod = null
if j < n.explicit_super_init_calls.length then
stop_prop = n.explicit_super_init_calls[j]
end
if j < n.explicit_super_init_calls.length then
stop_prop = n.explicit_super_init_calls[j]
end
@@
-120,7
+120,7
@@
redef class CompilerVisitor
if p.signature.arity == 0 then
cargs.add(cfc.varname(nmc.method_params[0]))
else
if p.signature.arity == 0 then
cargs.add(cfc.varname(nmc.method_params[0]))
else
- for va in nmc.method_params do
+ for va in nmc.method_params.as(not null) do
cargs.add(cfc.varname(va))
end
end
cargs.add(cfc.varname(va))
end
end
@@
-140,22
+140,22
@@
end
# A C function currently written
class CFunctionContext
# A C function currently written
class CFunctionContext
- readable attr _visitor: CompilerVisitor
+ readable var _visitor: CompilerVisitor
# Next available variable number
# Next available variable number
- attr _variable_index: Int = 0
+ var _variable_index: Int = 0
# Total number of variable
# Total number of variable
- attr _variable_index_max: Int = 0
+ var _variable_index_max: Int = 0
# Association between nit variable and the corrsponding c variable index
# Association between nit variable and the corrsponding c variable index
- attr _varindexes: Map[Variable, Int] = new HashMap[Variable, Int]
+ var _varindexes: Map[Variable, Int] = new HashMap[Variable, Int]
# Are we currenlty in a closure definition?
# Are we currenlty in a closure definition?
- readable writable attr _closure: NitMethodContext = null
+ readable writable var _closure: nullable NitMethodContext = null
# Return the cvariable of a Nit variable
# Return the cvariable of a Nit variable
- meth varname(v: Variable): String
+ fun varname(v: Variable): String
do
if v isa ClosureVariable then
return closure_variable(_varindexes[v])
do
if v isa ClosureVariable then
return closure_variable(_varindexes[v])
@@
-165,7
+165,7
@@
class CFunctionContext
end
# Return the next available variable
end
# Return the next available variable
- meth get_var(comment: String): String
+ fun get_var(comment: nullable String): String
do
var v = variable(_variable_index)
_variable_index = _variable_index + 1
do
var v = variable(_variable_index)
_variable_index = _variable_index + 1
@@
-178,7
+178,7
@@
class CFunctionContext
return v
end
return v
end
- meth register_variable(v: Variable): String
+ fun register_variable(v: Variable): String
do
_varindexes[v] = _variable_index
var s = get_var("Local variable")
do
_varindexes[v] = _variable_index
var s = get_var("Local variable")
@@
-186,9
+186,9
@@
class CFunctionContext
end
# Next available closure variable number
end
# Next available closure variable number
- attr _closurevariable_index: Int = 0
+ var _closurevariable_index: Int = 0
- meth register_closurevariable(v: ClosureVariable): String
+ fun register_closurevariable(v: ClosureVariable): String
do
var s = "closurevariable[{_closurevariable_index}]"
_varindexes[v] = _closurevariable_index
do
var s = "closurevariable[{_closurevariable_index}]"
_varindexes[v] = _closurevariable_index
@@
-201,7
+201,7
@@
class CFunctionContext
end
# Return the ith cvariable
end
# Return the ith cvariable
- protected meth variable(i: Int): String
+ protected fun variable(i: Int): String
do
if closure != null then
var vn = once new Array[String]
do
if closure != null then
var vn = once new Array[String]
@@
-223,7
+223,7
@@
class CFunctionContext
end
# Return the ith closurevariable
end
# Return the ith closurevariable
- protected meth closure_variable(i: Int): String
+ protected fun closure_variable(i: Int): String
do
if closure != null then
return "(closctx->closurevariable[{i}])"
do
if closure != null then
return "(closctx->closurevariable[{i}])"
@@
-233,7
+233,7
@@
class CFunctionContext
end
# Is s a valid variable
end
# Is s a valid variable
- protected meth is_valid_variable(s: String): Bool
+ protected fun is_valid_variable(s: String): Bool
do
for i in [0.._variable_index[ do
if s == variable(i) then return true
do
for i in [0.._variable_index[ do
if s == variable(i) then return true
@@
-242,7
+242,7
@@
class CFunctionContext
end
# Mark the variable available
end
# Mark the variable available
- meth free_var(v: String)
+ fun free_var(v: String)
do
# FIXME: So ugly..
if v == variable(_variable_index-1) then
do
# FIXME: So ugly..
if v == variable(_variable_index-1) then
@@
-252,7
+252,7
@@
class CFunctionContext
# Generate the local variable declarations
# To use at the end of the C function once all variables are known
# Generate the local variable declarations
# To use at the end of the C function once all variables are known
- meth generate_var_decls
+ fun generate_var_decls
do
if _variable_index_max > 0 then
visitor.add_decl("val_t variable[{_variable_index_max}];")
do
if _variable_index_max > 0 then
visitor.add_decl("val_t variable[{_variable_index_max}];")
@@
-272,30
+272,30
@@
end
# A Nit method currenlty compiled
class NitMethodContext
# Current method compiled
# A Nit method currenlty compiled
class NitMethodContext
# Current method compiled
- readable attr _method: MMSrcMethod
+ readable var _method: nullable MMSrcMethod
# Association between parameters and the corresponding variables
# Association between parameters and the corresponding variables
- readable writable attr _method_params: Array[ParamVariable]
+ readable writable var _method_params: nullable Array[ParamVariable]
# Where a nit return must branch
# Where a nit return must branch
- readable writable attr _return_label: String
-
+ readable writable var _return_label: nullable String
+
# Where a nit break must branch
# Where a nit break must branch
- readable writable attr _break_label: String
-
+ readable writable var _break_label: nullable String
+
# Where a nit continue must branch
# Where a nit continue must branch
- readable writable attr _continue_label: String
+ readable writable var _continue_label: nullable String
# Variable where a functionnal nit return must store its value
# Variable where a functionnal nit return must store its value
- readable writable attr _return_value: String
+ readable writable var _return_value: nullable String
# Variable where a functionnal nit break must store its value
# Variable where a functionnal nit break must store its value
- readable writable attr _break_value: String
+ readable writable var _break_value: nullable String
# Variable where a functionnal nit continue must store its value
# Variable where a functionnal nit continue must store its value
- readable writable attr _continue_value: String
+ readable writable var _continue_value: nullable String
- init(method: MMSrcMethod)
+ init(method: nullable MMSrcMethod)
do
_method = method
end
do
_method = method
end
@@
-304,13
+304,13
@@
end
###############################################################################
redef class ClosureVariable
###############################################################################
redef class ClosureVariable
- readable writable attr _ctypename: String
+ readable writable var _ctypename: nullable String
end
redef class MMMethod
# Compile as an expression.
# require that signature.return_type != null
end
redef class MMMethod
# Compile as an expression.
# require that signature.return_type != null
- meth compile_expr_call(v: CompilerVisitor, cargs: Array[String]): String
+ fun compile_expr_call(v: CompilerVisitor, cargs: Array[String]): String
do
assert signature.return_type != null
var s = intern_compile_call(v, cargs)
do
assert signature.return_type != null
var s = intern_compile_call(v, cargs)
@@
-320,7
+320,7
@@
redef class MMMethod
# Compile as a statement.
# require that signature.return_type == null
# Compile as a statement.
# require that signature.return_type == null
- meth compile_stmt_call(v: CompilerVisitor, cargs: Array[String])
+ fun compile_stmt_call(v: CompilerVisitor, cargs: Array[String])
do
assert signature.return_type == null
var s = intern_compile_call(v, cargs)
do
assert signature.return_type == null
var s = intern_compile_call(v, cargs)
@@
-331,7
+331,7
@@
redef class MMMethod
# Most calls are compiled with a table access,
# primitive calles are inlined
# == and != are guarded and possibly inlined
# Most calls are compiled with a table access,
# primitive calles are inlined
# == and != are guarded and possibly inlined
- private meth intern_compile_call(v: CompilerVisitor, cargs: Array[String]): String
+ private fun intern_compile_call(v: CompilerVisitor, cargs: Array[String]): nullable String
do
var i = self
if i isa MMSrcMethod then
do
var i = self
if i isa MMSrcMethod then
@@
-373,9
+373,9
@@
redef class MMMethod
end
# Compile a call on self for given arguments and given closures
end
# Compile a call on self for given arguments and given closures
- meth compile_call_and_closures(v: CompilerVisitor, cargs: Array[String], clos_defs: Array[PClosureDef]): String
+ fun compile_call_and_closures(v: CompilerVisitor, cargs: Array[String], clos_defs: nullable Array[PClosureDef]): nullable String
do
do
- var ve: String = null
+ var ve: String
var arity = 0
if clos_defs != null then arity = clos_defs.length
var arity = 0
if clos_defs != null then arity = clos_defs.length
@@
-433,13
+433,13
@@
redef class MMMethod
end
# Compile a call as constructor with given args
end
# Compile a call as constructor with given args
- meth compile_constructor_call(v: CompilerVisitor, recvtype: MMType, cargs: Array[String]): String
+ fun compile_constructor_call(v: CompilerVisitor, recvtype: MMType, cargs: Array[String]): String
do
return "NEW_{recvtype.local_class}_{global.intro.cname}({cargs.join(", ")}) /*new {recvtype}*/"
end
# Compile a call as call-next-method on self with given args
do
return "NEW_{recvtype.local_class}_{global.intro.cname}({cargs.join(", ")}) /*new {recvtype}*/"
end
# Compile a call as call-next-method on self with given args
- meth compile_super_call(v: CompilerVisitor, cargs: Array[String]): String
+ fun compile_super_call(v: CompilerVisitor, cargs: Array[String]): String
do
var m = "{super_meth_call}({cargs[0]})"
var vcall = "{m}({cargs.join(", ")}) /*super {local_class}::{name}*/"
do
var m = "{super_meth_call}({cargs[0]})"
var vcall = "{m}({cargs.join(", ")}) /*super {local_class}::{name}*/"
@@
-447,7
+447,7
@@
redef class MMMethod
end
# Cname of the i-th closure C struct type
end
# Cname of the i-th closure C struct type
- protected meth closure_cname(i: Int): String
+ protected fun closure_cname(i: Int): String
do
return "FWBT_{cname}_{i}"
end
do
return "FWBT_{cname}_{i}"
end
@@
-455,13
+455,24
@@
end
redef class MMAttribute
# Compile a read acces on selffor a given reciever.
redef class MMAttribute
# Compile a read acces on selffor a given reciever.
- meth compile_read_access(v: CompilerVisitor, recv: String): String
+ fun compile_isset(v: CompilerVisitor, n: PNode, recv: String): String
+ do
+ return "TAG_Bool({global.attr_access}({recv})!=NIT_NULL) /* isset {local_class}::{name}*/"
+ end
+
+ # Compile a read acces on selffor a given reciever.
+ fun compile_read_access(v: CompilerVisitor, n: PNode, recv: String): String
do
do
- return "{global.attr_access}({recv}) /*{local_class}::{name}*/"
+ var res = "{global.attr_access}({recv}) /*{local_class}::{name}*/"
+ if not signature.return_type.is_nullable then
+ res = v.ensure_var(res, "{local_class}::{name}")
+ v.add_instr("if ({res} == NIT_NULL) \{ fprintf(stderr, \"Uninitialized attribute %s\", \"{name}\"); {v.printf_locate_error(n)} nit_exit(1); } /* implicit isset */;")
+ end
+ return res
end
# Compile a write acces on selffor a given reciever.
end
# Compile a write acces on selffor a given reciever.
- meth compile_write_access(v: CompilerVisitor, recv: String, value: String)
+ fun compile_write_access(v: CompilerVisitor, n: nullable PNode, recv: String, value: String)
do
v.add_instr("{global.attr_access}({recv}) /*{local_class}::{name}*/ = {value};")
end
do
v.add_instr("{global.attr_access}({recv}) /*{local_class}::{name}*/ = {value};")
end
@@
-469,13
+480,13
@@
end
redef class MMLocalProperty
# Compile the property as a C property
redef class MMLocalProperty
# Compile the property as a C property
- meth compile_property_to_c(v: CompilerVisitor) do end
+ fun compile_property_to_c(v: CompilerVisitor) do end
end
redef class MMSrcMethod
# Compile and declare the signature to C
end
redef class MMSrcMethod
# Compile and declare the signature to C
- protected meth decl_csignature(v: CompilerVisitor, args: Array[String]): String
+ protected fun decl_csignature(v: CompilerVisitor, args: Array[String]): String
do
var params = new Array[String]
params.add("val_t {args[0]}")
do
var params = new Array[String]
params.add("val_t {args[0]}")
@@
-518,7
+529,7
@@
redef class MMSrcMethod
return s
end
return s
end
- redef meth compile_property_to_c(v)
+ redef fun compile_property_to_c(v)
do
v.cfc = new CFunctionContext(v)
do
v.cfc = new CFunctionContext(v)
@@
-565,33
+576,33
@@
redef class MMSrcMethod
end
# Compile the method body inline
end
# Compile the method body inline
- meth do_compile_inside(v: CompilerVisitor, params: Array[String]): String is abstract
+ fun do_compile_inside(v: CompilerVisitor, params: Array[String]): nullable String is abstract
end
redef class MMReadImplementationMethod
end
redef class MMReadImplementationMethod
- redef meth do_compile_inside(v, params)
+ redef fun do_compile_inside(v, params)
do
do
- return node.prop.compile_read_access(v, params[0])
+ return node.prop.compile_read_access(v, node, params[0])
end
end
redef class MMWriteImplementationMethod
end
end
redef class MMWriteImplementationMethod
- redef meth do_compile_inside(v, params)
+ redef fun do_compile_inside(v, params)
do
do
- node.prop.compile_write_access(v, params[0], params[1])
+ node.prop.compile_write_access(v, node, params[0], params[1])
return null
end
end
redef class MMMethSrcMethod
return null
end
end
redef class MMMethSrcMethod
- redef meth do_compile_inside(v, params)
+ redef fun do_compile_inside(v, params)
do
return node.do_compile_inside(v, self, params)
end
end
redef class MMImplicitInit
do
return node.do_compile_inside(v, self, params)
end
end
redef class MMImplicitInit
- redef meth do_compile_inside(v, params)
+ redef fun do_compile_inside(v, params)
do
var f = params.length - unassigned_attributes.length
var recv = params.first
do
var f = params.length - unassigned_attributes.length
var recv = params.first
@@
-611,7
+622,7
@@
redef class MMImplicitInit
end
for i in [f..params.length[ do
var attribute = unassigned_attributes[i-f]
end
for i in [f..params.length[ do
var attribute = unassigned_attributes[i-f]
- attribute.compile_write_access(v, recv, params[i])
+ attribute.compile_write_access(v, null, recv, params[i])
end
return null
end
end
return null
end
@@
-620,7
+631,7
@@
end
redef class MMType
# Compile a subtype check to self
# Return a NIT Bool
redef class MMType
# Compile a subtype check to self
# Return a NIT Bool
- meth compile_cast(v: CompilerVisitor, recv: String, fromtype: MMType): String
+ fun compile_cast(v: CompilerVisitor, recv: String, fromtype: MMType): String
do
# Fixme: handle formaltypes
var g = local_class.global
do
# Fixme: handle formaltypes
var g = local_class.global
@@
-639,7
+650,7
@@
redef class MMType
end
# Compile a cast assertion
end
# Compile a cast assertion
- meth compile_type_check(v: CompilerVisitor, recv: String, n: PNode, fromtype: MMType)
+ fun compile_type_check(v: CompilerVisitor, recv: String, n: PNode, fromtype: MMType)
do
# Fixme: handle formaltypes
var g = local_class.global
do
# Fixme: handle formaltypes
var g = local_class.global
@@
-658,7
+669,7
@@
redef class MMType
end
# Compile a notnull cast assertion
end
# Compile a notnull cast assertion
- meth compile_notnull_check(v: CompilerVisitor, recv: String, n: PNode)
+ fun compile_notnull_check(v: CompilerVisitor, recv: String, n: PNode)
do
if is_nullable then
v.add_instr("if (({recv}==NIT_NULL)) \{ fprintf(stderr, \"Cast failled\"); {v.printf_locate_error(n)} nit_exit(1); } /*cast {self}*/;")
do
if is_nullable then
v.add_instr("if (({recv}==NIT_NULL)) \{ fprintf(stderr, \"Cast failled\"); {v.printf_locate_error(n)} nit_exit(1); } /*cast {self}*/;")
@@
-670,21
+681,21
@@
end
redef class AMethPropdef
# Compile the method body
redef class AMethPropdef
# Compile the method body
- meth do_compile_inside(v: CompilerVisitor, method: MMSrcMethod, params: Array[String]): String is abstract
+ fun do_compile_inside(v: CompilerVisitor, method: MMSrcMethod, params: Array[String]): nullable String is abstract
end
redef class PSignature
end
redef class PSignature
- meth compile_parameters(v: CompilerVisitor, orig_sig: MMSignature, params: Array[String]) is abstract
+ fun compile_parameters(v: CompilerVisitor, orig_sig: MMSignature, params: Array[String]) is abstract
end
redef class ASignature
end
redef class ASignature
- redef meth compile_parameters(v: CompilerVisitor, orig_sig: MMSignature, params: Array[String])
+ redef fun compile_parameters(v: CompilerVisitor, orig_sig: MMSignature, params: Array[String])
do
for ap in n_params do
var cname = v.cfc.register_variable(ap.variable)
v.nmc.method_params.add(ap.variable)
var orig_type = orig_sig[ap.position]
do
for ap in n_params do
var cname = v.cfc.register_variable(ap.variable)
v.nmc.method_params.add(ap.variable)
var orig_type = orig_sig[ap.position]
- if not orig_type < ap.variable.stype then
+ if not orig_type < ap.variable.stype.as(not null) then
# FIXME: do not test always
# FIXME: handle formal types
v.add_instr("/* check if p<{ap.variable.stype} with p:{orig_type} */")
# FIXME: do not test always
# FIXME: handle formal types
v.add_instr("/* check if p<{ap.variable.stype} with p:{orig_type} */")
@@
-702,7
+713,7
@@
redef class ASignature
end
redef class AConcreteMethPropdef
end
redef class AConcreteMethPropdef
- redef meth do_compile_inside(v, method, params)
+ redef fun do_compile_inside(v, method, params)
do
var old_nmc = v.nmc
v.nmc = new NitMethodContext(method)
do
var old_nmc = v.nmc
v.nmc = new NitMethodContext(method)
@@
-712,13
+723,13
@@
redef class AConcreteMethPropdef
params.shift
v.nmc.method_params = [self_var]
params.shift
v.nmc.method_params = [self_var]
+ var orig_meth: MMLocalProperty = method.global.intro
+ var orig_sig = orig_meth.signature_for(method.signature.recv)
if n_signature != null then
if n_signature != null then
- var orig_meth: MMLocalProperty = method.global.intro
- var orig_sig = orig_meth.signature_for(method.signature.recv)
n_signature.compile_parameters(v, orig_sig, params)
end
n_signature.compile_parameters(v, orig_sig, params)
end
- var itpos: String = null
+ var itpos: nullable String = null
if self isa AConcreteInitPropdef then
itpos = "VAL2OBJ({selfcname})->vft[{method.local_class.global.init_table_pos_id}].i"
# v.add_instr("printf(\"{method.full_name}: inittable[%d] = %d\\n\", {itpos}, init_table[{itpos}]);")
if self isa AConcreteInitPropdef then
itpos = "VAL2OBJ({selfcname})->vft[{method.local_class.global.init_table_pos_id}].i"
# v.add_instr("printf(\"{method.full_name}: inittable[%d] = %d\\n\", {itpos}, init_table[{itpos}]);")
@@
-736,7
+747,7
@@
redef class AConcreteMethPropdef
v.add_instr("init_table[{itpos}] = 1;")
end
v.add_instr("init_table[{itpos}] = 1;")
end
- var ret: String = null
+ var ret: nullable String = null
if method.signature.return_type != null then
ret = v.nmc.return_value
end
if method.signature.return_type != null then
ret = v.nmc.return_value
end
@@
-747,7
+758,7
@@
redef class AConcreteMethPropdef
end
redef class ADeferredMethPropdef
end
redef class ADeferredMethPropdef
- redef meth do_compile_inside(v, method, params)
+ redef fun do_compile_inside(v, method, params)
do
v.add_instr("fprintf(stderr, \"Deferred method called\");")
v.add_instr(v.printf_locate_error(self))
do
v.add_instr("fprintf(stderr, \"Deferred method called\");")
v.add_instr(v.printf_locate_error(self))
@@
-761,7
+772,7
@@
redef class ADeferredMethPropdef
end
redef class AExternMethPropdef
end
redef class AExternMethPropdef
- redef meth do_compile_inside(v, method, params)
+ redef fun do_compile_inside(v, method, params)
do
var ename = "{method.module.name}_{method.local_class.name}_{method.local_class.name}_{method.name}_{method.signature.arity}"
if n_extern != null then
do
var ename = "{method.module.name}_{method.local_class.name}_{method.local_class.name}_{method.name}_{method.signature.arity}"
if n_extern != null then
@@
-788,11
+799,11
@@
redef class AExternMethPropdef
end
redef class AInternMethPropdef
end
redef class AInternMethPropdef
- redef meth do_compile_inside(v, method, p)
+ redef fun do_compile_inside(v, method, p)
do
var c = method.local_class.name
var n = method.name
do
var c = method.local_class.name
var n = method.name
- var s: String = null
+ var s: nullable String = null
if c == once "Int".to_symbol then
if n == once "object_id".to_symbol then
s = "{p[0]}"
if c == once "Int".to_symbol then
if n == once "object_id".to_symbol then
s = "{p[0]}"
@@
-965,20
+976,20
@@
end
redef class PExpr
# Compile the node as an expression
# Only the visitor should call it
redef class PExpr
# Compile the node as an expression
# Only the visitor should call it
- meth compile_expr(v: CompilerVisitor): String is abstract
+ fun compile_expr(v: CompilerVisitor): String is abstract
# Prepare a call of node as a statement
# Only the visitor should call it
# It's used for local variable managment
# Prepare a call of node as a statement
# Only the visitor should call it
# It's used for local variable managment
- meth prepare_compile_stmt(v: CompilerVisitor) do end
+ fun prepare_compile_stmt(v: CompilerVisitor) do end
# Compile the node as a statement
# Only the visitor should call it
# Compile the node as a statement
# Only the visitor should call it
- meth compile_stmt(v: CompilerVisitor) do printl("Error!")
+ fun compile_stmt(v: CompilerVisitor) do printl("Error!")
end
redef class ABlockExpr
end
redef class ABlockExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
for n in n_expr do
v.compile_stmt(n)
do
for n in n_expr do
v.compile_stmt(n)
@@
-987,29
+998,29
@@
redef class ABlockExpr
end
redef class AVardeclExpr
end
redef class AVardeclExpr
- redef meth prepare_compile_stmt(v)
+ redef fun prepare_compile_stmt(v)
do
v.cfc.register_variable(variable)
end
do
v.cfc.register_variable(variable)
end
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var cname = v.cfc.varname(variable)
if n_expr == null then
v.add_instr("/*{cname} is variable {variable.name}*/")
else
do
var cname = v.cfc.varname(variable)
if n_expr == null then
v.add_instr("/*{cname} is variable {variable.name}*/")
else
- var e = v.compile_expr(n_expr)
+ var e = v.compile_expr(n_expr.as(not null))
v.add_assignment(cname, e)
end
end
end
redef class AReturnExpr
v.add_assignment(cname, e)
end
end
end
redef class AReturnExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
if n_expr != null then
do
if n_expr != null then
- var e = v.compile_expr(n_expr)
- v.add_assignment(v.nmc.return_value, e)
+ var e = v.compile_expr(n_expr.as(not null))
+ v.add_assignment(v.nmc.return_value.as(not null), e)
end
if v.cfc.closure == v.nmc then v.add_instr("closctx->has_broke = &({v.nmc.return_value});")
v.add_instr("goto {v.nmc.return_label};")
end
if v.cfc.closure == v.nmc then v.add_instr("closctx->has_broke = &({v.nmc.return_value});")
v.add_instr("goto {v.nmc.return_label};")
@@
-1017,11
+1028,11
@@
redef class AReturnExpr
end
redef class ABreakExpr
end
redef class ABreakExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
if n_expr != null then
do
if n_expr != null then
- var e = v.compile_expr(n_expr)
- v.add_assignment(v.nmc.break_value, e)
+ var e = v.compile_expr(n_expr.as(not null))
+ v.add_assignment(v.nmc.break_value.as(not null), e)
end
if v.cfc.closure == v.nmc then v.add_instr("closctx->has_broke = &({v.nmc.break_value}); closctx->broke_value = *closctx->has_broke;")
v.add_instr("goto {v.nmc.break_label};")
end
if v.cfc.closure == v.nmc then v.add_instr("closctx->has_broke = &({v.nmc.break_value}); closctx->broke_value = *closctx->has_broke;")
v.add_instr("goto {v.nmc.break_label};")
@@
-1029,32
+1040,32
@@
redef class ABreakExpr
end
redef class AContinueExpr
end
redef class AContinueExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
if n_expr != null then
do
if n_expr != null then
- var e = v.compile_expr(n_expr)
- v.add_assignment(v.nmc.continue_value, e)
+ var e = v.compile_expr(n_expr.as(not null))
+ v.add_assignment(v.nmc.continue_value.as(not null), e)
end
v.add_instr("goto {v.nmc.continue_label};")
end
end
redef class AAbortExpr
end
v.add_instr("goto {v.nmc.continue_label};")
end
end
redef class AAbortExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
v.add_instr("fprintf(stderr, \"Aborted\"); {v.printf_locate_error(self)} nit_exit(1);")
end
end
redef class ADoExpr
do
v.add_instr("fprintf(stderr, \"Aborted\"); {v.printf_locate_error(self)} nit_exit(1);")
end
end
redef class ADoExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
v.compile_stmt(n_block)
end
end
redef class AIfExpr
do
v.compile_stmt(n_block)
end
end
redef class AIfExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e = v.compile_expr(n_expr)
v.add_instr("if (UNTAG_Bool({e})) \{ /*if*/")
do
var e = v.compile_expr(n_expr)
v.add_instr("if (UNTAG_Bool({e})) \{ /*if*/")
@@
-1075,7
+1086,7
@@
redef class AIfExpr
end
redef class AIfexprExpr
end
redef class AIfexprExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.compile_expr(n_expr)
v.add_instr("if (UNTAG_Bool({e})) \{ /*if*/")
do
var e = v.compile_expr(n_expr)
v.add_instr("if (UNTAG_Bool({e})) \{ /*if*/")
@@
-1096,8
+1107,8
@@
end
class AControlableBlock
special PExpr
class AControlableBlock
special PExpr
- meth compile_inside_block(v: CompilerVisitor) is abstract
- redef meth compile_stmt(v)
+ fun compile_inside_block(v: CompilerVisitor) is abstract
+ redef fun compile_stmt(v)
do
var old_break_label = v.nmc.break_label
var old_continue_label = v.nmc.continue_label
do
var old_break_label = v.nmc.break_label
var old_continue_label = v.nmc.continue_label
@@
-1115,7
+1126,7
@@
end
redef class AWhileExpr
special AControlableBlock
redef class AWhileExpr
special AControlableBlock
- redef meth compile_inside_block(v)
+ redef fun compile_inside_block(v)
do
v.add_instr("while (true) \{ /*while*/")
v.indent
do
v.add_instr("while (true) \{ /*while*/")
v.indent
@@
-1132,7
+1143,7
@@
end
redef class AForExpr
special AControlableBlock
redef class AForExpr
special AControlableBlock
- redef meth compile_inside_block(v)
+ redef fun compile_inside_block(v)
do
var e = v.compile_expr(n_expr)
var ittype = meth_iterator.signature.return_type
do
var e = v.compile_expr(n_expr)
var ittype = meth_iterator.signature.return_type
@@
-1159,7
+1170,7
@@
special AControlableBlock
end
redef class AAssertExpr
end
redef class AAssertExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e = v.compile_expr(n_expr)
var s = ""
do
var e = v.compile_expr(n_expr)
var s = ""
@@
-1171,14
+1182,14
@@
redef class AAssertExpr
end
redef class AVarExpr
end
redef class AVarExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return " {v.cfc.varname(variable)} /*{variable.name}*/"
end
end
redef class AVarAssignExpr
do
return " {v.cfc.varname(variable)} /*{variable.name}*/"
end
end
redef class AVarAssignExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e = v.compile_expr(n_value)
v.add_assignment(v.cfc.varname(variable), "{e} /*{variable.name}=*/")
do
var e = v.compile_expr(n_value)
v.add_assignment(v.cfc.varname(variable), "{e} /*{variable.name}=*/")
@@
-1186,7
+1197,7
@@
redef class AVarAssignExpr
end
redef class AVarReassignExpr
end
redef class AVarReassignExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e1 = v.cfc.varname(variable)
var e2 = v.compile_expr(n_value)
do
var e1 = v.cfc.varname(variable)
var e2 = v.compile_expr(n_value)
@@
-1196,14
+1207,14
@@
redef class AVarReassignExpr
end
redef class ASelfExpr
end
redef class ASelfExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return v.cfc.varname(v.nmc.method_params[0])
end
end
redef class AOrExpr
do
return v.cfc.varname(v.nmc.method_params[0])
end
end
redef class AOrExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.ensure_var(v.compile_expr(n_expr), "Left 'or' operand")
v.add_instr("if (!UNTAG_Bool({e})) \{ /* or */")
do
var e = v.ensure_var(v.compile_expr(n_expr), "Left 'or' operand")
v.add_instr("if (!UNTAG_Bool({e})) \{ /* or */")
@@
-1218,7
+1229,7
@@
redef class AOrExpr
end
redef class AAndExpr
end
redef class AAndExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.ensure_var(v.compile_expr(n_expr), "Left 'and' operand")
v.add_instr("if (UNTAG_Bool({e})) \{ /* and */")
do
var e = v.ensure_var(v.compile_expr(n_expr), "Left 'and' operand")
v.add_instr("if (UNTAG_Bool({e})) \{ /* and */")
@@
-1233,14
+1244,14
@@
redef class AAndExpr
end
redef class ANotExpr
end
redef class ANotExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return " TAG_Bool(!UNTAG_Bool({v.compile_expr(n_expr)}))"
end
end
redef class AEeExpr
do
return " TAG_Bool(!UNTAG_Bool({v.compile_expr(n_expr)}))"
end
end
redef class AEeExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.compile_expr(n_expr)
var e2 = v.compile_expr(n_expr2)
do
var e = v.compile_expr(n_expr)
var e2 = v.compile_expr(n_expr2)
@@
-1249,7
+1260,7
@@
redef class AEeExpr
end
redef class AIsaExpr
end
redef class AIsaExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.compile_expr(n_expr)
return n_type.stype.compile_cast(v, e, n_expr.stype)
do
var e = v.compile_expr(n_expr)
return n_type.stype.compile_cast(v, e, n_expr.stype)
@@
-1257,7
+1268,7
@@
redef class AIsaExpr
end
redef class AAsCastExpr
end
redef class AAsCastExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.compile_expr(n_expr)
n_type.stype.compile_type_check(v, e, self, n_expr.stype)
do
var e = v.compile_expr(n_expr)
n_type.stype.compile_type_check(v, e, self, n_expr.stype)
@@
-1266,7
+1277,7
@@
redef class AAsCastExpr
end
redef class AAsNotnullExpr
end
redef class AAsNotnullExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.compile_expr(n_expr)
n_expr.stype.compile_notnull_check(v, e, self)
do
var e = v.compile_expr(n_expr)
n_expr.stype.compile_notnull_check(v, e, self)
@@
-1275,42
+1286,42
@@
redef class AAsNotnullExpr
end
redef class ATrueExpr
end
redef class ATrueExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return " TAG_Bool(true)"
end
end
redef class AFalseExpr
do
return " TAG_Bool(true)"
end
end
redef class AFalseExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return " TAG_Bool(false)"
end
end
redef class AIntExpr
do
return " TAG_Bool(false)"
end
end
redef class AIntExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return " TAG_Int({n_number.text})"
end
end
redef class AFloatExpr
do
return " TAG_Int({n_number.text})"
end
end
redef class AFloatExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return "BOX_Float({n_float.text})"
end
end
redef class ACharExpr
do
return "BOX_Float({n_float.text})"
end
end
redef class ACharExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return " TAG_Char({n_char.text})"
end
end
redef class AStringFormExpr
do
return " TAG_Char({n_char.text})"
end
end
redef class AStringFormExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
compute_string_info
var i = v.new_number
do
compute_string_info
var i = v.new_number
@@
-1320,7
+1331,7
@@
redef class AStringFormExpr
v.add_instr("else \{")
v.indent
v.cfc.free_var(cvar)
v.add_instr("else \{")
v.indent
v.cfc.free_var(cvar)
- var e = meth_with_native.compile_constructor_call(v, stype , ["BOX_NativeString(\"{_cstring}\")", "TAG_Int({_cstring_length})"])
+ var e = meth_with_native.compile_constructor_call(v, stype, ["BOX_NativeString(\"{_cstring}\")", "TAG_Int({_cstring_length})"])
v.add_assignment(cvar, e)
v.add_instr("once_value_{i} = {cvar};")
v.unindent
v.add_assignment(cvar, e)
v.add_instr("once_value_{i} = {cvar};")
v.unindent
@@
-1329,16
+1340,16
@@
redef class AStringFormExpr
end
# The raw string value
end
# The raw string value
- protected meth string_text: String is abstract
+ protected fun string_text: String is abstract
# The string in a C native format
# The string in a C native format
- protected attr _cstring: String
+ protected var _cstring: nullable String
# The string length in bytes
# The string length in bytes
- protected attr _cstring_length: Int
+ protected var _cstring_length: nullable Int
# Compute _cstring and _cstring_length using string_text
# Compute _cstring and _cstring_length using string_text
- protected meth compute_string_info
+ protected fun compute_string_info
do
var len = 0
var str = string_text
do
var len = 0
var str = string_text
@@
-1364,22
+1375,22
@@
redef class AStringFormExpr
end
redef class AStringExpr
end
redef class AStringExpr
- redef meth string_text do return n_string.text.substring(1, n_string.text.length - 2)
+ redef fun string_text do return n_string.text.substring(1, n_string.text.length - 2)
end
redef class AStartStringExpr
end
redef class AStartStringExpr
- redef meth string_text do return n_string.text.substring(1, n_string.text.length - 2)
+ redef fun string_text do return n_string.text.substring(1, n_string.text.length - 2)
end
redef class AMidStringExpr
end
redef class AMidStringExpr
- redef meth string_text do return n_string.text.substring(1, n_string.text.length - 2)
+ redef fun string_text do return n_string.text.substring(1, n_string.text.length - 2)
end
redef class AEndStringExpr
end
redef class AEndStringExpr
- redef meth string_text do return n_string.text.substring(1, n_string.text.length - 2)
+ redef fun string_text do return n_string.text.substring(1, n_string.text.length - 2)
end
redef class ASuperstringExpr
end
redef class ASuperstringExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
do
- var array = meth_with_capacity.compile_constructor_call(v, atype, ["TAG_Int({n_exprs.length})"])
+ var array = meth_with_capacity.compile_constructor_call(v, atype.as(not null), ["TAG_Int({n_exprs.length})"])
array = v.ensure_var(array, "Array (for super-string)")
for ne in n_exprs do
array = v.ensure_var(array, "Array (for super-string)")
for ne in n_exprs do
@@
-1397,14
+1408,14
@@
redef class ASuperstringExpr
end
redef class ANullExpr
end
redef class ANullExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return " NIT_NULL /*null*/"
end
end
redef class AArrayExpr
do
return " NIT_NULL /*null*/"
end
end
redef class AArrayExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var recv = meth_with_capacity.compile_constructor_call(v, stype, ["TAG_Int({n_exprs.length})"])
recv = v.ensure_var(recv, "Literal array")
do
var recv = meth_with_capacity.compile_constructor_call(v, stype, ["TAG_Int({n_exprs.length})"])
recv = v.ensure_var(recv, "Literal array")
@@
-1418,7
+1429,7
@@
redef class AArrayExpr
end
redef class ARangeExpr
end
redef class ARangeExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.compile_expr(n_expr)
var e2 = v.compile_expr(n_expr2)
do
var e = v.compile_expr(n_expr)
var e2 = v.compile_expr(n_expr2)
@@
-1427,7
+1438,7
@@
redef class ARangeExpr
end
redef class ASuperExpr
end
redef class ASuperExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e = intern_compile_call(v)
if e != null then
do
var e = intern_compile_call(v)
if e != null then
@@
-1435,14
+1446,14
@@
redef class ASuperExpr
end
end
end
end
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = intern_compile_call(v)
assert e != null
return e
end
do
var e = intern_compile_call(v)
assert e != null
return e
end
- private meth intern_compile_call(v: CompilerVisitor): String
+ private fun intern_compile_call(v: CompilerVisitor): nullable String
do
var arity = v.nmc.method_params.length - 1
if init_in_superclass != null then
do
var arity = v.nmc.method_params.length - 1
if init_in_superclass != null then
@@
-1470,37
+1481,45
@@
redef class ASuperExpr
end
redef class AAttrExpr
end
redef class AAttrExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = v.compile_expr(n_expr)
do
var e = v.compile_expr(n_expr)
- return prop.compile_read_access(v, e)
+ return prop.compile_read_access(v, n_id, e)
end
end
redef class AAttrAssignExpr
end
end
redef class AAttrAssignExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e = v.compile_expr(n_expr)
var e2 = v.compile_expr(n_value)
do
var e = v.compile_expr(n_expr)
var e2 = v.compile_expr(n_value)
- prop.compile_write_access(v, e, e2)
+ prop.compile_write_access(v, n_id, e, e2)
end
end
redef class AAttrReassignExpr
end
end
redef class AAttrReassignExpr
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e1 = v.compile_expr(n_expr)
do
var e1 = v.compile_expr(n_expr)
- var e2 = prop.compile_read_access(v, e1)
+ var e2 = prop.compile_read_access(v, n_id, e1)
var e3 = v.compile_expr(n_value)
var e4 = assign_method.compile_expr_call(v, [e2, e3])
var e3 = v.compile_expr(n_value)
var e4 = assign_method.compile_expr_call(v, [e2, e3])
- prop.compile_write_access(v, e1, e4)
+ prop.compile_write_access(v, n_id, e1, e4)
+ end
+end
+
+redef class AIssetAttrExpr
+ redef fun compile_expr(v)
+ do
+ var e = v.compile_expr(n_expr)
+ return prop.compile_isset(v, n_id, e)
end
end
redef class AAbsAbsSendExpr
# Compile each argument and add them to the array
end
end
redef class AAbsAbsSendExpr
# Compile each argument and add them to the array
- meth compile_arguments_in(v: CompilerVisitor, cargs: Array[String])
+ fun compile_arguments_in(v: CompilerVisitor, cargs: Array[String])
do
do
- for a in arguments do
+ for a in arguments.as(not null) do
cargs.add(v.compile_expr(a))
end
end
cargs.add(v.compile_expr(a))
end
end
@@
-1508,14
+1527,14
@@
redef class AAbsAbsSendExpr
end
redef class ASendExpr
end
redef class ASendExpr
- private meth intern_compile_call(v: CompilerVisitor): String
+ private fun intern_compile_call(v: CompilerVisitor): nullable String
do
var recv = v.compile_expr(n_expr)
var cargs = new Array[String]
cargs.add(recv)
compile_arguments_in(v, cargs)
do
var recv = v.compile_expr(n_expr)
var cargs = new Array[String]
cargs.add(recv)
compile_arguments_in(v, cargs)
- var e: String
+ var e: nullable String
if prop_signature.closures.is_empty then
e = prop.intern_compile_call(v, cargs)
else
if prop_signature.closures.is_empty then
e = prop.intern_compile_call(v, cargs)
else
@@
-1528,14
+1547,14
@@
redef class ASendExpr
return e
end
return e
end
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = intern_compile_call(v)
assert e != null
return e
end
do
var e = intern_compile_call(v)
assert e != null
return e
end
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e = intern_compile_call(v)
if e != null then
do
var e = intern_compile_call(v)
if e != null then
@@
-1545,9
+1564,9
@@
redef class ASendExpr
end
redef class ASendReassignExpr
end
redef class ASendReassignExpr
- redef meth compile_expr(v) do abort
+ redef fun compile_expr(v) do abort
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var recv = v.compile_expr(n_expr)
var cargs = new Array[String]
do
var recv = v.compile_expr(n_expr)
var cargs = new Array[String]
@@
-1563,30
+1582,30
@@
redef class ASendReassignExpr
end
redef class ANewExpr
end
redef class ANewExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var cargs = new Array[String]
compile_arguments_in(v, cargs)
do
var cargs = new Array[String]
compile_arguments_in(v, cargs)
- return prop.compile_constructor_call(v, stype, cargs)
+ return prop.compile_constructor_call(v, stype, cargs)
end
end
- redef meth compile_stmt(v) do abort
+ redef fun compile_stmt(v) do abort
end
redef class PClosureDef
# Compile the closure definition as a function in v.out_contexts
# Return the cname of the function
end
redef class PClosureDef
# Compile the closure definition as a function in v.out_contexts
# Return the cname of the function
- meth compile_closure(v: CompilerVisitor, closcn: String): String is abstract
+ fun compile_closure(v: CompilerVisitor, closcn: String): String is abstract
# Compile the closure definition inside the current C function.
# Compile the closure definition inside the current C function.
- meth do_compile_inside(v: CompilerVisitor, params: Array[String]): String is abstract
+ fun do_compile_inside(v: CompilerVisitor, params: nullable Array[String]): nullable String is abstract
end
redef class AClosureDef
# The cname of the function
end
redef class AClosureDef
# The cname of the function
- readable attr _cname: String
+ readable var _cname: nullable String
- redef meth compile_closure(v, closcn)
+ redef fun compile_closure(v, closcn)
do
var ctx_old = v.ctx
v.ctx = new CContext
do
var ctx_old = v.ctx
v.ctx = new CContext
@@
-1656,7
+1675,7
@@
redef class AClosureDef
return "(&{closcnv})"
end
return "(&{closcnv})"
end
- protected meth decl_csignature(v: CompilerVisitor, args: Array[String], closcn: String): String
+ protected fun decl_csignature(v: CompilerVisitor, args: Array[String], closcn: String): String
do
var params = new Array[String]
params.add("struct WBT_ *closctx")
do
var params = new Array[String]
params.add("struct WBT_ *closctx")
@@
-1677,7
+1696,7
@@
redef class AClosureDef
return s
end
return s
end
- redef meth do_compile_inside(v, params)
+ redef fun do_compile_inside(v, params)
do
for i in [0..variables.length[ do
var vacname = v.cfc.register_variable(variables[i])
do
for i in [0..variables.length[ do
var vacname = v.cfc.register_variable(variables[i])
@@
-1696,7
+1715,7
@@
redef class AClosureDef
v.add_instr("{v.nmc.continue_label}: while(false);")
v.add_instr("{v.nmc.continue_label}: while(false);")
- var ret: String = null
+ var ret: nullable String = null
if closure.signature.return_type != null then ret = v.nmc.continue_value
v.nmc.continue_value = old_cv
if closure.signature.return_type != null then ret = v.nmc.continue_value
v.nmc.continue_value = old_cv
@@
-1708,12
+1727,12
@@
redef class AClosureDef
end
redef class PClosureDecl
end
redef class PClosureDecl
- meth do_compile_inside(v: CompilerVisitor, params: Array[String]): String is abstract
+ fun do_compile_inside(v: CompilerVisitor, params: Array[String]): nullable String is abstract
end
redef class AClosureDecl
end
redef class AClosureDecl
- redef meth do_compile_inside(v, params)
+ redef fun do_compile_inside(v, params)
do
do
- if n_signature != null then n_signature.compile_parameters(v, variable.closure.signature, params)
+ n_signature.compile_parameters(v, variable.closure.signature, params)
var old_cv = v.nmc.continue_value
var old_cl = v.nmc.continue_label
var old_cv = v.nmc.continue_value
var old_cl = v.nmc.continue_label
@@
-1727,7
+1746,7
@@
redef class AClosureDecl
v.add_instr("{v.nmc.continue_label}: while(false);")
v.add_instr("{v.nmc.continue_label}: while(false);")
- var ret: String = null
+ var ret: nullable String = null
if variable.closure.signature.return_type != null then ret = v.nmc.continue_value
v.nmc.continue_value = old_cv
if variable.closure.signature.return_type != null then ret = v.nmc.continue_value
v.nmc.continue_value = old_cv
@@
-1739,11
+1758,11
@@
redef class AClosureDecl
end
redef class AClosureCallExpr
end
redef class AClosureCallExpr
- meth intern_compile_call(v: CompilerVisitor): String
+ fun intern_compile_call(v: CompilerVisitor): nullable String
do
var cargs = new Array[String]
compile_arguments_in(v, cargs)
do
var cargs = new Array[String]
compile_arguments_in(v, cargs)
- var va: String = null
+ var va: nullable String = null
if variable.closure.signature.return_type != null then va = v.cfc.get_var("Closure call result value")
if variable.closure.is_optional then
if variable.closure.signature.return_type != null then va = v.cfc.get_var("Closure call result value")
if variable.closure.is_optional then
@@
-1752,7
+1771,7
@@
redef class AClosureCallExpr
var n = variable.decl
assert n isa AClosureDecl
var s = n.do_compile_inside(v, cargs)
var n = variable.decl
assert n isa AClosureDecl
var s = n.do_compile_inside(v, cargs)
- if s != null then v.add_assignment(va, s)
+ if s != null then v.add_assignment(va.as(not null), s)
v.unindent
v.add_instr("} else \{")
v.indent
v.unindent
v.add_instr("} else \{")
v.indent
@@
-1769,7
+1788,7
@@
redef class AClosureCallExpr
end
v.add_instr("if ({ivar}->has_broke) \{")
v.indent
end
v.add_instr("if ({ivar}->has_broke) \{")
v.indent
- if n_closure_defs != null and n_closure_defs.length == 1 then do
+ if n_closure_defs.length == 1 then do
n_closure_defs.first.do_compile_inside(v, null)
end
if v.cfc.closure == v.nmc then v.add_instr("if ({ivar}->has_broke) \{ closctx->has_broke = {ivar}->has_broke; closctx->broke_value = {ivar}->broke_value;\}")
n_closure_defs.first.do_compile_inside(v, null)
end
if v.cfc.closure == v.nmc then v.add_instr("if ({ivar}->has_broke) \{ closctx->has_broke = {ivar}->has_broke; closctx->broke_value = {ivar}->broke_value;\}")
@@
-1784,14
+1803,14
@@
redef class AClosureCallExpr
return va
end
return va
end
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var e = intern_compile_call(v)
assert e != null
return e
end
do
var e = intern_compile_call(v)
assert e != null
return e
end
- redef meth compile_stmt(v)
+ redef fun compile_stmt(v)
do
var e = intern_compile_call(v)
if e != null then
do
var e = intern_compile_call(v)
if e != null then
@@
-1801,14
+1820,14
@@
redef class AClosureCallExpr
end
redef class AProxyExpr
end
redef class AProxyExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
return v.compile_expr(n_expr)
end
end
redef class AOnceExpr
do
return v.compile_expr(n_expr)
end
end
redef class AOnceExpr
- redef meth compile_expr(v)
+ redef fun compile_expr(v)
do
var i = v.new_number
var cvar = v.cfc.get_var("Once expression result")
do
var i = v.new_number
var cvar = v.cfc.get_var("Once expression result")