From e0fcdc6e3577f8c40b019396b400928379d928b9 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 2 Jun 2023 22:04:36 -0400 Subject: feat: runtime defined words are compiled; --- forthmachine.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'forthmachine.h') diff --git a/forthmachine.h b/forthmachine.h index 8854eac..50eb4d8 100644 --- a/forthmachine.h +++ b/forthmachine.h @@ -20,31 +20,33 @@ typedef void (*directiveop)(forthmachine* fm, int len, char* line, int* i); extern char* outputbuffer; extern int outputline; +typedef enum { + compileditem_stackop = 0, + compileditem_literal = 1, + compileditem_ifcontrol = 2, +} compileditem_type; + typedef struct { - bool isliteral; + compileditem_type type; union { wordop* wordop; stackitem literal; + struct { + int jumpto; + }; }; } compileditem; typedef enum { - directive = 0, - builtin = 1, - script = 2, - compiled = 3, + builtin = 0, + compiled = 1, } optype; struct wordop { char* word; optype optype; union { - directiveop directive; stackop op; - struct { - char* script; - int scriptlen; - }; struct { compileditem* oplist; int oplistlen; @@ -63,6 +65,8 @@ struct optable { */ wordop* optable_getop(optable* optable, char *word); +void defineop(forthmachine* fm, char *input, int* starti); + optable* optable_new(); struct forthmachine { -- cgit v1.2.3