nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'pu/class_name' into wip
[nit.git]
/
src
/
compiling
/
compiling_global.nit
diff --git
a/src/compiling/compiling_global.nit
b/src/compiling/compiling_global.nit
index
7123ad3
..
1a8a817
100644
(file)
--- a/
src/compiling/compiling_global.nit
+++ b/
src/compiling/compiling_global.nit
@@
-24,16
+24,18
@@
redef class Program
# Compile module and class tables
fun compile_tables_to_c(v: CompilerVisitor)
do
# Compile module and class tables
fun compile_tables_to_c(v: CompilerVisitor)
do
- for m in module.mhe.greaters_and_self do
+ for m in main_module.mhe.greaters_and_self do
m.compile_local_table_to_c(v)
end
m.compile_local_table_to_c(v)
end
- for c in module.local_classes do
+ with_each_live_local_classes !action(c) do
+ if c.global.is_abstract or c.global.is_interface then continue
c.compile_tables_to_c(v)
end
c.compile_tables_to_c(v)
end
+
var s = new Buffer.from("classtable_t TAG2VFT[4] = \{NULL")
for t in ["Int","Char","Bool"] do
var s = new Buffer.from("classtable_t TAG2VFT[4] = \{NULL")
for t in ["Int","Char","Bool"] do
- if module.has_global_class_named(t.to_symbol) then
+ if main_module.has_global_class_named(t.to_symbol) then
s.append(", (const classtable_t)VFT_{t}")
else
s.append(", NULL")
s.append(", (const classtable_t)VFT_{t}")
else
s.append(", NULL")
@@
-68,7
+70,7
@@
redef class MMModule
fun declare_class_tables_to_c(v: CompilerVisitor)
do
for c in local_classes do
fun declare_class_tables_to_c(v: CompilerVisitor)
do
for c in local_classes do
- if c.global.module == self then
+ if c.global.mmmodule == self then
c.declare_tables_to_c(v)
end
end
c.declare_tables_to_c(v)
end
end
@@
-78,13
+80,13
@@
redef class MMModule
fun compile_mod_to_c(v: CompilerVisitor)
do
v.add_decl("extern const char *LOCATE_{name};")
fun compile_mod_to_c(v: CompilerVisitor)
do
v.add_decl("extern const char *LOCATE_{name};")
- if not v.program.tc.global then
+ if not v.program.tc.use_SFT_optimization then
v.add_decl("extern const int SFT_{name}[];")
end
var i = 0
for e in local_table do
var value: String
v.add_decl("extern const int SFT_{name}[];")
end
var i = 0
for e in local_table do
var value: String
- if v.program.tc.global then
+ if v.program.tc.use_SFT_optimization then
value = "{e.value(v.program)}"
else
value = "SFT_{name}[{i}]"
value = "{e.value(v.program)}"
else
value = "SFT_{name}[{i}]"
@@
-114,9
+116,9
@@
redef class MMModule
# Compile module file for the current module
fun compile_local_table_to_c(v: CompilerVisitor)
do
# Compile module file for the current module
fun compile_local_table_to_c(v: CompilerVisitor)
do
- v.add_instr("const char *LOCATE_{name} = \"{location.file}\";")
+ v.add_instr("const char *LOCATE_{name} = \"{location.file.filename}\";")
- if v.program.tc.global or local_table.is_empty then
+ if v.program.tc.use_SFT_optimization or local_table.is_empty then
return
end
return
end
@@
-279,6
+281,14
@@
redef class TableEltClassSelfId
end
end
end
end
+redef class TableEltClassSelfName
+ redef fun compile_to_c(v, c)
+ do
+ var prog = v.program
+ return "\"{c.global.name}\" /* {prog.table_information.color(self)}: Class Name */"
+ end
+end
+
redef class TableEltClassObjectSize
redef fun compile_to_c(v, c)
do
redef class TableEltClassObjectSize
redef fun compile_to_c(v, c)
do
@@
-322,11
+332,7
@@
redef class MMLocalClass
v.add_decl("")
var pi = primitive_info
v.add_decl("extern const classtable_elt_t VFT_{name}[];")
v.add_decl("")
var pi = primitive_info
v.add_decl("extern const classtable_elt_t VFT_{name}[];")
- if name == "NativeArray".to_symbol then
- v.add_decl("val_t NEW_NativeArray(size_t length, size_t size);")
- else if pi == null then
- # v.add_decl("val_t NEW_{name}(void);")
- else if not pi.tagged then
+ if pi != null and not pi.tagged then
var t = pi.cname
var tbox = "struct TBOX_{name}"
v.add_decl("{tbox} \{ const classtable_elt_t * vft; bigint object_id; {t} val;};")
var t = pi.cname
var tbox = "struct TBOX_{name}"
v.add_decl("{tbox} \{ const classtable_elt_t * vft; bigint object_id; {t} val;};")
@@
-386,11
+392,10
@@
redef class MMLocalClass
# Generate INIT_ATTRIBUTES routine
var cname = "INIT_ATTRIBUTES__{name}"
var args = init_var_iroutine.compile_signature_to_c(v, cname, "init var of {name}", null, null)
# Generate INIT_ATTRIBUTES routine
var cname = "INIT_ATTRIBUTES__{name}"
var args = init_var_iroutine.compile_signature_to_c(v, cname, "init var of {name}", null, null)
- var ctx_old = v.ctx
- v.ctx = new CContext
+ var decl_writer_old = v.decl_writer
+ v.decl_writer = v.writer.sub
init_var_iroutine.compile_to_c(v, cname, args)
init_var_iroutine.compile_to_c(v, cname, args)
- ctx_old.append(v.ctx)
- v.ctx = ctx_old
+ v.decl_writer = decl_writer_old
v.unindent
v.add_instr("}")
end
v.unindent
v.add_instr("}")
end
@@
-413,11
+418,10
@@
redef class MMLocalClass
# Compile CHECKNAME
var cname = "CHECKNEW_{name}"
var args = checknew_iroutine.compile_signature_to_c(v, cname, "check new {name}", null, null)
# Compile CHECKNAME
var cname = "CHECKNEW_{name}"
var args = checknew_iroutine.compile_signature_to_c(v, cname, "check new {name}", null, null)
- var ctx_old = v.ctx
- v.ctx = new CContext
+ var decl_writer_old = v.decl_writer
+ v.decl_writer = v.writer.sub
checknew_iroutine.compile_to_c(v, cname, args)
checknew_iroutine.compile_to_c(v, cname, args)
- ctx_old.append(v.ctx)
- v.ctx = ctx_old
+ v.decl_writer = decl_writer_old
v.unindent
v.add_instr("}")
end
v.unindent
v.add_instr("}")
end
@@
-433,13
+437,12
@@
redef class MMLocalClass
var cname = "NEW_{self}_{p.global.intro.cname}"
var new_args = new_instance_iroutine[p].compile_signature_to_c(v, cname, "new {self} {p.full_name}", null, null)
var cname = "NEW_{self}_{p.global.intro.cname}"
var new_args = new_instance_iroutine[p].compile_signature_to_c(v, cname, "new {self} {p.full_name}", null, null)
- var ctx_old = v.ctx
- v.ctx = new CContext
+ var decl_writer_old = v.decl_writer
+ v.decl_writer = v.writer.sub
v.add_instr(init_table_decl)
var e = new_instance_iroutine[p].compile_to_c(v, cname, new_args).as(not null)
v.add_instr("return {e};")
v.add_instr(init_table_decl)
var e = new_instance_iroutine[p].compile_to_c(v, cname, new_args).as(not null)
v.add_instr("return {e};")
- ctx_old.append(v.ctx)
- v.ctx = ctx_old
+ v.decl_writer = decl_writer_old
v.unindent
v.add_instr("}")
end
v.unindent
v.add_instr("}")
end
@@
-469,10
+472,10
@@
redef class MMMethod
var more_params: nullable String = null
if global.is_init then more_params = "int* init_table"
var args = ir.compile_signature_to_c(v, cname, full_name, null, more_params)
var more_params: nullable String = null
if global.is_init then more_params = "int* init_table"
var args = ir.compile_signature_to_c(v, cname, full_name, null, more_params)
- var ctx_old = v.ctx
- v.ctx = new CContext
-
- v.out_contexts.clear
+ var writer_old = v.writer
+ v.writer = v.writer.sub
+ var decl_writer_old = v.decl_writer
+ v.decl_writer = v.writer.sub
var itpos: nullable String = null
if global.is_init then
var itpos: nullable String = null
if global.is_init then
@@
-489,15
+492,13
@@
redef class MMMethod
if s == null then
v.add_instr("return;")
else
if s == null then
v.add_instr("return;")
else
- v.add_instr("return ", s, ";")
+ v.add_instr("return {s};")
end
end
-
- ctx_old.append(v.ctx)
- v.ctx = ctx_old
v.unindent
v.add_instr("}")
v.unindent
v.add_instr("}")
- for ctx in v.out_contexts do v.ctx.merge(ctx)
+ v.writer = writer_old
+ v.decl_writer = decl_writer_old
end
end
end
end