-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bcode.c
More file actions
41 lines (38 loc) · 1014 Bytes
/
test_bcode.c
File metadata and controls
41 lines (38 loc) · 1014 Bytes
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
#include <stdio.h> // FILE{}, fgets()
#include "bcode.h"
FILE *Debug;
int
main()
{
char buffer[ 256 ];
byte_t bytes[ 256 ];
int i, ret;
Debug = stderr;
token_init();
while (fgets(buffer, 256, stdin) != NULL) {
if (*buffer == 0 || *buffer == '\n')
break;
fprintf(Debug, "===== %s", buffer);
token_source(buffer);
ret = bcode_compile(bytes);
if (ret < 0) {
ret = -ret;
fprintf(Debug, "***** Error: %s\n", bcode_result(ret));
break;
}
fprintf(Debug, ">>>>> Compiled bytecodes [ %d bytes ]\n", ret);
for (i = 0; i < ret; i++) {
if ((i % 16) == 0)
fprintf(Debug, " ");
fprintf(Debug, "%02X ", bytes[ i ]);
if ((i % 16) == 15)
fprintf(Debug, "\n");
}
if ((i % 16) != 15)
fprintf(Debug, "\n");
#ifdef DEBUG
bcode_dump(bytes);
#endif // DEBUG
}
return ret;
}