X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fscript%2Fexpr.h;h=d3607579e382b6995a9a07c87aeb63b47eb945fd;hb=0f7df4bfd40f00df03d9333c74b9cfc3ce6e2f64;hp=bf77829988f25a85e9c57a9d86eab6cee3cc4f9e;hpb=04faffd9c7e0ac9fee69500e7143ae84fb2e22fb;p=nothing.git diff --git a/src/script/expr.h b/src/script/expr.h index bf778299..d3607579 100644 --- a/src/script/expr.h +++ b/src/script/expr.h @@ -1,11 +1,21 @@ #ifndef ATOM_H_ #define ATOM_H_ +#include #include +typedef struct Gc Gc; + struct Cons; struct Atom; +// TODO(#321): get rid of gc argument from expr macros (just assume that it's `gc` in the current scope) +#define NUMBER(G, X) atom_as_expr(create_number_atom(G, X)) +#define STRING(G, S) atom_as_expr(create_string_atom(G, S, NULL)) +#define SYMBOL(G, S) atom_as_expr(create_symbol_atom(G, S, NULL)) +#define CONS(G, CAR, CDR) cons_as_expr(create_cons(G, CAR, CDR)) +#define NIL(G) SYMBOL(G, "nil") + enum ExprType { EXPR_ATOM = 0, @@ -42,15 +52,16 @@ struct Atom enum AtomType type; union { - float num; // ATOM_NUMBER + // TODO(#330): Atom doesn't support floats + long int num; // ATOM_NUMBER char *sym; // ATOM_SYMBOL char *str; // ATOM_STRING }; }; -struct Atom *create_number_atom(float num); -struct Atom *create_string_atom(const char *str, const char *str_end); -struct Atom *create_symbol_atom(const char *sym, const char *sym_end); +struct Atom *create_number_atom(Gc *gc, long int num); +struct Atom *create_string_atom(Gc *gc, const char *str, const char *str_end); +struct Atom *create_symbol_atom(Gc *gc, const char *sym, const char *sym_end); void destroy_atom(struct Atom *atom); void print_atom_as_sexpr(struct Atom *atom); @@ -60,7 +71,7 @@ struct Cons struct Expr cdr; }; -struct Cons *create_cons(struct Expr car, struct Expr cdr); +struct Cons *create_cons(Gc *gc, struct Expr car, struct Expr cdr); void destroy_cons(struct Cons *cons); void print_cons_as_sexpr(struct Cons *cons);