summaryrefslogtreecommitdiff
path: root/lib/aplwc_internal.h
blob: 44785edd2b6da6ce818ab2043092f708d584e869 (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
113
114
115
116
117
/* Aplwc - A Programming Language With Constraints
 *
 * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com>
 *
 * This file is part of aplwc.
 *
 * Aplwc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Aplwc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with aplwc.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef APLWC_INTERNAL_H
#define APLWC_INTERNAL_H

#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>

enum aplwc_token_tag {
	APLWC_TOKEN_SYSCMD,
	APLWC_TOKEN_SYSCMD_ARGS,
	
	APLWC_TOKEN_ERROR,
};

enum aplwc_ast_tag {
	APLWC_AST_SYSCMD,

	APLWC_AST_ERROR,
};

enum aplwc_instr_tag {
	APLWC_INSTR_SYSCMD_CALL,
	APLWC_INSTR_ERROR,
	APLWC_INSTR_END,
};

struct aplwc {
	void *(*alloc)(size_t);
	void (*free)(void *);
	void *(*realloc)(void *, size_t);
	
	struct aplwc_syscmd **syscmds;
	int n_syscmds;
        bool running;
};

struct aplwc_eval_context {
	struct aplwc *aplwc;
	char *text;
	size_t offset;
	size_t length;

	size_t n_tokens;
	struct aplwc_token **tokens;

	size_t token_offset;
	struct aplwc_ast *ast;

	struct aplwc_instrs *instrs;
};

struct aplwc_token {
	enum aplwc_token_tag tag;
	size_t offset_start;
	size_t offset_end;
	
	union {
	} data;
};

struct aplwc_ast {
	enum aplwc_ast_tag tag;

	union {
		struct {
			struct aplwc_syscmd *syscmd;
			char *args;
		} syscmd;
	} data;
};

struct aplwc_instrs {
	size_t n_instrs;
	uint64_t *instrs;
};

struct aplwc_instr {
	int type;
	enum aplwc_instr_tag op;
	
	uint64_t encoded;
};
struct aplwc_syscmd *aplwc_lookup_syscmd(struct aplwc *, const char *);
struct aplwc_eval_context *aplwc_new_eval_context(struct aplwc *);
void aplwc_scan_line(struct aplwc_eval_context *, const char *);
void aplwc_parse(struct aplwc_eval_context *);
void aplwc_compile(struct aplwc_eval_context *);
void aplwc_eval(struct aplwc_eval_context *);
void aplwc_free_eval_context(struct aplwc_eval_context *);
void aplwc_free_ast(struct aplwc *, struct aplwc_ast *);
char *aplwc_strdup(struct aplwc *, const char *);
void aplwc_output(struct aplwc *, const char *, ...);
void aplwc_voutput(struct aplwc *, const char *, va_list);
void aplwc_encode_instr(struct aplwc_instr *);
void aplwc_decode_instr(struct aplwc_instr *);
	
#endif /* APLWC_INTERNAL_H */