Begin transition to Jai-like syntax

This commit is contained in:
Ginger Bill
2017-01-01 19:08:03 +00:00
parent 3f1195cd03
commit a48e0c7179
20 changed files with 2348 additions and 2365 deletions
+34 -34
View File
@@ -30,22 +30,22 @@ proc copy_non_overlapping(dst, src rawptr, len int) -> rawptr #link_name "__mem_
proc compare(dst, src rawptr, n int) -> int #link_name "__mem_compare" {
// Translation of http://mgronhol.github.io/fast-strcmp/
var a = slice_ptr(dst as ^byte, n);
var b = slice_ptr(src as ^byte, n);
a := slice_ptr(dst as ^byte, n);
b := slice_ptr(src as ^byte, n);
var fast = n/size_of(int) + 1;
var offset = (fast-1)*size_of(int);
var curr_block = 0;
fast := n/size_of(int) + 1;
offset := (fast-1)*size_of(int);
curr_block := 0;
if n <= size_of(int) {
fast = 0;
}
var la = slice_ptr(^a[0] as ^int, fast);
var lb = slice_ptr(^b[0] as ^int, fast);
la := slice_ptr(^a[0] as ^int, fast);
lb := slice_ptr(^b[0] as ^int, fast);
for ; curr_block < fast; curr_block++ {
if (la[curr_block] ~ lb[curr_block]) != 0 {
for var pos = curr_block*size_of(int); pos < n; pos++ {
for pos := curr_block*size_of(int); pos < n; pos++ {
if (a[pos] ~ b[pos]) != 0 {
return a[pos] as int - b[pos] as int;
}
@@ -80,9 +80,9 @@ proc is_power_of_two(x int) -> bool {
proc align_forward(ptr rawptr, align int) -> rawptr {
assert(is_power_of_two(align));
var a = align as uint;
var p = ptr as uint;
var modulo = p & (a-1);
a := align as uint;
p := ptr as uint;
modulo := p & (a-1);
if modulo != 0 {
p += a - modulo;
}
@@ -97,14 +97,14 @@ type Allocation_Header struct {
proc allocation_header_fill(header ^Allocation_Header, data rawptr, size int) {
header.size = size;
var ptr = (header+1) as ^int;
ptr := (header+1) as ^int;
for var i = 0; ptr as rawptr < data; i++ {
for i := 0; ptr as rawptr < data; i++ {
(ptr+i)^ = -1;
}
}
proc allocation_header(data rawptr) -> ^Allocation_Header {
var p = data as ^int;
p := data as ^int;
for (p-1)^ == -1 {
p = (p-1);
}
@@ -164,20 +164,20 @@ proc arena_allocator_proc(allocator_data rawptr, mode Allocator_Mode,
size, alignment int,
old_memory rawptr, old_size int, flags u64) -> rawptr {
using Allocator_Mode;
var arena = allocator_data as ^Arena;
arena := allocator_data as ^Arena;
match mode {
case ALLOC:
var total_size = size + alignment;
total_size := size + alignment;
if arena.memory.count + total_size > arena.memory.capacity {
fmt.fprintln(os.stderr, "Arena out of memory");
return nil;
}
#no_bounds_check var end = ^arena.memory[arena.memory.count];
#no_bounds_check end := ^arena.memory[arena.memory.count];
var ptr = align_forward(end, alignment);
ptr := align_forward(end, alignment);
arena.memory.count += total_size;
return zero(ptr, size);
@@ -196,7 +196,7 @@ proc arena_allocator_proc(allocator_data rawptr, mode Allocator_Mode,
}
proc begin_arena_temp_memory(a ^Arena) -> Arena_Temp_Memory {
var tmp Arena_Temp_Memory;
tmp: Arena_Temp_Memory;
tmp.arena = a;
tmp.original_count = a.memory.count;
a.temp_count++;
@@ -230,8 +230,8 @@ proc align_of_type_info(type_info ^Type_Info) -> int {
return n - (n >> 1);
}
const WORD_SIZE = size_of(int);
const MAX_ALIGN = size_of([vector 64]f64); // TODO(bill): Should these constants be builtin constants?
WORD_SIZE :: size_of(int);
MAX_ALIGN :: size_of([vector 64]f64); // TODO(bill): Should these constants be builtin constants?
using Type_Info;
match type info : type_info {
@@ -256,9 +256,9 @@ proc align_of_type_info(type_info ^Type_Info) -> int {
case Slice:
return WORD_SIZE;
case Vector:
var size = size_of_type_info(info.elem);
var count = max(prev_pow2(info.count as i64), 1) as int;
var total = size * count;
size := size_of_type_info(info.elem);
count := max(prev_pow2(info.count as i64), 1) as int;
total := size * count;
return clamp(total, 1, MAX_ALIGN);
case Struct:
return info.align;
@@ -272,12 +272,12 @@ proc align_of_type_info(type_info ^Type_Info) -> int {
}
proc align_formula(size, align int) -> int {
var result = size + align-1;
result := size + align-1;
return result - result%align;
}
proc size_of_type_info(type_info ^Type_Info) -> int {
const WORD_SIZE = size_of(int);
WORD_SIZE :: size_of(int);
using Type_Info;
match type info : type_info {
case Named:
@@ -299,13 +299,13 @@ proc size_of_type_info(type_info ^Type_Info) -> int {
case Procedure:
return WORD_SIZE;
case Array:
var count = info.count;
count := info.count;
if count == 0 {
return 0;
}
var size = size_of_type_info(info.elem);
var align = align_of_type_info(info.elem);
var alignment = align_formula(size, align);
size := size_of_type_info(info.elem);
align := align_of_type_info(info.elem);
alignment := align_formula(size, align);
return alignment*(count-1) + size;
case Slice:
return 3*WORD_SIZE;
@@ -320,18 +320,18 @@ proc size_of_type_info(type_info ^Type_Info) -> int {
return false;
}
var count = info.count;
count := info.count;
if count == 0 {
return 0;
}
var bit_size = 8*size_of_type_info(info.elem);
bit_size := 8*size_of_type_info(info.elem);
if is_bool(info.elem) {
// NOTE(bill): LLVM can store booleans as 1 bit because a boolean _is_ an `i1`
// Silly LLVM spec
bit_size = 1;
}
var total_size_in_bits = bit_size * count;
var total_size = (total_size_in_bits+7)/8;
total_size_in_bits := bit_size * count;
total_size := (total_size_in_bits+7)/8;
return total_size;
case Struct: