use queues::*; use std::cell::RefCell; use std::collections::HashSet; use std::mem::take; use std::rc::Rc; use swc_common::Spanned; use crate::asm::{ Array, Builtin, Definition, DefinitionContent, FnLine, Function, Instruction, Label, Pointer, Register, Value, }; use crate::diagnostic::{Diagnostic, DiagnosticLevel}; use crate::expression_compiler::CompiledExpression; use crate::expression_compiler::ExpressionCompiler; use crate::instruction_mutates_this::instruction_mutates_this; use crate::name_allocator::{NameAllocator, RegAllocator}; use crate::scope::{NameId, OwnerId}; use crate::scope_analysis::{fn_to_owner_id, Name, ScopeAnalysis}; #[derive(Clone, Debug)] pub enum Functionish { Fn(Option, swc_ecma_ast::Function), Arrow(swc_ecma_ast::ArrowExpr), Constructor(Vec, swc_common::Span, swc_ecma_ast::Constructor), } impl Spanned for Functionish { fn span(&self) -> swc_common::Span { match self { Functionish::Fn(_, fn_) => fn_.span, Functionish::Arrow(arrow) => arrow.span, Functionish::Constructor(_, class_span, _) => *class_span, } } } impl Functionish { pub fn owner_id(&self) -> OwnerId { match self { Functionish::Fn(ident, fn_) => fn_to_owner_id(ident, fn_), _ => OwnerId::Span(self.span().clone()), } } } #[derive(Clone, Debug)] pub struct QueuedFunction { pub definition_pointer: Pointer, pub fn_name: Option, pub functionish: Functionish, } pub struct LoopLabels { pub continue_: Label, pub break_: Label, } pub struct CatchSetting { pub label: Label, pub reg: Register, } pub struct FunctionCompiler { pub current: Function, pub definitions: Vec, pub owner_id: OwnerId, pub scope_analysis: Rc, pub definition_allocator: Rc>, pub reg_allocator: RegAllocator, pub label_allocator: NameAllocator, pub queue: Queue, pub loop_labels: Vec, pub catch_settings: Vec, pub end_label: Option