Skip to content

Commit

Permalink
make cast operators more systematic
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed Jun 27, 2024
1 parent bea1e4c commit d27a2b0
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion FrontEnd/LangTest/heapsort_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
(@ref let! buf (array 32 u8) undef)
(for i 0 size 1 :
(let v auto (^ (pinc data i)))
(fmt::print# (wrapas v fmt::r64_hex) NEWLINE))
(fmt::print# (wrap_as v fmt::r64_hex) NEWLINE))
(return))


Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/LangTest/linked_list_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(@wrapped type NoneType void)


@pub (global None auto (wrapas void_val NoneType))
@pub (global None auto (wrap_as void_val NoneType))


@pub (defrec LinkedListNode :
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/Lib/bytestream.cw
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pub (@wrapped type OutOfBoundsError void)


@pub (global OutOfBoundsErrorVal auto (wrapas void_val OutOfBoundsError))
@pub (global OutOfBoundsErrorVal auto (wrap_as void_val OutOfBoundsError))


@doc ""
Expand Down
8 changes: 4 additions & 4 deletions FrontEnd/Lib/flate.cw
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@
@pub (@wrapped type CorruptionError void)


@pub (global CorruptionErrorVal auto (wrapas void_val CorruptionError))
@pub (global CorruptionErrorVal auto (wrap_as void_val CorruptionError))


@doc "the input bitstream was truncated"
@pub (@wrapped type TruncationError void)


@pub (global TruncationErrorVal auto (wrapas void_val TruncationError))
@pub (global TruncationErrorVal auto (wrap_as void_val TruncationError))


@doc "the provided output buffer was not large enough"
@pub (@wrapped type NoSpaceError void)


@pub (global NoSpaceErrorVal auto (wrapas void_val NoSpaceError))
@pub (global NoSpaceErrorVal auto (wrap_as void_val NoSpaceError))


@pub (@wrapped type Success void)


@pub (global SuccessVal auto (wrapas void_val Success))
@pub (global SuccessVal auto (wrap_as void_val Success))


(global MAX_HUFFMAN_BITS u16 15)
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/Lib/fmt.cw
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
(param v (ptr void))
(param out (slice! u8))
(param options (ptr! SysFormatOptions))] uint :
(let h auto (wrapas (bitwise_as v uint) uint_hex))
(let h auto (wrap_as (bitwise_as v uint) uint_hex))
(return (SysRender@ [h out options])))


Expand Down
6 changes: 3 additions & 3 deletions FrontEnd/Lib/fmt_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
(test::AssertSliceEq# (slice_val (front s) n) "69")
(= n (fmt::SysRender@ [-69_s32 s (&! opt)]))
(test::AssertSliceEq# (slice_val (front s) n) "-69")
(= n (fmt::SysRender@ [(wrapas 120 fmt::rune) s (&! opt)]))
(= n (fmt::SysRender@ [(wrap_as 120 fmt::rune) s (&! opt)]))
(test::AssertSliceEq# (slice_val (front s) n) "x")
(= n (fmt::SysRender@ [(wrapas 2 fmt::r64_hex) s (&! opt)]))
(= n (fmt::SysRender@ [(wrap_as 2 fmt::r64_hex) s (&! opt)]))
(test::AssertSliceEq# (slice_val (front s) n) "0x1.p1")
(= n (fmt::SysRender@ [color:blue s (&! opt)]))
(test::AssertSliceEq# (slice_val (front s) n) "2")
Expand All @@ -65,7 +65,7 @@
s
(&! opt)]))
(test::AssertSliceEq# (slice_val (front s) n) "111+222i")
(= n (fmt::SysRender@ [(wrapas test_string fmt::str_hex) s (&! opt)]))
(= n (fmt::SysRender@ [(wrap_as test_string fmt::str_hex) s (&! opt)]))
(test::AssertSliceEq# (slice_val (front s) n) "7177657274795f31323334")
@doc "test end"
(test::Success#)
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/Lib/heapsort_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(@ref let! buf (array 32 u8) undef)
(for i 0 size 1 :
(let v auto (^ (pinc data i)))
(fmt::print# (wrapas v fmt::r64_hex) NEWLINE))
(fmt::print# (wrap_as v fmt::r64_hex) NEWLINE))
(return))


Expand Down
12 changes: 6 additions & 6 deletions FrontEnd/Lib/os.cw
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@
@pub (@wrapped type FD s32)


@pub (global Stdin auto (wrapas 0 FD))
@pub (global Stdin auto (wrap_as 0 FD))


@pub (global Stdout auto (wrapas 1 FD))
@pub (global Stdout auto (wrap_as 1 FD))


@pub (global Stderr auto (wrapas 2 FD))
@pub (global Stderr auto (wrap_as 2 FD))


@pub (fun FileWrite [(param fd FD) (param buffer (slice u8))] (union [uint Error]) :
(let res auto (write [(unwrap fd) (front buffer) (len buffer)]))
(if (< res 0) :
(return (wrapas (as res s32) Error))
(return (wrap_as (as res s32) Error))
:
(return (as res uint))))


@pub (fun FileRead [(param fd FD) (param buffer (slice! u8))] (union [uint Error]) :
(let res auto (read [(unwrap fd) (front! buffer) (len buffer)]))
(if (< res 0) :
(return (wrapas (as res s32) Error))
(return (wrap_as (as res s32) Error))
:
(return (as res uint))))


@pub (fun TimeNanoSleep [(param req (ptr TimeSpec)) (param rem (ptr! TimeSpec))] Error :
(let res auto (nanosleep [req rem]))
(return (wrapas res Error)))
(return (wrap_as res Error)))
)

2 changes: 1 addition & 1 deletion FrontEnd/Lib/sha3.cw
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ https://emn178.github.io/online-tools/sha3_512.html
(fmt::print# tag "\n")
(for i 0 5_uint 1 :
(for j 0 5_uint 1 :
(fmt::print# " " (wrapas (at (^ x) (+ i (* j 5))) fmt::u64_hex)))
(fmt::print# " " (wrap_as (at (^ x) (+ i (* j 5))) fmt::u64_hex)))
(fmt::print# "\n")))


Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/Lib/sha3_test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ If not you're just wasting my time
(do (test_Keccak512 []))
(do (test_Sha3512 []))
@doc """(let hash auto (sha3::Keccak512 [limerick]))
(fmt::print# (wrapas hash fmt::str_hex) "\n")"""
(fmt::print# (wrap_as hash fmt::str_hex) "\n")"""
(test::Success#)
(return 0))
)
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/TestData/ascii_anim.cw
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
(fmt::print# (get_fg_color [a]) (get_style [a]))
:)
(= last_attr a)
(fmt::print# (wrapas c fmt::rune)))))
(fmt::print# (wrap_as c fmt::rune)))))


@pub (fun window_fill [
Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/cwast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ def __repr__(self):
class ExprWrap:
"""Cast: underlying type -> enum/wrapped
"""
ALIAS = "wrapas"
ALIAS = "wrap_as"
GROUP = GROUP.Expression
FLAGS = NF_EXPR
#
Expand Down

0 comments on commit d27a2b0

Please sign in to comment.