Przeglądaj źródła

Change procedure group syntax from `proc[]` to `proc{}`; deprecate `proc[]` (raises warning currently)

gingerBill 6 lat temu
rodzic
commit
28583bfff8

+ 10 - 10
core/bits/bits.odin

@@ -66,7 +66,7 @@ byte_swap_int :: proc(i: int) -> int {
 	}
 }
 
-byte_swap :: proc[
+byte_swap :: proc{
 	byte_swap_u16,
 	byte_swap_u32,
 	byte_swap_u64,
@@ -75,7 +75,7 @@ byte_swap :: proc[
 	byte_swap_i64,
 	byte_swap_uint,
 	byte_swap_int,
-];
+};
 
 count_zeros8   :: proc(i:   u8) ->   u8 { return   8 - count_ones8(i); }
 count_zeros16  :: proc(i:  u16) ->  u16 { return  16 - count_ones16(i); }
@@ -150,13 +150,13 @@ overflowing_add_int :: proc(lhs, rhs: int) -> (int, bool) {
 	}
 }
 
-overflowing_add :: proc[
+overflowing_add :: proc{
 	overflowing_add_u8,   overflowing_add_i8,
 	overflowing_add_u16,  overflowing_add_i16,
 	overflowing_add_u32,  overflowing_add_i32,
 	overflowing_add_u64,  overflowing_add_i64,
 	overflowing_add_uint, overflowing_add_int,
-];
+};
 
 foreign {
 	@(link_name="llvm.usub.with.overflow.i8")  overflowing_sub_u8  :: proc(lhs, rhs:  u8) -> (u8, bool)  ---
@@ -187,13 +187,13 @@ overflowing_sub_int :: proc(lhs, rhs: int) -> (int, bool) {
 	}
 }
 
-overflowing_sub :: proc[
+overflowing_sub :: proc{
 	overflowing_sub_u8,   overflowing_sub_i8,
 	overflowing_sub_u16,  overflowing_sub_i16,
 	overflowing_sub_u32,  overflowing_sub_i32,
 	overflowing_sub_u64,  overflowing_sub_i64,
 	overflowing_sub_uint, overflowing_sub_int,
-];
+};
 
 
 foreign {
@@ -225,13 +225,13 @@ overflowing_mul_int :: proc(lhs, rhs: int) -> (int, bool) {
 	}
 }
 
-overflowing_mul :: proc[
+overflowing_mul :: proc{
 	overflowing_mul_u8,   overflowing_mul_i8,
 	overflowing_mul_u16,  overflowing_mul_i16,
 	overflowing_mul_u32,  overflowing_mul_i32,
 	overflowing_mul_u64,  overflowing_mul_i64,
 	overflowing_mul_uint, overflowing_mul_int,
-];
+};
 
 is_power_of_two_u8   :: proc(i:   u8) -> bool { return i > 0 && (i & (i-1)) == 0; }
 is_power_of_two_i8   :: proc(i:   i8) -> bool { return i > 0 && (i & (i-1)) == 0; }
@@ -244,10 +244,10 @@ is_power_of_two_i64  :: proc(i:  i64) -> bool { return i > 0 && (i & (i-1)) == 0
 is_power_of_two_uint :: proc(i: uint) -> bool { return i > 0 && (i & (i-1)) == 0; }
 is_power_of_two_int  :: proc(i:  int) -> bool { return i > 0 && (i & (i-1)) == 0; }
 
-is_power_of_two :: proc[
+is_power_of_two :: proc{
 	is_power_of_two_u8,   is_power_of_two_i8,
 	is_power_of_two_u16,  is_power_of_two_i16,
 	is_power_of_two_u32,  is_power_of_two_i32,
 	is_power_of_two_u64,  is_power_of_two_i64,
 	is_power_of_two_uint, is_power_of_two_int,
-]
+};

+ 21 - 23
core/math/math.odin

@@ -63,7 +63,7 @@ foreign _ {
 	log_f64 :: proc(x: f64) -> f64 ---;
 }
 
-log :: proc[log_f32, log_f64];
+log :: proc{log_f32, log_f64};
 
 tan_f32 :: proc "c" (θ: f32) -> f32 { return sin(θ)/cos(θ); }
 tan_f64 :: proc "c" (θ: f64) -> f64 { return sin(θ)/cos(θ); }
@@ -94,31 +94,31 @@ copy_sign_f64 :: proc(x, y: f64) -> f64 {
 }
 
 
-sqrt      :: proc[sqrt_f32, sqrt_f64];
-sin       :: proc[sin_f32, sin_f64];
-cos       :: proc[cos_f32, cos_f64];
-tan       :: proc[tan_f32, tan_f64];
-pow       :: proc[pow_f32, pow_f64];
-fmuladd   :: proc[fmuladd_f32, fmuladd_f64];
-sign      :: proc[sign_f32, sign_f64];
-copy_sign :: proc[copy_sign_f32, copy_sign_f64];
+sqrt      :: proc{sqrt_f32, sqrt_f64};
+sin       :: proc{sin_f32, sin_f64};
+cos       :: proc{cos_f32, cos_f64};
+tan       :: proc{tan_f32, tan_f64};
+pow       :: proc{pow_f32, pow_f64};
+fmuladd   :: proc{fmuladd_f32, fmuladd_f64};
+sign      :: proc{sign_f32, sign_f64};
+copy_sign :: proc{copy_sign_f32, copy_sign_f64};
 
 
 round_f32 :: proc(x: f32) -> f32 { return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5); }
 round_f64 :: proc(x: f64) -> f64 { return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5); }
