Skip to content

Commit

Permalink
add parsing binarys to lisp syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
CrowdHailer committed Oct 11, 2023
1 parent 3cc705e commit 70a27e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eyg/saved/saved.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions eyg/src/harness/ffi/core.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pub fn lib() {
|> extend("capture", capture())
|> extend("encode_uri", encode_uri())
|> extend("base64_encode", base64_encode())
// binary
|> extend("binary_from_integers", binary_from_integers())
// integer
|> extend("int_add", integer.add())
|> extend("int_subtract", integer.subtract())
Expand Down Expand Up @@ -366,3 +368,22 @@ pub fn do_base64_encode(term, rev, env, k) {
k,
)
}

pub fn binary_from_integers() {
let type_ = t.Fun(t.LinkedList(t.Integer), t.Open(-1), t.Binary)
#(type_, r.Arity1(do_binary_from_integers))
}

pub fn do_binary_from_integers(term, rev, env, k) {
use parts <- cast.require(cast.list(term), rev, env, k)
let content =
list.fold(
list.reverse(parts),
<<>>,
fn(acc, el) {
let assert r.Integer(i) = el
<<i, acc:bit_string>>
},
)
r.prim(r.Value(r.Binary(content)), rev, env, k)
}

0 comments on commit 70a27e6

Please sign in to comment.