# limitations under the License.
# Common things for NIT compilation and C generation
-package compiling_base
+module compiling_base
import mmloader
private import utils
-import primitive_info
+private import primitive_info
import program
import compiling_writer
do
_program = p
_compdir = p.tc.compdir.as(not null)
- _build_file = "{compdir}/{program.main_module.name}._build.sh"
+ _build_file = "{compdir}/{program.main_module.cname}._build.sh"
end
# The Nit program compiled to C
if _module_include.has_key(m) then
return _module_include[m]
end
- var filename = "{m.name}.{get_file_ending}.h"
+ var filename = "{m.cname}.{get_file_ending}.h"
_module_include[m] = filename
return filename
end
var verbose = ""
var tc = program.tc
- if tc.verbose_level > 0 then
- verbose = "-"
- for i in [1..tc.verbose_level] do verbose = verbose + "v"
+ if tc.verbose_level == 1 then
+ verbose = "-v"
+ else if tc.verbose_level >= 2 then
+ # We catch tc.verbose_level >= 2, since 3+ is not valid with gccx
+ verbose = "-vv"
end
+ # include compdir to find frontier files (._nitni.h) from native
+ # implementations as .nit.h must have an import of <{name}._nitni.h>
+ include_dirs.add( "-I {compdir}" )
+
f.write("#!/bin/sh\n")
- f.write("# This shell script is generated by NIT to compile the program {program.main_module.name}.\n")
+ f.write("# This shell script is generated by NIT to compile the program {program.main_module.full_name}.\n")
f.write("CLIBDIR=\"{tc.clibdir.as(not null)}\"\n")
f.write("{tc.bindir.as(not null)}/gccx {verbose} -d {compdir} -I $CLIBDIR {include_dirs.join(" ")}")
if tc.output_file != null then
end
if tc.boost then f.write(" -O")
if not tc.cc_link then f.write(" -x \"-c\"")
- for l in tc.cc_libs do f.write(" -x \"-l {l}\"")
+ for l in tc.cc_libs do f.write(" -l {l}")
for lp in tc.cc_lib_paths do f.write(" -x \"-L {lp}\"")
for ip in tc.cc_include_paths do f.write(" -x \"-I {ip}\"")
f.write(" \"$@\" \\\n {files.join("\\\n ")}\n")
do
return "ATTR_{intro.cname}"
end
+
+ # C symbol refering a virtual type class color
+ fun vt_class_color: String
+ do
+ return "VTCOLOR_{intro.cname}"
+ end
+
+ # C symbol refering a virtual type class id
+ fun vt_class_id: String
+ do
+ return "VTID_{intro.cname}"
+ end
end
redef class MMGlobalClass
+ # Cacher result of cname
+ var _cname_cache: nullable String
+
+ # The mangled name of the global class
+ fun cname: String
+ do
+ var cname = _cname_cache
+ if cname == null then
+ cname = intro.mmmodule.cname + "___" + cmangle(intro.name)
+ _cname_cache = cname
+ end
+ return cname
+ end
+
# C symbol refering the identifier of the class
fun id_id: String
do
- return "ID_{intro.name}"
+ return "ID_{cname}"
end
# C symbol refering the color of the class (for subtype tests)
fun color_id: String
do
- return "COLOR_{intro.name}"
+ return "COLOR_{cname}"
end
# C symbol refering the init table position of the class (for constructor linearization)
fun init_table_pos_id: String
do
- return "INIT_TABLE_POS_{intro.name}"
+ return "INIT_TABLE_POS_{cname}"
end
end
+redef class MMModule
+ # Cacher result of cname
+ var _cname_cache: nullable String
+
+ # The mangled name of the module
+ fun cname: String
+ do
+ var cname = _cname_cache
+ if cname == null then
+ var l = new List[String]
+ var m: nullable MMModule = self
+ while m != null do
+ l.unshift(cmangle(m.name))
+ var d: nullable MMDirectory = m.directory
+ while d != null and d.owner == m do d = d.parent
+ if d == null then m = null else m = d.owner
+ end
+ cname = l.to_a.join("___")
+ _cname_cache = cname
+ end
+ return cname
+ end
+end
+
+redef class MMLocalClass
+ # The mangled name of the global class
+ fun cname: String do return global.cname
+end
+
redef class MMLocalProperty
# Cacher result of cname
var _cname_cache: nullable String
do
var cname = _cname_cache
if cname == null then
- cname = cmangle(mmmodule.name, local_class.name, name)
+ cname = mmmodule.cname + "___" + cmangle(local_class.name, name)
_cname_cache = cname
end
return cname