Skip to content

Commit

Permalink
Add support for builtin Byte (#118)
Browse files Browse the repository at this point in the history
> ⚠️ Depends on:
> * #117
> * anoma/juvix#2918

Adds support for the builtin Byte type introduced in:
* anoma/juvix#2918
  • Loading branch information
paulcadman authored Aug 5, 2024
1 parent 5a4c63a commit 5424a48
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Stdlib/Data/Byte.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Stdlib.Data.Byte;

import Stdlib.Data.Byte.Base open using {Byte} public;
import Stdlib.Data.Byte.Base as Byte public;
import Stdlib.Function open;
import Stdlib.Data.Nat;
import Stdlib.Data.String.Base open;

import Stdlib.Trait.Eq open public;
import Stdlib.Trait.FromNatural open;
import Stdlib.Trait.Show open public;

{-# specialize: true, inline: case #-}
instance
eqByteI : Eq Byte := mkEq (Byte.==);

instance
showByteI : Show Byte :=
mkShow@{
show := Byte.toNat >> Show.show
};

{-# specialize: true, inline: case #-}
instance
fromNaturalByteI : FromNatural Byte :=
mkFromNatural@{
fromNat := Byte.fromNat
};
22 changes: 22 additions & 0 deletions Stdlib/Data/Byte/Base.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Stdlib.Data.Byte.Base;

import Stdlib.Data.Bool.Base open;
import Stdlib.Data.Fixity open;
import Stdlib.Data.Nat.Base open;

--- An 8-bit unsigned integer.
builtin byte
axiom Byte : Type;

--- Converts a ;Nat; to a ;Byte;. It takes the modulus of the input natural number with 256.
builtin byte-from-nat
axiom fromNat : Nat -> Byte;

--- Converts a ;Byte; to the corresponding ;Nat;.
builtin byte-to-nat
axiom toNat : Byte -> Nat;

syntax operator == comparison;

builtin byte-eq
axiom == : Byte -> Byte -> Bool;
1 change: 1 addition & 0 deletions Stdlib/Prelude.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Stdlib.Prelude;
import Stdlib.Data.Fixity open public;

import Stdlib.Data.Bool open public;
import Stdlib.Data.Byte open public;
import Stdlib.Data.Unit open public;
import Stdlib.Data.List open public;
import Stdlib.Data.Maybe open public;
Expand Down

0 comments on commit 5424a48

Please sign in to comment.