Implement direct class comparison

This commit is contained in:
Andrew Morris
2023-08-16 15:30:25 +10:00
parent 5d1da13903
commit d49937663c
12 changed files with 75 additions and 30 deletions

View File

@@ -197,6 +197,7 @@ impl Assembler {
fn class(&mut self, class: &Class) {
self.output.push(ValueType::Class as u8);
self.meta(&class.meta);
self.value(&class.constructor);
self.value(&class.prototype);
self.value(&class.static_);

View File

@@ -256,6 +256,11 @@ impl Kal {
}
Kal::Function(_) => return None,
Kal::Class(class) => VsClass {
name: class.meta.name,
content_hash: match class.meta.content_hashable {
asm::ContentHashable::Empty | asm::ContentHashable::Src(_, _) => None,
asm::ContentHashable::Content(hash) => Some(hash.0),
},
constructor: class.constructor.try_to_val()?,
prototype: class.prototype.try_to_val()?,
static_: class.static_.try_to_val()?,

View File

@@ -6,7 +6,7 @@ use valuescript_vm::{
vs_value::{ToVal, Val},
};
use crate::asm::{Number, Value};
use crate::asm::{ContentHashable, Number, Value};
pub trait TryToVal {
fn try_to_val(self) -> Result<Val, Val>;
@@ -45,6 +45,11 @@ impl TryToVal for Value {
.to_val()
}
Value::Class(class) => VsClass {
name: class.meta.name,
content_hash: match class.meta.content_hashable {
ContentHashable::Empty | ContentHashable::Src(_, _) => None,
ContentHashable::Content(hash) => Some(hash.0),
},
constructor: class.constructor.try_to_val()?,
prototype: class.prototype.try_to_val()?,
static_: class.static_.try_to_val()?,