Consolidate expression creation functions in expr module
This commit is contained in:
46
lib/expr.c
Normal file
46
lib/expr.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "expr.h"
|
||||
#include "store.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
expr_t *expr_integer(store_t *store, int64_t value)
|
||||
{
|
||||
expr_t *expr = store_alloc(store);
|
||||
expr->is_atom = true;
|
||||
expr->atom.type = ATOM_TYPE_INTEGER;
|
||||
expr->atom.integer = value;
|
||||
return expr;
|
||||
}
|
||||
|
||||
expr_t *expr_symbol(store_t *store, const symbol_t *symbol)
|
||||
{
|
||||
expr_t *expr = store_alloc(store);
|
||||
expr->is_atom = true;
|
||||
expr->atom.type = ATOM_TYPE_SYMBOL;
|
||||
memcpy(&expr->atom.symbol, symbol, sizeof(symbol_t));
|
||||
return expr;
|
||||
}
|
||||
|
||||
expr_t *expr_str_symbol(store_t *store, const char *str)
|
||||
{
|
||||
symbol_t symbol = { .len = strlen(str) };
|
||||
memcpy(symbol.buf, str, symbol.len);
|
||||
return expr_symbol(store, &symbol);
|
||||
}
|
||||
|
||||
expr_t *expr_empty_list(store_t *store)
|
||||
{
|
||||
expr_t *expr = store_alloc(store);
|
||||
expr->is_atom = true;
|
||||
expr->atom.type = ATOM_TYPE_EMPTY_LIST;
|
||||
return expr;
|
||||
}
|
||||
|
||||
expr_t *expr_pair(store_t *store, expr_t *car, expr_t *cdr)
|
||||
{
|
||||
expr_t *expr = store_alloc(store);
|
||||
expr->is_atom = false;
|
||||
expr->pair.car = car;
|
||||
expr->pair.cdr = cdr;
|
||||
return expr;
|
||||
}
|
||||
Reference in New Issue
Block a user