aboutsummaryrefslogtreecommitdiff
path: root/nextlang.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-02-08 00:52:18 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-02-08 00:52:18 -0500
commit930c09f46d1e249fc889e8f1179046a48c1eaf32 (patch)
tree4900307e726dcbc643b12341a9bb7168edebdff5 /nextlang.c
parentee0f45e2959484d390c30a8a1430a0f040f56631 (diff)
More features and progress
Diffstat (limited to 'nextlang.c')
-rw-r--r--nextlang.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/nextlang.c b/nextlang.c
index f3b8d88b..7b56d0a6 100644
--- a/nextlang.c
+++ b/nextlang.c
@@ -2,15 +2,23 @@
#include <stdlib.h>
#include <gc.h>
#include <gc/cord.h>
+#include <printf.h>
#include "ast.h"
#include "parse.h"
#include "compile.h"
+#include "types.h"
int main(int argc, char *argv[])
{
if (argc < 2) return 1;
+ // register_printf_modifier(L"p");
+ if (register_printf_specifier('T', printf_type, printf_pointer_size))
+ errx(1, "Couldn't set printf specifier");
+ if (register_printf_specifier('W', printf_ast, printf_pointer_size))
+ errx(1, "Couldn't set printf specifier");
+
const char *autofmt = getenv("AUTOFMT");
if (!autofmt) autofmt = "indent -kr -nut | bat --file-name=out.c";
@@ -34,7 +42,7 @@ int main(int argc, char *argv[])
// Predeclare types:
for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) {
switch (stmt->ast->tag) {
- case TypeDef: {
+ case StructDef: case EnumDef: {
code = CORD_cat(code, compile(stmt->ast));
break;
}
@@ -48,8 +56,8 @@ int main(int argc, char *argv[])
case FunctionDef: {
auto fndef = Match(stmt->ast, FunctionDef);
CORD_sprintf(&code, "%rstatic %r %r(", code, fndef->ret_type ? compile_type(fndef->ret_type) : "void", compile(fndef->name));
- for (arg_list_t *arg = fndef->args; arg; arg = arg->next) {
- CORD_sprintf(&code, "%r%r %s", code, compile_type(arg->type), arg->var.name);
+ for (arg_ast_t *arg = fndef->args; arg; arg = arg->next) {
+ CORD_sprintf(&code, "%r%r %s", code, compile_type(arg->type), arg->name);
if (arg->next) code = CORD_cat(code, ", ");
}
code = CORD_cat(code, ");\n");
@@ -77,7 +85,7 @@ int main(int argc, char *argv[])
"GC_INIT();\n\n");
for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) {
switch (stmt->ast->tag) {
- case FunctionDef: case TypeDef: break;
+ case FunctionDef: case StructDef: case EnumDef: break;
default: {
code = CORD_cat(code, compile(stmt->ast));
code = CORD_cat(code, ";\n");