-round :: proc[round_f32, round_f64];
+round :: proc{round_f32, round_f64};
 
 floor_f32 :: proc(x: f32) -> f32 { return x >= 0 ? f32(i64(x)) : f32(i64(x-0.5)); } // TODO: Get accurate versions
 floor_f64 :: proc(x: f64) -> f64 { return x >= 0 ? f64(i64(x)) : f64(i64(x-0.5)); } // TODO: Get accurate versions
-floor :: proc[floor_f32, floor_f64];
+floor :: proc{floor_f32, floor_f64};
 
 ceil_f32 :: proc(x: f32) -> f32 { return x < 0 ? f32(i64(x)) : f32(i64(x+1)); }// TODO: Get accurate versions
 ceil_f64 :: proc(x: f64) -> f64 { return x < 0 ? f64(i64(x)) : f64(i64(x+1)); }// TODO: Get accurate versions
-ceil :: proc[ceil_f32, ceil_f64];
+ceil :: proc{ceil_f32, ceil_f64};
 
 remainder_f32 :: proc(x, y: f32) -> f32 { return x - round(x/y) * y; }
 remainder_f64 :: proc(x, y: f64) -> f64 { return x - round(x/y) * y; }
-remainder :: proc[remainder_f32, remainder_f64];
+remainder :: proc{remainder_f32, remainder_f64};
 
 mod_f32 :: proc(x, y: f32) -> f32 {
 	result: f32;
@@ -138,7 +138,7 @@ mod_f64 :: proc(x, y: f64) -> f64 {
 	}
 	return copy_sign(result, x);
 }
-mod :: proc[mod_f32, mod_f64];
+mod :: proc{mod_f32, mod_f64};
 
 
 
@@ -148,19 +148,17 @@ to_degrees :: proc(radians: f32) -> f32 { return radians * 360 / TAU; }
 
 
 
-mul :: proc[
+mul :: proc{
 	mat3_mul,
 	mat4_mul, mat4_mul_vec4,
 	quat_mul, quat_mulf,
-];
+};
 
-div :: proc[
-	quat_div, quat_divf,
-];
+div :: proc{quat_div, quat_divf};
 
