Working on actually making a program
This commit is contained in:
@@ -183,7 +183,10 @@ gen_expr(Ast_Expr *ast){
|
|||||||
auto name_for_printf = (Ast_Atom *)node->name;
|
auto name_for_printf = (Ast_Atom *)node->name;
|
||||||
For(node->exprs){
|
For(node->exprs){
|
||||||
if(intern_printf == name_for_printf->intern_val && &it == node->exprs.data){
|
if(intern_printf == name_for_printf->intern_val && &it == node->exprs.data){
|
||||||
gen("\"%s\"", name_for_printf->intern_val.str);
|
Ast_Atom *atom = (Ast_Atom *)it->item;
|
||||||
|
assert(atom->kind == AST_VALUE);
|
||||||
|
assert(atom->type == untyped_string);
|
||||||
|
gen("\"%s\"", atom->intern_val.str);
|
||||||
}
|
}
|
||||||
else gen_expr(it->item);
|
else gen_expr(it->item);
|
||||||
if(!node->exprs.is_last(&it)) gen(", ");
|
if(!node->exprs.is_last(&it)) gen(", ");
|
||||||
@@ -218,6 +221,7 @@ gen_ast(Ast *ast){
|
|||||||
|
|
||||||
CASE(PACKAGE, Package){
|
CASE(PACKAGE, Package){
|
||||||
For(node->ordered) {
|
For(node->ordered) {
|
||||||
|
genln("");
|
||||||
genln("");
|
genln("");
|
||||||
gen_ast(it);
|
gen_ast(it);
|
||||||
}
|
}
|
||||||
|
|||||||
6
main.cpp
6
main.cpp
@@ -78,8 +78,9 @@ Expr:
|
|||||||
|
|
||||||
@todo
|
@todo
|
||||||
[ ] - Passing down program to compile through command line
|
[ ] - Passing down program to compile through command line
|
||||||
[ ] - Switch
|
|
||||||
[ ] - Arrays with size passed
|
[ ] - Arrays with size passed
|
||||||
|
[ ] - Switch
|
||||||
|
[ ] - Fix printf somehow.
|
||||||
|
|
||||||
[ ] - Comma notation when declaring variables thing1, thing2: S32
|
[ ] - Comma notation when declaring variables thing1, thing2: S32
|
||||||
[ ] - Array of inferred size
|
[ ] - Array of inferred size
|
||||||
@@ -106,6 +107,7 @@ Expr:
|
|||||||
[ ] - Compound that zeros values - .{} , Compound that assumes defaults from struct definition - {}
|
[ ] - Compound that zeros values - .{} , Compound that assumes defaults from struct definition - {}
|
||||||
[ ] - Inject stack traces into the program
|
[ ] - Inject stack traces into the program
|
||||||
[ ] - Rewrite constants to embed lambda, types, structs etc.? ???
|
[ ] - Rewrite constants to embed lambda, types, structs etc.? ???
|
||||||
|
[ ] - Var args using Any array - args: []Any - delete vargs
|
||||||
|
|
||||||
@donzo
|
@donzo
|
||||||
[x] - We need ++ -- operators
|
[x] - We need ++ -- operators
|
||||||
@@ -185,9 +187,9 @@ int main(){
|
|||||||
printf("%s", result.str);
|
printf("%s", result.str);
|
||||||
result = compile_file("lambdas.kl"_s);
|
result = compile_file("lambdas.kl"_s);
|
||||||
printf("%s", result.str);
|
printf("%s", result.str);
|
||||||
#endif
|
|
||||||
result = compile_file("new_types.kl"_s);
|
result = compile_file("new_types.kl"_s);
|
||||||
printf("%s", result.str);
|
printf("%s", result.str);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|||||||
26
program.c
26
program.c
@@ -31,22 +31,39 @@ int main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct Token{
|
typedef struct Token{
|
||||||
|
U8 kind;
|
||||||
U8 *str;
|
U8 *str;
|
||||||
S64 len;
|
S64 len;
|
||||||
|
/*enum Kind{
|
||||||
|
Number = 0,
|
||||||
|
};*/
|
||||||
}Token;
|
}Token;
|
||||||
|
|
||||||
|
String kind_name(U8 kind){
|
||||||
|
if((kind==0)){
|
||||||
|
return LIT("<Number>");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return LIT("<Unknown>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Bool is_numeric(U8 c){
|
Bool is_numeric(U8 c){
|
||||||
Bool result = ((c>=48)&&(c<=57));
|
Bool result = ((c>=48)&&(c<=57));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void entry(){
|
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;
|
S64 token_count = 0;
|
||||||
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]))){
|
||||||
|
(t.kind=0);
|
||||||
(t.str=(&(string_to_lex.str[i])));
|
(t.str=(&(string_to_lex.str[i])));
|
||||||
(t.len=i);
|
(t.len=i);
|
||||||
for(;is_numeric((string_to_lex.str[i]));){
|
for(;is_numeric((string_to_lex.str[i]));){
|
||||||
@@ -54,7 +71,10 @@ void entry(){
|
|||||||
}
|
}
|
||||||
(t.len=(i-t.len));
|
(t.len=(i-t.len));
|
||||||
((token_array[(token_count++)])=t);
|
((token_array[(token_count++)])=t);
|
||||||
(token_count+=1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(S64 i = 0;(i<token_count);(i++)){
|
||||||
|
Token *tk = (&(token_array[i]));
|
||||||
|
printf("%.*s", ((S32 )tk->len), tk->str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
23
program.kl
23
program.kl
@@ -1,10 +1,20 @@
|
|||||||
|
|
||||||
#foreign printf :: (str: String, ...)
|
#foreign printf :: (str: String, ...)
|
||||||
|
|
||||||
Token :: struct
|
Token :: struct
|
||||||
|
kind: U8
|
||||||
str: *U8
|
str: *U8
|
||||||
len: S64
|
len: S64
|
||||||
|
|
||||||
|
Kind :: enum
|
||||||
|
Number
|
||||||
|
|
||||||
|
|
||||||
|
kind_name :: (kind: U8): String
|
||||||
|
if kind == Token.Kind.Number
|
||||||
|
return "<Number>"
|
||||||
|
else
|
||||||
|
return "<Unknown>"
|
||||||
|
|
||||||
is_numeric :: (c: U8): Bool
|
is_numeric :: (c: U8): Bool
|
||||||
result := c >= '0 && c <= '9
|
result := c >= '0 && c <= '9
|
||||||
return result
|
return result
|
||||||
@@ -12,20 +22,19 @@ is_numeric :: (c: U8): Bool
|
|||||||
entry :: ()
|
entry :: ()
|
||||||
string_to_lex := "Identifier 2425525 Not_Number"
|
string_to_lex := "Identifier 2425525 Not_Number"
|
||||||
token_array: [32]Token
|
token_array: [32]Token
|
||||||
token_count: U32
|
token_count: S64 = 0
|
||||||
|
|
||||||
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
|
||||||
if is_numeric(string_to_lex.str[i])
|
if is_numeric(string_to_lex.str[i])
|
||||||
|
t.kind = Token.Kind.Number
|
||||||
t.str = &string_to_lex.str[i]
|
t.str = &string_to_lex.str[i]
|
||||||
t.len = i
|
t.len = i
|
||||||
for is_numeric(string_to_lex.str[i])
|
for is_numeric(string_to_lex.str[i])
|
||||||
i+=1
|
i+=1
|
||||||
t.len = i - t.len
|
t.len = i - t.len
|
||||||
token_array[token_count++] = t
|
token_array[token_count++] = t
|
||||||
token_count+=1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for i := 0, i < token_count, i++
|
||||||
|
tk := &token_array[i]
|
||||||
|
printf("%.*s", cast(tk.len: S32), tk.str)
|
||||||
|
|||||||
@@ -352,9 +352,7 @@ resolve_typespec(Ast_Expr *ast, B32 ast_can_be_null){
|
|||||||
function void resolve_stmt(Ast *ast, Ast_Resolved_Type *ret);
|
function void resolve_stmt(Ast *ast, Ast_Resolved_Type *ret);
|
||||||
function void
|
function void
|
||||||
resolve_stmt_block(Ast_Block *block, Ast_Resolved_Type *ret){
|
resolve_stmt_block(Ast_Block *block, Ast_Resolved_Type *ret){
|
||||||
Scope(){
|
|
||||||
For(block->stmts) resolve_stmt(it, ret);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @note: Ret is return value of function passed down the stack
|
// @note: Ret is return value of function passed down the stack
|
||||||
@@ -397,18 +395,25 @@ resolve_stmt(Ast *ast, Ast_Resolved_Type *ret){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve_expr(node->init, ret);
|
Scope(){
|
||||||
resolve_expr(node->cond, ret);
|
resolve_expr(node->init, ret);
|
||||||
resolve_expr(node->iter, ret);
|
resolve_expr(node->cond, ret);
|
||||||
resolve_stmt_block(node->block, ret);
|
resolve_expr(node->iter, ret);
|
||||||
|
For(node->block->stmts)
|
||||||
|
resolve_stmt(it, ret);
|
||||||
|
}
|
||||||
BREAK();
|
BREAK();
|
||||||
}
|
}
|
||||||
|
|
||||||
CASE(IF, If){
|
CASE(IF, If){
|
||||||
For(node->ifs){
|
For(node->ifs){
|
||||||
resolve_stmt(it->init, ret);
|
resolve_stmt(it->init, ret);
|
||||||
resolve_expr(it->expr); // @todo: typechecking
|
Scope(){
|
||||||
resolve_stmt_block(it->block, ret);
|
resolve_expr(it->expr); // @todo: typechecking
|
||||||
|
resolve_stmt_block(it->block, ret);
|
||||||
|
For_It(it->block->stmts, jt)
|
||||||
|
resolve_stmt(jt, ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BREAK();
|
BREAK();
|
||||||
}
|
}
|
||||||
@@ -690,6 +695,7 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res
|
|||||||
parsing_error(lambda->pos, "Cant name index a lambda with var args");
|
parsing_error(lambda->pos, "Cant name index a lambda with var args");
|
||||||
for(S64 i = lambda->args.len; i < node->exprs.len; i++){
|
for(S64 i = lambda->args.len; i < node->exprs.len; i++){
|
||||||
Ast_Call_Item *item = node->exprs.data[i];
|
Ast_Call_Item *item = node->exprs.data[i];
|
||||||
|
resolve_expr(item->item);
|
||||||
item->flags = set_flag(item->flags, AST_ITEM_INCLUDED);
|
item->flags = set_flag(item->flags, AST_ITEM_INCLUDED);
|
||||||
items.add(item);
|
items.add(item);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user