Skip to content

Commit

Permalink
update variables.h
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarorichard committed Jun 14, 2024
1 parent a13146d commit ce8e0df
Showing 1 changed file with 122 additions and 27 deletions.
149 changes: 122 additions & 27 deletions include/variables.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,111 @@
// #ifndef VARIABLES_H
// #define VARIABLES_H

// /* Include necessary headers */
// #include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <stdarg.h>
// #include <editline/readline.h>
// #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

Expand All @@ -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, ...);
Expand All @@ -56,7 +156,6 @@ void lval_println(lval* v);
char* ltype_name(int t);

/* Lisp Environment */

struct lenv {
int count;
char** syms;
Expand All @@ -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; }

Expand All @@ -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 */

0 comments on commit ce8e0df

Please # to comment.