Skip to content

Commit

Permalink
Use eval as an instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Sep 27, 2023
1 parent 9d33776 commit 63929ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/compiler/grammar/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,16 @@ impl Compiler {
)?;
state.parse_let()?;
}
Word::Eval => {
state.validate_argument(
0,
Capability::Expressions.into(),
token_info.line_num,
token_info.line_pos,
)?;
let expr = state.parse_expr()?;
state.instructions.push(Instruction::Eval(expr));
}

// While extension
Word::While => {
Expand Down
3 changes: 2 additions & 1 deletion tests/stalwart/expressions.svtest
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ test "Expressions - Arrays" {
test_fail "expr2[count(expr2) - 1] != 'f'";
}

eval "2 + 2";

if eval "[2 + 2, 'a' + 'b', 5 / 2, ext_zero()] != [4, 'ab', 2.5, 'my_value']" {
test_fail "[2 + 2, 'a' + 'b', 5 / 2] != [4, 'ab', 2.5]";
}

}

0 comments on commit 63929ef

Please sign in to comment.