From cac651cd88f8da1e5957b0cc13fa25d79e1887fc Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 23 Aug 2016 20:58:50 +0200 Subject: Many things - two-letter AST union members - AST_QUOTED - AST_LAMBDA - an interpreter that works - function registering in the interpreter - some builtins --- ast.h | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'ast.h') diff --git a/ast.h b/ast.h index 8d23ef9..6ec6ce8 100644 --- a/ast.h +++ b/ast.h @@ -2,24 +2,40 @@ #include +typedef struct InterState InterState; +typedef struct InterRet InterRet; +typedef struct AST AST; + +typedef InterRet (*lambdafunc_t)(InterState *is,int nargs,AST **args); + typedef enum ASTtype{ AST_LIST, + AST_LAMBDA, + AST_LAMBDAARG, AST_WORD, AST_NUMBER, AST_STRING, AST_SYMBOL, + AST_QUOTED, } ASTtype; -typedef struct AST AST; - typedef struct ASTlist{ int len; AST **nodes; - bool quoted; } ASTlist; +typedef struct ASTlambda{ + //exactly one is non-NULL + lambdafunc_t cfunc; + AST *body; +} ASTlambda; + +typedef struct ASTlambdaArg{ + int idx; +} ASTlambdaArg; + typedef struct ASTword{ char *word; } ASTword; @@ -42,14 +58,21 @@ typedef struct ASTsymbol{ //You should probably use ast_symbol(), in which case you don't have to do anything. } ASTsymbol; +typedef struct ASTquoted{ + AST *ast; +} ASTquoted; + struct AST{ ASTtype type; union { - ASTlist l; - ASTword w; - ASTnumber n; - ASTstring S; - ASTsymbol s; + ASTlist li; + ASTlambda la; + ASTlambdaArg ar; + ASTword wo; + ASTnumber nu; + ASTstring st; + ASTsymbol sy; + ASTquoted qu; }; }; @@ -61,7 +84,9 @@ AST* ast_copy(const AST *ast); char* ast_stringify(const AST *ast); AST* ast_list(int len,AST **nodes); //these convenience functions DO NOT copy their arguments +AST* ast_lambda(lambdafunc_t cfunc,AST *body); AST* ast_word(char *word); AST* ast_number(double num); AST* ast_string(char *str,int len); AST* ast_symbol(char *name); +AST* ast_quoted(AST *ast); -- cgit v1.2.3-54-g00ecf