Skip to content

Commit 9fc0e38

Browse files
committed
add variables for function parameters
1 parent c6775d7 commit 9fc0e38

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/compiler.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,24 @@ mod tests {
317317
jit(code);
318318
}
319319

320+
#[test]
321+
fn test_call_id() {
322+
let code = r#"
323+
assert(cond: bool) → void
324+
325+
id(x: i32) → i32 {
326+
x
327+
}
328+
329+
main {
330+
let y = id(42)
331+
// assert(y == 42)
332+
}
333+
"#;
334+
335+
jit(code);
336+
}
337+
320338
#[test]
321339
fn test_neg() {
322340
let code = r#"

src/jit.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ impl JIT {
170170

171171
let mut trans = FunctionTranslator::new(builder, &mut self.module);
172172

173+
// Add variables for the function parameters.
174+
for param in &decl.params {
175+
trans.declare_variable(&param.name, param.ty.expect("expected type").cranelift_type());
176+
}
177+
173178
trans.translate_fn(decl, decls);
174179

175180
// Need a return instruction at the end of the function's block.

0 commit comments

Comments
 (0)