-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdis.e
1967 lines (1618 loc) · 44.4 KB
/
dis.e
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
-- (c) Copyright - See License.txt
ifdef ETYPE_CHECK then
with type_check
elsedef
without type_check
end ifdef
without trace
include std/text.e
include std/pretty.e
include std/error.e
include std/map.e
include dot.e
include std/sort.e
include std/cmdline.e
include std/math.e
include cominit.e
include c_out.e
include fwdref.e
include global.e
include intinit.e
include mode.e as mode
include opnames.e
include reswords.e
include scanner.e
include symtab.e
include traninit.e
include dox.e as dox
integer out, pc, a, b, c, d, target, len, keep_running
sequence operation
procedure RTInternal(sequence msg)
-- Internal errors in back-end
--puts(2, '\n' & msg & '\n')
--? 1/0
-- M_CRASH = 67
machine_proc(67, msg)
end procedure
sequence ps_options = PRETTY_DEFAULT
ps_options[DISPLAY_ASCII] = 2
ps_options[LINE_BREAKS] = 0
function name_or_literal( integer sym )
if not sym then
return "[0: ???]"
elsif sym < 0 then
return sprintf("[UNRESOLVED FORWARD REFERENCE: %d]", sym )
elsif sym > length(SymTab) then
return sprintf("[_invalid_:%d]", sym )
elsif length(SymTab[sym]) = 1 then
return sprintf("[_deleted_:%d]", sym)
elsif length(SymTab[sym]) >= SIZEOF_VAR_ENTRY then
return sprintf("[%s:%d]", {SymTab[sym][S_NAME],sym})
elsif SymTab[sym][S_MODE] = M_TEMP and equal( SymTab[sym][S_OBJ], NOVALUE ) then
return sprintf("[_temp_:%d]", sym)
else
return sprintf("[LIT %s:%d]",{ pretty_sprint(SymTab[sym][S_OBJ], ps_options), sym})
end if
end function
function names( sequence n )
sequence nl
nl = {}
for i = 1 to length(n) do
if n[i] then
nl = append( nl, name_or_literal(n[i]))
else
nl = append( nl, "[0]" )
end if
end for
return nl
end function
procedure il( sequence dsm, integer len )
sequence format, code
integer line, space
format = "%6d: %03d"
for i = 1 to len do
format &= " %d"
end for
code = sprintf( format, pc & Code[pc..$] )
line = 1
while length(code) > 40 do
for c = 40 to 1 by -1 do
if code[c] = 32 then
if line > 1 then
code = " " & code
printf( out, "\n%-40s # ", {" " & code[1..c]})
else
printf( out, "%-40s # ", {code[1..c]})
end if
line += 1
code = code[c+1..$]
exit
end if
end for
end while
if length(code) then
if line > 1 then
printf( out, "\n%-40s # ", {" " & code})
else
printf( out, "%-40s # ", {code})
end if
end if
line = 1
while length(dsm) > 60 do
space = 0
for i = 60 to length(dsm) do
if dsm[i] = 32 then
if line > 1 then
puts( out, repeat( 32, 41 ) & "# " )
end if
puts( out, dsm[1..i] & "\n")
dsm = dsm[i+1..$]
line += 1
space = 1
exit
end if
end for
if not space then
exit
end if
end while
if length(dsm) then
if line > 1 then
puts( out, repeat( 32, 41 ) & "# " )
end if
puts( out, dsm & "\n")
end if
end procedure
procedure quadary()
il( sprintf( "%s: %s, %s, %s, %s => %s", {opnames[Code[pc]]} & names(Code[pc+1..pc+5])), 5)
pc += 6
end procedure
procedure pquadary()
il( sprintf( "%s: %s, %s, %s %s", {opnames[Code[pc]]} & names(Code[pc+1..pc+4])), 4)
pc += 5
end procedure
procedure trinary()
il( sprintf( "%s: %s, %s, %s => %s", {opnames[Code[pc]]} & names(Code[pc+1..pc+4])), 4)
pc += 5
end procedure
procedure ptrinary()
il( sprintf( "%s: %s, %s, %s", {opnames[Code[pc]]} & names(Code[pc+1..pc+3])), 3)
pc += 4
end procedure
procedure binary()
il( sprintf( "%s: %s, %s => %s", {opnames[Code[pc]]} & names(Code[pc+1..pc+3])), 3)
pc += 4
end procedure
procedure pbinary()
il( sprintf( "%s: %s, %s", {opnames[Code[pc]]} & names(Code[pc+1..pc+2])), 2)
pc += 3
end procedure
procedure unary( )
il( sprintf( "%s: %s => %s", {opnames[Code[pc]]} & names(Code[pc+1..pc+2])), 2)
pc += 3
end procedure
procedure punary( )
il( sprintf( "%s: %s ", {opnames[Code[pc]]} & names(Code[pc+1..pc+1])), 1)
pc += 2
end procedure
procedure nonary()
il( sprintf( "%s: %s", {opnames[Code[pc]], name_or_literal( Code[pc+1])}), 1)
pc += 2
end procedure
procedure pnonary()
il( sprintf( "%s:", {opnames[Code[pc]]}), 0)
pc += 1
end procedure
procedure opCOVERAGE_LINE()
object line
sequence entry_
integer lx
lx = Code[pc+1]
symtab_index sub = Code[pc+2]
if atom(slist[$]) then
slist = s_expand( slist )
end if
if atom(slist[lx][SRC]) then
slist[lx][SRC] = fetch_line(slist[lx][SRC])
end if
entry_ = slist[Code[pc+1]]
line = entry_[SRC]
if atom(line) then
line = ""
else
while length(line) and find( line[1], "\t " ) do
line = line[2..$]
end while
end if
il( sprintf( "%s: %s:(%d)<<%s>>", {opnames[Code[pc]], known_files[entry_[LOCAL_FILE_NO]], entry_[LINE] ,line}), 1)
pc += 2
end procedure
include std/filesys.e
procedure opCOVERAGE_ROUTINE()
il( sprintf( "%s: %s:%s\n",
{ opnames[Code[pc]], canonical_path( known_files[ SymTab[Code[pc+1]][S_FILE_NO] ] ),
sym_name( Code[pc+1] ) } ), 1 )
pc += 2
end procedure
procedure opSTARTLINE()
-- Start of a line. Use for diagnostics.
object line
sequence entry_
integer lx
lx = Code[pc+1]
if atom(slist[$]) then
slist = s_expand( slist )
end if
if atom(slist[lx][SRC]) then
slist[lx][SRC] = fetch_line(slist[lx][SRC])
end if
entry_ = slist[Code[pc+1]]
line = entry_[SRC]
if atom(line) then
line = ""
else
while length(line) and find( line[1], "\t " ) do
line = line[2..$]
end while
end if
il( sprintf( "%s: %s(%d)<<%s>>", {opnames[Code[pc]], known_files[entry_[LOCAL_FILE_NO]],entry_[LINE] ,line}), 1)
pc += 2
end procedure
procedure opREF_TEMP()
punary()
end procedure
procedure opDEREF_TEMP()
punary()
end procedure
procedure opNOVALUE_TEMP()
punary()
end procedure
procedure opTASK_YIELD()
-- temporarily stop running this task, and give the scheduler a chance
-- to pick a new task
pnonary()
end procedure
procedure opTASK_STATUS()
-- return task status
unary()
end procedure
procedure opTASK_LIST()
-- return list of active and suspended tasks
nonary()
end procedure
procedure opTASK_SELF()
-- return current task id
nonary()
end procedure
atom save_clock
save_clock = -1
procedure opTASK_CLOCK_STOP()
-- stop the scheduler clock
pnonary()
end procedure
procedure opTASK_CLOCK_START()
-- resume the scheduler clock
pnonary()
end procedure
procedure opTASK_SUSPEND()
-- suspend a task
punary()
end procedure
procedure opTASK_CREATE()
-- create a new task
binary()
end procedure
procedure opTASK_SCHEDULE()
-- schedule a task by linking it into the real-time tcb queue,
-- or the time sharing tcb queue
pbinary()
end procedure
procedure opEMBEDDED_PROCEDURE_CALL()
pbinary()
end procedure
procedure opEMBEDDED_FUNCTION_CALL()
binary()
end procedure
-- based on execute.e
function find_line(symtab_index sub, integer pc, integer file_only = 1)
-- return the file name and line that matches pc in sub
sequence linetab
integer line, gline
linetab = SymTab[sub][S_LINETAB]
line = 1
for i = 1 to length(linetab) do
if linetab[i] >= pc or linetab[i] = -2 then
line = i-1
while line > 1 and linetab[line] = -1 do
line -= 1
end while
exit
end if
end for
gline = SymTab[sub][S_FIRSTLINE] + line - 1
if file_only then
return slist[gline][LOCAL_FILE_NO]
elsif gline > length( slist ) or not gline then
-- probably a bug with the line table code in the parser
return { "??", -1, "???", gline }
else
return {known_files[slist[gline][LOCAL_FILE_NO]], slist[gline][LINE], slist[gline][SRC], gline}
end if
end function
procedure opPROC() -- Normal subroutine call
integer n, arg, sub, top
sequence dsm
-- make a procedure or function/type call
sub = Code[pc+1] -- subroutine
n = SymTab[sub][S_NUM_ARGS]
integer current_file
if CurrentSub = TopLevelSub then
current_file = find_line( sub, pc )
else
current_file = SymTab[CurrentSub][S_FILE_NO]
end if
-- record the data for the call graph
-- called_from maps from the caller to the callee
-- called_by maps from the callee back to the caller
map:nested_put( called_from, { current_file, CurrentSub, SymTab[sub][S_FILE_NO], sub }, 1 , map:ADD )
map:nested_put( called_by, { SymTab[sub][S_FILE_NO], sub, current_file, CurrentSub }, 1, map:ADD )
dsm = sprintf( "%s: %s",{opnames[Code[pc]],name_or_literal(sub)})
for i = 1 to n do
if i < n then
dsm &= ", "
end if
arg = Code[pc + i + 1]
dsm &= name_or_literal(arg)
end for
if SymTab[sub][S_TOKEN] != PROC then
dsm[1..4] = "FUNC"
dsm &= sprintf( " => %s", {name_or_literal(Code[pc + n + 2])})
il( dsm, n + 2 )
pc += n + 3
else
il( dsm, n + 1 )
pc += n + 2
end if
end procedure
integer result
result = 0
object result_val
procedure opRETURNP() -- return from procedure (or function)
pbinary()
-- pc += 3
end procedure
procedure opRETURNF()
-- return from function
result_val = Code[pc+3]
il( sprintf( "RETURNF: %s block[%d]", {name_or_literal(result_val), Code[pc+2]}), 3)
pc += 4
end procedure
procedure opCALL_BACK_RETURN()
-- keep_running = FALSE -- force return from do_exec()
il( "CALL_BACK_RETURN", 0 )
end procedure
procedure opBADRETURNF() -- shouldn't reach here
pnonary()
-- RTFatal("attempt to exit a function without returning a value") -- end of a function
end procedure
procedure opRETURNT() -- return from top-level "procedure"
pnonary()
end procedure
procedure opRHS_SUBS() -- find(opcode, {RHS_SUBS_CHECK, RHS_SUBS,
-- RHS_SUBS_I}) then
object sub, x
a = Code[pc+1]
b = Code[pc+2]
target = Code[pc+3]
il( sprintf("%s: %s sub %s => %s",{opnames[Code[pc]]} & names({a,b,target})), 3 )
pc += 4
end procedure
--
procedure opIF()
a = Code[pc+1]
il(sprintf( "%s: %s = 0 goto %04d", {opnames[Code[pc]],name_or_literal(a), Code[pc+2]}),2)
pc += 3
end procedure
procedure check()
il( sprintf("%s: %s",{opnames[Code[pc]] ,name_or_literal(Code[pc+1])}), 1 )
pc += 2
end procedure
procedure opINTEGER_CHECK()
check()
end procedure
procedure opATOM_CHECK()
check()
end procedure
procedure opSEQUENCE_CHECK()
check()
end procedure
--
procedure opASSIGN() -- or opASSIGN_I or SEQUENCE_COPY
a = Code[pc+1]
target = Code[pc+2]
il( sprintf("%s => %s", names( {a,target} )), 2 )
pc += 3
end procedure
--
procedure opELSE() -- or EXIT, ENDWHILE}) then
il( sprintf("%s goto %04d", {opnames[Code[pc]], Code[pc+1]}),1 )
-- pc = Code[pc+1]
pc += 2
end procedure
procedure opRIGHT_BRACE_N() -- form a sequence of any length
sequence x
len = Code[pc+1]
x = sprintf("RIGHT_BRACE_N: len %d", len)
for i = pc+len+1 to pc+2 by -1 do
-- last one comes first
x &= sprintf(", %s",{name_or_literal(Code[i])})
end for
target = Code[pc+len+2]
x &= sprintf(" => %s", {name_or_literal(target)})
il( x, len + 2 )
pc += 3 + len
end procedure
procedure opRIGHT_BRACE_2() -- form a sequence of length 2
binary()
end procedure
procedure opPLUS1() --or opPLUS1_I then
a = Code[pc+1]
-- [2] is not used
target = Code[pc+3]
il( sprintf("PLUS1: %s + 1 => %s", names( a & target )), 3 )
pc += 4
end procedure
procedure opGLOBAL_INIT_CHECK() --or PRIVATE_INIT_CHECK then
a = Code[pc+1]
il( sprintf("%s: %s", {opnames[Code[pc]],name_or_literal(a)}), 1 )
pc += 2
end procedure
procedure opWHILE() -- sometimes emit.c optimizes this away
a = Code[pc+1]
il( sprintf("WHILE: %s goto %04d else goto %04d", {name_or_literal(a), pc+3, Code[pc+2]}), 2 )
pc += 3
end procedure
procedure opLENGTH()
-- operand should be a sequence
a = Code[pc+1]
target = Code[pc+2]
il( sprintf("LENGTH: %s => %s", names(a&target)), 2 )
pc += 3
end procedure
-- Note: Multiple LHS subscripts, and $ within those subscripts,
-- is handled much more efficiently in the hand-coded C interpreter,
-- and in code translated to C, where C pointers can be used effectively.
procedure opPLENGTH()
-- Needed for some LHS uses of $. Operand should be a val index of a sequence,
-- with subscripts.
a = Code[pc+1]
target = Code[pc+2]
il( sprintf("PLENGTH: %s => %s", names( a & target )), 2 )
pc += 3
end procedure
procedure opLHS_SUBS()
-- Handle one LHS subscript, when there are multiple LHS subscripts.
a = Code[pc+1] -- base var sequence, or a temp that contains
-- {base index, subs1, subs2... so far}
b = Code[pc+2] -- subscript
target = Code[pc+3] -- temp for storing result
il( sprintf("LHS_SUBS: %s, %s => %s (UNUSED - %s)", names( Code[pc+1..pc+4] )), 4 )
-- a is a "pointer" to the result of previous subscripting
-- val[target] = append(val[a], val[b])
pc += 5
end procedure
--
procedure opLHS_SUBS1()
-- Handle first LHS subscript, when there are multiple LHS subscripts.
a = Code[pc+1] -- base var sequence, or a temp that contains
-- {base index, subs1, subs2... so far}
b = Code[pc+2] -- subscript
target = Code[pc+3] -- temp for storing result
il( sprintf("LHS_SUBS1: %s, %s => %s (UNUSED - %s)", names( Code[pc+1..pc+4] )), 4 )
-- a is the base var
-- val[target] = {a, val[b]}
pc += 5
end procedure
procedure opLHS_SUBS1_COPY()
-- Handle first LHS subscript, when there are multiple LHS subscripts.
-- In tricky situations a copy of the sequence is made into a temp.
-- (Protects against function call inside subscript expression.
-- In the C backend, it also prevents circular pointer references.)
a = Code[pc+1] -- base var sequence
b = Code[pc+2] -- subscript
target = Code[pc+3] -- temp for storing result
c = Code[pc+4] -- temp to hold base sequence while it's manipulated
il( sprintf("LHS_SUBS1_COPY: %s, %s => (%s) %s", names( Code[pc+1..pc+4] )), 4 )
-- val[c] = val[a]
-- a is the base var
-- val[target] = {c, val[b]}
pc += 5
end procedure
procedure opASSIGN_SUBS() -- also ASSIGN_SUBS_CHECK, ASSIGN_SUBS_I
-- LHS single subscript and assignment
object x, subs
a = Code[pc+1] -- the sequence
b = Code[pc+2] -- the subscript
c = Code[pc+3] -- the RHS value
-- x = val[a]
-- lhs_check_subs(x, val[b])
-- x = val[c]
-- subs = val[b]
-- val[a][subs] = x -- single LHS subscript
il( sprintf("%s: %s, %s <= %s", {opnames[Code[pc]]} & names( Code[pc+1..pc+3] )), 3 )
pc += 4
end procedure
procedure opPASSIGN_SUBS()
-- final LHS subscript and assignment after a series of subscripts
a = Code[pc+1]
b = Code[pc+2] -- subscript
c = Code[pc+3] -- RHS value
-- multiple LHS subscript case
-- lhs_seq_index = val[a][1]
-- lhs_subs = val[a][2..$]
-- val[lhs_seq_index] = assign_subs(val[lhs_seq_index],
-- lhs_subs & val[b],
-- val[c])
il( sprintf("PASSIGN_SUBS: %s, %s <= %s", names( Code[pc+1..pc+3] )), 3 )
pc += 4
end procedure
procedure opASSIGN_OP_SUBS() -- var[subs] op= expr
object x
a = Code[pc+1]
b = Code[pc+2]
target = Code[pc+3]
-- var with one subscript
-- lhs_subs = {}
-- x = val[a]
-- val[target] = var_subs(x, lhs_subs & val[b])
il( sprintf("ASSIGN_OP_SUBS: %s, %s => %s", names( Code[pc+1..pc+3] )), 3 )
pc += 4
end procedure
procedure opPASSIGN_OP_SUBS() -- var[subs] ... [subs] op= expr
a = Code[pc+1]
b = Code[pc+2]
target = Code[pc+3]
-- temp with multiple subscripts
-- lhs_seq_index = val[a][1]
-- lhs_subs = val[a][2..$]
il( sprintf("PASSIGN_OP_SUBS: %s, %s => %s (patch %04dd => %d)",
names( Code[pc+1..pc+3] ) & pc+9 & Code[pc+1]), 3 )
Code[pc+9] = Code[pc+1] -- patch upcoming op
-- val[target] = var_subs(val[lhs_seq_index], lhs_subs & val[b])
pc += 4
end procedure
procedure opASSIGN_OP_SLICE() --then -- var[i..j] op= expr
object x
a = Code[pc+1]
b = Code[pc+2]
c = Code[pc+3]
target = Code[pc+4]
il( sprintf("ASSIGN_OP_SLICE: %s, %s, %s => %s", names(a&b&c&target)),4 )
-- val[target] = var_slice(x, {}, val[b], val[c])
pc += 5
end procedure
procedure opPASSIGN_OP_SLICE() --then -- var[subs] ... [i..j] op= expr
object x
a = Code[pc+1]
b = Code[pc+2]
c = Code[pc+3]
target = Code[pc+4]
il( sprintf("PASSIGN_OP_SLICE: %s, %s, %s => %s (patch %04d => %d",
names(a&b&c&target) & pc+10 & Code[pc+1]),4 )
Code[pc+10] = Code[pc+1]
pc += 5
end procedure
procedure opASSIGN_SLICE() -- var[i..j] = expr
object x
a = Code[pc+1] -- sequence
b = Code[pc+2] -- 1st index
c = Code[pc+3] -- 2nd index
d = Code[pc+4] -- rhs value to assign
il(sprintf("ASSIGN_SLICE: %s %s..%s => %s", names({a,b,c,d})),4)
pc += 5
end procedure
procedure opPASSIGN_SLICE() -- var[x] ... [i..j] = expr
a = Code[pc+1] -- sequence
b = Code[pc+2] -- 1st index
c = Code[pc+3] -- 2nd index
d = Code[pc+4] -- rhs value to assign
il(sprintf("PASSIGN_SLICE: %s %s..%s => %s", names({a,b,c,d})),4)
pc += 5
end procedure
procedure opRHS_SLICE() -- rhs slice of a sequence a[i..j]
object x
a = Code[pc+1] -- sequence
b = Code[pc+2] -- 1st index
c = Code[pc+3] -- 2nd index
target = Code[pc+4]
il(sprintf("RHS_SLICE: %s %s..%s => %s", names({a,b,c,target})),4)
pc += 5
end procedure
procedure opTYPE_CHECK_FORWARD()
il( sprintf("TYPE_CHECK_FORWARD: %s OpTypeCheck: %d", names({Code[pc+1]}) & Code[pc+2] ), 2 )
pc += 3
end procedure
procedure opTYPE_CHECK()
pnonary()
end procedure
procedure is_an()
a = Code[pc+1]
target = Code[pc+2]
il( sprintf("%s: %s %s",{ opnames[Code[pc]] } & names(a&target)), 2 )
pc += 3
end procedure
procedure opIS_AN_INTEGER()
is_an()
end procedure
procedure opIS_AN_ATOM()
is_an()
end procedure
procedure opIS_A_SEQUENCE()
is_an()
end procedure
procedure opIS_AN_OBJECT()
is_an()
end procedure
-- -- ---------- start of unary ops -----------------
--
procedure opSQRT()
unary()
end procedure
procedure opSIN()
unary()
end procedure
procedure opCOS()
unary()
end procedure
procedure opTAN()
unary()
end procedure
procedure opARCTAN()
unary()
end procedure
procedure opLOG()
unary()
end procedure
procedure opNOT_BITS()
unary()
end procedure
procedure opFLOOR()
unary()
end procedure
procedure opNOT_IFW()
a = Code[pc+1]
il( sprintf( "NOT_IFW %s goto %04d else goto %04d",
{name_or_literal(a), pc + 3, Code[pc+2]}), 2 )
pc += 3
end procedure
procedure opNOT()
unary()
end procedure
procedure opUMINUS()
unary()
end procedure
procedure opRAND()
unary()
end procedure
procedure opDIV2() -- like unary, but pc+=4
a = Code[pc+1]
-- Code[pc+2] not used
target = Code[pc+3]
il( sprintf("DIV2: %s => %s",names( a & target )), 3 )
pc += 4
end procedure
procedure opFLOOR_DIV2()
a = Code[pc+1]
-- Code[pc+2] not used
target = Code[pc+3]
il( sprintf("FLOOR_DIV2: %s => %s",names( a & target )), 3 )
pc += 4
end procedure
-- ----------- start of binary ops ----------
--
procedure opGREATER_IFW()
a = Code[pc+1]
b = Code[pc+2]
il( sprintf( "GREATER_IFW %s > %s goto %04d else goto %04d",
{name_or_literal(a),name_or_literal(b), pc + 4, Code[pc+3]}), 3 )
pc += 4
end procedure
--
procedure opNOTEQ_IFW()
a = Code[pc+1]
b = Code[pc+2]
il( sprintf( "NOTEQ_IFW %s != %s goto %04d else goto %04d",
{name_or_literal(a),name_or_literal(b), pc + 4, Code[pc+3]}), 3 )
pc += 4
end procedure
procedure opLESSEQ_IFW()
a = Code[pc+1]
b = Code[pc+2]
il( sprintf( "LESSEQ_IFW %s <= %s goto %04d else goto %04d",
{name_or_literal(a),name_or_literal(b), pc + 4, Code[pc+3]}), 3 )
pc += 4
end procedure
procedure opGREATEREQ_IFW()
a = Code[pc+1]
b = Code[pc+2]
il( sprintf( "GREATEREQ_IFW %s > %s goto %04d else goto %04d",
{name_or_literal(a),name_or_literal(b), pc + 4, Code[pc+3]}), 3 )
pc += 4
end procedure
procedure opEQUALS_IFW()
a = Code[pc+1]
b = Code[pc+2]
sequence i
if Code[pc] = EQUALS_IFW then
i = ""
else
i = "_I"
end if
il( sprintf( "EQUALS_IFW%s %s = %s goto %04d else goto %04d",
{i, name_or_literal(a),name_or_literal(b), pc + 4, Code[pc+3]}), 3 )
pc += 4
end procedure
procedure opLESS_IFW()
a = Code[pc+1]
b = Code[pc+2]
il( sprintf( "IFW %s < %s goto %04d else goto %04d",
{name_or_literal(a),name_or_literal(b), pc + 4, Code[pc+3]}), 3 )
pc += 4
end procedure
-- -- other binary ops
--
procedure opMULTIPLY()
binary()
end procedure
procedure opPLUS() -- or opPLUS_I then
binary()
end procedure
procedure opMINUS() -- or opMINUS_I then
binary()
end procedure
procedure opOR()
binary()
end procedure
procedure opXOR()
binary()
end procedure
procedure opAND()
binary()
end procedure
procedure opDIVIDE()
binary()
end procedure
procedure opREMAINDER()
binary()
end procedure
procedure opFLOOR_DIV()
binary()
end procedure
procedure opAND_BITS()
binary()
end procedure
procedure opOR_BITS()
binary()
end procedure
procedure opXOR_BITS()
binary()
end procedure
procedure opPOWER()
binary()
end procedure
procedure opLESS()
binary()
end procedure
procedure opGREATER()
binary()
end procedure
procedure opEQUALS()
binary()
end procedure
procedure opNOTEQ()
binary()
end procedure
procedure opLESSEQ()
binary()
end procedure
procedure opGREATEREQ()
binary()
end procedure
-- short-circuit ops
procedure short_circuit()
a = Code[pc+1]
b = Code[pc+2]
il( sprintf("%s: %s, %s, %04d", {opnames[Code[pc]]} & names(a&b) & Code[pc+3]), 3 )
pc += 4
end procedure
procedure opSC1_AND()
short_circuit()
end procedure
procedure opSC1_AND_IF()
short_circuit()
end procedure
procedure opSC1_OR()
short_circuit()
end procedure
procedure opSC1_OR_IF()
short_circuit()
end procedure
procedure opSC2_OR() -- or opSC2_AND
-- short-circuit op
pbinary()
end procedure
-- for loops
procedure opFOR() -- or opFOR_I
-- enter into a for loop
integer increment, limit, initial, loopvar, jump
increment = Code[pc+1]
limit = Code[pc+2]
initial = Code[pc+3]
-- ignore current_sub = Code[pc+4] - we don't patch the ENDFOR
-- so recursion is not a problem
loopvar = Code[pc+5]
jump = Code[pc+6]