comparison jsbackend.rhope @ 135:18a4403fe576

Javascript backend can now produce broken output. Needs fixes plus port of standard lib
author Mike Pavone <pavone@retrodev.com>
date Sun, 14 Nov 2010 03:09:49 -0500
parents e1911b2fd5cc
children fc3815b7462f
comparison
equal deleted inserted replaced
134:386f4a874821 135:18a4403fe576
112 Register Fields@JS Type[ctype,field reg:out] 112 Register Fields@JS Type[ctype,field reg:out]
113 { 113 {
114 out <- Fold[_Register Field JS[?], field reg, [ctype]Fields >>] 114 out <- Fold[_Register Field JS[?], field reg, [ctype]Fields >>]
115 } 115 }
116 116
117 Rhope Type to JS[type,p:out,array] 117
118 { 118 Type Init@JS Type[jstype,id,method reg,field reg,p:out]
119 If[[Blueprint Of[type]]=[Type Instance()]] 119 {
120 { 120 ename <- Escape Rhope Name[[jstype]Name >>,p]
121 variant <- [type]Variant >>
122 If[[[type]Name >>] = ["Array"]]
123 {
124 [("Naked","Raw Pointer")]Find[=[variant,?]]
125 {
126 /*
127 //Below code assumes that paramaterized types are implemented
128 pre param <- [[type]Params >>]Index[0] {}
129 { pre param <- Type Instance["Any Type"] }
130 [[type]Params >>]Index[1]
131 { param,param <- [pre param]Set Variant[~] }
132 { param <- Val[pre param] }
133 child type <- Rhope Type to JS[param]
134 If[[variant] = ["Naked"]]
135 {
136 out <- Val[child type]
137 array <- "[1]"
138 }{
139 out <- [child type]Append[" *"]
140 array <- ""
141 } */
142 out <- "void *"
143 array <- ""
144 }{
145 typename <- "Array"
146 }
147 primitive <- No
148 }{
149 ,regulartype <- [("Naked","Raw Pointer")]Find[=[variant,?]]
150 {
151 [("Int64","Int32","Int16","Int8")]Find[=[[type]Name >>,?]]
152 {
153 primitive <- Yes
154 [[type]Name >>]Slice[3] {}
155 { typename <- [["int"]Append[~]]Append["_t"] }
156 }{
157 ,regulartype <- [("UInt64","UInt32","UInt16","UInt8")]Find[=[[type]Name >>,?]]
158 {
159 primitive <- Yes
160 [[type]Name >>]Slice[4] {}
161 { typename <- [["uint"]Append[~]]Append["_t"] }
162 }
163 }
164 }
165
166 Val[regulartype]
167 {
168 typename <- [type]Name >>
169 primitive <- No
170 }
171 }
172 }{
173 typename <- type
174 param <- "Any Type"
175 variant <- "boxed"
176 primitive <- No
177 }
178 121
179 Val[typename] 122 [("Array", "Worker")]Find[=[[jstype]Name >>, ?]]
180 { array <- "" } 123 {
181 If[[typename] = ["Any Type"]] 124 constructor <- [[[["var t_"]Append[ename]]Append[" = "]]Append[ [("Array","Function")]Index[~] ]]Append[";\n"]
182 { 125 }{
183 out <- "struct object *" 126 constructor <- [["function t_"]Append[ename]]Append["\n{}\n"]
184 }{ 127 }
185 [("Naked","Raw Pointer")]Find[=[variant,?]] 128 out <- [[[[[constructor
186 { 129 ]Append[ [[[["t_"]Append[ename]]Append[".prototype.type_id = "]]Append[id]]Append[";\n"] ]
187 If[primitive] 130 ]Append[ [["t_"]Append[ename]]Append[".prototype.conversions = new Array();\n"] ]
188 { 131 ]Append[ [["t = new t_Blueprint;\nt.id = "]Append[id]]Append[";\n"] ]
189 prefix <- "" 132 ]Append[ [["t.construct = t_"]Append[ename]]Append[";\n"] ]
190 }{ 133 ]Append[ [["registered_types["]Append[id]]Append["] = t;\n\n"] ]
191 prefix <- "nt_"
192 }
193 }{
194 prefix <- "t_"
195 }
196
197 If[[variant]=["Naked"]]
198 {
199 postfix <- ""
200 }{
201 postfix <- " *"
202 }
203 }
204 If[primitive]
205 {
206 escaped <- Val[typename]
207 }{
208 escaped <- Escape Rhope Name[typename,p]
209 }
210 out <- [[prefix]Append[escaped]]Append[postfix]
211 }
212
213 _Type Def JS Type[text,field,p:out]
214 {
215 name <- [field]Index[0]
216 ,postfix <- Rhope Type to JS[[field]Index[1],p]
217 { type <- ["\n\t"]Append[~] }
218
219 out <- [[[[text]Append[type]]Append[" "]]Append[[Escape Rhope Name[name,p]]Append[postfix]]]Append[";"]
220 }
221
222 Type Def@JS Type[ctype,p:out]
223 {
224 If[[[[ctype]Fields >>]Length] = [1]]
225 {
226 out <- [[[[_Type Def JS Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0], p]]Append["\n} t_"]]Append[Escape Rhope Name[[ctype]Name >>,p]]]Append[";"]
227 ]Append[
228 [[[["typedef "
229 ]Append[Rhope Type to JS[ [[[ctype]Fields >>]Index[0]]Index[1],p ]]
230 ]Append[" nt_"]
231 ]Append[Escape Rhope Name[[ctype]Name >>,p]]
232 ]Append[";"] ]
233 }{
234 //HACK!!!
235 If[[[ctype]Name >>]=["Blueprint"]]
236 {
237 out <- ""
238 }{
239 [("Array","Boxed Array","Worker")]Find[=[[ctype]Name >>,?]]
240 { oend <- "\nMObject(" }
241 { oend <- "\nObject(" }
242 out <- [Fold[_Type Def JS Type[?,?,p], "OBegin", [ctype]Fields >>]]Append[ [[oend]Append[Escape Rhope Name[[ctype]Name >>,p]]]Append[")"] ]
243 }
244 }
245 }
246
247 _Type Init JS[type name,method reg,text,method,p:out]
248 {
249 out <- [[text]Append[[["\n\tadd_method(bp, "]Append[ [method reg]Method ID[method] ]]Append[ [[", MethodName("]Append[Escape Rhope Name[method,p]]]Append[[","]Append[Escape Rhope Name[type name,p]]]]]]Append["));"]
250 }
251
252 _Type Init JS Field[type name,field reg,text,field,p:out]
253 {
254 fname <- [field]Index[0]
255 out <- [[[[text]Append[[["\n\tadd_getter(bp, "]Append[ String[[field reg]Field ID[fname]] ]]Append[ [[", MethodName("]Append[Escape Rhope Name[[fname]Append[" >>"],p]]]Append[[","]Append[Escape Rhope Name[type name,p]]]]]]Append["));"]
256 ]Append[[["\n\tadd_setter(bp, "]Append[ String[[field reg]Field ID[fname]] ]]Append[ [[", MethodName("]Append[Escape Rhope Name[[fname]Append[" <<"],p]]]Append[[","]Append[Escape Rhope Name[type name,p]]]]]]Append["));"]
257 }
258
259 Type Init@JS Type[ctype,id,method reg,field reg,p:out]
260 {
261 [("Array","Boxed Array", "Worker")]Find[=[[ctype]Name >>, ?]]
262 { size <- "-1" }
263 {
264 [("Int64","Int32","Int16","Int8")]Find[=[[ctype]Name >>, ?]]
265 {
266 [[ctype]Name >>]Slice[3] {}
267 { typename <- [["int"]Append[~]]Append["_t"] }
268 }{
269 [("UInt64","UInt32","UInt16","UInt8")]Find[=[[ctype]Name >>, ?]]
270 {
271 [[ctype]Name >>]Slice[4] {}
272 { typename <- [["uint"]Append[~]]Append["_t"] }
273 }{
274 If[[[ctype]Name >>]=["Blueprint"]]
275 { typename <- "blueprint *" }
276 {
277 If[[[ctype]Name >>]=["Boolean"]]
278 { typename <- "int32_t" }
279 { typename <- ["nt_"]Append[Escape Rhope Name[[ctype]Name >>,p]] }
280 }
281 }
282 }
283 size <- [["sizeof("]Append[typename]]Append[")"]
284 }
285 start <- [["\tbp = register_type_byid("
286 ]Append[id]
287 ]Append[
288 [[", "]Append[size]
289 ]Append[
290 [", (special_func)"]Append[
291 [
292 [[[[Escape Rhope Name[[ctype]Init >>,p]
293 ]Append[", (special_func)"]
294 ]Append[Escape Rhope Name[[ctype]Copy >> ,p]]
295 ]Append[", (special_func)"]
296 ]Append[Escape Rhope Name[[ctype]Cleanup >>,p]]
297 ]Append[");"]]] ]
298 out <- Val[start]//Fold[[["_Type Init JS Field"]Set Input[0, [ctype]Name >>]]Set Input[1, field reg], Fold[[["_Type Init JS"]Set Input[0, [ctype]Name >>]]Set Input[1, method reg], start, [ctype]Methods >>], [ctype]Fields >>]
299 } 134 }
300 135
301 Blueprint JS Type Registry 136 Blueprint JS Type Registry
302 { 137 {
303 Lookup 138 Lookup
307 } 142 }
308 143
309 JS Type Registry[p:out] 144 JS Type Registry[p:out]
310 { 145 {
311 out <- [[[[Build[JS Type Registry()]]Lookup << [ 146 out <- [[[[Build[JS Type Registry()]]Lookup << [
312 [[[[[[[[[[[[[[[[[[[Dictionary[] 147 [[[[[[[[[[[[[[[[[[Dictionary[]
313 ]Set["UInt8", "TYPE_UINT8"] //1 148 ]Set["UInt8", "TYPE_UINT8"] //1
314 ]Set["UInt16", "TYPE_UINT16"] //2 149 ]Set["UInt16", "TYPE_UINT16"] //2
315 ]Set["UInt32", "TYPE_UINT32"] //3 150 ]Set["UInt32", "TYPE_UINT32"] //3
316 ]Set["UInt64", "TYPE_UINT64"] //4 151 ]Set["UInt64", "TYPE_UINT64"] //4
317 ]Set["Int8", "TYPE_INT8"] //5 152 ]Set["Int8", "TYPE_INT8"] //5
319 ]Set["Int32", "TYPE_INT32"] //7 154 ]Set["Int32", "TYPE_INT32"] //7
320 ]Set["Int64", "TYPE_INT64"] //8 155 ]Set["Int64", "TYPE_INT64"] //8
321 ]Set["Boolean", "TYPE_BOOLEAN"] //9 156 ]Set["Boolean", "TYPE_BOOLEAN"] //9
322 ]Set["Float32", "TYPE_FLOAT32"] //10 157 ]Set["Float32", "TYPE_FLOAT32"] //10
323 ]Set["Float64", "TYPE_FLOAT64"] //11 158 ]Set["Float64", "TYPE_FLOAT64"] //11
324 ]Set["Real Number", "TYPE_FLOAT64"]
325 ]Set["Blueprint", "TYPE_BLUEPRINT"] //12 159 ]Set["Blueprint", "TYPE_BLUEPRINT"] //12
326 ]Set["Array", "TYPE_ARRAY"] //13 160 ]Set["Array", "TYPE_ARRAY"] //13
327 ]Set["Boxed Array", "TYPE_BOXEDARRAY"]//14 161 ]Set["Boxed Array", "TYPE_BOXEDARRAY"]//14
328 ]Set["Worker", "TYPE_WORKER"] //15 162 ]Set["Worker", "TYPE_WORKER"] //15
329 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] //16 163 ]Set["Method Missing Exception", "TYPE_METHODMISSINGEXCEPTION"] //16
330 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] //17 164 ]Set["Field Missing Exception", "TYPE_FIELDMISSINGEXCEPTION"] //17
331 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] //18 165 ]Set["Wrong Type Exception", "TYPE_WRONGTYPEEXCEPTION"]] //18
332 ]Definitions << [Dictionary[]] 166 ]Definitions << [Dictionary[]]
333 ]Next ID <<[0] 167 ]Next ID <<[0]
334 ]Escape Pattern <<[p] 168 ]Escape Pattern <<[p]
335 }
336
337 _Type Defs JS[text,def,p:out]
338 {
339 out <- [[text]Append[[def]Type Def[p]]]Append["\n\n"]
340 }
341
342 Type Defs@JS Type Registry[reg:out]
343 {
344 out <- Fold[_Type Defs JS[?,?,[reg]Escape Pattern >>], "", [reg]Definitions >>]
345 } 169 }
346 170
347 _Type Inits JS[reg,method reg,field reg,text,def,name:out] 171 _Type Inits JS[reg,method reg,field reg,text,def,name:out]
348 { 172 {
349 out <- [[text]Append[ [def]Type Init[[reg]Type ID[name], method reg, field reg,[reg]Escape Pattern >>] ]]Append["\n\n"] 173 out <- [[text]Append[ [def]Type Init[[reg]Type ID[name], method reg, field reg,[reg]Escape Pattern >>] ]]Append["\n\n"]
489 Multiply@JS Function[func,source1,source2,dest:out] 313 Multiply@JS Function[func,source1,source2,dest:out]
490 { 314 {
491 out <- [func]Add Operator Statement[source1,source2,dest," * "] 315 out <- [func]Add Operator Statement[source1,source2,dest," * "]
492 } 316 }
493 317
318 Get Constant Type@JS Function[func,const:out]
319 {
320 //TODO: Support more types as needed, particularly Float64 when support for that type is added in general
321 val <- [[func]Constants >>]Index[const] {}
322 { typename <- "Any Type" }
323 [(Int32(),UInt8(),UInt32())]Find[=[val,?]]
324 { typename <- [("Int32","UInt8","UInt32")]Index[~] }
325 { typename <- "Any Type" }
326 out <- Type Instance[typename]
327 }
328
329 Name Match[field,target name:out]
330 {
331 out <- [[field]Index[0]]=[target name]
332 }
333
334 Get Field Type@JS Function[func,otype,field:out]
335 {
336 def <- [[[func]Type Registry >>]Definitions >>]Index[[otype]Name >>]
337 {
338 [[~]Fields >>]Find[Name Match[?,field]]
339 { out <- [[[def]Fields >>]Index[~]]Index[1] }
340 { out <- Type Instance["Any Type"] }
341 }{
342 out <- Type Instance["Any Type"]
343 }
344 }
345
346 Get Var Type@JS Function[func,varname:out]
347 {
348 [[func]Inputs >>]Find[=[varname,?]]
349 {
350 out <- [[func]Input Types >>]Index[~]
351 }{
352 [[func]Outputs >>]Find[=[varname,?]]
353 {
354 out <- [[func]Output Types >>]Index[~]
355 }{
356 out <- [[func]Variables >>]Index[varname] {}
357 { out <- Type Instance["Any Type"] }
358 }
359 }
360 }
361
494 Divide@JS Function[func,source1,source2,dest:out] 362 Divide@JS Function[func,source1,source2,dest:out]
495 { 363 {
496 out <- [func]Add Operator Statement[source1,source2,dest," / "] 364 sourcetype <- [source1]Get Type[func]
365 If[[[sourcetype]Name >>]=["Float64"]]
366 {
367 out <- [func]Add Operator Statement[source1,source2,dest," / "]
368 }{
369 out <- [func]Add Statement[ [[[[[Make Op[dest, func]]Append[" = Math.floor(("]]Append[ Make Op[source1,func] ]]Append[") / ("]]Append[Make Op[source2, func]]]Append["))"] ]
370 }
497 } 371 }
498 372
499 DoLShift@JS Function[func,source1,source2,dest:out] 373 DoLShift@JS Function[func,source1,source2,dest:out]
500 { 374 {
501 out <- [func]Add Operator Statement[source1,source2,dest," << "] 375 out <- [func]Add Operator Statement[source1,source2,dest," << "]
553 out <- [func]Add Statement[[[dest]Append[" = "]]Append[source]] 427 out <- [func]Add Statement[[[dest]Append[" = "]]Append[source]]
554 } 428 }
555 429
556 Do AddRef@JS Function[func,psource,pdest:out] 430 Do AddRef@JS Function[func,psource,pdest:out]
557 { 431 {
558 source <- [psource]Make Op[func] 432 out <- [func]Move[psource,pdest]
559 dest <- [pdest]Make Op[func]
560 out <- [func]Add Statement[[[[dest]Append[" = add_ref((object *)"]]Append[source]]Append[")"]]
561 } 433 }
562 434
563 AddRef No Dest@JS Function[func,psource:out] 435 AddRef No Dest@JS Function[func,psource:out]
564 { 436 {
565 source <- [psource]Make Op[func] 437 out <- func
566 out <- [func]Add Statement[[["add_ref((object *)"]Append[source]]Append[")"]]
567 } 438 }
568 439
569 Release@JS Function[func,psource:out] 440 Release@JS Function[func,psource:out]
570 { 441 {
571 source <- [psource]Make Op[func] 442 out <- func
572 out <- [func]Add Statement[[["release_ref((object *)"]Append[source]]Append[")"]]
573 } 443 }
574 444
575 Set Null@JS Function[func,pdest:out] 445 Set Null@JS Function[func,pdest:out]
576 { 446 {
577 dest <- [pdest]Make Op[func] 447 dest <- [pdest]Make Op[func]
578 out <- [func]Add Statement[[dest]Append[" = NULL"]] 448 out <- [func]Add Statement[[dest]Append[" = NULL"]]
579 } 449 }
580 450
581 Lookup Constant@JS Function[func,const,doaddref:out] 451 Lookup Constant@JS Function[func,const,doaddref:out]
582 { 452 {
583 var <- ["_const_"]Append[Escape Rhope Name[const,[func]Escape Pattern >>]] 453 out <- ["_const_"]Append[Escape Rhope Name[const,[func]Escape Pattern >>]]
584 If[doaddref]
585 {
586 out <- [["add_ref("]Append[var]]Append[")"]
587 }{
588 out <- Val[var]
589 }
590 } 454 }
591 455
592 Field Result@JS Function[func,var,field:out] 456 Field Result@JS Function[func,var,field:out]
593 { 457 {
594 as op <- [var]Make Op[func] 458 as op <- [var]Make Op[func]
595 [(String(),String Cat(),String Slice())]Find[=[Blueprint Of[var],?]] 459 out <- [[as op]Append[".p_"]]Append[Escape Rhope Name[field,[func]Escape Pattern >>]]
596 {
597 [[func]Inputs >>]Find[=[var,?]]
598 {
599 type <- [[func]Input Types >>]Index[~]
600
601 }{
602 type <- [[func]Variables >>]Index[var] { Print["op refers to a var"] }
603 {
604 [[func]Outputs >>]Find[=[var,?]]
605 {
606 type <- [[func]Output Types >>]Index[~]
607 }{
608 //Does it make sense for us to do this?
609 type <- Type Instance["Any Type"]
610 }
611 }
612 }
613 }{
614 type <- Type Instance["Any Type"]
615 }
616 If[[[func]Convention >>] = ["rhope"]]
617 {
618 If[[type] = ["Any Type"]]
619 {
620 rvar <- Val[as op]
621 }{
622 rvar <- [[[["(("]Append[ Rhope Type to JS[type,[func]Escape Pattern >>] ]]Append[")("]]Append[as op]]Append["))"]
623 }
624 }{
625 rvar <- Val[as op]
626 }
627
628 [[func]Type Registry >>]Simple Type?[[type]Name >>]
629 { access <- "->" }
630 { access <- "->payload." }
631 {
632 //TODO: Generate some kind of error/exception in this case
633 access <- "->"
634 }
635 out <- [[rvar]Append[access]]Append[Escape Rhope Name[field,[func]Escape Pattern >>]]
636 } 460 }
637 461
638 Read Field@JS Function[func,var,field:out,result op] 462 Read Field@JS Function[func,var,field:out,result op]
639 { 463 {
640 out <- func 464 out <- func
645 { 469 {
646 out <- func 470 out <- func
647 result op <- Field Ref[var,field] 471 result op <- Field Ref[var,field]
648 } 472 }
649 473
650
651
652
653 Set Field Null@JS Function[func,var,field:out] 474 Set Field Null@JS Function[func,var,field:out]
654 { 475 {
655 out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ] 476 out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ]
656 } 477 }
657 478
661 out <- [func]Add Statement[ [dest]Append[[[" = copy_object("]Append[dest]]Append[")"]] ] 482 out <- [func]Add Statement[ [dest]Append[[[" = copy_object("]Append[dest]]Append[")"]] ]
662 } 483 }
663 484
664 Box@JS Function[func,psource,pdest,type:out] 485 Box@JS Function[func,psource,pdest,type:out]
665 { 486 {
666 dest <- [pdest]Make Op[func] 487 out <- func
667 source <- [psource]Make Op[func]
668 out <- [func]Add Statement[
669 [[[[[dest
670 ]Append[" = naked_to_boxed("]
671 ]Append[ [[func]Type Registry >>]Type ID[[type]Name >>] ]
672 ]Append[", &"]
673 ]Append[source]
674 ]Append[")"] ]
675 } 488 }
676 489
677 Unbox@JS Function[func,psource,pdest:out] 490 Unbox@JS Function[func,psource,pdest:out]
678 { 491 {
679 dest <- [pdest]Make Op[func] 492 out <- func
680 source <- [psource]Make Op[func]
681 out <- [func]Add Statement[
682 [[[["boxed_to_naked("
683 ]Append[source]
684 ]Append[", &"]
685 ]Append[dest]
686 ]Append[")"] ]
687 } 493 }
688 494
689 Get Raw Pointer@JS Function[func,psource,pdest:out] 495 Get Raw Pointer@JS Function[func,psource,pdest:out]
690 { 496 {
691 dest <- [pdest]Make Op[func] 497 out <- func
692 source <- [psource]Make Op[func]
693 out <- [func]Add Statement[ [[[dest]Append[" = (void*)("]]Append[source]]Append[" + 1)"] ]
694 } 498 }
695 499
696 Array Raw Pointer@JS Function[func,psource,pdest:out] 500 Array Raw Pointer@JS Function[func,psource,pdest:out]
697 { 501 {
698 dest <- [pdest]Make Op[func] 502 dest <- [pdest]Make Op[func]
724 ] 528 ]
725 } 529 }
726 530
727 Method Call@JS Function[func,method,args:out] 531 Method Call@JS Function[func,method,args:out]
728 { 532 {
729 out <- [func]Call[method,args] 533 If[[method]=["Call"]]
534 {
535 out <- [[[[[func]Add Raw Line[[["if ("]Append[Make Op[[args]Index[0], func]]]Append[".type_id == TYPE_WORKER) {"]]
536 ]Val Call[[args]Index[0], Tail[args,1]]
537 ]Add Raw Line["} else {"]
538 ]Func Base["Call",args, "MCall"]
539 ]Add Raw Line["}"]
540 }{
541 out <- [func]Func Base[Escape Rhope Name[method,[func]Escape Pattern >>],args, "MCall"]
542 }
543
730 } 544 }
731 545
732 Val Call@JS Function[func,to call,args:out] 546 Val Call@JS Function[func,to call,args:out]
733 { 547 {
734 worker <- Make Op[Strip Addref[to call], func] 548 worker <- Make Op[to call, func]
735 rargs <- Map[args, Make Op[?, func]] 549 rargs <- Map[args, Make Op[?, func]]
736 550
737 If[[[func]Last NumParams >>] = [-1]] 551 out <- [[[[[func]Add Raw Line[[[[["if ("]Append[worker]]Append[".Args.length > 0 || "]]Append[worker]]Append[".IsMethod) { "]]
738 { 552 ]Add Statement[[[[[" res = valcall("]Append[worker]]Append["["]]Append[ [rargs]Join[","] ]]Append["])"]]
739 prepped <- [[func]Add Raw Line[ 553 ]Add Raw Line["} else {"]
740 [[[["VCPrepCall(" 554 ]Add Statement[[[[[" res = "]Append[worker]]Append["("]]Append[ [rargs]Join[","] ]]Append[")"]]
741 ]Append[worker] 555 ]Add Raw Line["}"]
742 ]Append[", "]
743 ]Append[String[[rargs]Length]]
744 ]Append[")"] ]
745 ]Last NumParams <<[[rargs]Length]
746 }{
747 prepped <- [[func]Add Raw Line[
748 [[[[[["VCRePrepCall("
749 ]Append[worker]
750 ]Append[", "]
751 ]Append[String[[rargs]Length]]
752 ]Append[", "]
753 ]Append[String[[func]Last NumParams >>]]
754 ]Append[")"] ]
755 ]Last NumParams <<[[rargs]Length]
756 }
757
758
759 out <- [[[[Fold[_Val Function Arg JS[?, ?, ?, worker], prepped, rargs]
760 ]Add Raw Line[
761 [[[[[[[["ValCall("
762 ]Append[worker]
763 ]Append[", "]
764 ]Append[String[[rargs]Length]]
765 ]Append[", "]
766 ]Append[String[[func]Resume Index >>]]
767 ]Append[", "]
768 ]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
769 ]Append[")"]]
770 ]Add Raw Line["DISPATCH"]
771 ]Add Raw Line[
772 [[[["ValCallPostlude("
773 ]Append[String[[func]Resume Index >>]]
774 ]Append[", "]
775 ]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
776 ]Append[")"]]
777 ]Resume Index <<[ [[func]Resume Index >>]+[1] ]
778 } 556 }
779 557
780 Call@JS Function[func,name,args:out] 558 Call@JS Function[func,name,args:out]
781 { 559 {
782 If[[name]=["Call@Worker"]] 560 If[[name]=["Call@Worker"]]
783 { 561 {
784 //TODO: Handle case when user explicitly calls the fully qualified version, but the type of the first arg isn't Worker 562 //TODO: Handle case when user explicitly calls the fully qualified version, but the type of the first arg isn't Worker
785 out <- [func]Val Call[[args]Index[0], Tail[args,1]] 563 out <- [func]Val Call[[args]Index[0], Tail[args,1]]
786 }{ 564 }{
787 If[[name]=["Call"]] 565 out <- [func]Func Base[Escape Rhope Name[name,[func]Escape Pattern >>],args, "Call"]
788 {
789 to call <- [args]Index[0]
790 last numparams <- [func]Last NumParams >>
791 out <- [[[[[[func]Add Raw Line[[["if (get_blueprint("]Append[Make Op[Strip Addref[to call], func]]]Append[")->type_id == TYPE_WORKER) {"]]
792 ]Val Call[to call, Tail[args,1]]
793 ]Add Raw Line["} else {"]
794 ]Last NumParams <<[last numparams]
795 ]Func Base["Call",args, "Call"]
796 ]Add Raw Line["}"]
797 }{
798 out <- [func]Func Base[Escape Rhope Name[name,[func]Escape Pattern >>],args, "Call"]
799 }
800 } 566 }
801 } 567 }
802 568
803 Func Base@JS Function[func,tocall,args,type:out] 569 Func Base@JS Function[func,tocall,args,type:out]
804 { 570 {
571
805 Print[ [[func]Name >>]Append[ [": Func Base("]Append[tocall] ] ] 572 Print[ [[func]Name >>]Append[ [": Func Base("]Append[tocall] ] ]
806 rargs <- Map[args, Make Op[?, func]] 573 rargs <- Map[args, Make Op[?, func]]
807
808 If[[[rargs]Length] > [[func]Last NumParams >>]]
809 {
810 If[[[func]Last NumParams >>] = [-1]]
811 {
812 freed <- Val[func]
813 }{
814 freed <- [func]Add Raw Line["FreeCall"]
815 }
816 prepped <- [[freed]Add Raw Line[ [["PrepCall("]Append[String[[rargs]Length]]]Append[")"] ]
817 ]Last NumParams <<[[rargs]Length]
818 }{
819 prepped <- Val[func]
820 }
821 574
822 575 If[[type]=["MCall"]]
823 out <- [[Fold[_Function Arg JS[?], prepped, rargs] 576 {
824 ]Add Raw Line[ 577 out <- [func]Add Statement[[[[[[["res = "]Append[[rargs]Index[0]]]Append[".f_"]]Append[tocall]]Append["("]]Append[ [Tail[rargs, 1]]Join[","] ]]Append[")"]]
825 [[[[[[[[[type]Append["("] 578 }{
826 ]Append[tocall] 579 out <- [func]Add Statement[[[[["res = f_"]Append[tocall]]Append["("]]Append[ [rargs]Join[","] ]]Append[")"]]
827 ]Append[", "] 580 }
828 ]Append[String[[rargs]Length]]
829 ]Append[", "]
830 ]Append[String[[func]Resume Index >>]]
831 ]Append[", "]
832 ]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
833 ]Append[")"]]
834 ]Resume Index <<[ [[func]Resume Index >>]+[1] ]
835 } 581 }
836 582
837 Call Foreign@JS Function[func,name,language,args,store result:out] 583 Call Foreign@JS Function[func,name,language,args,store result:out]
838 { 584 {
839 rargs <- Map[args, Make Op[?, func]] 585 rargs <- Map[args, Make Op[?, func]]
840 //Assume language = "JS" for now 586 //Assume language = "JS" for now
841 base <- [[[name]Append["("]]Append[ Join[rargs, ", "] ]]Append[")"] 587 If[[name]Ends With["@"]]
588 {
589 base <- [[[[[[rargs]Index[0]]Append["."]]Append[ [name]Slice[ [[name]Length]-[1] ] ]]Append["("]]Append[ [Tail[rargs,1]]Join[","] ]]Append[")"]
590 }{
591 base <- [[[name]Append["("]]Append[ Join[rargs, ", "] ]]Append[")"]
592 }
842 ,do store <- [(String(), String Slice(), String Cat())]Find[=[Blueprint Of[store result], ?]] 593 ,do store <- [(String(), String Slice(), String Cat())]Find[=[Blueprint Of[store result], ?]]
843 { 594 {
844 ,do store <- If[[store result]=[""]] 595 ,do store <- If[[store result]=[""]]
845 { stmt <- Val[base] } 596 { stmt <- Val[base] }
846 } 597 }
850 out <- [func]Add Statement[stmt] 601 out <- [func]Add Statement[stmt]
851 } 602 }
852 603
853 Get Field Call@JS Function[func,field,source:out] 604 Get Field Call@JS Function[func,field,source:out]
854 { 605 {
855 out <- [func]Func Base[Escape Rhope Name[[field]Append[" >>"],[func]Escape Pattern >>], [()]Append[source], "Call"] 606 //This will need to change later when I add support for "Field Missing"
607 [func]Escape Pattern >>
608 {
609 esource <- Escape Rhope Name[Make Op[source,func], ~]
610 efield <- Escape Rhope Name[field, ~]
611 }
612 out <- [func]Add Statement[[[["res = "]Append[esource]]Append[".p_"]]Append[efield]]
856 } 613 }
857 614
858 Set Field Call@JS Function[func,field,object,value:out] 615 Set Field Call@JS Function[func,field,object,value:out]
859 { 616 {
860 out <- [func]Func Base[Escape Rhope Name[[field]Append[" <<"],[func]Escape Pattern >>], [[()]Append[object]]Append[value], "Call"] 617 out <- [func]Func Base[Escape Rhope Name[[field]Append[" <<"],[func]Escape Pattern >>], [[()]Append[object]]Append[value], "Call"]
861 } 618 }
862 619
863 Tail Method Call@JS Function[func,method,args:out] 620 Tail Method Call@JS Function[func,method,args:out]
864 { 621 {
865 out <- [func]Func Base[[[func]Method Registry >>]Method ID[method],args, "TMCall"] 622 //Javascript doesn't support tail calls, at least not directly anyway
623 out <- [func]Method Call[method,args]
866 } 624 }
867 625
868 Tail Call@JS Function[func,name,args:out] 626 Tail Call@JS Function[func,name,args:out]
869 { 627 {
870 out <- [func]Func Base[Escape Rhope Name[name,[func]Escape Pattern >>],args, "TCall"] 628 If[[name]=[[func]Name >>]]
629 {
630 //TODO: Support simple tail recursion
631 out <- func
632 }{
633 out <- [func]Call[name,args]
634 }
871 } 635 }
872 636
873 Resolve@JS Function[func,op:out] 637 Resolve@JS Function[func,op:out]
874 { 638 {
875 If[[[func]Convention >>] = ["rhope"]] 639 If[[[func]Convention >>] = ["rhope"]]
876 { 640 {
877 [[func]Inputs >>]Find[=[op,?]] 641 out <- ["lv_"]Append[Escape Rhope Name[op, [func]Escape Pattern >>]]
878 {
879 out <- [["my_cdata->params["]Append[String[~]]]Append[" ]"]
880 }{
881 out <- [[["lv_"]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append["->"]]Append[Escape Rhope Name[op,[func]Escape Pattern >>]]
882 }
883 }{ 642 }{
884 out <- Escape Rhope Name[op,[func]Escape Pattern >>] 643 out <- Escape Rhope Name[op,[func]Escape Pattern >>]
885 } 644 }
886 } 645 }
887 646
888 Resolve Output@JS Function[func,name:out] 647 Resolve Output@JS Function[func,name:out]
889 { 648 {
890 If[[[func]Convention >>] = ["rhope"]] 649 If[[[func]Convention >>] = ["rhope"]]
891 { 650 {
892 out <- [[["lv_"]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append["->"]]Append[Escape Rhope Name[name,[func]Escape Pattern >>]] 651 out <- ["lv_"]Append[Escape Rhope Name[name, [func]Escape Pattern >>]]
893 }{ 652 }{
894 out <- Escape Rhope Name[name,[func]Escape Pattern >>] 653 out <- Escape Rhope Name[name,[func]Escape Pattern >>]
895 } 654 }
896 } 655 }
897 656
898 Instruction Stream@JS Function[func:out] 657 Instruction Stream@JS Function[func:out]
899 { 658 {
900 out <- [func]Statements <<[()] 659 out <- [func]Statements <<[()]
906 } 665 }
907 666
908 Do If@JS Function[func,condition,stream:out] 667 Do If@JS Function[func,condition,stream:out]
909 { 668 {
910 cond <- [condition]Make Op[func] 669 cond <- [condition]Make Op[func]
911 out <- [[Fold[_If JS[?], [[func 670 out <- [Fold[_If JS[?], [[func
912 ]Add Raw Line[ [["if("]Append[cond]]Append[")"] ] 671 ]Add Raw Line[ [["if("]Append[cond]]Append[")"] ]
913 ]Add Raw Line["{"], [stream]Statements >>] 672 ]Add Raw Line["{"], [stream]Statements >>]
914 ]Add Raw Line["}"] 673 ]Add Raw Line["}"]
915 ]Resume Index <<[[stream]Resume Index >>]
916
917 } 674 }
918 675
919 Discard Outputs@JS Function[func,first to discard:out] 676 Discard Outputs@JS Function[func,first to discard:out]
920 { 677 {
921 out <- [[[[[func 678 out <- func
922 ]Add Raw Line[[["for(idx = "]Append[String[first to discard]]]Append["; idx < cdata->num_params; ++idx)"]]
923 ]Add Raw Line["{"]
924 ]Add Raw Line[" if (cdata->params[idx])"]
925 ]Add Raw Line[" release_ref(cdata->params[idx]);"]
926 ]Add Raw Line["}"]
927 } 679 }
928 680
929 Result Reference@JS Function[func,output:out] 681 Result Reference@JS Function[func,output:out]
930 { 682 {
931 out <- [["cdata->params["]Append[String[output]]]Append["]"] 683 out <- [["res["]Append[String[output]]]Append["]"]
932 } 684 }
933 685
934 Checked Result Reference@JS Function[func,output:out] 686 Checked Result Reference@JS Function[func,output:out]
935 { 687 {
936 out <- [[[["("]Append[String[output]]]Append[" < cdata->num_params ? cdata->params["]]Append[String[output]]]Append["] : NULL)"] 688 out <- [func]Result Reference[output]
937 } 689 }
938 690
939 691
940 If Null Else@JS Function[func,left,right:out] 692 If Null Else@JS Function[func,left,right:out]
941 { 693 {
942 check <- [[Make Condition[left]]Strip Addref]Make Op[func] 694 check <- [Make Condition[left]]Make Op[func]
943 l <- [left]Make Op[func] 695 l <- [left]Make Op[func]
944 r <- [right]Make Op[func] 696 r <- [right]Make Op[func]
945 out <- [[[[[["(" 697 out <- [[[[[["("
946 ]Append[check] 698 ]Append[check]
947 ]Append[" ? "] 699 ]Append[" != null ? "]
948 ]Append[l] 700 ]Append[l]
949 ]Append[" : "] 701 ]Append[" : "]
950 ]Append[r] 702 ]Append[r]
951 ]Append[")"] 703 ]Append[")"]
952 } 704 }
953 705
954 _Set Outputs JS[string,inputname,inputnum,func:out]
955 {
956 out <- [string]Append[[[ [ ["\tRet("]Append[String[inputnum]] ]Append[ [[", lv_"]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append["->"]]]Append[Escape Rhope Name[inputname,[func]Escape Pattern >>]]]Append[")\n"]]
957 }
958
959 Set Outputs@JS Function[func:out] 706 Set Outputs@JS Function[func:out]
960 { 707 {
961 If[[[func]Convention >>] = ["rhope"]] 708 If[[[func]Convention >>] = ["rhope"]]
962 { 709 {
963 out <- [[[Fold[_Set Outputs JS[?, ?, ?, func], "", [func]Outputs >>]]Append["\tNumRet("]]Append[String[[[func]Outputs >>]Length]]]Append[")\n"] 710 out <- [["\treturn ["]Append[ [Map[[func]Outputs >>, Escape Rhope Name[?, [func]Escape Pattern >>]]]Join[","] ]]Append["];\n"]
964 }{ 711 }{
965 [[func]Outputs >>]Index[0] 712 [[func]Outputs >>]Index[0]
966 { 713 {
967 out <- [["\treturn "]Append[Escape Rhope Name[~,[func]Escape Pattern >>]]]Append[";\n"] 714 out <- [["\treturn "]Append[Escape Rhope Name[~,[func]Escape Pattern >>]]]Append[";\n"]
968 }{ 715 }{
969 out <- "" 716 out <- ""
970 } 717 }
971 } 718 }
972 } 719 }
973 _Output Defs JS[string,varname,index,func:out] 720
974 { 721 Check Param Type JS[text,type,input num,func:out]
975 out <- [[[string]Append[ ["\t"]Append[Rhope Type to JS[[[func]Output Types >>]Index[index],[func]Escape Pattern >>]] ]]Append[[" "]Append[Escape Rhope Name[varname,[func]Escape Pattern >>]]]]Append[";\n"] 722 {
976 } 723 [(String(),String Cat(),String Slice())]Find[=[Blueprint Of[type],?]]
977 _Var Defs JS[string,type,varname,p:out] 724 {
978 { 725 typename <- type
979 out <- [[[string]Append[ ["\t"]Append[Rhope Type to JS[type,p]] ]]Append[[" "]Append[Escape Rhope Name[varname,p]]]]Append[";\n"] 726 }{
980 } 727 typename <- [type]Name >>
981 728 }
982 729 If[[typename] = ["Any Type"]]
983 Definitions@JS Function[func:out]
984 {
985 Print[["Definitions@JS Function: "]Append[[func]Name >>]]
986 {
987 If[ [[[func]Convention >>] = ["rhope"]] And [[ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] > [0]] ]
988 {
989 localtype <- [[[Fold[_Output Defs JS[?, ?, ?, func], Fold[_Var Defs JS[?,?,?,[func]Escape Pattern >>],"typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} lt_"]]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append[";\n"]
990 }{
991 localtype <- ""
992 }
993
994 If[ [[func]Convention >>] = ["rhope"] ]
995 {
996 /* parts <- [[func]Name >>]Split["@"]
997 [parts]Index[1]
998 {
999 proto <- [[[["MethodDef("
1000 ]Append[Escape Rhope Name[[parts]Index[0],[func]Escape Pattern >>]]
1001 ]Append[", "]
1002 ]Append[Escape Rhope Name[~,[func]Escape Pattern >>]]
1003 ]Append[")\n"]
1004 }{
1005 proto <- [["FuncDef("]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append[")\n"]
1006 } */
1007 out <- Val[localtype]
1008 }{
1009 out <- [[func]Naked Proto]Append[";\n"]
1010 }
1011 }
1012 }
1013
1014 _Proto Input[list,input,index,types,p:out]
1015 {
1016 out <- [list]Append[ [[Rhope Type to JS[[types]Index[index],p]]Append[" "]]Append[Escape Rhope Name[input,p]] ]
1017 }
1018
1019 Naked Proto@JS Function[func:out]
1020 {
1021 [[func]Output Types >>]Index[0]
1022 {
1023 outtype <- [Rhope Type to JS[~,[func]Escape Pattern >>]]Append[" "]
1024 }{
1025 outtype <- "void "
1026 }
1027 out <- [[[[outtype
1028 ]Append[ Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]
1029 ]Append["("]
1030 ]Append[ [Fold[_Proto Input[?, ?, ?, [func]Input Types >>,[func]Escape Pattern >>], (), [func]Inputs >>]]Join[", "] ]
1031 ]Append[")"]
1032 }
1033
1034 Type Check@JS Function[func,text,type,input num:out]
1035 {
1036 If[[type] = ["Any Type"]]
1037 { 730 {
1038 out <- text 731 out <- text
1039 }{ 732 }{
1040 out <- [text]Append[ [["\tParam("]Append[input num]]Append[ [[", "]Append[ [[func]Type Registry >>]Type ID[type] ]]Append[")"] ] ] 733 input <- ["lv_"]Append[Escape Rhope Name[[[func]Inputs >>]Index[input num], [func]Escape Pattern >>]]
1041 } 734 out <- [text]Append[ [[[["\t"]Append[input]]Append["= check_type("]]Append[input]]Append[ [[", "]Append[ [[func]Type Registry >>]Type ID[typename] ]]Append[");"] ] ]
1042 } 735 }
1043 736 }
1044 Check Param Type JS[text,type,input num,func:out] 737
1045 { 738 _Add Prefix[val:out]
1046 [(String(),String Cat(),String Slice())]Find[=[Blueprint Of[type],?]] 739 {
1047 { 740 out <- ["lv_"]Append[val]
1048 typename <- type
1049 }{
1050 typename <- [type]Name >>
1051 }
1052 If[[typename] = ["Any Type"]]
1053 {
1054 out <- text
1055 }{
1056 out <- [text]Append[[[["\tParam("]Append[String[input num]]]Append[ [","]Append[ [[func]Type Registry >>]Type ID[typename] ] ]]Append[")\n"]]
1057 }
1058 } 741 }
1059 742
1060 Text@JS Function[func:out] 743 Text@JS Function[func:out]
1061 { 744 {
1062 Print[["Text@JS Function: "]Append[[func]Name >>]] 745 Print[["Text@JS Function: "]Append[[func]Name >>]]
1063 If[ [[func]Convention >>] = ["rhope"] ] 746 If[ [[func]Convention >>] = ["rhope"] ]
1064 { 747 {
748
1065 before <- [[func]Name >>]Partition["@"] {} {} 749 before <- [[func]Name >>]Partition["@"] {} {}
1066 { 750 {
1067 type <- "MethodImpl" 751 ivars <- Tail[[func]Inputs >>, 1]
1068 cname <- [[[[Escape Rhope Name[before,[func]Escape Pattern >>] 752 cname <- [["t_"]Append[Escape Rhope Name[~,[func]Escape Pattern >>]]
1069 ]Append[", "] 753 ]Append[[".f_"]Append[Escape Rhope Name[before,[func]Escape Pattern >>]]]
1070 ]Append[Escape Rhope Name[~,[func]Escape Pattern >>]] 754 [[func]Inputs >>]Index[0]
1071 ]Append[", "] 755 { move this <- ["\tlv_"]Append[[Escape Rhope Name[~, [func]Escape Pattern >>]]Append[" = this;"]] }
1072 ]Append[ [[func]Type Registry >>]Type ID[~] ] 756 { move this <- "" }
1073 }{ 757 }{
1074 type <- "Func" 758 ivars <- [func]Inputs >>
1075 cname <- Val[fname] 759 fname <- Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]
760 move this <- ""
1076 } 761 }
762 inproc <- Val[Map[?, _Add Prefix[?]]]
763 }{
1077 fname <- Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>] 764 fname <- Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]
1078 param check <- Fold[Check Param Type JS[?, ?, ?, func], "", [func]Input Types >>] 765 ivars <- Inputs >>[func]
1079 If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ] 766 move this <- ""
1080 { 767 inproc <- Val[Val[?]]
1081 out <- [[[[[[[[ [type]Append["NoLocals("] 768 }
1082 ]Append[cname] 769 cname <- ["var "]Append[fname]
1083 ]Append[",\n\tNumParams "] 770 param check <- Fold[Check Param Type JS[?, ?, ?, func], "", [func]Input Types >>]
1084 ]Append[ String[[[func]Inputs >>]Length] ] 771
1085 ]Append[")\n\n"] 772 out <- [[[[[[[[[cname
1086 ]Append[param check] 773 ]Append[" = function("]
1087 ]Append[ [[func]Statements >>]Join[""] ] 774 ]Append[ [[inproc]Call[Map[ivars, Escape Rhope Name[?, [func]Escape Pattern >>]]]]Join[","] ]
1088 ]Append["EndFuncNoLocals\n"] 775 ]Append[")\n{\n"]
1089 ]Append["DISPATCH"] 776 ]Append[move this]
1090 }{ 777 ]Append[param check]
1091 If[[[func]Last NumParams >>] = [-1]] 778 ]Append[ [["\tvar "]Append[ [ [inproc]Call[Concatenate[[func]Outputs >>, Keys[[func]Variables >>]]] ]Join[","] ]]Append[";\n"] ]
1092 { 779 ]Append[ [[func]Statements >>]Join[""] ]
1093 freecall <- "" 780 ]Append[[func]Set Outputs]
1094 }{ 781 ]Append["}"]
1095 freecall <- "\n\tFreeCall\n"
1096 }
1097 out <- [[[[[[[[[[ [type]Append["("]
1098 ]Append[cname]
1099 ]Append[",\n\tNumParams "]
1100 ]Append[ String[[[func]Inputs >>]Length] ]
1101 ]Append[")\n\n"]
1102 ]Append[param check]
1103 ]Append[ [[func]Statements >>]Join[""] ]
1104 ]Append[freecall]
1105 ]Append[[func]Set Outputs]
1106 ]Append[[["EndFunc("]Append[fname]]Append[")\n"]]
1107 ]Append["DISPATCH"]
1108 }
1109 }{
1110
1111 out <- [[[
1112 Fold[_Output Defs JS[?, ?, ?, func],
1113 Fold[_Var Defs JS[?], [[func]Naked Proto]Append["\n{"], [func]Variables >>], [func]Outputs >>]
1114 ]Append[[[func]Statements >>]Join[""]]
1115 ]Append[[func]Set Outputs]
1116 ]Append["}"]
1117 }
1118 } 782 }
1119 783
1120 Blueprint JS Program 784 Blueprint JS Program
1121 { 785 {
1122 Functions 786 Functions
1132 p <- Pattern[("_", "@", " ", ":", "?", "+", "-", "*", "/", "<", ">", "(", ")", "!", "=", "'", 796 p <- Pattern[("_", "@", " ", ":", "?", "+", "-", "*", "/", "<", ">", "(", ")", "!", "=", "'",
1133 "\"", "\t", ",", ".", "\n", "{", "}", "[", "]", "#", "\\", "\r", ";", "&", "|", "%", "^", "`", "~")] 797 "\"", "\t", ",", ".", "\n", "{", "}", "[", "]", "#", "\\", "\r", ";", "&", "|", "%", "^", "`", "~")]
1134 out <- [[[[[[Build[JS Program()]]Functions <<[Dictionary[]]]Method Registry <<[JS Method Registry[]]]Type Registry <<[JS Type Registry[p]]]Field Registry <<[JS Field Registry[]]]Libraries <<[Dictionary[]]]Escape Pattern <<[p] 798 out <- [[[[[[Build[JS Program()]]Functions <<[Dictionary[]]]Method Registry <<[JS Method Registry[]]]Type Registry <<[JS Type Registry[p]]]Field Registry <<[JS Field Registry[]]]Libraries <<[Dictionary[]]]Escape Pattern <<[p]
1135 } 799 }
1136 800
801 Supported Number Types@JS Program[program:out]
802 {
803 out <- ("Int32","UInt8","UInt32")
804 }
805
806 Needed Specials@JS Program[program,typename,makespecial:out]
807 {
808 out <- ()
809 }
810
1137 Link@JS Program[program,language,library:out] 811 Link@JS Program[program,language,library:out]
1138 { 812 {
1139 If[[library] = ["runtime"]] 813 If[[library] = ["runtime"]]
1140 { 814 {
1141 out <- program 815 out <- program
1171 Method?@JS Program[program,funcname:is,isnot] 845 Method?@JS Program[program,funcname:is,isnot]
1172 { 846 {
1173 is,isnot <- [[program]Method Registry >>]Method ID[funcname] 847 is,isnot <- [[program]Method Registry >>]Method ID[funcname]
1174 } 848 }
1175 849
1176 _Defs JS Program[text,func:out]
1177 {
1178 def <- [func]Definitions
1179 If[[def]=[""]]
1180 {
1181 out <- text
1182 }{
1183 out <- [text]Append[[def]Append["\n\n"]]
1184 }
1185 }
1186
1187 _Text JS Program[text,func,type reg:out] 850 _Text JS Program[text,func,type reg:out]
1188 { 851 {
1189 out <- [text]Append[[[ [func]Type Registry <<[type reg] ]Text]Append["\n\n"]] 852 out <- [text]Append[[[ [func]Type Registry <<[type reg] ]Text]Append["\n\n"]]
1190 } 853 }
1191 854
1192 Combine Consts[consts,func:out] 855 Combine Consts[consts,func:out]
1193 { 856 {
1194 out <- Combine[[func]Constants >>, consts] 857 out <- Combine[[func]Constants >>, consts]
1195 }
1196
1197 _Consts JS Program[text,value,name,p:out]
1198 {
1199 out <- [text]Append[ [["object * _const_"]Append[Escape Rhope Name[name,p]]]Append[";\n"] ]
1200 }
1201
1202 _Consts JS Release[text,value,name,p:out]
1203 {
1204 out <- [text]Append[ [["\trelease_ref(_const_"]Append[Escape Rhope Name[name,p]]]Append[");\n"] ]
1205 } 858 }
1206 859
1207 _List Literal El[text,val,index,type reg:out] 860 _List Literal El[text,val,index,type reg:out]
1208 { 861 {
1209 out <- [[[[text 862 out <- [[[[text
1240 }{ 893 }{
1241 If[[valtype] = [Boolean()]] 894 If[[valtype] = [Boolean()]]
1242 { 895 {
1243 If[value] 896 If[value]
1244 { 897 {
1245 out <- "make_Bool(1)" 898 out <- "make_Bool(true)"
1246 }{ 899 }{
1247 out <- "make_Bool(0)" 900 out <- "make_Bool(false)"
1248 } 901 }
1249 }{ 902 }{
1250 903
1251 [(String(),String Slice(),String Cat())]Find[=[valtype,?]] 904 [(String(),String Slice(),String Cat())]Find[=[valtype,?]]
1252 { 905 {
1257 //TODO: Figure out how to fully support these in nested cases 910 //TODO: Figure out how to fully support these in nested cases
1258 //or workaround the problem higher up in the food chain 911 //or workaround the problem higher up in the food chain
1259 [[value]Args >>]Last 912 [[value]Args >>]Last
1260 { size <- String[[~]+[1]] } 913 { size <- String[[~]+[1]] }
1261 { size <- "0" } 914 { size <- "0" }
1262 out <- [[[[[["make_Worker(FUNC_" 915 out <- [[[[[["make_Worker(f_"
1263 ]Append[Escape Rhope Name[[value]Name >>,[type reg]Escape Pattern >>]] 916 ]Append[Escape Rhope Name[[value]Name >>,[type reg]Escape Pattern >>]]
1264 ]Append[", "] 917 ]Append[", "]
1265 ]Append[size] 918 ]Append[size]
1266 ]Append[", "] 919 ]Append[", "]
1267 ]Append[String[Fold[+[1,?], 0, [value]Args >>]]] 920 ]Append[String[Fold[+[1,?], 0, [value]Args >>]]]
1296 _Set Consts JS Program[text,value,name,type reg:out] 949 _Set Consts JS Program[text,value,name,type reg:out]
1297 { 950 {
1298 valtype <- Blueprint Of[value] 951 valtype <- Blueprint Of[value]
1299 [(String(),String Cat(),String Slice(),Worker Literal(),List(),List Leaf())]Find[=[valtype,?]] 952 [(String(),String Cat(),String Slice(),Worker Literal(),List(),List Leaf())]Find[=[valtype,?]]
1300 { 953 {
1301 Print[[name]Append[" is not of an early constant type"]]
1302 out <- text 954 out <- text
1303 }{ 955 }{
1304 Const Construct JS[value,type reg] 956 Const Construct JS[value,type reg]
1305 { out <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = "]]Append[~]]Append[";\n"] ] } 957 { out <- [text]Append[ [[[["var _const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = "]]Append[~]]Append[";\n"] ] }
1306 } 958 }
1307 } 959 }
1308 960
1309 _Set List Els[text,el,index,type reg:out] 961 _Set List Els[text,el,index,type reg:out]
1310 { 962 {
1324 [(String(),String Cat(),String Slice(),Worker Literal(),List(),List Leaf())]Find[=[valtype,?]] 976 [(String(),String Cat(),String Slice(),Worker Literal(),List(),List Leaf())]Find[=[valtype,?]]
1325 { 977 {
1326 If[[~]>[3]] 978 If[[~]>[3]]
1327 { 979 {
1328 out <- [Fold[_Set List Els[?, ?, ?, type reg], [text]Append["\trhope(FUNC_List, inout, 0, 1);\n"], value] 980 out <- [Fold[_Set List Els[?, ?, ?, type reg], [text]Append["\trhope(FUNC_List, inout, 0, 1);\n"], value]
1329 ]Append[[["\t_const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = inout[0];\n"]] 981 ]Append[[["var _const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = inout[0];\n"]]
1330 }{ 982 }{
1331 Const Construct JS[value,type reg] 983 Const Construct JS[value,type reg]
1332 { init <- [text]Append[ [[[["\t_const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = "]]Append[~]]Append[";\n"] ] } 984 { init <- [text]Append[ [[[["var _const_"]Append[Escape Rhope Name[name,[type reg]Escape Pattern >>]]]Append[" = "]]Append[~]]Append[";\n"] ] }
1333 985
1334 If[[valtype]=[Worker Literal()]] 986 If[[valtype]=[Worker Literal()]]
1335 { 987 {
1336 out <- Fold[_Set Worker Params JS[?, ?, ?, type reg, Escape Rhope Name[name,[type reg]Escape Pattern >>]], init, [value]Args >>] 988 out <- Fold[_Set Worker Params JS[?, ?, ?, type reg, Escape Rhope Name[name,[type reg]Escape Pattern >>]], init, [value]Args >>]
1337 }{ 989 }{
1341 }{ 993 }{
1342 out <- text 994 out <- text
1343 } 995 }
1344 } 996 }
1345 997
1346 _Dispatch Switch Sub[text, num, name:out] 998 Text Filename@JS Program[program,source name:out]
1347 { 999 {
1348 out <- [[[[[text 1000 out <- [source name]Append[".js"]
1349 ]Append["\tResumeEntry("]
1350 ]Append[String[num]]
1351 ]Append[","]
1352 ]Append[name]
1353 ]Append[")\\\n"]
1354 }
1355
1356 _Dispatch Switch[text,func,raw name:out]
1357 {
1358 If[[[func]Convention >>] = ["rhope"]]
1359 {
1360 name <- Escape Rhope Name[raw name,[func]Escape Pattern >>]
1361 out <- [[text]Append[ [["\tDispatchEntry("]Append[name]]Append[")\\\n"] ]
1362 ]Append[Fold[_Dispatch Switch Sub[?, ?, name], "", Range[1, [func]Resume Index >>]]]
1363 }{
1364 out <- text
1365 }
1366 }
1367
1368 _Dispatch Switch Methods[p,text,id,raw name:out]
1369 {
1370 name <- Escape Rhope Name[raw name,p]
1371 out <- [text]Append[ [["\tDispatchEntry("]Append[name]]Append[")\\\n"] ]
1372 }
1373
1374 _Dispatch Enum Sub[text, num, name:out]
1375 {
1376 out <- [[[[[text
1377 ]Append["\tRES_"]
1378 ]Append[String[num]]
1379 ]Append["_"]
1380 ]Append[name]
1381 ]Append[",\n"]
1382 }
1383
1384 _Dispatch Enum[text,func,raw name:out]
1385 {
1386 If[[[func]Convention >>] = ["rhope"]]
1387 {
1388 name <- Escape Rhope Name[raw name,[func]Escape Pattern >>]
1389 out <- [[text]Append[ [["\tFUNC_"]Append[name]]Append[",\n"] ]
1390 ]Append[Fold[_Dispatch Enum Sub[?, ?, name], "", Range[1, [func]Resume Index >>]]]
1391 }{
1392 out <- text
1393 }
1394 }
1395
1396 _Dispatch Enum Methods[p,text,types,name:out]
1397 {
1398 out <- [text]Append[ [["\tFUNC_"]Append[Escape Rhope Name[name,p]]]Append[",\n"] ]
1399 }
1400
1401 Dispatch@JS Program[program,all methods:out]
1402 {
1403 out <- [[[[["typedef enum {\n"
1404 ]Append[Fold[_Dispatch Enum[?],
1405 [Fold[_Dispatch Enum Methods[[program]Escape Pattern >>,?], "", all methods]]Append["\tFUNC_Build,\n\tFUNC_BlueprintSP_Of,\n\tFUNC_ID,\n\tFUNC_BlueprintSP_FromSP_ID,\n"],
1406 [program]Functions >>]]
1407 ]Append["\tEND\n} funcids;\n\n"]
1408 ]Append["#define DispatchEntries \\\n"]
1409 ]Append[Fold[_Dispatch Switch[?],
1410 [Fold[_Dispatch Switch Methods[[program]Escape Pattern >>,?], "", all methods]]Append["\tDispatchEntry(Build)\\\n\tDispatchEntry(BlueprintSP_Of)\\\n\tDispatchEntry(ID)\\\n\tDispatchEntry(BlueprintSP_FromSP_ID)\\\n"],
1411 [program]Functions >>]]
1412 ]Append["\tEndEntry\n\n"]
1413 }
1414
1415 Not Native[func:out]
1416 {
1417 If[[[func]Convention >>] = ["rhope"]]
1418 { out <- No }
1419 { out <- Yes }
1420 }
1421
1422 Native[func:out]
1423 {
1424 out <- [[func]Convention >>] = ["rhope"]
1425 }
1426
1427 Local Pointers[text,func:out]
1428 {
1429 If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ]
1430 {
1431 out <- text
1432 }{
1433 out <- [text]Append[[["\tFuncDef("]Append[Escape Rhope Name[[func]Name >>,[func]Escape Pattern >>]]]Append[")\n"]]
1434 }
1435 }
1436
1437 _Method to Types[dict,name,type:out]
1438 {
1439 typelist <- [dict]Index[name] {}
1440 { typelist <- () }
1441
1442 out <- [dict]Set[name, [typelist]Append[[type]Name >>]]
1443
1444 }
1445
1446 _Field to Types[dict,field,type:out]
1447 {
1448 name <- [field]Index[0]
1449 out <- _Method to Types[_Method to Types[dict, [name]Append[" >>"], type], [name]Append[" <<"], type]
1450
1451 }
1452
1453 Method to Types[dict,type:out]
1454 {
1455 out <- Fold[_Method to Types[?, ?, type], dict, [type]Methods >>]
1456 }
1457
1458 Field to Types[dict,type:out]
1459 {
1460 out <- Fold[_Field to Types[?, ?, type], dict, [type]Fields >>]
1461 }
1462
1463 _Method Dispatch[text, type, method, reg: out]
1464 {
1465 out <- [[[[[[[text]Append["\tMethodDispatch("]]Append[ [reg]Type ID[type] ]]Append[","]]Append[Escape Rhope Name[method,[reg]Escape Pattern >>]]]Append[","]]Append[Escape Rhope Name[type,[reg]Escape Pattern >>]]]Append[")\n"]
1466 }
1467
1468 Method Dispatch[text, types, method, reg: out]
1469 {
1470 out <- [[[Fold[_Method Dispatch[?, ?, method, reg], [[[text]Append["Method("]]Append[ Escape Rhope Name[method,[reg]Escape Pattern >>] ]]Append[")\n"], types]
1471 ]Append["EndMethod("]
1472 ]Append[Escape Rhope Name[method,[reg]Escape Pattern >>]]
1473 ]Append[")\n\n"]
1474 }
1475
1476 Init Type Names[text,typeid,name,reg:out]
1477 {
1478 [reg]Defined?[name]
1479 { out <- [text]Append[ [[[["\tregistered_types["]Append[typeid]]Append["]->name = "]]Append[Const Construct JS[name, reg]]]Append[";\n"] ] }
1480 { out <- text }
1481 } 1001 }
1482 1002
1483 Text@JS Program[program:out] 1003 Text@JS Program[program:out]
1484 { 1004 {
1485 p <- [program]Escape Pattern >> 1005 p <- [program]Escape Pattern >>
1486 type defs <- [[program]Type Registry >>]Definitions >>
1487 constants <- Fold[Combine Consts[?], Dictionary[], [program]Functions >>] 1006 constants <- Fold[Combine Consts[?], Dictionary[], [program]Functions >>]
1488 all methods <- Fold[Field to Types[?], Fold[Method to Types[?], Dictionary[], type defs], type defs] 1007
1489 headers <- "#include <stdio.h> 1008 out <- [[[[[["
1490 #include <stdlib.h> 1009 var i = 0;
1491 #include \"builtin.h\" 1010 var TYPE_ANY = i++;
1492 #include \"object.h\" 1011 var TYPE_INT32 = i++;
1493 #include \"context.h\" 1012 var TYPE_UINT8 = i++;
1494 #include \"func.h\" 1013 var TYPE_UINT32 = i++;
1495 #include \"integer.h\" 1014 var TYPE_BOOLEAN = i++;
1496 #include \"blueprint.h\" 1015 var TYPE_FLOAT64 = i++;
1497 #include \"array.h\" 1016 var TYPE_BLUEPRINT = i++;
1498 #include \"worker.h\" 1017 var TYPE_ARRAY = i++;
1499 #include \"bool.h\" 1018 var TYPE_WORKER = i++;
1500 #include <sys/time.h>\n\n" 1019 var TYPE_FIRST_USER = i;
1501 out <- [[[[[[[[[[[[[[[[[[headers 1020
1502 ]Append[[program]Dispatch[all methods]] 1021 registered_types = new Array();
1503 ]Append[[[program]Type Registry >>]Type Defs] 1022
1504 ]Append[Fold[_Consts JS Program[?,?,?,p], 1023 function t_Blueprint()
1505 Fold[_Defs JS Program[?], "", [program]Functions >>], 1024 {
1506 constants]] 1025 }
1507 ]Append[Fold[_Text JS Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Not Native[?]]]] 1026
1508 ]Append["\n 1027 t_Blueprint.prototype.type_id = TYPE_BLUEPRINT;
1509 #ifdef ENABLE_PROFILING 1028 t_Blueprint.prototype.conversions = new Array();
1510 uint64_t profile_counts[END]; 1029 var t = new t_Blueprint;
1511 uint64_t profile_nestedcounts[END]; 1030 t.id = TYPE_BLUEPRINT;
1512 uint64_t profile_totals[END]; 1031 t.construct = t_Blueprint;
1513 uint64_t profile_selftotals[END]; 1032 registered_types[TYPE_BLUEPRINT] = t;\n\n"
1514 uint64_t profile_activationlevel[END]; 1033 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
1515 #endif
1516
1517 int32_t rhope(uint32_t func, object ** params, uint16_t numparams, uint16_t callspace)
1518 {
1519 #ifdef ENABLE_PROFILING
1520 struct timeval time;
1521 #endif
1522 uint16_t resume,idx, vcparam_offset, last_vcparam;
1523 context * ct;
1524 calldata * cdata, *temp_cdata, *my_cdata;
1525 DispatchVar
1526 FuncDef(Build)
1527 FuncDef(BlueprintSP_Of)
1528 FuncDef(ID)
1529 FuncDef(BlueprintSP_FromSP_ID)\n"]
1530 ]Append[Fold[Local Pointers[?], "", [program]Functions >>]]
1531 ]Append[" 1034 ]Append["
1532 ct = new_context(); 1035
1533 cdata = alloc_cdata(ct, NULL, callspace); 1036 function make_Int32(val)
1534 cdata->num_params = numparams; 1037 {
1535 for(idx = 0; idx < numparams; ++idx) 1038 var out = new t_Int32;
1536 cdata->params[idx] = params[idx]; 1039 out.p_Val = val;
1537 cdata->func = END; 1040 return out;
1538 DISPATCH\n"] 1041 }
1539 ]Append[Fold[Method Dispatch[?, ?, ?, [program]Type Registry >>], "", all methods]] 1042
1540 ]Append[" 1043 function make_UInt8(val)
1541 Func(Build, 1044 {
1542 NumParams 1) 1045 var out = new t_UInt8;
1543 1046 out.p_Val = val & 255;
1544 Param(0, TYPE_BLUEPRINT) 1047 return out;
1545 1048 }
1546 lv_Build->bp = ((t_Blueprint *)(cdata->params[0]))->bp; 1049
1547 release_ref(cdata->params[0]); 1050 function make_UInt32(val)
1548 1051 {
1549 Ret(0, new_object_bp(lv_Build->bp)) 1052 var out = new t_UInt32;
1550 EndFunc(Build) 1053 out.p_Val = val;
1551 DISPATCH 1054 return out;
1552 1055 }
1553 Func(BlueprintSP_Of, 1056
1554 NumParams 1) 1057 function make_Boolean(val)
1555 1058 {
1556 lv_BlueprintSP_Of->bp = get_blueprint(cdata->params[0]); 1059 var out = new t_Boolean;
1557 release_ref(cdata->params[0]); 1060 out.p_Val = val;
1558 1061 return out;
1559 Ret(0, new_object(TYPE_BLUEPRINT)) 1062 }
1560 ((t_Blueprint *)cdata->params[0])->bp = lv_BlueprintSP_Of->bp; 1063
1561 EndFunc(BlueprintSP_Of) 1064 function make_Float64(val)
1562 DISPATCH 1065 {
1563 1066 var out = new t_Float64;
1564 Func(ID, NumParams 1) 1067 out.p_Val = val;
1565 1068 return out;
1566 Param(0, TYPE_BLUEPRINT) 1069 }
1567 1070
1568 lv_ID->id = new_object(TYPE_UINT32); 1071 function make_Blueprint(typeid)
1569 ((t_UInt32 *)lv_ID->id)->Num = ((t_Blueprint *)cdata->params[0])->bp->type_id; 1072 {
1570 release_ref(cdata->params[0]); 1073 return registered_types[typeid];
1571 Ret(0, lv_ID->id) 1074 }
1572 EndFunc(ID) 1075
1573 DISPATCH 1076 function check_type(val,typeid)
1574 1077 {
1575 Func(BlueprintSP_FromSP_ID, NumParams 1) 1078 if (val.type_id = typeid) {
1576 1079 return val;
1577 Param(0, TYPE_UINT32) 1080 }
1578 1081 if (val.conversions[type_id] != undefined) {
1579 lv_BlueprintSP_FromSP_ID->type = ((t_UInt32 *)cdata->params[0])->Num; 1082 var out = val.conversions[type_id](val);
1580 if (lv_BlueprintSP_FromSP_ID->type >= max_registered_type || !registered_types[lv_BlueprintSP_FromSP_ID->type]) { 1083 return out[0];
1581 Ret(1, cdata->params[0]) 1084 }
1582 Ret(0, NULL) 1085 throw new Error(\"Conversion needed\");
1086 }
1087
1088 function f_Build(type)
1089 {
1090 type = check_type(type, TYPE_BLUEPRINT);
1091 return [new type.construct()];
1092 }
1093
1094 function f_BlueprintSP_Of(val)
1095 {
1096 return [registered_types[val.type_id]];
1097 }
1098
1099 function f_ID(type)
1100 {
1101 type = check_type(type, TYPE_BLUEPRINT);
1102 return [type.id];
1103 }
1104
1105 function f_BlueprintSP_FromSP_ID(id)
1106 {
1107 id = check_type(id, TYPE_UINT32);
1108 if (id.p_Val > 0 && registered_types[id.p_Val] != null) {
1109 return [registered_types[id.p_Val], null];
1583 } else { 1110 } else {
1584 release_ref(cdata->params[0]); 1111 return [null,id];
1585 Ret(0, new_object(TYPE_BLUEPRINT)) 1112 }
1586 ((t_Blueprint *)cdata->params[0])->bp = registered_types[lv_BlueprintSP_FromSP_ID->type]; 1113 }\n"]
1587 Ret(1, NULL) 1114 ]Append[Fold[_Text JS Program[?, ?, [program]Type Registry >>], "", [program]Functions >>]]
1588 }
1589
1590 EndFunc(BlueprintSP_FromSP_ID)
1591 DISPATCH\n"]
1592 ]Append[Fold[_Text JS Program[?, ?, [program]Type Registry >>], "", Filter[[program]Functions >>, Native[?]]]]
1593 ]Append["
1594 DO_END:
1595 for(idx = 0; idx < cdata->num_params; ++idx)
1596 params[idx] = cdata->params[idx];
1597 free_context(ct);
1598 return cdata->num_params;
1599
1600 _exception:
1601 puts(\"Exception! Trace follows:\");
1602 while(cdata && cdata->func != END)
1603 {
1604 printf(\"%d\\n\", cdata->func);
1605 cdata = cdata->lastframe;
1606 }
1607 return -1;
1608 }
1609
1610 #include \"builtin.c\"
1611 #include \"array.c\"
1612 #include \"worker.c\"
1613
1614 int main(int argc, char **argv)
1615 {
1616 blueprint * bp;
1617 int numret;
1618 int idx;
1619 object * inout[3];
1620 register_builtin_types();\n\n"]
1621 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ]
1622 ]Append[Fold[_Set Consts JS Program[?, ?, ?, [program]Type Registry >>], "", constants]] 1115 ]Append[Fold[_Set Consts JS Program[?, ?, ?, [program]Type Registry >>], "", constants]]
1623 ]Append[Fold[_Set Late Consts JS[?, ?, ?, [program]Type Registry >>], "", constants]] 1116 ]Append[Fold[_Set Late Consts JS[?, ?, ?, [program]Type Registry >>], "", constants]]
1624 ]Append[Fold[Init Type Names[?, ?, ?, [program]Type Registry >>], "", [[program]Type Registry >>]Lookup >>]]
1625 ]Append[" 1117 ]Append["
1626 rhope(FUNC_List, inout, 0, 1); 1118 var args = f_List()[0];
1627 for (idx = 0; idx < argc; ++idx) 1119 for (var i in arguments) {
1628 { 1120 args = args.f_Append(make_String(arguments[i]))[0];
1629 inout[1] = make_String(argv[idx]); 1121 }
1630 rhope(FUNC_Append, inout, 2, 2); 1122 f_Main(args);"]
1631 } 1123
1632 numret = rhope(FUNC_Main, inout, 1, 1);"] 1124 }
1633 ]Append[Fold[_Consts JS Release[?, ?, ?, p], "", constants]] 1125
1634 ]Append[ 1126
1635 "
1636 print_mem_info(manager);
1637 print_live_object_types(manager);
1638
1639 #ifdef ENABLE_PROFILING
1640 for (idx = 0; idx < END; ++idx)
1641 {
1642 if(profile_counts[idx])
1643 printf(\"Func: %d\tCount: %llu\tTime: %llu\tAvg: %f\tSelf: %llu\tAvg: %f\tNested Count: %llu\\n\", idx, profile_counts[idx], profile_totals[idx], ((double)profile_totals[idx])/((double)profile_counts[idx]), profile_selftotals[idx], ((double)profile_selftotals[idx])/((double)profile_counts[idx]), profile_nestedcounts[idx]);
1644 }
1645 #endif
1646 if (!numret)
1647 return 0;
1648 if (numret < 0)
1649 return numret;
1650 if (get_blueprint(inout[0])->type_id == TYPE_INT32)
1651 return ((t_Int32 *)inout[0])->Num;
1652
1653 rhope(FUNC_If, inout, 1, 2);
1654 if (inout[0])
1655 return 0;
1656 return 1;
1657 }\n\n"]
1658
1659 }
1660
1661