| ... | @@ -497,6 +497,14 @@ static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, Ast | ... | @@ -497,6 +497,14 @@ static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, Ast |
| 497 | return &const_instruction->base; | 497 | return &const_instruction->base; |
| 498 | } | 498 | } |
| 499 | | 499 | |
| | 500 | static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| | 501 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| | 502 | const_instruction->base.type_entry = irb->codegen->builtin_types.entry_num_lit_int; |
| | 503 | const_instruction->base.static_value.special = ConstValSpecialStatic; |
| | 504 | bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, value); |
| | 505 | return &const_instruction->base; |
| | 506 | } |
| | 507 | |
| 500 | static IrInstruction *ir_build_const_bignum(IrBuilder *irb, Scope *scope, AstNode *source_node, BigNum *bignum) { | 508 | static IrInstruction *ir_build_const_bignum(IrBuilder *irb, Scope *scope, AstNode *source_node, BigNum *bignum) { |
| 501 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); | 509 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 502 | const_instruction->base.type_entry = (bignum->kind == BigNumKindInt) ? | 510 | const_instruction->base.type_entry = (bignum->kind == BigNumKindInt) ? |
| ... | @@ -1991,6 +1999,12 @@ static IrInstruction *ir_gen_num_lit(IrBuilder *irb, Scope *scope, AstNode *node | ... | @@ -1991,6 +1999,12 @@ static IrInstruction *ir_gen_num_lit(IrBuilder *irb, Scope *scope, AstNode *node |
| 1991 | return ir_build_const_bignum(irb, scope, node, node->data.number_literal.bignum); | 1999 | return ir_build_const_bignum(irb, scope, node, node->data.number_literal.bignum); |
| 1992 | } | 2000 | } |
| 1993 | | 2001 | |
| | 2002 | static IrInstruction *ir_gen_char_lit(IrBuilder *irb, Scope *scope, AstNode *node) { |
| | 2003 | assert(node->type == NodeTypeCharLiteral); |
| | 2004 | |
| | 2005 | return ir_build_const_uint(irb, scope, node, node->data.char_literal.value); |
| | 2006 | } |
| | 2007 | |
| 1994 | static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) { | 2008 | static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 1995 | assert(node->type == NodeTypeNullLiteral); | 2009 | assert(node->type == NodeTypeNullLiteral); |
| 1996 | | 2010 | |
| ... | @@ -3453,6 +3467,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -3453,6 +3467,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 3453 | return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval); | 3467 | return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval); |
| 3454 | case NodeTypeNumberLiteral: | 3468 | case NodeTypeNumberLiteral: |
| 3455 | return ir_lval_wrap(irb, scope, ir_gen_num_lit(irb, scope, node), lval); | 3469 | return ir_lval_wrap(irb, scope, ir_gen_num_lit(irb, scope, node), lval); |
| | 3470 | case NodeTypeCharLiteral: |
| | 3471 | return ir_lval_wrap(irb, scope, ir_gen_char_lit(irb, scope, node), lval); |
| 3456 | case NodeTypeSymbol: | 3472 | case NodeTypeSymbol: |
| 3457 | return ir_gen_symbol(irb, scope, node, lval); | 3473 | return ir_gen_symbol(irb, scope, node, lval); |
| 3458 | case NodeTypeFnCallExpr: | 3474 | case NodeTypeFnCallExpr: |
| ... | @@ -3510,7 +3526,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop | ... | @@ -3510,7 +3526,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 3510 | case NodeTypeSliceExpr: | 3526 | case NodeTypeSliceExpr: |
| 3511 | return ir_lval_wrap(irb, scope, ir_gen_slice(irb, scope, node), lval); | 3527 | return ir_lval_wrap(irb, scope, ir_gen_slice(irb, scope, node), lval); |
| 3512 | case NodeTypeUnwrapErrorExpr: | 3528 | case NodeTypeUnwrapErrorExpr: |
| 3513 | case NodeTypeCharLiteral: | | |
| 3514 | case NodeTypeZeroesLiteral: | 3529 | case NodeTypeZeroesLiteral: |
| 3515 | case NodeTypeVarLiteral: | 3530 | case NodeTypeVarLiteral: |
| 3516 | case NodeTypeFnProto: | 3531 | case NodeTypeFnProto: |
| ... | @@ -8893,47 +8908,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -8893,47 +8908,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 8893 | // } | 8908 | // } |
| 8894 | // zig_unreachable(); | 8909 | // zig_unreachable(); |
| 8895 | //} | 8910 | //} |
| 8896 | //static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context, | | |
| 8897 | // AstNode *node, LValPurpose purpose) | | |
| 8898 | //{ | | |
| 8899 | // TypeTableEntry *array_type = analyze_expression(g, import, context, nullptr, | | |
| 8900 | // node->data.array_access_expr.array_ref_expr); | | |
| 8901 | // | | |
| 8902 | // TypeTableEntry *return_type; | | |
| 8903 | // | | |
| 8904 | // if (array_type->id == TypeTableEntryIdInvalid) { | | |
| 8905 | // return_type = g->builtin_types.entry_invalid; | | |
| 8906 | // } else if (array_type->id == TypeTableEntryIdArray) { | | |
| 8907 | // if (array_type->data.array.len == 0) { | | |
| 8908 | // add_node_error(g, node, buf_sprintf("out of bounds array access")); | | |
| 8909 | // } | | |
| 8910 | // return_type = array_type->data.array.child_type; | | |
| 8911 | // } else if (array_type->id == TypeTableEntryIdPointer) { | | |
| 8912 | // if (array_type->data.pointer.is_const && purpose == LValPurposeAssign) { | | |
| 8913 | // add_node_error(g, node, buf_sprintf("cannot assign to constant")); | | |
| 8914 | // return g->builtin_types.entry_invalid; | | |
| 8915 | // } | | |
| 8916 | // return_type = array_type->data.pointer.child_type; | | |
| 8917 | // } else if (array_type->id == TypeTableEntryIdStruct && | | |
| 8918 | // array_type->data.structure.is_slice) | | |
| 8919 | // { | | |
| 8920 | // TypeTableEntry *pointer_type = array_type->data.structure.fields[0].type_entry; | | |
| 8921 | // if (pointer_type->data.pointer.is_const && purpose == LValPurposeAssign) { | | |
| 8922 | // add_node_error(g, node, buf_sprintf("cannot assign to constant")); | | |
| 8923 | // return g->builtin_types.entry_invalid; | | |
| 8924 | // } | | |
| 8925 | // return_type = pointer_type->data.pointer.child_type; | | |
| 8926 | // } else { | | |
| 8927 | // add_node_error(g, node, | | |
| 8928 | // buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name))); | | |
| 8929 | // return_type = g->builtin_types.entry_invalid; | | |
| 8930 | // } | | |
| 8931 | // | | |
| 8932 | // analyze_expression(g, import, context, g->builtin_types.entry_usize, node->data.array_access_expr.subscript); | | |
| 8933 | // | | |
| 8934 | // return return_type; | | |
| 8935 | //} | | |
| 8936 | // | | |
| 8937 | //static TypeTableEntry *analyze_unwrap_error_expr(CodeGen *g, ImportTableEntry *import, | 8911 | //static TypeTableEntry *analyze_unwrap_error_expr(CodeGen *g, ImportTableEntry *import, |
| 8938 | // BlockContext *parent_context, TypeTableEntry *expected_type, AstNode *node) | 8912 | // BlockContext *parent_context, TypeTableEntry *expected_type, AstNode *node) |
| 8939 | //{ | 8913 | //{ |
| ... | @@ -9120,18 +9094,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -9120,18 +9094,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 9120 | // } | 9094 | // } |
| 9121 | //} | 9095 | //} |
| 9122 | // | 9096 | // |
| 9123 | //static LLVMValueRef gen_array_ptr(CodeGen *g, AstNode *node) { | | |
| 9124 | // assert(node->type == NodeTypeArrayAccessExpr); | | |
| 9125 | // | | |
| 9126 | // AstNode *array_expr_node = node->data.array_access_expr.array_ref_expr; | | |
| 9127 | // TypeTableEntry *array_type = get_expr_type(array_expr_node); | | |
| 9128 | // | | |
| 9129 | // LLVMValueRef array_ptr = gen_array_base_ptr(g, array_expr_node); | | |
| 9130 | // | | |
| 9131 | // LLVMValueRef subscript_value = gen_expr(g, node->data.array_access_expr.subscript); | | |
| 9132 | // return gen_array_elem_ptr(g, node, array_ptr, array_type, subscript_value); | | |
| 9133 | //} | | |
| 9134 | // | | |
| 9135 | //static LLVMValueRef gen_unwrap_err_expr(CodeGen *g, AstNode *node) { | 9097 | //static LLVMValueRef gen_unwrap_err_expr(CodeGen *g, AstNode *node) { |
| 9136 | // assert(node->type == NodeTypeUnwrapErrorExpr); | 9098 | // assert(node->type == NodeTypeUnwrapErrorExpr); |
| 9137 | // | 9099 | // |