diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-07-01 11:38:44 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-07-01 11:38:44 +0100 |
| commit | ed089b44b9634c431785b5fa40c086f59900d740 (patch) | |
| tree | 3535d2a7a6fc0b5dfb90671b18926beedd753a6f /code | |
| parent | 33f4af2e195fcaa7a5b4fa7ea25a464f3597f18c (diff) | |
`do` keyword for inline statements instead of blocks
Diffstat (limited to 'code')
| -rw-r--r-- | code/demo.odin | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/code/demo.odin b/code/demo.odin index 1b07028ee..cba0212fb 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,8 +1,9 @@ import ( + "fmt.odin"; +/* "atomics.odin"; "bits.odin"; "decimal.odin"; - "fmt.odin"; "hash.odin"; "math.odin"; "mem.odin"; @@ -15,6 +16,7 @@ import ( "types.odin"; "utf8.odin"; "utf16.odin"; +*/ ) general_stuff :: proc() { @@ -34,6 +36,8 @@ general_stuff :: proc() { // The variadic part allows for extra type checking too which C does not provide c_printf :: proc(fmt: ^u8, #c_vararg args: ..any) -> i32 #link_name "printf" ---; } + str := "%d\n"; + c_printf(&str[0], i32(789456123)); Foo :: struct { @@ -72,9 +76,7 @@ foreign_blocks :: proc() { } default_arguments :: proc() { - hello :: proc(a: int = 9, b: int = 9) { - fmt.printf("a is %d; b is %d\n", a, b); - } + hello :: proc(a: int = 9, b: int = 9) do fmt.printf("a is %d; b is %d\n", a, b); fmt.println("\nTesting default arguments:"); hello(1, 2); hello(1); @@ -179,7 +181,7 @@ default_return_values :: proc() { some_thing :: proc(input: int) -> (result: ^Entity = nil, err := Error.None) { match { - case input == 3: return err = Error.WhyTheNumberThree; + case input == 3: return err = Error.WhyTheNumberThree; case input >= 10: return err = Error.TenIsTooBig; } @@ -215,9 +217,7 @@ call_location :: proc() { explicit_parametric_polymorphic_procedures :: proc() { // This is how `new` is actually implemented, see _preload.odin - alloc_type :: proc(T: type) -> ^T { - return ^T(alloc(size_of(T), align_of(T))); - } + alloc_type :: proc(T: type) -> ^T do return ^T(alloc(size_of(T), align_of(T))); int_ptr := alloc_type(int); defer free(int_ptr); @@ -231,9 +231,7 @@ explicit_parametric_polymorphic_procedures :: proc() { add :: proc(T: type, args: ..T) -> T { res: T; - for arg in args { - res += arg; - } + for arg in args do res += arg; return res; } @@ -298,7 +296,7 @@ explicit_parametric_polymorphic_procedures :: proc() { use_empty_slot :: proc(manager: ^EntityManager, batch: ^EntityBatch) -> ^Entity { for ok, i in batch.occupied { - if ok -> continue; + if ok do continue; batch.occupied[i] = true; e := &batch.data[i]; @@ -314,7 +312,7 @@ explicit_parametric_polymorphic_procedures :: proc() { gen_new_entity :: proc(manager: ^EntityManager) -> ^Entity { for b in manager.batches { e := use_empty_slot(manager, b); - if e != nil -> return e; + if e != nil do return e; } new_batch := new(EntityBatch); @@ -366,12 +364,9 @@ explicit_parametric_polymorphic_procedures :: proc() { } } - - - main :: proc() { -/* general_stuff(); +/* foreign_blocks(); default_arguments(); named_arguments(); |