summaryrefslogtreecommitdiff
path: root/src/lib/aplwc_internal.h
blob: 2e3e274560c5245f450d3121391a9bb65f3d3e8b (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef APLWC_INTERNAL_H
#define APLWC_INTERNAL_H

#include <aplwc.h>
#include <aplwc_macros.h>
#include <assert.h>
#include <stdalign.h>
#include <stdbool.h>
#include <string.h>

struct aplwc {
	enum aplwc_rc last_error;
	struct aplwc_module *modules;

	/* Memory management */
	uint8_t *data;
	size_t size;
	size_t offset;
};

struct aplwc_line {
	struct aplwc *aplwc;
	struct string *text;
	struct token_list *tokens;
};

struct string {
	size_t bytes;
	size_t chars;
	uint8_t utf8[1];
};

enum token_tag {
	TOKEN_TAG_IDENTIFIER,
	TOKEN_TAG_NEWLINE,
	TOKEN_TAG_NUMBER,
	TOKEN_TAG_LEFT_ARROW,
	TOKEN_TAG_DIAMOND,
	TOKEN_TAG_KEYWORD,
	TOKEN_TAG_TEXT,
	TOKEN_TAG_DEL,
	TOKEN_TAG_LEFT_PAREN,
	TOKEN_TAG_RIGHT_PAREN,
	TOKEN_TAG_IBEAM,
	TOKEN_TAG_QUAD,
	TOKEN_TAG_UNKNOWN_SYM
};

struct token {
	enum token_tag tag;
	size_t start;
	size_t end;
};

struct token_list {
	struct string *text;
	size_t length;
	struct token tokens[1];
};

enum value_tag {
	VALUE_NULL,
	VALUE_NUMBER
};

struct aplwc_value {
	struct aplwc *aplwc;
	enum value_tag tag;
};

struct aplwc_module {
	struct aplwc *aplwc;
	struct string *name;
	struct token_list *tokens;
	struct aplwc_module *link;
};

/* eval.c */
struct aplwc_value *eval_line(struct aplwc_line *);

/* memory.c */
void memory_init(struct aplwc *, uint8_t *, size_t);
struct aplwc *memory_alloc_aplwc(struct aplwc *);
struct aplwc_line *memory_alloc_aplwc_line(struct aplwc *);
struct string *memory_alloc_string(struct aplwc *, size_t);
struct token_list *memory_alloc_token_list(struct aplwc *, size_t);
struct aplwc_value *memory_alloc_aplwc_value(struct aplwc *);
struct aplwc_module *memory_alloc_aplwc_module(struct aplwc *);
struct module_imports *memory_alloc_module_imports(struct aplwc *, size_t);
void memory_free_aplwc(struct aplwc *, struct aplwc *);
void memory_free_aplwc_line(struct aplwc *, struct aplwc_line *);
void memory_free_string(struct aplwc *, struct string *);
void memory_free_token_list(struct aplwc *, struct token_list *);
void memory_free_aplwc_value(struct aplwc *, struct aplwc_value *);
void memory_free_aplwc_module(struct aplwc *, struct aplwc_module *);

/* string.c */
struct string *chars_to_string(struct aplwc *, const char *, int len);
uint32_t string_char(struct string *, size_t);
size_t char_length(struct string *, size_t);
int string_compare(struct string *, struct string *);

/* syntax.c */
struct token_list *scan_string(struct aplwc *, struct string *, int);
enum aplwc_rc check_tokens(struct token_list *);

/* module.c */
enum aplwc_rc load_module(struct aplwc *, struct string *, struct token_list *);
struct aplwc_module *module_lookup(struct aplwc *, struct string *);
struct string *module_imports_syms(struct module_imports *);

#endif /* APLWC_INTERNAL_H */