Pascal style declaration grouping with ()

This commit is contained in:
Ginger Bill
2017-06-12 15:42:21 +01:00
parent 2ab0d97573
commit 6b5e9aec8e
24 changed files with 2595 additions and 2470 deletions

View File

@@ -1,15 +1,23 @@
import "fmt.odin";
import "atomics.odin";
import "bits.odin";
import "math.odin";
import "mem.odin";
import "opengl.odin";
import "strconv.odin";
import "strings.odin";
import "sync.odin";
import "types.odin";
import "utf8.odin";
import "utf16.odin";
import (
"fmt.odin";
"hash.odin";
"atomics.odin";
"bits.odin";
"math.odin";
"mem.odin";
"opengl.odin";
"strconv.odin";
"strings.odin";
"sync.odin";
"types.odin";
"utf8.odin";
"utf16.odin";
)
const (
X = 123;
Y = 432;
)
proc main() {
proc(s: string){

View File

@@ -1,10 +1,11 @@
#shared_global_scope;
import "os.odin";
import "fmt.odin";
import "utf8.odin";
import "raw.odin";
import (
"os.odin";
"fmt.odin";
"utf8.odin";
"raw.odin";
)
// Naming Conventions:
// In general, PascalCase for types and snake_case for values
//
@@ -24,95 +25,98 @@ import "raw.odin";
// IMPORTANT NOTE(bill): Do not change the order of any of this data
// The compiler relies upon this _exact_ order
type TypeInfoEnumValue raw_union {
f: f64,
i: i128,
}
// NOTE(bill): This must match the compiler's
type CallingConvention enum {
Odin = 0,
C = 1,
Std = 2,
Fast = 3,
}
type (
TypeInfoEnumValue raw_union {
f: f64,
i: i128,
}
// NOTE(bill): This must match the compiler's
CallingConvention enum {
Odin = 0,
C = 1,
Std = 2,
Fast = 3,
}
type TypeInfoRecord struct #ordered {
types: []^TypeInfo,
names: []string,
offsets: []int, // offsets may not be used in tuples
usings: []bool, // usings may not be used in tuples
packed: bool,
ordered: bool,
custom_align: bool,
}
TypeInfoRecord struct #ordered {
types: []^TypeInfo,
names: []string,
offsets: []int, // offsets may not be used in tuples
usings: []bool, // usings may not be used in tuples
packed: bool,
ordered: bool,
custom_align: bool,
}
type TypeInfo union {
size: int,
align: int,
TypeInfo union {
size: int,
align: int,
Named{name: string, base: ^TypeInfo},
Integer{signed: bool},
Rune{},
Float{},
Complex{},
String{},
Boolean{},
Any{},
Pointer{
elem: ^TypeInfo, // nil -> rawptr
},
Atomic{elem: ^TypeInfo},
Procedure{
params: ^TypeInfo, // TypeInfo.Tuple
results: ^TypeInfo, // TypeInfo.Tuple
variadic: bool,
convention: CallingConvention,
},
Array{
elem: ^TypeInfo,
elem_size: int,
count: int,
},
DynamicArray{elem: ^TypeInfo, elem_size: int},
Slice {elem: ^TypeInfo, elem_size: int},
Vector {elem: ^TypeInfo, elem_size, count: int},
Tuple {using record: TypeInfoRecord}, // Only really used for procedures
Struct {using record: TypeInfoRecord},
RawUnion {using record: TypeInfoRecord},
Union{
common_fields: struct {
types: []^TypeInfo,
names: []string,
offsets: []int, // offsets may not be used in tuples
Named{name: string, base: ^TypeInfo},
Integer{signed: bool},
Rune{},
Float{},
Complex{},
String{},
Boolean{},
Any{},
Pointer{
elem: ^TypeInfo, // nil -> rawptr
},
variant_names: []string,
variant_types: []^TypeInfo,
},
Enum{
base: ^TypeInfo,
names: []string,
values: []TypeInfoEnumValue,
},
Map{
key: ^TypeInfo,
value: ^TypeInfo,
generated_struct: ^TypeInfo,
count: int, // == 0 if dynamic
},
BitField{
names: []string,
bits: []i32,
offsets: []i32,
},
}
Atomic{elem: ^TypeInfo},
Procedure{
params: ^TypeInfo, // TypeInfo.Tuple
results: ^TypeInfo, // TypeInfo.Tuple
variadic: bool,
convention: CallingConvention,
},
Array{
elem: ^TypeInfo,
elem_size: int,
count: int,
},
DynamicArray{elem: ^TypeInfo, elem_size: int},
Slice {elem: ^TypeInfo, elem_size: int},
Vector {elem: ^TypeInfo, elem_size, count: int},
Tuple {using record: TypeInfoRecord}, // Only really used for procedures
Struct {using record: TypeInfoRecord},
RawUnion {using record: TypeInfoRecord},
Union{
common_fields: struct {
types: []^TypeInfo,
names: []string,
offsets: []int, // offsets may not be used in tuples
},
variant_names: []string,
variant_types: []^TypeInfo,
},
Enum{
base: ^TypeInfo,
names: []string,
values: []TypeInfoEnumValue,
},
Map{
key: ^TypeInfo,
value: ^TypeInfo,
generated_struct: ^TypeInfo,
count: int, // == 0 if dynamic
},
BitField{
names: []string,
bits: []i32,
offsets: []i32,
},
}
)
// NOTE(bill): only the ones that are needed (not all types)
// This will be set by the compiler
var __type_table: []TypeInfo;
var (
__type_table: []TypeInfo;
var __argv__: ^^u8;
var __argc__: i32;
__argv__: ^^u8;
__argc__: i32;
)
proc type_info_base(info: ^TypeInfo) -> ^TypeInfo {
if info == nil {
@@ -151,29 +155,31 @@ proc read_cycle_counter() -> u64 #foreign __llvm_core "llvm.readcyclecounter";
// IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it)
type AllocatorMode enum u8 {
Alloc,
Free,
FreeAll,
Resize,
}
type AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode,
size, alignment: int,
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
type Allocator struct #ordered {
procedure: AllocatorProc,
data: rawptr,
}
type (
AllocatorMode enum u8 {
Alloc,
Free,
FreeAll,
Resize,
}
AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode,
size, alignment: int,
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
Allocator struct #ordered {
procedure: AllocatorProc,
data: rawptr,
}
type Context struct #ordered {
thread_id: int,
Context struct #ordered {
thread_id: int,
allocator: Allocator,
allocator: Allocator,
user_data: rawptr,
user_index: int,
}
user_data: rawptr,
user_index: int,
}
)
#thread_local var __context: Context;
@@ -553,33 +559,35 @@ proc __default_hash_string(s: string) -> u128 {
const __INITIAL_MAP_CAP = 16;
type __MapKey struct #ordered {
hash: u128,
str: string,
}
type (
__MapKey struct #ordered {
hash: u128,
str: string,
}
type __MapFindResult struct #ordered {
hash_index: int,
entry_prev: int,
entry_index: int,
}
__MapFindResult struct #ordered {
hash_index: int,
entry_prev: int,
entry_index: int,
}
type __MapEntryHeader struct #ordered {
key: __MapKey,
next: int,
/*
value: Value_Type,
*/
}
__MapEntryHeader struct #ordered {
key: __MapKey,
next: int,
/*
value: Value_Type,
*/
}
type __MapHeader struct #ordered {
m: ^raw.DynamicMap,
is_key_string: bool,
entry_size: int,
entry_align: int,
value_offset: int,
value_size: int,
}
__MapHeader struct #ordered {
m: ^raw.DynamicMap,
is_key_string: bool,
entry_size: int,
entry_align: int,
value_offset: int,
value_size: int,
}
)
proc __dynamic_map_reserve(using header: __MapHeader, cap: int) {
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap);

