cli: add recoverable endian APIs and qualified std enums
This commit is contained in:
45 files changed
+1205
-89
No files matched your search
@@ -0,0 +1,16 @@
|
||||
; expect: reject E1001
|
||||
; phase: 0
|
||||
; spec: docs/spec/07a-air-instructions.md; docs/spec/16-standard-library.md §2.3
|
||||
module test.endian_payload_type
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
|
||||
type @ReadU16 = enum { ok(u16), short_input }
|
||||
|
||||
fn @main() -> @ReadU16
|
||||
effects []
|
||||
entry:
|
||||
%wrong = const.u32 4660
|
||||
%result = enum.make @ReadU16.ok(%wrong)
|
||||
ret %result
|
||||
@@ -0,0 +1,63 @@
|
||||
; expect: run
|
||||
; result: {"variant":"ok","payload":[4660]}
|
||||
; phase: 1
|
||||
; spec: docs/spec/16-standard-library.md §2.3; docs/spec/07a-air-instructions.md
|
||||
module test.endian_read
|
||||
air 0
|
||||
lang 0.1
|
||||
features [arrays, ownership]
|
||||
|
||||
type @ReadU16 = enum { ok(u16), short_input }
|
||||
|
||||
fn @main() -> @ReadU16
|
||||
effects []
|
||||
entry:
|
||||
%storage = local.alloc array<u8, 2>
|
||||
local.zero %storage
|
||||
%m = borrow.mut %storage
|
||||
%dst = slice.make %m
|
||||
%zero = const.usize 0
|
||||
%one = const.usize 1
|
||||
%lo = const.u8 52
|
||||
%hi = const.u8 18
|
||||
%d0 = borrow.index %dst, %zero
|
||||
store %d0, %lo
|
||||
borrow.end %d0
|
||||
%d1 = borrow.index %dst, %one
|
||||
store %d1, %hi
|
||||
borrow.end %d1
|
||||
borrow.end %dst
|
||||
borrow.end %m
|
||||
%r = borrow.ref %storage
|
||||
%src = slice.make %r
|
||||
%result = call @read_u16_le(%src)
|
||||
borrow.end %src
|
||||
borrow.end %r
|
||||
ret %result
|
||||
|
||||
fn @read_u16_le(%src: slice<u8>) -> @ReadU16
|
||||
effects []
|
||||
entry:
|
||||
%n = slice.len %src
|
||||
%two = const.usize 2
|
||||
%short = lt.usize %n, %two
|
||||
cbr %short, @short_input(), @decode()
|
||||
short_input:
|
||||
%failure = enum.make @ReadU16.short_input()
|
||||
ret %failure
|
||||
decode:
|
||||
%zero = const.usize 0
|
||||
%one = const.usize 1
|
||||
%e0 = borrow.index %src, %zero
|
||||
%b0 = load %e0
|
||||
borrow.end %e0
|
||||
%e1 = borrow.index %src, %one
|
||||
%b1 = load %e1
|
||||
borrow.end %e1
|
||||
%lo = cast.checked.u16 %b0
|
||||
%hi = cast.checked.u16 %b1
|
||||
%eight = const.u16 8
|
||||
%shifted = shl.u16 %hi, %eight
|
||||
%value = or.u16 %lo, %shifted
|
||||
%success = enum.make @ReadU16.ok(%value)
|
||||
ret %success
|
||||
Reference in new issue
Block a user