-
Notifications
You must be signed in to change notification settings - Fork 0
/
loop.c
executable file
·165 lines (137 loc) · 2.78 KB
/
loop.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
// Copyleft by Potrepalov I.S.
// --------------------
/* +LOOP ?DO DO I J LOOP */
/*
* Data space (code file):
*
* doDO ( do_q_do )
* +-- link
* | loop body
* | .........
* | doLOOP ( do_plus_loop )
* +->
*
*
* Run time return stack (loop-sys):
*
* TOS: I - limit
* limit
* start loop body address (may be CONTINUE will be usefull...)
* link (for LEAVE)
* ........
*/
i( do_plus_loop ) // n -- ;r loop-sys1 -- loop-sys2 | loop-sys1 --
{
sCELL n = pop();
sCELL lc;
crs( 4, 0 );
lc = __rget(0);
if ( lc < 0 )
{
lc += n;
if ( lc >= 0 && n > 0 ) { F( LEAVE ); }
else { __rput( 0, lc ); IP = (xt*) __rget(2); }
} else {
lc += n;
if ( lc < 0 && n < 0 ) { F( LEAVE ); }
else { __rput( 0, lc ); IP = (xt*) __rget(2); }
}
}
i( plus_loop ) // +LOOP C: do-sys --
{
xt *tmp = (xt*)dp, *tmp2;
cds( 2, 0 );
if ( __get(0) != i_doDO ) Throw( -22 ); // control structure mismatch
__put( 0, (CELL) & hide_wl[i_do_plus_loop] );
F( comma );
*(CELL*)__pop() = (CELL)dp;
}
i( do_q_do ) // n1 n2 -- ;R -- loop-sys | n1 n1 -- ;R --
{
CELL start, limit;
cds( 2, 0 ); crs( 0, 4 );
start = __get(0);
limit = __get(1);
if ( start != limit )
{
__rpush( (CELL) *IP );
__rpush( (CELL) ++IP );
__rpush( limit );
__rpush( start - limit );
} else {
IP = (xt*) *(IP);
}
__ndrop(2);
}
i( q_do ) // ?DO C: -- do-sys
{
cds( 0, 2 );
__push( (CELL) &hide_wl[i_do_q_do] );
F( comma );
__push( (CELL) dp );
dp = (uchar*) (((CELL*)dp) + 1);
// ++(CELL*)dp;
__push( i_doDO );
}
i( doDO ) // n1 n2 -- ;r -- loop-sys
{
CELL limit;
cds( 2, 0 ); crs( 0, 4 );
#if DEBUG
printf( "Start: %d, limit %d", (int)__get(0), (int) __get(1) );
#endif
__rpush( (CELL) *IP );
__rpush( (CELL) ++IP );
limit = __get(1);
__rpush( limit );
__rpush( __get(0) - limit );
__ndrop(2);
}
i( DO ) // C: -- do-sys
{
cds( 0, 2 );
__push( (CELL) & hide_wl[i_doDO] );
F( comma );
__push( (CELL) dp );
dp = (uchar*) (((CELL*)dp) + 1);
// ++(CELL*)dp;
__push( i_doDO );
}
i( I ) // -- n ;r loop-sys -- loop-sys
{
crs( 4, 0 );
push( __rget(0) + __rget(1) );
}
i( J ) // -- n ;r loop-sys1 loop-sys2 -- loop-sys1 loop-sys2
{
crs( 8, 0 );
push( __rget(4) + __rget(5) );
}
i( LEAVE ) // -- ;r loop-sys --
{
crs( 4, 0 );
__rpop(); __rpop(); __rpop();
IP = (xt*)__rpop();
}
i( doLOOP ) // -- ;r loop-sys1 -- loop-sys2 | loop-sys1 --
{
sCELL lc;
crs( 3, 0 );
lc = __rget(0) + 1;
if ( lc ) { __rput( 0, lc ); IP = (xt*) __rget(2); }
else F( LEAVE );
}
i( LOOP ) // C: do-sys --
{
cds( 2, 0 );
if ( __get(0) != i_doDO ) Throw( -22 ); // control structure mismatch
__put( 0, (CELL) & hide_wl[i_doLOOP] );
F( comma );
*(CELL*)__pop() = (CELL)dp;
}
i( UNLOOP ) // -- ;r loop-sys --
{
crs( 4, 0 );
__rpop(); __rpop(); __rpop(); __rpop();
}
// End of file