Printf is working !!
This commit is contained in:
10
ccodegen.cpp
10
ccodegen.cpp
@@ -180,8 +180,12 @@ gen_expr(Ast_Expr *ast){
|
|||||||
else{
|
else{
|
||||||
gen_expr(node->name);
|
gen_expr(node->name);
|
||||||
gen("(");
|
gen("(");
|
||||||
|
auto name_for_printf = (Ast_Atom *)node->name;
|
||||||
For(node->exprs){
|
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(", ");
|
if(!node->exprs.is_last(&it)) gen(", ");
|
||||||
}
|
}
|
||||||
gen(")");
|
gen(")");
|
||||||
@@ -310,6 +314,9 @@ gen_ast(Ast *ast){
|
|||||||
|
|
||||||
case TYPE_LAMBDA:{
|
case TYPE_LAMBDA:{
|
||||||
if(node->value->kind == AST_LAMBDA){
|
if(node->value->kind == AST_LAMBDA){
|
||||||
|
if(is_flag_set(node->flags, AST_FOREIGN)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
Ast_Lambda *lambda = (Ast_Lambda *)node->value;
|
Ast_Lambda *lambda = (Ast_Lambda *)node->value;
|
||||||
Ast_Resolved_Type *ret = resolved_type_get(lambda->ret);
|
Ast_Resolved_Type *ret = resolved_type_get(lambda->ret);
|
||||||
gen_simple_decl(ret, node->name);
|
gen_simple_decl(ret, node->name);
|
||||||
@@ -419,6 +426,7 @@ compile_string(String filecontent, String filename = "default_name"_s){
|
|||||||
|
|
||||||
gen(R"==(
|
gen(R"==(
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
typedef int8_t S8;
|
typedef int8_t S8;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
typedef int32_t S32;
|
typedef int32_t S32;
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ Intern_String keyword_enum;
|
|||||||
|
|
||||||
Intern_String intern_void;
|
Intern_String intern_void;
|
||||||
Intern_String intern_foreign;
|
Intern_String intern_foreign;
|
||||||
|
Intern_String intern_printf;
|
||||||
|
|
||||||
struct Ast_Package;
|
struct Ast_Package;
|
||||||
struct Sym;
|
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_foreign = intern_string(&l->interns, "#foreign"_s);
|
||||||
intern_void = intern_string(&l->interns, "void"_s);
|
intern_void = intern_string(&l->interns, "void"_s);
|
||||||
|
intern_printf = intern_string(&l->interns, "printf"_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
typedef int8_t S8;
|
typedef int8_t S8;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
typedef int32_t S32;
|
typedef int32_t S32;
|
||||||
@@ -29,7 +30,7 @@ int main(){
|
|||||||
entry();
|
entry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printf();
|
|
||||||
typedef struct Token{
|
typedef struct Token{
|
||||||
U8 *str;
|
U8 *str;
|
||||||
S64 len;
|
S64 len;
|
||||||
@@ -42,7 +43,7 @@ void entry(){
|
|||||||
String string_to_lex = LIT("Identifier 2425525 Not_Number");
|
String string_to_lex = LIT("Identifier 2425525 Not_Number");
|
||||||
Token token_array[32];
|
Token token_array[32];
|
||||||
U32 token_count;
|
U32 token_count;
|
||||||
printf(LIT("test"), 32);
|
printf("printf", 32);
|
||||||
Token t;
|
Token t;
|
||||||
for(S64 i = 0;(i<string_to_lex.len);(i+=1)){
|
for(S64 i = 0;(i<string_to_lex.len);(i+=1)){
|
||||||
if(is_numeric((string_to_lex.str[i]))){
|
if(is_numeric((string_to_lex.str[i]))){
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#foreign printf :: (...)
|
#foreign printf :: (str: String, ...)
|
||||||
|
|
||||||
Token :: struct
|
Token :: struct
|
||||||
str: *U8
|
str: *U8
|
||||||
@@ -14,7 +14,7 @@ entry :: ()
|
|||||||
token_array: [32]Token
|
token_array: [32]Token
|
||||||
token_count: U32
|
token_count: U32
|
||||||
|
|
||||||
printf("test", 32)
|
printf("test %d", 32)
|
||||||
|
|
||||||
t: Token
|
t: Token
|
||||||
for i := 0, i < string_to_lex.len, i+=1
|
for i := 0, i < string_to_lex.len, i+=1
|
||||||
|
|||||||
Reference in New Issue
Block a user