-inverse :: proc[mat4_inverse, quat_inverse];
-dot     :: proc[vec_dot, quat_dot];
-cross   :: proc[cross2, cross3];
+inverse :: proc{mat4_inverse, quat_inverse};
+dot     :: proc{vec_dot, quat_dot};
+cross   :: proc{cross2, cross3};
 
 vec_dot :: proc(a, b: $T/[$N]$E) -> E {
 	res: E;
@@ -361,7 +359,7 @@ scale_f32 :: proc(m: Mat4, s: f32) -> Mat4 {
 	return m;
 }
 
-scale :: proc[scale_vec3, scale_f32];
+scale :: proc{scale_vec3, scale_f32};
 
 
 look_at :: proc(eye, centre, up: Vec3) -> Mat4 {

+ 4 - 4
core/mem/alloc.odin

@@ -74,13 +74,13 @@ delete_map :: proc(m: $T/map[$K]$V, loc := #caller_location) {
 }
 
 
-delete :: proc[
+delete :: proc{
 	delete_string,
 	delete_cstring,
 	delete_dynamic_array,
 	delete_slice,
 	delete_map,
-];
+};
 
 
 new :: inline proc($T: typeid, allocator := context.allocator, loc := #caller_location) -> ^T {
@@ -122,13 +122,13 @@ make_map :: proc($T: typeid/map[$K]$E, auto_cast cap: int = 16, allocator := con
 	return m;
 }
 
-make :: proc[
+make :: proc{
 	make_slice,
 	make_dynamic_array,
 	make_dynamic_array_len,
 	make_dynamic_array_len_cap,
 	make_map,
-];
+};
 
 
 

+ 1 - 1
core/mem/mem.odin

@@ -5,7 +5,7 @@ foreign _ {
 	@(link_name = "llvm.bswap.i32") swap32 :: proc(b: u32) -> u32 ---;
 	@(link_name = "llvm.bswap.i64") swap64 :: proc(b: u64) -> u64 ---;
 }
-swap :: proc[swap16, swap32, swap64];
+swap :: proc{swap16, swap32, swap64};
 
 
 

+ 1 - 1
core/mem/raw.odin

@@ -46,6 +46,6 @@ raw_dynamic_array_data :: inline proc(a: $T/[dynamic]$E) -> ^E {
 	return cast(^E)(^Raw_Dynamic_Array)(&a).data;
 }
 
-raw_data :: proc[raw_string_data, raw_slice_data, raw_dynamic_array_data];
+raw_data :: proc{raw_string_data, raw_slice_data, raw_dynamic_array_data};
 
 

+ 14 - 14
core/runtime/core.odin

@@ -401,44 +401,44 @@ ordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_locati
 
 
 @(builtin)
-clear :: proc[clear_dynamic_array, clear_map];
+clear :: proc{clear_dynamic_array, clear_map};
 
 @(builtin)
-reserve :: proc[reserve_dynamic_array, reserve_map];
+reserve :: proc{reserve_dynamic_array, reserve_map};
 
 @(builtin)
-resize :: proc[resize_dynamic_array];
+resize :: proc{resize_dynamic_array};
 
 
 @(builtin)
-new :: proc[mem.new];
+new :: proc{mem.new};
 
 @(builtin)
-new_clone :: proc[mem.new_clone];
+new_clone :: proc{mem.new_clone};
 
 @(builtin)
-free :: proc[mem.free];
+free :: proc{mem.free};
 
 @(builtin)
-free_all :: proc[mem.free_all];
+free_all :: proc{mem.free_all};
 
 @(builtin)
-delete :: proc[
+delete :: proc{
 	mem.delete_string,
 	mem.delete_cstring,
 	mem.delete_dynamic_array,
 	mem.delete_slice,
 	mem.delete_map,
-];
+};
 
 @(builtin)
-make :: proc[
+make :: proc{
 	mem.make_slice,
 	mem.make_dynamic_array,
 	mem.make_dynamic_array_len,
 	mem.make_dynamic_array_len_cap,
 	mem.make_map,
-];
+};
 
 
 
@@ -508,7 +508,7 @@ append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location)
 	}
 	return len(array);
 }
-@(builtin) append :: proc[append_elem, append_elems];
+@(builtin) append :: proc{append_elem, append_elems};
 
 
 
@@ -616,8 +616,8 @@ excl_bit_set :: inline proc(s: ^$S/bit_set[$E; $U], other: S) -> S {
 	return s^;
 }
 
-@(builtin) incl :: proc[incl_elem, incl_elems, incl_bit_set];
-@(builtin) excl :: proc[excl_elem, excl_elems, excl_bit_set];
+@(builtin) incl :: proc{incl_elem, incl_elems, incl_bit_set};
+@(builtin) excl :: proc{excl_elem, excl_elems, excl_bit_set};
 
 
 

+ 8 - 12
examples/demo/demo.odin

