| ... | @@ -114,18 +114,20 @@ TypeTableEntry *new_type_table_entry(TypeTableEntryId id) { | ... | @@ -114,18 +114,20 @@ TypeTableEntry *new_type_table_entry(TypeTableEntryId id) { |
| 114 | return entry; | 114 | return entry; |
| 115 | } | 115 | } |
| 116 | | 116 | |
| 117 | static TypeTableEntry *get_number_literal_type_unsigned(CodeGen *g, uint64_t x) { | 117 | static NumLit get_number_literal_kind_unsigned(uint64_t x) { |
| 118 | NumLit kind; | | |
| 119 | if (x <= UINT8_MAX) { | 118 | if (x <= UINT8_MAX) { |
| 120 | kind = NumLitU8; | 119 | return NumLitU8; |
| 121 | } else if (x <= UINT16_MAX) { | 120 | } else if (x <= UINT16_MAX) { |
| 122 | kind = NumLitU16; | 121 | return NumLitU16; |
| 123 | } else if (x <= UINT32_MAX) { | 122 | } else if (x <= UINT32_MAX) { |
| 124 | kind = NumLitU32; | 123 | return NumLitU32; |
| 125 | } else { | 124 | } else { |
| 126 | kind = NumLitU64; | 125 | return NumLitU64; |
| 127 | } | 126 | } |
| 128 | return g->num_lit_types[kind]; | 127 | } |
| | 128 | |
| | 129 | static TypeTableEntry *get_number_literal_type_unsigned(CodeGen *g, uint64_t x) { |
| | 130 | return g->num_lit_types[get_number_literal_kind_unsigned(x)]; |
| 129 | } | 131 | } |
| 130 | | 132 | |
| 131 | TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const) { | 133 | TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const) { |
| ... | @@ -243,6 +245,26 @@ static TypeTableEntry *eval_const_expr(CodeGen *g, BlockContext *context, | ... | @@ -243,6 +245,26 @@ static TypeTableEntry *eval_const_expr(CodeGen *g, BlockContext *context, |
| 243 | case NodeTypeBinOpExpr: | 245 | case NodeTypeBinOpExpr: |
| 244 | zig_panic("TODO eval_const_expr bin op expr"); | 246 | zig_panic("TODO eval_const_expr bin op expr"); |
| 245 | break; | 247 | break; |
| | 248 | case NodeTypeCompilerFnType: |
| | 249 | { |
| | 250 | Buf *name = &node->data.compiler_fn_type.name; |
| | 251 | TypeTableEntry *expr_type = node->codegen_node->expr_node.type_entry; |
| | 252 | if (buf_eql_str(name, "sizeof")) { |
| | 253 | TypeTableEntry *target_type = node->data.compiler_fn_type.type->codegen_node->data.type_node.entry; |
| | 254 | out_number_literal->overflow = false; |
| | 255 | out_number_literal->data.x_uint = target_type->size_in_bits / 8; |
| | 256 | out_number_literal->kind = get_number_literal_kind_unsigned(out_number_literal->data.x_uint); |
| | 257 | |
| | 258 | return expr_type; |
| | 259 | } else if (buf_eql_str(name, "max_value")) { |
| | 260 | zig_panic("TODO eval_const_expr max_value"); |
| | 261 | } else if (buf_eql_str(name, "min_value")) { |
| | 262 | zig_panic("TODO eval_const_expr min_value"); |
| | 263 | } else { |
| | 264 | return g->builtin_types.entry_invalid; |
| | 265 | } |
| | 266 | break; |
| | 267 | } |
| 246 | case NodeTypeSymbol: | 268 | case NodeTypeSymbol: |
| 247 | { | 269 | { |
| 248 | VariableTableEntry *var = find_variable(context, &node->data.symbol); | 270 | VariableTableEntry *var = find_variable(context, &node->data.symbol); |