/
rf.c
1197 lines (1046 loc) · 18.6 KB
/
rf.c
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
/* ORTERFORTH */
#include "rf.h"
/* FORTH MACHINE */
/* SP */
#ifndef RF_TARGET_SP
uintptr_t *rf_sp = 0;
#endif
#ifndef RF_INLINE_SP
uintptr_t rf_sp_pop(void)
{
return *(rf_sp++);
}
void __FASTCALL__ rf_sp_push(uintptr_t a)
{
*(--rf_sp) = a;
}
#endif
/* RP */
#ifndef RF_TARGET_RP
uintptr_t *rf_rp = 0;
#endif
#ifndef RF_INLINE_RP
uintptr_t rf_rp_pop(void)
{
return *(rf_rp++);
}
void __FASTCALL__ rf_rp_push(uintptr_t a)
{
*(--rf_rp) = a;
}
#endif
/* IP */
#ifndef RF_TARGET_IP
uintptr_t *rf_ip = 0;
#endif
/* W */
#ifndef RF_TARGET_W
rf_code_t *rf_w = 0;
#endif
/* UP */
#ifndef RF_TARGET_UP
uintptr_t *rf_up = 0;
#endif
/* TRAMPOLINE */
/* trampoline function pointer */
#ifndef RF_TARGET_FP
rf_code_t rf_fp = 0;
#endif
#ifndef RF_TARGET_TRAMPOLINE
/* A loop that repeatedly executes function pointers. */
void rf_trampoline(void)
{
while (rf_fp) {
/* Default implementation does nothing here; assembly
implementations can switch machine state into registers
(and, if the processor return stack is used by the Forth
machine, ensure the return address is on the C stack not
the Forth stack). */
rf_fp();
}
}
/* Called at start of each C-based code word. */
void rf_start(void)
{
/* Default implementation does nothing here; assembly
implementations can switch machine state out of registers
(and, if the processor return stack is used by the Forth
machine, move the stack frame). */
}
#endif
/* CODE */
#ifndef RF_TARGET_CODE_LIT
void rf_code_lit(void)
{
RF_START;
{
uintptr_t a = *(RF_IP_GET);
RF_SP_PUSH(a);
RF_IP_INC;
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_NEXT
void rf_next(void)
{
RF_START;
rf_w = (rf_code_t *) *(RF_IP_GET);
RF_IP_INC;
RF_JUMP(*rf_w);
}
#endif
#ifndef RF_TARGET_CODE_EXEC
void rf_code_exec(void)
{
RF_START;
rf_w = (rf_code_t *) RF_SP_POP;
RF_JUMP(*rf_w);
}
#endif
#ifndef RF_TARGET_CODE_BRAN
#ifndef RF_BRANCH
#define RF_BRANCH
static void rf_branch(void);
#endif
void rf_code_bran(void)
{
RF_START;
rf_branch();
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_ZBRAN
#ifndef RF_BRANCH
#define RF_BRANCH
static void rf_branch(void);
#endif
void rf_code_zbran(void)
{
RF_START;
if (RF_SP_POP) {
RF_IP_INC;
} else {
rf_branch();
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_XLOOP
#ifndef RF_BRANCH
#define RF_BRANCH
static void rf_branch(void);
#endif
void rf_code_xloop(void)
{
RF_START;
{
intptr_t index = (intptr_t) RF_RP_POP;
intptr_t limit = (intptr_t) RF_RP_POP;
++index;
if (limit > index) {
RF_RP_PUSH(limit);
RF_RP_PUSH(index);
rf_branch();
} else {
RF_IP_INC;
}
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_XPLOO
#ifndef RF_BRANCH
#define RF_BRANCH
static void rf_branch(void);
#endif
void rf_code_xploo(void)
{
RF_START;
{
intptr_t n = (intptr_t) RF_SP_POP;
intptr_t index = (intptr_t) RF_RP_POP;
intptr_t limit = (intptr_t) RF_RP_POP;
index += n;
if (((n > 0) && (index < limit)) || ((n < 0) && (index > limit))) {
RF_RP_PUSH(limit);
RF_RP_PUSH(index);
rf_branch();
} else {
RF_IP_INC;
}
}
RF_JUMP_NEXT;
}
#endif
#ifdef RF_BRANCH
static void rf_branch(void)
{
uintptr_t offset = (uintptr_t) *(RF_IP_GET);
RF_IP_SET((uintptr_t *) (((char *) RF_IP_GET) + offset));
}
#endif
#ifndef RF_TARGET_CODE_XDO
void rf_code_xdo(void)
{
RF_START;
{
uintptr_t n2 = RF_SP_POP;
uintptr_t n1 = RF_SP_POP;
RF_RP_PUSH(n1);
RF_RP_PUSH(n2);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_DODOE
void rf_code_dodoe(void)
{
RF_START;
{
uintptr_t *p1;
uintptr_t *p2;
/* execute the words after DOES> (addr in the PFA): */
/* push IP onto RP */
RF_RP_PUSH((uintptr_t) RF_IP_GET);
/* fetch first param *(W + 1) as new IP */
p1 = (uintptr_t *) rf_w + 1;
RF_IP_SET((uintptr_t *) (*p1));
/* push second param addr (W + 2) onto SP */
p2 = (uintptr_t *) rf_w + 2;
RF_SP_PUSH((uintptr_t) p2);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_RR
void rf_code_rr(void)
{
RF_START;
{
uintptr_t i = (uintptr_t) *(RF_RP_GET);
RF_SP_PUSH(i);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_DIGIT
static uint8_t rf_digit(uint8_t base, uint8_t c)
{
c -= 0x30;
if (c > 9) {
if (c < 17) {
return 0xFF;
}
c -= 7;
}
if (c < base) {
return c;
}
return 0xFF;
}
void rf_code_digit(void)
{
RF_START;
{
uint8_t b, c, d;
b = (uint8_t) RF_SP_POP;
c = (uint8_t) RF_SP_POP;
d = rf_digit(b, c);
if (d == 0xFF) {
RF_SP_PUSH(0);
} else {
RF_SP_PUSH(d);
RF_SP_PUSH(1);
}
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_PFIND
static uint8_t __FASTCALL__ **rf_lfa(uint8_t *nfa)
{
while (!(*(++nfa) & 0x80)) {
}
return (uint8_t **) ++nfa;
}
static uint8_t *rf_find(uint8_t *t, uint8_t length, uint8_t *nfa)
{
uint8_t b;
uint8_t *m, *n;
while (nfa) {
/* match length from name field incl smudge bit */
if (length == (*nfa & 0x3F)) {
/* match name - NB matches the whole aligned name field */
n = nfa;
m = t;
while (*(m++) == ((b = *(++n)) & 0x7F)) {
if (b & 0x80) return nfa;
}
}
/* if no match, follow link */
nfa = *(rf_lfa(nfa));
}
/* not found */
return 0;
}
static uintptr_t __FASTCALL__ *rf_pfa(uint8_t *nfa)
{
uint8_t **lfa = rf_lfa(nfa);
uintptr_t *pfa = (uintptr_t *) lfa + 2;
return pfa;
}
static uintptr_t rf_pfind(uint8_t *addr1, uint8_t *addr2)
{
uint8_t length;
uint8_t *f;
length = *addr1;
f = rf_find(addr1 + 1, length, addr2);
if (f) {
RF_SP_PUSH((uintptr_t) rf_pfa(f));
RF_SP_PUSH(*((uint8_t *) f));
return 1;
} else {
return 0;
}
}
void rf_code_pfind(void)
{
RF_START;
{
uint8_t *addr2;
uint8_t *addr1;
uintptr_t f;
addr2 = (uint8_t *) RF_SP_POP; /* nfa */
addr1 = (uint8_t *) RF_SP_POP; /* text to find */
f = rf_pfind(addr1, addr2);
RF_SP_PUSH(f);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_ENCL
static void rf_enclose(char c, char *addr1, uint8_t *s3, uint8_t *s2, uint8_t *s1)
{
char *hl = addr1;
uint8_t e = 0xFF;
/* skip leading delimiters */
hl--;
do {
++hl;
++e;
} while (*hl == c);
*s3 = e;
/* return if null */
if (!*hl) {
*s1 = e;
++e;
*s2 = e;
return;
}
/* traverse word */
do {
++hl;
++e;
/* return if delim */
if (*hl == c) {
*s2 = e;
++e;
*s1 = e;
return;
}
} while (*hl);
/* return if null */
*s2 = e;
*s1 = e;
}
static void rf_encl(void)
{
char c;
char *addr1;
uint8_t n1, n2, n3;
c = (char) RF_SP_POP;
addr1 = (char *) RF_SP_POP;
rf_enclose(c, addr1, &n1, &n2, &n3);
RF_SP_PUSH((uintptr_t) addr1);
RF_SP_PUSH(n1);
RF_SP_PUSH(n2);
RF_SP_PUSH(n3);
}
void rf_code_encl(void)
{
RF_START;
rf_encl();
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_CMOVE
void rf_code_cmove(void)
{
RF_START;
{
uintptr_t count = RF_SP_POP;
char *to = (char *) RF_SP_POP;
char *from = (char *) RF_SP_POP;
for (; count; count--) {
*(to++) = *(from++);
}
}
RF_JUMP_NEXT;
}
#endif
/* DOUBLE ARITHMETIC */
#if (RF_WORD_SIZE == 2)
#define RF_WORD_SIZE_BITS 16
#elif (RF_WORD_SIZE == 4)
#define RF_WORD_SIZE_BITS 32
#elif (RF_WORD_SIZE == 8)
#define RF_WORD_SIZE_BITS 64
#endif
#ifdef RF_DOUBLE_ARITH
#ifndef RF_TARGET_CODE_USTAR
#define RF_UNDOUBLE
#endif
#ifndef RF_TARGET_CODE_USLAS
#define RF_DOUBLE
#endif
#ifndef RF_TARGET_CODE_DPLUS
#define RF_DOUBLE
#define RF_UNDOUBLE
#endif
#ifndef RF_TARGET_CODE_DMINU
#define RF_DOUBLE
#define RF_UNDOUBLE
#endif
#endif
#ifdef RF_DOUBLE
static void rf_double(uintptr_t h, uintptr_t l, rf_double_t *d)
{
rf_double_t a = (rf_double_t) h << RF_WORD_SIZE_BITS;
rf_double_t b = (rf_double_t) l;
*d = a | b;
}
#endif
#ifdef RF_UNDOUBLE
static void rf_undouble(rf_double_t d, uintptr_t *h, uintptr_t *l)
{
*h = d >> RF_WORD_SIZE_BITS;
*l = d;
}
#endif
#ifndef RF_TARGET_CODE_USTAR
#ifdef RF_DOUBLE_ARITH
static void rf_ustar(uintptr_t a, uintptr_t b, uintptr_t *ch, uintptr_t *cl)
{
rf_double_t d;
d = (rf_double_t) a * b;
rf_undouble(d, ch, cl);
}
#else
#if (RF_WORD_SIZE==2)
#define RF_WORD_SIZE_BITS_HALF 8
#define RF_WORD_MASK_LO 0x00FFU
#define RF_WORD_MASK_HI 0xFF00U
#endif
#if (RF_WORD_SIZE==4)
#define RF_WORD_SIZE_BITS_HALF 16
#define RF_WORD_MASK_LO 0x0000FFFFU
#define RF_WORD_MASK_HI 0xFFFF0000U
#endif
#if (RF_WORD_SIZE==8)
#define RF_WORD_SIZE_BITS_HALF 32
#define RF_WORD_MASK_LO 0x00000000FFFFFFFFU
#define RF_WORD_MASK_HI 0xFFFFFFFF00000000U
#endif
static void rf_ustar(uintptr_t a, uintptr_t b, uintptr_t *ch, uintptr_t *cl)
{
uintptr_t ah = a >> RF_WORD_SIZE_BITS_HALF;
uintptr_t al = a & RF_WORD_MASK_LO;
uintptr_t bh = b >> RF_WORD_SIZE_BITS_HALF;
uintptr_t bl = b & RF_WORD_MASK_LO;
uintptr_t rl = al * bl;
uintptr_t rm1 = ah * bl;
uintptr_t rm2 = al * bh;
uintptr_t rh = ah * bh;
uintptr_t rml = (rm1 & RF_WORD_MASK_LO) + (rm2 & RF_WORD_MASK_LO);
uintptr_t rmh = (rm1 >> RF_WORD_SIZE_BITS_HALF) + (rm2 >> RF_WORD_SIZE_BITS_HALF);
rl += rml << RF_WORD_SIZE_BITS_HALF;
if (rml & RF_WORD_MASK_HI) {
rmh++;
}
rh += rmh;
*cl = rl;
*ch = rh;
}
#endif
void rf_code_ustar(void)
{
RF_START;
{
uintptr_t a, b, ch, cl;
a = RF_SP_POP;
b = RF_SP_POP;
rf_ustar(a, b, &ch, &cl);
RF_SP_PUSH(cl);
RF_SP_PUSH(ch);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_USLAS
#ifdef RF_DOUBLE_ARITH
static uintptr_t rf_uslas(uintptr_t uh, uintptr_t ul, uintptr_t v, uintptr_t *r)
{
rf_double_t a, b;
/* overflow or divide by zero */
if (uh >= v) {
*r = (uintptr_t) -1;
return (uintptr_t) -1;
}
rf_double(uh, ul, &a);
rf_double(0, v, &b);
*r = (uintptr_t) (a % b);
return (uintptr_t) (a / b);
}
#else
#if (RF_WORD_SIZE==2)
#define RF_TOPBIT 0x8000
#endif
#if (RF_WORD_SIZE==4)
#define RF_TOPBIT 0x80000000
#endif
#if (RF_WORD_SIZE==8)
#define RF_TOPBIT 0x8000000000000000
#endif
static uintptr_t rf_uslas(uintptr_t uh, uintptr_t ul, uintptr_t v, uintptr_t *r)
{
int i;
/* overflow or divide by zero */
if (v >= RF_TOPBIT || uh >= v) {
*r = (uintptr_t) -1;
return (uintptr_t) -1;
}
for (i = 0; i < RF_WORD_SIZE_BITS; i++) {
/* Start to shift numerator left (top bit is lost) */
uh <<= 1;
/* Add the carry to high word */
if (ul & RF_TOPBIT) {
uh++;
}
/* End of shift */
ul <<= 1;
/* Jump if can't subtract */
if (uh >= v) {
/* Subtract v and add the flag to result (in low word) */
uh -= v;
ul++;
}
}
/* result */
*r = uh;
return ul;
}
#endif
void rf_code_uslas(void)
{
RF_START;
{
uintptr_t ah, al, b, q, r;
b = RF_SP_POP;
ah = RF_SP_POP;
al = RF_SP_POP;
q = rf_uslas(ah, al, b, &r);
RF_SP_PUSH(r);
RF_SP_PUSH(q);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_ANDD
void rf_code_andd(void)
{
RF_START;
{
uintptr_t a;
uintptr_t b;
a = RF_SP_POP;
b = RF_SP_POP;
RF_SP_PUSH(a & b);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_ORR
void rf_code_orr(void)
{
RF_START;
{
uintptr_t a;
uintptr_t b;
a = RF_SP_POP;
b = RF_SP_POP;
RF_SP_PUSH(a | b);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_XORR
void rf_code_xorr(void)
{
RF_START;
{
uintptr_t a;
uintptr_t b;
a = RF_SP_POP;
b = RF_SP_POP;
RF_SP_PUSH(a ^ b);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_SPAT
void rf_code_spat(void)
{
RF_START;
{
uintptr_t sp;
sp = (uintptr_t) RF_SP_GET;
RF_SP_PUSH(sp);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_SPSTO
void rf_code_spsto(void)
{
RF_START;
RF_SP_SET((uintptr_t *) rf_up[3]);
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_RPSTO
void rf_code_rpsto(void)
{
RF_START;
RF_RP_SET((uintptr_t *) rf_up[4]);
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_SEMIS
void rf_code_semis(void)
{
RF_START;
RF_IP_SET((uintptr_t *) RF_RP_POP);
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_LEAVE
void rf_code_leave(void)
{
RF_START;
{
uintptr_t index;
index = (uintptr_t) RF_RP_POP;
(void) RF_RP_POP;
RF_RP_PUSH(index);
RF_RP_PUSH(index);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_TOR
void rf_code_tor(void)
{
RF_START;
RF_RP_PUSH(RF_SP_POP);
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_FROMR
void rf_code_fromr(void)
{
RF_START;
RF_SP_PUSH((uintptr_t) RF_RP_POP);
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_ZEQU
void rf_code_zequ(void)
{
RF_START;
{
uintptr_t a;
a = (RF_SP_POP == 0);
RF_SP_PUSH(a);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_ZLESS
void rf_code_zless(void)
{
RF_START;
{
uintptr_t a;
a = (((intptr_t) RF_SP_POP) < 0);
RF_SP_PUSH(a);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_PLUS
void rf_code_plus(void)
{
RF_START;
{
intptr_t a;
intptr_t b;
a = RF_SP_POP;
b = RF_SP_POP;
RF_SP_PUSH(a + b);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_DPLUS
#ifdef RF_DOUBLE_ARITH
static void rf_dplus(uintptr_t ah, uintptr_t al, uintptr_t bh, uintptr_t bl, uintptr_t *ch, uintptr_t *cl)
{
rf_double_t a;
rf_double_t b;
rf_double_t c;
rf_double(ah, al, &a);
rf_double(bh, bl, &b);
c = a + b;
rf_undouble(c, ch, cl);
}
#else
static void rf_dplus(uintptr_t ah, uintptr_t al, uintptr_t bh, uintptr_t bl, uintptr_t *ch, uintptr_t *cl)
{
*cl = al + bl;
*ch = ah + bh;
if (*cl < al)
(*ch)++;
}
#endif
void rf_code_dplus(void)
{
RF_START;
{
uintptr_t ah, al, bh, bl, ch, cl;
ah = RF_SP_POP;
al = RF_SP_POP;
bh = RF_SP_POP;
bl = RF_SP_POP;
rf_dplus(ah, al, bh, bl, &ch, &cl);
RF_SP_PUSH(cl);
RF_SP_PUSH(ch);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_MINUS
void rf_code_minus(void)
{
RF_START;
{
uintptr_t a;
a = (~RF_SP_POP) + 1;
RF_SP_PUSH(a);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_DMINU
#ifdef RF_DOUBLE_ARITH
static void rf_dminu(uintptr_t bh, uintptr_t bl, uintptr_t *ch, uintptr_t *cl)
{
rf_double_t d;
rf_double(bh, bl, &d);
d = -d;
rf_undouble(d, ch, cl);
}
#else
static void rf_dminu(uintptr_t bh, uintptr_t bl, uintptr_t *ch, uintptr_t *cl)
{
*cl = -bl;
*ch = -bh;
if (bl)
(*ch)--;
}
#endif
void rf_code_dminu(void)
{
RF_START;
{
uintptr_t bh, bl, ch, cl;
bh = RF_SP_POP;
bl = RF_SP_POP;
rf_dminu(bh, bl, &ch, &cl);
RF_SP_PUSH(cl);
RF_SP_PUSH(ch);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_OVER
void rf_code_over(void)
{
RF_START;
{
uintptr_t a;
uintptr_t b;
a = RF_SP_POP;
b = RF_SP_POP;
RF_SP_PUSH(b);
RF_SP_PUSH(a);
RF_SP_PUSH(b);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_DROP
void rf_code_drop(void)
{
RF_START;
(void) RF_SP_POP;
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_SWAP
void rf_code_swap(void)
{
RF_START;
{
uintptr_t a;
uintptr_t b;
a = RF_SP_POP;
b = RF_SP_POP;
RF_SP_PUSH(a);
RF_SP_PUSH(b);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_DUP
void rf_code_dup(void)
{
RF_START;
{
uintptr_t a;
a = RF_SP_POP;
RF_SP_PUSH(a);
RF_SP_PUSH(a);
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_PSTOR
void rf_code_pstor(void)
{
RF_START;
{
uintptr_t *addr;
intptr_t n;
addr = (uintptr_t *) RF_SP_POP;
n = (intptr_t) RF_SP_POP;
*addr += n;
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_TOGGL
void rf_code_toggl(void)
{
RF_START;
{
char bits;
char *addr;
bits = (char) RF_SP_POP;
addr = (char *) RF_SP_POP;
*addr ^= bits;
}
RF_JUMP_NEXT;
}
#endif
#ifndef RF_TARGET_CODE_AT
void rf_code_at(void)
{
RF_START;
{
uintptr_t *addr;
uintptr_t word;
addr = (uintptr_t *) RF_SP_POP;
word = *addr;