Browse Source

Fix demo for removing default struct values

gingerBill 7 years ago
parent
commit
718b80ba39
3 changed files with 7 additions and 5 deletions
  1. 4 1
      core/math.odin
  2. 1 1
      examples/demo.odin
  3. 2 3
      src/parser.cpp

+ 4 - 1
core/math.odin

@@ -23,7 +23,10 @@ Mat2 :: distinct [2][2]f32;
 Mat3 :: distinct [3][3]f32;
 Mat3 :: distinct [3][3]f32;
 Mat4 :: distinct [4][4]f32;
 Mat4 :: distinct [4][4]f32;
 
 
-Quat :: struct {x, y, z: f32, w: f32 = 1};
+Quat :: struct {x, y, z, w: f32};
+
+QUAT_IDENTITY := Quat{x = 0, y = 0, z = 0, w = 1};
+
 
 
 @(default_calling_convention="c")
 @(default_calling_convention="c")
 foreign __llvm_core {
 foreign __llvm_core {

+ 1 - 1
examples/demo.odin

@@ -154,7 +154,7 @@ union_type :: proc() {
 	}
 	}
 
 
 	Vector3 :: struct {x, y, z: f32};
 	Vector3 :: struct {x, y, z: f32};
-	Quaternion :: struct {x, y, z: f32, w: f32 = 1};
+	Quaternion :: struct {x, y, z, w: f32};
 
 
 	// More realistic examples
 	// More realistic examples
 	{
 	{

+ 2 - 3
src/parser.cpp

@@ -2889,7 +2889,7 @@ AstNode *parse_struct_field_list(AstFile *f, isize *name_count_) {
 
 
 	isize total_name_count = 0;
 	isize total_name_count = 0;
 
 
-	AstNode *params = parse_field_list(f, &total_name_count, FieldFlag_Struct, Token_CloseBrace, true, false);
+	AstNode *params = parse_field_list(f, &total_name_count, FieldFlag_Struct, Token_CloseBrace, false, false);
 	if (name_count_) *name_count_ = total_name_count;
 	if (name_count_) *name_count_ = total_name_count;
 	return params;
 	return params;
 }
 }
@@ -2948,7 +2948,6 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok
 		}
 		}
 
 
 		if (allow_token(f, Token_Eq)) {
 		if (allow_token(f, Token_Eq)) {
-			// TODO(bill): Should this be true==lhs or false==rhs?
 			default_value = parse_expr(f, false);
 			default_value = parse_expr(f, false);
 			if (!allow_default_parameters) {
 			if (!allow_default_parameters) {
 				syntax_error(f->curr_token, "Default parameters are only allowed for procedures");
 				syntax_error(f->curr_token, "Default parameters are only allowed for procedures");
@@ -3001,10 +3000,10 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok
 			}
 			}
 
 
 			if (allow_token(f, Token_Eq)) {
 			if (allow_token(f, Token_Eq)) {
-				// TODO(bill): Should this be true==lhs or false==rhs?
 				default_value = parse_expr(f, false);
 				default_value = parse_expr(f, false);
 				if (!allow_default_parameters) {
 				if (!allow_default_parameters) {
 					syntax_error(f->curr_token, "Default parameters are only allowed for procedures");
 					syntax_error(f->curr_token, "Default parameters are only allowed for procedures");
+				default_value = nullptr;
 				}
 				}
 			}
 			}