Skip to content

Refactor bytecode representation #4220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions cli/src/debug/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fn flowgraph_parse_format_option(value: &JsValue) -> JsResult<FlowgraphFormat> {
if value.is_undefined() {
return Ok(FlowgraphFormat::Mermaid);
}

if let Some(string) = value.as_string() {
return match string.to_std_string_escaped().cow_to_lowercase().as_ref() {
"mermaid" => Ok(FlowgraphFormat::Mermaid),
Expand All @@ -23,7 +22,6 @@ fn flowgraph_parse_format_option(value: &JsValue) -> JsResult<FlowgraphFormat> {
.into()),
};
}

Err(JsNativeError::typ()
.with_message("format type must be a string")
.into())
Expand All @@ -33,7 +31,6 @@ fn flowgraph_parse_direction_option(value: &JsValue) -> JsResult<Direction> {
if value.is_undefined() {
return Ok(Direction::LeftToRight);
}

if let Some(string) = value.as_string() {
return match string.to_std_string_escaped().cow_to_lowercase().as_ref() {
"leftright" | "lr" => Ok(Direction::LeftToRight),
Expand All @@ -45,7 +42,6 @@ fn flowgraph_parse_direction_option(value: &JsValue) -> JsResult<Direction> {
.into()),
};
}

Err(JsNativeError::typ()
.with_message("direction type must be a string")
.into())
Expand All @@ -58,13 +54,11 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResu
.with_message("expected function argument")
.into());
};

let Some(object) = value.as_object() else {
return Err(JsNativeError::typ()
.with_message(format!("expected object, got {}", value.type_of()))
.into());
};

let mut format = FlowgraphFormat::Mermaid;
let mut direction = Direction::LeftToRight;
if let Some(arguments) = args.get(1) {
Expand All @@ -87,16 +81,13 @@ fn flowgraph(_this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResu
.with_message("expected an ordinary function object")
.into());
};

let code = function.codeblock();

let mut graph = Graph::new(direction);
code.to_graph(graph.subgraph(String::default()));
let result = match format {
FlowgraphFormat::Graphviz => graph.to_graphviz_format(),
FlowgraphFormat::Mermaid => graph.to_mermaid_format(),
};

Ok(JsValue::new(js_string!(result)))
}

Expand Down
2 changes: 0 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,12 @@ fn generate_flowgraph<R: ReadChar>(
let code = script
.codeblock(context)
.map_err(|e| e.into_erased(context))?;

let direction = match direction {
Some(FlowgraphDirection::TopToBottom) | None => Direction::TopToBottom,
Some(FlowgraphDirection::BottomToTop) => Direction::BottomToTop,
Some(FlowgraphDirection::LeftToRight) => Direction::LeftToRight,
Some(FlowgraphDirection::RightToLeft) => Direction::RightToLeft,
};

let mut graph = Graph::new(direction);
code.to_graph(graph.subgraph(String::default()));
let result = match format {
Expand Down
1 change: 1 addition & 0 deletions core/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ indexmap = { workspace = true, features = ["std"] }
ryu-js.workspace = true
fast-float2.workspace = true
tap.workspace = true
paste.workspace = true

thiserror.workspace = true
dashmap.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/builtins/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
realm::Realm,
spanned_source_text::SourceText,
string::StaticJsStrings,
vm::{CallFrame, CallFrameFlags, Constant, Opcode, Registers},
vm::{CallFrame, CallFrameFlags, Constant, Registers},
Context, JsArgs, JsResult, JsString, JsValue, SpannedSourceText,
};
use boa_ast::{
Expand Down Expand Up @@ -285,7 +285,7 @@ impl Eval {
.constants
.push(Constant::Scope(lexical_scope.clone()));

compiler.emit_with_varying_operand(Opcode::PushScope, scope_index);
compiler.bytecode.emit_push_scope(scope_index.into());
if strict {
variable_scope = lexical_scope.clone();
compiler.variable_scope = lexical_scope.clone();
Expand Down
Loading
Loading