Files

67 lines
1.4 KiB
C

#include <stdio.h>
#define NOB_IMPLEMENTATION
#include "lisp.h"
int main(int argc, char **argv) {
if (argc < 2)
return 1;
argv++;
const char *line = *argv++;
Nob_String_View view = nob_sv_from_cstr(line);
if (nob_sv_eq(view, (Nob_String_View){.count = 1, .data = "-"})) {
printf("Reading from stdin\n");
Nob_String_Builder sb = {0};
char content[1];
while (read(stdin->_fileno, content, sizeof(*content)) == 1) {
if (*content == '\0')
break;
nob_sb_appendf(&sb, "%c", *content);
}
view = nob_sb_to_sv(sb);
}
Tokens tokens = {0};
if (tokenize(view, &tokens) != 0)
return 1;
#if 0
for (size_t i = 0; i < tokens.count; i++) {
Token tok = tokens.items[i];
printf("Token(kind=%s, data=" SV_Fmt ")\n", token_kind_name(tok.kind),
SV_Arg(tok.data));
}
#endif
Scopes scopes = {0};
build_scopes(&scopes);
Nodes result = {0};
parse(&tokens, &result);
#if 0
nob_da_foreach(Node, node, &result) {
node_print(*node);
printf("\n");
}
#endif
Nodes evaluated = {0};
int ret = eval(result, &scopes, &evaluated);
if (ret != 0) {
return 1;
}
nob_da_foreach(Node, node, &evaluated) {
node_print(*node);
printf("\n");
}
return 0;
}