|
|
@@ -29,6 +29,7 @@ char __locally *spl_input;
|
|
|
char __visible lbracket = '(', rbracket = ')';
|
|
|
|
|
|
struct spl_klist_node __visible wordlist = SPL_KLIST_NODE_INIT(&wordlist);
|
|
|
+struct spl_klist_node __visible spl_macros = SPL_KLIST_NODE_INIT(&spl_macros);
|
|
|
struct spearl_object __visible root_object;
|
|
|
|
|
|
#define callfn(fn) if (fn == -1) return -1
|
|
|
@@ -43,6 +44,8 @@ int spearl_init(void) {
|
|
|
|
|
|
root_object.list->nobjs = 0;
|
|
|
|
|
|
+ spl_builtin_init();
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -295,15 +298,31 @@ struct spearl_mcall *collect_args(struct spearl_list *list) {
|
|
|
|
|
|
|
|
|
static inline int mcall_valid(struct spearl_mcall *mcall) {
|
|
|
- if (mcall->dest && mcall->mname && !spl_klist_empty(&mcall->args))
|
|
|
+ if (mcall->dest && mcall->mname)
|
|
|
return 1;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
-static int do_expand_macro(struct spearl_list *list) {
|
|
|
+static struct spearl_macro *find_macro(struct spearl_mcall *mcall) {
|
|
|
+ struct spl_klist_node *n;
|
|
|
+ struct spearl_macro *macro;
|
|
|
+
|
|
|
+ for (n = spl_macros.next; n != &spl_macros; n = n->next) {
|
|
|
+ macro = macro_of_node(n);
|
|
|
+
|
|
|
+ if (!strncmp(macro->name, mcall->mname->word->p + 1, mcall->mname->word->len - 1))
|
|
|
+ return macro;
|
|
|
+ }
|
|
|
+
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+static int do_expand_macro(struct spearl_list *list, struct spl_klist_node *node) {
|
|
|
struct spearl_mcall *mcall;
|
|
|
+ struct spearl_macro *macro;
|
|
|
|
|
|
if (!(mcall = collect_args(list)))
|
|
|
return -1;
|
|
|
@@ -311,6 +330,12 @@ static int do_expand_macro(struct spearl_list *list) {
|
|
|
if (!mcall_valid(mcall))
|
|
|
return spearl_error(SPL_INCOMPLETE_CALL);
|
|
|
|
|
|
+ if (!(macro = find_macro(mcall)))
|
|
|
+ return spearl_error(SPL_MACRO_NEXISTS);
|
|
|
+
|
|
|
+ if (macro->type == BUILTIN)
|
|
|
+ callfn(expand_builtin_macro(macro, mcall, node));
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -325,7 +350,7 @@ static int expand_calls(void) {
|
|
|
if (obj->type != LIST)
|
|
|
return spearl_error(SPL_INVALID_LIST);
|
|
|
|
|
|
- callfn(do_expand_macro(obj->list));
|
|
|
+ callfn(do_expand_macro(obj->list, n));
|
|
|
}
|
|
|
|
|
|
return 0;
|