-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommandsRead.cpp
215 lines (168 loc) · 5.08 KB
/
commandsRead.cpp
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
#include "stdafx.h"
#include <vector>
#ifdef __amigaos4__
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/retroMode.h>
#endif
#ifdef __linux__
#include <stdint.h>
#include "os/linux/stuff.h"
#endif
#include <amosKittens.h>
#include <stack.h>
#include "commands.h"
#include "engine.h"
#include "debug.h"
#include "kittyErrors.h"
extern struct globalVar globalVars[];
extern int _last_var_index; // we need to know what index was to keep it.
extern int _set_var_index; // we need to resore index
extern unsigned short token_not_found;
extern struct stackFrame *currentFrame;
// this code should be able to handel expresion in data statement.
//
// The process:
//
// Read [object] -> [keep] -> [execute code from data] -> [store to keeped var], [object] -> [keep] -> [execute code from data] -> [store to keeped var]
extern struct nativeCommand nativeCommands[];
extern int nativeCommandsSize;
extern char *_setVar( struct glueCommands *data, int nextToken );
extern char *_cmdRead( struct glueCommands *data, int nextToken );
extern char *FinderTokenInBuffer( char *ptr, unsigned short token , unsigned short token_eof1, unsigned short token_eof2, char *_eof_ );
extern const char *TokenName( unsigned short token );
void _read_arg( struct nativeCommand *cmd, char *tokenBuffer );
void _exit_read_data( struct nativeCommand *cmd, char *tokenBuffer );
char *executeDataToken(char *ptr, unsigned short token)
{
struct nativeCommand *cmd;
char *ret;
// we are at end of line, we need to find the next data command.
switch (token)
{
case 0x0000:
// printf("** END OF LINE **\n");
ptr = FinderTokenInBuffer( ptr, 0x0404 , -1, -1, _file_end_ );
if (ptr) // if ptr, then token is 0x0404 (new line)
{
ptr+=4; // skip token.
currentFrame -> dataPointer = ptr; // set data_read_poiner
// end of line => comma, exit we have read something I hope.
if (do_input[instance.parenthesis_count] == _exit_read_data)
{
do_input[instance.parenthesis_count] = _read_arg;
return NULL;
}
}
else
{
return NULL;
}
break;
case 0x005C:
// printf("** EXIT ON COMMA **\n");
// comma, exit we have read something I hope.
if (do_input[instance.parenthesis_count] == _exit_read_data)
{
do_input[instance.parenthesis_count] = _read_arg;
return NULL;
}
break;
case 0x0404:
// printf("** SKIP DATA CMD **\n");
// data is expected
return ptr+2; // valid
}
// find the token
for (cmd = nativeCommands ; cmd < nativeCommands + nativeCommandsSize ; cmd++ )
{
if (token == cmd->id )
{
#ifdef show_token_numbers_yes
getLineFromPointer(ptr);
printf("DATA READ %08d %08X %20s:%08d stack is %d cmd stack is %d token %04x -- name %s\n",
lineFromPtr.line , ptr +2,__FUNCTION__,__LINE__, instance.stack, instance.cmdStack, token , TokenName(token));
#endif
ret = cmd -> fn( cmd, ptr ) ;
if (ret) ret += cmd -> size;
return ret;
}
}
token_not_found = token;
setError(33, ptr); // Out of Data
return NULL;
}
static void collect_data()
{
unsigned short token;
char *ptr = procStcakFrame[proc_stack_frame].dataPointer;
setStackNum(0);
token = *((short *) ptr );
ptr+=2;
while ( ptr = executeDataToken( ptr, token ) )
{
// last_tokens[parenthesis_count] = token;
token = *((short *) ptr );
ptr += 2; // next token.
procStcakFrame[proc_stack_frame].dataPointer = ptr; // store last valid.
}
}
void _exit_read_data( struct nativeCommand *cmd, char *tokenBuffer )
{
proc_names_printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
}
void _read_arg( struct nativeCommand *cmd, char *tokenBuffer )
{
int args = 0;
struct glueCommands data;
proc_names_printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
if (cmd == NULL)
{
args =__stack - cmdTmp[instance.cmdStack].stack + 1;
}
else
{
if (instance.cmdStack) if (cmdTmp[instance.cmdStack-1].cmd == _cmdRead)
{
args =__stack - cmdTmp[instance.cmdStack-1].stack + 1;
}
}
if (last_var)
{
int local_var_index = getVar(last_var) -> index;
int local_last_var = last_var;
do_input[instance.parenthesis_count] = _exit_read_data;
collect_data();
_set_var_index = local_var_index;
last_var = local_last_var;
data.lastVar = last_var;
}
_setVar( &data,0 );
}
char *_cmdRead( struct glueCommands *data, int nextToken )
{
proc_names_printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
_read_arg( NULL, NULL );
popStack(__stack - data -> stack );
do_input[instance.parenthesis_count] = do_std_next_arg;
do_breakdata = NULL;
return NULL;
}
char *cmdRead(struct nativeCommand *cmd, char *tokenBuffer )
{
proc_names_printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
printf("proc_stack_frame: %d\n",currentFrame -> dataPointer);
if (currentFrame -> dataPointer == 0x0000)
{
getLineFromPointer( tokenBuffer );
printf("setting error in %s at line %d\n",__FUNCTION__, lineFromPtr.line);
setError( 25, tokenBuffer);
}
else
{
do_input[instance.parenthesis_count] = _read_arg;
do_breakdata = NULL;
stackCmdNormal( _cmdRead, tokenBuffer );
}
return tokenBuffer;
}