only consider MMSrc classes in special cases.
Signed-off-by: Jean Privat <jean@pryen.org>
private import compiling_global
private import syntax
-redef class MMSrcModule
+redef class MMModule
# Compile the program
# Generate all sep files (_sep.[ch]), the main file (_table.c) and the build file (_build.sh)
# Then execute the build.sh
do
tc.info("Building tables",1)
for m in mhe.greaters_and_self do
- assert m isa MMSrcModule
tc.info("Building tables for module: {m.name}",2)
m.local_analysis(tc)
end
files.add("$CLIBDIR/nit_main.c")
tc.info("Generating C code",1)
for m in mhe.greaters_and_self do
- assert m isa MMSrcModule
files.add("{tc.compdir}/{m.name}._sep.c")
tc.info("Generating C code for module: {m.name}",2)
m.compile_separate_module(tc, ga)
end
# The processed module
- readable var _module: MMSrcModule
+ readable var _module: MMModule
# Where instr and decl are stored
readable writable var _ctx: CContext = new CContext
readable var _tc: ToolContext
# Create a new CompilerVisitor based on a module
- init(module: MMSrcModule, tc: ToolContext)
+ init(module: MMModule, tc: ToolContext)
do
_module = module
_tc = tc
# FIXME: do something better.
readable writable var _max_class_table_length: Int = 0
- init(module: MMSrcModule)
+ init(module: MMModule)
do
_module = module
end
special CompilerVisitor
# The global analysis result
readable var _global_analysis: GlobalAnalysis
- init(m: MMSrcModule, tc: ToolContext, ga: GlobalAnalysis)
+ init(m: MMModule, tc: ToolContext, ga: GlobalAnalysis)
do
super(m, tc)
_global_analysis = ga
init(c: MMLocalClass) do _local_class = c
end
-redef class MMSrcLocalClass
+redef class MMConcreteClass
# The table element of the subtype check
fun class_color_pos: TableEltClassColor do return _class_color_pos.as(not null)
var _class_color_pos: nullable TableEltClassColor
module_table.add(cpp)
clt.add(new TableEltClassInitTable(self))
end
- for p in src_local_properties do
+ for p in local_local_properties do
var pg = p.global
if pg.intro == p then
- if p isa MMSrcAttribute then
+ if p isa MMAttribute then
ilt.add(new TableEltAttr(p))
- else if p isa MMSrcMethod then
+ else if p isa MMMethod then
clt.add(new TableEltMeth(p))
end
end
- if p isa MMSrcMethod and p.need_super then
+ if p isa MMMethod and p.need_super then
clt.add(new TableEltSuper(p))
end
end
end
end
-redef class MMSrcModule
+redef class MMModule
# The local table of the module (refers things introduced in the module)
var _local_table: Array[ModuleTableElt] = new Array[ModuleTableElt]
# Builds the local tables and local classes layouts
fun local_analysis(tc: ToolContext)
do
- for c in src_local_classes do
- c.build_layout_in(tc, _local_table)
+ for c in local_classes do
+ if c isa MMConcreteClass then
+ c.build_layout_in(tc, _local_table)
+ end
end
end
# Store the colortableelt in the class table pool
var bc = c.global.intro
- assert bc isa MMSrcLocalClass
+ assert bc isa MMConcreteClass
ctab.add(bc.class_color_pos)
end
assert cc.class_table.is_empty
cc.class_table.add_all(scc.class_table)
var bc = c.global.intro
- assert bc isa MMSrcLocalClass
+ assert bc isa MMConcreteClass
var colpos = bc.class_color_pos
var colposcolor = cc.class_table.length
ga.color(colpos) = colposcolor
var cte = cc.class_layout
var ite = cc.instance_layout
for sc in c.crhe.greaters_and_self do
- if sc isa MMSrcLocalClass then
+ if sc isa MMConcreteClass then
cte.add(sc, sc.class_layout)
ite.add(sc, sc.instance_layout)
end
cc.class_table.clear
cc.class_table.add_all(scc.class_table)
var bc = c.global.intro
- assert bc isa MMSrcLocalClass
+ assert bc isa MMConcreteClass
var colpos = bc.class_color_pos
cc.class_table[ga.color(colpos)] = colpos
while cc.class_table.length <= maxcolor do
fun compile_tables_to_c(v: GlobalCompilerVisitor)
do
for m in mhe.greaters_and_self do
- assert m isa MMSrcModule
m.compile_local_table_to_c(v)
end
end
e.compile_macros(v, value)
end
- for c in src_local_classes do
+ for c in local_classes do
+ if not c isa MMConcreteClass then continue
for pg in c.global_properties do
var p = c[pg]
if p.local_class == c then
# A Nit method currenlty compiled
class NitMethodContext
# Current method compiled
- readable var _method: nullable MMSrcMethod
+ readable var _method: nullable MMMethod
# Association between parameters and the corresponding variables
readable writable var _method_params: nullable Array[ParamVariable]
# Variable where a functionnal nit continue must store its value
readable writable var _continue_value: nullable String
- init(method: nullable MMSrcMethod)
+ init(method: nullable MMMethod)
do
_method = method
end
readable writable var _ctypename: nullable String
end
+redef class MMAttribute
+ # Compile a read acces on selffor a given reciever.
+ 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
+ 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.
+ 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
+end
+
+redef class MMLocalProperty
+ # Compile the property as a C property
+ fun compile_property_to_c(v: CompilerVisitor) do end
+end
+
redef class MMMethod
# Compile as an expression.
# require that signature.return_type != null
do
return "FWBT_{cname}_{i}"
end
-end
-
-redef class MMAttribute
- # Compile a read acces on selffor a given reciever.
- 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
- 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.
- 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
-end
-
-redef class MMLocalProperty
- # Compile the property as a C property
- fun compile_property_to_c(v: CompilerVisitor) do end
-end
-
-redef class MMSrcMethod
# Compile and declare the signature to C
protected fun decl_csignature(v: CompilerVisitor, args: Array[String]): String
redef class AMethPropdef
# Compile the method body
- fun do_compile_inside(v: CompilerVisitor, method: MMSrcMethod, params: Array[String]): nullable String is abstract
+ fun do_compile_inside(v: CompilerVisitor, method: MMMethod, params: Array[String]): nullable String is abstract
end
redef class PSignature
redef fun perform_work(mods)
do
for mod in mods do
- assert mod isa MMSrcModule
mod.compile_prog_to_c(self)
end