-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotc.c
51 lines (39 loc) · 1.14 KB
/
notc.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
/* notc.c - a simple interpreter for a c-like language
*
* Copyright (c) 2014 by David Michael Betz. All rights reserved.
*
*/
#include <stdio.h>
#include "db_compiler.h"
#include "db_image.h"
#include "db_vm.h"
static uint8_t space[HEAPSIZE];
static int TermGetLine(void *cookie, char *buf, int len, VMVALUE *pLineNumber);
int main(int argc, char *argv[])
{
VMVALUE lineNumber = 0;
ImageHdr *image;
VMVALUE code;
System *sys;
VM_sysinit(argc, argv);
VM_printf("notc 0.001\n");
sys = InitSystem(space, sizeof(space));
sys->getLine = TermGetLine;
sys->getLineCookie = &lineNumber;
if (!(image = AllocateImage(sys, IMAGESIZE)))
return 1;
sys->freeMark = sys->freeNext;
for (;;) {
if ((code = Compile(sys, image)) != 0) {
sys->freeNext = sys->freeMark;
Execute(sys, image, code);
}
}
return 0;
}
static int TermGetLine(void *cookie, char *buf, int len, VMVALUE *pLineNumber)
{
VMVALUE *pLine = (VMVALUE *)cookie;
*pLineNumber = ++(*pLine);
return VM_getline(buf, len) != NULL;
}