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 var _colors
: HashMap[TableElt, Int] = new HashMap[TableElt, Int]
28 # The color of a table element.
29 fun color
(e
: TableElt): Int
34 # Is a table element already colored?
35 fun has_color
(e
: TableElt): Bool
37 return _colors
.has_key
(e
)
40 # Assign a color to a table element.
41 fun color
=(e
: TableElt, c
: Int)
45 for i
in [0..e
.length
[ do
46 _colors
[e
.item
(i
)] = idx
52 # All information and results of the global analysis.
55 # Associate global classes to compiled classes
56 readable var _compiled_classes
: HashMap[MMGlobalClass, CompiledClass] = new HashMap[MMGlobalClass, CompiledClass]
58 # The main module of the program globally analysed
59 readable var _module
: MMModule
61 # FIXME: do something better.
62 readable writable var _max_class_table_length
: Int = 0
64 init(module: MMSrcModule)
70 class GlobalCompilerVisitor
71 special CompilerVisitor
72 # The global analysis result
73 readable var _global_analysis
: GlobalAnalysis
74 init(m
: MMSrcModule, tc
: ToolContext, ga
: GlobalAnalysis)
81 # A compiled class is a class in a program
84 # The corresponding local class in the main module of the prgram
85 readable var _local_class
: MMLocalClass
87 # The identifier of the class
88 readable writable var _id
: Int = 0
90 # The full class table of the class
91 readable var _class_table
: Array[nullable TableElt] = new Array[nullable TableElt]
93 # The full instance table of the class
94 readable var _instance_table
: Array[nullable TableElt] = new Array[nullable TableElt]
96 # The proper class table part (no superclasses but all refinements)
97 readable writable var _class_layout
: TableEltComposite = new TableEltComposite(self)
99 # The proper instance table part (no superclasses but all refinements)
100 readable writable var _instance_layout
: TableEltComposite = new TableEltComposite(self)
102 init(c
: MMLocalClass) do _local_class
= c
105 redef class MMSrcLocalClass
106 # The table element of the subtype check
107 fun class_color_pos
: TableEltClassColor do return _class_color_pos
.as(not null)
108 var _class_color_pos
: nullable TableEltClassColor
110 # The proper local class table part (nor superclasses nor refinments)
111 readable var _class_layout
: Array[TableElt] = new Array[TableElt]
113 # The proper local instance table part (nor superclasses nor refinments)
114 readable var _instance_layout
: Array[TableElt] = new Array[TableElt]
116 # Build the local layout of the class and feed the module table
117 fun 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 var cpp
= new TableEltClassColor(self)
125 _class_color_pos
= cpp
126 module_table
.add
(cpp
)
127 clt
.add
(new TableEltClassInitTable(self))
129 for p
in src_local_properties
do
131 if pg
.intro
== p
then
132 if p
isa MMSrcAttribute then
133 ilt
.add
(new TableEltAttr(p
))
134 else if p
isa MMSrcMethod then
135 clt
.add
(new TableEltMeth(p
))
138 if p
isa MMSrcMethod and p
.need_super
then
139 clt
.add
(new TableEltSuper(p
))
143 if not ilt
.is_empty
then
144 var teg
= new ModuleTableEltGroup
145 teg
.elements
.append
(ilt
)
146 module_table
.add
(teg
)
149 if not clt
.is_empty
then
150 var teg
= new ModuleTableEltGroup
151 teg
.elements
.append
(clt
)
152 module_table
.add
(teg
)
157 redef class MMSrcModule
158 # The local table of the module (refers things introduced in the module)
159 var _local_table
: Array[ModuleTableElt] = new Array[ModuleTableElt]
161 # Builds the local tables and local classes layouts
162 fun local_analysis
(tc
: ToolContext)
164 for c
in src_local_classes
do
165 c
.build_layout_in
(tc
, _local_table
)
169 # Do the complete global analysis
170 fun global_analysis
(cctx
: ToolContext): GlobalAnalysis
172 #print "Do the complete global analysis"
173 var ga
= new GlobalAnalysis(self)
174 var smallest_classes
= new Array[MMLocalClass]
175 var global_properties
= new HashSet[MMGlobalProperty]
176 var ctab
= new Array[TableElt]
177 var itab
= new Array[TableElt]
179 ctab
.add
(new TableEltClassSelfId)
180 itab
.add
(new TableEltVftPointer)
185 # We have to work on ALL the classes of the module
186 var classes
= new Array[MMLocalClass]
187 for c
in local_classes
do
188 c
.compute_super_classes
191 (new ClassSorter).sort
(classes
)
194 # Finish processing the class (if invisible)
196 c
.inherit_global_properties
198 # Associate a CompiledClass to the class
199 var cc
= new CompiledClass(c
)
200 ga
.compiled_classes
[c
.global
] = cc
202 # Assign a unique class identifier
203 # (negative are for primitive classes)
206 if c
.primitive_info
!= null then
208 pclassid
= pclassid
- 4
211 classid
= classid
+ 4
214 # Register is the class is a leaf
215 if c
.cshe
.direct_smallers
.is_empty
then
216 smallest_classes
.add
(c
)
219 # Store the colortableelt in the class table pool
220 var bc
= c
.global
.intro
221 assert bc
isa MMSrcLocalClass
222 ctab
.add
(bc
.class_color_pos
)
225 # Compute core and crown classes for colorization
226 var crown_classes
= new HashSet[MMLocalClass]
227 var core_classes
= new HashSet[MMLocalClass]
228 for c
in smallest_classes
do
229 while c
.cshe
.direct_greaters
.length
== 1 do
230 c
= c
.cshe
.direct_greaters
.first
233 core_classes
.add_all
(c
.cshe
.greaters_and_self
)
235 #print("nbclasses: {classes.length} leaves: {smallest_classes.length} crown: {crown_classes.length} core: {core_classes.length}")
237 # Colorize core color for typechecks
238 colorize
(ga
, ctab
, crown_classes
, 0)
240 # Compute tables for typechecks
243 var cc
= ga
.compiled_classes
[c
.global
]
244 if core_classes
.has
(c
) then
245 # For core classes, just build the table
246 build_tables_in
(cc
.class_table
, ga
, c
, ctab
)
247 if maxcolor
< cc
.class_table
.length
then maxcolor
= cc
.class_table
.length
249 # For other classes, it's easier: just append to the parent tables
250 var sc
= c
.cshe
.direct_greaters
.first
251 var scc
= ga
.compiled_classes
[sc
.global
]
252 assert cc
.class_table
.is_empty
253 cc
.class_table
.add_all
(scc
.class_table
)
254 var bc
= c
.global
.intro
255 assert bc
isa MMSrcLocalClass
256 var colpos
= bc
.class_color_pos
257 var colposcolor
= cc
.class_table
.length
258 ga
.color
(colpos
) = colposcolor
259 cc
.class_table
.add
(colpos
)
260 if maxcolor
< colposcolor
then maxcolor
= colposcolor
263 ga
.max_class_table_length
= maxcolor
+ 1
265 # Fill class table and instance tables pools
267 var cc
= ga
.compiled_classes
[c
.global
]
268 var cte
= cc
.class_layout
269 var ite
= cc
.instance_layout
270 for sc
in c
.crhe
.greaters_and_self
do
271 if sc
isa MMSrcLocalClass then
272 cte
.add
(sc
, sc
.class_layout
)
273 ite
.add
(sc
, sc
.instance_layout
)
277 if core_classes
.has
(c
) then
278 if cte
.length
> 0 then
281 if ite
.length
> 0 then
287 # Colorize all elements in pools tables
288 colorize
(ga
, ctab
, crown_classes
, maxcolor
+1)
289 colorize
(ga
, itab
, crown_classes
, 0)
291 # Build class and instance tables now things are colored
292 ga
.max_class_table_length
= 0
294 var cc
= ga
.compiled_classes
[c
.global
]
295 if core_classes
.has
(c
) then
296 # For core classes, just build the table
297 build_tables_in
(cc
.class_table
, ga
, c
, ctab
)
298 build_tables_in
(cc
.instance_table
, ga
, c
, itab
)
300 # For other classes, it's easier: just append to the parent tables
301 var sc
= c
.cshe
.direct_greaters
.first
302 var scc
= ga
.compiled_classes
[sc
.global
]
304 cc
.class_table
.add_all
(scc
.class_table
)
305 var bc
= c
.global
.intro
306 assert bc
isa MMSrcLocalClass
307 var colpos
= bc
.class_color_pos
308 cc
.class_table
[ga
.color
(colpos
)] = colpos
309 while cc
.class_table
.length
<= maxcolor
do
310 cc
.class_table
.add
(null)
312 append_to_table
(ga
, cc
.class_table
, cc
.class_layout
)
313 assert cc
.instance_table
.is_empty
314 cc
.instance_table
.add_all
(scc
.instance_table
)
315 append_to_table
(ga
, cc
.instance_table
, cc
.instance_layout
)
322 private fun append_to_table
(cc
: ColorContext, table
: Array[nullable TableElt], cmp
: TableEltComposite)
324 for j
in [0..cmp
.length
[ do
326 cc
.color
(e
) = table
.length
331 private fun build_tables_in
(table
: Array[nullable TableElt], ga
: GlobalAnalysis, c
: MMLocalClass, elts
: Array[TableElt])
333 var tab
= new HashMap[Int, TableElt]
336 if e
.is_related_to
(c
) then
337 var col
= ga
.color
(e
)
338 var l
= col
+ e
.length
347 if tab
.has_key
(i
) then
349 for j
in [0..e
.length
[ do
361 fun colorize
(ga
: GlobalAnalysis, elts
: Array[TableElt], classes
: Collection[MMLocalClass], startcolor
: Int)
363 var colors
= new HashMap[Int, Array[TableElt]]
364 var rel_classes
= new Array[MMLocalClass]
368 if ga
.has_color
(e
) then
373 if e
.is_related_to
(c
) then
377 var trycolor
= startcolor
378 while trycolor
!= color
do
380 for c
in rel_classes
do
383 if colors
.has_key
(trycolor
+ idx
) and not free_color
(colors
[trycolor
+ idx
], c
) then
384 trycolor
= trycolor
+ idx
+ 1
394 for idx
in [0..len
[ do
395 if colors
.has_key
(color
+ idx
) then
396 colors
[color
+ idx
].add
(e
)
398 colors
[color
+ idx
] = [e
]
404 private fun free_color
(es
: Array[TableElt], c
: MMLocalClass): Bool
407 if e2
.is_related_to
(c
) then
414 # Compile module and class tables
415 fun compile_tables_to_c
(v
: GlobalCompilerVisitor)
417 for m
in mhe
.greaters_and_self
do
418 assert m
isa MMSrcModule
419 m
.compile_local_table_to_c
(v
)
422 for c
in local_classes
do
423 c
.compile_tables_to_c
(v
)
425 var s
= new Buffer.from
("classtable_t TAG2VFT[4] = \{NULL")
426 for t
in ["Int","Char","Bool"] do
427 if has_global_class_named
(t
.to_symbol
) then
428 s
.append
(", (const classtable_t)VFT_{t}")
437 # Declare class table (for _sep.h)
438 fun declare_class_tables_to_c
(v
: GlobalCompilerVisitor)
440 for c
in local_classes
do
441 if c
.global
.module == self then
442 c
.declare_tables_to_c
(v
)
447 # Compile main part (for _table.c)
448 fun compile_main_part
(v
: GlobalCompilerVisitor)
450 v
.add_instr
("int main(int argc, char **argv) \{")
452 v
.add_instr
("prepare_signals();")
453 v
.add_instr
("glob_argc = argc; glob_argv = argv;")
454 var sysname
= once
"Sys".to_symbol
455 if not has_global_class_named
(sysname
) then
458 var sys
= class_by_name
(sysname
)
459 var name
= once
"main".to_symbol
460 if not sys
.has_global_property_by_name
(name
) then
463 var mainm
= sys
.select_method
(name
)
464 v
.add_instr
("G_sys = NEW_Sys();")
465 v
.add_instr
("{mainm.cname}(G_sys);")
468 v
.add_instr
("return 0;")
474 fun 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 fun 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 fun 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 fun is_related_to
(c
: MMLocalClass): Bool is abstract
543 # Number of sub-elements. 1 if none
544 fun length
: Int do return 1
546 # Access the ith subelement.
547 fun item
(i
: Int): TableElt do return self
549 # Return the value of the element for a given class
550 fun 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 fun 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 var _elements
: Array[TableElt] = new Array[TableElt]
566 redef fun value
(ga
) do return "{ga.color(_elements.first)} /* Group of ? */"
567 redef fun 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 var _property
: MMLocalProperty
582 init(p
: MMLocalProperty)
588 # An element that represents a function pointer to a global method
591 redef fun 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 fun 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 fun compile_macros
(v
, value
)
610 v
.add_decl
("#define {p.super_meth_call}(recv) (({p.cname}_t)CALL((recv), ({value})))")
613 redef fun 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}"
634 # An element that represents the value stored for a global attribute
637 redef fun compile_macros
(v
, value
)
639 var pg
= _property
.global
640 v
.add_decl
("#define {pg.attr_access}(recv) ATTR(recv, ({value}))")
643 redef fun compile_to_c
(v
, c
)
645 var ga
= v
.global_analysis
646 var p
= c
[_property
.global
]
647 return "/* {ga.color(self)}: Attribute {c}::{p} */"
651 # An element representing a class information
652 class AbsTableEltClass
654 # The local class where the information comes from
655 var _local_class
: MMLocalClass
657 init(c
: MMLocalClass)
662 # The C macro name refering the value
663 fun symbol
: String is abstract
665 redef fun compile_macros
(v
, value
)
667 v
.add_decl
("#define {symbol} ({value})")
671 # An element of a class table representing a class information
674 special AbsTableEltClass
675 redef fun is_related_to
(c
)
677 var bc
= c
.module[_local_class
.global
]
682 # An element representing the id of a class in a module table
683 class TableEltClassId
684 special ModuleTableElt
685 special AbsTableEltClass
686 redef fun symbol
do return _local_class
.global
.id_id
690 return "{ga.compiled_classes[_local_class.global].id} /* Id of {_local_class} */"
694 # An element representing the constructor marker position in a class table
695 class TableEltClassInitTable
696 special TableEltClass
697 redef fun symbol
do return _local_class
.global
.init_table_pos_id
699 redef fun compile_to_c
(v
, c
)
701 var ga
= v
.global_analysis
702 var cc
= ga
.compiled_classes
[_local_class
.global
]
703 var linext
= c
.cshe
.reverse_linear_extension
705 while linext
[i
].global
!= _local_class
.global
do
708 return "{i} /* {ga.color(self)}: {c} < {cc.local_class}: superclass init_table position */"
712 # An element used for a cast
713 # Note: this element is both a TableElt and a ModuleTableElt.
714 # At the TableElt offset, there is the id of the super-class
715 # At the ModuleTableElt offset, there is the TableElt offset (ie. the color of the super-class).
716 class TableEltClassColor
717 special TableEltClass
718 special ModuleTableElt
719 redef fun symbol
do return _local_class
.global
.color_id
723 return "{ga.color(self)} /* Color of {_local_class} */"
726 redef fun compile_to_c
(v
, c
)
728 var ga
= v
.global_analysis
729 var cc
= ga
.compiled_classes
[_local_class
.global
]
730 return "{cc.id} /* {ga.color(self)}: {c} < {cc.local_class}: superclass typecheck marker */"
734 # A Group of elements introduced in the same global-class that are colored together
735 class TableEltComposite
737 var _table
: Array[TableElt]
738 var _cc
: CompiledClass
739 var _offsets
: HashMap[MMLocalClass, Int]
740 redef fun length
do return _table
.length
741 redef fun is_related_to
(c
) do return c
.cshe
<= _cc
.local_class
743 fun add
(c
: MMLocalClass, tab
: Array[TableElt])
745 _offsets
[c
] = _table
.length
749 redef fun item
(i
) do return _table
[i
]
751 redef fun compile_to_c
(v
, c
) do abort
753 init(cc
: CompiledClass)
756 _table
= new Array[TableElt]
757 _offsets
= new HashMap[MMLocalClass, Int]
761 # The element that represent the class id
762 class TableEltClassSelfId
764 redef fun is_related_to
(c
) do return true
765 redef fun compile_to_c
(v
, c
)
767 var ga
= v
.global_analysis
768 return "{v.global_analysis.compiled_classes[c.global].id} /* {ga.color(self)}: Identity */"
773 class TableEltVftPointer
775 redef fun is_related_to
(c
) do return true
776 redef fun compile_to_c
(v
, c
)
778 var ga
= v
.global_analysis
779 return "/* {ga.color(self)}: Pointer to the classtable */"
783 ###############################################################################
785 # Used to sort local class in a deterministic total order
786 # The total order superset the class refinement and the class specialisation relations
788 special AbstractSorter[MMLocalClass]
789 redef fun compare
(a
, b
) do return a
.compare
(b
)
793 redef class MMLocalClass
794 # Comparaison in a total order that superset the class refinement and the class specialisation relations
795 fun compare
(b
: MMLocalClass): Int
800 else if a
.module.mhe
< b
.module then
802 else if b
.module.mhe
< a
.module then
812 return b
.name
.to_s
<=> a
.name
.to_s
816 # Declaration and macros related to the class table
817 fun declare_tables_to_c
(v
: GlobalCompilerVisitor)
820 var pi
= primitive_info
821 v
.add_decl
("extern const classtable_elt_t VFT_{name}[];")
823 # v.add_decl("val_t NEW_{name}(void);")
824 else if not pi
.tagged
then
826 var tbox
= "struct TBOX_{name}"
827 v
.add_decl
("{tbox} \{ const classtable_elt_t * vft; {t} val;};")
828 v
.add_decl
("val_t BOX_{name}({t} val);")
829 v
.add_decl
("#define UNBOX_{name}(x) ((({tbox} *)(VAL2OBJ(x)))->val)")
833 # Compilation of table and new (or box)
834 fun compile_tables_to_c
(v
: GlobalCompilerVisitor)
836 var cc
= v
.global_analysis
.compiled_classes
[self.global
]
837 var ctab
= cc
.class_table
838 var clen
= ctab
.length
839 if v
.global_analysis
.max_class_table_length
> ctab
.length
then
840 clen
= v
.global_analysis
.max_class_table_length
843 v
.add_instr
("const classtable_elt_t VFT_{name}[{clen}] = \{")
847 v
.add_instr
("\{0} /* Class Hole :( */,")
849 v
.add_instr
("\{(bigint) {e.compile_to_c(v, self)}},")
852 if clen
> ctab
.length
then
853 v
.add_instr
("\{0},"*(clen-ctab
.length
))
857 var itab
= cc
.instance_table
860 v
.add_instr
("/* Instance Hole :( */")
862 v
.add_instr
(e
.compile_to_c
(v
, self))
866 var pi
= primitive_info
868 v
.cfc
= new CFunctionContext(v
)
869 v
.nmc
= new NitMethodContext(null)
870 var s
= "val_t NEW_{name}(void)"
871 v
.add_instr
(s
+ " \{")
876 var self_var
= new ParamVariable(once
("self".to_symbol
), null)
877 var self_var_cname
= v
.cfc
.register_variable
(self_var
)
878 v
.nmc
.method_params
= [self_var
]
880 v
.add_instr
("obj_t obj;")
881 v
.add_instr
("obj = alloc(sizeof(val_t) * {itab.length});")
882 v
.add_instr
("obj->vft = (classtable_elt_t*)VFT_{name};")
883 v
.add_assignment
(self_var_cname
, "OBJ2VAL(obj)")
885 for g
in global_properties
do
887 var t
= p
.signature
.return_type
888 if p
isa MMAttribute and t
!= null then
889 # FIXME: Not compatible with sep compilation
890 assert p
isa MMSrcAttribute
894 var e
= ne
.compile_expr
(v
)
895 v
.add_instr
("{p.global.attr_access}(obj) = {e};")
899 v
.add_instr
("return OBJ2VAL(obj);")
900 v
.cfc
.generate_var_decls
901 ctx_old
.append
(v
.ctx
)
907 var s
= "void CHECKNEW_{name}(val_t self, char *from)"
908 v
.add_instr
(s
+ " \{")
912 for g
in global_properties
do
914 var t
= p
.signature
.return_type
915 if p
isa MMAttribute and t
!= null and not t
.is_nullable
then
916 v
.add_instr
("if ({p.global.attr_access}(self) == NIT_NULL) \{ fprintf(stderr, \"Uninitialized attribute %s at %s.\\n\", \"{p.full_name}\", from
); nit_exit
(1); \
}")
919 ctx_old.append(v.ctx)
924 var init_table_size = cshe.greaters.length + 1
925 var init_table_decl = "int init_table
[{init_table_size}] = \
{0{", 0" * (init_table_size-1)}};"
927 for g in global_properties do
929 # FIXME skip invisible constructors
930 if not p.global.is_init_for(self) then continue
931 var params = new Array[String]
933 for i in [0..p.signature.arity[ do
934 params.add("val_t p
{i}")
937 args.add("init_table
")
938 var s = "val_t
NEW_{self}_
{p.global.intro.cname}({params.join(", ")}) \
{"
941 v.add_instr(init_table_decl)
942 v.add_instr("val_t
self = NEW_{name}();")
943 v.add_instr("{p.cname}({args.join(", ")});")
944 v.add_instr("CHECKNEW_{name}(self, \
"{p.full_name} for {self}\");")
945 v.add_instr("return self;")
949 else if not pi.tagged then
951 var tbox = "struct
TBOX_{name}"
952 v.add_instr("val_t
BOX_{name}({t} val
) \
{")
954 v.add_instr("{tbox} *box
= ({tbox}*)alloc
(sizeof
({tbox}));")
955 v.add_instr("box-
>vft
= VFT_{name};")
956 v.add_instr("box-
>val
= val
;")
957 v.add_instr("return OBJ2VAL(box
);")