-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrush.data
29619 lines (27061 loc) · 516 KB
/
rush.data
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
del /F /Q ..\bin\*.ilk
del /F /Q ..\bin\*.pdb
del /F /Q .\*.ncb
attrib -R -S -A -H .\*.suo
del /F /Q .\*.suo
del /F /Q .\*.user
del /F /Q .\proj\*.vsp
rem del /F /Q .\proj\*.filters
del /F /Q .\proj\*.psess
del /F /Q .\proj\*.sdf
del /F /Q .\proj\*.ncb
attrib -R -S -A -H .\proj\*.suo
del /F /Q .\proj\*.suo
del /F /Q .\proj\*.user
rd /S /Q .\proj\debug
rd /S /Q .\proj\Release
del /F /Q .\rush.asm
del /F /Q .\rush.cpp
del /F /Q .\rush.exe
del /F /Q .\example\test\*.exe
del /F /Q .\example\test\*.cpp
del /F /Q ..\bin\rush_gpp.asm
del /F /Q ..\bin\rush_nasm.asm
del /F /Q ..\bin\rush_gpp.exe
del /F /Q ..\bin\rush_nasm.exe
pause#include "back/zmain.h"
#ifdef EMSCRIPTEN
extern "C" int js_main(char* s)
{
return !zmain::compile((uchar*)s);
}
#else
#ifndef __GNUC__
int main()
{
return !zmain::compile(null);
}
#else
int main(int argc,char* argv[])
{
xf::get_xf()->argc=argc;
xf::get_xf()->argv=argv;
return !zmain::compile(null);
}
#endif
#endif
嚜�#pragma once
#include "../front/yexp.h"
#include "zopt.h"
//��瘙�隞��
//tfunc.vsent->vasm
//餈������冽�int�”颲曉��閬�占bx銝�
//���nt���冽撖寞頨怎��潸�銵��
//�嗅�蝐餃����冽撖孵��刻�銵��
struct zasm
{
static rbool process(tsh& sh,tfunc& tfi)
{
for(int i=0;i<tfi.vsent.count();i++)
{
rbuf<tasm> vasm;
ifn(proc_ret(sh,tfi.vsent[i],vasm,tfi))
{
rserror(tfi.vsent[i],"build asm error");
return false;
}
if(tconf::c_op_match)
{
yopt::op_match(sh,vasm);
}
if(tconf::c_op_merge)
{
yopt::op_add_sub(sh,vasm);
}
for(int j=0;j<vasm.count();j++)
{
vasm[j].pos=tfi.vsent[i].pos;
}
tfi.vasm+=vasm;
}
add_asm_ebp(sh,tfi);
return true;
}
static void push_double(const tsh& sh,rbuf<tasm>& vasm,double dval)
{
vasm+=rf::vstr(rskey(c_push),rstr(*((uint*)(&dval)+1)));
vasm+=rf::vstr(rskey(c_push),rstr(*((uint*)(&dval))));
}
static rbool add_asm_ebp(const tsh& sh,tfunc& tfi)
{
rbuf<tasm> vasm;
tasm item;
item.pos=tfi.pos;
int size=yfind::get_func_local_size(tfi);
ifn(tconf::c_op_zero&&size==0)
{
item.vstr=rf::vstr(rskey(c_sub),rskey(c_esp),
rsoptr(c_comma),rstr(size));
vasm+=item;
}
rbool b_use_ebp=use_ebp(sh,tfi.vasm);
rbool protect_ebx=(tfi.name.get_left()==r_char('~')&&
!yfind::is_empty_struct_type(sh,tfi.ptci->name)&&
!tfi.vsent.empty()||tfi.is_cfunc);
if(b_use_ebp)
{
item.vstr=rf::vstr(rskey(c_push),rskey(c_ebp));
vasm+=item;
item.vstr=rf::vstr(rskey(c_mov),rskey(c_ebp),
rsoptr(c_comma),rskey(c_esp));
vasm+=item;
}
if(protect_ebx)
{
item.vstr=rf::vstr(rskey(c_push),rskey(c_ebx));
vasm+=item;
}
if(tfi.is_cfunc)
{
//todo 憒�ebx�si�di�芯耨�孵�銝靽
item.vstr=rf::vstr(rskey(c_push),rskey(c_esi));
vasm+=item;
item.vstr=rf::vstr(rskey(c_push),rskey(c_edi));
vasm+=item;
}
vasm+=tfi.vasm;
item.pos=tfi.pos;
if(tfi.is_cfunc)
{
//todo: change to one line
item.vstr.clear();
item.vstr.push(rskey(c_pop));
item.vstr.push(rskey(c_edi));
vasm.push(item);
item.vstr.clear();
item.vstr.push(rskey(c_pop));
item.vstr.push(rskey(c_esi));
vasm.push(item);
}
if(protect_ebx)
{
item.vstr.clear();
item.vstr.push(rskey(c_pop));
item.vstr.push(rskey(c_ebx));
vasm.push(item);
}
if(b_use_ebp)
{
item.vstr.clear();
item.vstr.push(rskey(c_pop));
item.vstr.push(rskey(c_ebp));
vasm.push(item);
}
ifn(tconf::c_op_zero&&size==0)
{
item.vstr.clear();
item.vstr.push(rskey(c_add));
item.vstr.push(rskey(c_esp));
item.vstr.push(rsoptr(c_comma));
item.vstr.push(rstr(size));
vasm.push(item);
}
size=yfind::get_func_param_size(tfi);
if(size>0)
{
item.vstr.clear();
item.vstr.push(rskey(c_reti));
item.vstr.push(rstr(size));
vasm.push(item);
}
else
{
item.vstr.clear();
item.vstr.push(rskey(c_retn));
vasm.push(item);
}
tfi.vasm=r_move(vasm);
return true;
}
static rbool use_ebp(const tsh& sh,const rbuf<tasm>& vasm)
{
if(!tconf::c_op_ebp)
{
return true;
}
for(int i=0;i<vasm.count();i++)
{
for(int j=0;j<vasm[i].vstr.count();j++)
{
if(vasm[i].vstr[j]==rskey(c_ebp))
{
return true;
}
}
}
return false;
}
static rbool proc_ret(tsh& sh,const tsent& src,rbuf<tasm>& vasm,
tfunc& tfi,int level=0)
{
rstr name=src.vword.get_bottom().val;
if(sh.m_key.is_asm_ins(name)||ybase::is_tag<tword>(src.vword))
{
vasm+=ybase::vword_to_vstr(src.vword);
return true;
}
//餈�撣賊�
if(src.vword.count()==1)
{
if(src.vword[0].is_cint())
{
//蝏�霂��撠�摨skey(c_mov)瘥�"mov"��擃�
vasm+=rf::vstr(rskey(c_mov),rskey(c_ebx),
rsoptr(c_comma),src.vword[0].val);
return true;
}
elif(sh.m_key.is_asm_reg(src.vword[0].val))
{
vasm+=rf::vstr(rskey(c_mov),rskey(c_ebx),
rsoptr(c_comma),src.vword[0].val);
return true;
}
elif(src.vword[0].is_cpoint())
{
if(src.vword[0].is_caddr())
{
vasm+=rf::vstr(rskey(c_mov),
rskey(c_ebx),rsoptr(c_comma),
src.vword[0].val);
}
else
{
vasm+=rf::vstr(rskey(c_mov),
rskey(c_ebx),rsoptr(c_comma),
src.vword[0].val.sub_trim(1));
}
return true;
}
}
if(src.vword.count()==7&&src.vword[1].val==rsoptr(c_addr))
{
vasm+=rf::vstr(rskey(c_mov),rskey(c_ebx),rsoptr(c_comma),
rsoptr(c_mbk_l),rsoptr(c_addr),rsoptr(c_comma),
src.vword[3].val,rsoptr(c_comma),src.vword[5].val,
rsoptr(c_mbk_r));
return true;
}
//餈���
tdata* ptdi=yfind::local_search(tfi,
get_src_in(sh,src).vword.get(0).val);
if(ptdi!=null)
{
if(yfind::is_type_mebx(sh,src.type))
{
vasm+=rf::vstr(rskey(c_lea),rskey(c_esi),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_ebp),rsoptr(c_plus),
rstr(ptdi->off),rsoptr(c_mbk_r));
//餈�餈隞乩���
if(!add_esi(sh,ptdi->type,vasm,src))
{
rserror("");
return false;
}
vasm+=rf::vstr(rskey(c_mov),rskey(c_ebx),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
if(ybase::is_quote(src.type)&&
(ybase::get_tname(src.type)==rskey(c_int)||
ybase::is_point(ybase::get_tname(src.type))))
{
vasm+=rf::vstr(rskey(c_mov),rskey(c_ebx),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_ebx),rsoptr(c_mbk_r));
}
}
return true;
}
//餈��賣
return proc_ret_func(sh,src,vasm,tfi,level);
}
static rbool proc_ret_func(tsh& sh,const tsent& src,rbuf<tasm>& vasm,
tfunc& tfi,int level)
{
tdata retval;
if(!a_exp(sh,get_src_in(sh,src),vasm,retval,tfi,level))
{
return false;
}
int size;
//憭�賣餈�void嚗�甇文�銝��亙�剖隞交�擃���
if(src.type!=rskey(c_void)&&yfind::is_type_mebx(sh,src.type))
{
vasm+=rf::vstr(rskey(c_mov),rskey(c_esi),
rsoptr(c_comma),rskey(c_esp));
int cur=vasm.count();
if(!add_esi(sh,retval.type,vasm,src))
{
rserror("");
return false;
}
if(cur==vasm.count())
{
vasm.pop();
vasm+=rf::vstr(rskey(c_mov),rskey(c_ebx),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esp),rsoptr(c_mbk_r));
}
else
{
vasm+=rf::vstr(rskey(c_mov),rskey(c_ebx),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
}
if(ybase::is_quote(src.type)&&
(ybase::get_tname(src.type)==rskey(c_int)||
ybase::is_point(ybase::get_tname(src.type))))
{
vasm+=rf::vstr(rskey(c_mov),rskey(c_ebx),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_ebx),rsoptr(c_mbk_r));
}
}
if(!destruct_ret(sh,retval,vasm))
{
rserror("");
return false;
}
size=yfind::get_ceil_space(retval);
vasm+=rf::vstr(rskey(c_add),rskey(c_esp),rsoptr(c_comma),size);
return true;
}
//閫��銵刻噢撘���蝻誨��
static rbool a_exp(tsh& sh,const tsent& src,rbuf<tasm>& vasm,tdata& retval,
tfunc& tfi,int level=0)
{
if(level>c_rs_deep)
{
rserror("");
return false;
}
level++;
if(src.vword.get_bottom().val!=rsoptr(c_mbk_l)||
src.vword.get_top().val!=rsoptr(c_mbk_r))
{
rserror("");
return false;
}
if(src.vword.get(1).val==rsoptr(c_dot))
{
rserror("");
return false;
}
int size;
rbuf<rbuf<tword> > vlisp;
yexp::get_vlisp(sh,src.vword,vlisp);
if(src.vword.get(1).val==rskey(c_pcall))
{
if(vlisp.count()!=5)
{
rserror("");
return false;
}
retval.type=vlisp[1].get(0).val;
retval.size=yfind::get_type_size(sh,retval.type);
size=yfind::get_ceil_space(retval);
vasm+=rf::vstr(rskey(c_sub),rskey(c_esp),
rsoptr(c_comma),size);
rbuf<rbuf<tword> > vparam;
yexp::get_vlisp(sh,vlisp[4],vparam);
rbuf<tsent> vsent;
yexp::get_vsent(vparam,vsent,src);
for(int i=vsent.count()-1;i>=0;i--)
{
//todo:撌脫�蝐餃��啁�����瑕�
if(!yexp::p_exp(sh,vsent[i],tfi,level,tenv()))
{
return false;
}
}
for(int i=vsent.count()-1;i>=0;i--)
{
tdata tdi;
tdi.type=ybase::get_tname(vsent[i].type);
tdi.size=yfind::get_type_size(sh,tdi.type);
if(!pass_param(sh,vsent[i],tdi,vasm,tfi,level))
{
return false;
}
}
tsent sent=src;
sent.vword=vlisp[3];
if(!yexp::p_exp(sh,sent,tfi,level,tenv()))
{
return false;
}
if(!proc_ret(sh,sent,vasm,tfi,level))
{
return false;
}
if(sent.type==rstr("rp<void>"))
{
vasm+=rf::vstr(rskey(c_call),rskey(c_ebx));
}
else
{
rserror("");
return false;
}
return true;
}
if(vlisp.count()!=3)
{
rserror("");
return false;
}
yexp::get_vlisp(sh,vlisp[2],vlisp);
rbuf<tsent> vsent;
yexp::get_vsent(vlisp,vsent,src);
for(int i=vsent.count()-1;i>=0;i--)
{
if(!yexp::p_exp(sh,vsent[i],tfi,level,tenv()))
{
return false;
}
}
rstr cname=src.vword.get(1).val;
rstr fname=src.vword.get(3).val;//p_exp撌脩��僎鈭ame_dec
tclass* ptci=yfind::class_search(sh,cname);
if(null==ptci)
{
rserror("");
return false;
}
tfunc* ptfi=yfind::func_search_dec(*ptci,fname);
if(ptfi==null)
{
rserror("");
return false;
}
retval=ptfi->retval;
if(tconf::c_op_empty_func&&
yfind::is_empty_struct_type(sh,ptci->name)&&
(yfind::is_destruct(sh,*ptfi)||
yfind::is_emptystruct(sh,*ptfi)))
{
return true;
}
if(ptfi->param.count()!=vsent.count())
{
rserror("");
return false;
}
size=yfind::get_ceil_space(retval);
vasm+=rf::vstr(rskey(c_sub),rskey(c_esp),rsoptr(c_comma),size);
for(int i=vsent.count()-1;i>=0;i--)
{
if(!pass_param(sh,vsent[i],ptfi->param[i],vasm,tfi,level))
{
return false;
}
}
vasm+=ybase::get_func_declare_call(sh,*ptci,*ptfi);
return true;
}
static rbool pass_param(tsh& sh,const tsent& src,const tdata& dst,rbuf<tasm>& vasm,
tfunc& tfi,int level)
{
if(src.vword.empty())
{
rserror("");
return false;
}
int size;
tsent src_in=get_src_in(sh,src);
if(src_in.vword.get(1).val==rskey(c_pcall)||
yfind::is_class(sh,src_in.vword.get(1).val))
{
//�霂瑕��啁征��
size=yfind::get_ceil_space(dst);
vasm+=rf::vstr(rskey(c_sub),rskey(c_esp),
rsoptr(c_comma),size);
//��憭�摮”颲曉�
tdata retval;
if(!a_exp(sh,src_in,vasm,retval,tfi,level))
{
return false;
}
//�瑕�隡��啁��啣���曉esi�di銝哨�
//��賣餈���dot嚗�int.get().m_in
if(!obtain_var_addr_f(sh,retval,src,vasm))
{
rserror("");
return false;
}
//隡���
if(!copy_param(sh,src.type,dst.type,vasm))
{
rserror("");
return false;
}
//��餈���
if(!destruct_ret(sh,retval,vasm))
{
rserror("");
return false;
}
//���
size=yfind::get_ceil_space(retval);
vasm+=rf::vstr(rskey(c_add),rskey(c_esp),
rsoptr(c_comma),size);
}
elif(src.vword[0].is_cint())
{
vasm+=rf::vstr(rskey(c_push),src.vword[0].val);
}
elif(src.vword[0].is_cuint())
{
vasm+=rf::vstr(rskey(c_push),src.vword[0].val.sub_trim(1));
}
elif(src.vword[0].is_cdouble())
{
double dval=src.vword[0].val.todouble();
push_double(sh,vasm,dval);
}
elif(src.vword.count()==7&&
src.vword.get(1).val==rsoptr(c_addr)&&
src.vword[0].val==rsoptr(c_mbk_l))
{
rbuf<rstr> vstr=ybase::vword_to_vstr(src.vword);
vstr.push_front(rskey(c_push));
vasm+=vstr;
}
elif(src.vword[0].is_cpoint())
{
if(src.vword.get_bottom().is_caddr())
{
vasm+=rf::vstr(rskey(c_push),src.vword[0].val);
}
else
{
vasm+=rf::vstr(rskey(c_push),src.vword[0].val.sub_trim(1));
}
}
elif(src.vword[0].is_cstr())
{
vasm+=rf::vstr(rskey(c_push),src.vword[0].val);
}
elif(sh.m_key.is_asm_reg(src.vword[0].val))
{
vasm+=rf::vstr(rskey(c_push),src.vword[0].val);
}
else
{
rstr name=src_in.vword.get(0).val;
tdata* ptdi=yfind::local_search(tfi,name);
if(ptdi==null)
{
tfi.name.printl();
rserror(name);
return false;
}
int cur=vasm.count()+3;
if(!obtain_var_addr_var(sh,src,dst,ptdi,vasm))
{
rserror("");
return false;
}
if(cur==vasm.count()&&tconf::c_op_pass)
{
if(yfind::is_op_pass_type(sh,dst.type)&&
dst.type==src.type)
{
vasm.m_count-=3;
vasm+=rf::vstr(rskey(c_push),rsoptr(c_mbk_l),
rskey(c_ebp),rsoptr(c_plus),
rstr(ptdi->off),rsoptr(c_mbk_r));
return true;
}
if(ybase::is_quote(dst.type)&&ybase::is_quote(src.type))
{
vasm.m_count-=3;
vasm+=rf::vstr(rskey(c_push),rsoptr(c_mbk_l),
rskey(c_ebp),rsoptr(c_plus),
rstr(ptdi->off),rsoptr(c_mbk_r));
return true;
}
if(ybase::is_quote(dst.type))
{
vasm.m_count-=3;
vasm+=rf::vstr(rskey(c_lea),rskey(c_esi),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_ebp),rsoptr(c_plus),
rstr(ptdi->off),rsoptr(c_mbk_r));
vasm+=rf::vstr(rskey(c_push),rskey(c_esi));
return true;
}
}
//靚�瑁���唳餈隞乩���
return copy_param(sh,src.type,dst.type,vasm);
}
return true;
}
static rbool obtain_var_addr_var(const tsh& sh,const tsent& src,const tdata& dst,
const tdata* ptdi,rbuf<tasm>& vasm)
{
int size=yfind::get_ceil_space(dst);
vasm+=rf::vstr(rskey(c_sub),rskey(c_esp),rsoptr(c_comma),size);
vasm+=rf::vstr(rskey(c_mov),rskey(c_edi),rsoptr(c_comma),
rskey(c_esp));
vasm+=rf::vstr(rskey(c_lea),rskey(c_esi),rsoptr(c_comma),
rsoptr(c_mbk_l),rskey(c_ebp),rsoptr(c_plus),
rstr(ptdi->off),rsoptr(c_mbk_r));
return add_esi(sh,ptdi->type,vasm,src);
}
static rbool obtain_var_addr_f(const tsh& sh,tdata& retval,
const tsent& src,rbuf<tasm>& vasm)
{
int size=yfind::get_ceil_space(retval);
vasm+=rf::vstr(rskey(c_lea),rskey(c_edi),rsoptr(c_comma),
rsoptr(c_mbk_l),rskey(c_esp),rsoptr(c_plus),
rstr(size),rsoptr(c_mbk_r));
vasm+=rf::vstr(rskey(c_mov),rskey(c_esi),rsoptr(c_comma),
rskey(c_esp));
return add_esi(sh,retval.type,vasm,src);
}
static tsent get_src_in(const tsh& sh,const tsent& src)
{
if(src.vword.get(1).val!=rsoptr(c_dot))
{
return src;
}
tsent sent=src;
int start=0;
while(start+2<src.vword.count()&&
src.vword[start].val==rsoptr(c_mbk_l)&&
src.vword[start+1].val==rsoptr(c_dot))
{
start+=3;
}
if(src.vword[start].val==rsoptr(c_mbk_l))
{
int right=ybase::find_symm_mbk(sh,src.vword,start);
sent.vword=src.vword.sub(start,right+1);
}
else
{
sent.vword=src.vword.sub(start,start+1);
}
return r_move(sent);
}
// [ . , [ . , [ . , a , b ] , c ] , d ]
static rbool add_esi(const tsh& sh,rstr type,rbuf<tasm>& vasm,const tsent& src)
{
int start=0;
const rbuf<tword>& v=src.vword;
if(v.get(1).val!=rsoptr(c_dot))
{
return true;
}
while(start+2<v.count()&&
v[start].val==rsoptr(c_mbk_l)&&
v[start+1].val==rsoptr(c_dot))
{
start+=3;
}
int right=start+2;
if(v[start].val==rsoptr(c_mbk_l))
{
right=ybase::find_symm_mbk(sh,v,start);
if(right>=v.count())
{
return false;
}
right+=2;
}
for(int i=0;i<start;i+=3)
{
tclass* ptci=yfind::class_search_t(sh,type);
if(null==ptci)
{
return false;
}
tdata* ptdi=yfind::data_member_search(*ptci,v.get(right).val);
if(null==ptdi)
{
return false;
}
if(ybase::is_quote(type))
{
vasm+=rf::vstr(rskey(c_mov),rskey(c_esi),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
}
if(ptdi->off!=0)
{
vasm+=rf::vstr(rskey(c_add),rskey(c_esi),
rsoptr(c_comma),ptdi->off);
}
type=ptdi->type;
right+=3;
}
return true;
}
//src��摰�撌脩�摮�牠si銝�,dst���牠di銝�
static rbool copy_param(const tsh& sh,const rstr& src,
const rstr& dst,rbuf<tasm>& vasm)
{
//���臭誑��頧祆
if(ybase::is_point(dst)&&ybase::is_point(src)||
dst==rskey(c_rd32)&&yfind::get_type_size(sh,src)==4)
{
vasm+=rf::vstr(rskey(c_mov),rsoptr(c_mbk_l),
rskey(c_edi),rsoptr(c_mbk_r),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
return true;
}
//�格��臬���
if(ybase::is_quote(dst))
{
if(ybase::is_quote(src))
{
//皞撘
vasm+=rf::vstr(rskey(c_mov),rsoptr(c_mbk_l),
rskey(c_edi),rsoptr(c_mbk_r),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
}
else
{
//皞撖寡情
vasm+=rf::vstr(rskey(c_mov),rsoptr(c_mbk_l),
rskey(c_edi),rsoptr(c_mbk_r),
rsoptr(c_comma),rskey(c_esi));
}
return true;
}
if(tconf::c_op_pass)
{
if(yfind::is_op_pass_type(sh,dst))
{
if(ybase::is_quote(src))
{
//皞撘
vasm+=rf::vstr(rskey(c_mov),rskey(c_esi),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
}
vasm+=rf::vstr(rskey(c_mov),rsoptr(c_mbk_l),
rskey(c_edi),rsoptr(c_mbk_r),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
return true;
}
if(dst==rskey(c_double)||dst==rskey(c_int64))
{
if(ybase::is_quote(src))
{
vasm+=rf::vstr(rskey(c_mov),rskey(c_esi),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
}
vasm+=rf::vstr(rskey(c_mov),rsoptr(c_mbk_l),
rskey(c_edi),rsoptr(c_mbk_r),
rsoptr(c_comma),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
vasm+=rf::vstr(rskey(c_mov),rsoptr(c_mbk_l),
rskey(c_edi),rsoptr(c_plus),"4",
rsoptr(c_mbk_r),rsoptr(c_comma),
rsoptr(c_mbk_l),rskey(c_esi),
rsoptr(c_plus),"4",rsoptr(c_mbk_r));
return true;
}
}
//�格��臬笆鞊⊿�閬��冽韐����
if(ybase::is_quote(src))
{
//皞撘
vasm+=rf::vstr(rskey(c_push),rsoptr(c_mbk_l),
rskey(c_esi),rsoptr(c_mbk_r));
}
else
{
//皞撖寡情
vasm+=rf::vstr(rskey(c_push),rskey(c_esi));
}
vasm+=rf::vstr(rskey(c_push),rskey(c_edi));
tclass* ptci=yfind::class_search_t(sh,src);
if(ptci==null)
{
return false;
}
tfunc* pcopystruct=yfind::copystruct_search(*ptci);
if(pcopystruct==null)
{
return false;
}
vasm+=ybase::get_func_declare_call(sh,*ptci,*pcopystruct);
return true;
}
static rbool destruct_ret(const tsh& sh,const tdata& retval,rbuf<tasm>& vasm)
{
rstr type=retval.type;
if(ybase::is_quote(type))
{
return true;
}
if(type==rskey(c_void))
{
return true;
}
tclass* ptci=yfind::class_search(sh,type);
if(ptci==null)
{
return false;
}
tfunc* pdestruct=yfind::destruct_search(*ptci);
if(pdestruct==null)
{
return false;
}
if(tconf::c_op_empty_func&&yfind::is_empty_struct_type(sh,type))
{
return true;
}
vasm+=rf::vstr(rskey(c_mov),rskey(c_esi),
rsoptr(c_comma),rskey(c_esp));
vasm+=rf::vstr(rskey(c_push),rskey(c_esi));
vasm+=ybase::get_func_declare_call(sh,*ptci,*pdestruct);
return true;
}
};
嚜�#pragma once
#include "../front/ysent.h"
#include "../front/yword.h"
#include "zasm.h"
//��鈭��嗡誨�掩
struct zbin
{
//撠�銝芸�啁蕃霂�鈭��嗡誨��
static rbool process(tsh& sh,tfunc& tfi)
{
if(!tfi.vasm.empty())
{
return true;
}
if(!cp_vword_to_vasm(sh,tfi,tenv()))
{
return false;
}
for(int i=0;i<tfi.vasm.count();i++)
{
if(!proc_asm(sh,tfi.vasm,tfi.vasm[i]))
{
rserror(tfi.vasm[i],"asm error");
return false;
}
tfi.vasm[i].ptfi=&tfi;
}
return true;
}
//隞�啁�霂”蝻��釘asm
static rbool cp_vword_to_vasm(tsh& sh,tfunc& tfi,tenv env)
{
ifn(ysent::process(sh,tfi,env))
{
rserror(tfi,"sent error");
return false;
}
ifn(zasm::process(sh,tfi))
{
rserror(tfi,"asm error");
return false;
}
return true;
}
static rbool proc_vasm(tsh& sh,rbuf<tasm>& vasm)
{
for(int i=0;i<vasm.count();i++)
{
if(!proc_asm(sh,vasm[i]))
{
return false;
}
}
return true;
}
static rbool proc_asm(tsh& sh,tasm& oasm)
{
rbuf<tasm> vasm;
return proc_asm(sh,vasm,oasm);
}
//撠�蝻誨�蕃霂�鈭��嗡誨��
static rbool proc_asm(tsh& sh,rbuf<tasm>& vasm,tasm& oasm)
{
if(ybase::is_tag<rstr>(oasm.vstr))
{
oasm.ins.type=tins::c_nop_n;
return true;
}
oasm.ins.type=sh.m_key.get_key_index(oasm.vstr.get_bottom());
if(oasm.ins.type>tkey::c_rn)
{
rserror(oasm);
return false;
}
if(oasm.vstr.count()==2&&
ybase::is_jmp_ins(oasm.ins.type)&&
!sh.m_key.is_asm_reg(oasm.vstr[1]))
{
int line=oasm.vstr[1].toint();
int i;
for(i=0;i<vasm.count();i++)
{
if(ybase::is_tag<rstr>(vasm[i].vstr)&&
vasm[i].vstr[0]==oasm.vstr[1])
{
break;
}
}
if(i>=vasm.count())
{
rserror(oasm);
return false;
}
oasm.ins.type*=6;
oasm.ins.first.type=topnd::c_imme;
oasm.ins.first.val=(uint)(&vasm[i]);
return true;
}
oasm.ins.type*=6;
if(!a_asm(sh,oasm))
{
rserror(oasm);
return false;
}
return true;
}
static int find_comma(tsh& sh,rbuf<rstr>& v)
{
int count1=0;
int count2=0;
int i;
for(i=1;i<v.count();i++)
{
if(rsoptr(c_sbk_l)==v[i])
{
count1++;
}
elif(rsoptr(c_sbk_r)==v[i])
{
count1--;
}
elif(rsoptr(c_mbk_l)==v[i])
{
count2++;
}
elif(rsoptr(c_mbk_r)==v[i])
{
count2--;
}
elif(count1==0&&count2==0&&v[i]==rsoptr(c_comma))
{
break;
}
}
return i;
}