blob: fed187b7174280ef6f38e17792bcb0c0508d1c4f (
plain) (
blame)
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
|
#ifndef _ENCODING_H_
#define _ENCODING_H_
#include <stdbool.h>
#include <stdint.h>
#include "slice.h"
#include "value.h"
typedef uint8_t local;
#define NUM_LOCALS 8
// An arg can be a value or a constant.
struct arg {
local local;
value constant;
};
enum opcode {
OALLOC = 1,
OCALL = 2,
OPOKE = 3,
OPEEK = 4,
OSHUF = 5,
OEXIT = 6,
};
struct op {
enum opcode code;
union {
struct {
local out;
struct arg size;
} alloc;
struct {
uint8_t offset;
local pointer;
struct arg value;
} poke;
struct {
local out;
uint8_t offset;
struct arg value;
} peek;
struct {
local out;
struct arg value;
} shuf;
struct {
struct arg value;
} exit;
};
};
struct result {
struct op op;
int n;
};
struct result parse(struct slice);
#endif
|