summaryrefslogtreecommitdiff
path: root/vm.h
blob: 4af630031038ddaf1903801291641da112d75167 (plain)
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
#ifndef _vm_h
#define _vm_h

#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>

typedef struct _thread Thread;

#include "val.h"
#include "com.h"

typedef struct {
	size_t ip;
	Chunk *ch;
	size_t fp;
} StackFrame;

#define MAXDEPTH  64
#define STACKSIZE 256*MAXDEPTH
typedef struct _thread {
	Chunk *ch;
	size_t ip;
	Val stack[STACKSIZE];
	size_t fp;
	size_t sp;
	StackFrame rstack[MAXDEPTH];
	size_t rsp;
} Thread;
Thread thread_new(State *S);

typedef enum {
	OP_RET,
	OP_LOADK,

	OP_ADD,
	OP_SUB,
	OP_MUL,
	OP_DIV,
	OP_MOD,

	OP_EQU,
	OP_CMP,

	OP_HALT,

	OP_DROP,

	OP_GETGLOBAL,
	OP_SETGLOBAL,

	OP_GETLOCAL,
	OP_SETLOCAL,

	OP_TRUE,
	OP_FALSE,
	OP_NIL,

	OP_0BRANCH,
	OP_SKIP,
	OP_REDO,

	OP_CALL,
	OP_ENDSCOPE,
} Op;

int runvm(State *S);

#endif