Skip to content
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

Implement procref instruction #1113

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 0.8.0 (TBD)

#### Assembly
- Expanded capabilities of the `debug` decorator. Added `debug.mem` and `debug.local` variations.
- Expanded capabilities of the `debug` decorator. Added `debug.mem` and `debug.local` variations (#1103).
- Introduced the `emit.<event_id>` assembly instruction (#1119).
- Introduced the `procref.<proc_name>` assembly instruction (#1113).

Expand Down
2 changes: 1 addition & 1 deletion assembly/src/assembler/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl AssemblyContext {
}
}

/// Returns the [Procedure] by its index from the vector of compiled procedures.
/// Returns the [Procedure] by its index from the vector of local procedures.
pub fn get_local_procedure(&self, idx: u16) -> Result<&Procedure, AssemblyError> {
let module_context = self.module_stack.last().expect("no modules");
module_context
Expand Down
73 changes: 42 additions & 31 deletions miden/tests/integration/flow_control/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use assembly::{ast::ModuleAst, LibraryNamespace, LibraryPath, MaslLibrary, Module};
use assembly::{ast::ProgramAst, Assembler, AssemblyContext};
use stdlib::StdLibrary;
use test_utils::{build_test, AdviceInputs, StackInputs, Test, TestError};
use vm_core::{code_blocks::CodeBlock, StarkField};

// SIMPLE FLOW CONTROL TESTS
// ================================================================================================
Expand Down Expand Up @@ -358,49 +360,58 @@ fn simple_dyncall() {
// ================================================================================================

#[test]
fn fmpadd() {
let module_source = "
export.foo
push.1.2
end";
let module_ast = ModuleAst::parse(module_source).unwrap();
let library_path = LibraryPath::new("module::path::one").unwrap();
let module = Module::new(library_path, module_ast);
let masl_lib = MaslLibrary::new(
LibraryNamespace::new("module").unwrap(),
assembly::Version::default(),
false,
vec![module],
vec![],
)
.unwrap();

fn procref() {
let source = "
use.module::path::one
use.std::math::u64

proc.baz.4
proc.foo.4
push.3.4
end

begin
procref.one::foo
procref.u64::overflowing_add
push.0
procref.baz
procref.foo
end";

let assembler = Assembler::default();
let program_ast = ProgramAst::parse(source).unwrap();

// compile program to get mast roots from the CodeBlock
let compiled_program = assembler
.with_library(&StdLibrary::default())
.unwrap()
.compile_in_context(&program_ast, &mut AssemblyContext::for_program(Some(&program_ast)))
.unwrap();

let mut mast_roots = Vec::new();
let span = match compiled_program {
CodeBlock::Span(span) => span.clone(),
_ => unreachable!(),
};
for batch in span.op_batches() {
for op in batch.ops() {
match op {
// procref uses only `Push` operations
vm_core::Operation::Push(v) => mast_roots.push(v.as_int()),
_ => {}
}
}
}

Fumuran marked this conversation as resolved.
Show resolved Hide resolved
bobbinth marked this conversation as resolved.
Show resolved Hide resolved
let mut test = build_test!(source, &[]);
test.libraries = vec![masl_lib];
test.libraries = vec![StdLibrary::default().into()];

test.expect_stack(&[
14955017261620687123,
7483764806157722537,
3983040829500348437,
17415803850183235164,
mast_roots[7],
mast_roots[6],
mast_roots[5],
mast_roots[4],
0,
10769795280686168241,
18286248910168089036,
9534016474345631087,
17844857521614540683,
mast_roots[3],
mast_roots[2],
mast_roots[1],
mast_roots[0],
]);

test.prove_and_verify(vec![], false);
Expand Down
Loading