mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-25 23:14:59 -07:00
Begin "Everything's a namespace"
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
||||
#load "file.odin"
|
||||
|
||||
print_string :: proc(s: string) {
|
||||
file_write(file_get_standard(FileStandard.OUTPUT), ^s[0], len(s));
|
||||
file_write(file_get_standard(FileStandard.OUTPUT), s as []byte);
|
||||
}
|
||||
|
||||
byte_reverse :: proc(b: []byte) {
|
||||
|
||||
+29
-5
@@ -32,6 +32,30 @@ main :: proc() {
|
||||
d := ptr_sub(y, ptr_offset(x, 1));
|
||||
print_int(d); nl();
|
||||
|
||||
Thing :: type struct {
|
||||
CONSTANT :: 123;
|
||||
Thing :: type struct {
|
||||
y: f32;
|
||||
|
||||
z: int;
|
||||
w: int;
|
||||
}
|
||||
|
||||
x: Thing;
|
||||
}
|
||||
|
||||
test :: proc() -> int {
|
||||
t_outer: Thing;
|
||||
t_outer.x = Thing.Thing{};
|
||||
using Thing;
|
||||
t_inner: Thing;
|
||||
t_inner.y = 1;
|
||||
print_int(CONSTANT); nl();
|
||||
return CONSTANT;
|
||||
}
|
||||
|
||||
test__ := test();
|
||||
|
||||
|
||||
|
||||
// run_game();
|
||||
@@ -301,7 +325,7 @@ types :: proc() {
|
||||
Array3Int :: type [3]int;
|
||||
|
||||
Vec3 :: type struct {
|
||||
x, y, z: f32
|
||||
x, y, z: f32;
|
||||
}
|
||||
|
||||
BinaryNode :: type struct {
|
||||
@@ -430,8 +454,8 @@ types :: proc() {
|
||||
variable: struct{
|
||||
visited, is_field, used, anonymous: bool;
|
||||
};
|
||||
procedure: struct { used: bool };
|
||||
buitlin: struct { id: i32 };
|
||||
procedure: struct { used: bool; };
|
||||
buitlin: struct { id: i32; };
|
||||
};
|
||||
}
|
||||
|
||||
@@ -632,7 +656,7 @@ data_control :: proc() {
|
||||
context.allocator = __default_allocator();
|
||||
defer context.allocator = prev_allocator;
|
||||
|
||||
File :: type struct { filename: string };
|
||||
File :: type struct { filename: string; };
|
||||
FileError :: type int;
|
||||
open_file :: proc(filename: string) -> (File, FileError) {
|
||||
return File{}, 0;
|
||||
@@ -717,7 +741,7 @@ using_fields :: proc() {
|
||||
|
||||
{ // Crazy Shit
|
||||
Vec2 :: type union {
|
||||
using _xy: struct {x, y: f32};
|
||||
using _xy: struct { x, y: f32; };
|
||||
e: [2]f32;
|
||||
v: {2}f32;
|
||||
}
|
||||
|
||||
+13
-13
@@ -1,18 +1,16 @@
|
||||
#load "win32.odin"
|
||||
|
||||
FileHandle :: type HANDLE;
|
||||
|
||||
File :: type struct {
|
||||
handle: FileHandle;
|
||||
Handle :: type HANDLE;
|
||||
handle: Handle;
|
||||
}
|
||||
|
||||
file_open :: proc(name: string) -> (File, bool) {
|
||||
buf: [300]byte;
|
||||
_ = copy(buf[:], name as []byte);
|
||||
f := File{
|
||||
handle = CreateFileA(^buf[0], FILE_GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, 0, null),
|
||||
};
|
||||
success := f.handle != INVALID_HANDLE_VALUE as FileHandle;
|
||||
f := File{CreateFileA(^buf[0], FILE_GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, 0, null)};
|
||||
success := f.handle != INVALID_HANDLE_VALUE as File.Handle;
|
||||
|
||||
return f, success;
|
||||
}
|
||||
|
||||
@@ -22,7 +20,7 @@ file_create :: proc(name: string) -> (File, bool) {
|
||||
f := File{
|
||||
handle = CreateFileA(^buf[0], FILE_GENERIC_WRITE, FILE_SHARE_READ, null, CREATE_ALWAYS, 0, null),
|
||||
};
|
||||
success := f.handle != INVALID_HANDLE_VALUE as FileHandle;
|
||||
success := f.handle != INVALID_HANDLE_VALUE as File.Handle;
|
||||
return f, success;
|
||||
}
|
||||
|
||||
@@ -31,9 +29,9 @@ file_close :: proc(f: ^File) {
|
||||
CloseHandle(f.handle);
|
||||
}
|
||||
|
||||
file_write :: proc(f: ^File, buf: rawptr, len: int) -> bool {
|
||||
file_write :: proc(f: ^File, buf: []byte) -> bool {
|
||||
bytes_written: i32;
|
||||
return WriteFile(f.handle, buf, len as i32, ^bytes_written, null) != 0;
|
||||
return WriteFile(f.handle, ^buf[0], len(buf) as i32, ^bytes_written, null) != 0;
|
||||
}
|
||||
|
||||
FileStandard :: type enum {
|
||||
@@ -47,10 +45,12 @@ __std_file_set := false;
|
||||
__std_files: [FileStandard.COUNT as int]File;
|
||||
|
||||
file_get_standard :: proc(std: FileStandard) -> ^File {
|
||||
// using FileStandard;
|
||||
if (!__std_file_set) {
|
||||
__std_files[FileStandard.INPUT] .handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
__std_files[FileStandard.OUTPUT].handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
__std_files[FileStandard.ERROR] .handle = GetStdHandle(STD_ERROR_HANDLE);
|
||||
using FileStandard;
|
||||
__std_files[INPUT] .handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
__std_files[OUTPUT].handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
__std_files[ERROR] .handle = GetStdHandle(STD_ERROR_HANDLE);
|
||||
__std_file_set = true;
|
||||
}
|
||||
return ^__std_files[std];
|
||||
|
||||
@@ -98,7 +98,7 @@ memory_copy :: proc(dst, src: rawptr, n: int) #inline {
|
||||
w = (s as ^u32)^;
|
||||
d^ = s^; d = ptr_offset(d, 1); s = ptr_offset(s, 1);
|
||||
d^ = s^; d = ptr_offset(d, 1); s = ptr_offset(s, 1);
|
||||
n -= 2
|
||||
n -= 2;
|
||||
|
||||
for n > 17 {
|
||||
d32 := d as ^u32;
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ LPARAM :: type int;
|
||||
LRESULT :: type int;
|
||||
ATOM :: type i16;
|
||||
BOOL :: type i32;
|
||||
POINT :: type struct { x, y: i32 };
|
||||
POINT :: type struct { x, y: i32; };
|
||||
|
||||
INVALID_HANDLE_VALUE :: (-1 as int) as HANDLE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user