#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "words.h"
Go to the source code of this file.
| #define DBG |
( |
|
fmt, |
|
|
|
... |
|
) |
| {} |
| #define FORTH_DICT_SIZE 1000 |
| #define FORTH_TYPE int32_t |
Default data stack type definition
| #define HI |
( |
|
x | ) |
((unsigned char) (((x) >> 8) & 0xFF)) |
Comma separated list of types to generate math operations for
| #define LO |
( |
|
x | ) |
((unsigned char) ((x) & 0xFF)) |
| #define MAX_BEGIN_LOOP_DEPTH 5 |
Maximal BEGIN loop nesting depth
| #define MAX_DO_LOOP_DEPTH 3 |
Maximal DO loop nesting depth
| #define PFORTH_WORD_RUN |
( |
|
w | ) |
{ word_function f = *(word->function); f(); } |
| #define POINTER_TYPE void * |
| #define PRINT |
( |
|
fmt, |
|
|
|
... |
|
) |
| fprintf(stdout, fmt, __VA_ARGS__); |
| #define WORD_IS_ARRAY (w) (w.text_code[1] & 0x02) |
| #define WORD_IS_CONSTANT (w) (w.text_code[1] & 0x01) |
| #define WORD_IS_VARIABLE (w) (w.text_code[0] == 0x01) |
| typedef void(* word_function) () |
Type of function to be called from the word.
| uint8_t* data_stack_bottom |
( |
| ) |
|
| dict_t* dict_create |
( |
uint32_t |
size | ) |
|
Create a new hash table dictionary.
- Parameters
-
- Returns
- pointer to created dictionary
| void dict_free |
( |
dict_t * |
dict, |
|
|
uint32_t |
size |
|
) |
| |
Retrieve the word from the dictionary.
- Parameters
-
| dict | dictionary to use |
| key | FORTH word in ASCII form |
- Returns
- pointer to word inside the dictionary. Do not harm it.
Insert word into dictionary.
The word will be copied into the dictionary. The value must be freed in caller afterwards.
- Parameters
-
| dict | dictionary to use |
| key | FORTH word in ASCII form |
| value | pointer to pforth_word struct with the word. |
- Returns
- pointer to the newly created word
Debug printer for the whole data stack
| void eval |
( |
dict_t * |
dict, |
|
|
const char * |
line, |
|
|
const char * |
line_end |
|
) |
| |
Evaluate the FORTH line
- Parameters
-
| dict | the dictionary to use |
| line | the FORTH line |
| line_end | the last byte to interpret, if NULL then function evaluates ASCIIZ line |
Free the FORTH machine internal structures.
Deallocate stacks, remove dictionary.
Init the FORTH machine.
Allocate stacks, create dictionary.
Allocate memory for new word
- Returns
- pointer to new word
-
NULL if not enough memory
Copy the word from src to dest
The dest must be allocated beforehand.
- Parameters
-
| src | source word |
| dest | destination buffer |
- Returns
- pointer to the buffer (equal to
dest)
-
NULL if not enough memory
Create a duplicate of the word src
The memory is allocated inside and must be freed in caller
- Parameters
-
- Returns
- pointer to new word
-
NULL if not enough memory
Free the word structure
- Parameters
-
| int preprocess |
( |
char * |
line | ) |
|
Preprocess the FORTH line.
The preprocessing is done in-place, comments and newlines are removed by replacing with space characters. There's no space compression pass - it's easier to do that right in eval().
- Parameters
-
| line | the line to be preprocessed. |
Register native (compile-time) word
- Parameters
-
| op | The FORTH word to add |
| f | Function to call |
| uint8_t* return_stack_bottom |
( |
| ) |
|
The global data stack top pointer for the FORTH machine
Storage for the FORTH words