View File

@@ -1,27 +1,28 @@
const U8_MIN = u8(0);
const U16_MIN = u16(0);
const U32_MIN = u32(0);
const U64_MIN = u64(0);
const U128_MIN = u128(0);
const (
U8_MIN = u8(0);
U16_MIN = u16(0);
U32_MIN = u32(0);
U64_MIN = u64(0);
U128_MIN = u128(0);
const I8_MIN = i8(-0x80);
const I16_MIN = i16(-0x8000);
const I32_MIN = i32(-0x8000_0000);
const I64_MIN = i64(-0x8000_0000_0000_0000);
const I128_MIN = i128(-0x8000_0000_0000_0000_0000_0000_0000_0000);
I8_MIN = i8(-0x80);
I16_MIN = i16(-0x8000);
I32_MIN = i32(-0x8000_0000);
I64_MIN = i64(-0x8000_0000_0000_0000);
I128_MIN = i128(-0x8000_0000_0000_0000_0000_0000_0000_0000);
const U8_MAX = ~u8(0);
const U16_MAX = ~u16(0);
const U32_MAX = ~u32(0);
const U64_MAX = ~u64(0);
const U128_MAX = ~u128(0);
const I8_MAX = i8(0x7f);
const I16_MAX = i16(0x7fff);
const I32_MAX = i32(0x7fff_ffff);
const I64_MAX = i64(0x7fff_ffff_ffff_ffff);
const I128_MAX = i128(0x7fff_ffff_ffff_ffff_ffff_ffff_ffff_ffff);
U8_MAX = ~u8(0);
U16_MAX = ~u16(0);
U32_MAX = ~u32(0);
U64_MAX = ~u64(0);
U128_MAX = ~u128(0);
I8_MAX = i8(0x7f);
I16_MAX = i16(0x7fff);
I32_MAX = i32(0x7fff_ffff);
I64_MAX = i64(0x7fff_ffff_ffff_ffff);
I128_MAX = i128(0x7fff_ffff_ffff_ffff_ffff_ffff_ffff_ffff);
)
proc count_ones(i: u8) -> u8 { proc __llvm_ctpop(u8) -> u8 #foreign __llvm_core "llvm.ctpop.i8"; return __llvm_ctpop(i); }
proc count_ones(i: i8) -> i8 { proc __llvm_ctpop(i8) -> i8 #foreign __llvm_core "llvm.ctpop.i8"; return __llvm_ctpop(i); }

View File

@@ -1,10 +1,11 @@
import "os.odin";
import "mem.odin";
import "utf8.odin";
import "types.odin";
import "strconv.odin";
import "raw.odin";
import (
"os.odin";
"mem.odin";
"utf8.odin";
"types.odin";
"strconv.odin";
"raw.odin";
)
const _BUFFER_SIZE = 1<<12;

View File

@@ -1,61 +1,61 @@
crc32 :: proc(data: []u8) -> u32 {
result := ~u32(0);
proc crc32(data: []u8) -> u32 {
var result = ~u32(0);
for b in data {
result = result>>8 ~ _crc32_table[(result ~ u32(b)) & 0xff];
}
return ~result;
}
crc64 :: proc(data: []u8) -> u64 {
result := ~u64(0);
proc crc64(data: []u8) -> u64 {
var result = ~u64(0);
for b in data {
result = result>>8 ~ _crc64_table[(result ~ u64(b)) & 0xff];
}
return ~result;
}
fnv32 :: proc(data: []u8) -> u32 {
h: u32 = 0x811c9dc5;
proc fnv32(data: []u8) -> u32 {
var h: u32 = 0x811c9dc5;
for b in data {
h = (h * 0x01000193) ~ u32(b);
}
return h;
}
fnv64 :: proc(data: []u8) -> u64 {
h: u64 = 0xcbf29ce484222325;
proc fnv64(data: []u8) -> u64 {
var h: u64 = 0xcbf29ce484222325;
for b in data {
h = (h * 0x100000001b3) ~ u64(b);
}
return h;
}
fnv32a :: proc(data: []u8) -> u32 {
h: u32 = 0x811c9dc5;
proc fnv32a(data: []u8) -> u32 {
var h: u32 = 0x811c9dc5;
for b in data {
h = (h ~ u32(b)) * 0x01000193;
}
return h;
}
fnv64a :: proc(data: []u8) -> u64 {
h: u64 = 0xcbf29ce484222325;
proc fnv64a(data: []u8) -> u64 {
var h: u64 = 0xcbf29ce484222325;
for b in data {
h = (h ~ u64(b)) * 0x100000001b3;
}
return h;
}
murmur32 :: proc(data: []u8) -> u32 {
c1_32: u32 : 0xcc9e2d51;
c2_32: u32 : 0x1b873593;
proc murmur32(data: []u8) -> u32 {
const c1_32: u32 = 0xcc9e2d51;
const c2_32: u32 = 0x1b873593;
h1: u32 = 0;
nblocks := len(data)/4;
p := &data[0];
p1 := p + 4*nblocks;
var h1: u32 = 0;
var nblocks = len(data)/4;
var p = &data[0];
var p1 = p + 4*nblocks;
for ; p < p1; p += 4 {
k1 := ^u32(p)^;
var k1 = ^u32(p)^;
k1 *= c1_32;
k1 = (k1 << 15) | (k1 >> 17);
@@ -66,9 +66,9 @@ murmur32 :: proc(data: []u8) -> u32 {
h1 = h1*5 + 0xe6546b64;
}
tail := data[nblocks*4 ..];
var tail = data[nblocks*4 ..];
k1: u32;
var k1: u32;
match len(tail)&3 {
case 3:
k1 ~= u32(tail[2]) << 16;
@@ -95,18 +95,18 @@ murmur32 :: proc(data: []u8) -> u32 {
return h1;
}
murmur64 :: proc(data: []u8) -> u64 {
SEED :: 0x9747b28c;
proc murmur64(data: []u8) -> u64 {
const SEED = 0x9747b28c;
when size_of(int) == 8 {
m :: 0xc6a4a7935bd1e995;
r :: 47;
const m = 0xc6a4a7935bd1e995;
const r = 47;
h: u64 = SEED ~ (u64(len(data)) * m);
data64 := slice_ptr(^u64(&data[0]), len(data)/size_of(u64));
var h: u64 = SEED ~ (u64(len(data)) * m);
var data64 = slice_ptr(^u64(&data[0]), len(data)/size_of(u64));
for _, i in data64 {
k := data64[i];
var k = data64[i];
k *= m;
k ~= k>>r;
@@ -134,18 +134,18 @@ murmur64 :: proc(data: []u8) -> u64 {
return h;
} else {
m :: 0x5bd1e995;
r :: 24;
const m = 0x5bd1e995;
const r = 24;
h1 := u32(SEED) ~ u32(len(data));
h2 := u32(SEED) >> 32;
var h1 = u32(SEED) ~ u32(len(data));
var h2 = u32(SEED) >> 32;
data32 := slice_ptr(cast(^u32)&data[0], len(data)/size_of(u32));
len := len(data);
var data32 = slice_ptr(cast(^u32)&data[0], len(data)/size_of(u32));
var len = len(data);
i := 0;
var i = 0;
for len >= 8 {
k1, k2: u32;
var k1, k2: u32;
k1 = data32[i]; i++;
k1 *= m;
k1 ~= k1>>r;
@@ -164,7 +164,7 @@ murmur64 :: proc(data: []u8) -> u64 {
}
if len >= 4 {
k1: u32;
var k1: u32;
k1 = data32[i]; i++;
k1 *= m;
k1 ~= k1>>r;
@@ -175,7 +175,7 @@ murmur64 :: proc(data: []u8) -> u64 {
}
// TODO(bill): Fix this
#no_bounds_check data8 := slice_to_bytes(data32[i..])[0..<3];
#no_bounds_check var data8 = slice_to_bytes(data32[i..])[0..<3];
match len {
case 3:
h2 ~= u32(data8[2]) << 16;
@@ -197,13 +197,13 @@ murmur64 :: proc(data: []u8) -> u64 {
h2 ~= h1>>19;
h2 *= m;
h := cast(u64)(h1)<<32 | cast(u64)(h2);
var h = cast(u64)(h1)<<32 | cast(u64)(h2);
return h;
}
}
immutable _crc32_table := [256]u32{
let _crc32_table = [256]u32{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@@ -269,7 +269,7 @@ immutable _crc32_table := [256]u32{
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
immutable _crc64_table := [256]u64{
let _crc64_table = [256]u64{
0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5,
0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a,
0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b,

View File

@@ -1,31 +1,34 @@
const TAU = 6.28318530717958647692528676655900576;
const PI = 3.14159265358979323846264338327950288;
const ONE_OVER_TAU = 0.636619772367581343075535053490057448;
const ONE_OVER_PI = 0.159154943091895335768883763372514362;
const (
TAU = 6.28318530717958647692528676655900576;
PI = 3.14159265358979323846264338327950288;
ONE_OVER_TAU = 0.636619772367581343075535053490057448;
ONE_OVER_PI = 0.159154943091895335768883763372514362;
const E = 2.71828182845904523536;
const SQRT_TWO = 1.41421356237309504880168872420969808;
const SQRT_THREE = 1.73205080756887729352744634150587236;
const SQRT_FIVE = 2.23606797749978969640917366873127623;
E = 2.71828182845904523536;
SQRT_TWO = 1.41421356237309504880168872420969808;
SQRT_THREE = 1.73205080756887729352744634150587236;
SQRT_FIVE = 2.23606797749978969640917366873127623;
const LOG_TWO = 0.693147180559945309417232121458176568;
const LOG_TEN = 2.30258509299404568401799145468436421;
LOG_TWO = 0.693147180559945309417232121458176568;
LOG_TEN = 2.30258509299404568401799145468436421;
const EPSILON = 1.19209290e-7;
EPSILON = 1.19209290e-7;
const τ = TAU;
const π = PI;
type Vec2 [vector 2]f32;
type Vec3 [vector 3]f32;
type Vec4 [vector 4]f32;
τ = TAU;
π = PI;
)
type (
Vec2 [vector 2]f32;
Vec3 [vector 3]f32;
Vec4 [vector 4]f32;
// Column major
type Mat2 [2][2]f32;
type Mat3 [3][3]f32;
type Mat4 [4][4]f32;
Mat2 [2][2]f32;
Mat3 [3][3]f32;
Mat4 [4][4]f32;
type Complex complex64;
Complex complex64;
)
proc sqrt(x: f32) -> f32 #foreign __llvm_core "llvm.sqrt.f32";
proc sqrt(x: f64) -> f64 #foreign __llvm_core "llvm.sqrt.f64";

View File

@@ -1,5 +1,7 @@
import "fmt.odin";
import "os.odin";
import (
"fmt.odin";
"os.odin";
)
proc swap(b: u16) -> u16 #foreign __llvm_core "llvm.bswap.i16";
proc swap(b: u32) -> u32 #foreign __llvm_core "llvm.bswap.i32";

View File

@@ -1,7 +1,9 @@
#foreign_system_library lib "opengl32.lib" when ODIN_OS == "windows";
#foreign_system_library lib "gl" when ODIN_OS == "linux";
import win32 "sys/windows.odin" when ODIN_OS == "windows";
import "sys/wgl.odin" when ODIN_OS == "windows";
import (
win32 "sys/windows.odin" when ODIN_OS == "windows";
"sys/wgl.odin" when ODIN_OS == "windows";
)
import_load "opengl_constants.odin";
proc Clear (mask: u32) #foreign lib "glClear";

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,8 @@
import_load "os_windows.odin" when ODIN_OS == "windows";
import_load "os_x.odin" when ODIN_OS == "osx";
import_load "os_linux.odin" when ODIN_OS == "linux";
import_load (
"os_windows.odin" when ODIN_OS == "windows";
"os_x.odin" when ODIN_OS == "osx";
"os_linux.odin" when ODIN_OS == "linux";
)
proc write_string(fd: Handle, str: string) -> (int, Errno) {
return write(fd, []u8(str));

View File

@@ -1,36 +1,40 @@
#foreign_system_library dl "dl";
#foreign_system_library libc "c";
import "strings.odin";
type Handle i32;
type FileTime u64;
type Errno i32;
type (
Handle i32;
FileTime u64;
Errno i32;
)
// INVALID_HANDLE: Handle : -1;
const (
O_RDONLY = 0x00000;
O_WRONLY = 0x00001;
O_RDWR = 0x00002;
O_CREAT = 0x00040;
O_EXCL = 0x00080;
O_NOCTTY = 0x00100;
O_TRUNC = 0x00200;
O_NONBLOCK = 0x00800;
O_APPEND = 0x00400;
O_SYNC = 0x01000;
O_ASYNC = 0x02000;
O_CLOEXEC = 0x80000;
SEEK_SET = 0;
SEEK_CUR = 1;
SEEK_END = 2;
SEEK_DATA = 3;
SEEK_HOLE = 4;
SEEK_MAX = SEEK_HOLE;
const O_RDONLY = 0x00000;
const O_WRONLY = 0x00001;
const O_RDWR = 0x00002;
const O_CREAT = 0x00040;
const O_EXCL = 0x00080;
const O_NOCTTY = 0x00100;
const O_TRUNC = 0x00200;
const O_NONBLOCK = 0x00800;
const O_APPEND = 0x00400;
const O_SYNC = 0x01000;
const O_ASYNC = 0x02000;
const O_CLOEXEC = 0x80000;
const SEEK_SET = 0;
const SEEK_CUR = 1;
const SEEK_END = 2;
const SEEK_DATA = 3;
const SEEK_HOLE = 4;
const SEEK_MAX = SEEK_HOLE;
// NOTE(zangent): These are OS specific!
// Do not mix these up!
const RTLD_LAZY = 0x001;
const RTLD_NOW = 0x002;
const RTLD_BINDING_MASK = 0x3;
const RTLD_GLOBAL = 0x100;
// NOTE(zangent): These are OS specific!
// Do not mix these up!
RTLD_LAZY = 0x001;
RTLD_NOW = 0x002;
RTLD_BINDING_MASK = 0x3;
RTLD_GLOBAL = 0x100;
)
// "Argv" arguments converted to Odin strings
let args = _alloc_command_line_arguments();
@@ -70,41 +74,39 @@ type Stat struct #ordered {
};
// File type
const (
S_IFMT = 0170000; // Type of file mask
S_IFIFO = 0010000; // Named pipe (fifo)
S_IFCHR = 0020000; // Character special
S_IFDIR = 0040000; // Directory
S_IFBLK = 0060000; // Block special
S_IFREG = 0100000; // Regular
S_IFLNK = 0120000; // Symbolic link
S_IFSOCK = 0140000; // Socket
const S_IFMT = 0170000; // Type of file mask
const S_IFIFO = 0010000; // Named pipe (fifo)
const S_IFCHR = 0020000; // Character special
const S_IFDIR = 0040000; // Directory
const S_IFBLK = 0060000; // Block special
const S_IFREG = 0100000; // Regular
const S_IFLNK = 0120000; // Symbolic link
const S_IFSOCK = 0140000; // Socket
// File mode
// Read, write, execute/search by owner
S_IRWXU = 0000700; // RWX mask for owner
S_IRUSR = 0000400; // R for owner
S_IWUSR = 0000200; // W for owner
S_IXUSR = 0000100; // X for owner
// File mode
// Read, write, execute/search by owner
// Read, write, execute/search by group
S_IRWXG = 0000070; // RWX mask for group
S_IRGRP = 0000040; // R for group
S_IWGRP = 0000020; // W for group
S_IXGRP = 0000010; // X for group
const S_IRWXU = 0000700; // RWX mask for owner
const S_IRUSR = 0000400; // R for owner
const S_IWUSR = 0000200; // W for owner
const S_IXUSR = 0000100; // X for owner
// Read, write, execute/search by others
S_IRWXO = 0000007; // RWX mask for other
S_IROTH = 0000004; // R for other
S_IWOTH = 0000002; // W for other
S_IXOTH = 0000001; // X for other
// Read, write, execute/search by group
const S_IRWXG = 0000070; // RWX mask for group
const S_IRGRP = 0000040; // R for group
const S_IWGRP = 0000020; // W for group
const S_IXGRP = 0000010; // X for group
// Read, write, execute/search by others
const S_IRWXO = 0000007; // RWX mask for other
const S_IROTH = 0000004; // R for other
const S_IWOTH = 0000002; // W for other
const S_IXOTH = 0000001; // X for other
const S_ISUID = 0004000; // Set user id on execution
const S_ISGID = 0002000; // Set group id on execution
const S_ISVTX = 0001000; // Directory restrcted delete
S_ISUID = 0004000; // Set user id on execution
S_ISGID = 0002000; // Set group id on execution
S_ISVTX = 0001000; // Directory restrcted delete
)
proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
proc S_ISREG (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; }
@@ -114,13 +116,12 @@ proc S_ISBLK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; }
proc S_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
const R_OK = 4; // Test for read permission
const W_OK = 2; // Test for write permission
const X_OK = 1; // Test for execute permission
const F_OK = 0; // Test for file existance
#foreign_system_library dl "dl";
#foreign_system_library libc "c";
const (
R_OK = 4; // Test for read permission
W_OK = 2; // Test for write permission
X_OK = 1; // Test for execute permission
F_OK = 0; // Test for file existance
)
proc _unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
proc _unix_close (fd: Handle) -> i32 #foreign libc "close";
@@ -187,10 +188,11 @@ proc file_size(fd: Handle) -> (i64, Errno) {
// NOTE(bill): Uses startup to initialize it
var stdin: Handle = 0;
var stdout: Handle = 1;
var stderr: Handle = 2;
var (
stdin: Handle = 0;
stdout: Handle = 1;
stderr: Handle = 2;
)
/* TODO(zangent): Implement these!
proc last_write_time(fd: Handle) -> FileTime {}
proc last_write_time_by_name(name: string) -> FileTime {}

View File

@@ -1,52 +1,54 @@
import win32 "sys/windows.odin";
type Handle int;
type FileTime u64;
type Errno int;
type (
Handle int;
FileTime u64;
Errno int;
)
const INVALID_HANDLE: Handle = -1;
const (
INVALID_HANDLE: Handle = -1;
O_RDONLY = 0x00000;
O_WRONLY = 0x00001;
O_RDWR = 0x00002;
O_CREAT = 0x00040;
O_EXCL = 0x00080;
O_NOCTTY = 0x00100;
O_TRUNC = 0x00200;
O_NONBLOCK = 0x00800;
O_APPEND = 0x00400;
O_SYNC = 0x01000;
O_ASYNC = 0x02000;
O_CLOEXEC = 0x80000;
const O_RDONLY = 0x00000;
const O_WRONLY = 0x00001;
const O_RDWR = 0x00002;
const O_CREAT = 0x00040;
const O_EXCL = 0x00080;
const O_NOCTTY = 0x00100;
const O_TRUNC = 0x00200;
const O_NONBLOCK = 0x00800;
const O_APPEND = 0x00400;
const O_SYNC = 0x01000;
const O_ASYNC = 0x02000;
const O_CLOEXEC = 0x80000;
const ERROR_NONE: Errno = 0;
const ERROR_FILE_NOT_FOUND: Errno = 2;
const ERROR_PATH_NOT_FOUND: Errno = 3;
const ERROR_ACCESS_DENIED: Errno = 5;
const ERROR_NO_MORE_FILES: Errno = 18;
const ERROR_HANDLE_EOF: Errno = 38;
const ERROR_NETNAME_DELETED: Errno = 64;
const ERROR_FILE_EXISTS: Errno = 80;
const ERROR_BROKEN_PIPE: Errno = 109;
const ERROR_BUFFER_OVERFLOW: Errno = 111;
const ERROR_INSUFFICIENT_BUFFER: Errno = 122;
const ERROR_MOD_NOT_FOUND: Errno = 126;
const ERROR_PROC_NOT_FOUND: Errno = 127;
const ERROR_DIR_NOT_EMPTY: Errno = 145;
const ERROR_ALREADY_EXISTS: Errno = 183;
const ERROR_ENVVAR_NOT_FOUND: Errno = 203;
const ERROR_MORE_DATA: Errno = 234;
const ERROR_OPERATION_ABORTED: Errno = 995;
const ERROR_IO_PENDING: Errno = 997;
const ERROR_NOT_FOUND: Errno = 1168;
const ERROR_PRIVILEGE_NOT_HELD: Errno = 1314;
const WSAEACCES: Errno = 10013;
const WSAECONNRESET: Errno = 10054;
// Windows reserves errors >= 1<<29 for application use
const ERROR_FILE_IS_PIPE: Errno = 1<<29 + 0;
ERROR_NONE: Errno = 0;
ERROR_FILE_NOT_FOUND: Errno = 2;
ERROR_PATH_NOT_FOUND: Errno = 3;
ERROR_ACCESS_DENIED: Errno = 5;
ERROR_NO_MORE_FILES: Errno = 18;
ERROR_HANDLE_EOF: Errno = 38;
ERROR_NETNAME_DELETED: Errno = 64;
ERROR_FILE_EXISTS: Errno = 80;
ERROR_BROKEN_PIPE: Errno = 109;
ERROR_BUFFER_OVERFLOW: Errno = 111;
ERROR_INSUFFICIENT_BUFFER: Errno = 122;
ERROR_MOD_NOT_FOUND: Errno = 126;
ERROR_PROC_NOT_FOUND: Errno = 127;
ERROR_DIR_NOT_EMPTY: Errno = 145;
ERROR_ALREADY_EXISTS: Errno = 183;
ERROR_ENVVAR_NOT_FOUND: Errno = 203;
ERROR_MORE_DATA: Errno = 234;
ERROR_OPERATION_ABORTED: Errno = 995;
ERROR_IO_PENDING: Errno = 997;
ERROR_NOT_FOUND: Errno = 1168;
ERROR_PRIVILEGE_NOT_HELD: Errno = 1314;
WSAEACCES: Errno = 10013;
WSAECONNRESET: Errno = 10054;
// Windows reserves errors >= 1<<29 for application use
ERROR_FILE_IS_PIPE: Errno = 1<<29 + 0;
)
// "Argv" arguments converted to Odin strings
let args = _alloc_command_line_arguments();

View File

@@ -1,43 +1,46 @@
#foreign_system_library dl "dl";
#foreign_system_library libc "c";
import "fmt.odin";
import "strings.odin";
type Handle i32;
type FileTime u64;
type Errno int;
type (
Handle i32;
FileTime u64;
Errno int;
// TODO(zangent): Find out how to make this work on x64 and x32.
type AddressSize i64;
AddressSize int;
)
// INVALID_HANDLE: Handle : -1;
const (
O_RDONLY = 0x00000;
O_WRONLY = 0x00001;
O_RDWR = 0x00002;
O_CREAT = 0x00040;
O_EXCL = 0x00080;
O_NOCTTY = 0x00100;
O_TRUNC = 0x00200;
O_NONBLOCK = 0x00800;
O_APPEND = 0x00400;
O_SYNC = 0x01000;
O_ASYNC = 0x02000;
O_CLOEXEC = 0x80000;
SEEK_SET = 0;
SEEK_CUR = 1;
SEEK_END = 2;
SEEK_DATA = 3;
SEEK_HOLE = 4;
SEEK_MAX = SEEK_HOLE;
const O_RDONLY = 0x00000;
const O_WRONLY = 0x00001;
const O_RDWR = 0x00002;
const O_CREAT = 0x00040;
const O_EXCL = 0x00080;
const O_NOCTTY = 0x00100;
const O_TRUNC = 0x00200;
const O_NONBLOCK = 0x00800;
const O_APPEND = 0x00400;
const O_SYNC = 0x01000;
const O_ASYNC = 0x02000;
const O_CLOEXEC = 0x80000;
const SEEK_SET = 0;
const SEEK_CUR = 1;
const SEEK_END = 2;
const SEEK_DATA = 3;
const SEEK_HOLE = 4;
const SEEK_MAX = SEEK_HOLE;
// NOTE(zangent): These are OS specific!
// Do not mix these up!
const RTLD_LAZY = 0x1;
const RTLD_NOW = 0x2;
const RTLD_LOCAL = 0x4;
const RTLD_GLOBAL = 0x8;
const RTLD_NODELETE = 0x80;
const RTLD_NOLOAD = 0x10;
const RTLD_FIRST = 0x100;
// NOTE(zangent): These are OS specific!
// Do not mix these up!
RTLD_LAZY = 0x1;
RTLD_NOW = 0x2;
RTLD_LOCAL = 0x4;
RTLD_GLOBAL = 0x8;
RTLD_NODELETE = 0x80;
RTLD_NOLOAD = 0x10;
RTLD_FIRST = 0x100;
)
var args: [dynamic]string;
@@ -71,41 +74,39 @@ type Stat struct #ordered {
};
// File type
const (
S_IFMT = 0170000; // Type of file mask
S_IFIFO = 0010000; // Named pipe (fifo)
S_IFCHR = 0020000; // Character special
S_IFDIR = 0040000; // Directory
S_IFBLK = 0060000; // Block special
S_IFREG = 0100000; // Regular
S_IFLNK = 0120000; // Symbolic link
S_IFSOCK = 0140000; // Socket
const S_IFMT = 0170000; // Type of file mask
const S_IFIFO = 0010000; // Named pipe (fifo)
const S_IFCHR = 0020000; // Character special
const S_IFDIR = 0040000; // Directory
const S_IFBLK = 0060000; // Block special
const S_IFREG = 0100000; // Regular
const S_IFLNK = 0120000; // Symbolic link
const S_IFSOCK = 0140000; // Socket
// File mode
// Read, write, execute/search by owner
S_IRWXU = 0000700; // RWX mask for owner
S_IRUSR = 0000400; // R for owner
S_IWUSR = 0000200; // W for owner
S_IXUSR = 0000100; // X for owner
// File mode
// Read, write, execute/search by owner
// Read, write, execute/search by group
S_IRWXG = 0000070; // RWX mask for group
S_IRGRP = 0000040; // R for group
S_IWGRP = 0000020; // W for group
S_IXGRP = 0000010; // X for group
const S_IRWXU = 0000700; // RWX mask for owner
const S_IRUSR = 0000400; // R for owner
const S_IWUSR = 0000200; // W for owner
const S_IXUSR = 0000100; // X for owner
// Read, write, execute/search by others
S_IRWXO = 0000007; // RWX mask for other
S_IROTH = 0000004; // R for other
S_IWOTH = 0000002; // W for other
S_IXOTH = 0000001; // X for other
// Read, write, execute/search by group
const S_IRWXG = 0000070; // RWX mask for group
const S_IRGRP = 0000040; // R for group
const S_IWGRP = 0000020; // W for group
const S_IXGRP = 0000010; // X for group
// Read, write, execute/search by others
const S_IRWXO = 0000007; // RWX mask for other
const S_IROTH = 0000004; // R for other
const S_IWOTH = 0000002; // W for other
const S_IXOTH = 0000001; // X for other
const S_ISUID = 0004000; // Set user id on execution
const S_ISGID = 0002000; // Set group id on execution
const S_ISVTX = 0001000; // Directory restrcted delete
S_ISUID = 0004000; // Set user id on execution
S_ISGID = 0002000; // Set group id on execution
S_ISVTX = 0001000; // Directory restrcted delete
)
proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
proc S_ISREG (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; }
@@ -115,13 +116,12 @@ proc S_ISBLK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; }
proc S_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
const R_OK = 4; // Test for read permission
const W_OK = 2; // Test for write permission
const X_OK = 1; // Test for execute permission
const F_OK = 0; // Test for file existance
#foreign_system_library dl "dl";
#foreign_system_library libc "c";
const (
R_OK = 4; // Test for read permission
W_OK = 2; // Test for write permission
X_OK = 1; // Test for execute permission
F_OK = 0; // Test for file existance
)
proc unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
proc unix_close (handle: Handle) #foreign libc "close";
@@ -206,10 +206,11 @@ proc file_size(fd: Handle) -> (i64, Errno) {
// NOTE(bill): Uses startup to initialize it
var stdin: Handle = 0; // get_std_handle(win32.STD_INPUT_HANDLE);
var stdout: Handle = 1; // get_std_handle(win32.STD_OUTPUT_HANDLE);
var stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_HANDLE);
var (
stdin: Handle = 0; // get_std_handle(win32.STD_INPUT_HANDLE);
stdout: Handle = 1; // get_std_handle(win32.STD_OUTPUT_HANDLE);
stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_HANDLE);
)
/* TODO(zangent): Implement these!
proc last_write_time(fd: Handle) -> FileTime {}
proc last_write_time_by_name(name: string) -> FileTime {}

View File

@@ -1,27 +1,29 @@
type Any struct #ordered {
data: rawptr,
type_info: ^TypeInfo,
};
type (
Any struct #ordered {
data: rawptr,
type_info: ^TypeInfo,
};
type String struct #ordered {
data: ^u8,
len: int,
};
String struct #ordered {
data: ^u8,
len: int,
};
type Slice struct #ordered {
data: rawptr,
len: int,
cap: int,
};
Slice struct #ordered {
data: rawptr,
len: int,
cap: int,
};
type DynamicArray struct #ordered {
data: rawptr,
len: int,
cap: int,
allocator: Allocator,
};
DynamicArray struct #ordered {
data: rawptr,
len: int,
cap: int,
allocator: Allocator,
};
type DynamicMap struct #ordered {
hashes: [dynamic]int,
entries: DynamicArray,
};
DynamicMap struct #ordered {
hashes: [dynamic]int,
entries: DynamicArray,
};
)

View File

@@ -1,2 +1,4 @@
import_load "sync_windows.odin" when ODIN_OS == "windows";
import_load "sync_linux.odin" when ODIN_OS == "linux";
import_load (
"sync_windows.odin" when ODIN_OS == "windows";
"sync_linux.odin" when ODIN_OS == "linux";
)

View File

@@ -1,5 +1,7 @@
import "atomics.odin";
import "os.odin";
import (
"atomics.odin";
"os.odin";
)
type Semaphore struct {
// _handle: win32.Handle,

View File

@@ -1,5 +1,7 @@
import win32 "sys/windows.odin" when ODIN_OS == "windows";
import "atomics.odin";
import (
win32 "sys/windows.odin" when ODIN_OS == "windows";
"atomics.odin";
)
type Semaphore struct {
_handle: win32.Handle,

View File

@@ -1,11 +1,12 @@
const REPLACEMENT_CHAR = '\uFFFD';
const MAX_RUNE = '\U0010FFFF';
const _surr1 = 0xd800;
const _surr2 = 0xdc00;
const _surr3 = 0xe000;
const _surr_self = 0x10000;
const (
REPLACEMENT_CHAR = '\uFFFD';
MAX_RUNE = '\U0010FFFF';
_surr1 = 0xd800;
_surr2 = 0xdc00;
_surr3 = 0xe000;
_surr_self = 0x10000;
)
proc is_surrogate(r: rune) -> bool {
return _surr1 <= r && r < _surr3;

View File

@@ -1,62 +1,66 @@
const RUNE_ERROR = '\ufffd';
const RUNE_SELF = 0x80;
const RUNE_BOM = 0xfeff;
const RUNE_EOF = ~rune(0);
const MAX_RUNE = '\U0010ffff';
const UTF_MAX = 4;
const (
RUNE_ERROR = '\ufffd';
RUNE_SELF = 0x80;
RUNE_BOM = 0xfeff;
RUNE_EOF = ~rune(0);
MAX_RUNE = '\U0010ffff';
UTF_MAX = 4;
const SURROGATE_MIN = 0xd800;
const SURROGATE_MAX = 0xdfff;
SURROGATE_MIN = 0xd800;
SURROGATE_MAX = 0xdfff;
const T1 = 0b0000_0000;
const TX = 0b1000_0000;
const T2 = 0b1100_0000;
const T3 = 0b1110_0000;
const T4 = 0b1111_0000;
const T5 = 0b1111_1000;
T1 = 0b0000_0000;
TX = 0b1000_0000;
T2 = 0b1100_0000;
T3 = 0b1110_0000;
T4 = 0b1111_0000;
T5 = 0b1111_1000;
const MASKX = 0b0011_1111;
const MASK2 = 0b0001_1111;
const MASK3 = 0b0000_1111;
const MASK4 = 0b0000_0111;
MASKX = 0b0011_1111;
MASK2 = 0b0001_1111;
MASK3 = 0b0000_1111;
MASK4 = 0b0000_0111;
const RUNE1_MAX = 1<<7 - 1;
const RUNE2_MAX = 1<<11 - 1;
const RUNE3_MAX = 1<<16 - 1;
RUNE1_MAX = 1<<7 - 1;
RUNE2_MAX = 1<<11 - 1;
RUNE3_MAX = 1<<16 - 1;
// The default lowest and highest continuation byte.
const LOCB = 0b1000_0000;
const HICB = 0b1011_1111;
// The default lowest and highest continuation byte.
LOCB = 0b1000_0000;
HICB = 0b1011_1111;
)
type AcceptRange struct { lo, hi: u8 }
let accept_ranges = [5]AcceptRange{
{0x80, 0xbf},
{0xa0, 0xbf},
{0x80, 0x9f},
{0x90, 0xbf},
{0x80, 0x8f},
};
let (
accept_ranges = [5]AcceptRange{
{0x80, 0xbf},
{0xa0, 0xbf},
{0x80, 0x9f},
{0x90, 0xbf},
{0x80, 0x8f},
};
let accept_sizes = [256]u8{
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x00-0x0f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x10-0x1f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x20-0x2f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x30-0x3f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x40-0x4f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x50-0x5f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x60-0x6f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x70-0x7f
accept_sizes = [256]u8{
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x00-0x0f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x10-0x1f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x20-0x2f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x30-0x3f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x40-0x4f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x50-0x5f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x60-0x6f
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x70-0x7f
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0x80-0x8f
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0x90-0x9f
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xa0-0xaf
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xb0-0xbf
0xf1, 0xf1, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 0xc0-0xcf
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 0xd0-0xdf
0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x23, 0x03, 0x03, // 0xe0-0xef
0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff
};
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0x80-0x8f
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0x90-0x9f
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xa0-0xaf
0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xb0-0xbf
0xf1, 0xf1, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 0xc0-0xcf
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, // 0xd0-0xdf
0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x23, 0x03, 0x03, // 0xe0-0xef
0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff
};
)
proc encode_rune(r: rune) -> ([4]u8, int) {
var buf: [4]u8;

View File

@@ -1535,121 +1535,126 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
check_stmt(c, pa->body, mod_flags);
case_end;
case_ast_node(vd, ValueDecl, node);
case_ast_node(gd, GenDecl, node);
GB_ASSERT(!c->context.scope->is_file);
if (vd->token.kind == Token_const) {
// NOTE(bill): Handled elsewhere
} else {
Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
isize entity_count = 0;
for_array(i, gd->specs) {
AstNode *spec = gd->specs[i];
switch (gd->token.kind) {
case Token_var:
case Token_let: {
ast_node(vd, ValueSpec, spec);
if (vd->flags & VarDeclFlag_thread_local) {
vd->flags &= ~VarDeclFlag_thread_local;
error_node(node, "`thread_local` may only be applied to a variable declaration");
}
Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
isize entity_count = 0;
for_array(i, vd->names) {
AstNode *name = vd->names[i];
Entity *entity = NULL;
if (name->kind != AstNode_Ident) {
error_node(name, "A variable declaration must be an identifier");
} else {
Token token = name->Ident;
String str = token.string;
Entity *found = NULL;
// NOTE(bill): Ignore assignments to `_`
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;
if (gd->flags & VarDeclFlag_thread_local) {
gd->flags &= ~VarDeclFlag_thread_local;
error_node(node, "`thread_local` may only be applied to a variable declaration");
}
for_array(i, vd->names) {
AstNode *name = vd->names[i];
Entity *entity = NULL;
if (name->kind != AstNode_Ident) {
error_node(name, "A variable declaration must be an identifier");
} 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;
Token token = name->Ident;
String str = token.string;
Entity *found = NULL;
// NOTE(bill): Ignore assignments to `_`
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, (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;
if (vd->type) {
init_type = check_type(c, vd->type, NULL);
if (init_type == NULL) {
init_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) {
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;
}
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));
e->flags |= EntityFlag_Visited;
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;
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 ((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;

View File

@@ -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_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) {
isize lhs = d->names.count;
isize rhs = d->values.count;
bool check_arity_match(Checker *c, AstNodeValueSpec *spec) {
isize lhs = spec->names.count;
isize rhs = spec->values.count;
if (rhs == 0) {
if (d->type == NULL) {
error_node(d->names[0], "Missing type or initial expression");
if (spec->type == NULL) {
error_node(spec->names[0], "Missing type or initial expression");
return false;
}
} else if (lhs < rhs) {
if (lhs < d->values.count) {
AstNode *n = d->values[lhs];
if (lhs < spec->values.count) {
AstNode *n = spec->values[lhs];
gbString str = expr_to_string(n);
error_node(n, "Extra initial expression `%s`", str);
gb_string_free(str);
} else {
error_node(d->names[0], "Extra initial expression");
error_node(spec->names[0], "Extra initial expression");
}
return false;
} else if (lhs > rhs && rhs != 1) {
AstNode *n = d->names[rhs];
AstNode *n = spec->names[rhs];
gbString str = expr_to_string(n);
error_node(n, "Missing expression for `%s`", 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_ast_node(vd, ValueDecl, decl);
if (vd->token.kind != Token_const) {
if (!c->context.scope->is_file) {
// NOTE(bill): local scope -> handle later and in order
break;
}
// 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];
if (vd->flags & VarDeclFlag_thread_local) {
error_node(decl, "#thread_local variable declarations cannot have initialization values");
case_ast_node(gd, GenDecl, decl);
for_array(i, gd->specs) {
AstNode *spec = gd->specs[i];
switch (gd->token.kind) {
case Token_var:
case Token_let: {
if (!c->context.scope->is_file) {
// NOTE(bill): local scope -> handle later and in order
break;
}
}
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) {
AstNode *name = vd->names[i];
AstNode *value = NULL;
if (i < vd->values.count) {
value = vd->values[i];
if (gd->flags & VarDeclFlag_thread_local) {
error_node(decl, "#thread_local variable declarations cannot have initialization values");
}
}
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) {
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, (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;
break;
}
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);
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);
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);
}
} 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;
@@ -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);
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);
if (!c->context.scope->is_file) {
if (fl->is_system) {
@@ -1882,7 +1899,7 @@ void check_import_entities(Checker *c, Map<Scope *> *file_scopes) {
for_array(i, c->delayed_imports) {
Scope *parent_scope = c->delayed_imports[i].parent;
AstNode *decl = c->delayed_imports[i].decl;
ast_node(id, ImportDecl, decl);
ast_node(id, ImportSpec, decl);
Token token = id->relpath;
GB_ASSERT(parent_scope->is_file);

View File

@@ -5793,7 +5793,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
case_ast_node(us, UsingStmt, node);
for_array(i, us->list) {
AstNode *decl = unparen_expr(us->list[i]);
if (decl->kind == AstNode_ValueDecl) {
if (decl->kind == AstNode_GenDecl) {
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);
case_end;
case_ast_node(vd, ValueDecl, node);
if (vd->token.kind != Token_const) {
irModule *m = proc->module;
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
case_ast_node(gd, GenDecl, node);
for_array(i, gd->specs) {
AstNode *spec = gd->specs[i];
switch (gd->token.kind) {
case Token_var:
case Token_let: {
ast_node(vd, ValueSpec, spec);
if (vd->values.count == 0) { // declared and zero-initialized
for_array(i, vd->names) {
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);
irModule *m = proc->module;
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
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);
if (vd->values.count == 0) { // declared and zero-initialized
for_array(i, vd->names) {
AstNode *name = vd->names[i];
if (!ir_is_blank_ident(name)) {
ir_add_local_for_identifier(proc, name, true);
}
} 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) {
ir_addr_store(proc, lvals[i], inits[i]);
case Token_type: {
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;
@@ -5936,28 +5968,6 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
}
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);
ir_emit_comment(proc, str_lit("AssignStmt"));

View File

@@ -297,13 +297,6 @@ AST_NODE_KIND(_ComplexStmtEnd, "", i32) \
AST_NODE_KIND(_StmtEnd, "", i32) \
AST_NODE_KIND(_DeclBegin, "", i32) \
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 { \
Token token; \
AstNode *name; \
@@ -314,20 +307,6 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
String foreign_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 { \
Token token, filepath; \
Token library_name; \
@@ -339,6 +318,29 @@ AST_NODE_KIND(_DeclBegin, "", i32) \
Token token; \
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(Field, "field", struct { \
Array<AstNode *> names; \
@@ -540,12 +542,15 @@ Token ast_node_token(AstNode *node) {
case AstNode_PushContext: return node->PushContext.token;
case AstNode_BadDecl: return node->BadDecl.begin;
case AstNode_ValueDecl: return node->ValueDecl.token;
case AstNode_ProcDecl: return node->ProcDecl.token;
case AstNode_ImportDecl: return node->ImportDecl.token;
case AstNode_ForeignLibrary: return node->ForeignLibrary.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:
if (node->Field.names.count > 0) {
@@ -761,15 +766,6 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) {
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:
n->ForeignLibrary.cond = clone_ast_node(a, n->ForeignLibrary.cond);
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,
u64 tags, AstNode *foreign_library, String foreign_name, String link_name) {
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;
}
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 *result = make_ast_node(f, AstNode_ForeignLibrary);
result->ForeignLibrary.token = token;
@@ -1487,6 +1455,41 @@ AstNode *ast_label_decl(AstFile *f, Token token, AstNode *name) {
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) {
Token prev = f->curr_token;
@@ -1688,18 +1691,9 @@ bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) {
return s->ProcLit.body != NULL;
case AstNode_ProcDecl:
return s->ProcDecl.body != NULL;
case AstNode_TypeDecl:
return is_semicolon_optional_for_node(f, s->TypeDecl.type);
case AstNode_ValueDecl:
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;
case AstNode_TypeSpec:
return is_semicolon_optional_for_node(f, s->TypeSpec.type);
}
return false;
@@ -2526,61 +2520,6 @@ AstNode *parse_type(AstFile *f) {
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) {
TokenKind look_ahead = look_ahead_token_kind(f, 1);
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);
}
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 *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_const:
case Token_let:
next_token(f);
return parse_value_decl(f, token);
return parse_decl(f);
}
Array<AstNode *> lhs = parse_lhs_expr_list(f);
@@ -3723,20 +3829,11 @@ AstNode *parse_stmt(AstFile *f) {
case Token_var:
case Token_const:
case Token_let:
s = parse_simple_stmt(f, StmtAllowFlag_None);
expect_semicolon(f, s);
return s;
case Token_proc:
s = parse_proc_decl(f);
expect_semicolon(f, s);
return s;
case Token_type:
s = parse_type_decl(f);
expect_semicolon(f, s);
return s;
case Token_import:
case Token_import_load:
return parse_decl(f);
case Token_if: return parse_if_stmt(f);
case Token_when: return parse_when_stmt(f);
@@ -3767,8 +3864,7 @@ AstNode *parse_stmt(AstFile *f) {
AstNode *decl = NULL;
if (f->curr_token.kind == Token_var ||
f->curr_token.kind == Token_let) {
Token var = f->curr_token; next_token(f);
decl = parse_value_decl(f, var);
decl = parse_decl(f);
expect_semicolon(f, decl);
} else {
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 1
if (decl->ValueDecl.token.kind == Token_const) {
syntax_error(token, "`using` may not be applied to constant declarations");
if (decl != NULL && decl->kind == AstNode_GenDecl) {
if (decl->GenDecl.token.kind != Token_var &&
decl->GenDecl.token.kind != Token_let) {
syntax_error(token, "`using` may only be applied to variable declarations");
return decl;
}
if (f->curr_proc == NULL) {
syntax_error(token, "`using` is not allowed at the file scope");
} else {
decl->ValueDecl.flags |= VarDeclFlag_using;
decl->GenDecl.flags |= VarDeclFlag_using;
}
#else
decl->ValueDecl.flags |= VarDeclFlag_using;
#endif
return decl;
}
@@ -3846,6 +3939,7 @@ AstNode *parse_stmt(AstFile *f) {
return ast_push_context(f, token, expr, body);
} break;
#if 0
case Token_import: {
Token token = expect_token(f, Token_import);
AstNode *cond = NULL;
@@ -3907,6 +4001,7 @@ AstNode *parse_stmt(AstFile *f) {
expect_semicolon(f, decl);
return decl;
}
#endif
case Token_Hash: {
AstNode *s = NULL;
@@ -3989,14 +4084,15 @@ AstNode *parse_stmt(AstFile *f) {
} else if (tag == "thread_local") {
AstNode *s = parse_stmt(f);
if (s->kind == AstNode_ValueDecl) {
if (s->ValueDecl.token.kind == Token_const) {
syntax_error(token, "`thread_local` may not be applied to constant declarations");
if (s->kind == AstNode_GenDecl) {
if (s->GenDecl.token.kind != Token_var &&
s->GenDecl.token.kind != Token_let) {
syntax_error(token, "`thread_local` may only be applied to variable declarations");
}
if (f->curr_proc != NULL) {
syntax_error(token, "`thread_local` is only allowed at the file scope");
} else {
s->ValueDecl.flags |= VarDeclFlag_thread_local;
s->GenDecl.flags |= VarDeclFlag_thread_local;
}
return s;
}
@@ -4219,87 +4315,94 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod
node->kind != AstNode_EmptyStmt) {
// NOTE(bill): Sanity check
syntax_error_node(node, "Only declarations are allowed at file scope %.*s", LIT(ast_node_strings[node->kind]));
} else if (node->kind == AstNode_ImportDecl) {
ast_node(id, ImportDecl, node);
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 = {};
} else if (node->kind == AstNode_GenDecl) {
ast_node(gd, GenDecl, node);
if (gd->token.kind == Token_import ||
gd->token.kind == Token_import_load) {
for_array(spec_index, gd->specs) {
AstNode *spec = gd->specs[spec_index];
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
isize colon_pos = -1;
for (isize j = 0; j < file_str.len; j++) {
if (file_str[j] == ':') {
colon_pos = j;
break;
}
}
if (colon_pos > 0) {
collection_name = make_string(file_str.text, colon_pos);
file_str.text += colon_pos+1;
file_str.len -= colon_pos+1;
}
#if 0
isize colon_pos = -1;
for (isize j = 0; j < file_str.len; j++) {
if (file_str[j] == ':') {
colon_pos = j;
break;
}
}
if (colon_pos > 0) {
collection_name = make_string(file_str.text, colon_pos);
file_str.text += colon_pos+1;
file_str.len -= colon_pos+1;
}
if (collection_name.len == 0) {
syntax_error_node(node, "Missing import collection for path: `%.*s`", LIT(oirignal_string));
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
continue;
}
if (collection_name.len == 0) {
syntax_error_node(node, "Missing import collection for path: `%.*s`", LIT(oirignal_string));
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
continue;
}
if (collection_name == "core") {
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
import_file = abs_path;
}
} else if (collection_name == "local") {
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 (collection_name == "core") {
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
import_file = abs_path;
}
} else if (collection_name == "local") {
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
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;
}
} else {
syntax_error_node(node, "Unknown import collection: `%.*s`", LIT(collection_name));
decls[i] = ast_bad_decl(f, id->relpath, id->relpath);
continue;
}
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
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;
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;
id->fullpath = import_file;
try_add_import_path(p, import_file, file_str, ast_node_token(node).pos);
}
}
#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) {
AstNodeForeignLibrary *fl = &node->ForeignLibrary;
String file_str = fl->filepath.string;

View File

@@ -1948,7 +1948,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) {
case_ast_node(us, UsingStmt, node);
for_array(i, us->list) {
AstNode *decl = unparen_expr(us->list[i]);
if (decl->kind == AstNode_ValueDecl) {
if (decl->kind == AstNode_GenDecl) {
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);
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);
ssa_emit_comment(p, str_lit("AssignStmt"));