@@ -56,7 +56,7 @@ general_stuff :: proc() {
 	/*
 	 * Remove *_val_of built-in procedures
 	 * size_of, align_of, offset_of
-	 * type_of, type_info_of
+	 * type_of, type_info_of, typeid_of
 	 */
 
 	{ // `expand_to_tuple` built-in procedure
@@ -108,6 +108,9 @@ general_stuff :: proc() {
 
 		My_Struct :: struct{x: int};
 		#assert(My_Struct != struct{x: int});
+
+		My_Struct2 :: My_Struct;
+		#assert(My_Struct2 == My_Struct);
 	}
 
 	{
@@ -213,6 +216,7 @@ union_type :: proc() {
 		case Monster:
 			if e.is_robot  do fmt.println("Robotic");
 			if e.is_zombie do fmt.println("Grrrr!");
+			fmt.println("I'm a monster");
 		}
 	}
 
@@ -371,7 +375,6 @@ parametric_polymorphism :: proc() {
 			return make(T, len);
 		}
 
-
 		// Only allow types that are specializations of `Table`
 		allocate :: proc(table: ^$T/Table, capacity: int) {
 			c := context;
@@ -509,7 +512,7 @@ parametric_polymorphism :: proc() {
 			fmt.printf("Generating an array of type %v from the value %v of type %v\n",
 			           typeid_of(type_of(res)), N, typeid_of(I));
 			for i in 0..N-1 {
-				res[i] = i*i;
+				res[i] = T(i*i);
 			}
 			return;
 		}
@@ -666,11 +669,6 @@ using_enum :: proc() {
 	f2 := C;
 	fmt.println(f0, f1, f2);
 	fmt.println(len(Foo));
-
-	// Non-comparsion operations are not allowed with enum
-	// You must convert to an integer if you want to do this
-	// x := f0 + f1;
-	y := int(f0) + int(f1);
 }
 
 explicit_procedure_overloading :: proc() {
@@ -692,7 +690,7 @@ explicit_procedure_overloading :: proc() {
 		return x;
 	}
 
-	add :: proc[add_ints, add_floats, add_numbers];
+	add :: proc{add_ints, add_floats, add_numbers};
 
 	add(int(1), int(2));
 	add(f32(1), f32(2));
@@ -738,7 +736,6 @@ complete_switch :: proc() {
 	}
 }
 
-
 cstring_example :: proc() {
 	W :: "Hellope";
 	X :: cstring(W);
@@ -801,7 +798,7 @@ bit_set_type :: proc() {
 	}
 	{
 		x: bit_set['A'..'Z'];
-		assert(size_of(x) == size_of(u32));
+		#assert(size_of(x) == size_of(u32));
 		y: bit_set[0..8; u16];
 		fmt.println(typeid_of(type_of(x))); // bit_set[A..Z]
 		fmt.println(typeid_of(type_of(y))); // bit_set[0..8; u16]
@@ -820,7 +817,6 @@ bit_set_type :: proc() {
 		b := Letters{'A', 'B', 'C', 'D', 'F'};
 		c := Letters{'A', 'B'};
 
-
 		assert(a <= b); // 'a' is a subset of 'b'
 		assert(b >= a); // 'b' is a superset of 'a'
 		assert(a < b);  // 'a' is a strict subset of 'b'

+ 2 - 2
src/check_expr.cpp

@@ -6543,12 +6543,12 @@ gbString write_expr_to_string(gbString str, Ast *node) {
 	case_end;
 
 	case_ast_node(pg, ProcGroup, node);
-		str = gb_string_appendc(str, "proc[");
+		str = gb_string_appendc(str, "proc{");
 		for_array(i, pg->args) {
 			if (i > 0) str = gb_string_appendc(str, ", ");
 			str = write_expr_to_string(str, pg->args[i]);
 		}
-		str = gb_string_append_rune(str, ']');
+		str = gb_string_append_rune(str, '}');
 	case_end;
 
 	case_ast_node(pl, ProcLit, node);

+ 24 - 1
src/parser.cpp

@@ -1742,8 +1742,31 @@ Ast *parse_operand(AstFile *f, bool lhs) {
 	case Token_proc: {
 		Token token = expect_token(f, Token_proc);
 
-		if (f->curr_token.kind == Token_OpenBracket) { // ProcGroup
+		if (f->curr_token.kind == Token_OpenBrace) { // ProcGroup
+			Token open = expect_token(f, Token_OpenBrace);
+
+			auto args = array_make<Ast *>(heap_allocator());
+
+			while (f->curr_token.kind != Token_CloseBrace &&
+			       f->curr_token.kind != Token_EOF) {
+				Ast *elem = parse_expr(f, false);
+				array_add(&args, elem);
+
+				if (!allow_token(f, Token_Comma)) {
+					break;
+				}
+			}
+
+			Token close = expect_token(f, Token_CloseBrace);
+
+			if (args.count == 0) {
+				syntax_error(token, "Expected a least 1 argument in a procedure group");
+			}
+
+			return ast_proc_group(f, token, open, close, args);
+		} else if (f->curr_token.kind == Token_OpenBracket) { // ProcGroup
 			Token open = expect_token(f, Token_OpenBracket);
+			warning(open, "Procedure groups using [] are now deprecated, please use {} instead");
 
 			auto args = array_make<Ast *>(heap_allocator());