Skip to content
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 core/engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,7 @@ impl<'ctx> ByteCompiler<'ctx> {
global_lexs: self.global_lexs.into_boxed_slice(),
global_fns: self.global_fns.into_boxed_slice(),
global_vars: self.global_vars.into_boxed_slice(),
debug_id: CodeBlock::get_next_codeblock_id(),
}
}

Expand Down
25 changes: 24 additions & 1 deletion core/engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ pub struct CodeBlock {
pub(crate) global_lexs: Box<[u32]>,
pub(crate) global_fns: Box<[GlobalFunctionBinding]>,
pub(crate) global_vars: Box<[u32]>,

// Used for identifying anonymous functions in compiled output and call frames.
pub(crate) debug_id: u64,
}

/// ---- `CodeBlock` public API ----
Expand Down Expand Up @@ -194,6 +197,7 @@ impl CodeBlock {
global_lexs: Box::default(),
global_fns: Box::default(),
global_vars: Box::default(),
debug_id: CodeBlock::get_next_codeblock_id(),
}
}

Expand Down Expand Up @@ -345,6 +349,18 @@ impl CodeBlock {
pub(crate) fn source_info(&self) -> &SourceInfo {
&self.source_info
}

pub(crate) fn get_next_codeblock_id() -> u64 {
thread_local! {
static CODEBLOCK_ID_COUNTER: Cell<u64> = const { Cell::new(0) };
}

CODEBLOCK_ID_COUNTER.with(|c| {
let id = c.get();
c.set(id + 1);
id
})
}
}

/// ---- `CodeBlock` private API ----
Expand Down Expand Up @@ -913,7 +929,14 @@ impl Display for CodeBlock {
writeln!(
f,
"{:-^80}",
format!("Compiled Output: '{}'", name.to_std_string_escaped()),
format!(
" Compiled Output: {} ",
if name.is_empty() {
format!("[anon#{}]", self.debug_id)
} else {
format!("'{}'", name.to_std_string_escaped())
}
),
)?;
writeln!(
f,
Expand Down
9 changes: 7 additions & 2 deletions core/engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,13 @@ impl Context {
" VM Start ".to_string()
} else {
format!(
" Call Frame -- {} ",
frame.code_block().name().to_std_string_escaped()
" Call Frame '{}'{} ",
frame.code_block().name().to_std_string_escaped(),
if frame.code_block().name().is_empty() {
format!(" [anon#{}]", frame.code_block().debug_id)
} else {
String::new()
}
)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/insta-bytecode/src/lib.rs
expression: output
input_file: tests/insta-bytecode/scripts/basic-loop.js
---
---------------------------Compiled Output: '<main>'----------------------------
-------------------------- Compiled Output: '<main>' ---------------------------
Location Handler Opcode Operands
000000 PushZero dst:r02
000005 Jump address:000014
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/insta-bytecode/src/lib.rs
expression: output
input_file: tests/insta-bytecode/scripts/double-loop-function.js
---
---------------------------Compiled Output: '<main>'----------------------------
-------------------------- Compiled Output: '<main>' ---------------------------
Location Handler Opcode Operands
000000 PushZero dst:r02
000005 Jump address:000014
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source: tests/insta-bytecode/src/lib.rs
expression: output
input_file: tests/insta-bytecode/scripts/new.js
---
---------------------------Compiled Output: '<main>'----------------------------
-------------------------- Compiled Output: '<main>' ---------------------------
Location Handler Opcode Operands
000000 PushScope scope_index:1
000005 GetFunction index:2, dst:r01
Expand Down
Loading