Printf is working !!
This commit is contained in:
10
ccodegen.cpp
10
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 <stdint.h>
|
||||
#include <stdio.h>
|
||||
typedef int8_t S8;
|
||||
typedef int16_t S16;
|
||||
typedef int32_t S32;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
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<string_to_lex.len);(i+=1)){
|
||||
if(is_numeric((string_to_lex.str[i]))){
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
#foreign printf :: (...)
|
||||
#foreign printf :: (str: String, ...)
|
||||
|
||||
Token :: struct
|
||||
str: *U8
|
||||
@@ -14,7 +14,7 @@ entry :: ()
|
||||
token_array: [32]Token
|
||||
token_count: U32
|
||||
|
||||
printf("test", 32)
|
||||
printf("test %d", 32)
|
||||
|
||||
t: Token
|
||||
for i := 0, i < string_to_lex.len, i+=1
|
||||
|
||||
Reference in New Issue
Block a user