Skip to content

Commit

Permalink
support new function call shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Sep 14, 2023
1 parent 5027012 commit 6d02b58
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 200 deletions.
16 changes: 8 additions & 8 deletions FrontEnd/LangTest/array_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@

(= a b)
(test::AssertEq! (at a 0) 4_u8)
(test::AssertEq! (call update_array [a 0 2]) 4_u8)
(test::AssertEq! (call update_array [a 0 3]) 2_u8)
(test::AssertEq! (call update_array [(^ pa_mut) 0 2]) 3_u8)
(test::AssertEq! (update_array [a 0 2]) 4_u8)
(test::AssertEq! (update_array [a 0 3]) 2_u8)
(test::AssertEq! (update_array [(^ pa_mut) 0 2]) 3_u8)
)


Expand Down Expand Up @@ -164,14 +164,14 @@
(test::AssertEq! (at f3 0) 111_s32)
@doc "basic"
(test::AssertEq! (at c3 0) 4_u8)
(test::AssertEq! (call update_array [c3 0 77]) 4_u8)
(test::AssertEq! (call update_array [c3 0 5]) 77_u8)
(test::AssertEq! (update_array [c3 0 77]) 4_u8)
(test::AssertEq! (update_array [c3 0 5]) 77_u8)
)

(fun @cdecl main [(param argc s32) (param argv (ptr (ptr u8)))] s32 :
(stmt (call test_global_array []))
(stmt (call test_local_array []))
(stmt (call test_mixed_array []))
(stmt (test_global_array []))
(stmt (test_local_array []))
(stmt (test_mixed_array []))
@doc "test end"
(test::Success!)
(return 0))
Expand Down
8 changes: 4 additions & 4 deletions FrontEnd/LangTest/assign_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
(-= (. gr1 i2) 0x1)
(test::AssertEq! (. gr1 i2) 0x1234567812345677_u64)
@doc "gr1 u64 via pointer"
(= (. (^ (call get_addr [])) i2) 0x1234567812345678)
(test::AssertEq! (. (^ (call get_addr [])) i2) 0x1234567812345678_u64)
(-= (. (^ (call get_addr [])) i2) 0x1)
(test::AssertEq! (. (^ (call get_addr [])) i2) 0x1234567812345677_u64)
(= (. (^ (get_addr [])) i2) 0x1234567812345678)
(test::AssertEq! (. (^ (get_addr [])) i2) 0x1234567812345678_u64)
(-= (. (^ (get_addr [])) i2) 0x1)
(test::AssertEq! (. (^ (get_addr [])) i2) 0x1234567812345677_u64)
@doc "gar1 s64"
(= (. (at gar1 3) i1) 0x8765432187654321)
(test::AssertEq! (. (at gar1 3) i1) 0x8765432187654321_s64)
Expand Down
18 changes: 9 additions & 9 deletions FrontEnd/LangTest/defer_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@

(fun foo [] void :
(defer :
(stmt (call store ['h'])))
(stmt (store ['h'])))
(defer :
(stmt (call store ['g'])))
(stmt (call store ['a']))
(stmt (store ['g'])))
(stmt (store ['a']))
(block _ :
(stmt (call store ['b']))
(stmt (store ['b']))
(defer :
(stmt (call store ['e'])))
(stmt (store ['e'])))
(defer :
(stmt (call store ['d'])))
(stmt (call store ['c'])))
(stmt (call store ['f']))
(stmt (store ['d'])))
(stmt (store ['c'])))
(stmt (store ['f']))
)


(fun @cdecl main [(param argc s32) (param argv (ptr (ptr u8)))] s32 :
(stmt (call foo []))
(stmt (foo []))
(test::AssertSliceEq! (slice_val (front gSequence) gIndex) "abcdefgh")
@doc "test end"
(test::Success!)
Expand Down
8 changes: 4 additions & 4 deletions FrontEnd/LangTest/expr_sint_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@
)

