Reduce number of range and slice operators #239

Replace .. and ... with : and ..
This commit is contained in:
gingerBill
2018-08-01 21:34:59 +01:00
parent a6fe656f21
commit 0718f14774
31 changed files with 204 additions and 219 deletions
+8 -10
View File
@@ -74,11 +74,9 @@ general_stuff :: proc() {
}
{
// .. half-closed range
// ... open range
// .. open range
for in 0..2 {} // 0, 1
for in 0...2 {} // 0, 1, 2
for in 0..2 {} // 0, 1, 2
}
{ // Multiple sized booleans
@@ -267,17 +265,17 @@ union_type :: proc() {
/*
Entity :: struct {
...
..
derived: union{^Frog, ^Monster},
}
Frog :: struct {
using entity: Entity,
...
..
}
Monster :: struct {
using entity: Entity,
...
..
}
new_entity :: proc(T: type) -> ^Entity {
@@ -451,7 +449,7 @@ parametric_polymorphism :: proc() {
get_hash :: proc(s: string) -> u32 { // fnv32a
h: u32 = 0x811c9dc5;
for i in 0..len(s) {
for i in 0..len(s)-1 {
h = (h ~ u32(s[i])) * 0x01000193;
}
return h;
@@ -500,12 +498,12 @@ threading_example :: proc() {
}
ordered_remove :: proc(array: ^[dynamic]$T, index: int, loc := #caller_location) {
runtime.bounds_check_error_loc(loc, index, len(array));
copy(array[index..], array[index+1..]);
copy(array[index:], array[index+1:]);
pop(array);
}
worker_proc :: proc(t: ^thread.Thread) -> int {
for iteration in 1...5 {
for iteration in 1..5 {
fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration);
fmt.printf("`%s`: iteration %d\n", prefix_table[t.user_index], iteration);
// win32.sleep(1);
+3 -3
View File
@@ -95,7 +95,7 @@ enumerations :: proc() {
}
variadic_procedures :: proc() {
print_ints :: proc(args: ...int) {
print_ints :: proc(args: ..int) {
for arg, i in args {
if i > 0 do print(", ");
print(arg);
@@ -106,7 +106,7 @@ variadic_procedures :: proc() {
print_ints(1); nl();
print_ints(1, 2, 3); nl();
print_prefix_f32s :: proc(prefix: string, args: ...f32) {
print_prefix_f32s :: proc(prefix: string, args: ..f32) {
print(prefix);
print(": ");
for arg, i in args {
@@ -323,7 +323,7 @@ match_statement :: proc() {
Vector3 :: struct {x, y, z: f32}
print_floats :: proc(args: ...f32) {
print_floats :: proc(args: ..f32) {
for arg, i in args {
if i > 0 do print(", ");
print(arg);
+2 -2
View File
@@ -32,7 +32,7 @@ main :: proc() {
/*
push_allocator x {
...
..
}
is equivalent to:
@@ -42,7 +42,7 @@ main :: proc() {
__context.allocator = x
defer __context.allocator = prev_allocator
...
..
}
*/
+2 -2
View File
@@ -21,7 +21,7 @@ when true {
Removed:
* Maybe/option types
* Remove `type` keyword and other "reserved" keywords
* ..< and ... removed and replace with .. (half-closed range)
* ..< and .. removed and replace with .. (half-closed range)
Changed:
* `#assert` and `assert` return the value of the condition for semantic reasons
@@ -51,7 +51,7 @@ when true {
}
{
// Removal of ..< and ...
// Removal of ..< and ..
for i in 0..16 {
}
// Is similar to
+6 -6
View File
@@ -69,10 +69,10 @@ general_stuff :: proc() {
{
// .. half-closed range
// ... open range
// .. open range
for in 0..2 {} // 0, 1
for in 0...2 {} // 0, 1, 2
for in 0..2 {} // 0, 1, 2
}
}
@@ -287,17 +287,17 @@ union_type :: proc() {
/*
Entity :: struct {
...
..
derived: union{^Frog, ^Monster};
}
Frog :: struct {
using entity: Entity;
...
..
}
Monster :: struct {
using entity: Entity;
...
..
}
new_entity :: proc(T: type) -> ^Entity {
@@ -522,7 +522,7 @@ threading_example :: proc() {
}
worker_proc :: proc(t: ^thread.Thread) -> int {
for iteration in 1...5 {
for iteration in 1..5 {
fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration);
fmt.printf("`%s`: iteration %d\n", prefix_table[t.user_index], iteration);
// win32.sleep(1);
+6 -6
View File
@@ -72,10 +72,10 @@ general_stuff :: proc() {
{
// .. half-closed range
// ... open range
// .. open range
for in 0..2 {} // 0, 1
for in 0...2 {} // 0, 1, 2
for in 0..2 {} // 0, 1, 2
}
{ // Multiple sized booleans
@@ -324,17 +324,17 @@ union_type :: proc() {
/*
Entity :: struct {
...
..
derived: union{^Frog, ^Monster},
}
Frog :: struct {
using entity: Entity,
...
..
}
Monster :: struct {
using entity: Entity,
...
..
}
new_entity :: proc(T: type) -> ^Entity {
@@ -559,7 +559,7 @@ threading_example :: proc() {
}
worker_proc :: proc(t: ^thread.Thread) -> int {
for iteration in 1...5 {
for iteration in 1..5 {
fmt.printf("Thread %d is on iteration %d\n", t.user_index, iteration);
fmt.printf("`%s`: iteration %d\n", prefix_table[t.user_index], iteration);
// win32.sleep(1);
+4 -4
View File
@@ -36,7 +36,7 @@ general_stuff :: proc() {
// C-style variadic procedures
foreign __llvm_core {
// The variadic part allows for extra type checking too which C does not provide
c_printf :: proc(fmt: ^u8, #c_vararg args: ...any) -> i32 #link_name "printf" ---;
c_printf :: proc(fmt: ^u8, #c_vararg args: ..any) -> i32 #link_name "printf" ---;
}
str := "%d\n\x00";
// c_printf(&str[0], i32(789456123));
@@ -154,8 +154,8 @@ default_return_values :: proc() {
match x {
case 0: return;
case 1: return "Goodbye";
case 2: return "Goodbye", "cruel world...";
case 3: return second = "cruel world...", first = "Goodbye";
case 2: return "Goodbye", "cruel world..";
case 3: return second = "cruel world..", first = "Goodbye";
}
return second = "my old friend.";
@@ -231,7 +231,7 @@ explicit_parametric_polymorphic_procedures :: proc() {
defer free(another_ptr);
add :: proc(T: type, args: ...T) -> T {
add :: proc(T: type, args: ..T) -> T {
res: T;
for arg in args do res += arg;
return res;