From 8ee23054bf771e56802ce21d70229b7f8f2e9654 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 15 Sep 2024 17:34:34 -0400 Subject: Update Inline C syntax and documentation/tests --- examples/coroutine.tm | 20 ++++++-------------- examples/game/player.tm | 8 ++++---- examples/http.tm | 4 ++-- examples/log.tm | 8 +++----- 4 files changed, 15 insertions(+), 25 deletions(-) (limited to 'examples') diff --git a/examples/coroutine.tm b/examples/coroutine.tm index 1d3d4dcf..35eb5fda 100644 --- a/examples/coroutine.tm +++ b/examples/coroutine.tm @@ -29,16 +29,12 @@ _shared_stack := !@Memory struct Coroutine(co:@Memory): func is_finished(co:Coroutine; inline)->Bool: - return inline C ( - ((aco_t*)$co.$co)->is_finished - ):Bool + return inline C:Bool {((aco_t*)$co.$co)->is_finished} func resume(co:Coroutine)->Bool: if co:is_finished(): return no - inline C { - aco_resume($co.$co); - } + inline C { aco_resume($co.$co); } return yes func _init(): @@ -46,13 +42,9 @@ func _init(): aco_set_allocator(GC_malloc, NULL); aco_thread_init(aco_exit_fn); } - _main_co = inline C( - aco_create(NULL, NULL, 0, NULL, NULL) - ):@Memory + _main_co = inline C:@Memory { aco_create(NULL, NULL, 0, NULL, NULL) } - _shared_stack = inline C( - aco_shared_stack_new(0); - ):@Memory + _shared_stack = inline C:@Memory { aco_shared_stack_new(0) } func new(co:func())->Coroutine: if not _main_co: @@ -60,9 +52,9 @@ func new(co:func())->Coroutine: main_co := _main_co shared_stack := _shared_stack - aco_ptr := inline C ( + aco_ptr := inline C:@Memory { aco_create($main_co, $shared_stack, 0, (void*)$co.fn, $co.userdata) - ):@Memory + } return Coroutine(aco_ptr) func yield(; inline): diff --git a/examples/game/player.tm b/examples/game/player.tm index dff95b9d..5909ae63 100644 --- a/examples/game/player.tm +++ b/examples/game/player.tm @@ -13,12 +13,12 @@ struct Player(pos,prev_pos:Vec2): SIZE := Vec2(30, 30) func update(p:&Player): - target_x := inline C ( + target_x := inline C:Num { (Num_t)((IsKeyDown(KEY_A) ? -1 : 0) + (IsKeyDown(KEY_D) ? 1 : 0)) - ) : Num - target_y := inline C ( + } + target_y := inline C:Num { (Num_t)((IsKeyDown(KEY_W) ? -1 : 0) + (IsKeyDown(KEY_S) ? 1 : 0)) - ) : Num + } target_vel := Vec2(target_x, target_y):norm() * WALK_SPEED vel := (p.pos - p.prev_pos)/World.DT diff --git a/examples/http.tm b/examples/http.tm index 0a27ece2..bbec3308 100644 --- a/examples/http.tm +++ b/examples/http.tm @@ -12,9 +12,9 @@ _curl := !@Memory func _send(method:_Method, url:Text, data:Text?, headers=[:Text])->HTTPResponse: chunks := @[:Text] save_chunk := func(chunk:CString, size:Int64, n:Int64): - chunks:insert(inline C ( + chunks:insert(inline C:Text { Text$format("%.*s", $size*$n, $chunk) - ) : Text) + }) return n*size inline C { diff --git a/examples/log.tm b/examples/log.tm index 24397c90..42df072c 100644 --- a/examples/log.tm +++ b/examples/log.tm @@ -6,15 +6,13 @@ timestamp_format := CString("%F %T") logfiles := {:Path} func _timestamp()->Text: - c_str := inline C ( - ({ + c_str := inline C:CString { char *str = GC_MALLOC_ATOMIC(20); time_t t; time(&t); struct tm *tm_info = localtime(&t); strftime(str, 20, "%F %T", tm_info); - str; - }) - ) : CString + str + } return c_str:as_text() func info(text:Text, newline=yes): -- cgit v1.2.3