-
Notifications
You must be signed in to change notification settings - Fork 7
/
astcore.jc
13039 lines (12904 loc) · 530 KB
/
astcore.jc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//coulddo: whether s7rc is necessary
import "system.jc"
import "ctobj.jc"
import "util.jc"
import System.Algorithm.*
import System.Console.*
import System.Math.*
import Util.*
import Ctobj.*
ENABLE_FEM_DSL=1
ENABLE_GVN=1
ENABLE_DEADELIM=1
ENABLE_STACK_ALLOCS=1
DEBUG_MONITOR_REACH=0
DEBUG_REACH_LOG=0
DEBUG_EVAL_LOG=0
DEBUG_DUMP_FIX_CONSTANT_TYPES=0
DEBUG_DUMP_LAMBDA=0
DEBUG_DUMP_RC=0
DEBUG_DUMP_FLATTEN=0
DEBUG_DUMP_USER_FLAGS=0
DEBUG_DUMP_DERIV=0
DEBUG_TRAP_MEMBER_NOT_FOUND=0
DEBUG_DUMP_SSA=0
DEBUG_DUMP_DEADELIM=0
DEBUG_DUMP_PASSES=(Platform.BUILD=="debug")
DEBUG_DUMP_GVN_DETAILS=0
DEBUG_DUMP_SCCP=0
DEBUG_DUMP_STACKALLOC=0
DEBUG_DUMP_CALL_GRAPH=0
///////////////
DERIV_HAS_REUSABLE_COMPONENTS=0x80000000
fcompiler_callback=function(PExpression,int):TSCCPValue
g_inited_astcore=0
//g_builtin_scope=PCTObject(0)
g_cbobj_reach_fn_only=PCTObject(0)
g_cbobj_expand_inline_oneval=PCTObject(0)
g_cbobj_function_used_oneval=PCTObject(0)
g_cbobj_template_instantiation_oneval=PCTObject(0)
g_cbobj_generated_function_oncgen=PCTObject(0)
g_cbobj_cimport_cgen=PCTObject(0)
fdummy_callback=function(PExpression pecall,int expr_oplevel){return TSCCPValue(){'tid':g_vtid_UNINIT}}
auto citeexpr(PExpression pe)
epos0=readPool(pe+1)
epos1=readPool(pe+2)
if !epos0||!epos1:
return dumpExpr(pe,__zero(fcolorer_callback))
if epos1<0:
paepos=epos0
for(;;)
assert(readPool(paepos)==g_tid_TAdvancedEpos)
epos0=readPool(paepos+1)
epos1=readPool(paepos+2)
if epos0&0x80000000:
paepos=epos1
else
break
return cite_raw(epos0,epos1)
auto errorAtAEPos(int type0,PCTObject paepos0,string serr0)
type=type0
paepos=paepos0
serr=serr0
if Platform.BUILD=="debug":
arv=new int[int]
while paepos:
if Platform.BUILD=="debug":
if arv[paepos]:
Writeln('epos loop! ',paepos)
assert(0)
arv[paepos]=1
assert(readPool(paepos)==g_tid_TAdvancedEpos)
epos0=readPool(paepos+1)
epos1=readPool(paepos+2)
if epos0&0x80000000:
//it's an inline nested thing
paepos=(epos0&0x7fffffff)
if readPool(epos1)==g_tid_TAdvancedEpos:
//it's the parent-epos combo, show the error
assert(readPool(epos1+1)>=0)
error(type,readPool(epos1+1),readPool(epos1+2),serr)
else
//it's the parent-inline combo, reset the error but don't show it
assert(readPool(epos1)==g_tid_TFunction)
type=ETYPE_NOTE
serr="within expanded inline function '@1'".Replace(["@1",dumpFunction(epos1)])
else
//it's a normal epos
paepos=0
error(type,epos0,epos1,serr)
auto errorAtExpr(int type,PExpression pe,string serr)
if !g_expr_errored[pe]:
if g_names_resolved:
//only keep one error at each leaf location
paepos0=readPool(pe+1)
assert(readPool(paepos0)==g_tid_TAdvancedEpos)
if readPool(paepos0+1)<0:
paepos0=readPool(paepos0+2)
if g_expr_errored[0x80000000|paepos0]:return
g_expr_errored[0x80000000|paepos0]=1
paepos0=readPool(pe+1)
errorAtAEPos(type,paepos0,serr)
else
error(type,readPool(pe+1),readPool(pe+2),serr)
//generate the template notes
for(pei=pe;pei;)
pe_parent=readPool(pei+EXPR_OFS_CALLER)
if isBuiltin(pei,g_id_function):
val=getExprValue(pei)
assert(val.tid==g_vtid_CTVAL)
pobjfn=val.val
pobjfn_template=readPool(pobjfn+FUNCTION_OFS_TEMPLATE)
if pobjfn_template:
errorAtAEPos(ETYPE_NOTE,readPool(pobjfn+FUNCTION_OFS_TEMPLATE_EPOS0),"during instantiation of '@1'".Replace(["@1",dumpFunction(pobjfn)]))
pei=pe_parent
g_expr_errored[pe]=1
auto getDotMember(PExpression pecall,int do_err,int do_dyndecl)
peobj=readPool(pecall+EXPR_OFS_ARGS+0)
val_obj=getExprValue(peobj)
if val_obj.tid==g_vtid_STR||val_obj.tid==g_vtid_CTVAL:
//constant string or constant function dotted, force into rtvar
pobj_str_var=PCTObject(0)
if isExpr(peobj,EFLAG_VARIABLE):
pobj_str_var=getVariable(peobj)
else if isExpr(peobj,EFLAG_FCALL):
pobjfn=getExprFunction(peobj)
if pobjfn:
pobj_str_var=readPool(pobjfn+FUNCTION_OFS_PVAR_RETURN)
if pobj_str_var:
//dotted const strings / functions become vars
//if val_obj.tid==g_vtid_STR:
// t=getStdObject(pecall,STDTYPE_STRING)
//else
t=getValueTypeEx(pecall,val_obj)
if !t:return 0
if val_obj.tid==g_vtid_CTVAL&&isFunction(val_obj.val):
//151022: getValueTypeEx - it doesn't call setFunctionUsed for void functions
//151022: need setParameterSlotTypes since we need to setvar its params
setFunctionUsed(val_obj.val)
setParameterSlotTypes(val_obj.val)
fstore_eval_core_ex(pecall,pobj_str_var,TSCCPValue(){tid:g_vtid_RTVAR,'val':t},1)
pe_member_name=readPool(pecall+EXPR_OFS_ARGS+1)
id_member=getExprValueAs(pe_member_name,g_vtid_STR)
if !id_member:
pobj_member=getExprValueAs(pe_member_name,g_vtid_CTVAL)
if isVariable(pobj_member):
return pobj_member
else
return 0
t=getExprType(peobj)
if !t||!tisclass(t):
val=getExprValue(peobj)
if val.tid!=g_vtid_UNINIT&&do_err:
if DEBUG_TRAP_MEMBER_NOT_FOUND:
Writeln('-------------------');Writeln(dumpExpr(pecall,__zero(fcolorer_callback)))
Writeln('-------------------');Writeln(dumpExpr(g_pe_top,__zero(fcolorer_callback)))
assert(0)
if t:
errorAtExpr(ETYPE_ERROR,pecall,"only class-typed expressions can have members ('@3'), but '@1' is of type '@2'".Replace(["@1",citeexpr(peobj),"@2",dumpType(t),"@3",getIdString(id_member)]))
else
errorAtExpr(ETYPE_ERROR,pecall,"only class-typed expressions can have members ('@2'), but '@1' is of an invalid type".Replace(["@1",citeexpr(peobj),"@2",getIdString(id_member)]))
//Writeln(">>> "+dumpExpr(pecall,fcolor_abbrv_blocks))
//Writeln('top='+dumpExpr(g_pe_top,fcolor_reach_eval))
//assert(0)
setnop(pecall)
return 0
setFunctionUsed(t)//dotted-but-never-newed class
if !id_member:
pobj_member=getExprValueAs(pe_member_name,g_vtid_CTVAL)
//direct dot
if pobj_member&&isVariable(pobj_member):
return pobj_member
pf_class=t
pobj_member=lookupFunctionVariable(pf_class,id_member)
if !pobj_member&&(getFFlag(pf_class)&FFLAG_SUPPORT_DYNAMIC_MEMBERS):
if do_dyndecl:
//dynamic objects - allow dynamic variable decl - push-able member list + i2 hash
pobj_member=makevar(pf_class)
writePool(pobj_member+VAR_OFS_ID,id_member)
p_members=readPool(pf_class+FUNCTION_OFS_PMEMBER_LIST);
n_members=readPool(pf_class+FUNCTION_OFS_NMEMBER_LIST);
sz_list=readPool(pf_class+FUNCTION_OFS_SZ_MEMBER_LIST);
if !(n_members<sz_list):
//double it
sz_list=max(32,n_members*2)
p_members0=p_members
p_members=int(g_ctobject_pool.n)
g_ctobject_pool.resize(p_members+sz_list)
writePool(pf_class+FUNCTION_OFS_PMEMBER_LIST,p_members)
writePool(pf_class+FUNCTION_OFS_SZ_MEMBER_LIST,sz_list)
for i=0:n_members-1
writePool(p_members+i,readPool(p_members0+i))
writePool(pf_class+FUNCTION_OFS_NMEMBER_LIST,n_members+1)
writePool(p_members+n_members,id_member)
writeGlobalI2Hash(int2(pf_class,id_member),pobj_member)
else
return 0
if !pobj_member&&do_err:
errorAtExpr(ETYPE_ERROR,pecall,"class '@1' doesn't have member '@2'".Replace(["@1",dumpType(t),"@2",getIdString(id_member)]))
//assert(0)
//assert(id_member!=g_id_operator_bracket)
if DEBUG_TRAP_MEMBER_NOT_FOUND:
Writeln('-------------------');Writeln(dumpExpr(pecall,__zero(fcolorer_callback)))
Writeln('-------------------');Writeln(dumpExpr(g_pe_top,__zero(fcolorer_callback)))
assert(0)
return 0
//cache the result
//writePool(pe_member_name,EFLAG_CTVAL+pobj_member)
return pobj_member
inline fstore_eval_core(PExpression pecall,PCTObject pobj_var,PExpression pe_value,int test_return)
val_new=getExprValue(pe_value)
return fstore_eval_core_ex(pecall,pobj_var,val_new,test_return)
auto fstore_eval_core_ex(PExpression pecall,PCTObject pobj_var,TSCCPValue val_new,int test_return)
vv=readPoolTyped(pobj_var,TVariable)
val_old=TSCCPValue()
val_old.tid=vv.tid
val_old.val=vv.val
val_final=mergeValues(pecall,val_old,val_new, pobj_var|0x80000000,pecall)
if pobj_var&&vv.tid!=g_vtid_UNINIT&&val_final.tid==g_vtid_RTVAR&&tisclass(readPool(pobj_var+VAR_OFS_OWNER)):{
val_oldx=TSCCPValue()
val_oldx.tid=vv.tid
val_oldx.val=vv.val
auto check_t0=getValueType(val_oldx)
auto check_t1=getValueType(val_final)
if check_t0!=check_t1:
errorAtExpr(ETYPE_WARNING,pecall,"member '@1' has changed type: @2 -> @3".Replace([
"@1",getIdString(readPool(pobj_var+VAR_OFS_ID)),
"@2",dumpType(check_t0),
"@3",dumpType(check_t1)]))
}
//Writeln(getIdString(ervar.v.key),' <- ',getIdString(val_old.tid),' || ',getIdString(val_new.tid))
force_changed=0
if val_final.tid==g_vtid_CTVAL:
//but if it's a function
pobj=val_final.val
pobjfn=getAsFunction(pobj)
if pobjfn:
value_time_new=readPool(pobjfn+FUNCTION_OFS_VALUE_TIME)
if vv.value_time<value_time_new||val_old.tid!=val_final.tid||val_old.val!=val_final.val:
vv.value_time=value_time_new
force_changed=1
//if val_old.tid==val_final.tid&&val_old.val==val_final.val:
// Writeln(getIdString(ervar.v.key),' ',vv.value_time,' ',value_time_new)
// if force_changed:
// Writeln('force_changed! ',getIdString(ervar.v.key))
if val_old.tid==val_final.tid&&val_old.val==val_final.val&&!force_changed:
//it didn't change
return TSCCPValue(){tid:g_vtid_UNINIT}
//g_readable_c_code
if pobj_var:
//if it's a function, try to set the function's name
vid=readPool(pobj_var+VAR_OFS_ID)
if val_final.tid==g_vtid_CTVAL:
pobj=val_final.val
pobjfn=getAsFunction(pobj)
if pobjfn:
id_name=readPool(pobjfn+FUNCTION_OFS_NAME)
if !id_name:
writePool(pobjfn+FUNCTION_OFS_NAME,vid)
//write back and invalidate all users
vv.tid=val_final.tid
vv.val=val_final.val
writePoolTyped(pobj_var,vv)
if DEBUG_EVAL_LOG:
Write('changed - queueeval ',dumpObject(pobj_var),' ',getIdString(val_old.tid),' -> ',getIdString(val_final.tid))
//if vv.id==getid('length')&&val_final.tid==g_vtid_RTVAR:
// assert(0)
//if pobj_var==1102774:
// Writeln('top='+dumpExpr(g_pe_top,fcolor_reach_eval))
// assert(0)
if val_final.tid==g_vtid_CNS:
Write(' ',dumpConst(Util.g_const_values[val_final.val]))
else if val_final.tid==g_vtid_STR:
Write(' ',getIdString(val_final.val))
else if val_final.tid==g_vtid_CTVAL:
Write(' ',dumpObject(val_final.val))
else if val_final.tid==g_vtid_RTVAR:
Write(' ',dumpType(val_final.val))
Writeln()
queueEvalUsers(pobj_var)
idvar=readPool(pobj_var+VAR_OFS_ID)
if test_return:
if idvar==g_id_return:
pobjfn=getOwningFunction(pecall)
if pobjfn:
pvar_return=readPool(pobjfn+FUNCTION_OFS_PVAR_RETURN)
if pobj_var==pvar_return:
queueEvalFunction(pobjfn)
if idvar==g_id_finalizer&&val_new.tid==g_vtid_CTVAL&&readPool(val_new.val)==g_tid_TFunction:
pobjfn=getOwningFunction(pecall)
if tisrealclass(pobjfn):
setFunctionUsed(val_new.val)
else
id_ccnv=getCcnv(pobjfn)
if id_ccnv==g_id_struct:
//coulddo: support it
errorAtExpr(ETYPE_WARNING,pecall,"__done__ is not supported in a struct")
else
errorAtExpr(ETYPE_WARNING,pecall,"__done__ is pointless in an ordinary function")
return TSCCPValue(){'tid':g_vtid_UNINIT}
auto lockValueCheck(PExpression pe,int id_error_message)
writePool(pe+EXPR_OFS_CALLER,0)
return call(g_id_assert_ctval,pe,exprstr(id_error_message))
inline getExprNArgs(PExpression pe)
//we return args number for the expression
ret=readPool(pe)
assert((ret&EFLAG_MASK)==EFLAG_FCALL&&!EFLAG_FCALL)
return ret
auto computeConstIfBranch(PExpression pecall,TSCCPValue val_cond)
//we return branch arg number for call expression, given cond value
n_args=getExprNArgs(pecall)
cns_branch=1
for i=2:2:n_args-2
val_i=getExprValue(readPool(pecall+EXPR_OFS_ARGS+i))
if isValueZero(val_i):
if isValueZero(val_cond):
cns_branch=i+1
break
else
if val_cond.tid==val_i.tid&&val_cond.val==val_i.val:
cns_branch=i+1
break
//handle shared case values
while cns_branch<n_args&&readPool(readPool(pecall+EXPR_OFS_ARGS+cns_branch))==EFLAG_STRING+g_id_case:
cns_branch+=2
if cns_branch>=n_args:
cns_branch=1
return cns_branch
ftransformer_callback=function(PExpression):PExpression
inline transformCode(PExpression pesrc, ftransformer_callback ftransformer, PExpression[] as_before,PExpression pe_replacement,PExpression[] as_after)
return transformCodeEx(pesrc, ftransformer, as_before,pe_replacement,as_after, 1)
//inline
auto replaceExpr(PExpression pesrc, PExpression pe_replacement)
//return transformCode(pesrc,__zero(ftransformer_callback), PExpression[].NULL,pe_replacement,PExpression[].NULL)
pecaller=readPool(pesrc+EXPR_OFS_CALLER)
return sccpQueueReach(insertCallAt(pecaller,pesrc,function(PExpression pe){return pe_replacement}))
auto replaceExprNoQueueReach(PExpression pesrc, PExpression pe_replacement)
//return transformCode(pesrc,__zero(ftransformer_callback), PExpression[].NULL,pe_replacement,PExpression[].NULL)
pecaller=readPool(pesrc+EXPR_OFS_CALLER)
return insertCallAt(pecaller,pesrc,function(PExpression pe){return pe_replacement})
auto transformCodeEx(PExpression pesrc, ftransformer_callback ftransformer, PExpression[] as_before,PExpression pe_replacement,PExpression[] as_after, int queue_reach)
if !ftransformer&&(!as_before||!as_before.n)&&!pe_replacement&&(!as_after||!as_after.n):
return pesrc
pecaller=readPool(pesrc+EXPR_OFS_CALLER)
nargs_caller=readPool(pecaller)&~EFLAG_MASK
if pesrc<=0:
arg_id=~pesrc
else
arg_id=-2
for i=-1:nargs_caller-1
if readPool(pecaller+EXPR_OFS_ARGS+i)==pesrc:
arg_id=i
break
if arg_id<-1:
assert(0)
return 0
assert(u32(arg_id)<u32(nargs_caller)||arg_id==-1)
/////////////
pe_block_level=promoteToBlockLevel(pesrc)
peold=readPool(pecaller+EXPR_OFS_ARGS+arg_id)
epos0=readPool(peold+1)
epos1=readPool(peold+2)
writePool(peold+EXPR_OFS_CALLER,0)
pe_real_replacement=peold
pe_transformed=PExpression(0)
if pe_replacement:
if ftransformer:
pe_transformed=ftransformer(pe_real_replacement)
pe_real_replacement=pe_replacement
/////////////
//create the new thing
need_temp=(pesrc!=pe_block_level&&as_after&&as_after.n&&!isExpr(pe_real_replacement,EFLAG_VARIABLE))
pv_temp=PCTObject(0)
pe_block_mid0=PExpression(0)
if need_temp:
pf_owner=getOwningFunction(pecaller)
pv_temp=makevar(pf_owner)
val=getExprValue(pe_real_replacement)
writePool(pv_temp+0,val.tid)
writePool(pv_temp+1,val.val)
//writePool(pe_real_replacement+1,epos0)
//writePool(pe_real_replacement+2,epos1)
fillepos(pe_real_replacement,epos0,epos1)
pe_block_mid0=call(g_id_store,exprvar(pv_temp),pe_real_replacement)
writePool(pv_temp+VAR_OFS_DEFINING_STORE,pe_block_mid0)
pe_real_replacement=exprvar(pv_temp)
//writePool(pe_real_replacement+1,epos0)
//writePool(pe_real_replacement+2,epos1)
else
pe_block_mid0=0
/////
writePool(pe_real_replacement+EXPR_OFS_CALLER,pecaller)
//writePool(pe_real_replacement+1,epos0)
//writePool(pe_real_replacement+2,epos1)
fillepos(pe_real_replacement,epos0,epos1)
writePool(pecaller+EXPR_OFS_ARGS+arg_id,pe_real_replacement)
if queue_reach:
sccpQueueReach(pe_real_replacement)
/////
pe_fnblock=exprvar(g_symbols[g_id_block].user_slot)
pe_new_block=poolCode(TExpression(){'flags_n_args':EFLAG_FCALL})
g_ctobject_pool.push(pe_fnblock)
if as_before:g_ctobject_pool.push(as_before)
if pe_transformed:
sccpQueueReach(pe_transformed)//avoid assertion failure
g_ctobject_pool.push(pe_transformed)
if pe_block_mid0:g_ctobject_pool.push(pe_block_mid0)
if pe_block_level==pesrc:
g_ctobject_pool.push(pe_real_replacement)
if as_after:g_ctobject_pool.push(as_after)
if pe_block_level!=pesrc:
g_ctobject_pool.push(pe_block_level)
else
pe_block_level=pe_real_replacement
pe_block_level_caller=readPool(pe_block_level+EXPR_OFS_CALLER)
n_args=(g_ctobject_pool.n-(pe_new_block+EXPR_OFS_ARGS))
if n_args==1:
pe_new_block=readPool(pe_new_block+EXPR_OFS_ARGS+0)
//n_args=getExprNArgs(pe_new_block)
//in that case, we don't need the caller reset anymore
n_args=0
else
writePool(pe_new_block,int(EFLAG_FCALL+n_args))
//replace pe_block_level with pe_new_block
pe_new_block=insertCallAt(pe_block_level_caller,pe_block_level,function(PExpression pe){return pe_new_block})
if queue_reach:
sccpQueueReach(pe_new_block)
for i=0:n_args-1
//if readPool(pe_new_block+EXPR_OFS_ARGS+i)>=536000000:
// Writeln('bad arg: ',i,' ',readPool(pe_new_block+EXPR_OFS_ARGS+i),' ',n_args,' ',pe_block_level,' ',
// pesrc,' ',dumpExpr(pe_block_level,__zero(fcolorer_callback)),' ',
// pe_new_block,' ',dumpExpr(pe_new_block,__zero(fcolorer_callback)))
writePool(readPool(pe_new_block+EXPR_OFS_ARGS+i)+EXPR_OFS_CALLER,pe_new_block)
//Writeln("TT>> "+dumpExpr(pe_new_block,function(PExpression pe_test){
// if pe_test==pe_block_level||pe_test==pesrc:return 9;
// if pe_test==pecaller:return 11;
// return fcolor_reach_eval(pe_test)
//}))
return pe_new_block
auto queueCodeGen(PCTObject pobjfn)
if !(getFFlag(pobjfn)&FFLAG_CGEN_QUEUED):
if Platform.BUILD=="debug":
if !(getCcnv(pobjfn)!=g_id_inline&&getCcnv(pobjfn)!=g_id_inline_loopbody):
Writeln('queueing inline function: ',dumpFunction(pobjfn))
assert(getCcnv(pobjfn)!=g_id_inline&&getCcnv(pobjfn)!=g_id_inline_loopbody)
setFFlag(pobjfn,FFLAG_CGEN_QUEUED)
g_gencode_queue.push(readPool(pobjfn+FUNCTION_OFS_PEDECL))
if Platform.BUILD=="debug":
if !(!isExpr(readPool(pobjfn+FUNCTION_OFS_CODE),EFLAG_FCALL)||testUserFlag(readPool(pobjfn+FUNCTION_OFS_CODE),QUEUE_FLAG_REACH)):
if !(getFFlag(pobjfn)&FFLAG_IMPORTED):
Writeln('queueing unreached function: ',dumpFunction(pobjfn))
assert(0)
//assert(!isExpr(readPool(pobjfn+FUNCTION_OFS_PEDECL),EFLAG_STRING))
//Writeln('queueCodeGen: ',dumpObject(pobjfn))
auto setParameterSlotTypes(PCTObject pobjfn)
pe_decl=readPool(pobjfn+FUNCTION_OFS_PEDECL)
n_funcargs=((readPool(pe_decl)&~EFLAG_MASK)-2)>>1
p_param_values=readPool(pobjfn+FUNCTION_OFS_PPARAM_VALUE_SLOTS)
for i=0:n_funcargs-1
t=getExprValueAs(readPool(pe_decl+EXPR_OFS_ARGS+1+i*2),g_vtid_CTVAL)
if t:
writePool(p_param_values+i*3+0,g_vtid_RTVAR)
writePool(p_param_values+i*3+1,t)
pe_ldparam=readPool(p_param_values+i*3+2)
if pe_ldparam:
sccpQueueEval(pe_ldparam)
auto fcolor_user_flags(PExpression pe)
val=getExprValue(pe)
if val.tid==g_vtid_UNINIT:
if !testUserFlag(pe,QUEUE_FLAG_REACH):
if isBuiltin(pe,g_id_block):
return -2
else
return -1
if isBuiltin(pe,g_id_function):
return -2
c=7
if isExpr(pe,EFLAG_VARIABLE):
pobj_var=getVariable(pe)
if pobj_var:
if testUserFlag(pobj_var,1):
c-=1
if testUserFlag(pobj_var,2):
c-=2
return c
if testUserFlag(pe,1):
c-=1
if testUserFlag(pe,2):
c-=2
return c
auto getLIObjectStringPair(PCTObject pobj)
id_str0=0
id_str1=0
key=int2(0x80000000+pobj,0x80000001)
if readPool(pobj)==g_tid_TFunction:
id_str_stored=readEPosHash(key)
if !id_str_stored:
id_str_stored=getid(dumpFunction(pobj)+"\n")
writeEPosHash(key,id_str_stored)
id_str0=id_str_stored
else
assert(readPool(pobj)==g_tid_TAdvancedEpos)
epos0=readPool(pobj+1)
assert(epos0>0)
(id_fn0,ln0,col0)=getLineInfo(epos0)
id_str0=id_fn0
id_str_stored=readEPosHash(key)
if !id_str_stored:
epos1=readPool(pobj+2)
(id_fn1,ln1,col1)=getLineInfo(epos1)
//Writeln(getIdString(id_fn0),' ',getIdString(id_fn1),' ',epos0,' ',epos1)
assert(id_fn0==id_fn1)
if ln0==ln1:
id_str_stored=getid(FormatAsText(':',ln0+1,',',col0+1,'-',col1+1,': '))
else
id_str_stored=getid(FormatAsText(':',ln0+1,',',col0+1,'-',ln1+1,',',col1+1,': '))
writeEPosHash(key,id_str_stored)
id_str1=id_str_stored
return int2(id_str0,id_str1)
auto genLIString(string buf,int id)
if !readEPosHash(int2(0x80000000+id,0x80000002)):
g_debug_file_info_buffer.push('static const char s7_Df')
g_debug_file_info_buffer.push(toBase32(id))
g_debug_file_info_buffer.push('[]="')
g_debug_file_info_buffer.push(genString(getIdString(id)))
g_debug_file_info_buffer.push('";\n')
writeEPosHash(int2(0x80000000+id,0x80000002),1)
buf.push("s7_Df")
buf.push(toBase32(id))
if Platform.BUILD=="debug":
g_li_arv=new int[int]
auto getLineInfoId(PCTObject paepos)
if Platform.BUILD=="debug":
if g_li_arv[paepos]:
Writeln('epos loop! ',paepos)
assert(0)
g_li_arv[paepos]=1
key=int2(0x80000000+paepos,0x80000000)
lid=readEPosHash(key)
if !lid:
assert(readPool(paepos)==g_tid_TAdvancedEpos)
epos0=readPool(paepos+1)
lid_next=0
if epos0&0x80000000:
lid_next=getLineInfoId(epos0&0x7fffffff)
id_strs=getLIObjectStringPair(readPool(paepos+2))
else
id_strs=getLIObjectStringPair(paepos)
if id_strs.y:
g_debug_line_info_buffer.push('{')
genLIString(g_debug_line_info_buffer,id_strs.y)
if lid_next:
g_debug_line_info_buffer.push(',s7_DL+')
g_debug_line_info_buffer.push(string(lid_next-1))
g_debug_line_info_buffer.push('},\n')
lid_next=++g_current_line_info_id
g_debug_line_info_buffer.push('{')
genLIString(g_debug_line_info_buffer,id_strs.x)
if lid_next:
g_debug_line_info_buffer.push(',s7_DL+')
g_debug_line_info_buffer.push(string(lid_next-1))
g_debug_line_info_buffer.push('},\n')
lid=++g_current_line_info_id
writeEPosHash(key,lid)
return lid
auto genLineInfoExpr(PExpression pecall)
//we set a leaf to the spapAddCallStack structure
//nested epos should form a pre-built tree, print epos and print func ops, addcallstack chains a print fun
//just "print string", could share pointers
paepos0=readPool(pecall+1)
if !paepos0:
g_code_buffer.push('0')
return
if Platform.BUILD=="debug":
g_li_arv=new int[int]
lid=getLineInfoId(paepos0)
g_code_buffer.push("s7_Dd.li=s7_DL+")
SWrite(g_code_buffer,lid-1)
inline parameterTypeCheck(PCTObject t_expected,PCTObject t)
if t_expected==t:return 1
if tisbuiltin(t_expected)&&tisbuiltin(t):
ct_expected=readPool(t_expected+1)
ct=readPool(t+1)
if ct_expected==const_type(CTYPE_INT,Util.bitSize())&&ct==const_type(CTYPE_INT,32):
//iptr always matches i32
return 1
return 0
auto getReturnLabel(PCTObject pf)
id_ret=readPool(pf+FUNCTION_OFS_RETURN_LABEL_CACHE)
if !id_ret:
id_ret=catid(g_id_return_,getid(toBase32(pf)))
writePool(pf+FUNCTION_OFS_RETURN_LABEL_CACHE,id_ret)
return id_ret
inline isReturnJump(PExpression pe)
if isBuiltin(pe,g_id_blockex):
flags_id=readPool(readPool(pe+EXPR_OFS_ARGS+0))
if (flags_id&EFLAG_MASK)==EFLAG_STRING:
return isTempId(flags_id-EFLAG_STRING)
else
return 0
else
return 0
auto makeAdvEpos(int epos0,int epos1)
assert(epos1>0)
epos_new=readEPosHash(int2(epos0,epos1))
if !epos_new:
epos_new=poolObject(TAdvancedEpos(){'epos0':epos0,'epos1':epos1})
writeEPosHash(int2(epos0,epos1),epos_new)
return epos_new
auto expr_C_const(string sdata)
vid=int(g_ctobject_pool.n)
s_c_code=new string
s_c_code.push("@raw:long long s7_CD")
s_c_code.push(toBase32(vid))
s_c_code.push("[]={")
nalg=(sdata.n&-8)
buf64=sdata[:nalg-1].ConvertToAsBinary(i64)
for i=0:buf64.n-1
if s_c_code.back()!='{':
s_c_code.push(',')
s_c_code.push(string(buf64[i]))
s_c_code.push('LL')
tail=0LL
for i=nalg:sdata.n-1
tail|=i64(u8(sdata[i]))<<(int(i-nalg)*8)
if s_c_code.back()!='{':
s_c_code.push(',')
s_c_code.push(string(tail))
s_c_code.push('LL')
s_c_code.push('};')
return call(g_id_C_wrap,exprctval(getBuiltinType(CTYPE_POINTER)),exprstr(getid(s_c_code)),expriptr(vid))
g_varifyDblMembers_called=new int[PCTObject]
auto varifyDblMembers(PExpression pecall,PCTObject t)
if !t||!tisclass(t):return
if g_varifyDblMembers_called[t]:return
g_varifyDblMembers_called[t]=1
if DEBUG_DUMP_DERIV:
Writeln('varifyDblMembers: ',dumpType(t))
p_members=readPool(t+FUNCTION_OFS_PMEMBER_LIST)
n_members=readPool(t+FUNCTION_OFS_NMEMBER_LIST)
for i=0:n_members-1
id_member=readPool(p_members+i)
if id_member==g_id_this||id_member==g_id_return:continue
pobj_member=lookupFunctionVariable(t,id_member)
t_i=getVariableType(pobj_member)
//Writeln(getIdString(readPool(pobj_member)),' ',dumpType(t_i),' ',getIdString(id_member))
if readPool(pobj_member)==g_vtid_CNS:
if tisctype(t_i,CTYPE_FLOAT):
if DEBUG_DUMP_DERIV:
Writeln('varify: ',dumpType(t_i),' ',getIdString(id_member))
fstore_eval_core_ex(pecall,pobj_member,TSCCPValue(){'tid':g_vtid_RTVAR,'val':t_i},0)
else
varifyDblMembers(pecall,t_i)
g_json_pool=new int[][int]
g_id_error_class_cannot_change=getid("expression '@1' is used as a class and has to hold a constant value")
g_id_error_template_cannot_change=getid("expression '@1' is used as a template function and has to hold a constant value")
g_id_error_inline_cannot_change=getid("expression '@1' is used as an inline function and has to hold a constant value")
g_id_error_const_cannot_change=getid("expression '@1' is used as a template parameter and has to hold a constant value")
g_id_error_int_cannot_change=getid("expression '@1' is used as a constant integer and has to hold a constant value")
g_id_symderiv=getid("symbolicDerivative")
g_id_option_exclusive=getid("<exclusive>")
g_id_ANM_decompose=getid("__ANM_decompose")
g_id_make_polynomial=getid("__make_polynomial")
g_id_deriv=getid("_deriv")
//g_id_deriv_prefix=getid("_deriv_")
g_id_deriv_callback=getid("_deriv_callback")
g_id_deriv_pulling_masks=getid("_deriv_pulling_masks")
g_id_deriv_reusable_components=getid("_deriv_reusable_components")
g_id__=getid("_")
g_id_powd=getid("powd")
g_id_gvn_ctunique=getid("<gvn_ctunique>")
g_id_assert_type=getid("__assert_type")
//these are initialized later
g_fakectval_gvn_cns=0
g_fakectval_gvn_str=0
g_fakectval_gvn_extvar=0
g_cid_null=getid_const(CTYPE_POINTER,0LL)
auto coreInit()
if g_inited_astcore:return
g_inited_astcore=1
g_fakectval_gvn_cns=int(g_ctobject_pool.n);g_ctobject_pool.push(0)
g_fakectval_gvn_str=int(g_ctobject_pool.n);g_ctobject_pool.push(0)
g_fakectval_gvn_extvar=int(g_ctobject_pool.n);g_ctobject_pool.push(0)
//g_builtin_scope=ONew()
/////////////////////
freach_fn_only=function(PExpression pecall,int expr_oplevel){
sccpQueueReach(readPool(pecall+EXPR_OFS_FUNCTION))
return TSCCPValue(){'tid':g_vtid_UNINIT}
}
fexpand_inline_oneval=function(PExpression pecall,int expr_oplevel){
//type check
//Writeln('fexpand_inline_oneval')
pobjfn=getExprFunction(pecall)
is_loop_body=(getCcnv(pobjfn)==g_id_inline_loopbody)
//Writeln('expanding: ',dumpFunction(pobjfn))
n_args=getExprNArgs(pecall)
n_funcargs=getNumberOfArguments(pobjfn)
if n_args<n_funcargs:
sfname=new(getIdString(readPool(pobjfn+FUNCTION_OFS_NAME)))
//Writeln(dumpExpr(g_pe_top,fcolor_reach_eval))
//Writeln("bad inline - "+dumpExpr(pecall,fcolor_abbrv_blocks))
//assert(0)
errorAtExpr(ETYPE_ERROR,pecall,"inline function '@1' takes @2 arguments, but only @3 are provided".Replace([
"@1",sfname,
"@2",string(n_funcargs),
"@3",string(n_args)
]))
setnop(pecall)
return TSCCPValue(){'tid':g_vtid_UNINIT}
pe_decl=readPool(pobjfn+FUNCTION_OFS_PEDECL)
pe_param_checks=PExpression[].NULL
for i=0:n_funcargs-1
pe_argi=readPool(pecall+EXPR_OFS_ARGS+i)
pe_typei=readPool(pe_decl+EXPR_OFS_ARGS+i*2+1)
val_t_expected=getExprValue(pe_typei)
t_expected=0
if val_t_expected.tid==g_vtid_CTVAL:
t_expected=val_t_expected.val
else if val_t_expected.tid==g_vtid_STR:
//auto
continue
else if val_t_expected.tid==g_vtid_UNINIT:
t_expected=0
else
assert(0)
continue
t=getExprType(pe_argi)
if !t:
//typed inline parameters *MUST* be typed before expanding
if (readPool(pe_argi)&EFLAG_MASK)==EFLAG_STRING:
//wait for the string type
sccpQueueEval(pecall)
else
sccpQueueReach(pe_argi)
return TSCCPValue(){'tid':g_vtid_UNINIT}
if !t_expected:
//wait for the type later
if !pe_param_checks:
pe_param_checks=new PExpression[]
pe_param_checks.push(fillepos(call(g_id_assert_ctval,exprstr(g_id_assert_type),getid("type mismatch at parameter #@3 of @4: '@1' is expected but '@2' provided".Replace(["@1",citeexpr(pe_typei),"@2",dumpType(t),"@3",string(i),"@4",dumpFunction(pobjfn)])),
cloneExpr(pe_typei),exprctval(t)),readPool(pe_argi+EXPR_OFS_EPOS),0))
//Writeln(dumpFunction(pobjfn),' ',i,' ',dumpType(t_expected),' ',dumpType(t))
if !parameterTypeCheck(t_expected,t):
errorAtExpr(ETYPE_ERROR,pe_argi,"type mismatch at parameter #@3 of @4: '@1' expected but '@2' provided".Replace(["@1",dumpType(t_expected),"@2",dumpType(t),"@3",string(i),"@4",dumpFunction(pobjfn)]))
setnop(pecall)
return TSCCPValue(){'tid':g_vtid_UNINIT}
//actual expanding
//fn=readPoolTyped(pobjfn,TFunction)
pf_owner=getOwningFunction(pecall)
assert(!!pf_owner)
var_map=new PCTObject[PCTObject]
var_map[pobjfn]=pf_owner
pe_func=readPool(pecall+EXPR_OFS_FUNCTION)
pe_this=0
pe_store_this=0
pe_expanded=cloneExprEx(readPool(pobjfn+FUNCTION_OFS_CODE),var_map,CLONE_WIPE_TO_UNREACHED|CLONE_VARS|(tisclass(pf_owner)?0:CLONE_KEEP_VAR_IDS))
/////////
//old epos plus function
epos_parent=0x80000000+makeAdvEpos(0x80000000+readPool(pecall+1),pobjfn)
fnest_eposes=function(PExpression pe){
epos_old=readPool(pe+1)
assert(epos_old>=0)
if epos_old:
//strip previous inline callstacks
while readPool(epos_old)==g_tid_TAdvancedEpos&&readPool(epos_old+1)<0
epos_old=readPool(epos_old+2)
writePool(pe+1,makeAdvEpos(epos_parent,epos_old))
return 1
}
dfsExpr(pe_expanded,fnest_eposes)
/////////
if isBuiltin(pe_func,g_id_dot):
//assert(0)
//Writeln(">>> "+dumpExpr(pecall,fcolor_abbrv_blocks))
pe_this=readPool(pe_func+EXPR_OFS_ARGS+0)
pv_this=rcGetVariableIfExprIsOne(pe_this)
if !pv_this:
pv_this=makevar(pf_owner)
writePool(pv_this+0,g_vtid_RTVAR)
writePool(pv_this+1,getExprType(pe_this))
pe_store_this=call(g_id_store,exprvar(pv_this),pe_this)
writePool(pv_this+VAR_OFS_DEFINING_STORE,pe_store_this)
pf_class=getOwningFunction(readPool(readPool(pobjfn+FUNCTION_OFS_PEDECL)+EXPR_OFS_CALLER))
//var_map[pf_class]=~pv_this
freplace_class_members=function(PExpression pe){
if isExpr(pe,EFLAG_VARIABLE):
auto pobj_var=getVariable(pe)
if readPool(pobj_var+VAR_OFS_OWNER)==pf_class:
auto idvar=readPool(pobj_var+VAR_OFS_ID)
assert(!!idvar)
pecaller=readPool(pe+EXPR_OFS_CALLER)
//if idvar==getid("f0"):
// Writeln(dumpType(pf_class),' ',dumpObject(pf_owner))
// Writeln(">>>f0!\n"+dumpExpr(pe_expanded,__zero(fcolorer_callback)))
// assert(0)
if idvar==g_id_this:
//this
writePool(pe,EFLAG_VARIABLE+pv_this)
else if isBuiltin(pecaller,g_id_store)&&pe==readPool(pecaller+EXPR_OFS_ARGS+0):
//stdot
pecaller_caller=readPool(pecaller+EXPR_OFS_CALLER)
fcreate_stdot=function(PExpression pe_store){
//return call(g_id_stdot,exprvar(pv_this),exprstr(idvar),readPool(pe_store+EXPR_OFS_ARGS+1))
return call(g_id_stdot,exprvar(pv_this),exprctval(pobj_var),readPool(pe_store+EXPR_OFS_ARGS+1))
}
insertCallAt(pecaller_caller,pecaller,fcreate_stdot)
else
//dot
fcreate_dot=function(PExpression pe_var){
return call(g_id_dot,exprvar(pv_this),exprctval(pobj_var))
}
insertCallAt(pecaller,pe,fcreate_dot)
return 0
//else if isBuiltin(pe,g_id_function):
// return 0
return 1
}
if pf_class&&tisclass(pf_class):
dfsExpr(pe_expanded,freplace_class_members)
pvar_return=var_map[readPool(pobjfn+FUNCTION_OFS_PVAR_RETURN)]
n_args_call=(readPool(pecall)&~EFLAG_MASK)
prototype_mismatch=0
//the scoping is fine for inline calls: the inline function itself has to be defined at some ancestor of the current scope
//we could use wiped code, what we really need is a "scope jumper" to skip the things in-between
//so it's scope-jumper + pre-resolved parameter exprs
//bind parameters - ldparam replacement
//n_funcargs=(nargs_pecode-2)>>1
pvar_arg_ret=new PCTObject[n_args_call] //shouldn't use gencode: lackof decl
//pv_arguments=PCTObject(0)
p_argument_vars=0L
id_return_label=getReturnLabel(pobjfn)
need_return_scope=0
createArgumentVars=function(){
if !p_argument_vars:
p_argument_vars=g_ctobject_pool.n
g_ctobject_pool.resize(p_argument_vars+n_args_call+1)
g_ctobject_pool[p_argument_vars]=n_args_call
for i=0:n_args_call-1
if !pvar_arg_ret[i]:
pvar_arg_ret[i]=makevar(pf_owner)
if !pe_param_checks:
pe_param_checks=new PExpression[]
pe_param_ass=call(g_id_store,exprvar(pvar_arg_ret[i]),readPool(pecall+EXPR_OFS_ARGS+i))
writePool(pvar_arg_ret[i]+VAR_OFS_DEFINING_STORE,pe_param_ass)
pe_param_checks.push(pe_param_ass)
//sccpQueueReach(pe_param_ass)
g_ctobject_pool[p_argument_vars+1+i]=pvar_arg_ret[i]
//Writeln('gen p_argument_vars=',p_argument_vars,' n_args_call=',n_args_call);
}
freplace_args_loop_body=function(PExpression pe){
if isBuiltin(pe,g_id_function):
pe_ccnv=readPool(pe+EXPR_OFS_ARGS)
if readPool(pe_ccnv)==EFLAG_STRING+g_id_inline_loopbody:
return 1
else
return 0
else if isBuiltin(pe,g_id_blockex)&&readPool(readPool(pe+EXPR_OFS_ARGS+0))==EFLAG_STRING+id_return_label:
need_return_scope=1
return 1
else if !is_loop_body&&isBuiltin(pe,g_id_arguments_length):
replaceExprNoQueueReach(pe,expriptr(n_args_call))
return 0
else if !is_loop_body&&isBuiltin(pe,g_id_arguments_bracket):
createArgumentVars()
pe_context_id=readPool(pe+EXPR_OFS_ARGS+0)
writePool(pe_context_id,EFLAG_CONST+getid_const(const_type(CTYPE_INT,64),i64(p_argument_vars)))
return 0
else if !is_loop_body&&isBuiltin(pe,g_id_prototype_matches):
createArgumentVars()
pe_context_id=readPool(pe+EXPR_OFS_ARGS+0)
writePool(pe_context_id,EFLAG_CONST+getid_const(const_type(CTYPE_INT,64),i64(p_argument_vars)))
return 0
else if !is_loop_body&&isBuiltin(pe,g_id_dot):
//Writeln('*** call(arguments) shit ',dumpExpr(pe,__zero(fcolorer_callback)))
pe_member_name=readPool(pe+EXPR_OFS_ARGS+1)
id_member=getExprValueAs(pe_member_name,g_vtid_STR)
if id_member==g_id_call:
pecaller=readPool(pe+EXPR_OFS_CALLER)
if readPool(pecaller+EXPR_OFS_FUNCTION)==pe:
pe_call_arg=readPool(pecaller+EXPR_OFS_ARGS+0)
//pvar_call_arg=getVariable(pe_call_arg)
//if pvar_call_arg&&readPool(pvar_call_arg+VAR_OFS_ID)==g_id_arguments:
if isBuiltin(pe_call_arg,g_id_arguments_placeholder):
//f0.call(arguments)
pe_real_func=readPool(pe+EXPR_OFS_ARGS+0)
createArgumentVars()
as_call=new PExpression[n_args_call+1]
as_call[0]=pe_real_func
for i=0:n_args_call-1
as_call[i+1]=exprvar(pvar_arg_ret[i])
pe_new_caller=replaceExprNoQueueReach(pecaller,indcall(as_call))
//Writeln('*** call(arguments)')
//Writeln(dumpExpr(pe_new_caller,__zero(fcolorer_callback)))
return 0
return 1
else
return 1
}
DISABLE_INLINE_RETURN=1
DISABLE_SINGLE_ASS_USE=2
disabled_optimization_flags=0
freplace_args=function(PExpression pe_store_i){
if isBuiltin(pe_store_i,g_id_function):
pe_ccnv=readPool(pe_store_i+EXPR_OFS_ARGS)
if readPool(pe_ccnv)==EFLAG_STRING+g_id_inline_loopbody:
dfsExpr(pe_store_i,freplace_args_loop_body)
return 0
if isBuiltin(pe_store_i,g_id_disable_inline_return):
if getExprNArgs(pe_store_i)>0:
disabled_optimization_flags|=getExprValueAs(readPool(pe_store_i+EXPR_OFS_ARGS+0),g_vtid_CNS)
else
disabled_optimization_flags|=DISABLE_INLINE_RETURN
setnop(pe_store_i)
return 0
//if isReturnJump(pe_store_i):
if isBuiltin(pe_store_i,g_id_store):
pe_var_i=readPool(pe_store_i+EXPR_OFS_ARGS+0)
pe_code_i=readPool(pe_store_i+EXPR_OFS_ARGS+1)
if isBuiltin(pe_code_i,g_id_ldparam):
paramid=getExprValueAs(readPool(pe_code_i+EXPR_OFS_ARGS+0),g_vtid_CNS)
if !(u32(paramid)<u32(n_args_call)):
prototype_mismatch=1+paramid
return 0
pe_param=readPool(pecall+EXPR_OFS_ARGS+paramid)
//writePool(pe_param+EXPR_OFS_CALLER,0)
pvar=getVariable(pe_var_i)
writePool(pvar+VAR_OFS_USER_FLAGS,readPool(pvar+VAR_OFS_USER_FLAGS)&~VAR_FLAG_PARAM)
assert(!!pvar)
if pvar_arg_ret[paramid]:
pe_param=exprvar(pvar_arg_ret[paramid])
else
pvar_arg_ret[paramid]=pvar
//bind the param
//no premature param reach
insertCallAt(pe_store_i,pe_code_i,function(PExpression pe){return pe_param})
//sccpQueueReach()
return 0
else
return 1
else if isBuiltin(pe_store_i,g_id_cite_param):
param_id=0
param_id_provided=0
if readPool(pe_store_i)==EFLAG_FCALL+1:
pe_param=readPool(pe_store_i+EXPR_OFS_ARGS+0)
if isExpr(pe_param,EFLAG_CONST):
param_id=getExprValueAs(pe_param,g_vtid_CNS)
param_id_provided=1
else if isExpr(pe_param,EFLAG_VARIABLE):
pobj_var_cite_param=getVariable(pe_param)
for i=0:pvar_arg_ret.n-1
if pvar_arg_ret[i]==pobj_var_cite_param:
param_id=int(i)
param_id_provided=1
break
if !param_id_provided:
id_cite=getid("<invalid citation: you can only cite a parameter variable or a parameter ID>")
else if u32(param_id)>=u32(n_args_call):
id_cite=getid("<invalid parameter ID @1>".Replace(["@1",string(param_id)]))
else
id_cite=getid(citeexpr(readPool(pecall+EXPR_OFS_ARGS+param_id)))
replaceExprNoQueueReach(pe_store_i,exprstr(id_cite))
return 0
else
return freplace_args_loop_body(pe_store_i)
}
dfsExpr(pe_expanded,freplace_args)