control stack merged into data stack
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@
|
||||
#define DICT_SIZE 1024
|
||||
#define HEAP_SIZE (1024*1024)
|
||||
#define MAXLINE 65535
|
||||
#define PAD_SIZE 256
|
||||
#define PAD_OFFSET 340
|
||||
#define WORDBUF_SIZE 128
|
||||
#define INPUT_BUFFER_SIZE 256
|
||||
|
||||
|
||||
@@ -124,11 +124,6 @@ struct fh_word_s {
|
||||
* to a shared pointer if multi-threading and synchronization is added.
|
||||
*/
|
||||
struct fh_thread_s {
|
||||
/** Control stack */
|
||||
uint32_t control_stack[CONTROL_STACK_DEPTH];
|
||||
size_t control_stack_top;
|
||||
size_t control_stack_hwm;
|
||||
|
||||
/** Data stack */
|
||||
uint32_t data_stack[DATA_STACK_DEPTH];
|
||||
size_t data_stack_top;
|
||||
@@ -150,15 +145,6 @@ 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;
|
||||
|
||||
|
||||
+12
-6
@@ -9,12 +9,14 @@
|
||||
|
||||
enum fh_error ds_roll(struct fh_thread_s *fh, int n);
|
||||
|
||||
/** Peek n-th element of data stack */
|
||||
/** Peek n-th element of data stack, 0=topmost */
|
||||
enum fh_error ds_peek_n(struct fh_thread_s *fh, uint32_t *out, int n);
|
||||
/** Peek n-th element of return stack */
|
||||
/** Peek n-th element of return stack, 0=topmost */
|
||||
enum fh_error rs_peek_n(struct fh_thread_s *fh, uint32_t *out, int n);
|
||||
/** Peek n-th element of control stack */
|
||||
enum fh_error cs_peek_n(struct fh_thread_s *fh, uint32_t *out, int n);
|
||||
/** Peek n-th element of control stack, 0=topmost */
|
||||
static inline enum fh_error cs_peek_n(struct fh_thread_s *fh, uint32_t *out, int n) {
|
||||
return ds_peek_n(fh, out, n);
|
||||
}
|
||||
|
||||
/** Peek top of data stack */
|
||||
static inline enum fh_error ds_peek(struct fh_thread_s *fh, uint32_t *out)
|
||||
@@ -36,10 +38,14 @@ static inline enum fh_error cs_peek(struct fh_thread_s *fh, uint32_t *out)
|
||||
|
||||
enum fh_error ds_pop(struct fh_thread_s *fh, uint32_t *out);
|
||||
enum fh_error rs_pop(struct fh_thread_s *fh, uint32_t *out);
|
||||
enum fh_error cs_pop(struct fh_thread_s *fh, uint32_t *out);
|
||||
static inline enum fh_error cs_pop(struct fh_thread_s *fh, uint32_t *out) {
|
||||
return ds_pop(fh, out);
|
||||
}
|
||||
|
||||
enum fh_error ds_push(struct fh_thread_s *fh, uint32_t in);
|
||||
enum fh_error rs_push(struct fh_thread_s *fh, uint32_t in);
|
||||
enum fh_error cs_push(struct fh_thread_s *fh, uint32_t in);
|
||||
static inline enum fh_error cs_push(struct fh_thread_s *fh, uint32_t in) {
|
||||
return ds_push(fh, in);
|
||||
}
|
||||
|
||||
#endif //FORTH_FH_STACK_H
|
||||
|
||||
@@ -42,17 +42,6 @@ enum fh_error rs_peek_n(struct fh_thread_s *fh, uint32_t *out, int n)
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
/** Peek top of control stack */
|
||||
enum fh_error cs_peek_n(struct fh_thread_s *fh, uint32_t *out, int n)
|
||||
{
|
||||
if (fh->control_stack_top <= n) {
|
||||
LOG("CS peek_n UNDERFLOW");
|
||||
return FH_ERR_CS_UNDERFLOW;
|
||||
}
|
||||
*out = fh->control_stack[fh->control_stack_top - 1 - n];
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
/** Pop from data stack */
|
||||
enum fh_error ds_pop(struct fh_thread_s *fh, uint32_t *out)
|
||||
{
|
||||
@@ -77,18 +66,6 @@ enum fh_error rs_pop(struct fh_thread_s *fh, uint32_t *out)
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
/** Pop from control stack */
|
||||
enum fh_error cs_pop(struct fh_thread_s *fh, uint32_t *out)
|
||||
{
|
||||
if (fh->control_stack_top == 0) {
|
||||
LOG("CS pop UNDERFLOW");
|
||||
return FH_ERR_CS_UNDERFLOW;
|
||||
}
|
||||
*out = fh->control_stack[--fh->control_stack_top];
|
||||
LOG("CS pop %d", *out);
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
#define UPDATE_HWM(hwm, top) \
|
||||
do { \
|
||||
if((hwm) < (top)) { \
|
||||
@@ -119,15 +96,3 @@ enum fh_error rs_push(struct fh_thread_s *fh, uint32_t in)
|
||||
UPDATE_HWM(fh->return_stack_hwm, fh->return_stack_top);
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
/** Push to control stack */
|
||||
enum fh_error cs_push(struct fh_thread_s *fh, uint32_t in)
|
||||
{
|
||||
LOG("CS push %d", in);
|
||||
if (fh->control_stack_top == CONTROL_STACK_DEPTH) {
|
||||
return FH_ERR_CS_OVERFLOW;
|
||||
}
|
||||
fh->control_stack[fh->control_stack_top++] = in;
|
||||
UPDATE_HWM(fh->control_stack_hwm, fh->control_stack_top);
|
||||
return FH_OK;
|
||||
}
|
||||
|
||||
+2
-2
@@ -84,8 +84,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Show resource usage
|
||||
LOG("\nResources used: DS %dW, RS %dW, CS %dW, memory %dB\n",
|
||||
(int) fh.data_stack_hwm, (int) fh.return_stack_hwm, (int) fh.control_stack_hwm,
|
||||
LOG("\nResources used: DS %dW, RS %dW, memory %dB\n",
|
||||
(int) fh.data_stack_hwm, (int) fh.return_stack_hwm,
|
||||
(int) fh.here);
|
||||
|
||||
FHPRINT_SVC("Bye.\n");
|
||||
|
||||
Reference in New Issue
Block a user