use one buffer for both compiled code and data
This commit is contained in:
+3
-1
@@ -12,9 +12,11 @@
|
||||
#define RETURN_STACK_DEPTH 1024
|
||||
#define MAX_NAME_LEN 32
|
||||
#define DICT_SIZE 1024
|
||||
#define COMPILED_BUFFER_SIZE (1024*1024)
|
||||
#define HEAP_SIZE (1024*1024)
|
||||
#define MAXLINE 65535
|
||||
#define PAD_SIZE 256
|
||||
#define WORDBUF_SIZE 128
|
||||
#define INPUT_BUFFER_SIZE 256
|
||||
|
||||
#define CELL 4
|
||||
|
||||
|
||||
+12
-8
@@ -24,14 +24,18 @@ enum fh_error fh_heap_reserve(
|
||||
);
|
||||
void fh_heap_write(struct fh_thread_s *fh, uint32_t addr, const void *src, uint32_t len);
|
||||
enum fh_error fh_heap_put(struct fh_thread_s *fh, const void *src, uint32_t len);
|
||||
void fh_heap_copy_from_compile(struct fh_thread_s *fh, uint32_t addr, uint32_t srcaddr, uint32_t len);
|
||||
void fh_heap_copy(struct fh_thread_s *fh, uint32_t addr, uint32_t srcaddr, uint32_t len);
|
||||
|
||||
enum fh_error fh_compile_reserve(
|
||||
struct fh_thread_s *fh,
|
||||
size_t len,
|
||||
uint32_t *addr
|
||||
);
|
||||
void fh_compile_write(struct fh_thread_s *fh, uint32_t addr, const void *src, uint32_t len);
|
||||
enum fh_error fh_compile_put(struct fh_thread_s *fh, const void *src, uint32_t len);
|
||||
static inline char *fh_str_at(struct fh_thread_s *fh, uint32_t addr) {
|
||||
return (char *) &fh->heap[addr];
|
||||
}
|
||||
|
||||
static inline struct fh_instruction_s *fh_instr_at(struct fh_thread_s *fh, uint32_t addr) {
|
||||
return (void *) &fh->heap[addr];
|
||||
}
|
||||
|
||||
static inline struct fh_word_s *fh_word_at(struct fh_thread_s *fh, uint32_t addr) {
|
||||
return (struct fh_word_s *) &fh->heap[addr];
|
||||
}
|
||||
|
||||
#endif //FORTH_FH_MEM_H
|
||||
|
||||
+12
-7
@@ -108,8 +108,7 @@ struct fh_word_s {
|
||||
word_exec_t handler;
|
||||
/** Indicates that this is a built-in instruction and not a word call */
|
||||
bool builtin;
|
||||
/** Indicates that this instruction should always be treated as interpreted,
|
||||
* in practice this is only used for `;` */
|
||||
/** Indicates that this instruction should always be treated as interpreted */
|
||||
bool immediate;
|
||||
/** Start address in case of user words, or param for builtins */
|
||||
union {
|
||||
@@ -140,13 +139,10 @@ struct fh_thread_s {
|
||||
size_t return_stack_top;
|
||||
size_t return_stack_hwm;
|
||||
|
||||
/** Data heap */
|
||||
/** Data buffer used for everything */
|
||||
uint8_t heap[HEAP_SIZE];
|
||||
size_t heap_top; // aka "HERE"
|
||||
size_t here;
|
||||
|
||||
/** Compile buffer, used for both word data and literals */
|
||||
uint8_t compile[COMPILED_BUFFER_SIZE];
|
||||
size_t compile_top;
|
||||
/** Pointer into the compile buffer for execution */
|
||||
uint32_t execptr;
|
||||
|
||||
@@ -154,6 +150,15 @@ struct fh_thread_s {
|
||||
struct fh_word_s dict[DICT_SIZE];
|
||||
uint32_t dict_top;
|
||||
|
||||
/** Pad buffer */
|
||||
uint8_t pad[PAD_SIZE];
|
||||
/** WORD and pictured output buffer */
|
||||
uint8_t wordbuf[WORDBUF_SIZE];
|
||||
|
||||
/** Input buffer */
|
||||
uint8_t inbuf[INPUT_BUFFER_SIZE];
|
||||
uint32_t inbuf_ptr;
|
||||
|
||||
/** Forth state */
|
||||
enum fh_state state;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user