-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackops.c
More file actions
157 lines (118 loc) · 2.15 KB
/
Copy pathstackops.c
File metadata and controls
157 lines (118 loc) · 2.15 KB
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
/* stackops.c - операции со стэком */
#include "stack.h"
void Dup() /* dup n1 -> n1, n2 */
{
SINGLE a;
a = PopSingle();
PushSingle(a);
PushSingle(a);
}
void qdup() /* ?dup n1 -> n1, |n1| */
{
SINGLE a;
a = PopSingle();
PushSingle(a);
if(a)
PushSingle(a);
}
void drop() /* drop n1 -> */
{
stackhead -= SINGLESIZE;
}
void over() /* over n1, n2 -> n1, n2, n1 */
{
SINGLE a, b;
a = PopSingle();
b = PopSingle();
PushSingle(b);
PushSingle(a);
PushSingle(b);
}
void rot() /* rot n1, n2, n3 -> n2, n3, n1 */
{
SINGLE a, b, c;
a = PopSingle();
b = PopSingle();
c = PopSingle();
PushSingle(b);
PushSingle(a);
PushSingle(c);
}
void swap() /* swap n1, n2 -> n2, n1 */
{
SINGLE a, b;
a = PopSingle();
b = PopSingle();
PushSingle(a);
PushSingle(b);
}
void pick() /* pick d1, d2, ..., dn, n -> d1, d2, ..., dn, d1 */
{
SINGLE n;
n = PopSingle();
PushNUnsigned(FetchNUnsigned(stackhead-n*SINGLESIZE-1));
}
void twoswap() /* 2swap d2, d1 -> d1, d2 */
{
DOUBLE d1, d2;
d1 = PopDouble();
d2 = PopDouble();
PushDouble(d1);
PushDouble(d2);
}
void minusrot() /* -rot n1, n2, n3 -> n3, n1, n2 */
{
SINGLE a, b, c;
a = PopSingle();
b = PopSingle();
c = PopSingle();
PushSingle(c);
PushSingle(a);
PushSingle(b);
}
void twodup() /* 2dup d -> d, d */
{
DOUBLE d;
d = PopDouble();
PushDouble(d);
PushDouble(d);
}
void twodrop() /* 2drop d -> */
{
stackhead -= DOUBLESIZE;
}
void press() /* press n1, n2 -> n2 */
{
SINGLE n2;
n2 = PopSingle();
(void)PopSingle();
PushSingle(n2);
}
void twoover() /* 2over d1, d2 -> d1, d2, d1 */
{
DOUBLE a, b;
a = PopDouble();
b = PopDouble();
PushDouble(b);
PushDouble(a);
PushDouble(b);
}
void spfetch() /* sp@ -> a */
{
PushNUnsigned(stackhead);
}
void spstore() /* sp! a -> */
{
stackhead = PopNUnsigned();
}
void roll() /* roll d1, d2, ..., dn, n -> d2, d3, ..., dn, d1 */
{
SINGLE n;
NUNSIGNED b;
int i;
n = PopSingle();
b = FetchNUnsigned(stackhead-n*SINGLESIZE-1);
for(i = stackhead-n*SINGLESIZE; i > stackhead-1; i++)
vocabulary[i] = vocabulary[i+2];
PushNUnsigned(b);
}