Skip to content

Commit

Permalink
feat(vm): Add Char <-> Int conversion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Mar 30, 2018
1 parent ecbbc13 commit 620df40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/pass/char.glu
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let { run, Test, assert_eq, test, group, ? } = import! std.test
let { (<|) } = import! std.function
let prelude = import! std.prelude
let { Applicative, (*>), ? } = import! std.applicative
let char @ { ? } = import! std.char

group "char" [
test "from_int" <| \_ -> assert_eq (char.from_int 97) (Some 'a'),
test "from_int_error" <| \_ -> assert_eq (char.from_int 0x110000) None,
test "to_int" <| \_ -> assert_eq (char.to_int 'a') 97,
]
2 changes: 2 additions & 0 deletions vm/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ pub fn load_char(vm: &Thread) -> Result<ExternModule> {
ExternModule::new(
vm,
record! {
from_int => named_primitive!(1, "std.char.prim.from_int", ::std::char::from_u32),
to_int => named_primitive!(1, "std.char.prim.to_int", |c: char| c as u32),
is_digit => primitive!(2 std::char::prim::is_digit),
to_digit => primitive!(2 std::char::prim::to_digit),
len_utf8 => primitive!(1 std::char::prim::len_utf8),
Expand Down

0 comments on commit 620df40

Please sign in to comment.