(fun @cdecl main [(param argc s32) (param argv (ptr (ptr s8)))] s32 :
(stmt (call test_s64 [0x8765432187654321 0x1234567812345678]))
(stmt (call test_s32 [0x87654321 0x12345678]))
(stmt (call test_s16 [0x8765 0x1234]))
(stmt (call test_s8 [0x87 0x78]))
(stmt (test_s64 [0x8765432187654321 0x1234567812345678]))
(stmt (test_s32 [0x87654321 0x12345678]))
(stmt (test_s16 [0x8765 0x1234]))
(stmt (test_s8 [0x87 0x78]))

@doc "test end"
(test::Success!)
Expand Down
8 changes: 4 additions & 4 deletions FrontEnd/LangTest/expr_uint_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@
)

(fun @cdecl main [(param argc s32) (param argv (ptr (ptr u8)))] s32 :
(stmt (call test_u64 [0x8765432187654321 0x1234567812345678]))
(stmt (call test_u32 [0x87654321 0x12345678]))
(stmt (call test_u16 [0x4321 0x1234]))
(stmt (call test_u8 [0x87 0x78]))
(stmt (test_u64 [0x8765432187654321 0x1234567812345678]))
(stmt (test_u32 [0x87654321 0x12345678]))
(stmt (test_u16 [0x4321 0x1234]))
(stmt (test_u8 [0x87 0x78]))

@doc "test end"
(test::Success!)
Expand Down
14 changes: 7 additions & 7 deletions FrontEnd/LangTest/sum_tagged_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@

(fun test_tagged_union_parameter [] void :
(let @mut x TaggedUnion3 true)
(stmt (call fun_param [true true 0 x]))
(stmt (fun_param [true true 0 x]))
(= x 666_s32)
(stmt (call fun_param [false true 666 x]))
(stmt (fun_param [false true 666 x]))
)

(fun fun_result [
Expand All @@ -124,19 +124,19 @@


(fun test_tagged_union_result [] void :
(let @mut x auto (call fun_result [true false 2]))
(let @mut x auto (fun_result [true false 2]))
(test::AssertTrue! (is x bool))
(test::AssertFalse! (is x s32))

(= x (call fun_result [false false 2]))
(= x (fun_result [false false 2]))
(test::AssertFalse! (is x bool))
(test::AssertTrue! (is x s32))
)

(fun @cdecl main [(param argc s32) (param argv (ptr (ptr u8)))] s32 :
(stmt (call test_tagged_union_basic []))
(stmt (call test_tagged_union_result []))
(stmt (call test_tagged_union_parameter []))
(stmt (test_tagged_union_basic []))
(stmt (test_tagged_union_result []))
(stmt (test_tagged_union_parameter []))

@doc "test end"
(test::Success!)
Expand Down
6 changes: 3 additions & 3 deletions FrontEnd/LangTest/sum_untagged_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@
(test::AssertEq! (as (at array1 13) u32) 0x42280000_u32)
(test::AssertEq! (as (at array1 13) r32) 42_r32)

(= u1 (call with_union_result [true 10 2.0]))
(= u1 (with_union_result [true 10 2.0]))
(test::AssertEq! (as u1 u32) 10_u32)
(= u1 (call with_union_result [false 10 2.0]))
(= u1 (with_union_result [false 10 2.0]))
(test::AssertEq! (as u1 u32) 0x40000000_u32)

(= (at array1 13) 2.0_r64)
Expand All @@ -155,7 +155,7 @@


(fun @cdecl main [(param argc s32) (param argv (ptr (ptr u8)))] s32 :
(stmt (call test_untagged_union []))
(stmt (test_untagged_union []))

@doc "test end"
(test::Success!)
Expand Down
24 changes: 12 additions & 12 deletions FrontEnd/Lib/checksum_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@

(fun @cdecl main [(param argc s32) (param argv (ptr (ptr u8)))] s32 :
@doc "init"
(stmt (call checksum::InitCrcTab [checksum::PolyCrc32LE (& @mut Crc32Tab)]))
(stmt (checksum::InitCrcTab [checksum::PolyCrc32LE (& @mut Crc32Tab)]))
(fmt::print! ["\n\n"])
(stmt (call checksum::InitCrcTab [checksum::PolyCrc32cLE (& @mut Crc32cTab)]))
(stmt (checksum::InitCrcTab [checksum::PolyCrc32cLE (& @mut Crc32cTab)]))
@doc "crc32"
(test::AssertEq! (call checksum::CalcCrc [Data00 0 (& Crc32Tab)]) 0xefb5af2e_u32)
(test::AssertEq! (call checksum::CalcCrc [Data55 0 (& Crc32Tab)]) 0x6be062a7_u32)
(test::AssertEq! (call checksum::CalcCrc [DataAA 0 (& Crc32Tab)]) 0x3c6f327d_u32)
(test::AssertEq! (call checksum::CalcCrc [DataFF 0 (& Crc32Tab)]) 0xb83afff4_u32)
(test::AssertEq! (call checksum::CalcCrc [DataInc 0 (& Crc32Tab)]) 0x100ece8c_u32)
(test::AssertEq! (checksum::CalcCrc [Data00 0 (& Crc32Tab)]) 0xefb5af2e_u32)
(test::AssertEq! (checksum::CalcCrc [Data55 0 (& Crc32Tab)]) 0x6be062a7_u32)
(test::AssertEq! (checksum::CalcCrc [DataAA 0 (& Crc32Tab)]) 0x3c6f327d_u32)
(test::AssertEq! (checksum::CalcCrc [DataFF 0 (& Crc32Tab)]) 0xb83afff4_u32)
(test::AssertEq! (checksum::CalcCrc [DataInc 0 (& Crc32Tab)]) 0x100ece8c_u32)

@doc "crc32c"
(fmt::print! [(as (call checksum::CalcCrc [Data00 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (call checksum::CalcCrc [Data55 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (call checksum::CalcCrc [DataAA 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (call checksum::CalcCrc [DataFF 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (call checksum::CalcCrc [DataInc 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (checksum::CalcCrc [Data00 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (checksum::CalcCrc [Data55 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (checksum::CalcCrc [DataAA 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (checksum::CalcCrc [DataFF 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])
(fmt::print! [(as (checksum::CalcCrc [DataInc 0 (& Crc32cTab)]) fmt::u32_hex) "\n"])

@doc "test end"
(test::Success!)
Expand Down
44 changes: 22 additions & 22 deletions FrontEnd/Lib/fmt.cw
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(param options (ptr @mut SysFormatOptions))] uint :
(let s auto (? v (as "true" (slice u8)) (as "false" (slice u8))))
(let n uint (min (len buffer) (len s)))
(return (call mymemcpy [
(return (mymemcpy [
(front @mut buffer)
(front s)
n])))
Expand Down Expand Up @@ -64,7 +64,7 @@
(continue)
:))
(let n uint (min (- $max_width $pos) (len $out_eval)))
(return (call mymemcpy [
(return (mymemcpy [
(front @mut $out_eval)
(incp (front $tmp) $pos)
n]))))
Expand Down Expand Up @@ -98,7 +98,7 @@
(if (< v 0) :
(let v_unsigned auto (- 0_s32 v))
(= (at out 0) '-')
(return (+ 1 (unsigned_to_str! v_unsigned 10 32_uint (call slice_incp [out 1]))))
(return (+ 1 (unsigned_to_str! v_unsigned 10 32_uint (slice_incp [out 1]))))
:
(return (unsigned_to_str! (as v u32) 10 32_uint out))))

Expand All @@ -116,43 +116,43 @@
(param v u8)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call u8_to_str [v out])))
(return (u8_to_str [v out])))


(fun @polymorphic SysRender [
(param v u16)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call u16_to_str [v out])))
(return (u16_to_str [v out])))


(fun @polymorphic SysRender [
(param v u32)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call u32_to_str [v out])))
(return (u32_to_str [v out])))


(fun @polymorphic SysRender [
(param v u64)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call u64_to_str [v out])))
(return (u64_to_str [v out])))


(fun @polymorphic SysRender [
(param v s32)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call s32_to_str [v out])))
(return (s32_to_str [v out])))


(fun @polymorphic SysRender [
(param v (slice u8))
(param buffer (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(let n uint (min (len buffer) (len v)))
(return (call mymemcpy [
(return (mymemcpy [
(front @mut buffer)
(front v)
n])))
Expand All @@ -175,19 +175,19 @@
(param v u32_hex)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call u32_to_hex_str [(as v u32) out])))
(return (u32_to_hex_str [(as v u32) out])))

(fun @polymorphic SysRender [
(param v u16_hex)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call u16_to_hex_str [(as v u16) out])))
(return (u16_to_hex_str [(as v u16) out])))

(fun @polymorphic SysRender [
(param v u8_hex)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call u8_to_hex_str [(as v u8) out])))
(return (u8_to_hex_str [(as v u8) out])))


(type @pub @wrapped rune u8)
Expand Down Expand Up @@ -218,7 +218,7 @@

(fun slice_copy [(param src (slice u8)) (param dst (slice @mut u8))] uint :
(let n uint (min (len src) (len dst)))
(return (call mymemcpy [
(return (mymemcpy [
(front @mut dst)
(front src)
n])))
Expand All @@ -230,14 +230,14 @@
(param out (slice @mut u8))] uint :
(if frac_is_zero :
(if is_non_neg :
(return (call slice_copy [INF_POS out]))
(return (slice_copy [INF_POS out]))
:
(return (call slice_copy [INF_NEG out])))
(return (slice_copy [INF_NEG out])))
:
(if is_non_neg :
(return (call slice_copy [NAN_POS out]))
(return (slice_copy [NAN_POS out]))
:
(return (call slice_copy [NAN_NEG out])))))
(return (slice_copy [NAN_NEG out])))))


@doc """r64 format (IEEE 754): sign (1 bit) exponent (11 bits) fraction (52 bits)
Expand All @@ -250,7 +250,7 @@
(let exp_bits auto (and (>> val_bits 52) 0x7ff))
(let sign_bit auto (and (>> val_bits 63) 1))
(if (== exp_bits 0x7ff) :
(return (call nan_to_str [
(return (nan_to_str [
(== sign_bit 0)
(== frac_bits 0)
out]))
Expand Down Expand Up @@ -284,7 +284,7 @@
(= exp (- 0_s64 exp))
:)
(let rest auto (slice_val (incp buf i) (- (len out) i)))
(+= i (call u64_to_str [(as exp u64) rest]))
(+= i (u64_to_str [(as exp u64) rest]))
(return i))


Expand All @@ -295,7 +295,7 @@
(param v r64_hex)
(param out (slice @mut u8))
(param options (ptr @mut SysFormatOptions))] uint :
(return (call r64_to_hex_str [(as v r64) out])))
(return (r64_to_hex_str [(as v r64) out])))


(macro @pub print! STMT_LIST [
Expand All @@ -305,11 +305,11 @@
(macro_let @mut $curr uint 0)
(macro_let @mut @ref $options auto (rec_val SysFormatOptions []))
(macro_for $i $parts :
(+= $curr (call @polymorphic SysRender [
(+= $curr (@polymorphic SysRender [
$i
(slice_val (incp (front @mut $buffer) $curr) (- (len $buffer) $curr))
(& @mut $options)])))
(stmt (call os::write [(as os::Stdout s32) (front $buffer) $curr])))
(stmt (os::write [(as os::Stdout s32) (front $buffer) $curr])))


(fun @pub strz_to_slice [(param s (ptr u8))] (slice u8) :
Expand Down
6 changes: 3 additions & 3 deletions FrontEnd/Lib/os.cw
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

(fun @pub FileWrite [
(param fd FD) (param buffer (slice u8))] (union [uint Error]) :
(let res auto (call write [(as fd s32) (front buffer) (len buffer)]))
(let res auto (write [(as fd s32) (front buffer) (len buffer)]))
(if (< res 0) :
(return (as (as res s32) Error))
:
Expand All @@ -39,7 +39,7 @@

(fun @pub FileRead [
(param fd FD) (param buffer (slice @mut u8))] (union [uint Error]):
(let res auto (call read [(as fd s32) (front @mut buffer) (len buffer)]))
(let res auto (read [(as fd s32) (front @mut buffer) (len buffer)]))
(if (< res 0) :
(return (as (as res s32) Error))
:
Expand All @@ -50,7 +50,7 @@

(fun @pub TimeNanoSleep [(param req (ptr TimeSpec))
(param rem (ptr @mut TimeSpec))] Error :
(let res auto (call nanosleep [req rem]))
(let res auto (nanosleep [req rem]))
(return (as res Error))
)

Expand Down
Loading

0 comments on commit 6d02b58

Please sign in to comment.