-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquattro_istruzioni_repl.c
66 lines (49 loc) · 1.22 KB
/
quattro_istruzioni_repl.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
#include "quattro_istruzioni_repl.h"
static int readCommandLine(char *buffer, int maxSize) {
int i = 0;
int realMax = maxSize-1;
while(1) {
if(i>realMax) {
break;
}
buffer[i]=fgetc(stdin);
if(buffer[i]==EOF) {
return 0;
}
if(buffer[i]==13 || buffer[i]==10) {
break;
}
i++;
}
buffer[i]='\x0';
return 1;
}
void Instruction_Repl(ForthVm *vm)
{
char maxLine[1024];
ForthStream *fstr;
printf("%s\n", LEOFORTH_VERSION);
printf("Code Space: %i\n", vm->hereCodePtr);
printf("Data Space: %i\n", vm->hereDataPtr);
printf("----\n\n");
fstr = ForthStream_NewForBuffer("<line>", "");
ForthVm_SetParser(vm, fstr);
printf("\n\n");
while(TRUE) {
if(vm->internalState == VM_COMPILER) {
printf("(compiler) ");
}
printf("4> ");
fflush(stdout);
memset(maxLine, 0, 1024);
if(!readCommandLine(maxLine, 1024)) {
break;
}
ForthStream_ResetForBuffer(fstr, "<line>", maxLine);
vm->exitFlag=0;
ForthVm_Feed(vm);
ForthVm_Output(vm, " ok\n");
fflush(stdout);
}
ForthStream_Delete(fstr);
}