diff --git a/ccodegen.cpp b/ccodegen.cpp index 1f51727..b37af48 100644 --- a/ccodegen.cpp +++ b/ccodegen.cpp @@ -133,7 +133,8 @@ gen_expr(Ast_Expr *ast){ else gen("."); gen_expr(node->right); } - else if(node->op == TK_ColonAssign){ // @todo: I think this needs to be a stmt + else if(node->op == TK_ColonAssign){ + Sym *sym = resolved_get(node); Ast_Atom *atom = (Ast_Atom *)node->left; assert(is_atom(atom)); @@ -210,6 +211,8 @@ gen_expr(Ast_Expr *ast){ gen("("); auto name_for_printf = (Ast_Atom *)node->name; For(node->exprs){ + // @special_case @todo in the future this should be replaced + // with []Any if(intern_printf == name_for_printf->intern_val && &it == node->exprs.data){ Ast_Atom *atom = (Ast_Atom *)it->item; assert(atom->kind == AST_VALUE); @@ -231,7 +234,8 @@ gen_expr(Ast_Expr *ast){ function void gen_line(Ast *node){ - genln("#line %d", node->pos->line+1); + if(emit_line_directives) + genln("#line %d", node->pos->line+1); } function void @@ -254,7 +258,8 @@ gen_ast(Ast *ast){ switch(ast->kind){ CASE(PACKAGE, Package){ - genln("#line 0 \"%s\"", node->name.str); + if(emit_line_directives) + genln("#line 0 \"%s\"", node->name.str); For(node->ordered) { gen_line(it); genln(""); @@ -290,6 +295,8 @@ gen_ast(Ast *ast){ gen_simple_decl(sym->type, {}); gen("){}"); gen("}"); + } else { // Default zero + gen(" = {}"); } gen(";"); BREAK(); diff --git a/main.cpp b/main.cpp index 63e1f16..6a14377 100644 --- a/main.cpp +++ b/main.cpp @@ -80,7 +80,7 @@ Expr: [ ] - Arrays with size passed [ ] - Switch [ ] - Values inited to 0 by default -[ ] - Emitting #line +[ ] - Add c string [ ] - Comma notation when declaring variables thing1, thing2: S32 [ ] - Array of inferred size @@ -111,6 +111,8 @@ Expr: [ ] - Conditional compilation #if @donzo +[x] - Emitting #line +[x] - Making sure debugger works [x] - We need ++ -- operators [x] - Some way to call foreign functions [x] - We are parsing wrong here: (t.str=(&string_to_lex.str)[i]); @@ -178,7 +180,7 @@ int main(int argument_count, char **arguments){ - + emit_line_directives = false; if(argument_count > 1){ Scratch scratch; String name = string_fmt(scratch, "%s.kl", arguments[1]); diff --git a/new_types.kl b/new_types.kl index 941a7cd..cf78701 100644 --- a/new_types.kl +++ b/new_types.kl @@ -83,7 +83,30 @@ for_loops :: () Custom_Data :: struct thing: S32 +get_element_item :: (array: []Custom_Data, index: S64): Custom_Data + if index < array.len + return array[index] + else + return Custom_Data() + +get_element_pointer :: (array: []Custom_Data, index: S64): *Custom_Data + if index < array.len + return &array[index] + else + return 0 + +get_slice_len :: (array: []Custom_Data): S64 + return array.len + array_test :: () thing := []Custom_Data(Custom_Data(1), Custom_Data(2)) reference := thing - length := reference.len \ No newline at end of file + length := reference.len + + item := get_element_item(thing, 1) + pointer := get_element_pointer(thing, 0) + len := get_slice_len(thing) + + with_size: [2]Custom_Data + + // get_slice_len(with_size) \ No newline at end of file diff --git a/typecheck.cpp b/typecheck.cpp index 593b103..9c8898f 100644 --- a/typecheck.cpp +++ b/typecheck.cpp @@ -584,7 +584,7 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res if(!is_array(left.type) && !is_pointer(left.type)){ parsing_error(node->pos, "Indexing variable that is not an [Array] or [Pointer], it's of type %s instead", docname(left.type)); } - + sym_new_resolved(SYM_VAR, {}, left.value, node); return operand_lvalue(left.type->arr.base); BREAK(); @@ -710,9 +710,7 @@ resolve_expr(Ast_Expr *ast, Ast_Resolved_Type *expected_type, Sym *lambda_to_res if(item){ item->flags = set_flag(item->flags, AST_ITEM_INCLUDED); Operand expr = resolve_expr(item->item); - expr.value = convert_untyped_to_typed(node->pos, expr.value, resolved); - - if(expr.type != resolved) type_error(item->pos, resolved, expr.type, "Type is not matching function definition"); + make_sure_value_is_compatible_with_type(node->pos, &expr, resolved, TYPE_AND_EXPR_REQUIRED); items.add(item); } else{ diff --git a/typecheck.h b/typecheck.h index 8d1bc3a..59d59e4 100644 --- a/typecheck.h +++ b/typecheck.h @@ -292,7 +292,8 @@ type_array(Ast_Resolved_Type *base, B32 size_present, S64 size){ size = ARRAY_SIZE_INFERRED; } - U64 hash = hash_mix(hash_ptr(base), hash_u64(size)); + U64 hash_base = hash_ptr(base); + U64 hash = hash_mix(hash_base, hash_u64(size)); Ast_Resolved_Type *result = (Ast_Resolved_Type *)map_get(&pctx->type_map, hash); if(result){ assert(result->kind == TYPE_ARRAY); @@ -304,6 +305,7 @@ type_array(Ast_Resolved_Type *base, B32 size_present, S64 size){ result = type_new(pctx->perm, TYPE_ARRAY, pointer_size, pointer_align); result->arr.base = base; result->arr.size = size; + result->arr.inferred_size_hash = hash_mix(hash_base, hash_u64(ARRAY_SIZE_INFERRED)); map_insert(&pctx->type_map, hash, result); return result; } diff --git a/types.h b/types.h index 567d88a..aae98f4 100644 --- a/types.h +++ b/types.h @@ -100,6 +100,11 @@ struct Ast_Resolved_Type{ struct{ Ast_Resolved_Type *base; S64 size; + // @note: if you have array with size "[32]" + // you still want to pass that array into + // a function that expects an array of size "[]" + // so we want also should check this + U64 inferred_size_hash; }arr; struct{ Array members;