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]
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)
67 _compiled_classes
= new HashMap[MMGlobalClass, CompiledClass]
72 class GlobalCompilerVisitor
73 special CompilerVisitor
74 # The global analysis result
75 readable attr _global_analysis
: GlobalAnalysis
76 init(m
: MMSrcModule, tc
: ToolContext, ga
: GlobalAnalysis)
83 # A compiled class is a class in a program
86 # The corresponding local class in the main module of the prgram
87 readable attr _local_class
: MMLocalClass
89 # The identifier of the class
90 readable writable attr _id
: Int
92 # The full class table of the class
93 readable writable attr _class_table
: Array[TableElt]
95 # The full instance table of the class
96 readable writable attr _instance_table
: Array[TableElt]
98 # The proper class table part (no superclasses but all refinements)
99 readable writable attr _class_layout
: TableEltComposite
101 # The proper instance table part (no superclasses but all refinements)
102 readable writable attr _instance_layout
: TableEltComposite
104 init(c
: MMLocalClass) do _local_class
= c
107 redef class MMSrcLocalClass
108 # The table element of the subtype check
109 readable attr _class_color_pos
: TableEltClassColor
111 # The proper local class table part (nor superclasses nor refinments)
112 readable attr _class_layout
: Array[TableElt]
114 # The proper local instance table part (nor superclasses nor refinments)
115 readable attr _instance_layout
: Array[TableElt]
117 # Build the local layout of the class and feed the module table
118 meth build_layout_in
(tc
: ToolContext, module_table
: Array[ModuleTableElt])
120 var clt
= new Array[TableElt]
122 var ilt
= new Array[TableElt]
123 _instance_layout
= ilt
125 if global
.intro
== self then
126 module_table
.add
(new TableEltClassId(self))
127 _class_color_pos
= new TableEltClassColor(self)
128 module_table
.add
(_class_color_pos
)
129 clt
.add
(new TableEltClassInitTable(self))
131 for p
in src_local_properties
do
133 if pg
.intro
== p
then
134 if p
isa MMSrcAttribute then
135 ilt
.add
(new TableEltAttr(p
))
136 else if p
isa MMSrcMethod then
137 clt
.add
(new TableEltMeth(p
))
140 if p
isa MMSrcMethod and p
.need_super
then
141 clt
.add
(new TableEltSuper(p
))
145 if not ilt
.is_empty
then
146 var teg
= new ModuleTableEltGroup
147 teg
.elements
.append
(ilt
)
148 module_table
.add
(teg
)
151 if not clt
.is_empty
then
152 var teg
= new ModuleTableEltGroup
153 teg
.elements
.append
(clt
)
154 module_table
.add
(teg
)
159 redef class MMSrcModule
160 # The local table of the module (refers things introduced in the module)
161 attr _local_table
: Array[ModuleTableElt]
163 # Builds the local tables and local classes layouts
164 meth local_analysis
(tc
: ToolContext)
166 var lt
= new Array[ModuleTableElt]
168 for c
in src_local_classes
do
169 c
.build_layout_in
(tc
, lt
)
173 # Do the complete global analysis
174 meth global_analysis
(cctx
: ToolContext): GlobalAnalysis
176 #print "Do the complete global analysis"
177 var ga
= new GlobalAnalysis(self)
178 var smallest_classes
= new Array[MMLocalClass]
179 var global_properties
= new HashSet[MMGlobalProperty]
180 var ctab
= new Array[TableElt]
181 var itab
= new Array[TableElt]
183 ctab
.add
(new TableEltClassSelfId)
184 itab
.add
(new TableEltVftPointer)
189 # We have to work on ALL the classes of the module
190 var classes
= new Array[MMLocalClass]
191 for c
in local_classes
do
192 c
.compute_super_classes
195 (new ClassSorter).sort
(classes
)
198 # Finish processing the class (if invisible)
200 c
.inherit_global_properties
202 # Associate a CompiledClass to the class
203 var cc
= new CompiledClass(c
)
204 ga
.compiled_classes
[c
.global
] = cc
206 # Assign a unique class identifier
207 # (negative are for primitive classes)
210 if c
.primitive_info
!= null then
212 pclassid
= pclassid
- 4
215 classid
= classid
+ 4
218 # Register is the class is a leaf
219 if c
.cshe
.direct_smallers
.is_empty
then
220 smallest_classes
.add
(c
)
223 # Store the colortableelt in the class table pool
224 var bc
= c
.global
.intro
225 assert bc
isa MMSrcLocalClass
226 ctab
.add
(bc
.class_color_pos
)
229 # Compute core and crown classes for colorization
230 var crown_classes
= new HashSet[MMLocalClass]
231 var core_classes
= new HashSet[MMLocalClass]
232 for c
in smallest_classes
do
233 while c
.cshe
.direct_greaters
.length
== 1 do
234 c
= c
.cshe
.direct_greaters
.first
237 core_classes
.add_all
(c
.cshe
.greaters_and_self
)
239 #print("nbclasses: {classes.length} leaves: {smallest_classes.length} crown: {crown_classes.length} core: {core_classes.length}")
241 # Colorize core color for typechecks
242 colorize
(ga
, ctab
, crown_classes
, 0)
244 # Compute tables for typechecks
247 var cc
= ga
.compiled_classes
[c
.global
]
248 if core_classes
.has
(c
) then
249 # For core classes, just build the table
250 cc
.class_table
= build_tables
(ga
, c
, ctab
)
251 if maxcolor
< cc
.class_table
.length
then maxcolor
= cc
.class_table
.length
253 # For other classes, it's easier: just append to the parent tables
254 var sc
= c
.cshe
.direct_greaters
.first
255 var scc
= ga
.compiled_classes
[sc
.global
]
256 cc
.class_table
= scc
.class_table
.to_a
257 var bc
= c
.global
.intro
258 assert bc
isa MMSrcLocalClass
259 var colpos
= bc
.class_color_pos
260 var colposcolor
= cc
.class_table
.length
261 ga
.color
(colpos
) = colposcolor
262 cc
.class_table
.add
(colpos
)
263 if maxcolor
< colposcolor
then maxcolor
= colposcolor
266 ga
.max_class_table_length
= maxcolor
+ 1
268 # Fill class table and instance tables pools
270 var cc
= ga
.compiled_classes
[c
.global
]
271 var cte
= new TableEltComposite(cc
)
272 var ite
= new TableEltComposite(cc
)
273 for sc
in c
.crhe
.greaters_and_self
do
274 if sc
isa MMSrcLocalClass then
275 cte
.add
(sc
, sc
.class_layout
)
276 ite
.add
(sc
, sc
.instance_layout
)
278 cc
.class_layout
= cte
279 cc
.instance_layout
= ite
282 if core_classes
.has
(c
) then
283 if cte
.length
> 0 then
286 if ite
.length
> 0 then
292 # Colorize all elements in pools tables
293 colorize
(ga
, ctab
, crown_classes
, maxcolor
+1)
294 colorize
(ga
, itab
, crown_classes
, 0)
296 # Build class and instance tables now things are colored
297 ga
.max_class_table_length
= 0
299 var cc
= ga
.compiled_classes
[c
.global
]
300 if core_classes
.has
(c
) then
301 # For core classes, just build the table
302 cc
.class_table
= build_tables
(ga
, c
, ctab
)
303 cc
.instance_table
= build_tables
(ga
, c
, itab
)
305 # For other classes, it's easier: just append to the parent tables
306 var sc
= c
.cshe
.direct_greaters
.first
307 var scc
= ga
.compiled_classes
[sc
.global
]
308 cc
.class_table
= scc
.class_table
.to_a
309 var bc
= c
.global
.intro
310 assert bc
isa MMSrcLocalClass
311 var colpos
= bc
.class_color_pos
312 cc
.class_table
[ga
.color
(colpos
)] = colpos
313 while cc
.class_table
.length
<= maxcolor
do
314 cc
.class_table
.add
(null)
316 append_to_table
(ga
, cc
.class_table
, cc
.class_layout
)
317 cc
.instance_table
= scc
.instance_table
.to_a
318 append_to_table
(ga
, cc
.instance_table
, cc
.instance_layout
)
325 private meth append_to_table
(cc
: ColorContext, table
: Array[TableElt], cmp
: TableEltComposite)
327 for j
in [0..cmp
.length
[ do
329 cc
.color
(e
) = table
.length
334 private meth build_tables
(ga
: GlobalAnalysis, c
: MMLocalClass, elts
: Array[TableElt]): Array[TableElt]
336 var tab
= new HashMap[Int, TableElt]
339 if e
.is_related_to
(c
) then
340 var col
= ga
.color
(e
)
341 var l
= col
+ e
.length
348 var res
= new Array[TableElt]
351 if tab
.has_key
(i
) then
353 for j
in [0..e
.length
[ do
366 meth colorize
(ga
: GlobalAnalysis, elts
: Array[TableElt], classes
: Collection[MMLocalClass], startcolor
: Int)
368 var colors
= new HashMap[Int, Array[TableElt]]
369 var rel_classes
= new Array[MMLocalClass]
373 if ga
.has_color
(e
) then
378 if e
.is_related_to
(c
) then
382 var trycolor
= startcolor
383 while trycolor
!= color
do
385 for c
in rel_classes
do
388 if colors
.has_key
(trycolor
+ idx
) and not free_color
(colors
[trycolor
+ idx
], c
) then
389 trycolor
= trycolor
+ idx
+ 1
399 for idx
in [0..len
[ do
400 if colors
.has_key
(color
+ idx
) then
401 colors
[color
+ idx
].add
(e
)
403 colors
[color
+ idx
] = [e
]
409 private meth free_color
(es
: Array[TableElt], c
: MMLocalClass): Bool
412 if e2
.is_related_to
(c
) then
419 # Compile module and class tables
420 meth compile_tables_to_c
(v
: GlobalCompilerVisitor)
422 for m
in mhe
.greaters_and_self
do
423 assert m
isa MMSrcModule
424 m
.compile_local_table_to_c
(v
)
427 for c
in local_classes
do
428 c
.compile_tables_to_c
(v
)
430 var s
= new Buffer.from
("classtable_t TAG2VFT[4] = \{NULL")
431 for t
in ["Int","Char","Bool"] do
432 if has_global_class_named
(t
.to_symbol
) then
433 s
.append
(", (const classtable_t)VFT_{t}")
442 # Declare class table (for _sep.h)
443 meth declare_class_tables_to_c
(v
: GlobalCompilerVisitor)
445 for c
in local_classes
do
446 if c
.global
.module == self then
447 c
.declare_tables_to_c
(v
)
452 # Compile main part (for _table.c)
453 meth compile_main_part
(v
: GlobalCompilerVisitor)
455 v
.add_instr
("int main(int argc, char **argv) \{")
457 v
.add_instr
("prepare_signals();")
458 v
.add_instr
("glob_argc = argc; glob_argv = argv;")
459 var sysname
= once
"Sys".to_symbol
460 if not has_global_class_named
(sysname
) then
463 var sys
= class_by_name
(sysname
)
464 # var initm = sys.select_method(once "init".to_symbol)
465 var mainm
= sys
.select_method
(once
"main".to_symbol
)
466 if mainm
== null then
469 #v.add_instr("G_sys = NEW_{initm.cname}();")
470 v
.add_instr
("G_sys = NEW_Sys();")
471 v
.add_instr
("{mainm.cname}(G_sys);")
474 v
.add_instr
("return 0;")
480 meth compile_mod_to_c
(v
: GlobalCompilerVisitor)
482 v
.add_decl
("extern const char *LOCATE_{name};")
483 if not v
.tc
.global
then
484 v
.add_decl
("extern const int SFT_{name}[];")
487 for e
in _local_table
do
490 value
= "{e.value(v.global_analysis)}"
492 value
= "SFT_{name}[{i}]"
495 e
.compile_macros
(v
, value
)
497 for c
in src_local_classes
do
498 for pg
in c
.global_properties
do
500 if p
.local_class
== c
then
501 p
.compile_property_to_c
(v
)
503 if pg
.is_init_for
(c
) then
504 # Declare constructors
505 var params
= new Array[String]
506 for i
in [0..p
.signature
.arity
[ do
507 params
.add
("val_t p{i}")
509 v
.add_decl
("val_t NEW_{c}_{p.global.intro.cname}({params.join(", ")});")
515 # Compile module file for the current module
516 meth compile_local_table_to_c
(v
: GlobalCompilerVisitor)
518 v
.add_instr
("const char *LOCATE_{name} = \"{filename}\
";")
520 if v
.tc
.global
or _local_table
.is_empty
then
524 v
.add_instr
("const int SFT_{name}[{_local_table.length}] = \{")
526 for e
in _local_table
do
527 v
.add_instr
(e
.value
(v
.global_analysis
) + ",")
534 ###############################################################################
536 # An element of a class, an instance or a module table
537 abstract class AbsTableElt
538 # Compile the macro needed to use the element and other related elements
539 meth compile_macros
(v
: GlobalCompilerVisitor, value
: String) is abstract
542 # An element of a class or an instance table
543 # Such an elements represent method function pointers, attribute values, etc.
544 abstract class TableElt
546 # Is the element conflict to class `c' (used for coloring)
547 meth is_related_to
(c
: MMLocalClass): Bool is abstract
549 # Number of sub-elements. 1 if none
550 meth length
: Int do return 1
552 # Access the ith subelement.
553 meth item
(i
: Int): TableElt do return self
555 # Return the value of the element for a given class
556 meth compile_to_c
(v
: GlobalCompilerVisitor, c
: MMLocalClass): String is abstract
559 # An element of a module table
560 # Such an elements represent colors or identifiers
561 abstract class ModuleTableElt
563 # Return the value of the element once the global analisys is performed
564 meth value
(ga
: GlobalAnalysis): String is abstract
567 # An element of a module table that represents a group of TableElt defined in the same local class
568 class ModuleTableEltGroup
569 special ModuleTableElt
570 readable attr _elements
: Array[TableElt] = new Array[TableElt]
572 redef meth value
(ga
) do return "{ga.color(_elements.first)} /* Group of ? */"
573 redef meth compile_macros
(v
, value
)
576 for e
in _elements
do
577 e
.compile_macros
(v
, "{value} + {i}")
583 # An element that represents a class property
584 abstract class TableEltProp
586 attr _property
: MMLocalProperty
588 init(p
: MMLocalProperty)
594 # An element that represents a function pointer to a global method
597 redef meth compile_macros
(v
, value
)
599 var pg
= _property
.global
600 v
.add_decl
("#define {pg.meth_call}(recv) (({pg.intro.cname}_t)CALL((recv), ({value})))")
603 redef meth compile_to_c
(v
, c
)
605 var p
= c
[_property
.global
]
610 # An element that represents a function pointer to the super method of a local method
613 redef meth compile_macros
(v
, value
)
616 v
.add_decl
("#define {p.super_meth_call}(recv) (({p.cname}_t)CALL((recv), ({value})))")
619 redef meth compile_to_c
(v
, c
)
621 var pc
= _property
.local_class
622 var g
= _property
.global
623 var lin
= c
.che
.linear_extension
626 #print "{c.module}::{c} for {pc.module}::{pc}::{_property} try {s.module}:{s}"
629 else if found
and c
.che
< s
then
630 if s
.has_global_property
(g
) then
631 #print "found {s.module}::{s}::{p}"
641 # An element that represents the value stored for a global attribute
644 redef meth compile_macros
(v
, value
)
646 var pg
= _property
.global
647 v
.add_decl
("#define {pg.attr_access}(recv) ATTR(recv, ({value}))")
650 redef meth compile_to_c
(v
, c
)
652 var ga
= v
.global_analysis
653 var p
= c
[_property
.global
]
654 return "/* {ga.color(self)}: Attribute {c}::{p} */"
658 # An element representing a class information
659 class AbsTableEltClass
661 # The local class where the information comes from
662 attr _local_class
: MMLocalClass
664 init(c
: MMLocalClass)
669 # The C macro name refering the value
670 meth symbol
: String is abstract
672 redef meth compile_macros
(v
, value
)
674 v
.add_decl
("#define {symbol} ({value})")
678 # An element of a class table representing a class information
681 special AbsTableEltClass
682 redef meth is_related_to
(c
)
684 var bc
= c
.module[_local_class
.global
]
689 # An element representing the id of a class in a module table
690 class TableEltClassId
691 special ModuleTableElt
692 special AbsTableEltClass
693 redef meth symbol
do return _local_class
.global
.id_id
697 return "{ga.compiled_classes[_local_class.global].id} /* Id of {_local_class} */"
701 # An element representing the constructor marker position in a class table
702 class TableEltClassInitTable
703 special TableEltClass
704 redef meth symbol
do return _local_class
.global
.init_table_pos_id
706 redef meth compile_to_c
(v
, c
)
708 var ga
= v
.global_analysis
709 var cc
= ga
.compiled_classes
[_local_class
.global
]
710 var linext
= c
.cshe
.reverse_linear_extension
712 while linext
[i
].global
!= _local_class
.global
do
715 return "{i} /* {ga.color(self)}: {c} < {cc.local_class}: superclass init_table position */"
719 # An element used for a cast
720 # Note: this element is both a TableElt and a ModuleTableElt.
721 # At the TableElt offset, there is the id of the super-class
722 # At the ModuleTableElt offset, there is the TableElt offset (ie. the color of the super-class).
723 class TableEltClassColor
724 special TableEltClass
725 special ModuleTableElt
726 redef meth symbol
do return _local_class
.global
.color_id
730 return "{ga.color(self)} /* Color of {_local_class} */"
733 redef meth compile_to_c
(v
, c
)
735 var ga
= v
.global_analysis
736 var cc
= ga
.compiled_classes
[_local_class
.global
]
737 return "{cc.id} /* {ga.color(self)}: {c} < {cc.local_class}: superclass typecheck marker */"
741 # A Group of elements introduced in the same global-class that are colored together
742 class TableEltComposite
744 attr _table
: Array[TableElt]
745 attr _cc
: CompiledClass
746 attr _offsets
: HashMap[MMLocalClass, Int]
747 redef meth length
do return _table
.length
748 redef meth is_related_to
(c
) do return c
.cshe
<= _cc
.local_class
750 meth add
(c
: MMLocalClass, tab
: Array[TableElt])
752 _offsets
[c
] = _table
.length
756 redef meth item
(i
) do return _table
[i
]
758 redef meth compile_to_c
(v
, c
) do abort
760 init(cc
: CompiledClass)
763 _table
= new Array[TableElt]
764 _offsets
= new HashMap[MMLocalClass, Int]
768 # The element that represent the class id
769 class TableEltClassSelfId
771 redef meth is_related_to
(c
) do return true
772 redef meth compile_to_c
(v
, c
)
774 var ga
= v
.global_analysis
775 return "{v.global_analysis.compiled_classes[c.global].id} /* {ga.color(self)}: Identity */"
780 class TableEltVftPointer
782 redef meth is_related_to
(c
) do return true
783 redef meth compile_to_c
(v
, c
)
785 var ga
= v
.global_analysis
786 return "/* {ga.color(self)}: Pointer to the classtable */"
790 ###############################################################################
792 # Used to sort local class in a deterministic total order
793 # The total order superset the class refinement and the class specialisation relations
795 special AbstractSorter[MMLocalClass]
796 redef meth compare
(a
, b
) do return a
.compare
(b
)
800 redef class MMLocalClass
801 # Comparaison in a total order that superset the class refinement and the class specialisation relations
802 meth compare
(b
: MMLocalClass): Int
807 else if a
.module.mhe
< b
.module then
809 else if b
.module.mhe
< a
.module then
819 return b
.name
.to_s
<=> a
.name
.to_s
823 # Declaration and macros related to the class table
824 meth declare_tables_to_c
(v
: GlobalCompilerVisitor)
827 var pi
= primitive_info
828 v
.add_decl
("extern const classtable_elt_t VFT_{name}[];")
830 # v.add_decl("val_t NEW_{name}(void);")
831 else if not pi
.tagged
then
833 var tbox
= "struct TBOX_{name}"
834 v
.add_decl
("{tbox} \{ const classtable_elt_t * vft; {t} val;};")
835 v
.add_decl
("val_t BOX_{name}({t} val);")
836 v
.add_decl
("#define UNBOX_{name}(x) ((({tbox} *)(VAL2OBJ(x)))->val)")
840 # Compilation of table and new (or box)
841 meth compile_tables_to_c
(v
: GlobalCompilerVisitor)
843 var cc
= v
.global_analysis
.compiled_classes
[self.global
]
844 var ctab
= cc
.class_table
845 var clen
= ctab
.length
846 if v
.global_analysis
.max_class_table_length
> ctab
.length
then
847 clen
= v
.global_analysis
.max_class_table_length
850 v
.add_instr
("const classtable_elt_t VFT_{name}[{clen}] = \{")
854 v
.add_instr
("\{0} /* Class Hole :( */,")
856 v
.add_instr
("\{(bigint) {e.compile_to_c(v, self)}},")
859 if clen
> ctab
.length
then
860 v
.add_instr
("\{0},"*(clen-ctab
.length
))
864 var itab
= cc
.instance_table
867 v
.add_instr
("/* Instance Hole :( */")
869 v
.add_instr
(e
.compile_to_c
(v
, self))
873 var pi
= primitive_info
875 v
.cfc
= new CFunctionContext(v
)
876 v
.nmc
= new NitMethodContext(null)
877 var s
= "val_t NEW_{name}(void)"
878 v
.add_instr
(s
+ " \{")
883 var self_var
= new ParamVariable(null, null)
884 var self_var_cname
= v
.cfc
.register_variable
(self_var
)
885 v
.nmc
.method_params
= [self_var
]
887 v
.add_instr
("obj_t obj;")
888 v
.add_instr
("obj = alloc(sizeof(val_t) * {itab.length});")
889 v
.add_instr
("obj->vft = (classtable_elt_t*)VFT_{name};")
890 v
.add_assignment
(self_var_cname
, "OBJ2VAL(obj)")
892 for g
in global_properties
do
894 var t
= p
.signature
.return_type
895 if p
isa MMAttribute and t
!= null then
896 # FIXME: Not compatible with sep compilation
897 assert p
isa MMSrcAttribute
899 assert np
isa AAttrPropdef
902 var e
= ne
.compile_expr
(v
)
903 v
.add_instr
("{p.global.attr_access}(obj) = {e};")
905 var pi
= t
.local_class
.primitive_info
906 if pi
!= null and pi
.tagged
then
907 var default
= t
.default_cvalue
908 v
.add_instr
("{p.global.attr_access}(obj) = {default};")
913 v
.add_instr
("return OBJ2VAL(obj);")
914 v
.cfc
.generate_var_decls
915 ctx_old
.append
(v
.ctx
)
920 var init_table_size
= cshe
.greaters
.length
+ 1
921 var init_table_decl
= "int init_table[{init_table_size}] = \{0{", 0" * (init_table_size-1)}};"
923 for g
in global_properties
do
925 # FIXME skip invisible constructors
926 if not p
.global
.is_init_for
(self) then continue
927 var params
= new Array[String]
929 for i
in [0..p
.signature
.arity
[ do
930 params
.add
("val_t p{i}")
933 args
.add
("init_table")
934 var s
= "val_t NEW_{self}_{p.global.intro.cname}({params.join(", ")}) \{"
937 v
.add_instr
(init_table_decl
)
938 v
.add_instr
("val_t self = NEW_{name}();")
939 v
.add_instr
("{p.cname}({args.join(", ")});")
940 v
.add_instr
("return self;")
944 else if not pi
.tagged
then
946 var tbox
= "struct TBOX_{name}"
947 v
.add_instr
("val_t BOX_{name}({t} val) \{")
949 v
.add_instr
("{tbox} *box = ({tbox}*)alloc(sizeof({tbox}));")
950 v
.add_instr
("box->vft = VFT_{name};")
951 v
.add_instr
("box->val = val;")
952 v
.add_instr
("return OBJ2VAL(box);")