Skip to content

Commit

Permalink
Represent class as just a value in the assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 25, 2023
1 parent ed0d266 commit 200607f
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 18 deletions.
4 changes: 0 additions & 4 deletions valuescript_compiler/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ impl std::fmt::Display for Definition {
#[derive(Debug, Clone)]
pub enum DefinitionContent {
Function(Function),
Class(Class),
Value(Value),
Lazy(Lazy),
}
Expand All @@ -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)
}
Expand Down
3 changes: 0 additions & 3 deletions valuescript_compiler/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ impl Assembler {
DefinitionContent::Function(function) => {
self.function(function);
}
DefinitionContent::Class(class) => {
self.class(class);
}
DefinitionContent::Value(value) => {
self.value(value);
}
Expand Down
2 changes: 1 addition & 1 deletion valuescript_compiler/src/assembly_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
};

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions valuescript_compiler/src/module_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions valuescript_compiler/src/optimization/shake_tree.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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,
}

Expand Down
1 change: 0 additions & 1 deletion valuescript_compiler/src/optimization/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
}
Expand Down
5 changes: 0 additions & 5 deletions valuescript_compiler/src/visit_pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 200607f

Please sign in to comment.