-
Notifications
You must be signed in to change notification settings - Fork 0
/
sina_types.h
86 lines (69 loc) · 1.61 KB
/
sina_types.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef SINA_TYPES_H
#define SINA_TYPES_H
/*
* sina_types.h
*
* defines the types used by the sina interpreter. These are the basic
* building blocks of sina programs.
*
*/
#include <stddef.h>
#include "sina_error.h"
#define INTEGER_CHUNK 1
#define SYMBOL_CHUNK 2
#define ESCAPED_SYMBOL_CHUNK 3
#define LIST_NODE_CHUNK 4
#define LIST_HEAD_CHUNK 5
#define BLOCK_CHUNK 6
#define NATIVE_CHUNK 7
typedef char chunk_type;
typedef char chunk_colour; /* free vs. black, grey, white */
typedef struct {
volatile chunk_type type;
volatile chunk_colour colour;
} chunk_header;
typedef struct {
chunk_header header;
int value;
} integer_chunk;
typedef struct {
chunk_header header;
int symbol;
} symbol_chunk;
typedef struct {
chunk_header header;
int symbol;
} escaped_symbol_chunk;
typedef struct list_node_chunk {
chunk_header header;
chunk_header* data;
struct list_node_chunk* next;
} list_node_chunk;
typedef struct {
chunk_header header;
list_node_chunk* first;
list_node_chunk* last;
} list_head_chunk;
typedef struct {
chunk_header header;
list_head_chunk* code;
list_node_chunk* current;
} block_chunk;
/* maximum amount of symbols that can be bound */
#define SINAVM_MAX_SYMBOLS 1024
/* datastructure used by the interpreter for the vm
*/
typedef struct {
list_head_chunk* cs;
list_head_chunk* ds;
chunk_header** bindings;
unsigned int flags;
} sinavm_data;
typedef void (*native_func)(sinavm_data*);
typedef struct {
chunk_header header;
native_func func;
} native_chunk;
/* returns the size of a chunk */
size_t sizeof_chunk(int type);
#endif