Skip to content

Commit

Permalink
Added tests and fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phorward committed Nov 9, 2024
1 parent 326fc56 commit 5729ab1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/compiler/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,8 +1475,7 @@ impl Compiler {
"emit" => "op_accept",
"children" =>
(value!([
"emit" => "value_integer",
"value" => 0
"emit" => "value_void"
]))
]))
]))
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.tok
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ avg : @value {
cnt++
}

if !cnt return 0
if !cnt return void
res / cnt
}
4 changes: 2 additions & 2 deletions src/value/iter/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Iter {
let mut borrowed_iter = iter.borrow_mut();

if let Some(iter) = borrowed_iter.object_mut::<Iter>() {
Ok(iter.max().unwrap())
Ok(iter.max().unwrap_or(RefValue::from(Value::Void)))
} else {
Ok(iter.clone())
}
Expand All @@ -107,7 +107,7 @@ impl Iter {
let mut borrowed_iter = iter.borrow_mut();

if let Some(iter) = borrowed_iter.object_mut::<Iter>() {
Ok(iter.min().unwrap())
Ok(iter.min().unwrap_or(RefValue::from(Value::Void)))
} else {
Ok(iter.clone())
}
Expand Down
36 changes: 36 additions & 0 deletions tests/aggregates.tok
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#testmode:repl
# Aggregate Functions

l = list(range(10))

min(l)
max(l)
sum(l)
avg(l)

min(42)
max(42)
sum(42)
avg(42)

print(type(min(void)))
print(type(max(void)))
print(type(sum(void)))
print(type(avg(void)))


#---
#0
#9
#45
#4.5

#42
#42
#42
#42

#void
#void
#void
#void

0 comments on commit 5729ab1

Please sign in to comment.