mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:04:57 +00:00
LibJS/Bytecode: Simplify Bytecode::Interpreter lifetime model
The JS::VM now owns the one Bytecode::Interpreter. We no longer have multiple bytecode interpreters, and there is no concept of a "current" bytecode interpreter. If you ask for VM::bytecode_interpreter_if_exists(), it will return null if we're not running the program in "bytecode enabled" mode. If you ask for VM::bytecode_interpreter(), it will return a bytecode interpreter in all modes. This is used for situations where even the AST interpreter switches to bytecode mode (generators, etc.)
This commit is contained in:
parent
6150960671
commit
6537ed8fff
15 changed files with 117 additions and 106 deletions
|
@ -71,7 +71,6 @@ private:
|
|||
};
|
||||
|
||||
static bool s_dump_ast = false;
|
||||
static bool s_run_bytecode = false;
|
||||
static bool s_opt_bytecode = false;
|
||||
static bool s_as_module = false;
|
||||
static bool s_print_last_result = false;
|
||||
|
@ -212,10 +211,9 @@ static ErrorOr<bool> parse_and_run(JS::Interpreter& interpreter, StringView sour
|
|||
if (s_dump_ast)
|
||||
script_or_module->parse_node().dump(0);
|
||||
|
||||
if (s_run_bytecode) {
|
||||
JS::Bytecode::Interpreter bytecode_interpreter(interpreter.realm());
|
||||
bytecode_interpreter.set_optimizations_enabled(s_opt_bytecode);
|
||||
result = bytecode_interpreter.run(*script_or_module);
|
||||
if (auto* bytecode_interpreter = g_vm->bytecode_interpreter_if_exists()) {
|
||||
bytecode_interpreter->set_optimizations_enabled(s_opt_bytecode);
|
||||
result = bytecode_interpreter->run(*script_or_module);
|
||||
} else {
|
||||
result = interpreter.run(*script_or_module);
|
||||
}
|
||||
|
@ -579,12 +577,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
bool use_test262_global = false;
|
||||
StringView evaluate_script;
|
||||
Vector<StringView> script_paths;
|
||||
bool use_bytecode = false;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.set_general_help("This is a JavaScript interpreter.");
|
||||
args_parser.add_option(s_dump_ast, "Dump the AST", "dump-ast", 'A');
|
||||
args_parser.add_option(JS::Bytecode::g_dump_bytecode, "Dump the bytecode", "dump-bytecode", 'd');
|
||||
args_parser.add_option(s_run_bytecode, "Run the bytecode", "run-bytecode", 'b');
|
||||
args_parser.add_option(use_bytecode, "Run the bytecode", "run-bytecode", 'b');
|
||||
args_parser.add_option(s_opt_bytecode, "Optimize the bytecode", "optimize-bytecode", 'p');
|
||||
args_parser.add_option(s_as_module, "Treat as module", "as-module", 'm');
|
||||
args_parser.add_option(s_print_last_result, "Print last result", "print-last-result", 'l');
|
||||
|
@ -598,6 +597,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
args_parser.add_positional_argument(script_paths, "Path to script files", "scripts", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
JS::Bytecode::Interpreter::set_enabled(use_bytecode);
|
||||
|
||||
bool syntax_highlight = !disable_syntax_highlight;
|
||||
|
||||
AK::set_debug_enabled(!disable_debug_printing);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue