authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-16 17:24:13-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-16 17:24:13-05:00
log6a5e61acd117277eb2f943f5bc02ff7043542d4b
tree851a4debd13042f4f1fc30dcffb692bf205a5c9b
parentab8b14aa9fd6d434864476a37fb6fca75fedb121

get rid of zeroes literal

closes #222

9 files changed, 4 insertions(+), 38 deletions(-)

doc/langref.md+1-1
...@@ -149,7 +149,7 @@ GotoExpression = option("inline") "goto" Symbol...@@ -149,7 +149,7 @@ GotoExpression = option("inline") "goto" Symbol
149149
150GroupedExpression = "(" Expression ")"150GroupedExpression = "(" Expression ")"
151151
152KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type" | "this"152KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this"
153153
154ContainerDecl = option("extern") ("struct" | "enum" | "union") "{" many(StructMember) "}"154ContainerDecl = option("extern") ("struct" | "enum" | "union") "{" many(StructMember) "}"
155155
src/all_types.hpp-6
...@@ -126,7 +126,6 @@ enum ConstValSpecial {...@@ -126,7 +126,6 @@ enum ConstValSpecial {
126 ConstValSpecialRuntime,126 ConstValSpecialRuntime,
127 ConstValSpecialStatic,127 ConstValSpecialStatic,
128 ConstValSpecialUndef,128 ConstValSpecialUndef,
129 ConstValSpecialZeroes,
130};129};
131130
132enum RuntimeHintErrorUnion {131enum RuntimeHintErrorUnion {
...@@ -271,7 +270,6 @@ enum NodeType {...@@ -271,7 +270,6 @@ enum NodeType {
271 NodeTypeBoolLiteral,270 NodeTypeBoolLiteral,
272 NodeTypeNullLiteral,271 NodeTypeNullLiteral,
273 NodeTypeUndefinedLiteral,272 NodeTypeUndefinedLiteral,
274 NodeTypeZeroesLiteral,
275 NodeTypeThisLiteral,273 NodeTypeThisLiteral,
276 NodeTypeIfBoolExpr,274 NodeTypeIfBoolExpr,
277 NodeTypeIfVarExpr,275 NodeTypeIfVarExpr,
...@@ -655,9 +653,6 @@ struct AstNodeNullLiteral {...@@ -655,9 +653,6 @@ struct AstNodeNullLiteral {
655struct AstNodeUndefinedLiteral {653struct AstNodeUndefinedLiteral {
656};654};
657655
658struct AstNodeZeroesLiteral {
659};
660
661struct AstNodeThisLiteral {656struct AstNodeThisLiteral {
662};657};
663658
...@@ -737,7 +732,6 @@ struct AstNode {...@@ -737,7 +732,6 @@ struct AstNode {
737 AstNodeStructValueField struct_val_field;732 AstNodeStructValueField struct_val_field;
738 AstNodeNullLiteral null_literal;733 AstNodeNullLiteral null_literal;
739 AstNodeUndefinedLiteral undefined_literal;734 AstNodeUndefinedLiteral undefined_literal;
740 AstNodeZeroesLiteral zeroes_literal;
741 AstNodeThisLiteral this_literal;735 AstNodeThisLiteral this_literal;
742 AstNodeSymbolExpr symbol_expr;736 AstNodeSymbolExpr symbol_expr;
743 AstNodeBoolLiteral bool_literal;737 AstNodeBoolLiteral bool_literal;
src/analyze.cpp-5
...@@ -60,7 +60,6 @@ AstNode *first_executing_node(AstNode *node) {...@@ -60,7 +60,6 @@ AstNode *first_executing_node(AstNode *node) {
60 case NodeTypeBoolLiteral:60 case NodeTypeBoolLiteral:
61 case NodeTypeNullLiteral:61 case NodeTypeNullLiteral:
62 case NodeTypeUndefinedLiteral:62 case NodeTypeUndefinedLiteral:
63 case NodeTypeZeroesLiteral:
64 case NodeTypeThisLiteral:63 case NodeTypeThisLiteral:
65 case NodeTypeIfBoolExpr:64 case NodeTypeIfBoolExpr:
66 case NodeTypeIfVarExpr:65 case NodeTypeIfVarExpr:
...@@ -1793,7 +1792,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -1793,7 +1792,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
1793 case NodeTypeBoolLiteral:1792 case NodeTypeBoolLiteral:
1794 case NodeTypeNullLiteral:1793 case NodeTypeNullLiteral:
1795 case NodeTypeUndefinedLiteral:1794 case NodeTypeUndefinedLiteral:
1796 case NodeTypeZeroesLiteral:
1797 case NodeTypeThisLiteral:1795 case NodeTypeThisLiteral:
1798 case NodeTypeSymbol:1796 case NodeTypeSymbol:
1799 case NodeTypePrefixOpExpr:1797 case NodeTypePrefixOpExpr:
...@@ -3403,9 +3401,6 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {...@@ -3403,9 +3401,6 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
3403 case ConstValSpecialUndef:3401 case ConstValSpecialUndef:
3404 buf_appendf(buf, "undefined");3402 buf_appendf(buf, "undefined");
3405 return;3403 return;
3406 case ConstValSpecialZeroes:
3407 buf_appendf(buf, "zeroes");
3408 return;
3409 case ConstValSpecialStatic:3404 case ConstValSpecialStatic:
3410 break;3405 break;
3411 }3406 }
src/ast_render.cpp-3
...@@ -177,8 +177,6 @@ static const char *node_type_str(NodeType node_type) {...@@ -177,8 +177,6 @@ static const char *node_type_str(NodeType node_type) {
177 return "NullLiteral";177 return "NullLiteral";
178 case NodeTypeUndefinedLiteral:178 case NodeTypeUndefinedLiteral:
179 return "UndefinedLiteral";179 return "UndefinedLiteral";
180 case NodeTypeZeroesLiteral:
181 return "ZeroesLiteral";
182 case NodeTypeThisLiteral:180 case NodeTypeThisLiteral:
183 return "ThisLiteral";181 return "ThisLiteral";
184 case NodeTypeIfBoolExpr:182 case NodeTypeIfBoolExpr:
...@@ -877,7 +875,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -877,7 +875,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
877 case NodeTypeErrorValueDecl:875 case NodeTypeErrorValueDecl:
878 case NodeTypeStructField:876 case NodeTypeStructField:
879 case NodeTypeUse:877 case NodeTypeUse:
880 case NodeTypeZeroesLiteral:
881 zig_panic("TODO more ast rendering");878 zig_panic("TODO more ast rendering");
882 }879 }
883}880}
src/codegen.cpp+2-7
...@@ -1244,13 +1244,10 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,...@@ -1244,13 +1244,10 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
1244 IrInstruction *init_value = decl_var_instruction->init_value;1244 IrInstruction *init_value = decl_var_instruction->init_value;
12451245
1246 bool have_init_expr = false;1246 bool have_init_expr = false;
1247 bool want_zeroes = false;
12481247
1249 ConstExprValue *const_val = &init_value->value;1248 ConstExprValue *const_val = &init_value->value;
1250 if (const_val->special == ConstValSpecialRuntime || const_val->special == ConstValSpecialStatic)1249 if (const_val->special == ConstValSpecialRuntime || const_val->special == ConstValSpecialStatic)
1251 have_init_expr = true;1250 have_init_expr = true;
1252 if (const_val->special == ConstValSpecialZeroes)
1253 want_zeroes = true;
12541251
1255 if (have_init_expr) {1252 if (have_init_expr) {
1256 assert(var->value.type == init_value->value.type);1253 assert(var->value.type == init_value->value.type);
...@@ -1259,14 +1256,14 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,...@@ -1259,14 +1256,14 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
1259 bool ignore_uninit = false;1256 bool ignore_uninit = false;
1260 // handle runtime stack allocation1257 // handle runtime stack allocation
1261 bool want_safe = ir_want_debug_safety(g, &decl_var_instruction->base);1258 bool want_safe = ir_want_debug_safety(g, &decl_var_instruction->base);
1262 if (!ignore_uninit && (want_safe || want_zeroes)) {1259 if (!ignore_uninit && want_safe) {
1263 TypeTableEntry *usize = g->builtin_types.entry_usize;1260 TypeTableEntry *usize = g->builtin_types.entry_usize;
1264 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value.type->type_ref);1261 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value.type->type_ref);
1265 uint64_t align_bytes = get_memcpy_align(g, var->value.type);1262 uint64_t align_bytes = get_memcpy_align(g, var->value.type);
12661263
1267 // memset uninitialized memory to 0xa1264 // memset uninitialized memory to 0xa
1268 LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0);1265 LLVMTypeRef ptr_u8 = LLVMPointerType(LLVMInt8Type(), 0);
1269 LLVMValueRef fill_char = LLVMConstInt(LLVMInt8Type(), want_zeroes ? 0x00 : 0xaa, false);1266 LLVMValueRef fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
1270 LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, var->value_ref, ptr_u8, "");1267 LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, var->value_ref, ptr_u8, "");
1271 LLVMValueRef byte_count = LLVMConstInt(usize->type_ref, size_bytes, false);1268 LLVMValueRef byte_count = LLVMConstInt(usize->type_ref, size_bytes, false);
1272 LLVMValueRef align_in_bytes = LLVMConstInt(LLVMInt32Type(), align_bytes, false);1269 LLVMValueRef align_in_bytes = LLVMConstInt(LLVMInt32Type(), align_bytes, false);
...@@ -2440,8 +2437,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {...@@ -2440,8 +2437,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
2440 zig_unreachable();2437 zig_unreachable();
2441 case ConstValSpecialUndef:2438 case ConstValSpecialUndef:
2442 return LLVMGetUndef(canon_type->type_ref);2439 return LLVMGetUndef(canon_type->type_ref);
2443 case ConstValSpecialZeroes:
2444 return LLVMConstNull(canon_type->type_ref);
2445 case ConstValSpecialStatic:2440 case ConstValSpecialStatic:
2446 break;2441 break;
24472442
src/ir.cpp-5
...@@ -5223,8 +5223,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -5223,8 +5223,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
5223 zig_panic("TODO IR gen NodeTypeErrorValueDecl");5223 zig_panic("TODO IR gen NodeTypeErrorValueDecl");
5224 case NodeTypeTypeDecl:5224 case NodeTypeTypeDecl:
5225 zig_panic("TODO IR gen NodeTypeTypeDecl");5225 zig_panic("TODO IR gen NodeTypeTypeDecl");
5226 case NodeTypeZeroesLiteral:
5227 zig_panic("TODO zeroes is deprecated");
5228 }5226 }
5229 zig_unreachable();5227 zig_unreachable();
5230}5228}
...@@ -5930,9 +5928,6 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un...@@ -5930,9 +5928,6 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
5930 ir_add_error(ira, value, buf_sprintf("use of undefined value"));5928 ir_add_error(ira, value, buf_sprintf("use of undefined value"));
5931 return nullptr;5929 return nullptr;
5932 }5930 }
5933 case ConstValSpecialZeroes:
5934 ir_add_error(ira, value, buf_sprintf("zeroes is deprecated"));
5935 return nullptr;
5936 }5931 }
5937 zig_unreachable();5932 zig_unreachable();
5938}5933}
src/parser.cpp+1-8
...@@ -622,7 +622,7 @@ static AstNode *ast_parse_goto_expr(ParseContext *pc, size_t *token_index, bool...@@ -622,7 +622,7 @@ static AstNode *ast_parse_goto_expr(ParseContext *pc, size_t *token_index, bool
622}622}
623/*623/*
624PrimaryExpression = Number | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl624PrimaryExpression = Number | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl
625KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type" | "this"625KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this"
626*/626*/
627static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {627static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
628 Token *token = &pc->tokens->at(*token_index);628 Token *token = &pc->tokens->at(*token_index);
...@@ -670,10 +670,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo...@@ -670,10 +670,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
670 AstNode *node = ast_create_node(pc, NodeTypeUndefinedLiteral, token);670 AstNode *node = ast_create_node(pc, NodeTypeUndefinedLiteral, token);
671 *token_index += 1;671 *token_index += 1;
672 return node;672 return node;
673 } else if (token->id == TokenIdKeywordZeroes) {
674 AstNode *node = ast_create_node(pc, NodeTypeZeroesLiteral, token);
675 *token_index += 1;
676 return node;
677 } else if (token->id == TokenIdKeywordThis) {673 } else if (token->id == TokenIdKeywordThis) {
678 AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token);674 AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token);
679 *token_index += 1;675 *token_index += 1;
...@@ -2585,9 +2581,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -2585,9 +2581,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
2585 case NodeTypeUndefinedLiteral:2581 case NodeTypeUndefinedLiteral:
2586 // none2582 // none
2587 break;2583 break;
2588 case NodeTypeZeroesLiteral:
2589 // none
2590 break;
2591 case NodeTypeThisLiteral:2584 case NodeTypeThisLiteral:
2592 // none2585 // none
2593 break;2586 break;
src/tokenizer.cpp-2
...@@ -140,7 +140,6 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -140,7 +140,6 @@ static const struct ZigKeyword zig_keywords[] = {
140 {"var", TokenIdKeywordVar},140 {"var", TokenIdKeywordVar},
141 {"volatile", TokenIdKeywordVolatile},141 {"volatile", TokenIdKeywordVolatile},
142 {"while", TokenIdKeywordWhile},142 {"while", TokenIdKeywordWhile},
143 {"zeroes", TokenIdKeywordZeroes},
144};143};
145144
146bool is_zig_keyword(Buf *buf) {145bool is_zig_keyword(Buf *buf) {
...@@ -1472,7 +1471,6 @@ const char * token_name(TokenId id) {...@@ -1472,7 +1471,6 @@ const char * token_name(TokenId id) {
1472 case TokenIdKeywordNoAlias: return "noalias";1471 case TokenIdKeywordNoAlias: return "noalias";
1473 case TokenIdKeywordSwitch: return "switch";1472 case TokenIdKeywordSwitch: return "switch";
1474 case TokenIdKeywordUndefined: return "undefined";1473 case TokenIdKeywordUndefined: return "undefined";
1475 case TokenIdKeywordZeroes: return "zeroes";
1476 case TokenIdKeywordThis: return "this";1474 case TokenIdKeywordThis: return "this";
1477 case TokenIdKeywordError: return "error";1475 case TokenIdKeywordError: return "error";
1478 case TokenIdKeywordType: return "type";1476 case TokenIdKeywordType: return "type";
src/tokenizer.hpp-1
...@@ -40,7 +40,6 @@ enum TokenId {...@@ -40,7 +40,6 @@ enum TokenId {
40 TokenIdKeywordNoAlias,40 TokenIdKeywordNoAlias,
41 TokenIdKeywordSwitch,41 TokenIdKeywordSwitch,
42 TokenIdKeywordUndefined,42 TokenIdKeywordUndefined,
43 TokenIdKeywordZeroes,
44 TokenIdKeywordError,43 TokenIdKeywordError,
45 TokenIdKeywordType,44 TokenIdKeywordType,
46 TokenIdKeywordInline,45 TokenIdKeywordInline,