Skip to content

Commit

Permalink
Forward op overrides in Val
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 17, 2024
1 parent 0bbf100 commit 731e34c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions valuescript_vm/src/vs_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,48 @@ impl ValTrait for Val {
op_submov(self, key, value)
}

fn override_binary_op(&self, op: BinaryOp, right: &Val) -> Option<Result<Val, Val>> {
match self {
Val::Void
| Val::Undefined
| Val::Null
| Val::Bool(_)
| Val::Number(_)
| Val::BigInt(_)
| Val::Symbol(_)
| Val::String(_)
| Val::Array(_)
| Val::Object(_)
| Val::Function(_)
| Val::Class(_)
| Val::CopyCounter(_)
| Val::StoragePtr(_) => None,
Val::Static(static_) => static_.override_binary_op(op, right),
Val::Dynamic(dynamic) => dynamic.override_binary_op(op, right),
}
}

fn override_unary_op(&self, op: UnaryOp) -> Option<Result<Val, Val>> {
match self {
Val::Void
| Val::Undefined
| Val::Null
| Val::Bool(_)
| Val::Number(_)
| Val::BigInt(_)
| Val::Symbol(_)
| Val::String(_)
| Val::Array(_)
| Val::Object(_)
| Val::Function(_)
| Val::Class(_)
| Val::CopyCounter(_)
| Val::StoragePtr(_) => None,
Val::Static(static_) => static_.override_unary_op(op),
Val::Dynamic(dynamic) => dynamic.override_unary_op(op),
}
}

fn pretty_fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.pretty(), f)
}
Expand Down

0 comments on commit 731e34c

Please sign in to comment.