mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Represent class as just a value in the assembly
This commit is contained in:
@@ -72,7 +72,6 @@ impl std::fmt::Display for Definition {
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DefinitionContent {
|
||||
Function(Function),
|
||||
Class(Class),
|
||||
Value(Value),
|
||||
Lazy(Lazy),
|
||||
}
|
||||
@@ -83,9 +82,6 @@ impl std::fmt::Display for DefinitionContent {
|
||||
DefinitionContent::Function(function) => {
|
||||
write!(f, "{}", function)
|
||||
}
|
||||
DefinitionContent::Class(class) => {
|
||||
write!(f, "{}", class)
|
||||
}
|
||||
DefinitionContent::Value(value) => {
|
||||
write!(f, "{}", value)
|
||||
}
|
||||
|
||||
@@ -55,9 +55,6 @@ impl Assembler {
|
||||
DefinitionContent::Function(function) => {
|
||||
self.function(function);
|
||||
}
|
||||
DefinitionContent::Class(class) => {
|
||||
self.class(class);
|
||||
}
|
||||
DefinitionContent::Value(value) => {
|
||||
self.value(value);
|
||||
}
|
||||
|
||||
@@ -184,7 +184,6 @@ impl<'a> AssemblyParser<'a> {
|
||||
|
||||
let content = match c {
|
||||
'f' => DefinitionContent::Function(self.assemble_function()),
|
||||
'c' => DefinitionContent::Class(self.assemble_class()),
|
||||
_ => DefinitionContent::Value(self.assemble_value()),
|
||||
};
|
||||
|
||||
@@ -781,6 +780,7 @@ impl<'a> AssemblyParser<'a> {
|
||||
Some('-' | '.' | '0'..='9') => self.assemble_number(),
|
||||
Some('"') => Value::String(self.parse_string_literal()),
|
||||
Some('{') => Value::Object(Box::new(self.assemble_object())),
|
||||
Some('c') => Value::Class(Box::new(self.assemble_class())),
|
||||
Some(ref_c) => {
|
||||
let c = *ref_c;
|
||||
|
||||
|
||||
@@ -885,11 +885,11 @@ impl ModuleCompiler {
|
||||
|
||||
self.module.definitions.push(Definition {
|
||||
pointer: defn_name.clone(),
|
||||
content: DefinitionContent::Class(Class {
|
||||
content: DefinitionContent::Value(Value::Class(Box::new(Class {
|
||||
constructor,
|
||||
prototype: Value::Object(Box::new(prototype)),
|
||||
static_: Value::Object(Box::new(static_)),
|
||||
}),
|
||||
}))),
|
||||
});
|
||||
|
||||
self.module.definitions.append(&mut dependent_definitions);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
||||
use std::mem::take;
|
||||
|
||||
use crate::asm::Module;
|
||||
use crate::asm::{Definition, DefinitionContent, Pointer};
|
||||
use crate::asm::{Module, Value};
|
||||
use crate::visit_pointers::{visit_pointers, PointerVisitation};
|
||||
|
||||
pub fn shake_tree(module: &mut Module) {
|
||||
@@ -65,7 +65,7 @@ pub fn shake_tree(module: &mut Module) {
|
||||
|
||||
// First include pointers that are allowed to be circular
|
||||
match &defn.content {
|
||||
DefinitionContent::Function(..) | DefinitionContent::Class(..) => {}
|
||||
DefinitionContent::Function(..) | DefinitionContent::Value(Value::Class(..)) => {}
|
||||
DefinitionContent::Value(..) | DefinitionContent::Lazy(..) => continue,
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ pub fn simplify(module: &mut Module, take_registers: bool) {
|
||||
DefinitionContent::Function(fn_) => {
|
||||
simplify_fn(FnState::new(fn_, pointer_kals.clone()), fn_, take_registers)
|
||||
}
|
||||
DefinitionContent::Class(_) => {}
|
||||
DefinitionContent::Value(_) => {}
|
||||
DefinitionContent::Lazy(_) => {}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,6 @@ where
|
||||
DefinitionContent::Function(function) => {
|
||||
self.body(&definition.pointer, &mut function.body);
|
||||
}
|
||||
DefinitionContent::Class(class) => {
|
||||
self.value(Some(&definition.pointer), &mut class.constructor);
|
||||
self.value(Some(&definition.pointer), &mut class.prototype);
|
||||
self.value(Some(&definition.pointer), &mut class.static_);
|
||||
}
|
||||
DefinitionContent::Value(value) => {
|
||||
self.value(Some(&definition.pointer), value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user