Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 1156783

Browse files
Merge pull request #52 from Chia-Network/20220803-fix-inline-at-capture-modern
20220803 fix inline at capture in modern
2 parents b3d5202 + 8414cfc commit 1156783

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clvm_tools_rs"
3-
version = "0.1.22"
3+
version = "0.1.23"
44
edition = "2018"
55
authors = ["Art Yerkes <[email protected]>"]
66
description = "tools for working with chialisp language; compiler, repl, python and wasm bindings"

src/compiler/codegen.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ pub fn process_macro_call(
368368
let args_to_macro = list_to_cons(l.clone(), &converted_args);
369369
build_swap_table_mut(&mut swap_table, &args_to_macro);
370370

371-
let arg_strs: Vec<String> = args.iter().map(|x| x.to_sexp().to_string()).collect();
372-
373371
run(
374372
allocator,
375373
runner.clone(),

src/compiler/inline.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::classic::clvm::__type_compatibility__::bi_one;
88
use crate::classic::clvm_tools::stages::stage_0::TRunProgram;
99

1010
use crate::compiler::codegen::{generate_expr_code, get_call_name, get_callable};
11+
use crate::compiler::compiler::is_at_capture;
1112
use crate::compiler::comptypes::{
1213
BodyForm, Callable, CompileErr, CompiledCode, CompilerOpts, InlineFunction, PrimaryCodegen,
1314
};
@@ -81,6 +82,13 @@ fn pick_value_from_arg_element(
8182
) -> Option<Rc<BodyForm>> {
8283
match match_args.borrow() {
8384
SExp::Cons(l, a, b) => {
85+
if let Some((capture, children)) = is_at_capture(a.clone(), b.clone()) {
86+
if capture == name {
87+
return Some(apply(provided));
88+
}
89+
90+
return pick_value_from_arg_element(children, provided.clone(), apply, name);
91+
}
8492
let matched_a = pick_value_from_arg_element(
8593
a.clone(),
8694
provided.clone(),
@@ -161,8 +169,6 @@ fn replace_inline_body(
161169
args: &Vec<Rc<BodyForm>>,
162170
expr: Rc<BodyForm>,
163171
) -> Result<Rc<BodyForm>, CompileErr> {
164-
let arg_str_vec: Vec<String> = args.iter().map(|x| x.to_sexp().to_string()).collect();
165-
166172
match expr.borrow() {
167173
BodyForm::Let(_l, _, _, _) => Err(CompileErr(
168174
loc.clone(),
@@ -215,9 +221,12 @@ fn replace_inline_body(
215221
}
216222
}
217223
}
218-
BodyForm::Value(SExp::Atom(_, a)) => arg_lookup(inline.args.clone(), 0, args, a.clone())
219-
.map(|x| Ok(x.clone()))
220-
.unwrap_or_else(|| Ok(expr.clone())),
224+
BodyForm::Value(SExp::Atom(_, a)) => {
225+
let alookup = arg_lookup(inline.args.clone(), 0, args, a.clone())
226+
.map(|x| Ok(x.clone()))
227+
.unwrap_or_else(|| Ok(expr.clone()))?;
228+
Ok(alookup)
229+
}
221230
_ => Ok(expr.clone()),
222231
}
223232
}
@@ -231,7 +240,6 @@ pub fn replace_in_inline(
231240
inline: &InlineFunction,
232241
args: &Vec<Rc<BodyForm>>,
233242
) -> Result<CompiledCode, CompileErr> {
234-
let arg_str_vec: Vec<String> = args.iter().map(|x| x.to_sexp().to_string()).collect();
235243
replace_inline_body(
236244
allocator,
237245
runner.clone(),

src/tests/compiler/compiler.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,3 +1026,32 @@ fn sebastian_hash_test_2() {
10261026

10271027
assert_eq!(result.to_string(), "((0xf22ada22a0ed015000ea157013ee62dc6ce337a649ec01054fc62ed6caac7eaf 36364122602940516403027890844760998025315693007634105146514094828976803085567) (51 -54330418644829767769717664495663952010367061369724157609947295940464695774007 1))");
10281028
}
1029+
1030+
#[test]
1031+
fn test_modern_inline_at_capture() {
1032+
let result = run_string(
1033+
&indoc! {"
1034+
(mod (Z)
1035+
(include *standard-cl-21*)
1036+
(defun-inline check_lineage_proof
1037+
(
1038+
THIS_MOD_HASH
1039+
TYPES
1040+
(@ lineage_proof (foo bar))
1041+
conditions
1042+
)
1043+
(if TYPES
1044+
(x lineage_proof)
1045+
conditions
1046+
)
1047+
)
1048+
1049+
(check_lineage_proof 1 2 Z 4)
1050+
)"}
1051+
.to_string(),
1052+
&"(99)".to_string(),
1053+
)
1054+
.unwrap_err();
1055+
1056+
assert_eq!(result.1, "clvm raise in (8 5) (() 99)");
1057+
}

0 commit comments

Comments
 (0)