aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-09-09 23:33:54 +0100
committerGinger Bill <bill@gingerbill.org>2016-09-09 23:33:54 +0100
commit6979678ff947cecc8e6e0d0e8ceea7e0304d3f4e (patch)
tree774b9480272eba57e1a09011107cc136b43dde65 /examples
parent1ca752ce049b934df5d03af2f06265e219f5f402 (diff)
Begin reording of struct members by default.
Diffstat (limited to 'examples')
-rw-r--r--examples/basic.odin2
-rw-r--r--examples/demo.odin9
-rw-r--r--examples/old_demos/demo002.odin4
-rw-r--r--examples/old_runtime.odin2
-rw-r--r--examples/runtime.odin50
-rw-r--r--examples/win32.odin6
6 files changed, 40 insertions, 33 deletions
diff --git a/examples/basic.odin b/examples/basic.odin
index ad4b224c2..4d41f937d 100644
--- a/examples/basic.odin
+++ b/examples/basic.odin
@@ -16,7 +16,7 @@ print_string_to_buffer :: proc(buf: ^[]byte, s: string) {
if slice.len < slice.cap {
n := min(slice.cap-slice.len, len(s))
offset := ((slice.data as int) + slice.len) as ^byte
- memory_move(offset, ^s[0], n)
+ memory_copy(offset, ^s[0], n)
slice.len += n
}
}
diff --git a/examples/demo.odin b/examples/demo.odin
index 6d14320b9..b418693fa 100644
--- a/examples/demo.odin
+++ b/examples/demo.odin
@@ -1,10 +1,17 @@
#load "basic.odin"
-Vector3 :: struct { x, y, z: f32 }
main :: proc() {
+ Vector3 :: struct {
+ x: i8
+ y: i32
+ z: i16
+ }
v := Vector3{1, 4, 9}
+ t := type_info(v)
+
println(123, "Hello", true, 6.28)
println([4]int{1, 2, 3, 4})
+ println(v)
}
diff --git a/examples/old_demos/demo002.odin b/examples/old_demos/demo002.odin
index 899f9fc32..b9923f37a 100644
--- a/examples/old_demos/demo002.odin
+++ b/examples/old_demos/demo002.odin
@@ -180,8 +180,8 @@ new_builtins :: proc() {
{
// Compile time assert
COND :: true
- assert(COND)
- // assert(!COND)
+ compile_assert(COND)
+ // compile_assert(!COND)
// Runtime assert
x := true
diff --git a/examples/old_runtime.odin b/examples/old_runtime.odin
index 44ae3d64a..af788f11d 100644
--- a/examples/old_runtime.odin
+++ b/examples/old_runtime.odin
@@ -46,7 +46,7 @@ memory_copy :: proc(dst, src: rawptr, n: int) #inline {
}
v128b :: type {4}u32
- assert(align_of(v128b) == 16)
+ compile_assert(align_of(v128b) == 16)
d, s: ^byte = dst, src
diff --git a/examples/runtime.odin b/examples/runtime.odin
index 6a074eb91..dd787e0aa 100644
--- a/examples/runtime.odin
+++ b/examples/runtime.odin
@@ -3,43 +3,47 @@
// IMPORTANT NOTE(bill): Do not change the order of any of this data
// The compiler relies upon this _exact_ order
Type_Info :: union {
- Member :: struct {
- name: string
+ Member :: struct #ordered {
+ name: string // can be empty if tuple
type_info: ^Type_Info
- offset: int
+ offset: int // offsets are not used in tuples
}
- Record :: struct {
- fields: []Member // NOTE(bill): This will need to be allocated on the heap
+ Record :: struct #ordered {
+ fields: []Member // IMPORTANT: This will need to be allocated on the heap
}
- Named: struct {
+ Named: struct #ordered {
name: string
base: ^Type_Info
}
- Integer: struct {
+ Integer: struct #ordered {
size: int // in bytes
signed: bool
}
- Float: struct {
+ Float: struct #ordered {
size: int // in bytes
}
- String: struct {}
- Boolean: struct {}
- Pointer: struct {
+ String: struct #ordered {}
+ Boolean: struct #ordered {}
+ Pointer: struct #ordered {
elem: ^Type_Info
}
- Procedure: struct{}
- Array: struct {
+ Procedure: struct #ordered {
+ params: ^Type_Info // Type_Info.Tuple
+ results: ^Type_Info // Type_Info.Tuple
+ variadic: bool
+ }
+ Array: struct #ordered {
elem: ^Type_Info
elem_size: int
len: int
}
- Slice: struct {
+ Slice: struct #ordered {
elem: ^Type_Info
elem_size: int
}
- Vector: struct {
+ Vector: struct #ordered {
elem: ^Type_Info
elem_size: int
len: int
@@ -48,7 +52,7 @@ Type_Info :: union {
Struct: Record
Union: Record
Raw_Union: Record
- Enum: struct {
+ Enum: struct #ordered {
base: ^Type_Info
}
}
@@ -57,9 +61,9 @@ Type_Info :: union {
assume :: proc(cond: bool) #foreign "llvm.assume"
-__debug_trap :: proc() #foreign "llvm.debugtrap"
-__trap :: proc() #foreign "llvm.trap"
-read_cycle_counter :: proc() -> u64 #foreign "llvm.readcyclecounter"
+__debug_trap :: proc() #foreign "llvm.debugtrap"
+__trap :: proc() #foreign "llvm.trap"
+read_cycle_counter :: proc() -> u64 #foreign "llvm.readcyclecounter"
bit_reverse16 :: proc(b: u16) -> u16 #foreign "llvm.bitreverse.i16"
bit_reverse32 :: proc(b: u32) -> u32 #foreign "llvm.bitreverse.i32"
@@ -87,7 +91,8 @@ memory_zero :: proc(data: rawptr, len: int) {
memory_compare :: proc(dst, src: rawptr, len: int) -> int {
// TODO(bill): make a faster `memory_compare`
- a, b := slice_ptr(dst as ^byte, len), slice_ptr(src as ^byte, len)
+ a := slice_ptr(dst as ^byte, len)
+ b := slice_ptr(src as ^byte, len)
for i := 0; i < len; i++ {
if a[i] != b[i] {
return (a[i] - b[i]) as int
@@ -97,11 +102,6 @@ memory_compare :: proc(dst, src: rawptr, len: int) -> int {
}
memory_copy :: proc(dst, src: rawptr, len: int) #inline {
- llvm_memcpy_64bit :: proc(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memcpy.p0i8.p0i8.i64"
- llvm_memcpy_64bit(dst, src, len, 1, false)
-}
-
-memory_move :: proc(dst, src: rawptr, len: int) #inline {
llvm_memmove_64bit :: proc(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memmove.p0i8.p0i8.i64"
llvm_memmove_64bit(dst, src, len, 1, false)
}
diff --git a/examples/win32.odin b/examples/win32.odin
index 35c47ccba..f693a4def 100644
--- a/examples/win32.odin
+++ b/examples/win32.odin
@@ -42,7 +42,7 @@ INVALID_HANDLE_VALUE :: (-1 as int) as HANDLE
WNDPROC :: type proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT
-WNDCLASSEXA :: struct {
+WNDCLASSEXA :: struct #ordered {
size, style: u32
wnd_proc: WNDPROC
cls_extra, wnd_extra: i32
@@ -54,7 +54,7 @@ WNDCLASSEXA :: struct {
sm: HICON
}
-MSG :: struct {
+MSG :: struct #ordered {
hwnd: HWND
message: u32
wparam: WPARAM
@@ -191,7 +191,7 @@ PROC :: type proc()
wglCreateContextAttribsARBType :: type proc(hdc: HDC, hshareContext: rawptr, attribList: ^i32) -> HGLRC
-PIXELFORMATDESCRIPTOR :: struct {
+PIXELFORMATDESCRIPTOR :: struct #ordered {
size,
version,
flags: u32