Skip to content

Commit c078d5e

Browse files
committed
WIP
1 parent 5bf7385 commit c078d5e

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

clar2wasm/src/wasm_generator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,9 @@ impl WasmGenerator {
495495
simpleword.visit(self, builder, &arg_types, &return_type)?;
496496
} else if let Some(variadic) = words::lookup_variadic_simple(function_name) {
497497
let (arg_types, return_type) = get_types()?;
498+
let args_len = args.len();
498499

499-
variadic.charge(self, builder, arg_types.len() as u32)?;
500+
variadic.charge(self, builder, args_len as u32)?;
500501

501502
let mut args_enumerated = args.iter().enumerate();
502503

clar2wasm/src/words/bindings.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ impl ComplexWord for Let {
2727

2828
check_args!(generator, builder, 2, args_len, ArgumentCountCheck::AtLeast);
2929

30-
self.charge(generator, builder, args_len as u32)?;
31-
3230
let bindings = args.get_list(0)?;
31+
let bindings_len = bindings.len();
32+
33+
self.charge(generator, builder, bindings_len as u32)?;
3334

3435
// Save the current named locals
3536
let saved_locals = generator.bindings.clone();
@@ -89,9 +90,12 @@ impl ComplexWord for Let {
8990

9091
#[cfg(test)]
9192
mod tests {
92-
use clarity::vm::Value;
93+
use clarity::{types::StacksEpochId, vm::Value};
9394

94-
use crate::tools::{crosscheck, crosscheck_compare_only, crosscheck_expect_failure, evaluate};
95+
use crate::tools::{
96+
crosscheck, crosscheck_compare_only, crosscheck_expect_failure, crosscheck_with_epoch,
97+
evaluate,
98+
};
9599

96100
#[cfg(feature = "test-clarity-v1")]
97101
mod clarity_v1 {
@@ -132,6 +136,28 @@ mod tests {
132136
crosscheck_expect_failure(&format!("{ERR} (test)"));
133137
}
134138

139+
#[test]
140+
fn clar_let_cost() {
141+
const SNIPPET_LET: &str = r#"
142+
(let ((a u1) (b u2))
143+
(+ a b)
144+
)
145+
"#;
146+
const SNIPPET_NO_LET: &str = r#"
147+
(+ u1 u2)
148+
"#;
149+
// crosscheck_with_epoch(
150+
// SNIPPET_LET,
151+
// Ok(Some(Value::UInt(3))),
152+
// StacksEpochId::Epoch20,
153+
// );
154+
crosscheck_with_epoch(
155+
SNIPPET_NO_LET,
156+
Ok(Some(Value::UInt(3))),
157+
StacksEpochId::Epoch31,
158+
);
159+
}
160+
135161
#[test]
136162
fn clar_let_disallow_user_defined_names() {
137163
// It's not allowed to use names of user-defined functions as bindings
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(define-public (simple)
2+
(begin
3+
(let a u4)
4+
(let b u1)
5+
(ok (+ a b))
6+
)
7+
)

0 commit comments

Comments
 (0)