mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Prefix type and let to replace immutable
This commit is contained in:
+14
-14
@@ -24,19 +24,19 @@
|
|||||||
|
|
||||||
// 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
|
||||||
const TypeInfoEnumValue = raw_union {
|
type TypeInfoEnumValue raw_union {
|
||||||
f: f64,
|
f: f64,
|
||||||
i: i128,
|
i: i128,
|
||||||
}
|
}
|
||||||
// NOTE(bill): This must match the compiler's
|
// NOTE(bill): This must match the compiler's
|
||||||
const CallingConvention = enum {
|
type CallingConvention enum {
|
||||||
Odin = 0,
|
Odin = 0,
|
||||||
C = 1,
|
C = 1,
|
||||||
Std = 2,
|
Std = 2,
|
||||||
Fast = 3,
|
Fast = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeInfoRecord = struct #ordered {
|
type 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
|
||||||
@@ -46,7 +46,7 @@ const TypeInfoRecord = struct #ordered {
|
|||||||
custom_align: bool,
|
custom_align: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeInfo = union {
|
type TypeInfo union {
|
||||||
size: int,
|
size: int,
|
||||||
align: int,
|
align: int,
|
||||||
|
|
||||||
@@ -151,22 +151,22 @@ 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)
|
||||||
const AllocatorMode = enum u8 {
|
type AllocatorMode enum u8 {
|
||||||
Alloc,
|
Alloc,
|
||||||
Free,
|
Free,
|
||||||
FreeAll,
|
FreeAll,
|
||||||
Resize,
|
Resize,
|
||||||
}
|
}
|
||||||
const AllocatorProc = type proc(allocator_data: rawptr, mode: AllocatorMode,
|
type AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode,
|
||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
|
old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
|
||||||
const Allocator = struct #ordered {
|
type Allocator struct #ordered {
|
||||||
procedure: AllocatorProc,
|
procedure: AllocatorProc,
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Context = struct #ordered {
|
type Context struct #ordered {
|
||||||
thread_id: int,
|
thread_id: int,
|
||||||
|
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
@@ -553,18 +553,18 @@ proc __default_hash_string(s: string) -> u128 {
|
|||||||
|
|
||||||
const __INITIAL_MAP_CAP = 16;
|
const __INITIAL_MAP_CAP = 16;
|
||||||
|
|
||||||
const __MapKey = struct #ordered {
|
type __MapKey struct #ordered {
|
||||||
hash: u128,
|
hash: u128,
|
||||||
str: string,
|
str: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
const __MapFindResult = struct #ordered {
|
type __MapFindResult struct #ordered {
|
||||||
hash_index: int,
|
hash_index: int,
|
||||||
entry_prev: int,
|
entry_prev: int,
|
||||||
entry_index: int,
|
entry_index: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
const __MapEntryHeader = struct #ordered {
|
type __MapEntryHeader struct #ordered {
|
||||||
key: __MapKey,
|
key: __MapKey,
|
||||||
next: int,
|
next: int,
|
||||||
/*
|
/*
|
||||||
@@ -572,7 +572,7 @@ const __MapEntryHeader = struct #ordered {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
const __MapHeader = struct #ordered {
|
type __MapHeader struct #ordered {
|
||||||
m: ^raw.DynamicMap,
|
m: ^raw.DynamicMap,
|
||||||
is_key_string: bool,
|
is_key_string: bool,
|
||||||
entry_size: int,
|
entry_size: int,
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
// Multiple precision decimal numbers
|
// Multiple precision decimal numbers
|
||||||
// NOTE: This is only for floating point printing and nothing else
|
// NOTE: This is only for floating point printing and nothing else
|
||||||
|
|
||||||
const Decimal = struct {
|
type Decimal struct {
|
||||||
digits: [384]u8, // big-endian digits
|
digits: [384]u8, // big-endian digits
|
||||||
count: int,
|
count: int,
|
||||||
decimal_point: int,
|
decimal_point: int,
|
||||||
|
|||||||
+4
-4
@@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
const _BUFFER_SIZE = 1<<12;
|
const _BUFFER_SIZE = 1<<12;
|
||||||
|
|
||||||
const StringBuffer = union {
|
type StringBuffer union {
|
||||||
Static {buf: []u8},
|
Static {buf: []u8},
|
||||||
Dynamic{buf: [dynamic]u8},
|
Dynamic{buf: [dynamic]u8},
|
||||||
}
|
}
|
||||||
|
|
||||||
const FmtInfo = struct {
|
type FmtInfo struct {
|
||||||
minus: bool,
|
minus: bool,
|
||||||
plus: bool,
|
plus: bool,
|
||||||
space: bool,
|
space: bool,
|
||||||
@@ -582,8 +582,8 @@ proc _fmt_int(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: int,
|
|||||||
_pad(fi, s);
|
_pad(fi, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
immutable var __DIGITS_LOWER = "0123456789abcdefx";
|
let __DIGITS_LOWER = "0123456789abcdefx";
|
||||||
immutable var __DIGITS_UPPER = "0123456789ABCDEFX";
|
let __DIGITS_UPPER = "0123456789ABCDEFX";
|
||||||
|
|
||||||
proc fmt_rune(fi: ^FmtInfo, r: rune, verb: rune) {
|
proc fmt_rune(fi: ^FmtInfo, r: rune, verb: rune) {
|
||||||
match verb {
|
match verb {
|
||||||
|
|||||||
+7
-7
@@ -16,16 +16,16 @@ const EPSILON = 1.19209290e-7;
|
|||||||
const τ = TAU;
|
const τ = TAU;
|
||||||
const π = PI;
|
const π = PI;
|
||||||
|
|
||||||
const Vec2 = [vector 2]f32;
|
type Vec2 [vector 2]f32;
|
||||||
const Vec3 = [vector 3]f32;
|
type Vec3 [vector 3]f32;
|
||||||
const Vec4 = [vector 4]f32;
|
type Vec4 [vector 4]f32;
|
||||||
|
|
||||||
// Column major
|
// Column major
|
||||||
const Mat2 = [2][2]f32;
|
type Mat2 [2][2]f32;
|
||||||
const Mat3 = [3][3]f32;
|
type Mat3 [3][3]f32;
|
||||||
const Mat4 = [4][4]f32;
|
type Mat4 [4][4]f32;
|
||||||
|
|
||||||
const Complex = complex64;
|
type 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";
|
||||||
|
|||||||
+3
-3
@@ -50,7 +50,7 @@ proc align_forward(ptr: rawptr, align: int) -> rawptr {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const AllocationHeader = struct {
|
type AllocationHeader struct {
|
||||||
size: int,
|
size: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,14 +78,14 @@ proc allocation_header(data: rawptr) -> ^AllocationHeader {
|
|||||||
|
|
||||||
|
|
||||||
// Custom allocators
|
// Custom allocators
|
||||||
const Arena = struct {
|
type Arena struct {
|
||||||
backing: Allocator,
|
backing: Allocator,
|
||||||
offset: int,
|
offset: int,
|
||||||
memory: []u8,
|
memory: []u8,
|
||||||
temp_count: int,
|
temp_count: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ArenaTempMemory = struct {
|
type ArenaTempMemory struct {
|
||||||
arena: ^Arena,
|
arena: ^Arena,
|
||||||
original_count: int,
|
original_count: int,
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -1,9 +1,9 @@
|
|||||||
// #import "fmt.odin";
|
// #import "fmt.odin";
|
||||||
#import "strings.odin";
|
#import "strings.odin";
|
||||||
|
|
||||||
const Handle = i32;
|
type Handle i32;
|
||||||
const FileTime = u64;
|
type FileTime u64;
|
||||||
const Errno = i32;
|
type Errno i32;
|
||||||
|
|
||||||
// INVALID_HANDLE: Handle : -1;
|
// INVALID_HANDLE: Handle : -1;
|
||||||
|
|
||||||
@@ -34,9 +34,9 @@ const RTLD_BINDING_MASK = 0x3;
|
|||||||
const RTLD_GLOBAL = 0x100;
|
const RTLD_GLOBAL = 0x100;
|
||||||
|
|
||||||
// "Argv" arguments converted to Odin strings
|
// "Argv" arguments converted to Odin strings
|
||||||
immutable var args = _alloc_command_line_arguments();
|
let args = _alloc_command_line_arguments();
|
||||||
|
|
||||||
const _FileTime = struct #ordered {
|
type _FileTime struct #ordered {
|
||||||
seconds: i64,
|
seconds: i64,
|
||||||
nanoseconds: i32,
|
nanoseconds: i32,
|
||||||
reserved: i32,
|
reserved: i32,
|
||||||
@@ -46,7 +46,7 @@ const _FileTime = struct #ordered {
|
|||||||
// https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/jb-dev/sysroot/usr/include/bits/stat.h
|
// https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/jb-dev/sysroot/usr/include/bits/stat.h
|
||||||
// Validity is not guaranteed.
|
// Validity is not guaranteed.
|
||||||
|
|
||||||
const Stat = struct #ordered {
|
type Stat struct #ordered {
|
||||||
device_id: u64, // ID of device containing file
|
device_id: u64, // ID of device containing file
|
||||||
serial: u64, // File serial number
|
serial: u64, // File serial number
|
||||||
nlink: u32, // Number of hard links
|
nlink: u32, // Number of hard links
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#import win32 "sys/windows.odin";
|
#import win32 "sys/windows.odin";
|
||||||
|
|
||||||
const Handle = int;
|
type Handle int;
|
||||||
const FileTime = u64;
|
type FileTime u64;
|
||||||
const Errno = int;
|
type Errno int;
|
||||||
|
|
||||||
const INVALID_HANDLE: Handle = -1;
|
const INVALID_HANDLE: Handle = -1;
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ const ERROR_FILE_IS_PIPE: Errno = 1<<29 + 0;
|
|||||||
|
|
||||||
|
|
||||||
// "Argv" arguments converted to Odin strings
|
// "Argv" arguments converted to Odin strings
|
||||||
immutable var args = _alloc_command_line_arguments();
|
let args = _alloc_command_line_arguments();
|
||||||
|
|
||||||
|
|
||||||
proc open(path: string, mode: int, perm: u32) -> (Handle, Errno) {
|
proc open(path: string, mode: int, perm: u32) -> (Handle, Errno) {
|
||||||
|
|||||||
+6
-6
@@ -1,12 +1,12 @@
|
|||||||
#import "fmt.odin";
|
#import "fmt.odin";
|
||||||
#import "strings.odin";
|
#import "strings.odin";
|
||||||
|
|
||||||
const Handle = i32;
|
type Handle i32;
|
||||||
const FileTime = u64;
|
type FileTime u64;
|
||||||
const Errno = int;
|
type Errno int;
|
||||||
|
|
||||||
// TODO(zangent): Find out how to make this work on x64 and x32.
|
// TODO(zangent): Find out how to make this work on x64 and x32.
|
||||||
const AddressSize = i64;
|
type AddressSize i64;
|
||||||
|
|
||||||
// INVALID_HANDLE: Handle : -1;
|
// INVALID_HANDLE: Handle : -1;
|
||||||
|
|
||||||
@@ -41,12 +41,12 @@ const RTLD_FIRST = 0x100;
|
|||||||
|
|
||||||
var args: [dynamic]string;
|
var args: [dynamic]string;
|
||||||
|
|
||||||
const _FileTime = struct #ordered {
|
type _FileTime struct #ordered {
|
||||||
seconds: i64,
|
seconds: i64,
|
||||||
nanoseconds: i64
|
nanoseconds: i64
|
||||||
}
|
}
|
||||||
|
|
||||||
const Stat = struct #ordered {
|
type Stat struct #ordered {
|
||||||
device_id : i32, // ID of device containing file
|
device_id : i32, // ID of device containing file
|
||||||
mode : u16, // Mode of the file
|
mode : u16, // Mode of the file
|
||||||
nlink : u16, // Number of hard links
|
nlink : u16, // Number of hard links
|
||||||
|
|||||||
+6
-6
@@ -1,27 +1,27 @@
|
|||||||
const Any = struct #ordered {
|
type Any struct #ordered {
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
type_info: ^TypeInfo,
|
type_info: ^TypeInfo,
|
||||||
}
|
};
|
||||||
|
|
||||||
const String = struct #ordered {
|
type String struct #ordered {
|
||||||
data: ^u8,
|
data: ^u8,
|
||||||
len: int,
|
len: int,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Slice = struct #ordered {
|
type Slice struct #ordered {
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
len: int,
|
len: int,
|
||||||
cap: int,
|
cap: int,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DynamicArray = struct #ordered {
|
type DynamicArray struct #ordered {
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
len: int,
|
len: int,
|
||||||
cap: int,
|
cap: int,
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DynamicMap = struct #ordered {
|
type DynamicMap struct #ordered {
|
||||||
hashes: [dynamic]int,
|
hashes: [dynamic]int,
|
||||||
entries: DynamicArray,
|
entries: DynamicArray,
|
||||||
};
|
};
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
#import . "decimal.odin";
|
#import . "decimal.odin";
|
||||||
|
|
||||||
const IntFlag = enum {
|
type IntFlag enum {
|
||||||
Prefix = 1<<0,
|
Prefix = 1<<0,
|
||||||
Plus = 1<<1,
|
Plus = 1<<1,
|
||||||
Space = 1<<2,
|
Space = 1<<2,
|
||||||
@@ -210,14 +210,14 @@ proc append_float(buf: []u8, f: f64, fmt: u8, prec, bit_size: int) -> string {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const DecimalSlice = struct {
|
type DecimalSlice struct {
|
||||||
digits: []u8,
|
digits: []u8,
|
||||||
count: int,
|
count: int,
|
||||||
decimal_point: int,
|
decimal_point: int,
|
||||||
neg: bool,
|
neg: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Float_Info = struct {
|
type Float_Info struct {
|
||||||
mantbits: uint,
|
mantbits: uint,
|
||||||
expbits: uint,
|
expbits: uint,
|
||||||
bias: int,
|
bias: int,
|
||||||
@@ -415,7 +415,7 @@ proc round_shortest(d: ^Decimal, mant: u64, exp: int, flt: ^Float_Info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MAX_BASE = 32;
|
const MAX_BASE = 32;
|
||||||
immutable var digits = "0123456789abcdefghijklmnopqrstuvwxyz";
|
let digits = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
|
||||||
proc is_integer_negative(u: u128, is_signed: bool, bit_size: int) -> (unsigned: u128, neg: bool) {
|
proc is_integer_negative(u: u128, is_signed: bool, bit_size: int) -> (unsigned: u128, neg: bool) {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#import "atomics.odin";
|
#import "atomics.odin";
|
||||||
#import "os.odin";
|
#import "os.odin";
|
||||||
|
|
||||||
const Semaphore = struct {
|
type Semaphore struct {
|
||||||
// _handle: win32.Handle,
|
// _handle: win32.Handle,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Mutex = struct {
|
type Mutex struct {
|
||||||
_semaphore: Semaphore,
|
_semaphore: Semaphore,
|
||||||
_counter: i32,
|
_counter: i32,
|
||||||
_owner: i32,
|
_owner: i32,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
#import win32 "sys/windows.odin" when ODIN_OS == "windows";
|
||||||
#import "atomics.odin";
|
#import "atomics.odin";
|
||||||
|
|
||||||
const Semaphore = struct {
|
type Semaphore struct {
|
||||||
_handle: win32.Handle,
|
_handle: win32.Handle,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Mutex = struct {
|
type Mutex struct {
|
||||||
_semaphore: Semaphore,
|
_semaphore: Semaphore,
|
||||||
_counter: i32,
|
_counter: i32,
|
||||||
_owner: i32,
|
_owner: i32,
|
||||||
|
|||||||
+9
-9
@@ -9,10 +9,10 @@ const CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002;
|
|||||||
const CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001;
|
const CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001;
|
||||||
const CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002;
|
const CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002;
|
||||||
|
|
||||||
const Hglrc = Handle;
|
type Hglrc Handle;
|
||||||
const ColorRef = u32;
|
type ColorRef u32;
|
||||||
|
|
||||||
const LayerPlaneDescriptor = struct {
|
type LayerPlaneDescriptor struct {
|
||||||
size: u16,
|
size: u16,
|
||||||
version: u16,
|
version: u16,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
@@ -39,11 +39,11 @@ const LayerPlaneDescriptor = struct {
|
|||||||
transparent: ColorRef,
|
transparent: ColorRef,
|
||||||
}
|
}
|
||||||
|
|
||||||
const PointFloat = struct {
|
type PointFloat struct {
|
||||||
x, y: f32,
|
x, y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Glyph_MetricsFloat = struct {
|
type Glyph_MetricsFloat struct {
|
||||||
black_box_x: f32,
|
black_box_x: f32,
|
||||||
black_box_y: f32,
|
black_box_y: f32,
|
||||||
glyph_origin: PointFloat,
|
glyph_origin: PointFloat,
|
||||||
@@ -51,10 +51,10 @@ const Glyph_MetricsFloat = struct {
|
|||||||
cell_inc_y: f32,
|
cell_inc_y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const CreateContextAttribsARBType = type proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc;
|
type CreateContextAttribsARBType proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc;
|
||||||
const ChoosePixelFormatARBType = type proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c;
|
type ChoosePixelFormatARBType proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c;
|
||||||
const SwapIntervalEXTType = type proc(interval: i32) -> bool #cc_c;
|
type SwapIntervalEXTType proc(interval: i32) -> bool #cc_c;
|
||||||
const GetExtensionsStringARBType = type proc(Hdc) -> ^u8 #cc_c;
|
type GetExtensionsStringARBType proc(Hdc) -> ^u8 #cc_c;
|
||||||
|
|
||||||
|
|
||||||
var create_context_attribs_arb: CreateContextAttribsARBType;
|
var create_context_attribs_arb: CreateContextAttribsARBType;
|
||||||
|
|||||||
+35
-35
@@ -4,21 +4,21 @@
|
|||||||
#foreign_system_library "winmm.lib" when ODIN_OS == "windows";
|
#foreign_system_library "winmm.lib" when ODIN_OS == "windows";
|
||||||
#foreign_system_library "shell32.lib" when ODIN_OS == "windows";
|
#foreign_system_library "shell32.lib" when ODIN_OS == "windows";
|
||||||
|
|
||||||
const Handle = rawptr;
|
type Handle rawptr;
|
||||||
const Hwnd = Handle;
|
type Hwnd Handle;
|
||||||
const Hdc = Handle;
|
type Hdc Handle;
|
||||||
const Hinstance = Handle;
|
type Hinstance Handle;
|
||||||
const Hicon = Handle;
|
type Hicon Handle;
|
||||||
const Hcursor = Handle;
|
type Hcursor Handle;
|
||||||
const Hmenu = Handle;
|
type Hmenu Handle;
|
||||||
const Hbrush = Handle;
|
type Hbrush Handle;
|
||||||
const Hgdiobj = Handle;
|
type Hgdiobj Handle;
|
||||||
const Hmodule = Handle;
|
type Hmodule Handle;
|
||||||
const Wparam = uint;
|
type Wparam uint;
|
||||||
const Lparam = int;
|
type Lparam int;
|
||||||
const Lresult = int;
|
type Lresult int;
|
||||||
const Bool = i32;
|
type Bool i32;
|
||||||
const WndProc = type proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c;
|
type WndProc proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c;
|
||||||
|
|
||||||
|
|
||||||
const INVALID_HANDLE = Handle(~int(0));
|
const INVALID_HANDLE = Handle(~int(0));
|
||||||
@@ -86,11 +86,11 @@ const SM_CYSCREEN = 1;
|
|||||||
const SW_SHOW = 5;
|
const SW_SHOW = 5;
|
||||||
|
|
||||||
|
|
||||||
const Point = struct #ordered {
|
type Point struct #ordered {
|
||||||
x, y: i32,
|
x, y: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const WndClassExA = struct #ordered {
|
type WndClassExA struct #ordered {
|
||||||
size, style: u32,
|
size, style: u32,
|
||||||
wnd_proc: WndProc,
|
wnd_proc: WndProc,
|
||||||
cls_extra, wnd_extra: i32,
|
cls_extra, wnd_extra: i32,
|
||||||
@@ -102,7 +102,7 @@ const WndClassExA = struct #ordered {
|
|||||||
sm: Hicon,
|
sm: Hicon,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Msg = struct #ordered {
|
type Msg struct #ordered {
|
||||||
hwnd: Hwnd,
|
hwnd: Hwnd,
|
||||||
message: u32,
|
message: u32,
|
||||||
wparam: Wparam,
|
wparam: Wparam,
|
||||||
@@ -111,24 +111,24 @@ const Msg = struct #ordered {
|
|||||||
pt: Point,
|
pt: Point,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Rect = struct #ordered {
|
type Rect struct #ordered {
|
||||||
left: i32,
|
left: i32,
|
||||||
top: i32,
|
top: i32,
|
||||||
right: i32,
|
right: i32,
|
||||||
bottom: i32,
|
bottom: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Filetime = struct #ordered {
|
type Filetime struct #ordered {
|
||||||
lo, hi: u32,
|
lo, hi: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Systemtime = struct #ordered {
|
type Systemtime struct #ordered {
|
||||||
year, month: u16,
|
year, month: u16,
|
||||||
day_of_week, day: u16,
|
day_of_week, day: u16,
|
||||||
hour, minute, second, millisecond: u16,
|
hour, minute, second, millisecond: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ByHandleFileInformation = struct #ordered {
|
type ByHandleFileInformation struct #ordered {
|
||||||
file_attributes: u32,
|
file_attributes: u32,
|
||||||
creation_time,
|
creation_time,
|
||||||
last_access_time,
|
last_access_time,
|
||||||
@@ -141,7 +141,7 @@ const ByHandleFileInformation = struct #ordered {
|
|||||||
file_index_low: u32,
|
file_index_low: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const FileAttributeData = struct #ordered {
|
type FileAttributeData struct #ordered {
|
||||||
file_attributes: u32,
|
file_attributes: u32,
|
||||||
creation_time,
|
creation_time,
|
||||||
last_access_time,
|
last_access_time,
|
||||||
@@ -150,7 +150,7 @@ const FileAttributeData = struct #ordered {
|
|||||||
file_size_low: u32,
|
file_size_low: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const FindData = struct #ordered {
|
type FindData struct #ordered {
|
||||||
file_attributes : u32,
|
file_attributes : u32,
|
||||||
creation_time : Filetime,
|
creation_time : Filetime,
|
||||||
last_access_time : Filetime,
|
last_access_time : Filetime,
|
||||||
@@ -164,7 +164,7 @@ const FindData = struct #ordered {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const GET_FILEEX_INFO_LEVELS = i32;
|
type GET_FILEEX_INFO_LEVELS i32;
|
||||||
|
|
||||||
const GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS = 0;
|
const GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS = 0;
|
||||||
const GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS = 1;
|
const GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS = 1;
|
||||||
@@ -323,7 +323,7 @@ const HEAP_ZERO_MEMORY = 0x00000008;
|
|||||||
|
|
||||||
// Synchronization
|
// Synchronization
|
||||||
|
|
||||||
const Security_Attributes = struct #ordered {
|
type Security_Attributes struct #ordered {
|
||||||
length: u32,
|
length: u32,
|
||||||
security_descriptor: rawptr,
|
security_descriptor: rawptr,
|
||||||
inherit_handle: Bool,
|
inherit_handle: Bool,
|
||||||
@@ -357,7 +357,7 @@ proc read_barrier () #foreign kernel32 "ReadBarrier";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Hmonitor = Handle;
|
type Hmonitor Handle;
|
||||||
|
|
||||||
const GWL_STYLE = -16;
|
const GWL_STYLE = -16;
|
||||||
|
|
||||||
@@ -374,14 +374,14 @@ const SWP_NOSIZE = 0x0001;
|
|||||||
const SWP_NOMOVE = 0x0002;
|
const SWP_NOMOVE = 0x0002;
|
||||||
|
|
||||||
|
|
||||||
const MonitorInfo = struct #ordered {
|
type MonitorInfo struct #ordered {
|
||||||
size: u32,
|
size: u32,
|
||||||
monitor: Rect,
|
monitor: Rect,
|
||||||
work: Rect,
|
work: Rect,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const WindowPlacement = struct #ordered {
|
type WindowPlacement struct #ordered {
|
||||||
length: u32,
|
length: u32,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
show_cmd: u32,
|
show_cmd: u32,
|
||||||
@@ -418,7 +418,7 @@ proc LOWORD(lParam: Lparam) -> u16 { return u16(lParam); }
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const BitmapInfoHeader = struct #ordered {
|
type BitmapInfoHeader struct #ordered {
|
||||||
size: u32,
|
size: u32,
|
||||||
width, height: i32,
|
width, height: i32,
|
||||||
planes, bit_count: i16,
|
planes, bit_count: i16,
|
||||||
@@ -429,13 +429,13 @@ const BitmapInfoHeader = struct #ordered {
|
|||||||
clr_used: u32,
|
clr_used: u32,
|
||||||
clr_important: u32,
|
clr_important: u32,
|
||||||
}
|
}
|
||||||
const BitmapInfo = struct #ordered {
|
type BitmapInfo struct #ordered {
|
||||||
using header: BitmapInfoHeader,
|
using header: BitmapInfoHeader,
|
||||||
colors: [1]RgbQuad,
|
colors: [1]RgbQuad,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const RgbQuad = struct #ordered { blue, green, red, reserved: u8 }
|
type RgbQuad struct #ordered { blue, green, red, reserved: u8 }
|
||||||
|
|
||||||
const BI_RGB = 0;
|
const BI_RGB = 0;
|
||||||
const DIB_RGB_COLORS = 0x00;
|
const DIB_RGB_COLORS = 0x00;
|
||||||
@@ -481,7 +481,7 @@ const PFD_DOUBLEBUFFER_DONTCARE = 0x40000000;
|
|||||||
const PFD_STEREO_DONTCARE = 0x80000000;
|
const PFD_STEREO_DONTCARE = 0x80000000;
|
||||||
|
|
||||||
|
|
||||||
const PixelFormatDescriptor = struct #ordered {
|
type PixelFormatDescriptor struct #ordered {
|
||||||
size,
|
size,
|
||||||
version,
|
version,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
@@ -519,7 +519,7 @@ proc swap_buffers (hdc: Hdc) -> Bool
|
|||||||
proc release_dc (wnd: Hwnd, hdc: Hdc) -> i32 #foreign user32 "ReleaseDC";
|
proc release_dc (wnd: Hwnd, hdc: Hdc) -> i32 #foreign user32 "ReleaseDC";
|
||||||
|
|
||||||
|
|
||||||
const Proc = type proc() #cc_c;
|
type Proc proc() #cc_c;
|
||||||
|
|
||||||
const MAPVK_VK_TO_CHAR = 2;
|
const MAPVK_VK_TO_CHAR = 2;
|
||||||
const MAPVK_VK_TO_VSC = 0;
|
const MAPVK_VK_TO_VSC = 0;
|
||||||
@@ -533,7 +533,7 @@ proc get_async_key_state(v_key: i32) -> i16 #foreign user32 "GetAsyncKeyState";
|
|||||||
|
|
||||||
proc is_key_down(key: KeyCode) -> bool #inline { return get_async_key_state(i32(key)) < 0; }
|
proc is_key_down(key: KeyCode) -> bool #inline { return get_async_key_state(i32(key)) < 0; }
|
||||||
|
|
||||||
const KeyCode = enum i32 {
|
type KeyCode enum i32 {
|
||||||
Lbutton = 0x01,
|
Lbutton = 0x01,
|
||||||
Rbutton = 0x02,
|
Rbutton = 0x02,
|
||||||
Cancel = 0x03,
|
Cancel = 0x03,
|
||||||
|
|||||||
+3
-3
@@ -28,9 +28,9 @@ const RUNE3_MAX = 1<<16 - 1;
|
|||||||
const LOCB = 0b1000_0000;
|
const LOCB = 0b1000_0000;
|
||||||
const HICB = 0b1011_1111;
|
const HICB = 0b1011_1111;
|
||||||
|
|
||||||
const AcceptRange = struct { lo, hi: u8 }
|
type AcceptRange struct { lo, hi: u8 }
|
||||||
|
|
||||||
immutable var accept_ranges = [5]AcceptRange{
|
let accept_ranges = [5]AcceptRange{
|
||||||
{0x80, 0xbf},
|
{0x80, 0xbf},
|
||||||
{0xa0, 0xbf},
|
{0xa0, 0xbf},
|
||||||
{0x80, 0x9f},
|
{0x80, 0x9f},
|
||||||
@@ -38,7 +38,7 @@ immutable var accept_ranges = [5]AcceptRange{
|
|||||||
{0x80, 0x8f},
|
{0x80, 0x8f},
|
||||||
};
|
};
|
||||||
|
|
||||||
immutable var accept_sizes = [256]u8{
|
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, // 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
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init,
|
|||||||
if (init != NULL) {
|
if (init != NULL) {
|
||||||
check_expr_or_type(c, &operand, init);
|
check_expr_or_type(c, &operand, init);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
if (operand.mode == Addressing_Type) {
|
if (operand.mode == Addressing_Type) {
|
||||||
e->kind = Entity_TypeName;
|
e->kind = Entity_TypeName;
|
||||||
|
|
||||||
@@ -186,6 +187,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init,
|
|||||||
check_type_decl(c, e, d->type_expr, named_type);
|
check_type_decl(c, e, d->type_expr, named_type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
check_init_constant(c, e, &operand);
|
check_init_constant(c, e, &operand);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1538,7 +1538,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
|||||||
|
|
||||||
case_ast_node(vd, ValueDecl, 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_var) {
|
if (vd->token.kind == Token_const) {
|
||||||
// NOTE(bill): Handled elsewhere
|
// NOTE(bill): Handled elsewhere
|
||||||
} else {
|
} else {
|
||||||
Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
|
Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
|
||||||
|
|||||||
+43
-22
@@ -1451,7 +1451,7 @@ 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(vd, ValueDecl, decl);
|
||||||
if (vd->token.kind == Token_var) {
|
if (vd->token.kind != Token_const) {
|
||||||
if (!c->context.scope->is_file) {
|
if (!c->context.scope->is_file) {
|
||||||
// NOTE(bill): local scope -> handle later and in order
|
// NOTE(bill): local scope -> handle later and in order
|
||||||
break;
|
break;
|
||||||
@@ -1527,30 +1527,30 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco
|
|||||||
Entity *e = NULL;
|
Entity *e = NULL;
|
||||||
|
|
||||||
AstNode *up_init = unparen_expr(init);
|
AstNode *up_init = unparen_expr(init);
|
||||||
if (up_init != NULL && is_ast_node_type(up_init)) {
|
// if (up_init != NULL && is_ast_node_type(up_init)) {
|
||||||
AstNode *type = up_init;
|
// AstNode *type = up_init;
|
||||||
e = make_entity_type_name(c->allocator, d->scope, name->Ident, NULL);
|
// e = make_entity_type_name(c->allocator, d->scope, name->Ident, NULL);
|
||||||
// TODO(bill): What if vd->type != NULL??? How to handle this case?
|
// // TODO(bill): What if vd->type != NULL??? How to handle this case?
|
||||||
d->type_expr = type;
|
// d->type_expr = type;
|
||||||
d->init_expr = type;
|
// d->init_expr = type;
|
||||||
} else if (up_init != NULL && up_init->kind == AstNode_Alias) {
|
// } else if (up_init != NULL && up_init->kind == AstNode_Alias) {
|
||||||
#if 1
|
// #if 1
|
||||||
error_node(up_init, "#alias declarations are not yet supported");
|
// error_node(up_init, "#alias declarations are not yet supported");
|
||||||
continue;
|
// continue;
|
||||||
#else
|
// #else
|
||||||
e = make_entity_alias(c->allocator, d->scope, name->Ident, NULL, EntityAlias_Invalid, NULL);
|
// e = make_entity_alias(c->allocator, d->scope, name->Ident, NULL, EntityAlias_Invalid, NULL);
|
||||||
d->type_expr = vd->type;
|
// d->type_expr = vd->type;
|
||||||
d->init_expr = up_init->Alias.expr;
|
// d->init_expr = up_init->Alias.expr;
|
||||||
#endif
|
// #endif
|
||||||
// } else if (init != NULL && up_init->kind == AstNode_ProcLit) {
|
// // } else if (init != NULL && up_init->kind == AstNode_ProcLit) {
|
||||||
// e = make_entity_procedure(c->allocator, d->scope, name->Ident, NULL, up_init->ProcLit.tags);
|
// // e = make_entity_procedure(c->allocator, d->scope, name->Ident, NULL, up_init->ProcLit.tags);
|
||||||
// d->proc_lit = up_init;
|
// // d->proc_lit = up_init;
|
||||||
// d->type_expr = vd->type;
|
// // d->type_expr = vd->type;
|
||||||
} else {
|
// } else {
|
||||||
e = make_entity_constant(c->allocator, d->scope, name->Ident, NULL, empty_exact_value);
|
e = make_entity_constant(c->allocator, d->scope, name->Ident, NULL, empty_exact_value);
|
||||||
d->type_expr = vd->type;
|
d->type_expr = vd->type;
|
||||||
d->init_expr = init;
|
d->init_expr = init;
|
||||||
}
|
// }
|
||||||
GB_ASSERT(e != NULL);
|
GB_ASSERT(e != NULL);
|
||||||
e->identifier = name;
|
e->identifier = name;
|
||||||
|
|
||||||
@@ -1579,6 +1579,27 @@ 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);
|
case_ast_node(id, ImportDecl, decl);
|
||||||
if (!c->context.scope->is_file) {
|
if (!c->context.scope->is_file) {
|
||||||
if (id->is_import) {
|
if (id->is_import) {
|
||||||
|
|||||||
+23
-25
@@ -5813,7 +5813,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(vd, ValueDecl, node);
|
case_ast_node(vd, ValueDecl, node);
|
||||||
if (vd->token.kind == Token_var) {
|
if (vd->token.kind != Token_const) {
|
||||||
irModule *m = proc->module;
|
irModule *m = proc->module;
|
||||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
|
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
|
||||||
|
|
||||||
@@ -5862,30 +5862,6 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gb_temp_arena_memory_end(tmp);
|
gb_temp_arena_memory_end(tmp);
|
||||||
} else {
|
|
||||||
for_array(i, vd->names) {
|
|
||||||
AstNode *ident = vd->names[i];
|
|
||||||
GB_ASSERT(ident->kind == AstNode_Ident);
|
|
||||||
Entity *e = entity_of_ident(proc->module->info, ident);
|
|
||||||
GB_ASSERT(e != NULL);
|
|
||||||
switch (e->kind) {
|
|
||||||
case 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
@@ -5960,6 +5936,28 @@ 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"));
|
||||||
|
|
||||||
|
|||||||
+67
-28
@@ -314,6 +314,11 @@ 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 { \
|
AST_NODE_KIND(ImportDecl, "import declaration", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
bool is_import; \
|
bool is_import; \
|
||||||
@@ -1446,6 +1451,14 @@ 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 *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);
|
AstNode *result = make_ast_node(f, AstNode_ImportDecl);
|
||||||
@@ -1590,6 +1603,11 @@ void fix_advance_to_next_stmt(AstFile *f) {
|
|||||||
case Token_Semicolon:
|
case Token_Semicolon:
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case Token_var:
|
||||||
|
case Token_const:
|
||||||
|
case Token_let:
|
||||||
|
case Token_type:
|
||||||
|
|
||||||
case Token_if:
|
case Token_if:
|
||||||
case Token_when:
|
case Token_when:
|
||||||
case Token_return:
|
case Token_return:
|
||||||
@@ -1597,7 +1615,6 @@ void fix_advance_to_next_stmt(AstFile *f) {
|
|||||||
case Token_defer:
|
case Token_defer:
|
||||||
case Token_asm:
|
case Token_asm:
|
||||||
case Token_using:
|
case Token_using:
|
||||||
case Token_immutable:
|
|
||||||
// case Token_thread_local:
|
// case Token_thread_local:
|
||||||
// case Token_no_alias:
|
// case Token_no_alias:
|
||||||
|
|
||||||
@@ -1671,9 +1688,12 @@ 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_ValueDecl:
|
case AstNode_ValueDecl:
|
||||||
if (s->ValueDecl.token.kind != Token_var) {
|
if (s->ValueDecl.token.kind != Token_const) {
|
||||||
if (s->ValueDecl.values.count > 0) {
|
if (s->ValueDecl.values.count > 0) {
|
||||||
AstNode *last = s->ValueDecl.values[s->ValueDecl.values.count-1];
|
AstNode *last = s->ValueDecl.values[s->ValueDecl.values.count-1];
|
||||||
return is_semicolon_optional_for_node(f, last);
|
return is_semicolon_optional_for_node(f, last);
|
||||||
@@ -2511,7 +2531,7 @@ AstNode *parse_value_decl(AstFile *f, Token token) {
|
|||||||
Array<AstNode *> lhs = parse_lhs_expr_list(f);
|
Array<AstNode *> lhs = parse_lhs_expr_list(f);
|
||||||
AstNode *type = NULL;
|
AstNode *type = NULL;
|
||||||
Array<AstNode *> values = {};
|
Array<AstNode *> values = {};
|
||||||
bool is_mutable = token.kind == Token_var;
|
bool is_mutable = token.kind != Token_const;
|
||||||
|
|
||||||
if (allow_token(f, Token_Colon)) {
|
if (allow_token(f, Token_Colon)) {
|
||||||
type = parse_type(f);
|
type = parse_type(f);
|
||||||
@@ -2551,12 +2571,14 @@ AstNode *parse_value_decl(AstFile *f, Token token) {
|
|||||||
values = make_ast_node_array(f);
|
values = make_ast_node_array(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Array<AstNode *> specs = {};
|
Array<AstNode *> specs = {};
|
||||||
array_init(&specs, heap_allocator(), 1);
|
array_init(&specs, heap_allocator(), 1);
|
||||||
// Token token = ast_node_token(lhs[0]);
|
AstNode *decl = ast_value_decl(f, token, lhs, type, values);
|
||||||
// token.kind = is_mutable ? Token_var : Token_const;
|
if (token.kind == Token_let) {
|
||||||
// token.string = is_mutable ? str_lit("var") : str_lit("const");
|
decl->ValueDecl.flags |= VarDeclFlag_immutable;
|
||||||
return ast_value_decl(f, token, lhs, type, values);
|
}
|
||||||
|
return decl;
|
||||||
}
|
}
|
||||||
|
|
||||||
AstNode *parse_proc_decl(AstFile *f) {
|
AstNode *parse_proc_decl(AstFile *f) {
|
||||||
@@ -2583,6 +2605,13 @@ 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);
|
||||||
|
AstNode *name = parse_ident(f);
|
||||||
|
AstNode *type = parse_type(f);
|
||||||
|
return ast_type_decl(f, token, name, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) {
|
AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) {
|
||||||
@@ -2590,6 +2619,7 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) {
|
|||||||
switch (f->curr_token.kind) {
|
switch (f->curr_token.kind) {
|
||||||
case Token_var:
|
case Token_var:
|
||||||
case Token_const:
|
case Token_const:
|
||||||
|
case Token_let:
|
||||||
next_token(f);
|
next_token(f);
|
||||||
return parse_value_decl(f, token);
|
return parse_value_decl(f, token);
|
||||||
}
|
}
|
||||||
@@ -2783,7 +2813,7 @@ FieldPrefixKind is_token_field_prefix(AstFile *f) {
|
|||||||
case Token_using:
|
case Token_using:
|
||||||
return FieldPrefix_Using;
|
return FieldPrefix_Using;
|
||||||
|
|
||||||
case Token_immutable:
|
case Token_let:
|
||||||
return FieldPrefix_Immutable;
|
return FieldPrefix_Immutable;
|
||||||
|
|
||||||
case Token_Hash: {
|
case Token_Hash: {
|
||||||
@@ -3686,6 +3716,7 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
|
|
||||||
case Token_var:
|
case Token_var:
|
||||||
case Token_const:
|
case Token_const:
|
||||||
|
case Token_let:
|
||||||
s = parse_simple_stmt(f, StmtAllowFlag_None);
|
s = parse_simple_stmt(f, StmtAllowFlag_None);
|
||||||
expect_semicolon(f, s);
|
expect_semicolon(f, s);
|
||||||
return s;
|
return s;
|
||||||
@@ -3695,6 +3726,11 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
expect_semicolon(f, s);
|
expect_semicolon(f, s);
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
|
case Token_type:
|
||||||
|
s = parse_type_decl(f);
|
||||||
|
expect_semicolon(f, s);
|
||||||
|
return s;
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -3722,27 +3758,30 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
case Token_using: {
|
case Token_using: {
|
||||||
// TODO(bill): Make using statements better
|
// TODO(bill): Make using statements better
|
||||||
Token token = expect_token(f, Token_using);
|
Token token = expect_token(f, Token_using);
|
||||||
Array<AstNode *> list = parse_lhs_expr_list(f);
|
AstNode *decl = NULL;
|
||||||
if (list.count == 0) {
|
if (f->curr_token.kind == Token_var ||
|
||||||
syntax_error(token, "Illegal use of `using` statement");
|
f->curr_token.kind == Token_let) {
|
||||||
expect_semicolon(f, NULL);
|
Token var = f->curr_token; next_token(f);
|
||||||
return ast_bad_stmt(f, token, f->curr_token);
|
decl = parse_value_decl(f, var);
|
||||||
|
expect_semicolon(f, decl);
|
||||||
|
} else {
|
||||||
|
Array<AstNode *> list = parse_lhs_expr_list(f);
|
||||||
|
if (list.count == 0) {
|
||||||
|
syntax_error(token, "Illegal use of `using` statement");
|
||||||
|
expect_semicolon(f, NULL);
|
||||||
|
return ast_bad_stmt(f, token, f->curr_token);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f->curr_token.kind != Token_Colon) {
|
||||||
|
expect_semicolon(f, list[list.count-1]);
|
||||||
|
return ast_using_stmt(f, token, list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f->curr_token.kind != Token_Colon) {
|
|
||||||
expect_semicolon(f, list[list.count-1]);
|
|
||||||
return ast_using_stmt(f, token, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
Token var = ast_node_token(list[0]);
|
if (decl != NULL && decl->kind == AstNode_ValueDecl) {
|
||||||
var.kind = Token_var;
|
|
||||||
var.string = str_lit("var");
|
|
||||||
AstNode *decl = parse_value_decl(f, var);
|
|
||||||
expect_semicolon(f, decl);
|
|
||||||
|
|
||||||
if (decl->kind == AstNode_ValueDecl) {
|
|
||||||
#if 1
|
#if 1
|
||||||
if (decl->ValueDecl.token.kind != Token_var) {
|
if (decl->ValueDecl.token.kind == Token_const) {
|
||||||
syntax_error(token, "`using` may not be applied to constant declarations");
|
syntax_error(token, "`using` may not be applied to constant declarations");
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
@@ -3761,13 +3800,13 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
return ast_bad_stmt(f, token, f->curr_token);
|
return ast_bad_stmt(f, token, f->curr_token);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
#if 1
|
#if 0
|
||||||
case Token_immutable: {
|
case Token_immutable: {
|
||||||
Token token = expect_token(f, Token_immutable);
|
Token token = expect_token(f, Token_immutable);
|
||||||
AstNode *node = parse_stmt(f);
|
AstNode *node = parse_stmt(f);
|
||||||
|
|
||||||
if (node->kind == AstNode_ValueDecl) {
|
if (node->kind == AstNode_ValueDecl) {
|
||||||
if (node->ValueDecl.token.kind != Token_var) {
|
if (node->ValueDecl.token.kind == Token_const) {
|
||||||
syntax_error(token, "`immutable` may not be applied to constant declarations");
|
syntax_error(token, "`immutable` may not be applied to constant declarations");
|
||||||
} else {
|
} else {
|
||||||
node->ValueDecl.flags |= VarDeclFlag_immutable;
|
node->ValueDecl.flags |= VarDeclFlag_immutable;
|
||||||
@@ -3939,7 +3978,7 @@ AstNode *parse_stmt(AstFile *f) {
|
|||||||
AstNode *s = parse_stmt(f);
|
AstNode *s = parse_stmt(f);
|
||||||
|
|
||||||
if (s->kind == AstNode_ValueDecl) {
|
if (s->kind == AstNode_ValueDecl) {
|
||||||
if (s->ValueDecl.token.kind != Token_var) {
|
if (s->ValueDecl.token.kind == Token_const) {
|
||||||
syntax_error(token, "`thread_local` may not be applied to constant declarations");
|
syntax_error(token, "`thread_local` may not be applied to constant declarations");
|
||||||
}
|
}
|
||||||
if (f->curr_proc != NULL) {
|
if (f->curr_proc != NULL) {
|
||||||
|
|||||||
+1
-1
@@ -1969,7 +1969,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) {
|
|||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(vd, ValueDecl, node);
|
case_ast_node(vd, ValueDecl, node);
|
||||||
if (vd->token.kind == Token_var) {
|
if (vd->token.kind != Token_const) {
|
||||||
ssaModule *m = p->module;
|
ssaModule *m = p->module;
|
||||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
|
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena);
|
||||||
if (vd->values.count == 0) {
|
if (vd->values.count == 0) {
|
||||||
|
|||||||
+1
-1
@@ -83,6 +83,7 @@ TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \
|
|||||||
\
|
\
|
||||||
TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
||||||
TOKEN_KIND(Token_var, "var"), \
|
TOKEN_KIND(Token_var, "var"), \
|
||||||
|
TOKEN_KIND(Token_let, "let"), \
|
||||||
TOKEN_KIND(Token_const, "const"), \
|
TOKEN_KIND(Token_const, "const"), \
|
||||||
TOKEN_KIND(Token_type, "type"), \
|
TOKEN_KIND(Token_type, "type"), \
|
||||||
TOKEN_KIND(Token_when, "when"), \
|
TOKEN_KIND(Token_when, "when"), \
|
||||||
@@ -109,7 +110,6 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
|||||||
TOKEN_KIND(Token_dynamic, "dynamic"), \
|
TOKEN_KIND(Token_dynamic, "dynamic"), \
|
||||||
TOKEN_KIND(Token_map, "map"), \
|
TOKEN_KIND(Token_map, "map"), \
|
||||||
TOKEN_KIND(Token_using, "using"), \
|
TOKEN_KIND(Token_using, "using"), \
|
||||||
TOKEN_KIND(Token_immutable, "immutable"), \
|
|
||||||
TOKEN_KIND(Token_context, "context"), \
|
TOKEN_KIND(Token_context, "context"), \
|
||||||
TOKEN_KIND(Token_push_context, "push_context"), \
|
TOKEN_KIND(Token_push_context, "push_context"), \
|
||||||
TOKEN_KIND(Token_push_allocator, "push_allocator"), \
|
TOKEN_KIND(Token_push_allocator, "push_allocator"), \
|
||||||
|
|||||||
Reference in New Issue
Block a user