From ce8e0df49ba6ac9f00547912136910577ea11492 Mon Sep 17 00:00:00 2001 From: alvarorichard Date: Thu, 13 Jun 2024 22:28:44 -0300 Subject: [PATCH] update variables.h --- include/variables.h | 149 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 27 deletions(-) diff --git a/include/variables.h b/include/variables.h index 2e094ad..86a96c1 100644 --- a/include/variables.h +++ b/include/variables.h @@ -1,3 +1,111 @@ +// #ifndef VARIABLES_H +// #define VARIABLES_H + +// /* Include necessary headers */ +// #include +// #include +// #include +// #include +// #include +// #include "../include/mpc.h" + +// /* Forward Declarations */ + +// struct lval; +// struct lenv; +// typedef struct lval lval; +// typedef struct lenv lenv; + +// /* Lisp Value */ + +// // enum { LVAL_ERR, LVAL_NUM, LVAL_SYM, +// // LVAL_FUN, LVAL_SEXPR, LVAL_QEXPR } + +// // typedef lval*(*lbuiltin)(lenv*, lval*); + +// // enum { LVAL_ERR, LVAL_NUM, LVAL_SYM, +// // LVAL_FUN, LVAL_SEXPR, LVAL_QEXPR }; // Added semicolon here + +// //typedef lval*(*lbuiltin)(lenv*, lval*); + + +// // struct lval { +// // int type; +// // long num; +// // char* err; +// // char* sym; +// // lbuiltin fun; +// // int count; +// // lval** cell; +// // }; + +// lval* lval_num(long x); +// lval* lval_err(char* fmt, ...); +// lval* lval_sym(char* s); +// lval* lval_fun(lbuiltin func); +// lval* lval_sexpr(void); +// lval* lval_qexpr(void); +// void lval_del(lval* v); +// lval* lval_copy(lval* v); +// lval* lval_add(lval* v, lval* x); +// lval* lval_join(lval* x, lval* y); +// lval* lval_pop(lval* v, int i); +// lval* lval_take(lval* v, int i); +// void lval_print(lval* v); +// void lval_println(lval* v); +// char* ltype_name(int t); + +// /* Lisp Environment */ + +// struct lenv { +// int count; +// char** syms; +// lval** vals; +// }; + +// lenv* lenv_new(void); +// void lenv_del(lenv* e); +// lval* lenv_get(lenv* e, lval* k); +// void lenv_put(lenv* e, lval* k, lval* v); +// void lenv_add_builtin(lenv* e, char* name, lbuiltin func); +// void lenv_add_builtins(lenv* e); + +// /* Builtins */ + +// #define LASSERT(args, cond, fmt, ...) \ +// if (!(cond)) { lval* err = lval_err(fmt, ##__VA_ARGS__); lval_del(args); return err; } + +// #define LASSERT_TYPE(func, args, index, expect) \ +// LASSERT(args, args->cell[index]->type == expect, \ +// "Function '%s' passed incorrect type for argument %i. Got %s, Expected %s.", \ +// func, index, ltype_name(args->cell[index]->type), ltype_name(expect)) + +// #define LASSERT_NUM(func, args, num) \ +// LASSERT(args, args->count == num, \ +// "Function '%s' passed incorrect number of arguments. Got %i, Expected %i.", \ +// func, args->count, num) + +// #define LASSERT_NOT_EMPTY(func, args, index) \ +// LASSERT(args, args->cell[index]->count != 0, \ +// "Function '%s' passed {} for argument %i.", func, index); + +// /* Evaluation */ + +// lval* lval_eval(lenv* e, lval* v); +// lval* lval_eval_sexpr(lenv* e, lval* v); + +// /* Reading */ + +// lval* lval_read_num(mpc_ast_t* t); +// lval* lval_read(mpc_ast_t* t); + +// /* Main */ + +// int var(); + +// #endif /* VARIABLES_H */ + + #ifndef VARIABLES_H #define VARIABLES_H @@ -10,34 +118,26 @@ #include "../include/mpc.h" /* Forward Declarations */ - struct lval; struct lenv; typedef struct lval lval; typedef struct lenv lenv; -/* Lisp Value */ - -// enum { LVAL_ERR, LVAL_NUM, LVAL_SYM, -// LVAL_FUN, LVAL_SEXPR, LVAL_QEXPR } - -// typedef lval*(*lbuiltin)(lenv*, lval*); - -// enum { LVAL_ERR, LVAL_NUM, LVAL_SYM, -// LVAL_FUN, LVAL_SEXPR, LVAL_QEXPR }; // Added semicolon here +/* Define lbuiltin */ +typedef lval*(*lbuiltin)(lenv*, lval*); -//typedef lval*(*lbuiltin)(lenv*, lval*); - - -// struct lval { -// int type; -// long num; -// char* err; -// char* sym; -// lbuiltin fun; -// int count; -// lval** cell; -// }; +/* Lisp Value */ +enum { LVAL_ERR, LVAL_NUM, LVAL_SYM, LVAL_FUN, LVAL_SEXPR, LVAL_QEXPR }; + +struct lval { + int type; + long num; + char* err; + char* sym; + lbuiltin fun; + int count; + lval** cell; +}; lval* lval_num(long x); lval* lval_err(char* fmt, ...); @@ -56,7 +156,6 @@ void lval_println(lval* v); char* ltype_name(int t); /* Lisp Environment */ - struct lenv { int count; char** syms; @@ -71,7 +170,6 @@ void lenv_add_builtin(lenv* e, char* name, lbuiltin func); void lenv_add_builtins(lenv* e); /* Builtins */ - #define LASSERT(args, cond, fmt, ...) \ if (!(cond)) { lval* err = lval_err(fmt, ##__VA_ARGS__); lval_del(args); return err; } @@ -90,17 +188,14 @@ void lenv_add_builtins(lenv* e); "Function '%s' passed {} for argument %i.", func, index); /* Evaluation */ - lval* lval_eval(lenv* e, lval* v); lval* lval_eval_sexpr(lenv* e, lval* v); /* Reading */ - lval* lval_read_num(mpc_ast_t* t); lval* lval_read(mpc_ast_t* t); /* Main */ - int var(); #endif /* VARIABLES_H */