mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
metadata, fn_meta -> meta
This commit is contained in:
@@ -244,7 +244,7 @@ impl StructuredFormattable for Definition {
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DefinitionContent {
|
||||
Function(Function),
|
||||
FnMeta(FnMeta),
|
||||
Meta(Meta),
|
||||
Value(Value),
|
||||
Lazy(Lazy),
|
||||
}
|
||||
@@ -253,7 +253,7 @@ impl StructuredFormattable for DefinitionContent {
|
||||
fn structured_fmt(&self, sf: &mut StructuredFormatter<'_, '_>) -> std::fmt::Result {
|
||||
match self {
|
||||
DefinitionContent::Function(function) => sf.write(function),
|
||||
DefinitionContent::FnMeta(fn_meta) => sf.write(fn_meta),
|
||||
DefinitionContent::Meta(meta) => sf.write(meta),
|
||||
DefinitionContent::Value(value) => sf.write(value),
|
||||
DefinitionContent::Lazy(lazy) => sf.write(lazy),
|
||||
}
|
||||
@@ -261,14 +261,14 @@ impl StructuredFormattable for DefinitionContent {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
|
||||
pub struct FnMeta {
|
||||
pub struct Meta {
|
||||
pub name: String,
|
||||
pub content_hashable: ContentHashable,
|
||||
}
|
||||
|
||||
impl StructuredFormattable for FnMeta {
|
||||
impl StructuredFormattable for Meta {
|
||||
fn structured_fmt(&self, sf: &mut StructuredFormatter<'_, '_>) -> std::fmt::Result {
|
||||
sf.write("fn_meta {")?;
|
||||
sf.write("meta {")?;
|
||||
|
||||
sf.nest(|sf| {
|
||||
sf.write_line(&[
|
||||
@@ -339,21 +339,21 @@ impl StructuredFormattable for Pointer {
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Function {
|
||||
pub is_generator: bool,
|
||||
pub metadata: Option<Pointer>,
|
||||
pub meta: Option<Pointer>,
|
||||
pub parameters: Vec<Register>,
|
||||
pub body: Vec<FnLine>,
|
||||
}
|
||||
|
||||
impl StructuredFormattable for Function {
|
||||
fn structured_fmt(&self, sf: &mut StructuredFormatter<'_, '_>) -> std::fmt::Result {
|
||||
let metadata_str = match &self.metadata {
|
||||
let meta_str = match &self.meta {
|
||||
None => "".to_string(),
|
||||
Some(p) => format!(" {}", Structured(p)),
|
||||
};
|
||||
|
||||
match self.is_generator {
|
||||
false => sf.write(&format!("function{}(", metadata_str))?,
|
||||
true => sf.write(&format!("function*{}(", metadata_str))?,
|
||||
false => sf.write(&format!("function{}(", meta_str))?,
|
||||
true => sf.write(&format!("function*{}(", meta_str))?,
|
||||
}
|
||||
|
||||
for (i, parameter) in self.parameters.iter().enumerate() {
|
||||
@@ -384,7 +384,7 @@ impl StructuredFormattable for Function {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Class {
|
||||
pub metadata: FnMeta,
|
||||
pub meta: Meta,
|
||||
pub constructor: Value,
|
||||
pub prototype: Value,
|
||||
pub static_: Value,
|
||||
@@ -395,7 +395,7 @@ impl StructuredFormattable for Class {
|
||||
sf.write("class {")?;
|
||||
|
||||
sf.nest(|sf| {
|
||||
sf.write_line(&[&"metadata: ", &self.metadata, &","])?;
|
||||
sf.write_line(&[&"meta: ", &self.meta, &","])?;
|
||||
sf.write_line(&[&"constructor: ", &self.constructor, &","])?;
|
||||
sf.write_line(&[&"prototype: ", &MultilineValue(&self.prototype), &","])?;
|
||||
sf.write_line(&[&"static: ", &MultilineValue(&self.static_), &","])?;
|
||||
|
||||
@@ -8,8 +8,8 @@ use num_bigint::{BigInt, Sign};
|
||||
use valuescript_common::BuiltinName;
|
||||
|
||||
use crate::asm::{
|
||||
Array, Builtin, Class, ContentHashable, Definition, DefinitionContent, FnLine, FnMeta, Function,
|
||||
Hash, Instruction, Label, LabelRef, Lazy, Module, Number, Object, Pointer, Register, Structured,
|
||||
Array, Builtin, Class, ContentHashable, Definition, DefinitionContent, FnLine, Function, Hash,
|
||||
Instruction, Label, LabelRef, Lazy, Meta, Module, Number, Object, Pointer, Register, Structured,
|
||||
StructuredFormattable, Value,
|
||||
};
|
||||
|
||||
@@ -63,8 +63,8 @@ impl Assembler {
|
||||
DefinitionContent::Function(function) => {
|
||||
self.function(function);
|
||||
}
|
||||
DefinitionContent::FnMeta(fn_meta) => {
|
||||
self.fn_meta(fn_meta);
|
||||
DefinitionContent::Meta(meta) => {
|
||||
self.meta(meta);
|
||||
}
|
||||
DefinitionContent::Value(value) => {
|
||||
self.value(value);
|
||||
@@ -81,7 +81,7 @@ impl Assembler {
|
||||
true => ValueType::GeneratorFunction,
|
||||
} as u8);
|
||||
|
||||
match &function.metadata {
|
||||
match &function.meta {
|
||||
Some(p) => {
|
||||
self.output.push(0x01);
|
||||
self.pointer(p);
|
||||
@@ -133,12 +133,12 @@ impl Assembler {
|
||||
self.fn_data.labels_map.resolve(&mut self.output);
|
||||
}
|
||||
|
||||
fn fn_meta(&mut self, fn_meta: &FnMeta) {
|
||||
self.output.push(ValueType::FnMeta as u8);
|
||||
fn meta(&mut self, meta: &Meta) {
|
||||
self.output.push(ValueType::Meta as u8);
|
||||
|
||||
self.string(&fn_meta.name);
|
||||
self.string(&meta.name);
|
||||
|
||||
match &fn_meta.content_hashable {
|
||||
match &meta.content_hashable {
|
||||
ContentHashable::Empty => self.output.push(0x00),
|
||||
ContentHashable::Src(src_hash, deps) => {
|
||||
self.output.push(0x01);
|
||||
@@ -504,7 +504,7 @@ pub enum ValueType {
|
||||
BigInt = 0x13,
|
||||
GeneratorFunction = 0x14,
|
||||
ExportStar = 0x15,
|
||||
FnMeta = 0x16,
|
||||
Meta = 0x16,
|
||||
// External = TBD,
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use valuescript_common::{InstructionByte, BUILTIN_NAMES};
|
||||
|
||||
use crate::asm::{
|
||||
Array, Builtin, Class, ContentHashable, Definition, DefinitionContent, ExportStar, FnLine,
|
||||
FnMeta, Function, Hash, Instruction, Label, LabelRef, Module, Number, Object, Pointer, Register,
|
||||
Function, Hash, Instruction, Label, LabelRef, Meta, Module, Number, Object, Pointer, Register,
|
||||
Value,
|
||||
};
|
||||
|
||||
@@ -186,8 +186,8 @@ impl<'a> AssemblyParser<'a> {
|
||||
break 'b DefinitionContent::Function(self.assemble_function());
|
||||
}
|
||||
|
||||
if self.test_chars("fn_meta") {
|
||||
break 'b DefinitionContent::FnMeta(self.assemble_fn_meta());
|
||||
if self.test_chars("meta") {
|
||||
break 'b DefinitionContent::Meta(self.assemble_fn_meta());
|
||||
}
|
||||
|
||||
DefinitionContent::Value(self.assemble_value())
|
||||
@@ -422,10 +422,10 @@ impl<'a> AssemblyParser<'a> {
|
||||
self.parse_whitespace();
|
||||
|
||||
if self.test_chars("(") {
|
||||
// Leave metadata as void
|
||||
// Leave meta as void
|
||||
self.parse_exact("(");
|
||||
} else {
|
||||
function.metadata = Some(self.assemble_pointer());
|
||||
function.meta = Some(self.assemble_pointer());
|
||||
self.parse_optional_whitespace();
|
||||
self.parse_exact("(");
|
||||
}
|
||||
@@ -522,8 +522,8 @@ impl<'a> AssemblyParser<'a> {
|
||||
function
|
||||
}
|
||||
|
||||
fn assemble_fn_meta(&mut self) -> FnMeta {
|
||||
self.parse_exact("fn_meta {");
|
||||
fn assemble_fn_meta(&mut self) -> Meta {
|
||||
self.parse_exact("meta {");
|
||||
self.parse_optional_whitespace();
|
||||
|
||||
self.parse_exact("name: ");
|
||||
@@ -570,7 +570,7 @@ impl<'a> AssemblyParser<'a> {
|
||||
|
||||
self.parse_exact("}");
|
||||
|
||||
FnMeta {
|
||||
Meta {
|
||||
name,
|
||||
content_hashable,
|
||||
}
|
||||
@@ -580,8 +580,8 @@ impl<'a> AssemblyParser<'a> {
|
||||
self.parse_exact("class {");
|
||||
self.parse_optional_whitespace();
|
||||
|
||||
self.parse_exact("metadata: ");
|
||||
let metadata = self.assemble_fn_meta();
|
||||
self.parse_exact("meta: ");
|
||||
let meta = self.assemble_fn_meta();
|
||||
self.parse_exact(",");
|
||||
self.parse_optional_whitespace();
|
||||
|
||||
@@ -603,7 +603,7 @@ impl<'a> AssemblyParser<'a> {
|
||||
self.parse_exact("}");
|
||||
|
||||
Class {
|
||||
metadata,
|
||||
meta,
|
||||
constructor,
|
||||
prototype,
|
||||
static_,
|
||||
|
||||
@@ -5,8 +5,8 @@ use std::mem::take;
|
||||
use swc_common::Spanned;
|
||||
|
||||
use crate::asm::{
|
||||
Builtin, ContentHashable, Definition, DefinitionContent, FnLine, FnMeta, Function, Instruction,
|
||||
Label, Pointer, Register, Value,
|
||||
Builtin, ContentHashable, Definition, DefinitionContent, FnLine, Function, Instruction, Label,
|
||||
Meta, Pointer, Register, Value,
|
||||
};
|
||||
use crate::diagnostic::{Diagnostic, DiagnosticContainer, DiagnosticReporter};
|
||||
use crate::expression_compiler::CompiledExpression;
|
||||
@@ -34,9 +34,9 @@ impl Functionish {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata(&self, mc: &ModuleCompiler) -> FnMeta {
|
||||
pub fn meta(&self, mc: &ModuleCompiler) -> Meta {
|
||||
match self {
|
||||
Functionish::Fn(ident, fn_) => FnMeta {
|
||||
Functionish::Fn(ident, fn_) => Meta {
|
||||
name: ident
|
||||
.as_ref()
|
||||
.map_or_else(|| "".to_string(), |ident| ident.sym.to_string()),
|
||||
@@ -45,14 +45,14 @@ impl Functionish {
|
||||
mc.scope_analysis.get_deps(fn_.span),
|
||||
),
|
||||
},
|
||||
Functionish::Arrow(arrow) => FnMeta {
|
||||
Functionish::Arrow(arrow) => Meta {
|
||||
name: "".to_string(),
|
||||
content_hashable: ContentHashable::Src(
|
||||
src_hash(&mc.source, arrow.span),
|
||||
mc.scope_analysis.get_deps(arrow.span),
|
||||
),
|
||||
},
|
||||
Functionish::Constructor(_, _, _constructor) => FnMeta {
|
||||
Functionish::Constructor(_, _, _constructor) => Meta {
|
||||
name: "".to_string(), // TODO: Use class name?
|
||||
content_hashable: ContentHashable::Empty, // TODO
|
||||
},
|
||||
@@ -229,12 +229,12 @@ impl<'a> FunctionCompiler<'a> {
|
||||
Functionish::Constructor(..) => false,
|
||||
};
|
||||
|
||||
let metadata_pointer = self
|
||||
let meta_ptr = self
|
||||
.mc
|
||||
.allocate_defn(&format!("{}_meta", definition_pointer.name));
|
||||
|
||||
let metadata = functionish.metadata(self.mc);
|
||||
self.fn_.metadata = Some(metadata_pointer.clone());
|
||||
let meta = functionish.meta(self.mc);
|
||||
self.fn_.meta = Some(meta_ptr.clone());
|
||||
|
||||
self.set_owner_id(functionish.owner_id());
|
||||
|
||||
@@ -324,8 +324,8 @@ impl<'a> FunctionCompiler<'a> {
|
||||
});
|
||||
|
||||
self.mc.module.definitions.push(Definition {
|
||||
pointer: metadata_pointer,
|
||||
content: DefinitionContent::FnMeta(metadata),
|
||||
pointer: meta_ptr,
|
||||
content: DefinitionContent::Meta(meta),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -396,8 +396,8 @@ fn calculate_content_hashes(module: &mut Module, _diagnostics: &mut Vec<Diagnost
|
||||
ptr_to_src_trace.insert(defn.pointer.clone(), src_meta);
|
||||
|
||||
if let DefinitionContent::Function(fn_) = &defn.content {
|
||||
if let Some(metadata_ptr) = &fn_.metadata {
|
||||
meta_to_fn.insert(metadata_ptr.clone(), defn.pointer.clone());
|
||||
if let Some(meta_ptr) = &fn_.meta {
|
||||
meta_to_fn.insert(meta_ptr.clone(), defn.pointer.clone());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -406,18 +406,18 @@ fn calculate_content_hashes(module: &mut Module, _diagnostics: &mut Vec<Diagnost
|
||||
for defn in &mut module.definitions {
|
||||
match &mut defn.content {
|
||||
DefinitionContent::Function(_) => {}
|
||||
DefinitionContent::FnMeta(fn_meta) => {
|
||||
if let ContentHashable::Src(..) = &fn_meta.content_hashable {
|
||||
DefinitionContent::Meta(meta) => {
|
||||
if let ContentHashable::Src(..) = &meta.content_hashable {
|
||||
let content_hash =
|
||||
calculate_content_hash(&ptr_to_src_trace, meta_to_fn.get(&defn.pointer).unwrap());
|
||||
|
||||
fn_meta.content_hashable = ContentHashable::Content(content_hash);
|
||||
meta.content_hashable = ContentHashable::Content(content_hash);
|
||||
}
|
||||
}
|
||||
DefinitionContent::Value(value) => {
|
||||
if let Value::Class(class) = value {
|
||||
let content_hash = calculate_content_hash(&ptr_to_src_trace, &defn.pointer);
|
||||
class.metadata.content_hashable = ContentHashable::Content(content_hash);
|
||||
class.meta.content_hashable = ContentHashable::Content(content_hash);
|
||||
}
|
||||
}
|
||||
DefinitionContent::Lazy(_) => {}
|
||||
@@ -460,22 +460,22 @@ fn find_ptr_src_trace(
|
||||
) -> Option<(String, Vec<Value>)> {
|
||||
match module.get(ptr_to_index, ptr) {
|
||||
DefinitionContent::Function(fn_) => {
|
||||
let metadata_ptr = match &fn_.metadata {
|
||||
let meta_ptr = match &fn_.meta {
|
||||
Some(ptr) => ptr,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
let src_meta = match module.get(ptr_to_index, metadata_ptr) {
|
||||
DefinitionContent::FnMeta(fn_meta) => match &fn_meta.content_hashable {
|
||||
let src_meta = match module.get(ptr_to_index, meta_ptr) {
|
||||
DefinitionContent::Meta(meta) => match &meta.content_hashable {
|
||||
ContentHashable::Src(src_hash, deps) => (Structured(src_hash).to_string(), deps.clone()),
|
||||
_ => return None,
|
||||
},
|
||||
_ => panic!("metadata_ptr did not point to metadata"),
|
||||
_ => panic!("meta_ptr did not point to meta"),
|
||||
};
|
||||
|
||||
Some(src_meta)
|
||||
}
|
||||
DefinitionContent::FnMeta(_fn_meta) => None,
|
||||
DefinitionContent::Meta(_fn_meta) => None,
|
||||
DefinitionContent::Value(value) => find_value_src_trace(module, ptr_to_index, value),
|
||||
DefinitionContent::Lazy(_) => None,
|
||||
}
|
||||
@@ -488,7 +488,7 @@ fn find_value_src_trace(
|
||||
) -> Option<(String, Vec<Value>)> {
|
||||
match value {
|
||||
Value::Class(class) => {
|
||||
let src_meta = match &class.metadata.content_hashable {
|
||||
let src_meta = match &class.meta.content_hashable {
|
||||
ContentHashable::Src(src_hash, deps) => (Structured(src_hash).to_string(), deps.clone()),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ use swc_ecma_ast::EsVersion;
|
||||
use swc_ecma_parser::{Syntax, TsConfig};
|
||||
|
||||
use crate::asm::{
|
||||
Class, ContentHashable, Definition, DefinitionContent, FnLine, FnMeta, Instruction, Lazy, Module,
|
||||
Class, ContentHashable, Definition, DefinitionContent, FnLine, Instruction, Lazy, Meta, Module,
|
||||
Number, Object, Pointer, Register, Structured, Value,
|
||||
};
|
||||
use crate::diagnostic::{Diagnostic, DiagnosticContainer, DiagnosticReporter};
|
||||
@@ -881,7 +881,7 @@ impl ModuleCompiler {
|
||||
}
|
||||
|
||||
let class_value = Value::Class(Box::new(Class {
|
||||
metadata: FnMeta {
|
||||
meta: Meta {
|
||||
name: ident.map_or_else(String::new, |ident| ident.sym.to_string()),
|
||||
content_hashable: ContentHashable::Src(
|
||||
src_hash(&self.source, class.span),
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
asm::{self, Builtin, FnLine, FnMeta, Function, Number, Pointer, Register, Value},
|
||||
asm::{self, Builtin, FnLine, Function, Meta, Number, Pointer, Register, Value},
|
||||
instruction::Instruction,
|
||||
name_allocator::RegAllocator,
|
||||
};
|
||||
@@ -72,7 +72,7 @@ pub struct KFunction {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Class {
|
||||
pub metadata: FnMeta,
|
||||
pub meta: Meta,
|
||||
pub constructor: Kal,
|
||||
pub prototype: Kal,
|
||||
pub static_: Kal,
|
||||
@@ -137,7 +137,7 @@ impl Kal {
|
||||
.collect(),
|
||||
})),
|
||||
Value::Class(class) => Kal::Class(Box::new(Class {
|
||||
metadata: class.metadata.clone(),
|
||||
meta: class.meta.clone(),
|
||||
constructor: Kal::from_value(&class.constructor),
|
||||
prototype: Kal::from_value(&class.prototype),
|
||||
static_: Kal::from_value(&class.static_),
|
||||
@@ -211,7 +211,7 @@ impl Kal {
|
||||
}))),
|
||||
Kal::Function(_) => None,
|
||||
Kal::Class(class) => Some(Value::Class(Box::new(asm::Class {
|
||||
metadata: class.metadata.clone(),
|
||||
meta: class.meta.clone(),
|
||||
constructor: class.constructor.try_to_value()?,
|
||||
prototype: class.prototype.try_to_value()?,
|
||||
static_: class.static_.try_to_value()?,
|
||||
@@ -786,7 +786,7 @@ impl FnState {
|
||||
Kal::Object(Box::new(Object { properties }))
|
||||
}
|
||||
Value::Class(class) => Kal::Class(Box::new(Class {
|
||||
metadata: class.metadata.clone(),
|
||||
meta: class.meta.clone(),
|
||||
constructor: self.eval_arg(&mut class.constructor),
|
||||
prototype: self.eval_arg(&mut class.prototype),
|
||||
static_: self.eval_arg(&mut class.static_),
|
||||
|
||||
@@ -74,7 +74,7 @@ pub fn shake_tree(module: &mut Module) {
|
||||
match &defn.content {
|
||||
DefinitionContent::Function(..)
|
||||
| DefinitionContent::Value(Value::Class(..))
|
||||
| DefinitionContent::FnMeta(..) => {}
|
||||
| DefinitionContent::Meta(..) => {}
|
||||
DefinitionContent::Value(..) | DefinitionContent::Lazy(..) => continue,
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn simplify(module: &mut Module, take_registers: bool) {
|
||||
Kal::from_function(defn.pointer.clone(), fn_),
|
||||
);
|
||||
}
|
||||
DefinitionContent::FnMeta(_) => {}
|
||||
DefinitionContent::Meta(_) => {}
|
||||
DefinitionContent::Value(value) => {
|
||||
pointer_kals.insert(defn.pointer.clone(), Kal::from_value(value));
|
||||
}
|
||||
@@ -30,7 +30,7 @@ pub fn simplify(module: &mut Module, take_registers: bool) {
|
||||
DefinitionContent::Function(fn_) => {
|
||||
simplify_fn(FnState::new(fn_, pointer_kals.clone()), fn_, take_registers)
|
||||
}
|
||||
DefinitionContent::FnMeta(_) => {}
|
||||
DefinitionContent::Meta(_) => {}
|
||||
DefinitionContent::Value(_) => {}
|
||||
DefinitionContent::Lazy(_) => {}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::asm::{
|
||||
Array, ContentHashable, Definition, DefinitionContent, ExportStar, FnLine, FnMeta, Instruction,
|
||||
Array, ContentHashable, Definition, DefinitionContent, ExportStar, FnLine, Instruction, Meta,
|
||||
Module, Object, Pointer, Value,
|
||||
};
|
||||
|
||||
@@ -47,13 +47,13 @@ where
|
||||
|
||||
match &mut definition.content {
|
||||
DefinitionContent::Function(function) => {
|
||||
if let Some(metadata) = &mut function.metadata {
|
||||
self.pointer(Some(&definition.pointer), metadata);
|
||||
if let Some(meta) = &mut function.meta {
|
||||
self.pointer(Some(&definition.pointer), meta);
|
||||
}
|
||||
|
||||
self.body(&definition.pointer, &mut function.body);
|
||||
}
|
||||
DefinitionContent::FnMeta(fn_meta) => self.fn_meta(Some(&definition.pointer), fn_meta),
|
||||
DefinitionContent::Meta(meta) => self.meta(Some(&definition.pointer), meta),
|
||||
DefinitionContent::Value(value) => {
|
||||
self.value(Some(&definition.pointer), value);
|
||||
}
|
||||
@@ -63,8 +63,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_meta(&mut self, owner: Option<&Pointer>, fn_meta: &mut FnMeta) {
|
||||
match &mut fn_meta.content_hashable {
|
||||
fn meta(&mut self, owner: Option<&Pointer>, meta: &mut Meta) {
|
||||
match &mut meta.content_hashable {
|
||||
ContentHashable::Empty => {}
|
||||
ContentHashable::Src(_, deps) => {
|
||||
for dep in deps {
|
||||
@@ -109,7 +109,7 @@ where
|
||||
self.object(owner, object);
|
||||
}
|
||||
Class(class) => {
|
||||
self.fn_meta(owner, &mut class.metadata);
|
||||
self.meta(owner, &mut class.meta);
|
||||
self.value(owner, &mut class.constructor);
|
||||
self.value(owner, &mut class.prototype);
|
||||
self.value(owner, &mut class.static_);
|
||||
|
||||
Reference in New Issue
Block a user