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
149149
150150GroupedExpression = "(" Expression ")"
151151
152KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "zeroes" | "error" | "type" | "this"
152KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this"
153153
154154ContainerDecl = option("extern") ("struct" | "enum" | "union") "{" many(StructMember) "}"
155155
src/all_types.hpp-6
......@@ -126,7 +126,6 @@ enum ConstValSpecial {
126126 ConstValSpecialRuntime,
127127 ConstValSpecialStatic,
128128 ConstValSpecialUndef,
129 ConstValSpecialZeroes,
130129};
131130
132131enum RuntimeHintErrorUnion {
......@@ -271,7 +270,6 @@ enum NodeType {
271270 NodeTypeBoolLiteral,
272271 NodeTypeNullLiteral,
273272 NodeTypeUndefinedLiteral,
274 NodeTypeZeroesLiteral,
275273 NodeTypeThisLiteral,
276274 NodeTypeIfBoolExpr,
277275 NodeTypeIfVarExpr,
......@@ -655,9 +653,6 @@ struct AstNodeNullLiteral {
655653struct AstNodeUndefinedLiteral {
656654};
657655
658struct AstNodeZeroesLiteral {
659};
660
661656struct AstNodeThisLiteral {
662657};
663658
......@@ -737,7 +732,6 @@ struct AstNode {
737732 AstNodeStructValueField struct_val_field;
738733 AstNodeNullLiteral null_literal;
739734 AstNodeUndefinedLiteral undefined_literal;
740 AstNodeZeroesLiteral zeroes_literal;
741735 AstNodeThisLiteral this_literal;
742736 AstNodeSymbolExpr symbol_expr;
743737 AstNodeBoolLiteral bool_literal;
src/analyze.cpp-5
......@@ -60,7 +60,6 @@ AstNode *first_executing_node(AstNode *node) {
6060 case NodeTypeBoolLiteral:
6161 case NodeTypeNullLiteral:
6262 case NodeTypeUndefinedLiteral:
63 case NodeTypeZeroesLiteral:
6463 case NodeTypeThisLiteral:
6564 case NodeTypeIfBoolExpr:
6665 case NodeTypeIfVarExpr:
......@@ -1793,7 +1792,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
17931792 case NodeTypeBoolLiteral:
17941793 case NodeTypeNullLiteral:
17951794 case NodeTypeUndefinedLiteral:
1796 case NodeTypeZeroesLiteral:
17971795 case NodeTypeThisLiteral:
17981796 case NodeTypeSymbol:
17991797 case NodeTypePrefixOpExpr:
......@@ -3403,9 +3401,6 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
34033401 case ConstValSpecialUndef:
34043402 buf_appendf(buf, "undefined");
34053403 return;
3406 case ConstValSpecialZeroes:
3407 buf_appendf(buf, "zeroes");
3408 return;
34093404 case ConstValSpecialStatic:
34103405 break;
34113406 }
src/ast_render.cpp-3
......@@ -177,8 +177,6 @@ static const char *node_type_str(NodeType node_type) {
177177 return "NullLiteral";
178178 case NodeTypeUndefinedLiteral:
179179 return "UndefinedLiteral";
180 case NodeTypeZeroesLiteral:
181 return "ZeroesLiteral";
182180 case NodeTypeThisLiteral:
183181 return "ThisLiteral";
184182 case NodeTypeIfBoolExpr:
......@@ -877,7 +875,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
877875 case NodeTypeErrorValueDecl:
878876 case NodeTypeStructField:
879877 case NodeTypeUse:
880 case NodeTypeZeroesLiteral:
881878 zig_panic("TODO more ast rendering");
882879 }
883880}
src/codegen.cpp+2-7
......@@ -1244,13 +1244,10 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
12441244 IrInstruction *init_value = decl_var_instruction->init_value;
12451245
12461246 bool have_init_expr = false;
1247 bool want_zeroes = false;
12481247
12491248 ConstExprValue *const_val = &init_value->value;
12501249 if (const_val->special == ConstValSpecialRuntime || const_val->special == ConstValSpecialStatic)
12511250 have_init_expr = true;
1252 if (const_val->special == ConstValSpecialZeroes)
1253 want_zeroes = true;
12541251
12551252 if (have_init_expr) {
12561253 assert(var->value.type == init_value->value.type);
......@@ -1259,14 +1256,14 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
12591256 bool ignore_uninit = false;
12601257 // handle runtime stack allocation
12611258 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) {
12631260 TypeTableEntry *usize = g->builtin_types.entry_usize;
12641261 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value.type->type_ref);
12651262 uint64_t align_bytes = get_memcpy_align(g, var->value.type);
12661263
12671264 // memset uninitialized memory to 0xa
12681265 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);
12701267 LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, var->value_ref, ptr_u8, "");
12711268 LLVMValueRef byte_count = LLVMConstInt(usize->type_ref, size_bytes, false);
12721269 LLVMValueRef align_in_bytes = LLVMConstInt(LLVMInt32Type(), align_bytes, false);
......@@ -2440,8 +2437,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
24402437 zig_unreachable();
24412438 case ConstValSpecialUndef:
24422439 return LLVMGetUndef(canon_type->type_ref);
2443 case ConstValSpecialZeroes:
2444 return LLVMConstNull(canon_type->type_ref);
24452440 case ConstValSpecialStatic:
24462441 break;
24472442
src/ir.cpp-5
......@@ -5223,8 +5223,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
52235223 zig_panic("TODO IR gen NodeTypeErrorValueDecl");
52245224 case NodeTypeTypeDecl:
52255225 zig_panic("TODO IR gen NodeTypeTypeDecl");
5226 case NodeTypeZeroesLiteral:
5227 zig_panic("TODO zeroes is deprecated");
52285226 }
52295227 zig_unreachable();
52305228}
......@@ -5930,9 +5928,6 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
59305928 ir_add_error(ira, value, buf_sprintf("use of undefined value"));
59315929 return nullptr;
59325930 }
5933 case ConstValSpecialZeroes:
5934 ir_add_error(ira, value, buf_sprintf("zeroes is deprecated"));
5935 return nullptr;
59365931 }
59375932 zig_unreachable();
59385933}
src/parser.cpp+1-8
......@@ -622,7 +622,7 @@ static AstNode *ast_parse_goto_expr(ParseContext *pc, size_t *token_index, bool
622622}
623623/*
624624PrimaryExpression = 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"
626626*/
627627static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
628628 Token *token = &pc->tokens->at(*token_index);
......@@ -670,10 +670,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
670670 AstNode *node = ast_create_node(pc, NodeTypeUndefinedLiteral, token);
671671 *token_index += 1;
672672 return node;
673 } else if (token->id == TokenIdKeywordZeroes) {
674 AstNode *node = ast_create_node(pc, NodeTypeZeroesLiteral, token);
675 *token_index += 1;
676 return node;
677673 } else if (token->id == TokenIdKeywordThis) {
678674 AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token);
679675 *token_index += 1;
......@@ -2585,9 +2581,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
25852581 case NodeTypeUndefinedLiteral:
25862582 // none
25872583 break;
2588 case NodeTypeZeroesLiteral:
2589 // none
2590 break;
25912584 case NodeTypeThisLiteral:
25922585 // none
25932586 break;
src/tokenizer.cpp-2
......@@ -140,7 +140,6 @@ static const struct ZigKeyword zig_keywords[] = {
140140 {"var", TokenIdKeywordVar},
141141 {"volatile", TokenIdKeywordVolatile},
142142 {"while", TokenIdKeywordWhile},
143 {"zeroes", TokenIdKeywordZeroes},
144143};
145144
146145bool is_zig_keyword(Buf *buf) {
......@@ -1472,7 +1471,6 @@ const char * token_name(TokenId id) {
14721471 case TokenIdKeywordNoAlias: return "noalias";
14731472 case TokenIdKeywordSwitch: return "switch";
14741473 case TokenIdKeywordUndefined: return "undefined";
1475 case TokenIdKeywordZeroes: return "zeroes";
14761474 case TokenIdKeywordThis: return "this";
14771475 case TokenIdKeywordError: return "error";
14781476 case TokenIdKeywordType: return "type";
src/tokenizer.hpp-1
......@@ -40,7 +40,6 @@ enum TokenId {
4040 TokenIdKeywordNoAlias,
4141 TokenIdKeywordSwitch,
4242 TokenIdKeywordUndefined,
43 TokenIdKeywordZeroes,
4443 TokenIdKeywordError,
4544 TokenIdKeywordType,
4645 TokenIdKeywordInline,