1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Compute and generate tables for classes and modules.
18 package compiling_global
20 #import compiling_base
21 private import compiling_methods
24 # Something that store color of table elements
26 attr _colors
: HashMap[TableElt, Int] = null
28 # The color of a table element.
29 meth color
(e
: TableElt): Int
34 # Is a table element already colored?
35 meth has_color
(e
: TableElt): Bool
37 return _colors
!= null and _colors
.has_key
(e
)
40 # Assign a color to a table element.
41 meth color
=(e
: TableElt, c
: Int)
43 if _colors
== null then _colors
= new HashMap[TableElt, Int]
46 for i
in [0..e
.length
[ do
47 _colors
[e
.item
(i
)] = idx
53 # All information and results of the global analysis.
56 # Associate global classes to compiled classes
57 readable attr _compiled_classes
: HashMap[MMGlobalClass, CompiledClass] = new HashMap[MMGlobalClass, CompiledClass]
59 # The main module of the program globally analysed
60 readable attr _module
: MMModule
62 # FIXME: do something better.
63 readable writable attr _max_class_table_length
: Int
65 init(module: MMSrcModule)
71 class GlobalCompilerVisitor
72 special CompilerVisitor
73 # The global analysis result
74 readable attr _global_analysis
: GlobalAnalysis
75 init(m
: MMSrcModule, tc
: ToolContext, ga
: GlobalAnalysis)
82 # A compiled class is a class in a program
85 # The corresponding local class in the main module of the prgram
86 readable attr _local_class
: MMLocalClass
88 # The identifier of the class
89 readable writable attr _id
: Int
91 # The full class table of the class
92 readable attr _class_table
: Array[TableElt] = new Array[TableElt]
94 # The full instance table of the class
95 readable attr _instance_table
: Array[TableElt] = new Array[TableElt]
97 # The proper class table part (no superclasses but all refinements)
98 readable attr _class_layout
: TableEltComposite = new TableEltComposite(self)
100 # The proper instance table part (no superclasses but all refinements)
101 readable attr _instance_layout
: TableEltComposite = new TableEltComposite(self)
103 init(c
: MMLocalClass) do _local_class
= c
106 redef class MMSrcLocalClass
107 # The table element of the subtype check
108 readable attr _class_color_pos
: TableEltClassColor
110 # The proper local class table part (nor superclasses nor refinments)
111 readable attr _class_layout
: Array[TableElt] = new Array[TableElt]
113 # The proper local instance table part (nor superclasses nor refinments)
114 readable attr _instance_layout
: Array[TableElt] = new Array[TableElt]
116 # Build the local layout of the class and feed the module table
117 meth build_layout_in
(tc
: ToolContext, module_table
: Array[ModuleTableElt])
119 var clt
= _class_layout
120 var ilt
= _instance_layout
122 if global
.intro
== self then
123 module_table
.add
(new TableEltClassId(self))
124 _class_color_pos
= new TableEltClassColor(self)
125 module_table
.add
(_class_color_pos
)
126 clt
.add
(new TableEltClassInitTable(self))
128 for p
in src_local_properties
do
130 if pg
.intro
== p
then
131 if p
isa MMSrcAttribute then
132 ilt
.add
(new TableEltAttr(p
))
133 else if p
isa MMSrcMethod then
134 clt
.add
(new TableEltMeth(p
))
137 if p
isa MMSrcMethod and p
.need_super
then
138 clt
.add
(new TableEltSuper(p
))
142 if not ilt
.is_empty
then
143 var teg
= new ModuleTableEltGroup
144 teg
.elements
.append
(ilt
)
145 module_table
.add
(teg
)
148 if not clt
.is_empty
then
149 var teg
= new ModuleTableEltGroup
150 teg
.elements
.append
(clt
)
151 module_table
.add
(teg
)
156 redef class MMSrcModule
157 # The local table of the module (refers things introduced in the module)
158 attr _local_table
: Array[ModuleTableElt] = new Array[ModuleTableElt]
160 # Builds the local tables and local classes layouts
161 meth local_analysis
(tc
: ToolContext)
163 for c
in src_local_classes
do
164 c
.build_layout_in
(tc
, _local_table
)
168 # Do the complete global analysis
169 meth global_analysis
(cctx
: ToolContext): GlobalAnalysis
171 #print "Do the complete global analysis"
172 var ga
= new GlobalAnalysis(self)
173 var smallest_classes
= new Array[MMLocalClass]
174 var global_properties
= new HashSet[MMGlobalProperty]
175 var ctab
= new Array[TableElt]
176 var itab
= new Array[TableElt]
178 ctab
.add
(new TableEltClassSelfId)
179 itab
.add
(new TableEltVftPointer)
184 # We have to work on ALL the classes of the module
185 var classes
= new Array[MMLocalClass]
186 for c
in local_classes
do
187 c
.compute_super_classes
190 (new ClassSorter).sort
(classes
)
193 # Finish processing the class (if invisible)
195 c
.inherit_global_properties
197 # Associate a CompiledClass to the class
198 var cc
= new CompiledClass(c
)
199 ga
.compiled_classes
[c
.global
] = cc
201 # Assign a unique class identifier
202 # (negative are for primitive classes)
205 if c
.primitive_info
!= null then
207 pclassid
= pclassid
- 4
210 classid
= classid
+ 4
213 # Register is the class is a leaf
214 if c
.cshe
.direct_smallers
.is_empty
then
215 smallest_classes
.add
(c
)
218 # Store the colortableelt in the class table pool
219 var bc
= c
.global
.intro
220 assert bc
isa MMSrcLocalClass
221 ctab
.add
(bc
.class_color_pos
)
224 # Compute core and crown classes for colorization
225 var crown_classes
= new HashSet[MMLocalClass]
226 var core_classes
= new HashSet[MMLocalClass]
227 for c
in smallest_classes
do
228 while c
.cshe
.direct_greaters
.length
== 1 do
229 c
= c
.cshe
.direct_greaters
.first
232 core_classes
.add_all
(c
.cshe
.greaters_and_self
)
234 #print("nbclasses: {classes.length} leaves: {smallest_classes.length} crown: {crown_classes.length} core: {core_classes.length}")
236 # Colorize core color for typechecks
237 colorize
(ga
, ctab
, crown_classes
, 0)
239 # Compute tables for typechecks
242 var cc
= ga
.compiled_classes
[c
.global
]
243 if core_classes
.has
(c
) then
244 # For core classes, just build the table
245 build_tables_in
(cc
.class_table
, ga
, c
, ctab
)
246 if maxcolor
< cc
.class_table
.length
then maxcolor
= cc
.class_table
.length
248 # For other classes, it's easier: just append to the parent tables
249 var sc
= c
.cshe
.direct_greaters
.first
250 var scc
= ga
.compiled_classes
[sc
.global
]
251 assert cc
.class_table
.is_empty
252 cc
.class_table
.add_all
(scc
.class_table
)
253 var bc
= c
.global
.intro
254 assert bc
isa MMSrcLocalClass
255 var colpos
= bc
.class_color_pos
256 var colposcolor
= cc
.class_table
.length
257 ga
.color
(colpos
) = colposcolor
258 cc
.class_table
.add
(colpos
)
259 if maxcolor
< colposcolor
then maxcolor
= colposcolor
262 ga
.max_class_table_length
= maxcolor
+ 1
264 # Fill class table and instance tables pools
266 var cc
= ga
.compiled_classes
[c
.global
]
267 var cte
= cc
.class_layout
268 var ite
= cc
.instance_layout
269 for sc
in c
.crhe
.greaters_and_self
do
270 if sc
isa MMSrcLocalClass then
271 cte
.add
(sc
, sc
.class_layout
)
272 ite
.add
(sc
, sc
.instance_layout
)
276 if core_classes
.has
(c
) then
277 if cte
.length
> 0 then
280 if ite
.length
> 0 then
286 # Colorize all elements in pools tables
287 colorize
(ga
, ctab
, crown_classes
, maxcolor
+1)
288 colorize
(ga
, itab
, crown_classes
, 0)
290 # Build class and instance tables now things are colored
291 ga
.max_class_table_length
= 0
293 var cc
= ga
.compiled_classes
[c
.global
]
294 if core_classes
.has
(c
) then
295 # For core classes, just build the table
296 build_tables_in
(cc
.class_table
, ga
, c
, ctab
)
297 build_tables_in
(cc
.instance_table
, ga
, c
, itab
)
299 # For other classes, it's easier: just append to the parent tables
300 var sc
= c
.cshe
.direct_greaters
.first
301 var scc
= ga
.compiled_classes
[sc
.global
]
303 cc
.class_table
.add_all
(scc
.class_table
)
304 var bc
= c
.global
.intro
305 assert bc
isa MMSrcLocalClass
306 var colpos
= bc
.class_color_pos
307 cc
.class_table
[ga
.color
(colpos
)] = colpos
308 while cc
.class_table
.length
<= maxcolor
do
309 cc
.class_table
.add
(null)
311 append_to_table
(ga
, cc
.class_table
, cc
.class_layout
)
312 assert cc
.instance_table
.is_empty
313 cc
.instance_table
.add_all
(scc
.instance_table
)
314 append_to_table
(ga
, cc
.instance_table
, cc
.instance_layout
)
321 private meth append_to_table
(cc
: ColorContext, table
: Array[TableElt], cmp
: TableEltComposite)
323 for j
in [0..cmp
.length
[ do
325 cc
.color
(e
) = table
.length
330 private meth build_tables_in
(table
: Array[TableElt], ga
: GlobalAnalysis, c
: MMLocalClass, elts
: Array[TableElt])
332 var tab
= new HashMap[Int, TableElt]
335 if e
.is_related_to
(c
) then
336 var col
= ga
.color
(e
)
337 var l
= col
+ e
.length
346 if tab
.has_key
(i
) then
348 for j
in [0..e
.length
[ do
360 meth colorize
(ga
: GlobalAnalysis, elts
: Array[TableElt], classes
: Collection[MMLocalClass], startcolor
: Int)
362 var colors
= new HashMap[Int, Array[TableElt]]
363 var rel_classes
= new Array[MMLocalClass]
367 if ga
.has_color
(e
) then
372 if e
.is_related_to
(c
) then
376 var trycolor
= startcolor
377 while trycolor
!= color
do
379 for c
in rel_classes
do
382 if colors
.has_key
(trycolor
+ idx
) and not free_color
(colors
[trycolor
+ idx
], c
) then
383 trycolor
= trycolor
+ idx
+ 1
393 for idx
in [0..len
[ do
394 if colors
.has_key
(color
+ idx
) then
395 colors
[color
+ idx
].add
(e
)
397 colors
[color
+ idx
] = [e
]
403 private meth free_color
(es
: Array[TableElt], c
: MMLocalClass): Bool
406 if e2
.is_related_to
(c
) then
413 # Compile module and class tables
414 meth compile_tables_to_c
(v
: GlobalCompilerVisitor)
416 for m
in mhe
.greaters_and_self
do
417 assert m
isa MMSrcModule
418 m
.compile_local_table_to_c
(v
)
421 for c
in local_classes
do
422 c
.compile_tables_to_c
(v
)
424 var s
= new Buffer.from
("classtable_t TAG2VFT[4] = \{NULL")
425 for t
in ["Int","Char","Bool"] do
426 if has_global_class_named
(t
.to_symbol
) then
427 s
.append
(", (const classtable_t)VFT_{t}")
436 # Declare class table (for _sep.h)
437 meth declare_class_tables_to_c
(v
: GlobalCompilerVisitor)
439 for c
in local_classes
do
440 if c
.global
.module == self then
441 c
.declare_tables_to_c
(v
)
446 # Compile main part (for _table.c)
447 meth compile_main_part
(v
: GlobalCompilerVisitor)
449 v
.add_instr
("int main(int argc, char **argv) \{")
451 v
.add_instr
("prepare_signals();")
452 v
.add_instr
("glob_argc = argc; glob_argv = argv;")
453 var sysname
= once
"Sys".to_symbol
454 if not has_global_class_named
(sysname
) then
457 var sys
= class_by_name
(sysname
)
458 # var initm = sys.select_method(once "init".to_symbol)
459 var mainm
= sys
.select_method
(once
"main".to_symbol
)
460 if mainm
== null then
463 #v.add_instr("G_sys = NEW_{initm.cname}();")
464 v
.add_instr
("G_sys = NEW_Sys();")
465 v
.add_instr
("{mainm.cname}(G_sys);")
468 v
.add_instr
("return 0;")
474 meth compile_mod_to_c
(v
: GlobalCompilerVisitor)
476 v
.add_decl
("extern const char *LOCATE_{name};")
477 if not v
.tc
.global
then
478 v
.add_decl
("extern const int SFT_{name}[];")
481 for e
in _local_table
do
484 value
= "{e.value(v.global_analysis)}"
486 value
= "SFT_{name}[{i}]"
489 e
.compile_macros
(v
, value
)
491 for c
in src_local_classes
do
492 for pg
in c
.global_properties
do
494 if p
.local_class
== c
then
495 p
.compile_property_to_c
(v
)
497 if pg
.is_init_for
(c
) then
498 # Declare constructors
499 var params
= new Array[String]
500 for i
in [0..p
.signature
.arity
[ do
501 params
.add
("val_t p{i}")
503 v
.add_decl
("val_t NEW_{c}_{p.global.intro.cname}({params.join(", ")});")
509 # Compile module file for the current module
510 meth compile_local_table_to_c
(v
: GlobalCompilerVisitor)
512 v
.add_instr
("const char *LOCATE_{name} = \"{filename}\
";")
514 if v
.tc
.global
or _local_table
.is_empty
then
518 v
.add_instr
("const int SFT_{name}[{_local_table.length}] = \{")
520 for e
in _local_table
do
521 v
.add_instr
(e
.value
(v
.global_analysis
) + ",")
528 ###############################################################################
530 # An element of a class, an instance or a module table
531 abstract class AbsTableElt
532 # Compile the macro needed to use the element and other related elements
533 meth compile_macros
(v
: GlobalCompilerVisitor, value
: String) is abstract
536 # An element of a class or an instance table
537 # Such an elements represent method function pointers, attribute values, etc.
538 abstract class TableElt
540 # Is the element conflict to class `c' (used for coloring)
541 meth is_related_to
(c
: MMLocalClass): Bool is abstract
543 # Number of sub-elements. 1 if none
544 meth length
: Int do return 1
546 # Access the ith subelement.
547 meth item
(i
: Int): TableElt do return self
549 # Return the value of the element for a given class
550 meth compile_to_c
(v
: GlobalCompilerVisitor, c
: MMLocalClass): String is abstract
553 # An element of a module table
554 # Such an elements represent colors or identifiers
555 abstract class ModuleTableElt
557 # Return the value of the element once the global analisys is performed
558 meth value
(ga
: GlobalAnalysis): String is abstract
561 # An element of a module table that represents a group of TableElt defined in the same local class
562 class ModuleTableEltGroup
563 special ModuleTableElt
564 readable attr _elements
: Array[TableElt] = new Array[TableElt]
566 redef meth value
(ga
) do return "{ga.color(_elements.first)} /* Group of ? */"
567 redef meth compile_macros
(v
, value
)
570 for e
in _elements
do
571 e
.compile_macros
(v
, "{value} + {i}")
577 # An element that represents a class property
578 abstract class TableEltProp
580 attr _property
: MMLocalProperty
582 init(p
: MMLocalProperty)
588 # An element that represents a function pointer to a global method
591 redef meth compile_macros
(v
, value
)
593 var pg
= _property
.global
594 v
.add_decl
("#define {pg.meth_call}(recv) (({pg.intro.cname}_t)CALL((recv), ({value})))")
597 redef meth compile_to_c
(v
, c
)
599 var p
= c
[_property
.global
]
604 # An element that represents a function pointer to the super method of a local method
607 redef meth compile_macros
(v
, value
)
610 v
.add_decl
("#define {p.super_meth_call}(recv) (({p.cname}_t)CALL((recv), ({value})))")
613 redef meth compile_to_c
(v
, c
)
615 var pc
= _property
.local_class
616 var g
= _property
.global
617 var lin
= c
.che
.linear_extension
620 #print "{c.module}::{c} for {pc.module}::{pc}::{_property} try {s.module}:{s}"
623 else if found
and c
.che
< s
then
624 if s
.has_global_property
(g
) then
625 #print "found {s.module}::{s}::{p}"
635 # An element that represents the value stored for a global attribute
638 redef meth compile_macros
(v
, value
)
640 var pg
= _property
.global
641 v
.add_decl
("#define {pg.attr_access}(recv) ATTR(recv, ({value}))")
644 redef meth compile_to_c
(v
, c
)
646 var ga
= v
.global_analysis
647 var p
= c
[_property
.global
]
648 return "/* {ga.color(self)}: Attribute {c}::{p} */"
652 # An element representing a class information
653 class AbsTableEltClass
655 # The local class where the information comes from
656 attr _local_class
: MMLocalClass
658 init(c
: MMLocalClass)
663 # The C macro name refering the value
664 meth symbol
: String is abstract
666 redef meth compile_macros
(v
, value
)
668 v
.add_decl
("#define {symbol} ({value})")
672 # An element of a class table representing a class information
675 special AbsTableEltClass
676 redef meth is_related_to
(c
)
678 var bc
= c
.module[_local_class
.global
]
683 # An element representing the id of a class in a module table
684 class TableEltClassId
685 special ModuleTableElt
686 special AbsTableEltClass
687 redef meth symbol
do return _local_class
.global
.id_id
691 return "{ga.compiled_classes[_local_class.global].id} /* Id of {_local_class} */"
695 # An element representing the constructor marker position in a class table
696 class TableEltClassInitTable
697 special TableEltClass
698 redef meth symbol
do return _local_class
.global
.init_table_pos_id
700 redef meth compile_to_c
(v
, c
)
702 var ga
= v
.global_analysis
703 var cc
= ga
.compiled_classes
[_local_class
.global
]
704 var linext
= c
.cshe
.reverse_linear_extension
706 while linext
[i
].global
!= _local_class
.global
do
709 return "{i} /* {ga.color(self)}: {c} < {cc.local_class}: superclass init_table position */"
713 # An element used for a cast
714 # Note: this element is both a TableElt and a ModuleTableElt.
715 # At the TableElt offset, there is the id of the super-class
716 # At the ModuleTableElt offset, there is the TableElt offset (ie. the color of the super-class).
717 class TableEltClassColor
718 special TableEltClass
719 special ModuleTableElt
720 redef meth symbol
do return _local_class
.global
.color_id
724 return "{ga.color(self)} /* Color of {_local_class} */"
727 redef meth compile_to_c
(v
, c
)
729 var ga
= v
.global_analysis
730 var cc
= ga
.compiled_classes
[_local_class
.global
]
731 return "{cc.id} /* {ga.color(self)}: {c} < {cc.local_class}: superclass typecheck marker */"
735 # A Group of elements introduced in the same global-class that are colored together
736 class TableEltComposite
738 attr _table
: Array[TableElt]
739 attr _cc
: CompiledClass
740 attr _offsets
: HashMap[MMLocalClass, Int]
741 redef meth length
do return _table
.length
742 redef meth is_related_to
(c
) do return c
.cshe
<= _cc
.local_class
744 meth add
(c
: MMLocalClass, tab
: Array[TableElt])
746 _offsets
[c
] = _table
.length
750 redef meth item
(i
) do return _table
[i
]
752 redef meth compile_to_c
(v
, c
) do abort
754 init(cc
: CompiledClass)
757 _table
= new Array[TableElt]
758 _offsets
= new HashMap[MMLocalClass, Int]
762 # The element that represent the class id
763 class TableEltClassSelfId
765 redef meth is_related_to
(c
) do return true
766 redef meth compile_to_c
(v
, c
)
768 var ga
= v
.global_analysis
769 return "{v.global_analysis.compiled_classes[c.global].id} /* {ga.color(self)}: Identity */"
774 class TableEltVftPointer
776 redef meth is_related_to
(c
) do return true
777 redef meth compile_to_c
(v
, c
)
779 var ga
= v
.global_analysis
780 return "/* {ga.color(self)}: Pointer to the classtable */"
784 ###############################################################################
786 # Used to sort local class in a deterministic total order
787 # The total order superset the class refinement and the class specialisation relations
789 special AbstractSorter[MMLocalClass]
790 redef meth compare
(a
, b
) do return a
.compare
(b
)
794 redef class MMLocalClass
795 # Comparaison in a total order that superset the class refinement and the class specialisation relations
796 meth compare
(b
: MMLocalClass): Int
801 else if a
.module.mhe
< b
.module then
803 else if b
.module.mhe
< a
.module then
813 return b
.name
.to_s
<=> a
.name
.to_s
817 # Declaration and macros related to the class table
818 meth declare_tables_to_c
(v
: GlobalCompilerVisitor)
821 var pi
= primitive_info
822 v
.add_decl
("extern const classtable_elt_t VFT_{name}[];")
824 # v.add_decl("val_t NEW_{name}(void);")
825 else if not pi
.tagged
then
827 var tbox
= "struct TBOX_{name}"
828 v
.add_decl
("{tbox} \{ const classtable_elt_t * vft; {t} val;};")
829 v
.add_decl
("val_t BOX_{name}({t} val);")
830 v
.add_decl
("#define UNBOX_{name}(x) ((({tbox} *)(VAL2OBJ(x)))->val)")
834 # Compilation of table and new (or box)
835 meth compile_tables_to_c
(v
: GlobalCompilerVisitor)
837 var cc
= v
.global_analysis
.compiled_classes
[self.global
]
838 var ctab
= cc
.class_table
839 var clen
= ctab
.length
840 if v
.global_analysis
.max_class_table_length
> ctab
.length
then
841 clen
= v
.global_analysis
.max_class_table_length
844 v
.add_instr
("const classtable_elt_t VFT_{name}[{clen}] = \{")
848 v
.add_instr
("\{0} /* Class Hole :( */,")
850 v
.add_instr
("\{(bigint) {e.compile_to_c(v, self)}},")
853 if clen
> ctab
.length
then
854 v
.add_instr
("\{0},"*(clen-ctab
.length
))
858 var itab
= cc
.instance_table
861 v
.add_instr
("/* Instance Hole :( */")
863 v
.add_instr
(e
.compile_to_c
(v
, self))
867 var pi
= primitive_info
869 v
.cfc
= new CFunctionContext(v
)
870 v
.nmc
= new NitMethodContext(null)
871 var s
= "val_t NEW_{name}(void)"
872 v
.add_instr
(s
+ " \{")
877 var self_var
= new ParamVariable(null, null)
878 var self_var_cname
= v
.cfc
.register_variable
(self_var
)
879 v
.nmc
.method_params
= [self_var
]
881 v
.add_instr
("obj_t obj;")
882 v
.add_instr
("obj = alloc(sizeof(val_t) * {itab.length});")
883 v
.add_instr
("obj->vft = (classtable_elt_t*)VFT_{name};")
884 v
.add_assignment
(self_var_cname
, "OBJ2VAL(obj)")
886 for g
in global_properties
do
888 var t
= p
.signature
.return_type
889 if p
isa MMAttribute and t
!= null then
890 # FIXME: Not compatible with sep compilation
891 assert p
isa MMSrcAttribute
893 assert np
isa AAttrPropdef
896 var e
= ne
.compile_expr
(v
)
897 v
.add_instr
("{p.global.attr_access}(obj) = {e};")
901 v
.add_instr
("return OBJ2VAL(obj);")
902 v
.cfc
.generate_var_decls
903 ctx_old
.append
(v
.ctx
)
909 var s
= "void CHECKNEW_{name}(val_t self, char *from)"
910 v
.add_instr
(s
+ " \{")
914 for g
in global_properties
do
916 var t
= p
.signature
.return_type
917 if p
isa MMAttribute and t
!= null and not t
.is_nullable
and v
.tc
.opt_warn
.value
> 0 then
918 v
.add_instr
("if ({p.global.attr_access}(self) == NIT_NULL) fprintf(stderr, \"Uninitialized attribute
%s at
%s
.\\n\
", \"{p.full_name}\
", from);")
921 ctx_old
.append
(v
.ctx
)
926 var init_table_size
= cshe
.greaters
.length
+ 1
927 var init_table_decl
= "int init_table[{init_table_size}] = \{0{", 0" * (init_table_size-1)}};"
929 for g
in global_properties
do
931 # FIXME skip invisible constructors
932 if not p
.global
.is_init_for
(self) then continue
933 var params
= new Array[String]
935 for i
in [0..p
.signature
.arity
[ do
936 params
.add
("val_t p{i}")
939 args
.add
("init_table")
940 var s
= "val_t NEW_{self}_{p.global.intro.cname}({params.join(", ")}) \{"
943 v
.add_instr
(init_table_decl
)
944 v
.add_instr
("val_t self = NEW_{name}();")
945 v
.add_instr
("{p.cname}({args.join(", ")});")
946 v
.add_instr
("CHECKNEW_{name}(self, \"{p.full_name} for {self}\
");")
947 v
.add_instr
("return self;")
951 else if not pi
.tagged
then
953 var tbox
= "struct TBOX_{name}"
954 v
.add_instr
("val_t BOX_{name}({t} val) \{")
956 v
.add_instr
("{tbox} *box = ({tbox}*)alloc(sizeof({tbox}));")
957 v
.add_instr
("box->vft = VFT_{name};")
958 v
.add_instr
("box->val = val;")
959 v
.add_instr
("return OBJ2VAL(box);")