pforth
0943e5e71114f286dbb2474d55aabf91df02d104
Main Page
Data Structures
Files
File List
Globals
pforth.h
Go to the documentation of this file.
1
#pragma once
2
#include <stdint.h>
3
#include <stdlib.h>
4
#include <errno.h>
5
#include <string.h>
6
#include <stdio.h>
7
8
9
#ifdef DEBUG
10
#define DBG(fmt, ...) fprintf(stderr, "%s:%d: " fmt, __FILE__, __LINE__, __VA_ARGS__);
11
#else
12
#define DBG(fmt, ...) {}
13
#endif
14
15
#define PRINT(fmt, ...) fprintf(stdout, fmt, __VA_ARGS__);
16
17
#define LO(x) ((unsigned char) ((x) & 0xFF))
18
#define HI(x) ((unsigned char) (((x) >> 8) & 0xFF))
19
23
#define FORTH_DICT_SIZE 1000
24
28
#define MAX_DO_LOOP_DEPTH 3
29
33
#define MAX_BEGIN_LOOP_DEPTH 5
34
38
#define FORTH_TYPE int32_t
39
43
#define POINTER_TYPE void *
44
48
#define INT_TYPE_LIST FORTH_TYPE
49
53
typedef
void (*
word_function
)();
54
58
struct
_pforth_word
{
76
char
*
text_code
;
77
uint8_t
size
;
78
union
{
79
void
*
location
;
80
word_function
function
;
81
};
82
};
83
84
typedef
struct
_pforth_word
pforth_word
;
85
typedef
pforth_word
*
pforth_word_ptr
;
86
87
#define WORD_IS_VARIABLE (w) (w.text_code[0] == 0x01)
88
#define WORD_IS_CONSTANT (w) (w.text_code[1] & 0x01)
89
#define WORD_IS_ARRAY (w) (w.text_code[1] & 0x02)
90
91
extern
uint8_t*
data_stack_top
;
92
extern
void
*
return_stack_top
;
93
uint8_t*
data_stack_bottom
();
94
uint8_t*
return_stack_bottom
();
95
96
struct
_dict_entry
{
97
char
*
key
;
98
pforth_word_ptr
word
;
99
struct
_dict_entry
*
next
;
100
};
101
102
typedef
struct
_dict_entry
dict_entry
;
103
104
struct
dict_s
{
105
int
size
;
106
struct
_dict_entry
**
table
;
107
};
108
109
typedef
struct
dict_s
dict_t
;
110
111
dict_t
*
dict_create
(uint32_t
size
);
112
void
dict_free
(
dict_t
* dict, uint32_t
size
);
113
pforth_word_ptr
dict_set
(
dict_t
* dict,
const
char
* key,
const
pforth_word_ptr
value);
114
pforth_word_ptr
dict_get
(
dict_t
* dict,
const
char
* key);
115
119
extern
dict_t
*
forth_dict
;
120
126
void
pforth_init
();
127
133
void
pforth_deinit
();
134
145
pforth_word_ptr
pforth_word_copy
(
const
pforth_word_ptr
dest,
const
pforth_word_ptr
src);
146
156
pforth_word_ptr
pforth_word_dup
(
const
pforth_word_ptr
src);
157
164
pforth_word_ptr
pforth_word_alloc
();
165
171
void
pforth_word_free
(
const
pforth_word_ptr
word);
172
176
#define PFORTH_WORD_RUN(w) { word_function f = *(word->function); f(); }
177
187
int
preprocess
(
char
* line);
188
197
void
eval
(
dict_t
* dict,
const
char
* line,
const
char
* line_end);
198
205
void
register_native
(
const
char
* op,
word_function
f);
206
210
void
dump_stack
();
211
212
#include "
words.h
"
forth_dict
dict_t * forth_dict
Definition:
pforth.c:6
eval
void eval(dict_t *dict, const char *line, const char *line_end)
Definition:
interp.c:67
_dict_entry::word
pforth_word_ptr word
Definition:
pforth.h:98
dict_get
pforth_word_ptr dict_get(dict_t *dict, const char *key)
Definition:
dict.c:171
dump_stack
void dump_stack()
Definition:
pforth.c:72
register_native
void register_native(const char *op, word_function f)
Definition:
pforth.c:80
dict_set
pforth_word_ptr dict_set(dict_t *dict, const char *key, const pforth_word_ptr value)
Definition:
dict.c:123
return_stack_top
void * return_stack_top
Definition:
pforth.c:5
pforth_word_dup
pforth_word_ptr pforth_word_dup(const pforth_word_ptr src)
words.h
preprocess
int preprocess(char *line)
Definition:
interp.c:16
_pforth_word::location
void * location
Definition:
pforth.h:79
pforth_deinit
void pforth_deinit()
Definition:
pforth.c:39
dict_free
void dict_free(dict_t *dict, uint32_t size)
Definition:
dict.c:39
dict_s::size
int size
Definition:
pforth.h:105
dict_s::table
struct _dict_entry ** table
Definition:
pforth.h:106
_pforth_word::size
uint8_t size
Definition:
pforth.h:77
data_stack_top
uint8_t * data_stack_top
Definition:
pforth.c:4
return_stack_bottom
uint8_t * return_stack_bottom()
Definition:
pforth.c:12
_pforth_word::text_code
char * text_code
Definition:
pforth.h:76
_dict_entry
Definition:
pforth.h:96
_dict_entry::key
char * key
Definition:
pforth.h:97
pforth_word_ptr
pforth_word * pforth_word_ptr
Definition:
pforth.h:85
data_stack_bottom
uint8_t * data_stack_bottom()
Definition:
pforth.c:9
pforth_word_alloc
pforth_word_ptr pforth_word_alloc()
Definition:
pforth.c:15
dict_create
dict_t * dict_create(uint32_t size)
Definition:
dict.c:13
word_function
void(* word_function)()
Definition:
pforth.h:53
_pforth_word
Definition:
pforth.h:58
dict_s
Definition:
pforth.h:104
_dict_entry::next
struct _dict_entry * next
Definition:
pforth.h:99
pforth_word_free
void pforth_word_free(const pforth_word_ptr word)
Definition:
pforth.c:23
pforth_word_copy
pforth_word_ptr pforth_word_copy(const pforth_word_ptr dest, const pforth_word_ptr src)
Definition:
pforth.c:46
pforth_init
void pforth_init()
Definition:
pforth.c:30
src
pforth.h
Generated on Wed Oct 12 2016 15:27:19 for pforth by
1.8.11