Skip to content

Commit ff3061b

Browse files
committed
map_mutate example
1 parent 03986e9 commit ff3061b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

examples/map.zen

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mod stdlib;
2+
3+
fn map_mutate array func {
4+
let i = array_size(array) - 1;
5+
while i >= 0 {
6+
let array[i] = func(array[i]);
7+
let i = i - 1;
8+
}
9+
return null;
10+
}
11+
12+
fn main {
13+
let arr = [1,2,3,4,5];
14+
map_mutate(arr, fn val {
15+
return val * 2;
16+
});
17+
return arr;
18+
}

zenlang/src/ast/binop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{ast::node::Compile, opcode::Opcode};
22
use alloc::vec::*;
33

4+
#[derive(Debug)]
45
pub enum AstBinopOp {
56
PLUS,
67
MINUS,

zenlang/src/vm/vm_compute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use alloc::string::String;
77
impl VM {
88
pub(crate) fn compute_values(&mut self, left: Value, right: Value, op: AstBinopOp) -> Value {
99
let err = format!(
10-
"unmatched left and right value types: {:?} {:?}",
11-
left, right
10+
"unmatched left and right value types: {:?} {:?} with op {:?}",
11+
left, right, op
1212
);
1313
match op {
1414
AstBinopOp::PLUS => match (left, right) {

0 commit comments

Comments
 (0)