X-Git-Url: http://nitlanguage.org diff --git a/src/compiling/compiling_base.nit b/src/compiling/compiling_base.nit index c5bf61d..3fcdf8d 100644 --- a/src/compiling/compiling_base.nit +++ b/src/compiling/compiling_base.nit @@ -21,15 +21,14 @@ import syntax private import utils redef class ToolContext - readable writable attr _global: Bool - readable writable attr _attr_sim: Bool - readable writable attr _base_dir: String - readable writable attr _clibdir: String - readable writable attr _bindir: String - readable writable attr _output_file: String - readable writable attr _boost: Bool - readable writable attr _no_cc: Bool - readable writable attr _ext_prefix: String + readable writable attr _global: Bool = false + readable writable attr _compdir: nullable String = null + readable writable attr _clibdir: nullable String = null + readable writable attr _bindir: nullable String = null + readable writable attr _output_file: nullable String = null + readable writable attr _boost: Bool = false + readable writable attr _no_cc: Bool = false + readable writable attr _ext_prefix: String = "" end # Class used to generate files. @@ -64,7 +63,7 @@ class CompilerVisitor return res end # next number for new_number - attr _number_cpt: Int + attr _number_cpt: Int = 0 # Add an indent level. # New decl and instr will be indented. @@ -87,20 +86,24 @@ class CompilerVisitor return out.join("\n") end - # The current module processed - readable writable attr _module: MMSrcModule + # The processed module + readable attr _module: MMSrcModule # Where instr and decl are stored readable writable attr _ctx: CContext = new CContext # The current indent lever - readable writable attr _indent_level: Int + readable writable attr _indent_level: Int = 0 - # The current ToolContext - readable writable attr _tc: ToolContext + # The ToolContext info + readable attr _tc: ToolContext # Create a new CompilerVisitor based on a module - init(module: MMSrcModule) do _module = module + init(module: MMSrcModule, tc: ToolContext) + do + _module = module + _tc = tc + end end # Where instr and decl are stored for a module @@ -114,6 +117,12 @@ class CContext _instrs.append(c.decls) _instrs.append(c.instrs) end + + meth merge(c: CContext) + do + _decls.append(c.decls) + _instrs.append(c.instrs) + end init do end end @@ -130,13 +139,6 @@ redef class MMGlobalProperty do return "ATTR_{intro.cname}" end - - # C symbol refering the color of the global property - meth color_id: String - do - return "COLOR_{intro.cname}" - end - end redef class MMGlobalClass @@ -161,15 +163,15 @@ end redef class MMLocalClass # Cached primitive_info result - attr _primitive_info_cache: PrimitiveInfo + attr _primitive_info_cache: nullable PrimitiveInfo = null # If primitive_info result cached? - attr _primitive_info_b: Bool + attr _primitive_info_b: Bool = false # Return the primitive information of the class. # Return null if the class is not primitive # FIXME: Only here since there is no universal type yet - meth primitive_info: PrimitiveInfo + meth primitive_info: nullable PrimitiveInfo do if _primitive_info_b == true then return _primitive_info_cache @@ -205,10 +207,7 @@ redef class MMLocalClass var cnames = ["bigint", "char", "int", "float", "char *", "val_t *", "void *"] for i in [0..pnames.length[ do var n = pnames[i].to_symbol - var pi = new PrimitiveInfo - pi.name = n - pi.tagged = tagged[i] - pi.cname = cnames[i] + var pi = new PrimitiveInfo(n, tagged[i], cnames[i]) res[n] = pi end return res @@ -218,15 +217,20 @@ end # Information about a primitive class class PrimitiveInfo # The name of the class - readable writable attr _name: Symbol + readable attr _name: Symbol # Is the class tagged (aka not boxed) - readable writable attr _tagged: Bool + readable attr _tagged: Bool # The corresponding c type for the primitive value - readable writable attr _cname: String + readable attr _cname: String - private init do end + private init(n: Symbol, t: Bool, c: String) + do + _name = n + _tagged = t + _cname = c + end end redef class MMType @@ -284,21 +288,23 @@ end redef class MMLocalProperty # Cacher result of cname - attr _cname_cache: String + attr _cname_cache: nullable String # The mangled name of the method meth cname: String do - if _cname_cache == null then - _cname_cache = cmangle(module.name, local_class.name, name) + var cname = _cname_cache + if cname == null then + cname = cmangle(module.name, local_class.name, name) + _cname_cache = cname end - return _cname_cache + return cname end - # C symbol refering the color of the super call of a super property - meth color_id_for_super: String + # C macro used to get the function for the call of a super property + meth super_meth_call: String do - return "COLOR_SUPER_{cname}" + return "CALL_SUPER_{cname}" end end