aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-08-30 00:04:14 +0100
committerGinger Bill <bill@gingerbill.org>2016-08-30 00:04:14 +0100
commit0eaf7bd830dcda6e00f80eefed36bdf7beb02d5d (patch)
tree3e65c52384458031b5ede490429c9c1938d8ba0b /examples
parent593563d8eabf725ac851f4c3c72cd32b5a71aa7c (diff)
Begin "Everything's a namespace"
Diffstat (limited to 'examples')
-rw-r--r--examples/basic.odin2
-rw-r--r--examples/demo.odin34
-rw-r--r--examples/file.odin26
-rw-r--r--examples/runtime.odin2
-rw-r--r--examples/win32.odin2
5 files changed, 45 insertions, 21 deletions
diff --git a/examples/basic.odin b/examples/basic.odin
index 42d7404c2..c9a54d15a 100644
--- a/examples/basic.odin
+++ b/examples/basic.odin
@@ -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) {
diff --git a/examples/demo.odin b/examples/demo.odin
index 698e570cd..07fa7b1d5 100644
--- a/examples/demo.odin
+++ b/examples/demo.odin
@@ -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;
}
diff --git a/examples/file.odin b/examples/file.odin
index 3e827b3dd..a4011520a 100644
--- a/examples/file.odin
+++ b/examples/file.odin
@@ -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];
diff --git a/examples/runtime.odin b/examples/runtime.odin
index d6a6e354f..5f39bc306 100644
--- a/examples/runtime.odin
+++ b/examples/runtime.odin
@@ -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;
diff --git a/examples/win32.odin b/examples/win32.odin
index b262cbca3..4807cf2a2 100644
--- a/examples/win32.odin
+++ b/examples/win32.odin
@@ -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;