Skip to content

Commit

Permalink
feat: equals string
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Oct 12, 2024
1 parent 337f216 commit 3723373
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
15 changes: 13 additions & 2 deletions crates/uplc/src/machine/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,21 @@ impl<'a> Runtime<'a> {
Ok(value)
}
DefaultFunction::AppendString => todo!(),
DefaultFunction::EqualsString => todo!(),
DefaultFunction::EqualsString => {
let arg1 = self.args[0].unwrap_string()?;
let arg2 = self.args[1].unwrap_string()?;

let value = Value::bool(arena, arg1 == arg2);

Ok(value)
}
DefaultFunction::EncodeUtf8 => todo!(),
DefaultFunction::DecodeUtf8 => todo!(),
DefaultFunction::ChooseUnit => todo!(),
DefaultFunction::ChooseUnit => {
self.args[0].unwrap_unit()?;

Ok(self.args[1])
}
DefaultFunction::Trace => todo!(),
DefaultFunction::FstPair => {
let (_, _, first, _) = self.args[0].unwrap_pair()?;
Expand Down
16 changes: 14 additions & 2 deletions crates/uplc/src/machine/value.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use bumpalo::Bump;
use bumpalo::{
collections::{String as BumpString, Vec as BumpVec},
Bump,
};

use crate::{
constant::{Constant, Integer},
term::Term,
typ::Type,
};
use bumpalo::collections::Vec as BumpVec;

use super::{env::Env, runtime::Runtime, MachineError};

Expand Down Expand Up @@ -98,6 +100,16 @@ impl<'a> Value<'a> {
Ok(byte_string)
}

pub fn unwrap_string(&'a self) -> Result<&BumpString<'a>, MachineError<'a>> {
let inner = self.unwrap_constant()?;

let Constant::String(string) = inner else {
return Err(MachineError::type_mismatch(Type::String, inner));
};

Ok(string)
}

pub fn unwrap_bool(&'a self) -> Result<bool, MachineError<'a>> {
let inner = self.unwrap_constant()?;

Expand Down

0 comments on commit 3723373

Please sign in to comment.