mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-01-14 16:08:02 -05:00
Directly insert dependent definitions and diagnostics
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::asm::{
|
||||
Builtin, Definition, DefinitionContent, FnLine, Function, Instruction, Label, Pointer, Register,
|
||||
Value,
|
||||
};
|
||||
use crate::diagnostic::{Diagnostic, DiagnosticContainer, DiagnosticLevel, DiagnosticReporter};
|
||||
use crate::diagnostic::{Diagnostic, DiagnosticContainer, DiagnosticReporter};
|
||||
use crate::expression_compiler::CompiledExpression;
|
||||
use crate::expression_compiler::ExpressionCompiler;
|
||||
use crate::ident::Ident;
|
||||
@@ -63,7 +63,6 @@ pub struct CatchSetting {
|
||||
pub struct FunctionCompiler<'a> {
|
||||
pub mc: &'a mut ModuleCompiler,
|
||||
pub current: Function,
|
||||
pub definitions: Vec<Definition>,
|
||||
pub owner_id: OwnerId,
|
||||
pub reg_allocator: RegAllocator,
|
||||
pub label_allocator: NameAllocator,
|
||||
@@ -73,13 +72,11 @@ pub struct FunctionCompiler<'a> {
|
||||
pub end_label: Option<Label>,
|
||||
pub is_returning_register: Option<Register>,
|
||||
pub finally_labels: Vec<Label>,
|
||||
|
||||
pub diagnostics: Vec<Diagnostic>,
|
||||
}
|
||||
|
||||
impl<'a> DiagnosticContainer for FunctionCompiler<'a> {
|
||||
fn diagnostics_mut(&mut self) -> &mut Vec<Diagnostic> {
|
||||
&mut self.diagnostics
|
||||
&mut self.mc.diagnostics
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +90,6 @@ impl<'a> FunctionCompiler<'a> {
|
||||
FunctionCompiler {
|
||||
mc,
|
||||
current: Function::default(),
|
||||
definitions: vec![],
|
||||
owner_id,
|
||||
reg_allocator,
|
||||
label_allocator: NameAllocator::default(),
|
||||
@@ -103,7 +99,6 @@ impl<'a> FunctionCompiler<'a> {
|
||||
end_label: None,
|
||||
is_returning_register: None,
|
||||
finally_labels: vec![],
|
||||
diagnostics: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,11 +127,10 @@ impl<'a> FunctionCompiler<'a> {
|
||||
let name = self.mc.scope_analysis.lookup(ident);
|
||||
|
||||
if name.is_none() {
|
||||
self.diagnostics.push(Diagnostic {
|
||||
level: DiagnosticLevel::InternalError,
|
||||
message: format!("Could not find name for ident {:?}", ident),
|
||||
span: ident.span,
|
||||
});
|
||||
self.mc.diagnostics.push(Diagnostic::internal_error(
|
||||
ident.span,
|
||||
&format!("Could not find name for ident {:?}", ident),
|
||||
));
|
||||
}
|
||||
|
||||
name
|
||||
@@ -210,7 +204,7 @@ impl<'a> FunctionCompiler<'a> {
|
||||
definition_pointer: Pointer,
|
||||
fn_name: Option<String>,
|
||||
functionish: Functionish,
|
||||
) -> (Vec<Definition>, Vec<Diagnostic>) {
|
||||
) {
|
||||
let mut self_ = FunctionCompiler::new(mc, functionish.owner_id());
|
||||
|
||||
self_
|
||||
@@ -223,8 +217,6 @@ impl<'a> FunctionCompiler<'a> {
|
||||
.expect("Failed to queue function");
|
||||
|
||||
self_.process_queue();
|
||||
|
||||
(self_.definitions, self_.diagnostics)
|
||||
}
|
||||
|
||||
pub fn process_queue(&mut self) {
|
||||
@@ -333,7 +325,7 @@ impl<'a> FunctionCompiler<'a> {
|
||||
self.is_returning_register = None;
|
||||
}
|
||||
|
||||
self.definitions.push(Definition {
|
||||
self.mc.module.definitions.push(Definition {
|
||||
pointer: definition_pointer,
|
||||
content: DefinitionContent::Function(take(&mut self.current)),
|
||||
});
|
||||
@@ -1204,7 +1196,7 @@ impl<'a> FunctionCompiler<'a> {
|
||||
|
||||
let enum_value = self.mc.compile_enum_value(ts_enum);
|
||||
|
||||
self.definitions.push(Definition {
|
||||
self.mc.module.definitions.push(Definition {
|
||||
pointer,
|
||||
content: DefinitionContent::Value(enum_value),
|
||||
});
|
||||
|
||||
@@ -321,13 +321,11 @@ impl ModuleCompiler {
|
||||
));
|
||||
}
|
||||
|
||||
let mut fn_defns = self.compile_fn(
|
||||
self.compile_fn(
|
||||
pointer,
|
||||
Some(fn_name),
|
||||
Functionish::Fn(Some(fn_.ident.clone()), fn_.function.clone()),
|
||||
);
|
||||
|
||||
self.module.definitions.append(&mut fn_defns);
|
||||
}
|
||||
|
||||
fn compile_enum_decl(&mut self, export: bool, ts_enum: &swc_ecma_ast::TsEnumDecl) {
|
||||
@@ -396,13 +394,11 @@ impl ModuleCompiler {
|
||||
|
||||
self.module.export_default = Value::Pointer(defn.clone());
|
||||
|
||||
let mut fn_defns = self.compile_fn(
|
||||
self.compile_fn(
|
||||
defn,
|
||||
fn_name,
|
||||
Functionish::Fn(fn_.ident.clone(), fn_.function.clone()),
|
||||
);
|
||||
|
||||
self.module.definitions.append(&mut fn_defns);
|
||||
}
|
||||
DefaultDecl::TsInterfaceDecl(_) => {
|
||||
// Nothing to do
|
||||
@@ -701,13 +697,8 @@ impl ModuleCompiler {
|
||||
defn_pointer: Pointer,
|
||||
fn_name: Option<String>,
|
||||
functionish: Functionish,
|
||||
) -> Vec<Definition> {
|
||||
let (defn, mut diagnostics) =
|
||||
FunctionCompiler::compile(self, defn_pointer, fn_name, functionish);
|
||||
|
||||
self.diagnostics.append(&mut diagnostics);
|
||||
|
||||
defn
|
||||
) {
|
||||
FunctionCompiler::compile(self, defn_pointer, fn_name, functionish);
|
||||
}
|
||||
|
||||
pub fn compile_class(
|
||||
@@ -719,7 +710,6 @@ impl ModuleCompiler {
|
||||
let mut constructor: Value = Value::Void;
|
||||
let mut prototype: Object = Object::default();
|
||||
let mut static_: Object = Object::default();
|
||||
let mut dependent_definitions: Vec<Definition>;
|
||||
|
||||
let defn_name = match ident {
|
||||
Some(ident) => match self
|
||||
@@ -793,7 +783,6 @@ impl ModuleCompiler {
|
||||
|
||||
// Include any other definitions that were created by the member initializers
|
||||
mi_fnc.process_queue();
|
||||
dependent_definitions = std::mem::take(&mut mi_fnc.definitions);
|
||||
|
||||
let mut has_constructor = false;
|
||||
|
||||
@@ -803,7 +792,7 @@ impl ModuleCompiler {
|
||||
|
||||
let ctor_defn_name = self.allocate_defn(&format!("{}_constructor", defn_name.name));
|
||||
|
||||
dependent_definitions.append(&mut self.compile_fn(
|
||||
self.compile_fn(
|
||||
ctor_defn_name.clone(),
|
||||
None,
|
||||
Functionish::Constructor(
|
||||
@@ -811,7 +800,7 @@ impl ModuleCompiler {
|
||||
class.span,
|
||||
ctor.clone(),
|
||||
),
|
||||
));
|
||||
);
|
||||
|
||||
constructor = Value::Pointer(ctor_defn_name);
|
||||
}
|
||||
@@ -821,7 +810,7 @@ impl ModuleCompiler {
|
||||
let ctor_defn_name = self.allocate_defn(&format!("{}_constructor", defn_name.name));
|
||||
|
||||
constructor = Value::Pointer(ctor_defn_name.clone());
|
||||
dependent_definitions.push(Definition {
|
||||
self.module.definitions.push(Definition {
|
||||
pointer: ctor_defn_name,
|
||||
content: DefinitionContent::Function(Function {
|
||||
is_generator: false,
|
||||
@@ -849,11 +838,11 @@ impl ModuleCompiler {
|
||||
let method_defn_name =
|
||||
self.allocate_defn(&ident_from_str(&format!("{}_{}", defn_name.name, name)));
|
||||
|
||||
dependent_definitions.append(&mut self.compile_fn(
|
||||
self.compile_fn(
|
||||
method_defn_name.clone(),
|
||||
None,
|
||||
Functionish::Fn(None, method.function.clone()),
|
||||
));
|
||||
);
|
||||
|
||||
let dst = match method.is_static {
|
||||
false => &mut prototype,
|
||||
@@ -892,8 +881,6 @@ impl ModuleCompiler {
|
||||
}))),
|
||||
});
|
||||
|
||||
self.module.definitions.append(&mut dependent_definitions);
|
||||
|
||||
defn_name
|
||||
}
|
||||
|
||||
|
||||
@@ -108,14 +108,12 @@ impl<'a> StaticExpressionCompiler<'a> {
|
||||
None => self.mc.allocate_defn_numbered("_anon"),
|
||||
};
|
||||
|
||||
let mut nested_defns = self.mc.compile_fn(
|
||||
self.mc.compile_fn(
|
||||
p.clone(),
|
||||
fn_name.clone(),
|
||||
Functionish::Fn(fn_ident, method.function.clone()),
|
||||
);
|
||||
|
||||
self.mc.module.definitions.append(&mut nested_defns);
|
||||
|
||||
(key, Value::Pointer(p))
|
||||
}
|
||||
},
|
||||
@@ -161,22 +159,20 @@ impl<'a> StaticExpressionCompiler<'a> {
|
||||
None => self.mc.allocate_defn_numbered("_anon"),
|
||||
};
|
||||
|
||||
let mut fn_defns = self.mc.compile_fn(
|
||||
self.mc.compile_fn(
|
||||
p.clone(),
|
||||
fn_name,
|
||||
Functionish::Fn(fn_.ident.clone(), fn_.function.clone()),
|
||||
);
|
||||
|
||||
self.mc.module.definitions.append(&mut fn_defns);
|
||||
|
||||
Value::Pointer(p)
|
||||
}
|
||||
swc_ecma_ast::Expr::Arrow(arrow) => {
|
||||
let p = self.mc.allocate_defn_numbered("_anon");
|
||||
let mut fn_defns = self
|
||||
|
||||
self
|
||||
.mc
|
||||
.compile_fn(p.clone(), None, Functionish::Arrow(arrow.clone()));
|
||||
self.mc.module.definitions.append(&mut fn_defns);
|
||||
|
||||
Value::Pointer(p)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user