Language actually gets properly stepped through using debugger!

This commit is contained in:
Krzosa Karol
2022-06-07 17:53:04 +02:00
parent 9cdc5ee6c9
commit c69d2b7fe2
3 changed files with 36 additions and 0 deletions

View File

@@ -229,6 +229,11 @@ gen_expr(Ast_Expr *ast){
} }
} }
function void
gen_line(Ast *node){
genln("#line %d", node->pos->line+1);
}
function void function void
gen_ast(Ast *ast); gen_ast(Ast *ast);
function void function void
@@ -236,6 +241,7 @@ gen_block(Ast_Block *block){
gen("{"); gen("{");
global_indent++; global_indent++;
For(block->stmts) { For(block->stmts) {
gen_line(it);
genln(""); genln("");
gen_ast(it); gen_ast(it);
} }
@@ -248,7 +254,9 @@ gen_ast(Ast *ast){
switch(ast->kind){ switch(ast->kind){
CASE(PACKAGE, Package){ CASE(PACKAGE, Package){
genln("#line 0 \"%s\"", node->name.str);
For(node->ordered) { For(node->ordered) {
gen_line(it);
genln(""); genln("");
gen_ast(it); gen_ast(it);
} }

View File

@@ -80,6 +80,7 @@ Expr:
[ ] - Arrays with size passed [ ] - Arrays with size passed
[ ] - Switch [ ] - Switch
[ ] - Values inited to 0 by default [ ] - Values inited to 0 by default
[ ] - Emitting #line
[ ] - Comma notation when declaring variables thing1, thing2: S32 [ ] - Comma notation when declaring variables thing1, thing2: S32
[ ] - Array of inferred size [ ] - Array of inferred size

View File

@@ -35,7 +35,10 @@ int main(){
entry(); entry();
} }
#line 0 "program.kl"
#line 1
#line 3
typedef struct Token{ typedef struct Token{
U8 kind; U8 kind;
U8 *str; U8 *str;
@@ -44,37 +47,61 @@ typedef struct Token{
Number = 0, Number = 0,
};*/ };*/
}Token; }Token;
#line 12
String kind_name(U8 kind){ String kind_name(U8 kind){
#line 15
if((kind==0)){ if((kind==0)){
#line 14
return LIT("<Number>"); return LIT("<Number>");
} }
else{ else{
#line 16
return LIT("<Unknown>"); return LIT("<Unknown>");
} }
} }
#line 18
Bool is_numeric(U8 c){ Bool is_numeric(U8 c){
#line 19
Bool result = ((c>=48)&&(c<=57)); Bool result = ((c>=48)&&(c<=57));
#line 20
return result; return result;
} }
#line 22
void entry(){ void entry(){
#line 23
String string_to_lex = LIT("Identifier 2425525 Not_Number"); String string_to_lex = LIT("Identifier 2425525 Not_Number");
#line 24
Slice token_array = (Slice){32, (Token [32]){}}; Slice token_array = (Slice){32, (Token [32]){}};
#line 25
S64 token_count = 0; S64 token_count = 0;
#line 27
Token t; Token t;
#line 28
for(S64 i = 0;(i<string_to_lex.len);i+=1){ for(S64 i = 0;(i<string_to_lex.len);i+=1){
#line 29
if(is_numeric((string_to_lex.str[i]))){ if(is_numeric((string_to_lex.str[i]))){
#line 30
t.kind=0; t.kind=0;
#line 31
t.str=(&(string_to_lex.str[i])); t.str=(&(string_to_lex.str[i]));
#line 32
t.len=i; t.len=i;
#line 33
for(;is_numeric((string_to_lex.str[i]));){ for(;is_numeric((string_to_lex.str[i]));){
#line 34
i+=1; i+=1;
} }
#line 35
t.len=(i-t.len); t.len=(i-t.len);
#line 36
(((Token *)token_array.data)[(token_count++)])=t; (((Token *)token_array.data)[(token_count++)])=t;
} }
} }
#line 38
for(S64 i = 0;(i<token_count);(i++)){ for(S64 i = 0;(i<token_count);(i++)){
#line 39
Token *tk = (&(((Token *)token_array.data)[i])); Token *tk = (&(((Token *)token_array.data)[i]));
#line 40
printf("%.*s", ((S32 )tk->len), tk->str); printf("%.*s", ((S32 )tk->len), tk->str);
} }
} }