mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Pascal style declaration grouping with ()
This commit is contained in:
+20
-12
@@ -1,15 +1,23 @@
|
|||||||
import "fmt.odin";
|
import (
|
||||||
import "atomics.odin";
|
"fmt.odin";
|
||||||
import "bits.odin";
|
"hash.odin";
|
||||||
import "math.odin";
|
"atomics.odin";
|
||||||
import "mem.odin";
|
"bits.odin";
|
||||||
import "opengl.odin";
|
"math.odin";
|
||||||
import "strconv.odin";
|
"mem.odin";
|
||||||
import "strings.odin";
|
"opengl.odin";
|
||||||
import "sync.odin";
|
"strconv.odin";
|
||||||
import "types.odin";
|
"strings.odin";
|
||||||
import "utf8.odin";
|
"sync.odin";
|
||||||
import "utf16.odin";
|
"types.odin";
|
||||||
|
"utf8.odin";
|
||||||
|
"utf16.odin";
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
X = 123;
|
||||||
|
Y = 432;
|
||||||
|
)
|
||||||
|
|
||||||
proc main() {
|
proc main() {
|
||||||
proc(s: string){
|
proc(s: string){
|
||||||
|
|||||||
+137
-129
@@ -1,10 +1,11 @@
|
|||||||
#shared_global_scope;
|
#shared_global_scope;
|
||||||
|
|
||||||
import "os.odin";
|
import (
|
||||||
import "fmt.odin";
|
"os.odin";
|
||||||
import "utf8.odin";
|
"fmt.odin";
|
||||||
import "raw.odin";
|
"utf8.odin";
|
||||||
|
"raw.odin";
|
||||||
|
)
|
||||||
// Naming Conventions:
|
// Naming Conventions:
|
||||||
// In general, PascalCase for types and snake_case for values
|
// 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
|
// IMPORTANT NOTE(bill): Do not change the order of any of this data
|
||||||
// The compiler relies upon this _exact_ order
|
// The compiler relies upon this _exact_ order
|
||||||
type TypeInfoEnumValue raw_union {
|
type (
|
||||||
f: f64,
|
TypeInfoEnumValue raw_union {
|
||||||
i: i128,
|
f: f64,
|
||||||
}
|
i: i128,
|
||||||
// NOTE(bill): This must match the compiler's
|
}
|
||||||
type CallingConvention enum {
|
// NOTE(bill): This must match the compiler's
|
||||||
Odin = 0,
|
CallingConvention enum {
|
||||||
C = 1,
|
Odin = 0,
|
||||||
Std = 2,
|
C = 1,
|
||||||
Fast = 3,
|
Std = 2,
|
||||||
}
|
Fast = 3,
|
||||||
|
}
|
||||||
|
|
||||||
type TypeInfoRecord struct #ordered {
|
TypeInfoRecord struct #ordered {
|
||||||
types: []^TypeInfo,
|
types: []^TypeInfo,
|
||||||
names: []string,
|
names: []string,
|
||||||
offsets: []int, // offsets may not be used in tuples
|
offsets: []int, // offsets may not be used in tuples
|
||||||
usings: []bool, // usings may not be used in tuples
|
usings: []bool, // usings may not be used in tuples
|
||||||
packed: bool,
|
packed: bool,
|
||||||
ordered: bool,
|
ordered: bool,
|
||||||
custom_align: bool,
|
custom_align: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
type TypeInfo union {
|
TypeInfo union {
|
||||||
size: int,
|
size: int,
|
||||||
align: int,
|
align: int,
|
||||||
|
|
||||||
Named{name: string, base: ^TypeInfo},
|
Named{name: string, base: ^TypeInfo},
|
||||||
Integer{signed: bool},
|
Integer{signed: bool},
|
||||||
Rune{},
|
Rune{},
|
||||||
Float{},
|
Float{},
|
||||||
Complex{},
|
Complex{},
|
||||||
String{},
|
String{},
|
||||||
Boolean{},
|
Boolean{},
|
||||||
Any{},
|
Any{},
|
||||||
Pointer{
|
Pointer{
|
||||||
elem: ^TypeInfo, // nil -> rawptr
|
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
|
|
||||||
},
|
},
|
||||||
variant_names: []string,
|
Atomic{elem: ^TypeInfo},
|
||||||
variant_types: []^TypeInfo,
|
Procedure{
|
||||||
},
|
params: ^TypeInfo, // TypeInfo.Tuple
|
||||||
Enum{
|
results: ^TypeInfo, // TypeInfo.Tuple
|
||||||
base: ^TypeInfo,
|
variadic: bool,
|
||||||
names: []string,
|
convention: CallingConvention,
|
||||||
values: []TypeInfoEnumValue,
|
},
|
||||||
},
|
Array{
|
||||||
Map{
|
elem: ^TypeInfo,
|
||||||
key: ^TypeInfo,
|
elem_size: int,
|
||||||
value: ^TypeInfo,
|
count: int,
|
||||||
generated_struct: ^TypeInfo,
|
},
|
||||||
count: int, // == 0 if dynamic
|
DynamicArray{elem: ^TypeInfo, elem_size: int},
|
||||||
},
|
Slice {elem: ^TypeInfo, elem_size: int},
|
||||||
BitField{
|
Vector {elem: ^TypeInfo, elem_size, count: int},
|
||||||
names: []string,
|
Tuple {using record: TypeInfoRecord}, // Only really used for procedures
|
||||||
bits: []i32,
|
Struct {using record: TypeInfoRecord},
|
||||||
offsets: []i32,
|
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)
|
// NOTE(bill): only the ones that are needed (not all types)
|
||||||
// This will be set by the compiler
|
// This will be set by the compiler
|
||||||
var __type_table: []TypeInfo;
|
var (
|
||||||
|
__type_table: []TypeInfo;
|
||||||
|
|
||||||
var __argv__: ^^u8;
|
__argv__: ^^u8;
|
||||||
var __argc__: i32;
|
__argc__: i32;
|
||||||
|
)
|
||||||
|
|
||||||
proc type_info_base(info: ^TypeInfo) -> ^TypeInfo {
|
proc type_info_base(info: ^TypeInfo) -> ^TypeInfo {
|
||||||
if info == nil {
|
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)
|
// IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it)
|
||||||
type AllocatorMode enum u8 {
|
type (
|
||||||
Alloc,
|
AllocatorMode enum u8 {
|
||||||
Free,
|
Alloc,
|
||||||
FreeAll,
|
Free,
|
||||||
Resize,
|
FreeAll,
|
||||||
}
|
Resize,
|
||||||
type AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode,
|
}
|
||||||
size, alignment: int,
|
AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode,
|
||||||
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
|
size, alignment: int,
|
||||||
type Allocator struct #ordered {
|
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
|
||||||
procedure: AllocatorProc,
|
Allocator struct #ordered {
|
||||||
data: rawptr,
|
procedure: AllocatorProc,
|
||||||
}
|
data: rawptr,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type Context struct #ordered {
|
Context struct #ordered {
|
||||||
thread_id: int,
|
thread_id: int,
|
||||||
|
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
|
|
||||||
user_data: rawptr,
|
user_data: rawptr,
|
||||||
user_index: int,
|
user_index: int,
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
#thread_local var __context: Context;
|
#thread_local var __context: Context;
|
||||||
|
|
||||||
@@ -553,33 +559,35 @@ proc __default_hash_string(s: string) -> u128 {
|
|||||||
|
|
||||||
const __INITIAL_MAP_CAP = 16;
|
const __INITIAL_MAP_CAP = 16;
|
||||||
|
|
||||||
type __MapKey struct #ordered {
|
type (
|
||||||
hash: u128,
|
__MapKey struct #ordered {
|
||||||
str: string,
|
hash: u128,
|
||||||
}
|
str: string,
|
||||||
|
}
|
||||||
|
|
||||||
type __MapFindResult struct #ordered {
|
__MapFindResult struct #ordered {
|
||||||
hash_index: int,
|
hash_index: int,
|
||||||
entry_prev: int,
|
entry_prev: int,
|
||||||
entry_index: int,
|
entry_index: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
type __MapEntryHeader struct #ordered {
|
__MapEntryHeader struct #ordered {
|
||||||
key: __MapKey,
|
key: __MapKey,
|
||||||
next: int,
|
next: int,
|
||||||
/*
|
/*
|
||||||
value: Value_Type,
|
value: Value_Type,
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
type __MapHeader struct #ordered {
|
__MapHeader struct #ordered {
|
||||||
m: ^raw.DynamicMap,
|
m: ^raw.DynamicMap,
|
||||||
is_key_string: bool,
|
is_key_string: bool,
|
||||||
entry_size: int,
|
entry_size: int,
|
||||||
entry_align: int,
|
entry_align: int,
|
||||||
value_offset: int,
|
value_offset: int,
|
||||||
value_size: int,
|
value_size: int,
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
proc __dynamic_map_reserve(using header: __MapHeader, cap: int) {
|
proc __dynamic_map_reserve(using header: __MapHeader, cap: int) {
|
||||||
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap);
|
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap);
|
||||||
|
|||||||
+22
-21
@@ -1,27 +1,28 @@
|
|||||||
const U8_MIN = u8(0);
|
const (
|
||||||
const U16_MIN = u16(0);
|
U8_MIN = u8(0);
|
||||||
const U32_MIN = u32(0);
|
U16_MIN = u16(0);
|
||||||
const U64_MIN = u64(0);
|
U32_MIN = u32(0);
|
||||||
const U128_MIN = u128(0);
|
U64_MIN = u64(0);
|
||||||
|
U128_MIN = u128(0);
|
||||||
|
|
||||||
const I8_MIN = i8(-0x80);
|
I8_MIN = i8(-0x80);
|
||||||
const I16_MIN = i16(-0x8000);
|
I16_MIN = i16(-0x8000);
|
||||||
const I32_MIN = i32(-0x8000_0000);
|
I32_MIN = i32(-0x8000_0000);
|
||||||
const I64_MIN = i64(-0x8000_0000_0000_0000);
|
I64_MIN = i64(-0x8000_0000_0000_0000);
|
||||||
const I128_MIN = i128(-0x8000_0000_0000_0000_0000_0000_0000_0000);
|
I128_MIN = i128(-0x8000_0000_0000_0000_0000_0000_0000_0000);
|
||||||
|
|
||||||
const U8_MAX = ~u8(0);
|
U8_MAX = ~u8(0);
|
||||||
const U16_MAX = ~u16(0);
|
U16_MAX = ~u16(0);
|
||||||
const U32_MAX = ~u32(0);
|
U32_MAX = ~u32(0);
|
||||||
const U64_MAX = ~u64(0);
|
U64_MAX = ~u64(0);
|
||||||
const U128_MAX = ~u128(0);
|
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);
|
|
||||||
|
|
||||||
|
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: 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); }
|
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 (
|
||||||
import "mem.odin";
|
"os.odin";
|
||||||
import "utf8.odin";
|
"mem.odin";
|
||||||
import "types.odin";
|
"utf8.odin";
|
||||||
import "strconv.odin";
|
"types.odin";
|
||||||
import "raw.odin";
|
"strconv.odin";
|
||||||
|
"raw.odin";
|
||||||
|
)
|
||||||
|
|
||||||
const _BUFFER_SIZE = 1<<12;
|
const _BUFFER_SIZE = 1<<12;
|
||||||
|
|
||||||
|
|||||||
+42
-42
@@ -1,61 +1,61 @@
|
|||||||
crc32 :: proc(data: []u8) -> u32 {
|
proc crc32(data: []u8) -> u32 {
|
||||||
result := ~u32(0);
|
var result = ~u32(0);
|
||||||
for b in data {
|
for b in data {
|
||||||
result = result>>8 ~ _crc32_table[(result ~ u32(b)) & 0xff];
|
result = result>>8 ~ _crc32_table[(result ~ u32(b)) & 0xff];
|
||||||
}
|
}
|
||||||
return ~result;
|
return ~result;
|
||||||
}
|
}
|
||||||
crc64 :: proc(data: []u8) -> u64 {
|
proc crc64(data: []u8) -> u64 {
|
||||||
result := ~u64(0);
|
var result = ~u64(0);
|
||||||
for b in data {
|
for b in data {
|
||||||
result = result>>8 ~ _crc64_table[(result ~ u64(b)) & 0xff];
|
result = result>>8 ~ _crc64_table[(result ~ u64(b)) & 0xff];
|
||||||
}
|
}
|
||||||
return ~result;
|
return ~result;
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv32 :: proc(data: []u8) -> u32 {
|
proc fnv32(data: []u8) -> u32 {
|
||||||
h: u32 = 0x811c9dc5;
|
var h: u32 = 0x811c9dc5;
|
||||||
for b in data {
|
for b in data {
|
||||||
h = (h * 0x01000193) ~ u32(b);
|
h = (h * 0x01000193) ~ u32(b);
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv64 :: proc(data: []u8) -> u64 {
|
proc fnv64(data: []u8) -> u64 {
|
||||||
h: u64 = 0xcbf29ce484222325;
|
var h: u64 = 0xcbf29ce484222325;
|
||||||
for b in data {
|
for b in data {
|
||||||
h = (h * 0x100000001b3) ~ u64(b);
|
h = (h * 0x100000001b3) ~ u64(b);
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv32a :: proc(data: []u8) -> u32 {
|
proc fnv32a(data: []u8) -> u32 {
|
||||||
h: u32 = 0x811c9dc5;
|
var h: u32 = 0x811c9dc5;
|
||||||
for b in data {
|
for b in data {
|
||||||
h = (h ~ u32(b)) * 0x01000193;
|
h = (h ~ u32(b)) * 0x01000193;
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
fnv64a :: proc(data: []u8) -> u64 {
|
proc fnv64a(data: []u8) -> u64 {
|
||||||
h: u64 = 0xcbf29ce484222325;
|
var h: u64 = 0xcbf29ce484222325;
|
||||||
for b in data {
|
for b in data {
|
||||||
h = (h ~ u64(b)) * 0x100000001b3;
|
h = (h ~ u64(b)) * 0x100000001b3;
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
murmur32 :: proc(data: []u8) -> u32 {
|
proc murmur32(data: []u8) -> u32 {
|
||||||
c1_32: u32 : 0xcc9e2d51;
|
const c1_32: u32 = 0xcc9e2d51;
|
||||||
c2_32: u32 : 0x1b873593;
|
const c2_32: u32 = 0x1b873593;
|
||||||
|
|
||||||
h1: u32 = 0;
|
var h1: u32 = 0;
|
||||||
nblocks := len(data)/4;
|
var nblocks = len(data)/4;
|
||||||
p := &data[0];
|
var p = &data[0];
|
||||||
p1 := p + 4*nblocks;
|
var p1 = p + 4*nblocks;
|
||||||
|
|
||||||
for ; p < p1; p += 4 {
|
for ; p < p1; p += 4 {
|
||||||
k1 := ^u32(p)^;
|
var k1 = ^u32(p)^;
|
||||||
|
|
||||||
k1 *= c1_32;
|
k1 *= c1_32;
|
||||||
k1 = (k1 << 15) | (k1 >> 17);
|
k1 = (k1 << 15) | (k1 >> 17);
|
||||||
@@ -66,9 +66,9 @@ murmur32 :: proc(data: []u8) -> u32 {
|
|||||||
h1 = h1*5 + 0xe6546b64;
|
h1 = h1*5 + 0xe6546b64;
|
||||||
}
|
}
|
||||||
|
|
||||||
tail := data[nblocks*4 ..];
|
var tail = data[nblocks*4 ..];
|
||||||
|
|
||||||
k1: u32;
|
var k1: u32;
|
||||||
match len(tail)&3 {
|
match len(tail)&3 {
|
||||||
case 3:
|
case 3:
|
||||||
k1 ~= u32(tail[2]) << 16;
|
k1 ~= u32(tail[2]) << 16;
|
||||||
@@ -95,18 +95,18 @@ murmur32 :: proc(data: []u8) -> u32 {
|
|||||||
return h1;
|
return h1;
|
||||||
}
|
}
|
||||||
|
|
||||||
murmur64 :: proc(data: []u8) -> u64 {
|
proc murmur64(data: []u8) -> u64 {
|
||||||
SEED :: 0x9747b28c;
|
const SEED = 0x9747b28c;
|
||||||
|
|
||||||
when size_of(int) == 8 {
|
when size_of(int) == 8 {
|
||||||
m :: 0xc6a4a7935bd1e995;
|
const m = 0xc6a4a7935bd1e995;
|
||||||
r :: 47;
|
const r = 47;
|
||||||
|
|
||||||
h: u64 = SEED ~ (u64(len(data)) * m);
|
var h: u64 = SEED ~ (u64(len(data)) * m);
|
||||||
data64 := slice_ptr(^u64(&data[0]), len(data)/size_of(u64));
|
var data64 = slice_ptr(^u64(&data[0]), len(data)/size_of(u64));
|
||||||
|
|
||||||
for _, i in data64 {
|
for _, i in data64 {
|
||||||
k := data64[i];
|
var k = data64[i];
|
||||||
|
|
||||||
k *= m;
|
k *= m;
|
||||||
k ~= k>>r;
|
k ~= k>>r;
|
||||||
@@ -134,18 +134,18 @@ murmur64 :: proc(data: []u8) -> u64 {
|
|||||||
|
|
||||||
return h;
|
return h;
|
||||||
} else {
|
} else {
|
||||||
m :: 0x5bd1e995;
|
const m = 0x5bd1e995;
|
||||||
r :: 24;
|
const r = 24;
|
||||||
|
|
||||||
h1 := u32(SEED) ~ u32(len(data));
|
var h1 = u32(SEED) ~ u32(len(data));
|
||||||
h2 := u32(SEED) >> 32;
|
var h2 = u32(SEED) >> 32;
|
||||||
|
|
||||||
data32 := slice_ptr(cast(^u32)&data[0], len(data)/size_of(u32));
|
var data32 = slice_ptr(cast(^u32)&data[0], len(data)/size_of(u32));
|
||||||
len := len(data);
|
var len = len(data);
|
||||||
|
|
||||||
i := 0;
|
var i = 0;
|
||||||
for len >= 8 {
|
for len >= 8 {
|
||||||
k1, k2: u32;
|
var k1, k2: u32;
|
||||||
k1 = data32[i]; i++;
|
k1 = data32[i]; i++;
|
||||||
k1 *= m;
|
k1 *= m;
|
||||||
k1 ~= k1>>r;
|
k1 ~= k1>>r;
|
||||||
@@ -164,7 +164,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len >= 4 {
|
if len >= 4 {
|
||||||
k1: u32;
|
var k1: u32;
|
||||||
k1 = data32[i]; i++;
|
k1 = data32[i]; i++;
|
||||||
k1 *= m;
|
k1 *= m;
|
||||||
k1 ~= k1>>r;
|
k1 ~= k1>>r;
|
||||||
@@ -175,7 +175,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bill): Fix this
|
// 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 {
|
match len {
|
||||||
case 3:
|
case 3:
|
||||||
h2 ~= u32(data8[2]) << 16;
|
h2 ~= u32(data8[2]) << 16;
|
||||||
@@ -197,13 +197,13 @@ murmur64 :: proc(data: []u8) -> u64 {
|
|||||||
h2 ~= h1>>19;
|
h2 ~= h1>>19;
|
||||||
h2 *= m;
|
h2 *= m;
|
||||||
|
|
||||||
h := cast(u64)(h1)<<32 | cast(u64)(h2);
|
var h = cast(u64)(h1)<<32 | cast(u64)(h2);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
immutable _crc32_table := [256]u32{
|
let _crc32_table = [256]u32{
|
||||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
|
||||||
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
|
||||||
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||||
@@ -269,7 +269,7 @@ immutable _crc32_table := [256]u32{
|
|||||||
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
|
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
|
||||||
};
|
};
|
||||||
immutable _crc64_table := [256]u64{
|
let _crc64_table = [256]u64{
|
||||||
0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5,
|
0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5,
|
||||||
0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a,
|
0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a,
|
||||||
0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b,
|
0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b,
|
||||||
|
|||||||
+24
-21
@@ -1,31 +1,34 @@
|
|||||||
const TAU = 6.28318530717958647692528676655900576;
|
const (
|
||||||
const PI = 3.14159265358979323846264338327950288;
|
TAU = 6.28318530717958647692528676655900576;
|
||||||
const ONE_OVER_TAU = 0.636619772367581343075535053490057448;
|
PI = 3.14159265358979323846264338327950288;
|
||||||
const ONE_OVER_PI = 0.159154943091895335768883763372514362;
|
ONE_OVER_TAU = 0.636619772367581343075535053490057448;
|
||||||
|
ONE_OVER_PI = 0.159154943091895335768883763372514362;
|
||||||
|
|
||||||
const E = 2.71828182845904523536;
|
E = 2.71828182845904523536;
|
||||||
const SQRT_TWO = 1.41421356237309504880168872420969808;
|
SQRT_TWO = 1.41421356237309504880168872420969808;
|
||||||
const SQRT_THREE = 1.73205080756887729352744634150587236;
|
SQRT_THREE = 1.73205080756887729352744634150587236;
|
||||||
const SQRT_FIVE = 2.23606797749978969640917366873127623;
|
SQRT_FIVE = 2.23606797749978969640917366873127623;
|
||||||
|
|
||||||
const LOG_TWO = 0.693147180559945309417232121458176568;
|
LOG_TWO = 0.693147180559945309417232121458176568;
|
||||||
const LOG_TEN = 2.30258509299404568401799145468436421;
|
LOG_TEN = 2.30258509299404568401799145468436421;
|
||||||
|
|
||||||
const EPSILON = 1.19209290e-7;
|
EPSILON = 1.19209290e-7;
|
||||||
|
|
||||||
const τ = TAU;
|
τ = TAU;
|
||||||
const π = PI;
|
π = PI;
|
||||||
|
)
|
||||||
type Vec2 [vector 2]f32;
|
type (
|
||||||
type Vec3 [vector 3]f32;
|
Vec2 [vector 2]f32;
|
||||||
type Vec4 [vector 4]f32;
|
Vec3 [vector 3]f32;
|
||||||
|
Vec4 [vector 4]f32;
|
||||||
|
|
||||||
// Column major
|
// Column major
|
||||||
type Mat2 [2][2]f32;
|
Mat2 [2][2]f32;
|
||||||
type Mat3 [3][3]f32;
|
Mat3 [3][3]f32;
|
||||||
type Mat4 [4][4]f32;
|
Mat4 [4][4]f32;
|
||||||
|
|
||||||
type Complex complex64;
|
Complex complex64;
|
||||||
|
)
|
||||||
|
|
||||||
proc sqrt(x: f32) -> f32 #foreign __llvm_core "llvm.sqrt.f32";
|
proc sqrt(x: f32) -> f32 #foreign __llvm_core "llvm.sqrt.f32";
|
||||||
proc sqrt(x: f64) -> f64 #foreign __llvm_core "llvm.sqrt.f64";
|
proc sqrt(x: f64) -> f64 #foreign __llvm_core "llvm.sqrt.f64";
|
||||||
|
|||||||
+4
-2
@@ -1,5 +1,7 @@
|
|||||||
import "fmt.odin";
|
import (
|
||||||
import "os.odin";
|
"fmt.odin";
|
||||||
|
"os.odin";
|
||||||
|
)
|
||||||
|
|
||||||
proc swap(b: u16) -> u16 #foreign __llvm_core "llvm.bswap.i16";
|
proc swap(b: u16) -> u16 #foreign __llvm_core "llvm.bswap.i16";
|
||||||
proc swap(b: u32) -> u32 #foreign __llvm_core "llvm.bswap.i32";
|
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 "opengl32.lib" when ODIN_OS == "windows";
|
||||||
#foreign_system_library lib "gl" when ODIN_OS == "linux";
|
#foreign_system_library lib "gl" when ODIN_OS == "linux";
|
||||||
import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
import (
|
||||||
import "sys/wgl.odin" when ODIN_OS == "windows";
|
win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||||
|
"sys/wgl.odin" when ODIN_OS == "windows";
|
||||||
|
)
|
||||||
import_load "opengl_constants.odin";
|
import_load "opengl_constants.odin";
|
||||||
|
|
||||||
proc Clear (mask: u32) #foreign lib "glClear";
|
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 (
|
||||||
import_load "os_x.odin" when ODIN_OS == "osx";
|
"os_windows.odin" when ODIN_OS == "windows";
|
||||||
import_load "os_linux.odin" when ODIN_OS == "linux";
|
"os_x.odin" when ODIN_OS == "osx";
|
||||||
|
"os_linux.odin" when ODIN_OS == "linux";
|
||||||
|
)
|
||||||
|
|
||||||
proc write_string(fd: Handle, str: string) -> (int, Errno) {
|
proc write_string(fd: Handle, str: string) -> (int, Errno) {
|
||||||
return write(fd, []u8(str));
|
return write(fd, []u8(str));
|
||||||
|
|||||||
+73
-71
@@ -1,36 +1,40 @@
|
|||||||
|
#foreign_system_library dl "dl";
|
||||||
|
#foreign_system_library libc "c";
|
||||||
import "strings.odin";
|
import "strings.odin";
|
||||||
|
|
||||||
type Handle i32;
|
type (
|
||||||
type FileTime u64;
|
Handle i32;
|
||||||
type Errno 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;
|
// NOTE(zangent): These are OS specific!
|
||||||
const O_WRONLY = 0x00001;
|
// Do not mix these up!
|
||||||
const O_RDWR = 0x00002;
|
RTLD_LAZY = 0x001;
|
||||||
const O_CREAT = 0x00040;
|
RTLD_NOW = 0x002;
|
||||||
const O_EXCL = 0x00080;
|
RTLD_BINDING_MASK = 0x3;
|
||||||
const O_NOCTTY = 0x00100;
|
RTLD_GLOBAL = 0x100;
|
||||||
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;
|
|
||||||
|
|
||||||
// "Argv" arguments converted to Odin strings
|
// "Argv" arguments converted to Odin strings
|
||||||
let args = _alloc_command_line_arguments();
|
let args = _alloc_command_line_arguments();
|
||||||
@@ -70,41 +74,39 @@ type Stat struct #ordered {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// File type
|
// 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
|
// File mode
|
||||||
const S_IFIFO = 0010000; // Named pipe (fifo)
|
// Read, write, execute/search by owner
|
||||||
const S_IFCHR = 0020000; // Character special
|
S_IRWXU = 0000700; // RWX mask for owner
|
||||||
const S_IFDIR = 0040000; // Directory
|
S_IRUSR = 0000400; // R for owner
|
||||||
const S_IFBLK = 0060000; // Block special
|
S_IWUSR = 0000200; // W for owner
|
||||||
const S_IFREG = 0100000; // Regular
|
S_IXUSR = 0000100; // X for owner
|
||||||
const S_IFLNK = 0120000; // Symbolic link
|
|
||||||
const S_IFSOCK = 0140000; // Socket
|
|
||||||
|
|
||||||
// File mode
|
// Read, write, execute/search by group
|
||||||
// Read, write, execute/search by owner
|
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
|
// Read, write, execute/search by others
|
||||||
const S_IRUSR = 0000400; // R for owner
|
S_IRWXO = 0000007; // RWX mask for other
|
||||||
const S_IWUSR = 0000200; // W for owner
|
S_IROTH = 0000004; // R for other
|
||||||
const S_IXUSR = 0000100; // X for owner
|
S_IWOTH = 0000002; // W for other
|
||||||
|
S_IXOTH = 0000001; // X for other
|
||||||
|
|
||||||
// Read, write, execute/search by group
|
S_ISUID = 0004000; // Set user id on execution
|
||||||
|
S_ISGID = 0002000; // Set group id on execution
|
||||||
const S_IRWXG = 0000070; // RWX mask for group
|
S_ISVTX = 0001000; // Directory restrcted delete
|
||||||
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
|
|
||||||
|
|
||||||
proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
|
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; }
|
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_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
|
||||||
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
||||||
|
|
||||||
const R_OK = 4; // Test for read permission
|
const (
|
||||||
const W_OK = 2; // Test for write permission
|
R_OK = 4; // Test for read permission
|
||||||
const X_OK = 1; // Test for execute permission
|
W_OK = 2; // Test for write permission
|
||||||
const F_OK = 0; // Test for file existance
|
X_OK = 1; // Test for execute permission
|
||||||
|
F_OK = 0; // Test for file existance
|
||||||
#foreign_system_library dl "dl";
|
)
|
||||||
#foreign_system_library libc "c";
|
|
||||||
|
|
||||||
proc _unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
|
proc _unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
|
||||||
proc _unix_close (fd: Handle) -> i32 #foreign libc "close";
|
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
|
// NOTE(bill): Uses startup to initialize it
|
||||||
var stdin: Handle = 0;
|
var (
|
||||||
var stdout: Handle = 1;
|
stdin: Handle = 0;
|
||||||
var stderr: Handle = 2;
|
stdout: Handle = 1;
|
||||||
|
stderr: Handle = 2;
|
||||||
|
)
|
||||||
/* TODO(zangent): Implement these!
|
/* TODO(zangent): Implement these!
|
||||||
proc last_write_time(fd: Handle) -> FileTime {}
|
proc last_write_time(fd: Handle) -> FileTime {}
|
||||||
proc last_write_time_by_name(name: string) -> FileTime {}
|
proc last_write_time_by_name(name: string) -> FileTime {}
|
||||||
|
|||||||
+45
-43
@@ -1,52 +1,54 @@
|
|||||||
import win32 "sys/windows.odin";
|
import win32 "sys/windows.odin";
|
||||||
|
|
||||||
type Handle int;
|
type (
|
||||||
type FileTime u64;
|
Handle int;
|
||||||
type Errno 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;
|
ERROR_NONE: Errno = 0;
|
||||||
const O_WRONLY = 0x00001;
|
ERROR_FILE_NOT_FOUND: Errno = 2;
|
||||||
const O_RDWR = 0x00002;
|
ERROR_PATH_NOT_FOUND: Errno = 3;
|
||||||
const O_CREAT = 0x00040;
|
ERROR_ACCESS_DENIED: Errno = 5;
|
||||||
const O_EXCL = 0x00080;
|
ERROR_NO_MORE_FILES: Errno = 18;
|
||||||
const O_NOCTTY = 0x00100;
|
ERROR_HANDLE_EOF: Errno = 38;
|
||||||
const O_TRUNC = 0x00200;
|
ERROR_NETNAME_DELETED: Errno = 64;
|
||||||
const O_NONBLOCK = 0x00800;
|
ERROR_FILE_EXISTS: Errno = 80;
|
||||||
const O_APPEND = 0x00400;
|
ERROR_BROKEN_PIPE: Errno = 109;
|
||||||
const O_SYNC = 0x01000;
|
ERROR_BUFFER_OVERFLOW: Errno = 111;
|
||||||
const O_ASYNC = 0x02000;
|
ERROR_INSUFFICIENT_BUFFER: Errno = 122;
|
||||||
const O_CLOEXEC = 0x80000;
|
ERROR_MOD_NOT_FOUND: Errno = 126;
|
||||||
|
ERROR_PROC_NOT_FOUND: Errno = 127;
|
||||||
const ERROR_NONE: Errno = 0;
|
ERROR_DIR_NOT_EMPTY: Errno = 145;
|
||||||
const ERROR_FILE_NOT_FOUND: Errno = 2;
|
ERROR_ALREADY_EXISTS: Errno = 183;
|
||||||
const ERROR_PATH_NOT_FOUND: Errno = 3;
|
ERROR_ENVVAR_NOT_FOUND: Errno = 203;
|
||||||
const ERROR_ACCESS_DENIED: Errno = 5;
|
ERROR_MORE_DATA: Errno = 234;
|
||||||
const ERROR_NO_MORE_FILES: Errno = 18;
|
ERROR_OPERATION_ABORTED: Errno = 995;
|
||||||
const ERROR_HANDLE_EOF: Errno = 38;
|
ERROR_IO_PENDING: Errno = 997;
|
||||||
const ERROR_NETNAME_DELETED: Errno = 64;
|
ERROR_NOT_FOUND: Errno = 1168;
|
||||||
const ERROR_FILE_EXISTS: Errno = 80;
|
ERROR_PRIVILEGE_NOT_HELD: Errno = 1314;
|
||||||
const ERROR_BROKEN_PIPE: Errno = 109;
|
WSAEACCES: Errno = 10013;
|
||||||
const ERROR_BUFFER_OVERFLOW: Errno = 111;
|
WSAECONNRESET: Errno = 10054;
|
||||||
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;
|
|
||||||
|
|
||||||
|
// Windows reserves errors >= 1<<29 for application use
|
||||||
|
ERROR_FILE_IS_PIPE: Errno = 1<<29 + 0;
|
||||||
|
)
|
||||||
|
|
||||||
// "Argv" arguments converted to Odin strings
|
// "Argv" arguments converted to Odin strings
|
||||||
let args = _alloc_command_line_arguments();
|
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 "fmt.odin";
|
||||||
import "strings.odin";
|
import "strings.odin";
|
||||||
|
|
||||||
type Handle i32;
|
type (
|
||||||
type FileTime u64;
|
Handle i32;
|
||||||
type Errno int;
|
FileTime u64;
|
||||||
|
Errno int;
|
||||||
|
|
||||||
// TODO(zangent): Find out how to make this work on x64 and x32.
|
AddressSize int;
|
||||||
type AddressSize i64;
|
)
|
||||||
|
|
||||||
// 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;
|
// NOTE(zangent): These are OS specific!
|
||||||
const O_WRONLY = 0x00001;
|
// Do not mix these up!
|
||||||
const O_RDWR = 0x00002;
|
RTLD_LAZY = 0x1;
|
||||||
const O_CREAT = 0x00040;
|
RTLD_NOW = 0x2;
|
||||||
const O_EXCL = 0x00080;
|
RTLD_LOCAL = 0x4;
|
||||||
const O_NOCTTY = 0x00100;
|
RTLD_GLOBAL = 0x8;
|
||||||
const O_TRUNC = 0x00200;
|
RTLD_NODELETE = 0x80;
|
||||||
const O_NONBLOCK = 0x00800;
|
RTLD_NOLOAD = 0x10;
|
||||||
const O_APPEND = 0x00400;
|
RTLD_FIRST = 0x100;
|
||||||
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;
|
|
||||||
|
|
||||||
var args: [dynamic]string;
|
var args: [dynamic]string;
|
||||||
|
|
||||||
@@ -71,41 +74,39 @@ type Stat struct #ordered {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// File type
|
// 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
|
// File mode
|
||||||
const S_IFIFO = 0010000; // Named pipe (fifo)
|
// Read, write, execute/search by owner
|
||||||
const S_IFCHR = 0020000; // Character special
|
S_IRWXU = 0000700; // RWX mask for owner
|
||||||
const S_IFDIR = 0040000; // Directory
|
S_IRUSR = 0000400; // R for owner
|
||||||
const S_IFBLK = 0060000; // Block special
|
S_IWUSR = 0000200; // W for owner
|
||||||
const S_IFREG = 0100000; // Regular
|
S_IXUSR = 0000100; // X for owner
|
||||||
const S_IFLNK = 0120000; // Symbolic link
|
|
||||||
const S_IFSOCK = 0140000; // Socket
|
|
||||||
|
|
||||||
// File mode
|
// Read, write, execute/search by group
|
||||||
// Read, write, execute/search by owner
|
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
|
// Read, write, execute/search by others
|
||||||
const S_IRUSR = 0000400; // R for owner
|
S_IRWXO = 0000007; // RWX mask for other
|
||||||
const S_IWUSR = 0000200; // W for owner
|
S_IROTH = 0000004; // R for other
|
||||||
const S_IXUSR = 0000100; // X for owner
|
S_IWOTH = 0000002; // W for other
|
||||||
|
S_IXOTH = 0000001; // X for other
|
||||||
|
|
||||||
// Read, write, execute/search by group
|
S_ISUID = 0004000; // Set user id on execution
|
||||||
|
S_ISGID = 0002000; // Set group id on execution
|
||||||
const S_IRWXG = 0000070; // RWX mask for group
|
S_ISVTX = 0001000; // Directory restrcted delete
|
||||||
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
|
|
||||||
|
|
||||||
proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
|
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; }
|
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_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
|
||||||
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
||||||
|
|
||||||
const R_OK = 4; // Test for read permission
|
const (
|
||||||
const W_OK = 2; // Test for write permission
|
R_OK = 4; // Test for read permission
|
||||||
const X_OK = 1; // Test for execute permission
|
W_OK = 2; // Test for write permission
|
||||||
const F_OK = 0; // Test for file existance
|
X_OK = 1; // Test for execute permission
|
||||||
|
F_OK = 0; // Test for file existance
|
||||||
#foreign_system_library dl "dl";
|
)
|
||||||
#foreign_system_library libc "c";
|
|
||||||
|
|
||||||
proc unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
|
proc unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
|
||||||
proc unix_close (handle: Handle) #foreign libc "close";
|
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
|
// NOTE(bill): Uses startup to initialize it
|
||||||
var stdin: Handle = 0; // get_std_handle(win32.STD_INPUT_HANDLE);
|
var (
|
||||||
var stdout: Handle = 1; // get_std_handle(win32.STD_OUTPUT_HANDLE);
|
stdin: Handle = 0; // get_std_handle(win32.STD_INPUT_HANDLE);
|
||||||
var stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_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!
|
/* TODO(zangent): Implement these!
|
||||||
proc last_write_time(fd: Handle) -> FileTime {}
|
proc last_write_time(fd: Handle) -> FileTime {}
|
||||||
proc last_write_time_by_name(name: string) -> FileTime {}
|
proc last_write_time_by_name(name: string) -> FileTime {}
|
||||||
|
|||||||
+25
-23
@@ -1,27 +1,29 @@
|
|||||||
type Any struct #ordered {
|
type (
|
||||||
data: rawptr,
|
Any struct #ordered {
|
||||||
type_info: ^TypeInfo,
|
data: rawptr,
|
||||||
};
|
type_info: ^TypeInfo,
|
||||||
|
};
|
||||||
|
|
||||||
type String struct #ordered {
|
String struct #ordered {
|
||||||
data: ^u8,
|
data: ^u8,
|
||||||
len: int,
|
len: int,
|
||||||
};
|
};
|
||||||
|
|
||||||
type Slice struct #ordered {
|
Slice struct #ordered {
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
len: int,
|
len: int,
|
||||||
cap: int,
|
cap: int,
|
||||||
};
|
};
|
||||||
|
|
||||||
type DynamicArray struct #ordered {
|
DynamicArray struct #ordered {
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
len: int,
|
len: int,
|
||||||
cap: int,
|
cap: int,
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
};
|
};
|
||||||
|
|
||||||
type DynamicMap struct #ordered {
|
DynamicMap struct #ordered {
|
||||||
hashes: [dynamic]int,
|
hashes: [dynamic]int,
|
||||||
entries: DynamicArray,
|
entries: DynamicArray,
|
||||||
};
|
};
|
||||||
|
)
|
||||||
|
|||||||
+4
-2
@@ -1,2 +1,4 @@
|
|||||||
import_load "sync_windows.odin" when ODIN_OS == "windows";
|
import_load (
|
||||||
import_load "sync_linux.odin" when ODIN_OS == "linux";
|
"sync_windows.odin" when ODIN_OS == "windows";
|
||||||
|
"sync_linux.odin" when ODIN_OS == "linux";
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import "atomics.odin";
|
import (
|
||||||
import "os.odin";
|
"atomics.odin";
|
||||||
|
"os.odin";
|
||||||
|
)
|
||||||
|
|
||||||
type Semaphore struct {
|
type Semaphore struct {
|
||||||
// _handle: win32.Handle,
|
// _handle: win32.Handle,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
import (
|
||||||
import "atomics.odin";
|
win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||||
|
"atomics.odin";
|
||||||
|
)
|
||||||
|
|
||||||
type Semaphore struct {
|
type Semaphore struct {
|
||||||
_handle: win32.Handle,
|
_handle: win32.Handle,
|
||||||
|
|||||||
+8
-7
@@ -1,11 +1,12 @@
|
|||||||
const REPLACEMENT_CHAR = '\uFFFD';
|
const (
|
||||||
const MAX_RUNE = '\U0010FFFF';
|
REPLACEMENT_CHAR = '\uFFFD';
|
||||||
|
MAX_RUNE = '\U0010FFFF';
|
||||||
const _surr1 = 0xd800;
|
|
||||||
const _surr2 = 0xdc00;
|
|
||||||
const _surr3 = 0xe000;
|
|
||||||
const _surr_self = 0x10000;
|
|
||||||
|
|
||||||
|
_surr1 = 0xd800;
|
||||||
|
_surr2 = 0xdc00;
|
||||||
|
_surr3 = 0xe000;
|
||||||
|
_surr_self = 0x10000;
|
||||||
|
)
|
||||||
|
|
||||||
proc is_surrogate(r: rune) -> bool {
|
proc is_surrogate(r: rune) -> bool {
|
||||||
return _surr1 <= r && r < _surr3;
|
return _surr1 <= r && r < _surr3;
|
||||||
|
|||||||
+53
-49
@@ -1,62 +1,66 @@
|
|||||||
const RUNE_ERROR = '\ufffd';
|
const (
|
||||||
const RUNE_SELF = 0x80;
|
RUNE_ERROR = '\ufffd';
|
||||||
const RUNE_BOM = 0xfeff;
|
RUNE_SELF = 0x80;
|
||||||
const RUNE_EOF = ~rune(0);
|
RUNE_BOM = 0xfeff;
|
||||||
const MAX_RUNE = '\U0010ffff';
|
RUNE_EOF = ~rune(0);
|
||||||
const UTF_MAX = 4;
|
MAX_RUNE = '\U0010ffff';
|
||||||
|
UTF_MAX = 4;
|
||||||
|
|
||||||
const SURROGATE_MIN = 0xd800;
|
SURROGATE_MIN = 0xd800;
|
||||||
const SURROGATE_MAX = 0xdfff;
|
SURROGATE_MAX = 0xdfff;
|
||||||
|
|
||||||
const T1 = 0b0000_0000;
|
T1 = 0b0000_0000;
|
||||||
const TX = 0b1000_0000;
|
TX = 0b1000_0000;
|
||||||
const T2 = 0b1100_0000;
|
T2 = 0b1100_0000;
|
||||||
const T3 = 0b1110_0000;
|
T3 = 0b1110_0000;
|
||||||
const T4 = 0b1111_0000;
|
T4 = 0b1111_0000;
|
||||||
const T5 = 0b1111_1000;
|
T5 = 0b1111_1000;
|
||||||
|
|
||||||
const MASKX = 0b0011_1111;
|
MASKX = 0b0011_1111;
|
||||||
const MASK2 = 0b0001_1111;
|
MASK2 = 0b0001_1111;
|
||||||
const MASK3 = 0b0000_1111;
|
MASK3 = 0b0000_1111;
|
||||||
const MASK4 = 0b0000_0111;
|
MASK4 = 0b0000_0111;
|
||||||
|
|
||||||
const RUNE1_MAX = 1<<7 - 1;
|
RUNE1_MAX = 1<<7 - 1;
|
||||||
const RUNE2_MAX = 1<<11 - 1;
|
RUNE2_MAX = 1<<11 - 1;
|
||||||
const RUNE3_MAX = 1<<16 - 1;
|
RUNE3_MAX = 1<<16 - 1;
|
||||||
|
|
||||||
// The default lowest and highest continuation byte.
|
// The default lowest and highest continuation byte.
|
||||||
const LOCB = 0b1000_0000;
|
LOCB = 0b1000_0000;
|
||||||
const HICB = 0b1011_1111;
|
HICB = 0b1011_1111;
|
||||||
|
)
|
||||||
|
|
||||||
type AcceptRange struct { lo, hi: u8 }
|
type AcceptRange struct { lo, hi: u8 }
|
||||||
|
|
||||||
let accept_ranges = [5]AcceptRange{
|
let (
|
||||||
{0x80, 0xbf},
|
accept_ranges = [5]AcceptRange{
|
||||||
{0xa0, 0xbf},
|
{0x80, 0xbf},
|
||||||
{0x80, 0x9f},
|
{0xa0, 0xbf},
|
||||||
{0x90, 0xbf},
|
{0x80, 0x9f},
|
||||||
{0x80, 0x8f},
|
{0x90, 0xbf},
|
||||||
};
|
{0x80, 0x8f},
|
||||||
|
};
|
||||||
|
|
||||||
let accept_sizes = [256]u8{
|
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, // 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, // 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, // 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, // 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, // 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, // 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, // 0x60-0x6f
|
||||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x70-0x7f
|
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, // 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, // 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, // 0xa0-0xaf
|
||||||
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xb0-0xbf
|
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
|
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
|
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
|
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
|
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) {
|
proc encode_rune(r: rune) -> ([4]u8, int) {
|
||||||
var buf: [4]u8;
|
var buf: [4]u8;
|
||||||
|
|||||||
+105
-100
@@ -1535,121 +1535,126 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
|||||||
check_stmt(c, pa->body, mod_flags);
|
check_stmt(c, pa->body, mod_flags);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(gd, GenDecl, node);
|
||||||
case_ast_node(vd, ValueDecl, node);
|
|
||||||
GB_ASSERT(!c->context.scope->is_file);
|
GB_ASSERT(!c->context.scope->is_file);
|
||||||
if (vd->token.kind == Token_const) {
|
for_array(i, gd->specs) {
|
||||||
// NOTE(bill): Handled elsewhere
|
AstNode *spec = gd->specs[i];
|
||||||
} else {
|
switch (gd->token.kind) {
|
||||||
Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
|
case Token_var:
|
||||||
isize entity_count = 0;
|
case Token_let: {
|
||||||
|
ast_node(vd, ValueSpec, spec);
|
||||||
|
|
||||||
if (vd->flags & VarDeclFlag_thread_local) {
|
Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
|
||||||
vd->flags &= ~VarDeclFlag_thread_local;
|
isize entity_count = 0;
|
||||||
error_node(node, "`thread_local` may only be applied to a variable declaration");
|
|
||||||
}
|
|
||||||
|
|
||||||
for_array(i, vd->names) {
|
if (gd->flags & VarDeclFlag_thread_local) {
|
||||||
AstNode *name = vd->names[i];
|
gd->flags &= ~VarDeclFlag_thread_local;
|
||||||
Entity *entity = NULL;
|
error_node(node, "`thread_local` may only be applied to a variable declaration");
|
||||||
if (name->kind != AstNode_Ident) {
|
}
|
||||||
error_node(name, "A variable declaration must be an identifier");
|
|
||||||
} else {
|
for_array(i, vd->names) {
|
||||||
Token token = name->Ident;
|
AstNode *name = vd->names[i];
|
||||||
String str = token.string;
|
Entity *entity = NULL;
|
||||||
Entity *found = NULL;
|
if (name->kind != AstNode_Ident) {
|
||||||
// NOTE(bill): Ignore assignments to `_`
|
error_node(name, "A variable declaration must be an identifier");
|
||||||
if (str != "_") {
|
|
||||||
found = current_scope_lookup_entity(c->context.scope, str);
|
|
||||||
}
|
|
||||||
if (found == NULL) {
|
|
||||||
entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, (vd->flags&VarDeclFlag_immutable) != 0);
|
|
||||||
entity->identifier = name;
|
|
||||||
} else {
|
} else {
|
||||||
TokenPos pos = found->token.pos;
|
Token token = name->Ident;
|
||||||
error(token,
|
String str = token.string;
|
||||||
"Redeclaration of `%.*s` in this scope\n"
|
Entity *found = NULL;
|
||||||
"\tat %.*s(%td:%td)",
|
// NOTE(bill): Ignore assignments to `_`
|
||||||
LIT(str), LIT(pos.file), pos.line, pos.column);
|
if (str != "_") {
|
||||||
entity = found;
|
found = current_scope_lookup_entity(c->context.scope, str);
|
||||||
|
}
|
||||||
|
if (found == NULL) {
|
||||||
|
entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, (gd->flags&VarDeclFlag_immutable) != 0);
|
||||||
|
entity->identifier = name;
|
||||||
|
} else {
|
||||||
|
TokenPos pos = found->token.pos;
|
||||||
|
error(token,
|
||||||
|
"Redeclaration of `%.*s` in this scope\n"
|
||||||
|
"\tat %.*s(%td:%td)",
|
||||||
|
LIT(str), LIT(pos.file), pos.line, pos.column);
|
||||||
|
entity = found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (entity == NULL) {
|
||||||
|
entity = make_entity_dummy_variable(c->allocator, c->global_scope, ast_node_token(name));
|
||||||
|
}
|
||||||
|
entity->parent_proc_decl = c->context.curr_proc_decl;
|
||||||
|
entities[entity_count++] = entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
Type *init_type = NULL;
|
||||||
|
if (vd->type) {
|
||||||
|
init_type = check_type(c, vd->type, NULL);
|
||||||
|
if (init_type == NULL) {
|
||||||
|
init_type = t_invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entity == NULL) {
|
|
||||||
entity = make_entity_dummy_variable(c->allocator, c->global_scope, ast_node_token(name));
|
|
||||||
}
|
|
||||||
entity->parent_proc_decl = c->context.curr_proc_decl;
|
|
||||||
entities[entity_count++] = entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
Type *init_type = NULL;
|
for (isize i = 0; i < entity_count; i++) {
|
||||||
if (vd->type) {
|
Entity *e = entities[i];
|
||||||
init_type = check_type(c, vd->type, NULL);
|
GB_ASSERT(e != NULL);
|
||||||
if (init_type == NULL) {
|
if (e->flags & EntityFlag_Visited) {
|
||||||
init_type = t_invalid;
|
e->type = t_invalid;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (isize i = 0; i < entity_count; i++) {
|
|
||||||
Entity *e = entities[i];
|
|
||||||
GB_ASSERT(e != NULL);
|
|
||||||
if (e->flags & EntityFlag_Visited) {
|
|
||||||
e->type = t_invalid;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
e->flags |= EntityFlag_Visited;
|
|
||||||
|
|
||||||
if (e->type == NULL) {
|
|
||||||
e->type = init_type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
check_arity_match(c, vd);
|
|
||||||
check_init_variables(c, entities, entity_count, vd->values, str_lit("variable declaration"));
|
|
||||||
|
|
||||||
for (isize i = 0; i < entity_count; i++) {
|
|
||||||
add_entity(c, c->context.scope, entities[i]->identifier, entities[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((vd->flags & VarDeclFlag_using) != 0) {
|
|
||||||
Token token = ast_node_token(node);
|
|
||||||
if (vd->type != NULL && entity_count > 1) {
|
|
||||||
error(token, "`using` can only be applied to one variable of the same type");
|
|
||||||
// TODO(bill): Should a `continue` happen here?
|
|
||||||
}
|
|
||||||
|
|
||||||
for (isize entity_index = 0; entity_index < entity_count; entity_index++) {
|
|
||||||
Entity *e = entities[entity_index];
|
|
||||||
if (e == NULL) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (e->kind != Entity_Variable) {
|
e->flags |= EntityFlag_Visited;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
bool is_immutable = e->Variable.is_immutable;
|
|
||||||
String name = e->token.string;
|
|
||||||
Type *t = base_type(type_deref(e->type));
|
|
||||||
|
|
||||||
if (is_type_struct(t) || is_type_raw_union(t)) {
|
if (e->type == NULL) {
|
||||||
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
|
e->type = init_type;
|
||||||
GB_ASSERT(found != NULL);
|
}
|
||||||
for_array(i, (*found)->elements.entries) {
|
}
|
||||||
Entity *f = (*found)->elements.entries[i].value;
|
|
||||||
if (f->kind == Entity_Variable) {
|
check_arity_match(c, vd);
|
||||||
Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type);
|
check_init_variables(c, entities, entity_count, vd->values, str_lit("variable declaration"));
|
||||||
uvar->Variable.is_immutable = is_immutable;
|
|
||||||
Entity *prev = scope_insert_entity(c->context.scope, uvar);
|
for (isize i = 0; i < entity_count; i++) {
|
||||||
if (prev != NULL) {
|
add_entity(c, c->context.scope, entities[i]->identifier, entities[i]);
|
||||||
error(token, "Namespace collision while `using` `%.*s` of: %.*s", LIT(name), LIT(prev->token.string));
|
}
|
||||||
return;
|
|
||||||
|
if ((gd->flags & VarDeclFlag_using) != 0) {
|
||||||
|
Token token = ast_node_token(node);
|
||||||
|
if (vd->type != NULL && entity_count > 1) {
|
||||||
|
error(token, "`using` can only be applied to one variable of the same type");
|
||||||
|
// TODO(bill): Should a `continue` happen here?
|
||||||
|
}
|
||||||
|
|
||||||
|
for (isize entity_index = 0; entity_index < entity_count; entity_index++) {
|
||||||
|
Entity *e = entities[entity_index];
|
||||||
|
if (e == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (e->kind != Entity_Variable) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bool is_immutable = e->Variable.is_immutable;
|
||||||
|
String name = e->token.string;
|
||||||
|
Type *t = base_type(type_deref(e->type));
|
||||||
|
|
||||||
|
if (is_type_struct(t) || is_type_raw_union(t)) {
|
||||||
|
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
|
||||||
|
GB_ASSERT(found != NULL);
|
||||||
|
for_array(i, (*found)->elements.entries) {
|
||||||
|
Entity *f = (*found)->elements.entries[i].value;
|
||||||
|
if (f->kind == Entity_Variable) {
|
||||||
|
Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type);
|
||||||
|
uvar->Variable.is_immutable = is_immutable;
|
||||||
|
Entity *prev = scope_insert_entity(c->context.scope, uvar);
|
||||||
|
if (prev != NULL) {
|
||||||
|
error(token, "Namespace collision while `using` `%.*s` of: %.*s", LIT(name), LIT(prev->token.string));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// NOTE(bill): skip the rest to remove extra errors
|
||||||
|
error(token, "`using` can only be applied to variables of type struct or raw_union");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// NOTE(bill): skip the rest to remove extra errors
|
|
||||||
error(token, "`using` can only be applied to variables of type struct or raw_union");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|||||||
+156
-139
@@ -1249,7 +1249,7 @@ void init_preload(Checker *c) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool check_arity_match(Checker *c, AstNodeValueDecl *d);
|
bool check_arity_match(Checker *c, AstNodeValueSpec *s);
|
||||||
void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_scope);
|
void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_scope);
|
||||||
void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws, bool is_file_scope);
|
void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws, bool is_file_scope);
|
||||||
|
|
||||||
@@ -1362,27 +1362,27 @@ void check_procedure_overloading(Checker *c, Entity *e) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool check_arity_match(Checker *c, AstNodeValueDecl *d) {
|
bool check_arity_match(Checker *c, AstNodeValueSpec *spec) {
|
||||||
isize lhs = d->names.count;
|
isize lhs = spec->names.count;
|
||||||
isize rhs = d->values.count;
|
isize rhs = spec->values.count;
|
||||||
|
|
||||||
if (rhs == 0) {
|
if (rhs == 0) {
|
||||||
if (d->type == NULL) {
|
if (spec->type == NULL) {
|
||||||
error_node(d->names[0], "Missing type or initial expression");
|
error_node(spec->names[0], "Missing type or initial expression");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (lhs < rhs) {
|
} else if (lhs < rhs) {
|
||||||
if (lhs < d->values.count) {
|
if (lhs < spec->values.count) {
|
||||||
AstNode *n = d->values[lhs];
|
AstNode *n = spec->values[lhs];
|
||||||
gbString str = expr_to_string(n);
|
gbString str = expr_to_string(n);
|
||||||
error_node(n, "Extra initial expression `%s`", str);
|
error_node(n, "Extra initial expression `%s`", str);
|
||||||
gb_string_free(str);
|
gb_string_free(str);
|
||||||
} else {
|
} else {
|
||||||
error_node(d->names[0], "Extra initial expression");
|
error_node(spec->names[0], "Extra initial expression");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (lhs > rhs && rhs != 1) {
|
} else if (lhs > rhs && rhs != 1) {
|
||||||
AstNode *n = d->names[rhs];
|
AstNode *n = spec->names[rhs];
|
||||||
gbString str = expr_to_string(n);
|
gbString str = expr_to_string(n);
|
||||||
error_node(n, "Missing expression for `%s`", str);
|
error_node(n, "Missing expression for `%s`", str);
|
||||||
gb_string_free(str);
|
gb_string_free(str);
|
||||||
@@ -1450,114 +1450,166 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco
|
|||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(vd, ValueDecl, decl);
|
case_ast_node(gd, GenDecl, decl);
|
||||||
if (vd->token.kind != Token_const) {
|
for_array(i, gd->specs) {
|
||||||
if (!c->context.scope->is_file) {
|
AstNode *spec = gd->specs[i];
|
||||||
// NOTE(bill): local scope -> handle later and in order
|
switch (gd->token.kind) {
|
||||||
break;
|
case Token_var:
|
||||||
}
|
case Token_let: {
|
||||||
// NOTE(bill): You need to store the entity information here unline a constant declaration
|
if (!c->context.scope->is_file) {
|
||||||
isize entity_cap = vd->names.count;
|
// NOTE(bill): local scope -> handle later and in order
|
||||||
isize entity_count = 0;
|
break;
|
||||||
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_cap);
|
|
||||||
DeclInfo *di = NULL;
|
|
||||||
if (vd->values.count > 0) {
|
|
||||||
di = make_declaration_info(heap_allocator(), c->context.scope, c->context.decl);
|
|
||||||
di->entities = entities;
|
|
||||||
di->type_expr = vd->type;
|
|
||||||
di->init_expr = vd->values[0];
|
|
||||||
|
|
||||||
|
|
||||||
if (vd->flags & VarDeclFlag_thread_local) {
|
|
||||||
error_node(decl, "#thread_local variable declarations cannot have initialization values");
|
|
||||||
}
|
}
|
||||||
}
|
ast_node(vd, ValueSpec, spec);
|
||||||
|
|
||||||
|
// NOTE(bill): You need to store the entity information here unline a constant declaration
|
||||||
|
isize entity_cap = vd->names.count;
|
||||||
|
isize entity_count = 0;
|
||||||
|
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_cap);
|
||||||
|
DeclInfo *di = NULL;
|
||||||
|
if (vd->values.count > 0) {
|
||||||
|
di = make_declaration_info(heap_allocator(), c->context.scope, c->context.decl);
|
||||||
|
di->entities = entities;
|
||||||
|
di->type_expr = vd->type;
|
||||||
|
di->init_expr = vd->values[0];
|
||||||
|
|
||||||
|
|
||||||
for_array(i, vd->names) {
|
if (gd->flags & VarDeclFlag_thread_local) {
|
||||||
AstNode *name = vd->names[i];
|
error_node(decl, "#thread_local variable declarations cannot have initialization values");
|
||||||
AstNode *value = NULL;
|
}
|
||||||
if (i < vd->values.count) {
|
|
||||||
value = vd->values[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for_array(i, vd->names) {
|
||||||
|
AstNode *name = vd->names[i];
|
||||||
|
AstNode *value = NULL;
|
||||||
|
if (i < vd->values.count) {
|
||||||
|
value = vd->values[i];
|
||||||
|
}
|
||||||
|
if (name->kind != AstNode_Ident) {
|
||||||
|
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident, NULL, (gd->flags&VarDeclFlag_immutable) != 0);
|
||||||
|
e->Variable.is_thread_local = (gd->flags & VarDeclFlag_thread_local) != 0;
|
||||||
|
e->identifier = name;
|
||||||
|
|
||||||
|
if (gd->flags & VarDeclFlag_using) {
|
||||||
|
gd->flags &= ~VarDeclFlag_using; // NOTE(bill): This error will be only caught once
|
||||||
|
error_node(name, "`using` is not allowed at the file scope");
|
||||||
|
}
|
||||||
|
entities[entity_count++] = e;
|
||||||
|
|
||||||
|
DeclInfo *d = di;
|
||||||
|
if (d == NULL) {
|
||||||
|
AstNode *init_expr = value;
|
||||||
|
d = make_declaration_info(heap_allocator(), e->scope, c->context.decl);
|
||||||
|
d->type_expr = vd->type;
|
||||||
|
d->init_expr = init_expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_entity_and_decl_info(c, name, e, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (di != NULL) {
|
||||||
|
di->entity_count = entity_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
check_arity_match(c, vd);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case Token_const: {
|
||||||
|
ast_node(vd, ValueSpec, spec);
|
||||||
|
|
||||||
|
for_array(i, vd->names) {
|
||||||
|
AstNode *name = vd->names[i];
|
||||||
|
if (name->kind != AstNode_Ident) {
|
||||||
|
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
AstNode *init = NULL;
|
||||||
|
if (i < vd->values.count) {
|
||||||
|
init = vd->values[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclInfo *d = make_declaration_info(c->allocator, c->context.scope, c->context.decl);
|
||||||
|
Entity *e = NULL;
|
||||||
|
|
||||||
|
AstNode *up_init = unparen_expr(init);
|
||||||
|
// if (up_init != NULL && is_ast_node_type(up_init)) {
|
||||||
|
// AstNode *type = up_init;
|
||||||
|
// e = make_entity_type_name(c->allocator, d->scope, name->Ident, NULL);
|
||||||
|
// // TODO(bill): What if vd->type != NULL??? How to handle this case?
|
||||||
|
// d->type_expr = type;
|
||||||
|
// d->init_expr = type;
|
||||||
|
// } else if (up_init != NULL && up_init->kind == AstNode_Alias) {
|
||||||
|
// #if 1
|
||||||
|
// error_node(up_init, "#alias declarations are not yet supported");
|
||||||
|
// continue;
|
||||||
|
// #else
|
||||||
|
// e = make_entity_alias(c->allocator, d->scope, name->Ident, NULL, EntityAlias_Invalid, NULL);
|
||||||
|
// d->type_expr = vd->type;
|
||||||
|
// d->init_expr = up_init->Alias.expr;
|
||||||
|
// #endif
|
||||||
|
// // } else if (init != NULL && up_init->kind == AstNode_ProcLit) {
|
||||||
|
// // e = make_entity_procedure(c->allocator, d->scope, name->Ident, NULL, up_init->ProcLit.tags);
|
||||||
|
// // d->proc_lit = up_init;
|
||||||
|
// // d->type_expr = vd->type;
|
||||||
|
// } else {
|
||||||
|
e = make_entity_constant(c->allocator, d->scope, name->Ident, NULL, empty_exact_value);
|
||||||
|
d->type_expr = vd->type;
|
||||||
|
d->init_expr = init;
|
||||||
|
// }
|
||||||
|
GB_ASSERT(e != NULL);
|
||||||
|
e->identifier = name;
|
||||||
|
|
||||||
|
add_entity_and_decl_info(c, name, e, d);
|
||||||
|
}
|
||||||
|
|
||||||
|
check_arity_match(c, vd);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case Token_type: {
|
||||||
|
ast_node(td, TypeSpec, spec);
|
||||||
|
|
||||||
|
AstNode *name = td->name;
|
||||||
if (name->kind != AstNode_Ident) {
|
if (name->kind != AstNode_Ident) {
|
||||||
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
||||||
continue;
|
break;
|
||||||
}
|
|
||||||
Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident, NULL, (vd->flags&VarDeclFlag_immutable) != 0);
|
|
||||||
e->Variable.is_thread_local = (vd->flags & VarDeclFlag_thread_local) != 0;
|
|
||||||
e->identifier = name;
|
|
||||||
|
|
||||||
if (vd->flags & VarDeclFlag_using) {
|
|
||||||
vd->flags &= ~VarDeclFlag_using; // NOTE(bill): This error will be only caught once
|
|
||||||
error_node(name, "`using` is not allowed at the file scope");
|
|
||||||
}
|
|
||||||
entities[entity_count++] = e;
|
|
||||||
|
|
||||||
DeclInfo *d = di;
|
|
||||||
if (d == NULL) {
|
|
||||||
AstNode *init_expr = value;
|
|
||||||
d = make_declaration_info(heap_allocator(), e->scope, c->context.decl);
|
|
||||||
d->type_expr = vd->type;
|
|
||||||
d->init_expr = init_expr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_entity_and_decl_info(c, name, e, d);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (di != NULL) {
|
|
||||||
di->entity_count = entity_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
check_arity_match(c, vd);
|
|
||||||
} else {
|
|
||||||
for_array(i, vd->names) {
|
|
||||||
AstNode *name = vd->names[i];
|
|
||||||
if (name->kind != AstNode_Ident) {
|
|
||||||
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
AstNode *init = NULL;
|
|
||||||
if (i < vd->values.count) {
|
|
||||||
init = vd->values[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
DeclInfo *d = make_declaration_info(c->allocator, c->context.scope, c->context.decl);
|
DeclInfo *d = make_declaration_info(c->allocator, c->context.scope, c->context.decl);
|
||||||
Entity *e = NULL;
|
Entity *e = NULL;
|
||||||
|
|
||||||
AstNode *up_init = unparen_expr(init);
|
AstNode *type = unparen_expr(td->type);
|
||||||
// if (up_init != NULL && is_ast_node_type(up_init)) {
|
e = make_entity_type_name(c->allocator, d->scope, name->Ident, NULL);
|
||||||
// AstNode *type = up_init;
|
// TODO(bill): What if vd->type != NULL??? How to handle this case?
|
||||||
// e = make_entity_type_name(c->allocator, d->scope, name->Ident, NULL);
|
d->type_expr = type;
|
||||||
// // TODO(bill): What if vd->type != NULL??? How to handle this case?
|
d->init_expr = type;
|
||||||
// d->type_expr = type;
|
|
||||||
// d->init_expr = type;
|
|
||||||
// } else if (up_init != NULL && up_init->kind == AstNode_Alias) {
|
|
||||||
// #if 1
|
|
||||||
// error_node(up_init, "#alias declarations are not yet supported");
|
|
||||||
// continue;
|
|
||||||
// #else
|
|
||||||
// e = make_entity_alias(c->allocator, d->scope, name->Ident, NULL, EntityAlias_Invalid, NULL);
|
|
||||||
// d->type_expr = vd->type;
|
|
||||||
// d->init_expr = up_init->Alias.expr;
|
|
||||||
// #endif
|
|
||||||
// // } else if (init != NULL && up_init->kind == AstNode_ProcLit) {
|
|
||||||
// // e = make_entity_procedure(c->allocator, d->scope, name->Ident, NULL, up_init->ProcLit.tags);
|
|
||||||
// // d->proc_lit = up_init;
|
|
||||||
// // d->type_expr = vd->type;
|
|
||||||
// } else {
|
|
||||||
e = make_entity_constant(c->allocator, d->scope, name->Ident, NULL, empty_exact_value);
|
|
||||||
d->type_expr = vd->type;
|
|
||||||
d->init_expr = init;
|
|
||||||
// }
|
|
||||||
GB_ASSERT(e != NULL);
|
|
||||||
e->identifier = name;
|
e->identifier = name;
|
||||||
|
|
||||||
add_entity_and_decl_info(c, name, e, d);
|
add_entity_and_decl_info(c, name, e, d);
|
||||||
}
|
} break;
|
||||||
|
|
||||||
check_arity_match(c, vd);
|
case Token_import:
|
||||||
|
case Token_import_load: {
|
||||||
|
ast_node(id, ImportSpec, spec);
|
||||||
|
if (!c->context.scope->is_file) {
|
||||||
|
if (id->is_import) {
|
||||||
|
error_node(decl, "import declarations are only allowed in the file scope");
|
||||||
|
} else {
|
||||||
|
error_node(decl, "import_load declarations are only allowed in the file scope");
|
||||||
|
}
|
||||||
|
// NOTE(bill): _Should_ be caught by the parser
|
||||||
|
// TODO(bill): Better error handling if it isn't
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DelayedDecl di = {c->context.scope, spec};
|
||||||
|
array_add(&c->delayed_imports, di);
|
||||||
|
} break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
@@ -1579,41 +1631,6 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco
|
|||||||
add_entity_and_decl_info(c, name, e, d);
|
add_entity_and_decl_info(c, name, e, d);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(td, TypeDecl, decl);
|
|
||||||
AstNode *name = td->name;
|
|
||||||
if (name->kind != AstNode_Ident) {
|
|
||||||
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DeclInfo *d = make_declaration_info(c->allocator, c->context.scope, c->context.decl);
|
|
||||||
Entity *e = NULL;
|
|
||||||
|
|
||||||
AstNode *type = unparen_expr(td->type);
|
|
||||||
e = make_entity_type_name(c->allocator, d->scope, name->Ident, NULL);
|
|
||||||
// TODO(bill): What if vd->type != NULL??? How to handle this case?
|
|
||||||
d->type_expr = type;
|
|
||||||
d->init_expr = type;
|
|
||||||
|
|
||||||
e->identifier = name;
|
|
||||||
add_entity_and_decl_info(c, name, e, d);
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(id, ImportDecl, decl);
|
|
||||||
if (!c->context.scope->is_file) {
|
|
||||||
if (id->is_import) {
|
|
||||||
error_node(decl, "#import declarations are only allowed in the file scope");
|
|
||||||
} else {
|
|
||||||
error_node(decl, "#load declarations are only allowed in the file scope");
|
|
||||||
}
|
|
||||||
// NOTE(bill): _Should_ be caught by the parser
|
|
||||||
// TODO(bill): Better error handling if it isn't
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DelayedDecl di = {c->context.scope, decl};
|
|
||||||
array_add(&c->delayed_imports, di);
|
|
||||||
case_end;
|
|
||||||
case_ast_node(fl, ForeignLibrary, decl);
|
case_ast_node(fl, ForeignLibrary, decl);
|
||||||
if (!c->context.scope->is_file) {
|
if (!c->context.scope->is_file) {
|
||||||
if (fl->is_system) {
|
if (fl->is_system) {
|
||||||
@@ -1882,7 +1899,7 @@ void check_import_entities(Checker *c, Map<Scope *> *file_scopes) {
|
|||||||
for_array(i, c->delayed_imports) {
|
for_array(i, c->delayed_imports) {
|
||||||
Scope *parent_scope = c->delayed_imports[i].parent;
|
Scope *parent_scope = c->delayed_imports[i].parent;
|
||||||
AstNode *decl = c->delayed_imports[i].decl;
|
AstNode *decl = c->delayed_imports[i].decl;
|
||||||
ast_node(id, ImportDecl, decl);
|
ast_node(id, ImportSpec, decl);
|
||||||
Token token = id->relpath;
|
Token token = id->relpath;
|
||||||
|
|
||||||
GB_ASSERT(parent_scope->is_file);
|
GB_ASSERT(parent_scope->is_file);
|
||||||
|
|||||||
+74
-64
@@ -5793,7 +5793,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
case_ast_node(us, UsingStmt, node);
|
case_ast_node(us, UsingStmt, node);
|
||||||
for_array(i, us->list) {
|
for_array(i, us->list) {
|
||||||
AstNode *decl = unparen_expr(us->list[i]);
|
AstNode *decl = unparen_expr(us->list[i]);
|
||||||
if (decl->kind == AstNode_ValueDecl) {
|
if (decl->kind == AstNode_GenDecl) {
|
||||||
ir_build_stmt(proc, decl);
|
ir_build_stmt(proc, decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5812,56 +5812,88 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
ir_build_assign_op(proc, addr, v_one, op);
|
ir_build_assign_op(proc, addr, v_one, op);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(vd, ValueDecl, node);
|
case_ast_node(gd, GenDecl, node);
|
||||||
if (vd->token.kind != Token_const) {
|
for_array(i, gd->specs) {
|
||||||
irModule *m = proc->module;
|
AstNode *spec = gd->specs[i];
|
||||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
|
switch (gd->token.kind) {
|
||||||
|
case Token_var:
|
||||||
|
case Token_let: {
|
||||||
|
ast_node(vd, ValueSpec, spec);
|
||||||
|
|
||||||
if (vd->values.count == 0) { // declared and zero-initialized
|
irModule *m = proc->module;
|
||||||
for_array(i, vd->names) {
|
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
|
||||||
AstNode *name = vd->names[i];
|
|
||||||
if (!ir_is_blank_ident(name)) {
|
|
||||||
ir_add_local_for_identifier(proc, name, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { // Tuple(s)
|
|
||||||
Array<irAddr> lvals = {};
|
|
||||||
Array<irValue *> inits = {};
|
|
||||||
array_init(&lvals, m->tmp_allocator, vd->names.count);
|
|
||||||
array_init(&inits, m->tmp_allocator, vd->names.count);
|
|
||||||
|
|
||||||
for_array(i, vd->names) {
|
if (vd->values.count == 0) { // declared and zero-initialized
|
||||||
AstNode *name = vd->names[i];
|
for_array(i, vd->names) {
|
||||||
irAddr lval = ir_addr(NULL);
|
AstNode *name = vd->names[i];
|
||||||
if (!ir_is_blank_ident(name)) {
|
if (!ir_is_blank_ident(name)) {
|
||||||
ir_add_local_for_identifier(proc, name, false);
|
ir_add_local_for_identifier(proc, name, true);
|
||||||
lval = ir_build_addr(proc, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
array_add(&lvals, lval);
|
|
||||||
}
|
|
||||||
|
|
||||||
for_array(i, vd->values) {
|
|
||||||
irValue *init = ir_build_expr(proc, vd->values[i]);
|
|
||||||
Type *t = ir_type(init);
|
|
||||||
if (t->kind == Type_Tuple) {
|
|
||||||
for (isize i = 0; i < t->Tuple.variable_count; i++) {
|
|
||||||
Entity *e = t->Tuple.variables[i];
|
|
||||||
irValue *v = ir_emit_struct_ev(proc, init, i);
|
|
||||||
array_add(&inits, v);
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
array_add(&inits, init);
|
} else { // Tuple(s)
|
||||||
|
Array<irAddr> lvals = {};
|
||||||
|
Array<irValue *> inits = {};
|
||||||
|
array_init(&lvals, m->tmp_allocator, vd->names.count);
|
||||||
|
array_init(&inits, m->tmp_allocator, vd->names.count);
|
||||||
|
|
||||||
|
for_array(i, vd->names) {
|
||||||
|
AstNode *name = vd->names[i];
|
||||||
|
irAddr lval = ir_addr(NULL);
|
||||||
|
if (!ir_is_blank_ident(name)) {
|
||||||
|
ir_add_local_for_identifier(proc, name, false);
|
||||||
|
lval = ir_build_addr(proc, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
array_add(&lvals, lval);
|
||||||
|
}
|
||||||
|
|
||||||
|
for_array(i, vd->values) {
|
||||||
|
irValue *init = ir_build_expr(proc, vd->values[i]);
|
||||||
|
Type *t = ir_type(init);
|
||||||
|
if (t->kind == Type_Tuple) {
|
||||||
|
for (isize i = 0; i < t->Tuple.variable_count; i++) {
|
||||||
|
Entity *e = t->Tuple.variables[i];
|
||||||
|
irValue *v = ir_emit_struct_ev(proc, init, i);
|
||||||
|
array_add(&inits, v);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
array_add(&inits, init);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for_array(i, inits) {
|
||||||
|
ir_addr_store(proc, lvals[i], inits[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gb_temp_arena_memory_end(tmp);
|
||||||
|
} break;
|
||||||
|
|
||||||
for_array(i, inits) {
|
case Token_type: {
|
||||||
ir_addr_store(proc, lvals[i], inits[i]);
|
ast_node(td, TypeSpec, node);
|
||||||
|
|
||||||
|
AstNode *ident = td->name;
|
||||||
|
GB_ASSERT(ident->kind == AstNode_Ident);
|
||||||
|
Entity *e = entity_of_ident(proc->module->info, ident);
|
||||||
|
GB_ASSERT(e != NULL);
|
||||||
|
if (e->kind == Entity_TypeName) {
|
||||||
|
// NOTE(bill): Generate a new name
|
||||||
|
// parent_proc.name-guid
|
||||||
|
String ts_name = e->token.string;
|
||||||
|
isize name_len = proc->name.len + 1 + ts_name.len + 1 + 10 + 1;
|
||||||
|
u8 *name_text = gb_alloc_array(proc->module->allocator, u8, name_len);
|
||||||
|
i32 guid = cast(i32)proc->module->members.entries.count;
|
||||||
|
name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s-%d", LIT(proc->name), LIT(ts_name), guid);
|
||||||
|
String name = make_string(name_text, name_len-1);
|
||||||
|
|
||||||
|
irValue *value = ir_value_type_name(proc->module->allocator,
|
||||||
|
name, e->type);
|
||||||
|
map_set(&proc->module->entity_names, hash_pointer(e), name);
|
||||||
|
ir_gen_global_type_name(proc->module, e, name);
|
||||||
}
|
}
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_temp_arena_memory_end(tmp);
|
|
||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
@@ -5936,28 +5968,6 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(td, TypeDecl, node);
|
|
||||||
AstNode *ident = td->name;
|
|
||||||
GB_ASSERT(ident->kind == AstNode_Ident);
|
|
||||||
Entity *e = entity_of_ident(proc->module->info, ident);
|
|
||||||
GB_ASSERT(e != NULL);
|
|
||||||
if (e->kind == Entity_TypeName) {
|
|
||||||
// NOTE(bill): Generate a new name
|
|
||||||
// parent_proc.name-guid
|
|
||||||
String ts_name = e->token.string;
|
|
||||||
isize name_len = proc->name.len + 1 + ts_name.len + 1 + 10 + 1;
|
|
||||||
u8 *name_text = gb_alloc_array(proc->module->allocator, u8, name_len);
|
|
||||||
i32 guid = cast(i32)proc->module->members.entries.count;
|
|
||||||
name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s-%d", LIT(proc->name), LIT(ts_name), guid);
|
|
||||||
String name = make_string(name_text, name_len-1);
|
|
||||||
|
|
||||||
irValue *value = ir_value_type_name(proc->module->allocator,
|
|
||||||
name, e->type);
|
|
||||||
map_set(&proc->module->entity_names, hash_pointer(e), name);
|
|
||||||
ir_gen_global_type_name(proc->module, e, name);
|
|
||||||
}
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(as, AssignStmt, node);
|
case_ast_node(as, AssignStmt, node);
|
||||||
ir_emit_comment(proc, str_lit("AssignStmt"));
|
ir_emit_comment(proc, str_lit("AssignStmt"));
|
||||||
|
|
||||||
|
|||||||
+333
-230
@@ -297,13 +297,6 @@ AST_NODE_KIND(_ComplexStmtEnd, "", i32) \
|
|||||||
AST_NODE_KIND(_StmtEnd, "", i32) \
|
AST_NODE_KIND(_StmtEnd, "", i32) \
|
||||||
AST_NODE_KIND(_DeclBegin, "", i32) \
|
AST_NODE_KIND(_DeclBegin, "", i32) \
|
||||||
AST_NODE_KIND(BadDecl, "bad declaration", struct { Token begin, end; }) \
|
AST_NODE_KIND(BadDecl, "bad declaration", struct { Token begin, end; }) \
|
||||||
AST_NODE_KIND(ValueDecl, "value declaration", struct { \
|
|
||||||
Token token; \
|
|
||||||
Array<AstNode *> names; \
|
|
||||||
AstNode * type; \
|
|
||||||
Array<AstNode *> values; \
|
|
||||||
u32 flags; \
|
|
||||||
}) \
|
|
||||||
AST_NODE_KIND(ProcDecl, "procedure declaration", struct { \
|
AST_NODE_KIND(ProcDecl, "procedure declaration", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
AstNode *name; \
|
AstNode *name; \
|
||||||
@@ -314,20 +307,6 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
|
|||||||
String foreign_name; \
|
String foreign_name; \
|
||||||
String link_name; \
|
String link_name; \
|
||||||
}) \
|
}) \
|
||||||
AST_NODE_KIND(TypeDecl, "type declaration", struct { \
|
|
||||||
Token token; \
|
|
||||||
AstNode *name; \
|
|
||||||
AstNode *type; \
|
|
||||||
}) \
|
|
||||||
AST_NODE_KIND(ImportDecl, "import declaration", struct { \
|
|
||||||
Token token; \
|
|
||||||
bool is_import; \
|
|
||||||
Token relpath; \
|
|
||||||
String fullpath; \
|
|
||||||
Token import_name; \
|
|
||||||
AstNode *cond; \
|
|
||||||
AstNode *note; \
|
|
||||||
}) \
|
|
||||||
AST_NODE_KIND(ForeignLibrary, "foreign library", struct { \
|
AST_NODE_KIND(ForeignLibrary, "foreign library", struct { \
|
||||||
Token token, filepath; \
|
Token token, filepath; \
|
||||||
Token library_name; \
|
Token library_name; \
|
||||||
@@ -339,6 +318,29 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
|
|||||||
Token token; \
|
Token token; \
|
||||||
AstNode *name; \
|
AstNode *name; \
|
||||||
}) \
|
}) \
|
||||||
|
AST_NODE_KIND(GenDecl, "generic declaration", struct { \
|
||||||
|
Token token; \
|
||||||
|
Token open; \
|
||||||
|
Token close; \
|
||||||
|
Array<AstNode *> specs; \
|
||||||
|
u64 flags; \
|
||||||
|
}) \
|
||||||
|
AST_NODE_KIND(ValueSpec, "value specification", struct { \
|
||||||
|
Array<AstNode *> names; \
|
||||||
|
AstNode * type; \
|
||||||
|
Array<AstNode *> values; \
|
||||||
|
}) \
|
||||||
|
AST_NODE_KIND(TypeSpec, "type specification", struct { \
|
||||||
|
AstNode *name; \
|
||||||
|
AstNode *type; \
|
||||||
|
}) \
|
||||||
|
AST_NODE_KIND(ImportSpec, "import specification", struct { \
|
||||||
|
bool is_import; \
|
||||||
|
Token relpath; \
|
||||||
|
String fullpath; \
|
||||||
|
Token import_name; \
|
||||||
|
AstNode *cond; \
|
||||||
|
}) \
|
||||||
AST_NODE_KIND(_DeclEnd, "", i32) \
|
AST_NODE_KIND(_DeclEnd, "", i32) \
|
||||||
AST_NODE_KIND(Field, "field", struct { \
|
AST_NODE_KIND(Field, "field", struct { \
|
||||||
Array<AstNode *> names; \
|
Array<AstNode *> names; \
|
||||||
@@ -540,12 +542,15 @@ Token ast_node_token(AstNode *node) {
|
|||||||
case AstNode_PushContext: return node->PushContext.token;
|
case AstNode_PushContext: return node->PushContext.token;
|
||||||
|
|
||||||
case AstNode_BadDecl: return node->BadDecl.begin;
|
case AstNode_BadDecl: return node->BadDecl.begin;
|
||||||
case AstNode_ValueDecl: return node->ValueDecl.token;
|
|
||||||
case AstNode_ProcDecl: return node->ProcDecl.token;
|
case AstNode_ProcDecl: return node->ProcDecl.token;
|
||||||
case AstNode_ImportDecl: return node->ImportDecl.token;
|
|
||||||
case AstNode_ForeignLibrary: return node->ForeignLibrary.token;
|
case AstNode_ForeignLibrary: return node->ForeignLibrary.token;
|
||||||
case AstNode_Label: return node->Label.token;
|
case AstNode_Label: return node->Label.token;
|
||||||
|
|
||||||
|
case AstNode_GenDecl: return node->GenDecl.token;
|
||||||
|
case AstNode_ValueSpec: return ast_node_token(node->ValueSpec.names[0]);
|
||||||
|
case AstNode_ImportSpec: return node->ImportSpec.import_name;
|
||||||
|
case AstNode_TypeSpec: return ast_node_token(node->TypeSpec.name);
|
||||||
|
|
||||||
|
|
||||||
case AstNode_Field:
|
case AstNode_Field:
|
||||||
if (node->Field.names.count > 0) {
|
if (node->Field.names.count > 0) {
|
||||||
@@ -761,15 +766,6 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AstNode_BadDecl: break;
|
case AstNode_BadDecl: break;
|
||||||
case AstNode_ValueDecl:
|
|
||||||
n->ValueDecl.names = clone_ast_node_array(a, n->ValueDecl.names);
|
|
||||||
n->ValueDecl.type = clone_ast_node(a, n->ValueDecl.type);
|
|
||||||
n->ValueDecl.values = clone_ast_node_array(a, n->ValueDecl.values);
|
|
||||||
break;
|
|
||||||
case AstNode_ImportDecl:
|
|
||||||
n->ImportDecl.cond = clone_ast_node(a, n->ImportDecl.cond);
|
|
||||||
n->ImportDecl.note = clone_ast_node(a, n->ImportDecl.note);
|
|
||||||
break;
|
|
||||||
case AstNode_ForeignLibrary:
|
case AstNode_ForeignLibrary:
|
||||||
n->ForeignLibrary.cond = clone_ast_node(a, n->ForeignLibrary.cond);
|
n->ForeignLibrary.cond = clone_ast_node(a, n->ForeignLibrary.cond);
|
||||||
break;
|
break;
|
||||||
@@ -1428,15 +1424,6 @@ AstNode *ast_map_type(AstFile *f, Token token, AstNode *count, AstNode *key, Ast
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AstNode *ast_value_decl(AstFile *f, Token token, Array<AstNode *> names, AstNode *type, Array<AstNode *> values) {
|
|
||||||
AstNode *result = make_ast_node(f, AstNode_ValueDecl);
|
|
||||||
result->ValueDecl.token = token;
|
|
||||||
result->ValueDecl.names = names;
|
|
||||||
result->ValueDecl.type = type;
|
|
||||||
result->ValueDecl.values = values;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
AstNode *ast_proc_decl(AstFile *f, Token token, AstNode *name, AstNode *type, AstNode *body,
|
AstNode *ast_proc_decl(AstFile *f, Token token, AstNode *name, AstNode *type, AstNode *body,
|
||||||
u64 tags, AstNode *foreign_library, String foreign_name, String link_name) {
|
u64 tags, AstNode *foreign_library, String foreign_name, String link_name) {
|
||||||
AstNode *result = make_ast_node(f, AstNode_ProcDecl);
|
AstNode *result = make_ast_node(f, AstNode_ProcDecl);
|
||||||
@@ -1451,25 +1438,6 @@ AstNode *ast_proc_decl(AstFile *f, Token token, AstNode *name, AstNode *type, As
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AstNode *ast_type_decl(AstFile *f, Token token, AstNode *name, AstNode *type) {
|
|
||||||
AstNode *result = make_ast_node(f, AstNode_TypeDecl);
|
|
||||||
result->TypeDecl.token = token;
|
|
||||||
result->TypeDecl.name = name;
|
|
||||||
result->TypeDecl.type = type;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AstNode *ast_import_decl(AstFile *f, Token token, bool is_import, Token relpath, Token import_name, AstNode *cond) {
|
|
||||||
AstNode *result = make_ast_node(f, AstNode_ImportDecl);
|
|
||||||
result->ImportDecl.token = token;
|
|
||||||
result->ImportDecl.is_import = is_import;
|
|
||||||
result->ImportDecl.relpath = relpath;
|
|
||||||
result->ImportDecl.import_name = import_name;
|
|
||||||
result->ImportDecl.cond = cond;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
AstNode *ast_foreign_library(AstFile *f, Token token, Token filepath, Token library_name, AstNode *cond, bool is_system) {
|
AstNode *ast_foreign_library(AstFile *f, Token token, Token filepath, Token library_name, AstNode *cond, bool is_system) {
|
||||||
AstNode *result = make_ast_node(f, AstNode_ForeignLibrary);
|
AstNode *result = make_ast_node(f, AstNode_ForeignLibrary);
|
||||||
result->ForeignLibrary.token = token;
|
result->ForeignLibrary.token = token;
|
||||||
@@ -1487,6 +1455,41 @@ AstNode *ast_label_decl(AstFile *f, Token token, AstNode *name) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AstNode *ast_gen_decl(AstFile *f, Token token, Token open, Token close, Array<AstNode *> specs) {
|
||||||
|
AstNode *result = make_ast_node(f, AstNode_GenDecl);
|
||||||
|
result->GenDecl.token = token;
|
||||||
|
result->GenDecl.open = open;
|
||||||
|
result->GenDecl.close = close;
|
||||||
|
result->GenDecl.specs = specs;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
AstNode *ast_value_spec(AstFile *f, Array<AstNode *> names, AstNode *type, Array<AstNode *> values) {
|
||||||
|
AstNode *result = make_ast_node(f, AstNode_ValueSpec);
|
||||||
|
result->ValueSpec.names = names;
|
||||||
|
result->ValueSpec.type = type;
|
||||||
|
result->ValueSpec.values = values;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
AstNode *ast_type_spec(AstFile *f, AstNode *name, AstNode *type) {
|
||||||
|
AstNode *result = make_ast_node(f, AstNode_TypeSpec);
|
||||||
|
result->TypeSpec.name = name;
|
||||||
|
result->TypeSpec.type = type;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
AstNode *ast_import_spec(AstFile *f, bool is_import, Token relpath, Token import_name, AstNode *cond) {
|
||||||
|
AstNode *result = make_ast_node(f, AstNode_ImportSpec);
|
||||||
|
result->ImportSpec.is_import = is_import;
|
||||||
|
result->ImportSpec.relpath = relpath;
|
||||||
|
result->ImportSpec.import_name = import_name;
|
||||||
|
result->ImportSpec.cond = cond;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool next_token(AstFile *f) {
|
bool next_token(AstFile *f) {
|
||||||
Token prev = f->curr_token;
|
Token prev = f->curr_token;
|
||||||
@@ -1688,18 +1691,9 @@ bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) {
|
|||||||
return s->ProcLit.body != NULL;
|
return s->ProcLit.body != NULL;
|
||||||
case AstNode_ProcDecl:
|
case AstNode_ProcDecl:
|
||||||
return s->ProcDecl.body != NULL;
|
return s->ProcDecl.body != NULL;
|
||||||
case AstNode_TypeDecl:
|
|
||||||
return is_semicolon_optional_for_node(f, s->TypeDecl.type);
|
|
||||||
|
|
||||||
|
case AstNode_TypeSpec:
|
||||||
case AstNode_ValueDecl:
|
return is_semicolon_optional_for_node(f, s->TypeSpec.type);
|
||||||
if (s->ValueDecl.token.kind != Token_const) {
|
|
||||||
if (s->ValueDecl.values.count > 0) {
|
|
||||||
AstNode *last = s->ValueDecl.values[s->ValueDecl.values.count-1];
|
|
||||||
return is_semicolon_optional_for_node(f, last);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -2526,61 +2520,6 @@ AstNode *parse_type(AstFile *f) {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AstNode *parse_value_decl(AstFile *f, Token token) {
|
|
||||||
Array<AstNode *> lhs = parse_lhs_expr_list(f);
|
|
||||||
AstNode *type = NULL;
|
|
||||||
Array<AstNode *> values = {};
|
|
||||||
bool is_mutable = token.kind != Token_const;
|
|
||||||
|
|
||||||
if (allow_token(f, Token_Colon)) {
|
|
||||||
type = parse_type(f);
|
|
||||||
} else if (f->curr_token.kind != Token_Eq &&
|
|
||||||
f->curr_token.kind != Token_Semicolon) {
|
|
||||||
syntax_error(f->curr_token, "Expected a type separator `:` or `=`");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
switch (f->curr_token.kind) {
|
|
||||||
case Token_Eq:
|
|
||||||
next_token(f);
|
|
||||||
values = parse_rhs_expr_list(f);
|
|
||||||
if (values.count > lhs.count) {
|
|
||||||
syntax_error(f->curr_token, "Too many values on the right hand side of the declaration");
|
|
||||||
} else if (values.count < lhs.count && !is_mutable) {
|
|
||||||
syntax_error(f->curr_token, "All constant declarations must be defined");
|
|
||||||
} else if (values.count == 0) {
|
|
||||||
syntax_error(f->curr_token, "Expected an expression for this declaration");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_mutable) {
|
|
||||||
if (type == NULL && values.count == 0) {
|
|
||||||
syntax_error(f->curr_token, "Missing variable type or initialization");
|
|
||||||
return ast_bad_decl(f, f->curr_token, f->curr_token);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (type == NULL && values.count == 0 && lhs.count > 0) {
|
|
||||||
syntax_error(f->curr_token, "Missing constant value");
|
|
||||||
return ast_bad_decl(f, f->curr_token, f->curr_token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (values.data == NULL) {
|
|
||||||
values = make_ast_node_array(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Array<AstNode *> specs = {};
|
|
||||||
array_init(&specs, heap_allocator(), 1);
|
|
||||||
AstNode *decl = ast_value_decl(f, token, lhs, type, values);
|
|
||||||
if (token.kind == Token_let) {
|
|
||||||
decl->ValueDecl.flags |= VarDeclFlag_immutable;
|
|
||||||
}
|
|
||||||
return decl;
|
|
||||||
}
|
|
||||||
|
|
||||||
AstNode *parse_proc_decl(AstFile *f) {
|
AstNode *parse_proc_decl(AstFile *f) {
|
||||||
TokenKind look_ahead = look_ahead_token_kind(f, 1);
|
TokenKind look_ahead = look_ahead_token_kind(f, 1);
|
||||||
if (look_ahead != Token_Ident) {
|
if (look_ahead != Token_Ident) {
|
||||||
@@ -2611,11 +2550,179 @@ AstNode *parse_proc_decl(AstFile *f) {
|
|||||||
return ast_proc_decl(f, token, name, type, body, tags, foreign_library, foreign_name, link_name);
|
return ast_proc_decl(f, token, name, type, body, tags, foreign_library, foreign_name, link_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
AstNode *parse_type_decl(AstFile *f) {
|
|
||||||
Token token = expect_token(f, Token_type);
|
#define PARSE_SPEC_FUNC(name) AstNode *name(AstFile *f, Token token)
|
||||||
|
typedef PARSE_SPEC_FUNC(ParseSpecFunc);
|
||||||
|
|
||||||
|
AstNode *parse_gen_decl(AstFile *f, Token token, ParseSpecFunc *func) {
|
||||||
|
Array<AstNode *> specs = {};
|
||||||
|
Token open = {};
|
||||||
|
Token close = {};
|
||||||
|
|
||||||
|
if (f->curr_token.kind == Token_OpenParen) {
|
||||||
|
specs = make_ast_node_array(f);
|
||||||
|
open = expect_token(f, Token_OpenParen);
|
||||||
|
while (f->curr_token.kind != Token_CloseParen &&
|
||||||
|
f->curr_token.kind != Token_EOF) {
|
||||||
|
AstNode *spec = func(f, token);
|
||||||
|
array_add(&specs, spec);
|
||||||
|
expect_semicolon(f, spec);
|
||||||
|
}
|
||||||
|
close = expect_token(f, Token_CloseParen);
|
||||||
|
} else {
|
||||||
|
array_init(&specs, heap_allocator(), 1);
|
||||||
|
array_add(&specs, func(f, token));
|
||||||
|
}
|
||||||
|
|
||||||
|
AstNode *decl = ast_gen_decl(f, token, open, close, specs);
|
||||||
|
if (token.kind == Token_let) {
|
||||||
|
decl->GenDecl.flags |= VarDeclFlag_immutable;
|
||||||
|
}
|
||||||
|
return decl;
|
||||||
|
}
|
||||||
|
|
||||||
|
PARSE_SPEC_FUNC(parse_value_spec) {
|
||||||
|
bool is_mutable = token.kind != Token_const;
|
||||||
|
|
||||||
|
Array<AstNode *> names = parse_ident_list(f);
|
||||||
|
AstNode *type = NULL;
|
||||||
|
Array<AstNode *> values = {};
|
||||||
|
|
||||||
|
if (allow_token(f, Token_Colon)) {
|
||||||
|
type = parse_type(f);
|
||||||
|
} else if (f->curr_token.kind != Token_Eq &&
|
||||||
|
f->curr_token.kind != Token_Semicolon) {
|
||||||
|
syntax_error(f->curr_token, "Expected a type separator `:` or `=`");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allow_token(f, Token_Eq)) {
|
||||||
|
values = parse_rhs_expr_list(f);
|
||||||
|
if (values.count > names.count) {
|
||||||
|
syntax_error(f->curr_token, "Too many values on the right hand side of the declaration");
|
||||||
|
} else if (values.count < names.count && !is_mutable) {
|
||||||
|
syntax_error(f->curr_token, "All constant declarations must be defined");
|
||||||
|
} else if (values.count == 0) {
|
||||||
|
syntax_error(f->curr_token, "Expected an expression for this declaration");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (is_mutable) {
|
||||||
|
if (type == NULL && values.count == 0) {
|
||||||
|
syntax_error(f->curr_token, "Missing variable type or initialization");
|
||||||
|
return ast_bad_decl(f, f->curr_token, f->curr_token);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (type == NULL && values.count == 0 && names.count > 0) {
|
||||||
|
syntax_error(f->curr_token, "Missing constant value");
|
||||||
|
return ast_bad_decl(f, f->curr_token, f->curr_token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (values.data == NULL) {
|
||||||
|
values = make_ast_node_array(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ast_value_spec(f, names, type, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
PARSE_SPEC_FUNC(parse_type_spec) {
|
||||||
AstNode *name = parse_ident(f);
|
AstNode *name = parse_ident(f);
|
||||||
AstNode *type = parse_type(f);
|
AstNode *type = parse_type(f);
|
||||||
return ast_type_decl(f, token, name, type);
|
return ast_type_spec(f, name, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
PARSE_SPEC_FUNC(parse_import_spec) {
|
||||||
|
if (token.kind == Token_import) {
|
||||||
|
AstNode *cond = NULL;
|
||||||
|
Token import_name = {};
|
||||||
|
|
||||||
|
switch (f->curr_token.kind) {
|
||||||
|
case Token_Period:
|
||||||
|
import_name = f->curr_token;
|
||||||
|
import_name.kind = Token_Ident;
|
||||||
|
next_token(f);
|
||||||
|
break;
|
||||||
|
case Token_Ident:
|
||||||
|
import_name = f->curr_token;
|
||||||
|
next_token(f);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
import_name.pos = f->curr_token.pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (import_name.string == "_") {
|
||||||
|
syntax_error(import_name, "Illegal import name: `_`");
|
||||||
|
}
|
||||||
|
|
||||||
|
Token file_path = expect_token_after(f, Token_String, "import");
|
||||||
|
if (allow_token(f, Token_when)) {
|
||||||
|
cond = parse_expr(f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
AstNode *spec = NULL;
|
||||||
|
if (f->curr_proc != NULL) {
|
||||||
|
syntax_error(import_name, "You cannot use `import` within a procedure. This must be done at the file scope");
|
||||||
|
spec = ast_bad_decl(f, import_name, file_path);
|
||||||
|
} else {
|
||||||
|
spec = ast_import_spec(f, true, file_path, import_name, cond);
|
||||||
|
}
|
||||||
|
return spec;
|
||||||
|
} else {
|
||||||
|
AstNode *cond = NULL;
|
||||||
|
Token file_path = expect_token_after(f, Token_String, "import_load");
|
||||||
|
Token import_name = file_path;
|
||||||
|
import_name.string = str_lit(".");
|
||||||
|
|
||||||
|
if (allow_token(f, Token_when)) {
|
||||||
|
cond = parse_expr(f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
AstNode *spec = NULL;
|
||||||
|
if (f->curr_proc != NULL) {
|
||||||
|
syntax_error(import_name, "You cannot use `import_load` within a procedure. This must be done at the file scope");
|
||||||
|
spec = ast_bad_decl(f, import_name, file_path);
|
||||||
|
} else {
|
||||||
|
spec = ast_import_spec(f, false, file_path, import_name, cond);
|
||||||
|
}
|
||||||
|
return spec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AstNode *parse_decl(AstFile *f) {
|
||||||
|
ParseSpecFunc *func = NULL;
|
||||||
|
switch (f->curr_token.kind) {
|
||||||
|
case Token_var:
|
||||||
|
case Token_const:
|
||||||
|
case Token_let:
|
||||||
|
func = parse_value_spec;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Token_type:
|
||||||
|
func = parse_type_spec;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Token_import:
|
||||||
|
case Token_import_load:
|
||||||
|
func = parse_import_spec;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Token_proc:
|
||||||
|
return parse_proc_decl(f);
|
||||||
|
|
||||||
|
default: {
|
||||||
|
Token tok = f->curr_token;
|
||||||
|
fix_advance_to_next_stmt(f);
|
||||||
|
syntax_error(tok, "Expected a declaration");
|
||||||
|
return ast_bad_decl(f, tok, f->curr_token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Token token = f->curr_token;
|
||||||
|
next_token(f);
|
||||||
|
|
||||||
|
return parse_gen_decl(f, token, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2626,8 +2733,7 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) {
|
|||||||
case Token_var:
|
case Token_var:
|
||||||
case Token_const:
|
case Token_const:
|
||||||
case Token_let:
|
case Token_let:
|
||||||
next_token(f);
|
return parse_decl(f);
|
||||||
return parse_value_decl(f, token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<AstNode *> lhs = parse_lhs_expr_list(f);
|
Array<AstNode *> lhs = parse_lhs_expr_list(f);
|
||||||
@@ -3723,20 +3829,11 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
case Token_var:
|
case Token_var:
|
||||||
case Token_const:
|
case Token_const:
|
||||||
case Token_let:
|
case Token_let:
|
||||||
s = parse_simple_stmt(f, StmtAllowFlag_None);
|
|
||||||
expect_semicolon(f, s);
|
|
||||||
return s;
|
|
||||||
|
|
||||||
case Token_proc:
|
case Token_proc:
|
||||||
s = parse_proc_decl(f);
|
|
||||||
expect_semicolon(f, s);
|
|
||||||
return s;
|
|
||||||
|
|
||||||
case Token_type:
|
case Token_type:
|
||||||
s = parse_type_decl(f);
|
case Token_import:
|
||||||
expect_semicolon(f, s);
|
case Token_import_load:
|
||||||
return s;
|
return parse_decl(f);
|
||||||
|
|
||||||
|
|
||||||
case Token_if: return parse_if_stmt(f);
|
case Token_if: return parse_if_stmt(f);
|
||||||
case Token_when: return parse_when_stmt(f);
|
case Token_when: return parse_when_stmt(f);
|
||||||
@@ -3767,8 +3864,7 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
AstNode *decl = NULL;
|
AstNode *decl = NULL;
|
||||||
if (f->curr_token.kind == Token_var ||
|
if (f->curr_token.kind == Token_var ||
|
||||||
f->curr_token.kind == Token_let) {
|
f->curr_token.kind == Token_let) {
|
||||||
Token var = f->curr_token; next_token(f);
|
decl = parse_decl(f);
|
||||||
decl = parse_value_decl(f, var);
|
|
||||||
expect_semicolon(f, decl);
|
expect_semicolon(f, decl);
|
||||||
} else {
|
} else {
|
||||||
Array<AstNode *> list = parse_lhs_expr_list(f);
|
Array<AstNode *> list = parse_lhs_expr_list(f);
|
||||||
@@ -3785,20 +3881,17 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (decl != NULL && decl->kind == AstNode_ValueDecl) {
|
if (decl != NULL && decl->kind == AstNode_GenDecl) {
|
||||||
#if 1
|
if (decl->GenDecl.token.kind != Token_var &&
|
||||||
if (decl->ValueDecl.token.kind == Token_const) {
|
decl->GenDecl.token.kind != Token_let) {
|
||||||
syntax_error(token, "`using` may not be applied to constant declarations");
|
syntax_error(token, "`using` may only be applied to variable declarations");
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
if (f->curr_proc == NULL) {
|
if (f->curr_proc == NULL) {
|
||||||
syntax_error(token, "`using` is not allowed at the file scope");
|
syntax_error(token, "`using` is not allowed at the file scope");
|
||||||
} else {
|
} else {
|
||||||
decl->ValueDecl.flags |= VarDeclFlag_using;
|
decl->GenDecl.flags |= VarDeclFlag_using;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
decl->ValueDecl.flags |= VarDeclFlag_using;
|
|
||||||
#endif
|
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3846,6 +3939,7 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
return ast_push_context(f, token, expr, body);
|
return ast_push_context(f, token, expr, body);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
#if 0
|
||||||
case Token_import: {
|
case Token_import: {
|
||||||
Token token = expect_token(f, Token_import);
|
Token token = expect_token(f, Token_import);
|
||||||
AstNode *cond = NULL;
|
AstNode *cond = NULL;
|
||||||
@@ -3907,6 +4001,7 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
expect_semicolon(f, decl);
|
expect_semicolon(f, decl);
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
case Token_Hash: {
|
case Token_Hash: {
|
||||||
AstNode *s = NULL;
|
AstNode *s = NULL;
|
||||||
@@ -3989,14 +4084,15 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
} else if (tag == "thread_local") {
|
} else if (tag == "thread_local") {
|
||||||
AstNode *s = parse_stmt(f);
|
AstNode *s = parse_stmt(f);
|
||||||
|
|
||||||
if (s->kind == AstNode_ValueDecl) {
|
if (s->kind == AstNode_GenDecl) {
|
||||||
if (s->ValueDecl.token.kind == Token_const) {
|
if (s->GenDecl.token.kind != Token_var &&
|
||||||
syntax_error(token, "`thread_local` may not be applied to constant declarations");
|
s->GenDecl.token.kind != Token_let) {
|
||||||
|
syntax_error(token, "`thread_local` may only be applied to variable declarations");
|
||||||
}
|
}
|
||||||
if (f->curr_proc != NULL) {
|
if (f->curr_proc != NULL) {
|
||||||
syntax_error(token, "`thread_local` is only allowed at the file scope");
|
syntax_error(token, "`thread_local` is only allowed at the file scope");
|
||||||
} else {
|
} else {
|
||||||
s->ValueDecl.flags |= VarDeclFlag_thread_local;
|
s->GenDecl.flags |= VarDeclFlag_thread_local;
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -4219,87 +4315,94 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod
|
|||||||
node->kind != AstNode_EmptyStmt) {
|
node->kind != AstNode_EmptyStmt) {
|
||||||
// NOTE(bill): Sanity check
|
// NOTE(bill): Sanity check
|
||||||
syntax_error_node(node, "Only declarations are allowed at file scope %.*s", LIT(ast_node_strings[node->kind]));
|
syntax_error_node(node, "Only declarations are allowed at file scope %.*s", LIT(ast_node_strings[node->kind]));
|
||||||
} else if (node->kind == AstNode_ImportDecl) {
|
} else if (node->kind == AstNode_GenDecl) {
|
||||||
ast_node(id, ImportDecl, node);
|
ast_node(gd, GenDecl, node);
|
||||||
String collection_name = {};
|
if (gd->token.kind == Token_import ||
|
||||||
String oirignal_string = id->relpath.string;
|
gd->token.kind == Token_import_load) {
|
||||||
String file_str = id->relpath.string;
|
for_array(spec_index, gd->specs) {
|
||||||
gbAllocator allocator = heap_allocator(); // TODO(bill): Change this allocator
|
AstNode *spec = gd->specs[spec_index];
|
||||||
String import_file = {};
|
ast_node(id, ImportSpec, spec);
|
||||||
|
String collection_name = {};
|
||||||
|
String oirignal_string = id->relpath.string;
|
||||||
|
String file_str = id->relpath.string;
|
||||||
|
gbAllocator allocator = heap_allocator(); // TODO(bill): Change this allocator
|
||||||
|
String import_file = {};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
isize colon_pos = -1;
|
isize colon_pos = -1;
|
||||||
for (isize j = 0; j < file_str.len; j++) {
|
for (isize j = 0; j < file_str.len; j++) {
|
||||||
if (file_str[j] == ':') {
|
if (file_str[j] == ':') {
|
||||||
colon_pos = j;
|
colon_pos = j;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (colon_pos > 0) {
|
if (colon_pos > 0) {
|
||||||
collection_name = make_string(file_str.text, colon_pos);
|
collection_name = make_string(file_str.text, colon_pos);
|
||||||
file_str.text += colon_pos+1;
|
file_str.text += colon_pos+1;
|
||||||
file_str.len -= colon_pos+1;
|
file_str.len -= colon_pos+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collection_name.len == 0) {
|
if (collection_name.len == 0) {
|
||||||
syntax_error_node(node, "Missing import collection for path: `%.*s`", LIT(oirignal_string));
|
syntax_error_node(node, "Missing import collection for path: `%.*s`", LIT(oirignal_string));
|
||||||
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
|
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (collection_name == "core") {
|
if (collection_name == "core") {
|
||||||
String abs_path = get_fullpath_core(allocator, file_str);
|
String abs_path = get_fullpath_core(allocator, file_str);
|
||||||
if (gb_file_exists(cast(char *)abs_path.text)) { // NOTE(bill): This should be null terminated
|
if (gb_file_exists(cast(char *)abs_path.text)) { // NOTE(bill): This should be null terminated
|
||||||
import_file = abs_path;
|
import_file = abs_path;
|
||||||
}
|
}
|
||||||
} else if (collection_name == "local") {
|
} else if (collection_name == "local") {
|
||||||
String rel_path = get_fullpath_relative(allocator, base_dir, file_str);
|
String rel_path = get_fullpath_relative(allocator, base_dir, file_str);
|
||||||
if (gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated
|
if (gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated
|
||||||
|
import_file = rel_path;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
syntax_error_node(node, "Unknown import collection: `%.*s`", LIT(collection_name));
|
||||||
|
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_import_path_valid(file_str)) {
|
||||||
|
if (id->is_import) {
|
||||||
|
syntax_error_node(node, "Invalid import path: `%.*s`", LIT(file_str));
|
||||||
|
} else {
|
||||||
|
syntax_error_node(node, "Invalid include path: `%.*s`", LIT(file_str));
|
||||||
|
}
|
||||||
|
// NOTE(bill): It's a naughty name
|
||||||
|
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
if (!is_import_path_valid(file_str)) {
|
||||||
|
if (id->is_import) {
|
||||||
|
syntax_error_node(node, "Invalid import path: `%.*s`", LIT(file_str));
|
||||||
|
} else {
|
||||||
|
syntax_error_node(node, "Invalid include path: `%.*s`", LIT(file_str));
|
||||||
|
}
|
||||||
|
// NOTE(bill): It's a naughty name
|
||||||
|
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String rel_path = get_fullpath_relative(allocator, base_dir, file_str);
|
||||||
import_file = rel_path;
|
import_file = rel_path;
|
||||||
}
|
if (!gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated
|
||||||
} else {
|
String abs_path = get_fullpath_core(allocator, file_str);
|
||||||
syntax_error_node(node, "Unknown import collection: `%.*s`", LIT(collection_name));
|
if (gb_file_exists(cast(char *)abs_path.text)) {
|
||||||
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
|
import_file = abs_path;
|
||||||
continue;
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!is_import_path_valid(file_str)) {
|
id->fullpath = import_file;
|
||||||
if (id->is_import) {
|
try_add_import_path(p, import_file, file_str, ast_node_token(node).pos);
|
||||||
syntax_error_node(node, "Invalid import path: `%.*s`", LIT(file_str));
|
|
||||||
} else {
|
|
||||||
syntax_error_node(node, "Invalid include path: `%.*s`", LIT(file_str));
|
|
||||||
}
|
|
||||||
// NOTE(bill): It's a naughty name
|
|
||||||
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
if (!is_import_path_valid(file_str)) {
|
|
||||||
if (id->is_import) {
|
|
||||||
syntax_error_node(node, "Invalid import path: `%.*s`", LIT(file_str));
|
|
||||||
} else {
|
|
||||||
syntax_error_node(node, "Invalid include path: `%.*s`", LIT(file_str));
|
|
||||||
}
|
|
||||||
// NOTE(bill): It's a naughty name
|
|
||||||
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String rel_path = get_fullpath_relative(allocator, base_dir, file_str);
|
|
||||||
import_file = rel_path;
|
|
||||||
if (!gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated
|
|
||||||
String abs_path = get_fullpath_core(allocator, file_str);
|
|
||||||
if (gb_file_exists(cast(char *)abs_path.text)) {
|
|
||||||
import_file = abs_path;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
id->fullpath = import_file;
|
|
||||||
try_add_import_path(p, import_file, file_str, ast_node_token(node).pos);
|
|
||||||
} else if (node->kind == AstNode_ForeignLibrary) {
|
} else if (node->kind == AstNode_ForeignLibrary) {
|
||||||
AstNodeForeignLibrary *fl = &node->ForeignLibrary;
|
AstNodeForeignLibrary *fl = &node->ForeignLibrary;
|
||||||
String file_str = fl->filepath.string;
|
String file_str = fl->filepath.string;
|
||||||
|
|||||||
+1
-56
@@ -1948,7 +1948,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) {
|
|||||||
case_ast_node(us, UsingStmt, node);
|
case_ast_node(us, UsingStmt, node);
|
||||||
for_array(i, us->list) {
|
for_array(i, us->list) {
|
||||||
AstNode *decl = unparen_expr(us->list[i]);
|
AstNode *decl = unparen_expr(us->list[i]);
|
||||||
if (decl->kind == AstNode_ValueDecl) {
|
if (decl->kind == AstNode_GenDecl) {
|
||||||
ssa_build_stmt(p, decl);
|
ssa_build_stmt(p, decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1968,61 +1968,6 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) {
|
|||||||
ssa_build_assign_op(p, addr, ssa_const_int(p, t, 1), op);
|
ssa_build_assign_op(p, addr, ssa_const_int(p, t, 1), op);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(vd, ValueDecl, node);
|
|
||||||
if (vd->token.kind != Token_const) {
|
|
||||||
ssaModule *m = p->module;
|
|
||||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
|
|
||||||
if (vd->values.count == 0) {
|
|
||||||
for_array(i, vd->names) {
|
|
||||||
AstNode *name = vd->names[i];
|
|
||||||
if (!ssa_is_blank_ident(name)) {
|
|
||||||
ssa_add_local_for_ident(p, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Array<ssaAddr> lvals = {0};
|
|
||||||
Array<ssaValue *> inits = {0};
|
|
||||||
array_init(&lvals, m->tmp_allocator, vd->names.count);
|
|
||||||
array_init(&inits, m->tmp_allocator, vd->names.count);
|
|
||||||
|
|
||||||
for_array(i, vd->names) {
|
|
||||||
AstNode *name = vd->names[i];
|
|
||||||
ssaAddr lval = ssa_addr(NULL);
|
|
||||||
if (!ssa_is_blank_ident(name)) {
|
|
||||||
lval = ssa_add_local_for_ident(p, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
array_add(&lvals, lval);
|
|
||||||
}
|
|
||||||
|
|
||||||
for_array(i, vd->values) {
|
|
||||||
ssaValue *init = ssa_build_expr(p, vd->values[i]);
|
|
||||||
if (init == NULL) { // TODO(bill): remove this
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Type *t = base_type(init->type);
|
|
||||||
if (t->kind == Type_Tuple) {
|
|
||||||
for (isize i = 0; i < t->Tuple.variable_count; i++) {
|
|
||||||
// Entity *e = t->Tuple.variables[i];
|
|
||||||
ssaValue *v = ssa_emit_value_index(p, init, i);
|
|
||||||
array_add(&inits, v);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
array_add(&inits, init);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for_array(i, inits) {
|
|
||||||
ssa_addr_store(p, lvals[i], inits[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gb_temp_arena_memory_end(tmp);
|
|
||||||
} else {
|
|
||||||
GB_PANIC("TODO(bill): ssa_build_stmt Type/Proc Entities");
|
|
||||||
}
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(as, AssignStmt, node);
|
case_ast_node(as, AssignStmt, node);
|
||||||
ssa_emit_comment(p, str_lit("AssignStmt"));
|
ssa_emit_comment(p, str_lit("AssignStmt"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user