mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-01 20:28:15 +00:00
Pascal style declaration grouping with ()
This commit is contained in:
+137
-129
@@ -1,10 +1,11 @@
|
||||
#shared_global_scope;
|
||||
|
||||
import "os.odin";
|
||||
import "fmt.odin";
|
||||
import "utf8.odin";
|
||||
import "raw.odin";
|
||||
|
||||
import (
|
||||
"os.odin";
|
||||
"fmt.odin";
|
||||
"utf8.odin";
|
||||
"raw.odin";
|
||||
)
|
||||
// Naming Conventions:
|
||||
// In general, PascalCase for types and snake_case for values
|
||||
//
|
||||
@@ -24,95 +25,98 @@ import "raw.odin";
|
||||
|
||||
// IMPORTANT NOTE(bill): Do not change the order of any of this data
|
||||
// The compiler relies upon this _exact_ order
|
||||
type TypeInfoEnumValue raw_union {
|
||||
f: f64,
|
||||
i: i128,
|
||||
}
|
||||
// NOTE(bill): This must match the compiler's
|
||||
type CallingConvention enum {
|
||||
Odin = 0,
|
||||
C = 1,
|
||||
Std = 2,
|
||||
Fast = 3,
|
||||
}
|
||||
type (
|
||||
TypeInfoEnumValue raw_union {
|
||||
f: f64,
|
||||
i: i128,
|
||||
}
|
||||
// NOTE(bill): This must match the compiler's
|
||||
CallingConvention enum {
|
||||
Odin = 0,
|
||||
C = 1,
|
||||
Std = 2,
|
||||
Fast = 3,
|
||||
}
|
||||
|
||||
type TypeInfoRecord struct #ordered {
|
||||
types: []^TypeInfo,
|
||||
names: []string,
|
||||
offsets: []int, // offsets may not be used in tuples
|
||||
usings: []bool, // usings may not be used in tuples
|
||||
packed: bool,
|
||||
ordered: bool,
|
||||
custom_align: bool,
|
||||
}
|
||||
TypeInfoRecord struct #ordered {
|
||||
types: []^TypeInfo,
|
||||
names: []string,
|
||||
offsets: []int, // offsets may not be used in tuples
|
||||
usings: []bool, // usings may not be used in tuples
|
||||
packed: bool,
|
||||
ordered: bool,
|
||||
custom_align: bool,
|
||||
}
|
||||
|
||||
type TypeInfo union {
|
||||
size: int,
|
||||
align: int,
|
||||
TypeInfo union {
|
||||
size: int,
|
||||
align: int,
|
||||
|
||||
Named{name: string, base: ^TypeInfo},
|
||||
Integer{signed: bool},
|
||||
Rune{},
|
||||
Float{},
|
||||
Complex{},
|
||||
String{},
|
||||
Boolean{},
|
||||
Any{},
|
||||
Pointer{
|
||||
elem: ^TypeInfo, // nil -> rawptr
|
||||
},
|
||||
Atomic{elem: ^TypeInfo},
|
||||
Procedure{
|
||||
params: ^TypeInfo, // TypeInfo.Tuple
|
||||
results: ^TypeInfo, // TypeInfo.Tuple
|
||||
variadic: bool,
|
||||
convention: CallingConvention,
|
||||
},
|
||||
Array{
|
||||
elem: ^TypeInfo,
|
||||
elem_size: int,
|
||||
count: int,
|
||||
},
|
||||
DynamicArray{elem: ^TypeInfo, elem_size: int},
|
||||
Slice {elem: ^TypeInfo, elem_size: int},
|
||||
Vector {elem: ^TypeInfo, elem_size, count: int},
|
||||
Tuple {using record: TypeInfoRecord}, // Only really used for procedures
|
||||
Struct {using record: TypeInfoRecord},
|
||||
RawUnion {using record: TypeInfoRecord},
|
||||
Union{
|
||||
common_fields: struct {
|
||||
types: []^TypeInfo,
|
||||
names: []string,
|
||||
offsets: []int, // offsets may not be used in tuples
|
||||
Named{name: string, base: ^TypeInfo},
|
||||
Integer{signed: bool},
|
||||
Rune{},
|
||||
Float{},
|
||||
Complex{},
|
||||
String{},
|
||||
Boolean{},
|
||||
Any{},
|
||||
Pointer{
|
||||
elem: ^TypeInfo, // nil -> rawptr
|
||||
},
|
||||
variant_names: []string,
|
||||
variant_types: []^TypeInfo,
|
||||
},
|
||||
Enum{
|
||||
base: ^TypeInfo,
|
||||
names: []string,
|
||||
values: []TypeInfoEnumValue,
|
||||
},
|
||||
Map{
|
||||
key: ^TypeInfo,
|
||||
value: ^TypeInfo,
|
||||
generated_struct: ^TypeInfo,
|
||||
count: int, // == 0 if dynamic
|
||||
},
|
||||
BitField{
|
||||
names: []string,
|
||||
bits: []i32,
|
||||
offsets: []i32,
|
||||
},
|
||||
}
|
||||
|
||||
Atomic{elem: ^TypeInfo},
|
||||
Procedure{
|
||||
params: ^TypeInfo, // TypeInfo.Tuple
|
||||
results: ^TypeInfo, // TypeInfo.Tuple
|
||||
variadic: bool,
|
||||
convention: CallingConvention,
|
||||
},
|
||||
Array{
|
||||
elem: ^TypeInfo,
|
||||
elem_size: int,
|
||||
count: int,
|
||||
},
|
||||
DynamicArray{elem: ^TypeInfo, elem_size: int},
|
||||
Slice {elem: ^TypeInfo, elem_size: int},
|
||||
Vector {elem: ^TypeInfo, elem_size, count: int},
|
||||
Tuple {using record: TypeInfoRecord}, // Only really used for procedures
|
||||
Struct {using record: TypeInfoRecord},
|
||||
RawUnion {using record: TypeInfoRecord},
|
||||
Union{
|
||||
common_fields: struct {
|
||||
types: []^TypeInfo,
|
||||
names: []string,
|
||||
offsets: []int, // offsets may not be used in tuples
|
||||
},
|
||||
variant_names: []string,
|
||||
variant_types: []^TypeInfo,
|
||||
},
|
||||
Enum{
|
||||
base: ^TypeInfo,
|
||||
names: []string,
|
||||
values: []TypeInfoEnumValue,
|
||||
},
|
||||
Map{
|
||||
key: ^TypeInfo,
|
||||
value: ^TypeInfo,
|
||||
generated_struct: ^TypeInfo,
|
||||
count: int, // == 0 if dynamic
|
||||
},
|
||||
BitField{
|
||||
names: []string,
|
||||
bits: []i32,
|
||||
offsets: []i32,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// NOTE(bill): only the ones that are needed (not all types)
|
||||
// This will be set by the compiler
|
||||
var __type_table: []TypeInfo;
|
||||
var (
|
||||
__type_table: []TypeInfo;
|
||||
|
||||
var __argv__: ^^u8;
|
||||
var __argc__: i32;
|
||||
__argv__: ^^u8;
|
||||
__argc__: i32;
|
||||
)
|
||||
|
||||
proc type_info_base(info: ^TypeInfo) -> ^TypeInfo {
|
||||
if info == nil {
|
||||
@@ -151,29 +155,31 @@ proc read_cycle_counter() -> u64 #foreign __llvm_core "llvm.readcyclecounter";
|
||||
|
||||
|
||||
// IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it)
|
||||
type AllocatorMode enum u8 {
|
||||
Alloc,
|
||||
Free,
|
||||
FreeAll,
|
||||
Resize,
|
||||
}
|
||||
type AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
|
||||
type Allocator struct #ordered {
|
||||
procedure: AllocatorProc,
|
||||
data: rawptr,
|
||||
}
|
||||
type (
|
||||
AllocatorMode enum u8 {
|
||||
Alloc,
|
||||
Free,
|
||||
FreeAll,
|
||||
Resize,
|
||||
}
|
||||
AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
|
||||
Allocator struct #ordered {
|
||||
procedure: AllocatorProc,
|
||||
data: rawptr,
|
||||
}
|
||||
|
||||
|
||||
type Context struct #ordered {
|
||||
thread_id: int,
|
||||
Context struct #ordered {
|
||||
thread_id: int,
|
||||
|
||||
allocator: Allocator,
|
||||
allocator: Allocator,
|
||||
|
||||
user_data: rawptr,
|
||||
user_index: int,
|
||||
}
|
||||
user_data: rawptr,
|
||||
user_index: int,
|
||||
}
|
||||
)
|
||||
|
||||
#thread_local var __context: Context;
|
||||
|
||||
@@ -553,33 +559,35 @@ proc __default_hash_string(s: string) -> u128 {
|
||||
|
||||
const __INITIAL_MAP_CAP = 16;
|
||||
|
||||
type __MapKey struct #ordered {
|
||||
hash: u128,
|
||||
str: string,
|
||||
}
|
||||
type (
|
||||
__MapKey struct #ordered {
|
||||
hash: u128,
|
||||
str: string,
|
||||
}
|
||||
|
||||
type __MapFindResult struct #ordered {
|
||||
hash_index: int,
|
||||
entry_prev: int,
|
||||
entry_index: int,
|
||||
}
|
||||
__MapFindResult struct #ordered {
|
||||
hash_index: int,
|
||||
entry_prev: int,
|
||||
entry_index: int,
|
||||
}
|
||||
|
||||
type __MapEntryHeader struct #ordered {
|
||||
key: __MapKey,
|
||||
next: int,
|
||||
/*
|
||||
value: Value_Type,
|
||||
*/
|
||||
}
|
||||
__MapEntryHeader struct #ordered {
|
||||
key: __MapKey,
|
||||
next: int,
|
||||
/*
|
||||
value: Value_Type,
|
||||
*/
|
||||
}
|
||||
|
||||
type __MapHeader struct #ordered {
|
||||
m: ^raw.DynamicMap,
|
||||
is_key_string: bool,
|
||||
entry_size: int,
|
||||
entry_align: int,
|
||||
value_offset: int,
|
||||
value_size: int,
|
||||
}
|
||||
__MapHeader struct #ordered {
|
||||
m: ^raw.DynamicMap,
|
||||
is_key_string: bool,
|
||||
entry_size: int,
|
||||
entry_align: int,
|
||||
value_offset: int,
|
||||
value_size: int,
|
||||
}
|
||||
)
|
||||
|
||||
proc __dynamic_map_reserve(using header: __MapHeader, cap: int) {
|
||||
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap);
|
||||
|
||||
+22
-21
@@ -1,27 +1,28 @@
|
||||
const U8_MIN = u8(0);
|
||||
const U16_MIN = u16(0);
|
||||
const U32_MIN = u32(0);
|
||||
const U64_MIN = u64(0);
|
||||
const U128_MIN = u128(0);
|
||||
const (
|
||||
U8_MIN = u8(0);
|
||||
U16_MIN = u16(0);
|
||||
U32_MIN = u32(0);
|
||||
U64_MIN = u64(0);
|
||||
U128_MIN = u128(0);
|
||||
|
||||
const I8_MIN = i8(-0x80);
|
||||
const I16_MIN = i16(-0x8000);
|
||||
const I32_MIN = i32(-0x8000_0000);
|
||||
const I64_MIN = i64(-0x8000_0000_0000_0000);
|
||||
const I128_MIN = i128(-0x8000_0000_0000_0000_0000_0000_0000_0000);
|
||||
I8_MIN = i8(-0x80);
|
||||
I16_MIN = i16(-0x8000);
|
||||
I32_MIN = i32(-0x8000_0000);
|
||||
I64_MIN = i64(-0x8000_0000_0000_0000);
|
||||
I128_MIN = i128(-0x8000_0000_0000_0000_0000_0000_0000_0000);
|
||||
|
||||
const U8_MAX = ~u8(0);
|
||||
const U16_MAX = ~u16(0);
|
||||
const U32_MAX = ~u32(0);
|
||||
const U64_MAX = ~u64(0);
|
||||
const U128_MAX = ~u128(0);
|
||||
|
||||
const I8_MAX = i8(0x7f);
|
||||
const I16_MAX = i16(0x7fff);
|
||||
const I32_MAX = i32(0x7fff_ffff);
|
||||
const I64_MAX = i64(0x7fff_ffff_ffff_ffff);
|
||||
const I128_MAX = i128(0x7fff_ffff_ffff_ffff_ffff_ffff_ffff_ffff);
|
||||
U8_MAX = ~u8(0);
|
||||
U16_MAX = ~u16(0);
|
||||
U32_MAX = ~u32(0);
|
||||
U64_MAX = ~u64(0);
|
||||
U128_MAX = ~u128(0);
|
||||
|
||||
I8_MAX = i8(0x7f);
|
||||
I16_MAX = i16(0x7fff);
|
||||
I32_MAX = i32(0x7fff_ffff);
|
||||
I64_MAX = i64(0x7fff_ffff_ffff_ffff);
|
||||
I128_MAX = i128(0x7fff_ffff_ffff_ffff_ffff_ffff_ffff_ffff);
|
||||
)
|
||||
|
||||
proc count_ones(i: u8) -> u8 { proc __llvm_ctpop(u8) -> u8 #foreign __llvm_core "llvm.ctpop.i8"; return __llvm_ctpop(i); }
|
||||
proc count_ones(i: i8) -> i8 { proc __llvm_ctpop(i8) -> i8 #foreign __llvm_core "llvm.ctpop.i8"; return __llvm_ctpop(i); }
|
||||
|
||||
+8
-7
@@ -1,10 +1,11 @@
|
||||
import "os.odin";
|
||||
import "mem.odin";
|
||||
import "utf8.odin";
|
||||
import "types.odin";
|
||||
import "strconv.odin";
|
||||
import "raw.odin";
|
||||
|
||||
import (
|
||||
"os.odin";
|
||||
"mem.odin";
|
||||
"utf8.odin";
|
||||
"types.odin";
|
||||
"strconv.odin";
|
||||
"raw.odin";
|
||||
)
|
||||
|
||||
const _BUFFER_SIZE = 1<<12;
|
||||
|
||||
|
||||
+42
-42
@@ -1,61 +1,61 @@
|
||||
crc32 :: proc(data: []u8) -> u32 {
|
||||
result := ~u32(0);
|
||||
proc crc32(data: []u8) -> u32 {
|
||||
var result = ~u32(0);
|
||||
for b in data {
|
||||
result = result>>8 ~ _crc32_table[(result ~ u32(b)) & 0xff];
|
||||
}
|
||||
return ~result;
|
||||
}
|
||||
crc64 :: proc(data: []u8) -> u64 {
|
||||
result := ~u64(0);
|
||||
proc crc64(data: []u8) -> u64 {
|
||||
var result = ~u64(0);
|
||||
for b in data {
|
||||
result = result>>8 ~ _crc64_table[(result ~ u64(b)) & 0xff];
|
||||
}
|
||||
return ~result;
|
||||
}
|
||||
|
||||
fnv32 :: proc(data: []u8) -> u32 {
|
||||
h: u32 = 0x811c9dc5;
|
||||
proc fnv32(data: []u8) -> u32 {
|
||||
var h: u32 = 0x811c9dc5;
|
||||
for b in data {
|
||||
h = (h * 0x01000193) ~ u32(b);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
fnv64 :: proc(data: []u8) -> u64 {
|
||||
h: u64 = 0xcbf29ce484222325;
|
||||
proc fnv64(data: []u8) -> u64 {
|
||||
var h: u64 = 0xcbf29ce484222325;
|
||||
for b in data {
|
||||
h = (h * 0x100000001b3) ~ u64(b);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
fnv32a :: proc(data: []u8) -> u32 {
|
||||
h: u32 = 0x811c9dc5;
|
||||
proc fnv32a(data: []u8) -> u32 {
|
||||
var h: u32 = 0x811c9dc5;
|
||||
for b in data {
|
||||
h = (h ~ u32(b)) * 0x01000193;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
fnv64a :: proc(data: []u8) -> u64 {
|
||||
h: u64 = 0xcbf29ce484222325;
|
||||
proc fnv64a(data: []u8) -> u64 {
|
||||
var h: u64 = 0xcbf29ce484222325;
|
||||
for b in data {
|
||||
h = (h ~ u64(b)) * 0x100000001b3;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
murmur32 :: proc(data: []u8) -> u32 {
|
||||
c1_32: u32 : 0xcc9e2d51;
|
||||
c2_32: u32 : 0x1b873593;
|
||||
proc murmur32(data: []u8) -> u32 {
|
||||
const c1_32: u32 = 0xcc9e2d51;
|
||||
const c2_32: u32 = 0x1b873593;
|
||||
|
||||
h1: u32 = 0;
|
||||
nblocks := len(data)/4;
|
||||
p := &data[0];
|
||||
p1 := p + 4*nblocks;
|
||||
var h1: u32 = 0;
|
||||
var nblocks = len(data)/4;
|
||||
var p = &data[0];
|
||||
var p1 = p + 4*nblocks;
|
||||
|
||||
for ; p < p1; p += 4 {
|
||||
k1 := ^u32(p)^;
|
||||
var k1 = ^u32(p)^;
|
||||
|
||||
k1 *= c1_32;
|
||||
k1 = (k1 << 15) | (k1 >> 17);
|
||||
@@ -66,9 +66,9 @@ murmur32 :: proc(data: []u8) -> u32 {
|
||||
h1 = h1*5 + 0xe6546b64;
|
||||
}
|
||||
|
||||
tail := data[nblocks*4 ..];
|
||||
var tail = data[nblocks*4 ..];
|
||||
|
||||
k1: u32;
|
||||
var k1: u32;
|
||||
match len(tail)&3 {
|
||||
case 3:
|
||||
k1 ~= u32(tail[2]) << 16;
|
||||
@@ -95,18 +95,18 @@ murmur32 :: proc(data: []u8) -> u32 {
|
||||
return h1;
|
||||
}
|
||||
|
||||
murmur64 :: proc(data: []u8) -> u64 {
|
||||
SEED :: 0x9747b28c;
|
||||
proc murmur64(data: []u8) -> u64 {
|
||||
const SEED = 0x9747b28c;
|
||||
|
||||
when size_of(int) == 8 {
|
||||
m :: 0xc6a4a7935bd1e995;
|
||||
r :: 47;
|
||||
const m = 0xc6a4a7935bd1e995;
|
||||
const r = 47;
|
||||
|
||||
h: u64 = SEED ~ (u64(len(data)) * m);
|
||||
data64 := slice_ptr(^u64(&data[0]), len(data)/size_of(u64));
|
||||
var h: u64 = SEED ~ (u64(len(data)) * m);
|
||||
var data64 = slice_ptr(^u64(&data[0]), len(data)/size_of(u64));
|
||||
|
||||
for _, i in data64 {
|
||||
k := data64[i];
|
||||
var k = data64[i];
|
||||
|
||||
k *= m;
|
||||
k ~= k>>r;
|
||||
@@ -134,18 +134,18 @@ murmur64 :: proc(data: []u8) -> u64 {
|
||||
|
||||
return h;
|
||||
} else {
|
||||
m :: 0x5bd1e995;
|
||||
r :: 24;
|
||||
const m = 0x5bd1e995;
|
||||
const r = 24;
|
||||
|
||||
h1 := u32(SEED) ~ u32(len(data));
|
||||
h2 := u32(SEED) >> 32;
|
||||
var h1 = u32(SEED) ~ u32(len(data));
|
||||
var h2 = u32(SEED) >> 32;
|
||||
|
||||
data32 := slice_ptr(cast(^u32)&data[0], len(data)/size_of(u32));
|
||||
len := len(data);
|
||||
var data32 = slice_ptr(cast(^u32)&data[0], len(data)/size_of(u32));
|
||||
var len = len(data);
|
||||
|
||||
i := 0;
|
||||
var i = 0;
|
||||
for len >= 8 {
|
||||
k1, k2: u32;
|
||||
var k1, k2: u32;
|
||||
k1 = data32[i]; i++;
|
||||
k1 *= m;
|
||||
k1 ~= k1>>r;
|
||||
@@ -164,7 +164,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
||||
}
|
||||
|
||||
if len >= 4 {
|
||||
k1: u32;
|
||||
var k1: u32;
|
||||
k1 = data32[i]; i++;
|
||||
k1 *= m;
|
||||
k1 ~= k1>>r;
|
||||
@@ -175,7 +175,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
||||
}
|
||||
|
||||
// TODO(bill): Fix this
|
||||
#no_bounds_check data8 := slice_to_bytes(data32[i..])[0..<3];
|
||||
#no_bounds_check var data8 = slice_to_bytes(data32[i..])[0..<3];
|
||||
match len {
|
||||
case 3:
|
||||
h2 ~= u32(data8[2]) << 16;
|
||||
@@ -197,13 +197,13 @@ murmur64 :: proc(data: []u8) -> u64 {
|
||||
h2 ~= h1>>19;
|
||||
h2 *= m;
|
||||
|
||||
h := cast(u64)(h1)<<32 | cast(u64)(h2);
|
||||
var h = cast(u64)(h1)<<32 | cast(u64)(h2);
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
immutable _crc32_table := [256]u32{
|
||||
let _crc32_table = [256]u32{
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
|
||||
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
@@ -269,7 +269,7 @@ immutable _crc32_table := [256]u32{
|
||||
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
|
||||
};
|
||||
immutable _crc64_table := [256]u64{
|
||||
let _crc64_table = [256]u64{
|
||||
0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5,
|
||||
0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a,
|
||||
0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b,
|
||||
|
||||
+24
-21
@@ -1,31 +1,34 @@
|
||||
const TAU = 6.28318530717958647692528676655900576;
|
||||
const PI = 3.14159265358979323846264338327950288;
|
||||
const ONE_OVER_TAU = 0.636619772367581343075535053490057448;
|
||||
const ONE_OVER_PI = 0.159154943091895335768883763372514362;
|
||||
const (
|
||||
TAU = 6.28318530717958647692528676655900576;
|
||||
PI = 3.14159265358979323846264338327950288;
|
||||
ONE_OVER_TAU = 0.636619772367581343075535053490057448;
|
||||
ONE_OVER_PI = 0.159154943091895335768883763372514362;
|
||||
|
||||
const E = 2.71828182845904523536;
|
||||
const SQRT_TWO = 1.41421356237309504880168872420969808;
|
||||
const SQRT_THREE = 1.73205080756887729352744634150587236;
|
||||
const SQRT_FIVE = 2.23606797749978969640917366873127623;
|
||||
E = 2.71828182845904523536;
|
||||
SQRT_TWO = 1.41421356237309504880168872420969808;
|
||||
SQRT_THREE = 1.73205080756887729352744634150587236;
|
||||
SQRT_FIVE = 2.23606797749978969640917366873127623;
|
||||
|
||||
const LOG_TWO = 0.693147180559945309417232121458176568;
|
||||
const LOG_TEN = 2.30258509299404568401799145468436421;
|
||||
LOG_TWO = 0.693147180559945309417232121458176568;
|
||||
LOG_TEN = 2.30258509299404568401799145468436421;
|
||||
|
||||
const EPSILON = 1.19209290e-7;
|
||||
EPSILON = 1.19209290e-7;
|
||||
|
||||
const τ = TAU;
|
||||
const π = PI;
|
||||
|
||||
type Vec2 [vector 2]f32;
|
||||
type Vec3 [vector 3]f32;
|
||||
type Vec4 [vector 4]f32;
|
||||
τ = TAU;
|
||||
π = PI;
|
||||
)
|
||||
type (
|
||||
Vec2 [vector 2]f32;
|
||||
Vec3 [vector 3]f32;
|
||||
Vec4 [vector 4]f32;
|
||||
|
||||
// Column major
|
||||
type Mat2 [2][2]f32;
|
||||
type Mat3 [3][3]f32;
|
||||
type Mat4 [4][4]f32;
|
||||
Mat2 [2][2]f32;
|
||||
Mat3 [3][3]f32;
|
||||
Mat4 [4][4]f32;
|
||||
|
||||
type Complex complex64;
|
||||
Complex complex64;
|
||||
)
|
||||
|
||||
proc sqrt(x: f32) -> f32 #foreign __llvm_core "llvm.sqrt.f32";
|
||||
proc sqrt(x: f64) -> f64 #foreign __llvm_core "llvm.sqrt.f64";
|
||||
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
import "fmt.odin";
|
||||
import "os.odin";
|
||||
import (
|
||||
"fmt.odin";
|
||||
"os.odin";
|
||||
)
|
||||
|
||||
proc swap(b: u16) -> u16 #foreign __llvm_core "llvm.bswap.i16";
|
||||
proc swap(b: u32) -> u32 #foreign __llvm_core "llvm.bswap.i32";
|
||||
|
||||
+4
-2
@@ -1,7 +1,9 @@
|
||||
#foreign_system_library lib "opengl32.lib" when ODIN_OS == "windows";
|
||||
#foreign_system_library lib "gl" when ODIN_OS == "linux";
|
||||
import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||
import "sys/wgl.odin" when ODIN_OS == "windows";
|
||||
import (
|
||||
win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||
"sys/wgl.odin" when ODIN_OS == "windows";
|
||||
)
|
||||
import_load "opengl_constants.odin";
|
||||
|
||||
proc Clear (mask: u32) #foreign lib "glClear";
|
||||
|
||||
+1367
-1367
File diff suppressed because it is too large
Load Diff
+5
-3
@@ -1,6 +1,8 @@
|
||||
import_load "os_windows.odin" when ODIN_OS == "windows";
|
||||
import_load "os_x.odin" when ODIN_OS == "osx";
|
||||
import_load "os_linux.odin" when ODIN_OS == "linux";
|
||||
import_load (
|
||||
"os_windows.odin" when ODIN_OS == "windows";
|
||||
"os_x.odin" when ODIN_OS == "osx";
|
||||
"os_linux.odin" when ODIN_OS == "linux";
|
||||
)
|
||||
|
||||
proc write_string(fd: Handle, str: string) -> (int, Errno) {
|
||||
return write(fd, []u8(str));
|
||||
|
||||
+73
-71
@@ -1,36 +1,40 @@
|
||||
#foreign_system_library dl "dl";
|
||||
#foreign_system_library libc "c";
|
||||
import "strings.odin";
|
||||
|
||||
type Handle i32;
|
||||
type FileTime u64;
|
||||
type Errno i32;
|
||||
type (
|
||||
Handle i32;
|
||||
FileTime u64;
|
||||
Errno i32;
|
||||
)
|
||||
|
||||
// INVALID_HANDLE: Handle : -1;
|
||||
const (
|
||||
O_RDONLY = 0x00000;
|
||||
O_WRONLY = 0x00001;
|
||||
O_RDWR = 0x00002;
|
||||
O_CREAT = 0x00040;
|
||||
O_EXCL = 0x00080;
|
||||
O_NOCTTY = 0x00100;
|
||||
O_TRUNC = 0x00200;
|
||||
O_NONBLOCK = 0x00800;
|
||||
O_APPEND = 0x00400;
|
||||
O_SYNC = 0x01000;
|
||||
O_ASYNC = 0x02000;
|
||||
O_CLOEXEC = 0x80000;
|
||||
SEEK_SET = 0;
|
||||
SEEK_CUR = 1;
|
||||
SEEK_END = 2;
|
||||
SEEK_DATA = 3;
|
||||
SEEK_HOLE = 4;
|
||||
SEEK_MAX = SEEK_HOLE;
|
||||
|
||||
const O_RDONLY = 0x00000;
|
||||
const O_WRONLY = 0x00001;
|
||||
const O_RDWR = 0x00002;
|
||||
const O_CREAT = 0x00040;
|
||||
const O_EXCL = 0x00080;
|
||||
const O_NOCTTY = 0x00100;
|
||||
const O_TRUNC = 0x00200;
|
||||
const O_NONBLOCK = 0x00800;
|
||||
const O_APPEND = 0x00400;
|
||||
const O_SYNC = 0x01000;
|
||||
const O_ASYNC = 0x02000;
|
||||
const O_CLOEXEC = 0x80000;
|
||||
const SEEK_SET = 0;
|
||||
const SEEK_CUR = 1;
|
||||
const SEEK_END = 2;
|
||||
const SEEK_DATA = 3;
|
||||
const SEEK_HOLE = 4;
|
||||
const SEEK_MAX = SEEK_HOLE;
|
||||
|
||||
// NOTE(zangent): These are OS specific!
|
||||
// Do not mix these up!
|
||||
const RTLD_LAZY = 0x001;
|
||||
const RTLD_NOW = 0x002;
|
||||
const RTLD_BINDING_MASK = 0x3;
|
||||
const RTLD_GLOBAL = 0x100;
|
||||
// NOTE(zangent): These are OS specific!
|
||||
// Do not mix these up!
|
||||
RTLD_LAZY = 0x001;
|
||||
RTLD_NOW = 0x002;
|
||||
RTLD_BINDING_MASK = 0x3;
|
||||
RTLD_GLOBAL = 0x100;
|
||||
)
|
||||
|
||||
// "Argv" arguments converted to Odin strings
|
||||
let args = _alloc_command_line_arguments();
|
||||
@@ -70,41 +74,39 @@ type Stat struct #ordered {
|
||||
};
|
||||
|
||||
// File type
|
||||
const (
|
||||
S_IFMT = 0170000; // Type of file mask
|
||||
S_IFIFO = 0010000; // Named pipe (fifo)
|
||||
S_IFCHR = 0020000; // Character special
|
||||
S_IFDIR = 0040000; // Directory
|
||||
S_IFBLK = 0060000; // Block special
|
||||
S_IFREG = 0100000; // Regular
|
||||
S_IFLNK = 0120000; // Symbolic link
|
||||
S_IFSOCK = 0140000; // Socket
|
||||
|
||||
const S_IFMT = 0170000; // Type of file mask
|
||||
const S_IFIFO = 0010000; // Named pipe (fifo)
|
||||
const S_IFCHR = 0020000; // Character special
|
||||
const S_IFDIR = 0040000; // Directory
|
||||
const S_IFBLK = 0060000; // Block special
|
||||
const S_IFREG = 0100000; // Regular
|
||||
const S_IFLNK = 0120000; // Symbolic link
|
||||
const S_IFSOCK = 0140000; // Socket
|
||||
// File mode
|
||||
// Read, write, execute/search by owner
|
||||
S_IRWXU = 0000700; // RWX mask for owner
|
||||
S_IRUSR = 0000400; // R for owner
|
||||
S_IWUSR = 0000200; // W for owner
|
||||
S_IXUSR = 0000100; // X for owner
|
||||
|
||||
// File mode
|
||||
// Read, write, execute/search by owner
|
||||
// Read, write, execute/search by group
|
||||
S_IRWXG = 0000070; // RWX mask for group
|
||||
S_IRGRP = 0000040; // R for group
|
||||
S_IWGRP = 0000020; // W for group
|
||||
S_IXGRP = 0000010; // X for group
|
||||
|
||||
const S_IRWXU = 0000700; // RWX mask for owner
|
||||
const S_IRUSR = 0000400; // R for owner
|
||||
const S_IWUSR = 0000200; // W for owner
|
||||
const S_IXUSR = 0000100; // X for owner
|
||||
// Read, write, execute/search by others
|
||||
S_IRWXO = 0000007; // RWX mask for other
|
||||
S_IROTH = 0000004; // R for other
|
||||
S_IWOTH = 0000002; // W for other
|
||||
S_IXOTH = 0000001; // X for other
|
||||
|
||||
// Read, write, execute/search by group
|
||||
|
||||
const S_IRWXG = 0000070; // RWX mask for group
|
||||
const S_IRGRP = 0000040; // R for group
|
||||
const S_IWGRP = 0000020; // W for group
|
||||
const S_IXGRP = 0000010; // X for group
|
||||
|
||||
// Read, write, execute/search by others
|
||||
|
||||
const S_IRWXO = 0000007; // RWX mask for other
|
||||
const S_IROTH = 0000004; // R for other
|
||||
const S_IWOTH = 0000002; // W for other
|
||||
const S_IXOTH = 0000001; // X for other
|
||||
|
||||
const S_ISUID = 0004000; // Set user id on execution
|
||||
const S_ISGID = 0002000; // Set group id on execution
|
||||
const S_ISVTX = 0001000; // Directory restrcted delete
|
||||
S_ISUID = 0004000; // Set user id on execution
|
||||
S_ISGID = 0002000; // Set group id on execution
|
||||
S_ISVTX = 0001000; // Directory restrcted delete
|
||||
)
|
||||
|
||||
proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
|
||||
proc S_ISREG (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; }
|
||||
@@ -114,13 +116,12 @@ proc S_ISBLK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; }
|
||||
proc S_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
|
||||
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
||||
|
||||
const R_OK = 4; // Test for read permission
|
||||
const W_OK = 2; // Test for write permission
|
||||
const X_OK = 1; // Test for execute permission
|
||||
const F_OK = 0; // Test for file existance
|
||||
|
||||
#foreign_system_library dl "dl";
|
||||
#foreign_system_library libc "c";
|
||||
const (
|
||||
R_OK = 4; // Test for read permission
|
||||
W_OK = 2; // Test for write permission
|
||||
X_OK = 1; // Test for execute permission
|
||||
F_OK = 0; // Test for file existance
|
||||
)
|
||||
|
||||
proc _unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
|
||||
proc _unix_close (fd: Handle) -> i32 #foreign libc "close";
|
||||
@@ -187,10 +188,11 @@ proc file_size(fd: Handle) -> (i64, Errno) {
|
||||
|
||||
|
||||
// NOTE(bill): Uses startup to initialize it
|
||||
var stdin: Handle = 0;
|
||||
var stdout: Handle = 1;
|
||||
var stderr: Handle = 2;
|
||||
|
||||
var (
|
||||
stdin: Handle = 0;
|
||||
stdout: Handle = 1;
|
||||
stderr: Handle = 2;
|
||||
)
|
||||
/* TODO(zangent): Implement these!
|
||||
proc last_write_time(fd: Handle) -> FileTime {}
|
||||
proc last_write_time_by_name(name: string) -> FileTime {}
|
||||
|
||||
+45
-43
@@ -1,52 +1,54 @@
|
||||
import win32 "sys/windows.odin";
|
||||
|
||||
type Handle int;
|
||||
type FileTime u64;
|
||||
type Errno int;
|
||||
type (
|
||||
Handle int;
|
||||
FileTime u64;
|
||||
Errno int;
|
||||
)
|
||||
|
||||
const INVALID_HANDLE: Handle = -1;
|
||||
const (
|
||||
INVALID_HANDLE: Handle = -1;
|
||||
|
||||
O_RDONLY = 0x00000;
|
||||
O_WRONLY = 0x00001;
|
||||
O_RDWR = 0x00002;
|
||||
O_CREAT = 0x00040;
|
||||
O_EXCL = 0x00080;
|
||||
O_NOCTTY = 0x00100;
|
||||
O_TRUNC = 0x00200;
|
||||
O_NONBLOCK = 0x00800;
|
||||
O_APPEND = 0x00400;
|
||||
O_SYNC = 0x01000;
|
||||
O_ASYNC = 0x02000;
|
||||
O_CLOEXEC = 0x80000;
|
||||
|
||||
const O_RDONLY = 0x00000;
|
||||
const O_WRONLY = 0x00001;
|
||||
const O_RDWR = 0x00002;
|
||||
const O_CREAT = 0x00040;
|
||||
const O_EXCL = 0x00080;
|
||||
const O_NOCTTY = 0x00100;
|
||||
const O_TRUNC = 0x00200;
|
||||
const O_NONBLOCK = 0x00800;
|
||||
const O_APPEND = 0x00400;
|
||||
const O_SYNC = 0x01000;
|
||||
const O_ASYNC = 0x02000;
|
||||
const O_CLOEXEC = 0x80000;
|
||||
|
||||
const ERROR_NONE: Errno = 0;
|
||||
const ERROR_FILE_NOT_FOUND: Errno = 2;
|
||||
const ERROR_PATH_NOT_FOUND: Errno = 3;
|
||||
const ERROR_ACCESS_DENIED: Errno = 5;
|
||||
const ERROR_NO_MORE_FILES: Errno = 18;
|
||||
const ERROR_HANDLE_EOF: Errno = 38;
|
||||
const ERROR_NETNAME_DELETED: Errno = 64;
|
||||
const ERROR_FILE_EXISTS: Errno = 80;
|
||||
const ERROR_BROKEN_PIPE: Errno = 109;
|
||||
const ERROR_BUFFER_OVERFLOW: Errno = 111;
|
||||
const ERROR_INSUFFICIENT_BUFFER: Errno = 122;
|
||||
const ERROR_MOD_NOT_FOUND: Errno = 126;
|
||||
const ERROR_PROC_NOT_FOUND: Errno = 127;
|
||||
const ERROR_DIR_NOT_EMPTY: Errno = 145;
|
||||
const ERROR_ALREADY_EXISTS: Errno = 183;
|
||||
const ERROR_ENVVAR_NOT_FOUND: Errno = 203;
|
||||
const ERROR_MORE_DATA: Errno = 234;
|
||||
const ERROR_OPERATION_ABORTED: Errno = 995;
|
||||
const ERROR_IO_PENDING: Errno = 997;
|
||||
const ERROR_NOT_FOUND: Errno = 1168;
|
||||
const ERROR_PRIVILEGE_NOT_HELD: Errno = 1314;
|
||||
const WSAEACCES: Errno = 10013;
|
||||
const WSAECONNRESET: Errno = 10054;
|
||||
|
||||
// Windows reserves errors >= 1<<29 for application use
|
||||
const ERROR_FILE_IS_PIPE: Errno = 1<<29 + 0;
|
||||
ERROR_NONE: Errno = 0;
|
||||
ERROR_FILE_NOT_FOUND: Errno = 2;
|
||||
ERROR_PATH_NOT_FOUND: Errno = 3;
|
||||
ERROR_ACCESS_DENIED: Errno = 5;
|
||||
ERROR_NO_MORE_FILES: Errno = 18;
|
||||
ERROR_HANDLE_EOF: Errno = 38;
|
||||
ERROR_NETNAME_DELETED: Errno = 64;
|
||||
ERROR_FILE_EXISTS: Errno = 80;
|
||||
ERROR_BROKEN_PIPE: Errno = 109;
|
||||
ERROR_BUFFER_OVERFLOW: Errno = 111;
|
||||
ERROR_INSUFFICIENT_BUFFER: Errno = 122;
|
||||
ERROR_MOD_NOT_FOUND: Errno = 126;
|
||||
ERROR_PROC_NOT_FOUND: Errno = 127;
|
||||
ERROR_DIR_NOT_EMPTY: Errno = 145;
|
||||
ERROR_ALREADY_EXISTS: Errno = 183;
|
||||
ERROR_ENVVAR_NOT_FOUND: Errno = 203;
|
||||
ERROR_MORE_DATA: Errno = 234;
|
||||
ERROR_OPERATION_ABORTED: Errno = 995;
|
||||
ERROR_IO_PENDING: Errno = 997;
|
||||
ERROR_NOT_FOUND: Errno = 1168;
|
||||
ERROR_PRIVILEGE_NOT_HELD: Errno = 1314;
|
||||
WSAEACCES: Errno = 10013;
|
||||
WSAECONNRESET: Errno = 10054;
|
||||
|
||||
// Windows reserves errors >= 1<<29 for application use
|
||||
ERROR_FILE_IS_PIPE: Errno = 1<<29 + 0;
|
||||
)
|
||||
|
||||
// "Argv" arguments converted to Odin strings
|
||||
let args = _alloc_command_line_arguments();
|
||||
|
||||
+77
-76
@@ -1,43 +1,46 @@
|
||||
#foreign_system_library dl "dl";
|
||||
#foreign_system_library libc "c";
|
||||
import "fmt.odin";
|
||||
import "strings.odin";
|
||||
|
||||
type Handle i32;
|
||||
type FileTime u64;
|
||||
type Errno int;
|
||||
type (
|
||||
Handle i32;
|
||||
FileTime u64;
|
||||
Errno int;
|
||||
|
||||
// TODO(zangent): Find out how to make this work on x64 and x32.
|
||||
type AddressSize i64;
|
||||
AddressSize int;
|
||||
)
|
||||
|
||||
// INVALID_HANDLE: Handle : -1;
|
||||
const (
|
||||
O_RDONLY = 0x00000;
|
||||
O_WRONLY = 0x00001;
|
||||
O_RDWR = 0x00002;
|
||||
O_CREAT = 0x00040;
|
||||
O_EXCL = 0x00080;
|
||||
O_NOCTTY = 0x00100;
|
||||
O_TRUNC = 0x00200;
|
||||
O_NONBLOCK = 0x00800;
|
||||
O_APPEND = 0x00400;
|
||||
O_SYNC = 0x01000;
|
||||
O_ASYNC = 0x02000;
|
||||
O_CLOEXEC = 0x80000;
|
||||
SEEK_SET = 0;
|
||||
SEEK_CUR = 1;
|
||||
SEEK_END = 2;
|
||||
SEEK_DATA = 3;
|
||||
SEEK_HOLE = 4;
|
||||
SEEK_MAX = SEEK_HOLE;
|
||||
|
||||
const O_RDONLY = 0x00000;
|
||||
const O_WRONLY = 0x00001;
|
||||
const O_RDWR = 0x00002;
|
||||
const O_CREAT = 0x00040;
|
||||
const O_EXCL = 0x00080;
|
||||
const O_NOCTTY = 0x00100;
|
||||
const O_TRUNC = 0x00200;
|
||||
const O_NONBLOCK = 0x00800;
|
||||
const O_APPEND = 0x00400;
|
||||
const O_SYNC = 0x01000;
|
||||
const O_ASYNC = 0x02000;
|
||||
const O_CLOEXEC = 0x80000;
|
||||
const SEEK_SET = 0;
|
||||
const SEEK_CUR = 1;
|
||||
const SEEK_END = 2;
|
||||
const SEEK_DATA = 3;
|
||||
const SEEK_HOLE = 4;
|
||||
const SEEK_MAX = SEEK_HOLE;
|
||||
|
||||
// NOTE(zangent): These are OS specific!
|
||||
// Do not mix these up!
|
||||
const RTLD_LAZY = 0x1;
|
||||
const RTLD_NOW = 0x2;
|
||||
const RTLD_LOCAL = 0x4;
|
||||
const RTLD_GLOBAL = 0x8;
|
||||
const RTLD_NODELETE = 0x80;
|
||||
const RTLD_NOLOAD = 0x10;
|
||||
const RTLD_FIRST = 0x100;
|
||||
// NOTE(zangent): These are OS specific!
|
||||
// Do not mix these up!
|
||||
RTLD_LAZY = 0x1;
|
||||
RTLD_NOW = 0x2;
|
||||
RTLD_LOCAL = 0x4;
|
||||
RTLD_GLOBAL = 0x8;
|
||||
RTLD_NODELETE = 0x80;
|
||||
RTLD_NOLOAD = 0x10;
|
||||
RTLD_FIRST = 0x100;
|
||||
)
|
||||
|
||||
var args: [dynamic]string;
|
||||
|
||||
@@ -71,41 +74,39 @@ type Stat struct #ordered {
|
||||
};
|
||||
|
||||
// File type
|
||||
const (
|
||||
S_IFMT = 0170000; // Type of file mask
|
||||
S_IFIFO = 0010000; // Named pipe (fifo)
|
||||
S_IFCHR = 0020000; // Character special
|
||||
S_IFDIR = 0040000; // Directory
|
||||
S_IFBLK = 0060000; // Block special
|
||||
S_IFREG = 0100000; // Regular
|
||||
S_IFLNK = 0120000; // Symbolic link
|
||||
S_IFSOCK = 0140000; // Socket
|
||||
|
||||
const S_IFMT = 0170000; // Type of file mask
|
||||
const S_IFIFO = 0010000; // Named pipe (fifo)
|
||||
const S_IFCHR = 0020000; // Character special
|
||||
const S_IFDIR = 0040000; // Directory
|
||||
const S_IFBLK = 0060000; // Block special
|
||||
const S_IFREG = 0100000; // Regular
|
||||
const S_IFLNK = 0120000; // Symbolic link
|
||||
const S_IFSOCK = 0140000; // Socket
|
||||
// File mode
|
||||
// Read, write, execute/search by owner
|
||||
S_IRWXU = 0000700; // RWX mask for owner
|
||||
S_IRUSR = 0000400; // R for owner
|
||||
S_IWUSR = 0000200; // W for owner
|
||||
S_IXUSR = 0000100; // X for owner
|
||||
|
||||
// File mode
|
||||
// Read, write, execute/search by owner
|
||||
// Read, write, execute/search by group
|
||||
S_IRWXG = 0000070; // RWX mask for group
|
||||
S_IRGRP = 0000040; // R for group
|
||||
S_IWGRP = 0000020; // W for group
|
||||
S_IXGRP = 0000010; // X for group
|
||||
|
||||
const S_IRWXU = 0000700; // RWX mask for owner
|
||||
const S_IRUSR = 0000400; // R for owner
|
||||
const S_IWUSR = 0000200; // W for owner
|
||||
const S_IXUSR = 0000100; // X for owner
|
||||
// Read, write, execute/search by others
|
||||
S_IRWXO = 0000007; // RWX mask for other
|
||||
S_IROTH = 0000004; // R for other
|
||||
S_IWOTH = 0000002; // W for other
|
||||
S_IXOTH = 0000001; // X for other
|
||||
|
||||
// Read, write, execute/search by group
|
||||
|
||||
const S_IRWXG = 0000070; // RWX mask for group
|
||||
const S_IRGRP = 0000040; // R for group
|
||||
const S_IWGRP = 0000020; // W for group
|
||||
const S_IXGRP = 0000010; // X for group
|
||||
|
||||
// Read, write, execute/search by others
|
||||
|
||||
const S_IRWXO = 0000007; // RWX mask for other
|
||||
const S_IROTH = 0000004; // R for other
|
||||
const S_IWOTH = 0000002; // W for other
|
||||
const S_IXOTH = 0000001; // X for other
|
||||
|
||||
const S_ISUID = 0004000; // Set user id on execution
|
||||
const S_ISGID = 0002000; // Set group id on execution
|
||||
const S_ISVTX = 0001000; // Directory restrcted delete
|
||||
S_ISUID = 0004000; // Set user id on execution
|
||||
S_ISGID = 0002000; // Set group id on execution
|
||||
S_ISVTX = 0001000; // Directory restrcted delete
|
||||
)
|
||||
|
||||
proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
|
||||
proc S_ISREG (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; }
|
||||
@@ -115,13 +116,12 @@ proc S_ISBLK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; }
|
||||
proc S_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
|
||||
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
||||
|
||||
const R_OK = 4; // Test for read permission
|
||||
const W_OK = 2; // Test for write permission
|
||||
const X_OK = 1; // Test for execute permission
|
||||
const F_OK = 0; // Test for file existance
|
||||
|
||||
#foreign_system_library dl "dl";
|
||||
#foreign_system_library libc "c";
|
||||
const (
|
||||
R_OK = 4; // Test for read permission
|
||||
W_OK = 2; // Test for write permission
|
||||
X_OK = 1; // Test for execute permission
|
||||
F_OK = 0; // Test for file existance
|
||||
)
|
||||
|
||||
proc unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
|
||||
proc unix_close (handle: Handle) #foreign libc "close";
|
||||
@@ -206,10 +206,11 @@ proc file_size(fd: Handle) -> (i64, Errno) {
|
||||
|
||||
|
||||
// NOTE(bill): Uses startup to initialize it
|
||||
var stdin: Handle = 0; // get_std_handle(win32.STD_INPUT_HANDLE);
|
||||
var stdout: Handle = 1; // get_std_handle(win32.STD_OUTPUT_HANDLE);
|
||||
var stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_HANDLE);
|
||||
|
||||
var (
|
||||
stdin: Handle = 0; // get_std_handle(win32.STD_INPUT_HANDLE);
|
||||
stdout: Handle = 1; // get_std_handle(win32.STD_OUTPUT_HANDLE);
|
||||
stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_HANDLE);
|
||||
)
|
||||
/* TODO(zangent): Implement these!
|
||||
proc last_write_time(fd: Handle) -> FileTime {}
|
||||
proc last_write_time_by_name(name: string) -> FileTime {}
|
||||
|
||||
+25
-23
@@ -1,27 +1,29 @@
|
||||
type Any struct #ordered {
|
||||
data: rawptr,
|
||||
type_info: ^TypeInfo,
|
||||
};
|
||||
type (
|
||||
Any struct #ordered {
|
||||
data: rawptr,
|
||||
type_info: ^TypeInfo,
|
||||
};
|
||||
|
||||
type String struct #ordered {
|
||||
data: ^u8,
|
||||
len: int,
|
||||
};
|
||||
String struct #ordered {
|
||||
data: ^u8,
|
||||
len: int,
|
||||
};
|
||||
|
||||
type Slice struct #ordered {
|
||||
data: rawptr,
|
||||
len: int,
|
||||
cap: int,
|
||||
};
|
||||
Slice struct #ordered {
|
||||
data: rawptr,
|
||||
len: int,
|
||||
cap: int,
|
||||
};
|
||||
|
||||
type DynamicArray struct #ordered {
|
||||
data: rawptr,
|
||||
len: int,
|
||||
cap: int,
|
||||
allocator: Allocator,
|
||||
};
|
||||
DynamicArray struct #ordered {
|
||||
data: rawptr,
|
||||
len: int,
|
||||
cap: int,
|
||||
allocator: Allocator,
|
||||
};
|
||||
|
||||
type DynamicMap struct #ordered {
|
||||
hashes: [dynamic]int,
|
||||
entries: DynamicArray,
|
||||
};
|
||||
DynamicMap struct #ordered {
|
||||
hashes: [dynamic]int,
|
||||
entries: DynamicArray,
|
||||
};
|
||||
)
|
||||
|
||||
+4
-2
@@ -1,2 +1,4 @@
|
||||
import_load "sync_windows.odin" when ODIN_OS == "windows";
|
||||
import_load "sync_linux.odin" when ODIN_OS == "linux";
|
||||
import_load (
|
||||
"sync_windows.odin" when ODIN_OS == "windows";
|
||||
"sync_linux.odin" when ODIN_OS == "linux";
|
||||
)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import "atomics.odin";
|
||||
import "os.odin";
|
||||
import (
|
||||
"atomics.odin";
|
||||
"os.odin";
|
||||
)
|
||||
|
||||
type Semaphore struct {
|
||||
// _handle: win32.Handle,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||
import "atomics.odin";
|
||||
import (
|
||||
win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||
"atomics.odin";
|
||||
)
|
||||
|
||||
type Semaphore struct {
|
||||
_handle: win32.Handle,
|
||||
|
||||
+8
-7
@@ -1,11 +1,12 @@
|
||||
const REPLACEMENT_CHAR = '\uFFFD';
|
||||
const MAX_RUNE = '\U0010FFFF';
|
||||
|
||||
const _surr1 = 0xd800;
|
||||
const _surr2 = 0xdc00;
|
||||
const _surr3 = 0xe000;
|
||||
const _surr_self = 0x10000;
|
||||
const (
|
||||
REPLACEMENT_CHAR = '\uFFFD';
|
||||
MAX_RUNE = '\U0010FFFF';
|
||||
|
||||
_surr1 = 0xd800;
|
||||
_surr2 = 0xdc00;
|
||||
_surr3 = 0xe000;
|
||||
_surr_self = 0x10000;
|
||||
)
|
||||
|
||||
proc is_surrogate(r: rune) -> bool {
|
||||
return _surr1 <= r && r < _surr3;
|
||||
|
||||
+53
-49
@@ -1,62 +1,66 @@
|
||||
const RUNE_ERROR = '\ufffd';
|
||||
const RUNE_SELF = 0x80;
|
||||
const RUNE_BOM = 0xfeff;
|
||||
const RUNE_EOF = ~rune(0);
|
||||
const MAX_RUNE = '\U0010ffff';
|
||||
const UTF_MAX = 4;
|
||||
const (
|
||||
RUNE_ERROR = '\ufffd';
|
||||
RUNE_SELF = 0x80;
|
||||
RUNE_BOM = 0xfeff;
|
||||
RUNE_EOF = ~rune(0);
|
||||
MAX_RUNE = '\U0010ffff';
|
||||
UTF_MAX = 4;
|
||||
|
||||
const SURROGATE_MIN = 0xd800;
|
||||
const SURROGATE_MAX = 0xdfff;
|
||||
SURROGATE_MIN = 0xd800;
|
||||
SURROGATE_MAX = 0xdfff;
|
||||
|
||||
const T1 = 0b0000_0000;
|
||||
const TX = 0b1000_0000;
|
||||
const T2 = 0b1100_0000;
|
||||
const T3 = 0b1110_0000;
|
||||
const T4 = 0b1111_0000;
|
||||
const T5 = 0b1111_1000;
|
||||
T1 = 0b0000_0000;
|
||||
TX = 0b1000_0000;
|
||||
T2 = 0b1100_0000;
|
||||
T3 = 0b1110_0000;
|
||||
T4 = 0b1111_0000;
|
||||
T5 = 0b1111_1000;
|
||||
|
||||
const MASKX = 0b0011_1111;
|
||||
const MASK2 = 0b0001_1111;
|
||||
const MASK3 = 0b0000_1111;
|
||||
const MASK4 = 0b0000_0111;
|
||||
MASKX = 0b0011_1111;
|
||||
MASK2 = 0b0001_1111;
|
||||
MASK3 = 0b0000_1111;
|
||||
MASK4 = 0b0000_0111;
|
||||
|
||||
const RUNE1_MAX = 1<<7 - 1;
|
||||
const RUNE2_MAX = 1<<11 - 1;
|
||||
const RUNE3_MAX = 1<<16 - 1;
|
||||
RUNE1_MAX = 1<<7 - 1;
|
||||
RUNE2_MAX = 1<<11 - 1;
|
||||
RUNE3_MAX = 1<<16 - 1;
|
||||
|
||||
// The default lowest and highest continuation byte.
|
||||
const LOCB = 0b1000_0000;
|
||||
const HICB = 0b1011_1111;
|
||||
// The default lowest and highest continuation byte.
|
||||
LOCB = 0b1000_0000;
|
||||
HICB = 0b1011_1111;
|
||||
)
|
||||
|
||||
type AcceptRange struct { lo, hi: u8 }
|
||||
|
||||
let accept_ranges = [5]AcceptRange{
|
||||
{0x80, 0xbf},
|
||||
{0xa0, 0xbf},
|
||||
{0x80, 0x9f},
|
||||
{0x90, 0xbf},
|
||||
{0x80, 0x8f},
|
||||
};
|
||||
let (
|
||||
accept_ranges = [5]AcceptRange{
|
||||
{0x80, 0xbf},
|
||||
{0xa0, 0xbf},
|
||||
{0x80, 0x9f},
|
||||
{0x90, 0xbf},
|
||||
{0x80, 0x8f},
|
||||
};
|
||||
|
||||
let accept_sizes = [256]u8{
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x00-0x0f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x10-0x1f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x20-0x2f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x30-0x3f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x40-0x4f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x50-0x5f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x60-0x6f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x70-0x7f
|
||||
accept_sizes = [256]u8{
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x00-0x0f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x10-0x1f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x20-0x2f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x30-0x3f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x40-0x4f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x50-0x5f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x60-0x6f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x70-0x7f
|
||||
|
||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0x80-0x8f
|
||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0x90-0x9f
|
||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xa0-0xaf
|
||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xb0-0xbf
|
||||
0xf1, 0xf1, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 0xc0-0xcf
|
||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 0xd0-0xdf
|
||||
0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x23, 0x03, 0x03, // 0xe0-0xef
|
||||
0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff
|
||||
};
|
||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0x80-0x8f
|
||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0x90-0x9f
|
||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xa0-0xaf
|
||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xb0-0xbf
|
||||
0xf1, 0xf1, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 0xc0-0xcf
|
||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 0xd0-0xdf
|
||||
0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x23, 0x03, 0x03, // 0xe0-0xef
|
||||
0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff
|
||||
};
|
||||
)
|
||||
|
||||
proc encode_rune(r: rune) -> ([4]u8, int) {
|
||||
var buf: [4]u8;
|
||||
|
||||
Reference in New Issue
Block a user