aboutsummaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c55
1 files changed, 23 insertions, 32 deletions
diff --git a/src/ast.c b/src/ast.c
index faeae6e..f99a7b8 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -1,53 +1,44 @@
#include <stdio.h>
#include <lyn/ast.h>
-struct ast *reverse_ast_list(struct ast *root)
-{
- struct ast *new_root = NULL;
- while (root) {
- struct ast *next = root->next;
- root->next = new_root;
- new_root = root;
- root = next;
- }
-
- return new_root;
-}
-
#define dump(depth, fmt, ...) \
do { \
printf("//%*s", 2 * depth, ""); \
printf(fmt,##__VA_ARGS__); \
} while (0)
-void ast_dump(int depth, struct ast *ast)
+void ast_dump(int depth, struct lyn_value val)
{
- switch (ast->kind) {
- case LYN_ID: dump(depth, "%s\n", ast->s); return;
- case LYN_STR: dump(depth, "\"%s\"\n", ast->s); return;
- case LYN_INT: dump(depth, "%lld\n", ast->i); return;
- case LYN_FLOAT: dump(depth, "%f\n", ast->d); return;
+ switch (val.kind) {
+ case LYN_ID: dump(depth, "%s\n", val.s); return;
+ case LYN_STR: dump(depth, "\"%s\"\n", val.s); return;
+ case LYN_INT: dump(depth, "%lld\n", val.i); return;
+ case LYN_FLOAT: dump(depth, "%f\n", val.d); return;
case LYN_CMD:
dump(depth, "CMD\n");
- ast_dump_list(depth + 1, ast->args);
- return;
+ foreach_vec(ci, val.args) {
+ struct lyn_value v = vect_at(struct lyn_value, val.args, ci);
+ ast_dump(depth + 1, v);
+ }
- case LYN_LIST:
- dump(depth, "LIST\n");
- ast_dump_list(depth + 1, ast->args);
return;
case LYN_APPLY:
dump(depth, "APPLY\n");
- ast_dump_list(depth + 1, ast->args);
+ foreach_vec(ai, val.args) {
+ struct lyn_value v = vect_at(struct lyn_value, val.args, ai);
+ ast_dump(depth + 1, v);
+ }
return;
- }
-}
-void ast_dump_list(int depth, struct ast *ast)
-{
- while (ast) {
- ast_dump(depth, ast);
- ast = ast->next;
+ case LYN_GROUP:
+ dump(depth, "GROUP\n");
+ foreach_vec(gi, val.args) {
+ struct lyn_value v = vect_at(struct lyn_value, val.args, gi);
+ ast_dump(depth + 1, v);
+ }
+ return;
+
+ default: abort();
}
}