/* spearl/builtin.c
*
* This file is part of spearl.
*
* Spearl is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Spearl is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with spearl. If not, see
*/
#include
#include
#include
static struct spearl_list *do_builtin_macro(struct spearl_mcall *mcall) {
(void) mcall;
printf("hello, world");
return root_object.list;
}
int spl_builtin_init(void) {
spearl_define_builtin("macro", do_builtin_macro);
return 0;
}
int expand_builtin_macro(struct spearl_macro *macro, struct spearl_mcall *mcall,
struct spl_klist_node *node) {
struct spearl_list *list;
if (!(list = macro->builtin.do_builtin(mcall)))
return -1;
spl_klist_add(node->next, &container_of(list, struct spearl_object, list)->node);
return 0;
}
struct spearl_macro __visible *spearl_define_builtin(char *name,
spearl_builtin_fn_t fn) {
struct spearl_macro *macro;
macro = spl_macro_alloc();
macro->type = BUILTIN;
macro->name = name;
macro->builtin.name = name;
macro->builtin.do_builtin = fn;
spl_klist_init(¯o->node);
spl_klist_add(&spl_macros, ¯o->node);
return macro;
}