mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Fix inputs/passing/projEuler/p15.ts
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// // test_output! 137846528820
|
||||
// TODO: Regression here... VM says there's an exception now
|
||||
// test_output! 137846528820
|
||||
|
||||
export default function main() {
|
||||
let rc = new RouteCalculator();
|
||||
|
||||
@@ -146,7 +146,7 @@ impl std::fmt::Display for Register {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum InstructionOrLabel {
|
||||
Instruction(Instruction),
|
||||
Label(Label),
|
||||
@@ -195,7 +195,7 @@ impl std::fmt::Display for LabelRef {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Instruction {
|
||||
End,
|
||||
Mov(Value, Register),
|
||||
|
||||
@@ -812,7 +812,7 @@ impl Compiler {
|
||||
|
||||
for class_member in &class_decl.class.body {
|
||||
match class_member {
|
||||
swc_ecma_ast::ClassMember::Constructor(constructor) => {
|
||||
swc_ecma_ast::ClassMember::Constructor(ctor) => {
|
||||
has_constructor = true;
|
||||
|
||||
let ctor_defn_name = self.allocate_defn(&format!("{}_constructor", class_name));
|
||||
@@ -820,9 +820,11 @@ impl Compiler {
|
||||
self.compile_fn(
|
||||
ctor_defn_name.clone(),
|
||||
None,
|
||||
Functionish::Constructor(constructor.clone()),
|
||||
Functionish::Constructor(member_initializers_assembly.clone(), ctor.clone()),
|
||||
parent_scope,
|
||||
);
|
||||
|
||||
constructor = Value::Pointer(ctor_defn_name);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -1157,7 +1157,7 @@ impl<'a> ExpressionCompiler<'a> {
|
||||
match &qfn.functionish {
|
||||
Functionish::Fn(fn_) => fn_.span,
|
||||
Functionish::Arrow(arrow) => arrow.span,
|
||||
Functionish::Constructor(constructor) => constructor.span,
|
||||
Functionish::Constructor(_, constructor) => constructor.span,
|
||||
},
|
||||
&qfn.definition_pointer,
|
||||
&qfn.capture_params,
|
||||
@@ -1313,7 +1313,7 @@ impl<'a> ExpressionCompiler<'a> {
|
||||
match &qfn.functionish {
|
||||
Functionish::Fn(fn_) => fn_.span,
|
||||
Functionish::Arrow(arrow) => arrow.span,
|
||||
Functionish::Constructor(constructor) => constructor.span,
|
||||
Functionish::Constructor(_, constructor) => constructor.span,
|
||||
},
|
||||
&qfn.definition_pointer,
|
||||
&qfn.capture_params,
|
||||
|
||||
@@ -22,7 +22,7 @@ use super::scope::{init_std_scope, MappedName, Scope};
|
||||
pub enum Functionish {
|
||||
Fn(swc_ecma_ast::Function),
|
||||
Arrow(swc_ecma_ast::ArrowExpr),
|
||||
Constructor(swc_ecma_ast::Constructor),
|
||||
Constructor(Vec<InstructionOrLabel>, swc_ecma_ast::Constructor),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -213,20 +213,11 @@ impl FunctionCompiler {
|
||||
|
||||
self.add_param_code(functionish, ¶m_registers, &scope);
|
||||
|
||||
let mut handle_block_body = |block: &swc_ecma_ast::BlockStmt| {
|
||||
self.populate_fn_scope(block, &scope);
|
||||
self.populate_block_scope(block, &scope);
|
||||
|
||||
for i in 0..block.stmts.len() {
|
||||
self.statement(&block.stmts[i], i == block.stmts.len() - 1, &scope);
|
||||
}
|
||||
};
|
||||
|
||||
match functionish {
|
||||
Functionish::Fn(fn_) => {
|
||||
match &fn_.body {
|
||||
Some(block) => {
|
||||
handle_block_body(block);
|
||||
self.handle_block_body(block, &scope);
|
||||
}
|
||||
None => self.todo(
|
||||
fn_.span(),
|
||||
@@ -236,7 +227,7 @@ impl FunctionCompiler {
|
||||
}
|
||||
Functionish::Arrow(arrow) => match &arrow.body {
|
||||
swc_ecma_ast::BlockStmtOrExpr::BlockStmt(block) => {
|
||||
handle_block_body(block);
|
||||
self.handle_block_body(block, &scope);
|
||||
}
|
||||
swc_ecma_ast::BlockStmtOrExpr::Expr(expr) => {
|
||||
let mut expression_compiler = ExpressionCompiler {
|
||||
@@ -247,10 +238,13 @@ impl FunctionCompiler {
|
||||
expression_compiler.compile(expr, Some(Register::Return));
|
||||
}
|
||||
},
|
||||
Functionish::Constructor(constructor) => {
|
||||
Functionish::Constructor(member_initializers_assembly, constructor) => {
|
||||
let mut mia_copy = member_initializers_assembly.clone();
|
||||
self.current.body.append(&mut mia_copy);
|
||||
|
||||
match &constructor.body {
|
||||
Some(block) => {
|
||||
handle_block_body(block);
|
||||
self.handle_block_body(block, &scope);
|
||||
}
|
||||
None => self.todo(constructor.span(), "constructor without body"),
|
||||
};
|
||||
@@ -263,6 +257,15 @@ impl FunctionCompiler {
|
||||
});
|
||||
}
|
||||
|
||||
fn handle_block_body(&mut self, block: &swc_ecma_ast::BlockStmt, scope: &Scope) {
|
||||
self.populate_fn_scope(block, scope);
|
||||
self.populate_block_scope(block, scope);
|
||||
|
||||
for i in 0..block.stmts.len() {
|
||||
self.statement(&block.stmts[i], i == block.stmts.len() - 1, scope);
|
||||
}
|
||||
}
|
||||
|
||||
fn populate_fn_scope_params(&mut self, functionish: &Functionish, scope: &Scope) {
|
||||
match functionish {
|
||||
Functionish::Fn(fn_) => {
|
||||
@@ -275,7 +278,7 @@ impl FunctionCompiler {
|
||||
self.populate_scope_pat(p, scope);
|
||||
}
|
||||
}
|
||||
Functionish::Constructor(constructor) => {
|
||||
Functionish::Constructor(_, constructor) => {
|
||||
for potspp in &constructor.params {
|
||||
match potspp {
|
||||
swc_ecma_ast::ParamOrTsParamProp::TsParamProp(ts_param_prop) => {
|
||||
@@ -324,7 +327,7 @@ impl FunctionCompiler {
|
||||
param_registers.push(self.get_pattern_register(p, scope));
|
||||
}
|
||||
}
|
||||
Functionish::Constructor(constructor) => {
|
||||
Functionish::Constructor(_, constructor) => {
|
||||
for potspp in &constructor.params {
|
||||
match potspp {
|
||||
swc_ecma_ast::ParamOrTsParamProp::TsParamProp(ts_param_prop) => {
|
||||
@@ -393,7 +396,7 @@ impl FunctionCompiler {
|
||||
ec.pat(p, ¶m_registers[i], false, scope);
|
||||
}
|
||||
}
|
||||
Functionish::Constructor(constructor) => {
|
||||
Functionish::Constructor(_, constructor) => {
|
||||
for (i, potspp) in constructor.params.iter().enumerate() {
|
||||
match potspp {
|
||||
swc_ecma_ast::ParamOrTsParamProp::TsParamProp(_) => {
|
||||
|
||||
Reference in New Issue
Block a user