diff --git a/compiler/cl-interpret/src/builtin.rs b/compiler/cl-interpret/src/builtin.rs index a16f2a3..8c28d26 100644 --- a/compiler/cl-interpret/src/builtin.rs +++ b/compiler/cl-interpret/src/builtin.rs @@ -32,6 +32,7 @@ builtins! { } Ok(ConValue::Empty) } + /// Unstable variadic println function pub fn println<_, args> () -> IResult { let mut out = stdout().lock(); @@ -41,6 +42,7 @@ builtins! { writeln!(out).ok(); Ok(ConValue::Empty) } + /// Prints the [Debug](std::fmt::Debug) version of the input values pub fn dbg<_, args> () -> IResult { let mut out = stdout().lock(); @@ -49,6 +51,7 @@ builtins! { } Ok(args.into()) } + /// Dumps info from the environment pub fn dump() -> IResult { println!("{}", *env); @@ -65,6 +68,7 @@ builtins! { _ => Err(Error::TypeError)? }) } + /// Division `a / b` pub fn div(lhs, rhs) -> IResult { Ok(match (lhs, rhs){ @@ -73,6 +77,7 @@ builtins! { _ => Err(Error::TypeError)? }) } + /// Remainder `a % b` pub fn rem(lhs, rhs) -> IResult { Ok(match (lhs, rhs) { @@ -91,6 +96,7 @@ builtins! { _ => Err(Error::TypeError)? }) } + /// Subtraction `a - b` pub fn sub(lhs, rhs) -> IResult { Ok(match (lhs, rhs) { @@ -108,6 +114,7 @@ builtins! { _ => Err(Error::TypeError)?, }) } + /// Shift Right `a >> b` pub fn shr(lhs, rhs) -> IResult { Ok(match (lhs, rhs) { @@ -126,6 +133,7 @@ builtins! { _ => Err(Error::TypeError)?, }) } + /// Bitwise Or `a | b` pub fn or(lhs, rhs) -> IResult { Ok(match (lhs, rhs) { @@ -135,6 +143,7 @@ builtins! { _ => Err(Error::TypeError)?, }) } + /// Bitwise Exclusive Or `a ^ b` pub fn xor(lhs, rhs) -> IResult { Ok(match (lhs, rhs) { @@ -149,22 +158,27 @@ builtins! { pub fn lt(lhs, rhs) -> IResult { cmp!(lhs, rhs, false, <) } + /// Tests whether `a <= b` pub fn lt_eq(lhs, rhs) -> IResult { cmp!(lhs, rhs, true, <=) } + /// Tests whether `a == b` pub fn eq(lhs, rhs) -> IResult { cmp!(lhs, rhs, true, ==) } + /// Tests whether `a != b` pub fn neq(lhs, rhs) -> IResult { cmp!(lhs, rhs, false, !=) } + /// Tests whether `a <= b` pub fn gt_eq(lhs, rhs) -> IResult { cmp!(lhs, rhs, true, >=) } + /// Tests whether `a < b` pub fn gt(lhs, rhs) -> IResult { cmp!(lhs, rhs, false, >) @@ -179,6 +193,7 @@ builtins! { }; Ok(ConValue::RangeExc(lhs, rhs.saturating_sub(1))) } + /// Inclusive Range `a..=b` pub fn range_inc(lhs, rhs) -> IResult { let (&ConValue::Int(lhs), &ConValue::Int(rhs)) = (lhs, rhs) else { @@ -197,6 +212,7 @@ builtins! { _ => Err(Error::TypeError)?, }) } + /// Inverts the ConValue pub fn not(tail) -> IResult { Ok(match tail { @@ -206,6 +222,7 @@ builtins! { _ => Err(Error::TypeError)?, }) } + pub fn deref(tail) -> IResult { Ok(match tail { ConValue::Ref(v) => Rc::as_ref(v).clone(),