From 85a67a25ac9757e694166b3c9e9e2c8cdeefc6da Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Sat, 20 Sep 2025 23:25:29 -0400 Subject: Initial commit --- src/main.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..d543acf --- /dev/null +++ b/src/main.c @@ -0,0 +1,37 @@ +#include + +#include "utils.h" +#include "lexer.h" +#include "parser.h" +#include "runtime.h" + +pit_value test_add(pit_runtime *rt, pit_value args) { + i64 x = pit_as_integer(rt, pit_car(rt, args)); + i64 y = pit_as_integer(rt, pit_car(rt, pit_cdr(rt, args))); + return pit_integer_new(rt, x + y); +} + +int main(int argc, char **argv) { + if (argc < 2) pit_panic("usage: %s FILE", argv[0]); + pit_lexer *lex = pit_lex_file(argv[1]); + /* pit_lex_token t; */ + /* while ((t = pit_lex_next(lex)) > PIT_LEX_TOKEN_EOF) { */ + /* printf("%s ", pit_lex_token_name(t)); */ + /* } */ + /* puts(pit_lex_token_name(t)); */ + + pit_runtime *rt = pit_runtime_new(); + pit_check_error_maybe_panic(rt); + // pit_fset(rt, pit_intern_cstr(rt, "add"), pit_nativefunc_new(rt, test_add)); + // pit_trace(rt, pit_list(rt, 2, pit_integer_new(rt, 1), pit_integer_new(rt, 2))); + // pit_trace(rt, pit_cons(rt, pit_cons(rt, pit_integer_new(rt, 1), pit_bytes_new_cstr(rt, "foobarbaz")), pit_cons(rt, pit_integer_new(rt, 2), pit_integer_new(rt, 3)))); + // pit_check_error_maybe_panic(rt); + // pit_value res = pit_apply(rt, pit_fget(rt, pit_intern_cstr(rt, "add")), pit_list(rt, 2, pit_integer_new(rt, 1), pit_integer_new(rt, 2))); + // pit_check_error_maybe_panic(rt); + // pit_trace(rt, res); + + pit_parser *parse = pit_parser_from_lexer(lex); + pit_value v = pit_parse(rt, parse); + pit_check_error_maybe_panic(rt); + pit_trace(rt, v); +} -- cgit v1.2.3