remove some direct access to stack arrays
This commit is contained in:
+1
-3
@@ -7,14 +7,12 @@
|
||||
#ifndef FORTH_FH_CONFIG_H
|
||||
#define FORTH_FH_CONFIG_H
|
||||
|
||||
#define CONTROL_STACK_DEPTH 1024
|
||||
#define DATA_STACK_DEPTH 1024
|
||||
#define RETURN_STACK_DEPTH 1024
|
||||
#define MAX_NAME_LEN 32
|
||||
#define DICT_SIZE 1024
|
||||
#define HEAP_SIZE (1024*1024)
|
||||
#define MAXLINE 65535
|
||||
#define PAD_OFFSET 340
|
||||
#define PAD_OFFSET 340 // why? copied from somewhere
|
||||
#define WORDBUF_SIZE 128
|
||||
#define INPUT_BUFFER_SIZE 256
|
||||
|
||||
|
||||
+25
-19
@@ -538,18 +538,17 @@ static enum fh_error w_two_swap(struct fh_thread_s *fh, const struct fh_word_s *
|
||||
{
|
||||
(void) w;
|
||||
enum fh_error rv;
|
||||
if (fh->data_stack_top < 4) {
|
||||
LOG("DS two-swap UNDERFLOW");
|
||||
return FH_ERR_DS_UNDERFLOW;
|
||||
}
|
||||
|
||||
uint32_t n = fh->data_stack_top - 4;
|
||||
uint32_t a = fh->data_stack[n];
|
||||
uint32_t b = fh->data_stack[n + 1];
|
||||
fh->data_stack[n] = fh->data_stack[n + 2];
|
||||
fh->data_stack[n + 1] = fh->data_stack[n + 3];
|
||||
fh->data_stack[n + 2] = a;
|
||||
fh->data_stack[n + 3] = b;
|
||||
uint32_t a, b, c, d;
|
||||
TRY(ds_pop(fh, &a));
|
||||
TRY(ds_pop(fh, &b));
|
||||
TRY(ds_pop(fh, &c));
|
||||
TRY(ds_pop(fh, &d));
|
||||
|
||||
TRY(ds_push(fh, b));
|
||||
TRY(ds_push(fh, a));
|
||||
TRY(ds_push(fh, d));
|
||||
TRY(ds_push(fh, c));
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
@@ -719,14 +718,6 @@ static enum fh_error wp_putc(struct fh_thread_s *fh, const struct fh_word_s *w)
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
static enum fh_error w_space(struct fh_thread_s *fh, const struct fh_word_s *w)
|
||||
{
|
||||
(void) w;
|
||||
(void) fh;
|
||||
FHPRINT(" ");
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
static enum fh_error w_debug_dump(struct fh_thread_s *fh, const struct fh_word_s *w)
|
||||
{
|
||||
(void) w;
|
||||
@@ -996,6 +987,20 @@ static enum fh_error w_see(struct fh_thread_s *fh, const struct fh_word_s *w)
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
static enum fh_error w_pad(struct fh_thread_s *fh, const struct fh_word_s *w)
|
||||
{
|
||||
(void) w;
|
||||
enum fh_error rv;
|
||||
uint32_t addr = fh->here + PAD_OFFSET;
|
||||
if (addr + 84 >= HEAP_SIZE) {
|
||||
LOGE("Heap overflow, PAD is too small!");
|
||||
return FH_ERR_HEAP_FULL;
|
||||
}
|
||||
|
||||
TRY(ds_push(fh, addr));
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
static enum fh_error wp_const(struct fh_thread_s *fh, const struct fh_word_s *w)
|
||||
{
|
||||
enum fh_error rv;
|
||||
@@ -1177,6 +1182,7 @@ enum fh_error register_builtin_words(struct fh_thread_s *fh)
|
||||
{"hex", wp_setbase, 0, 16},
|
||||
{"base", wp_const, 0, MAGICADDR_BASE},
|
||||
{"here", wp_const, 0, MAGICADDR_HERE},
|
||||
{"pad", w_pad, 0, 0},
|
||||
{"false", wp_const, 0, 0},
|
||||
{"true", wp_const, 0, 0xFFFFFFFF},
|
||||
{"+", w_plus, 0, 0},
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "fh_stack.h"
|
||||
#include "fh_print.h"
|
||||
|
||||
// TODO stacks should grow down, not up!
|
||||
|
||||
enum fh_error ds_roll(struct fh_thread_s *fh, int n)
|
||||
{
|
||||
if (fh->data_stack_top <= n) {
|
||||
|
||||
Reference in New Issue
Block a user