forked from mandrookin/yaforth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaforth.h
100 lines (78 loc) · 2.15 KB
/
yaforth.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
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef _EAFORTH_H_
#define _EAFORTH_H_
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <string>
#include <stack>
#include <map>
#include <list>
#include <vector>
#include <stdint.h>
#include <malloc.h>
#include "memory.h"
typedef enum {
builtin,
user,
constant,
variable
} word_type_t;
typedef enum {
neutral,
function_name,
variable_state,
constant_value,
print_string,
done,
error,
finish,
eol_comment,
forth_comment,
} state_t;
typedef struct word_record record_t;
typedef state_t(*code_ptr_t)();
typedef void (*genetator_t)(ram_memory*, record_t*); // struct word_record*);
struct word_record {
word_t INDEX;
word_t LOCAL_INDEX;
std::string NAME;
word_type_t TYPE;
union {
uint32_t ADDR;
uint32_t CONSTANT;
code_ptr_t BLTN;
};
int MIN_STACK;
genetator_t GENERATE;
};
typedef struct {
record_t function;
std::vector<record_t> code;
std::map<std::string, uint32_t> strings;
} function_t;
typedef std::vector<function_t> function_list_t;
void define_constant(record_t* co);
void define_global_variable(record_t* co);
void define_function(record_t* co);
void register_code(record_t* co);
bool is_compile_mode();
int get_stack_size();
bool try_register_local_string(std::string& name, uint32_t address);
const char* find_variable_by_address(word_t counter);
function_t* lookup_current_function(void);
bool reset_current_function();
function_list_t& get_program();
record_t* find_record(uint32_t h);
typedef std::map<uint32_t, record_t> registry_t;
state_t forth(const char* str);
typedef struct command_line_parameters options_t;
struct command_line_parameters {
bool ansi_colors = false;
bool no_stdin = false;
bool generate_assembler = false;
};
constexpr unsigned int hash(const char* s, int off = 0) {
return !s[off] ? 5381 : (hash(s, off + 1) * 33) ^ s[off];
}
#endif