7 #include "script/expr.h"
9 struct Expr atom_as_expr(struct Atom *atom)
19 struct Expr cons_as_expr(struct Cons *cons)
29 void destroy_expr(struct Expr expr)
33 destroy_atom(expr.atom);
37 destroy_cons(expr.cons);
42 struct Cons *create_cons(struct Expr car, struct Expr cdr)
44 struct Cons *cons = malloc(sizeof(struct Cons));
55 void destroy_cons(struct Cons *cons)
57 destroy_expr(cons->car);
58 destroy_expr(cons->cdr);
62 struct Atom *create_atom(enum AtomType type, ...)
64 struct Atom *atom = malloc(sizeof(struct Atom));
75 const char *arg_str = va_arg(args, const char *);
76 const size_t n = strlen(arg_str);
77 char *str = malloc(sizeof(char) * (n + 1));
84 strncpy(str, arg_str, n);
89 atom->number = va_arg(args, int);
98 void destroy_atom(struct Atom *atom)
100 switch (atom->type) {