From 759825172cd87a8f14920b56ded4d0ec3a279b66 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Tue, 7 Jun 2022 11:27:09 +0200 Subject: [PATCH] Printf is working !! --- ccodegen.cpp | 10 +++++++++- compiler.h | 2 ++ program.c | 5 +++-- program.kl | 4 ++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ccodegen.cpp b/ccodegen.cpp index 3ac46bc..b99968b 100644 --- a/ccodegen.cpp +++ b/ccodegen.cpp @@ -180,8 +180,12 @@ gen_expr(Ast_Expr *ast){ else{ gen_expr(node->name); gen("("); + auto name_for_printf = (Ast_Atom *)node->name; For(node->exprs){ - gen_expr(it->item); + if(intern_printf == name_for_printf->intern_val && &it == node->exprs.data){ + gen("\"%s\"", name_for_printf->intern_val.str); + } + else gen_expr(it->item); if(!node->exprs.is_last(&it)) gen(", "); } gen(")"); @@ -310,6 +314,9 @@ gen_ast(Ast *ast){ case TYPE_LAMBDA:{ if(node->value->kind == AST_LAMBDA){ + if(is_flag_set(node->flags, AST_FOREIGN)){ + return; + } Ast_Lambda *lambda = (Ast_Lambda *)node->value; Ast_Resolved_Type *ret = resolved_type_get(lambda->ret); gen_simple_decl(ret, node->name); @@ -419,6 +426,7 @@ compile_string(String filecontent, String filename = "default_name"_s){ gen(R"==( #include +#include typedef int8_t S8; typedef int16_t S16; typedef int32_t S32; diff --git a/compiler.h b/compiler.h index f44010e..22c4e35 100644 --- a/compiler.h +++ b/compiler.h @@ -159,6 +159,7 @@ Intern_String keyword_enum; Intern_String intern_void; Intern_String intern_foreign; +Intern_String intern_printf; struct Ast_Package; struct Sym; @@ -208,6 +209,7 @@ lex_init(Allocator *token_string_arena, Allocator *map_allocator, Lexer *l){ intern_foreign = intern_string(&l->interns, "#foreign"_s); intern_void = intern_string(&l->interns, "void"_s); + intern_printf = intern_string(&l->interns, "printf"_s); } function void diff --git a/program.c b/program.c index fbf2186..7c8c635 100644 --- a/program.c +++ b/program.c @@ -1,5 +1,6 @@ #include +#include typedef int8_t S8; typedef int16_t S16; typedef int32_t S32; @@ -29,7 +30,7 @@ int main(){ entry(); } -void printf(); + typedef struct Token{ U8 *str; S64 len; @@ -42,7 +43,7 @@ void entry(){ String string_to_lex = LIT("Identifier 2425525 Not_Number"); Token token_array[32]; U32 token_count; - printf(LIT("test"), 32); + printf("printf", 32); Token t; for(S64 i = 0;(i