Skip to content

Commit 65f69b6

Browse files
committed
release "if" demo as 0.2.0-a1
1 parent 0bf4f1c commit 65f69b6

File tree

7 files changed

+20
-36
lines changed

7 files changed

+20
-36
lines changed

.github/workflows/publish.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ jobs:
1616
toolchain: nightly
1717
components: clippy
1818

19+
- run: cargo test
20+
1921
- run: cargo run -- -s demos/hello.cirru
2022
- run: cargo run -- -s demos/sum.cirru
2123
- run: cargo run -- -s demos/assert.cirru
2224
- run: cargo run -- -s demos/nested.cirru
2325
- run: cargo run -- -s demos/named.cirru
2426
- run: cargo run -- -s demos/recur.cirru
2527
- run: cargo run -- -s demos/fibonacci.cirru
28+
- run: cargo run -- -s demos/if.cirru
2629
- run: cargo run -- --emit-binary target/a.calx demos/named.cirru && cargo run -- --eval-binary target/a.calx
2730

2831
# - run: cargo test

.github/workflows/test.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ jobs:
2424
toolchain: nightly
2525
components: clippy
2626

27+
- run: cargo test
28+
2729
- run: cargo run -- -s demos/hello.cirru
2830
- run: cargo run -- -s demos/sum.cirru
2931
- run: cargo run -- -s demos/assert.cirru
3032
- run: cargo run -- -s demos/nested.cirru
3133
- run: cargo run -- -s demos/named.cirru
3234
- run: cargo run -- -s demos/recur.cirru
3335
- run: cargo run -- -s demos/fibonacci.cirru
36+
- run: cargo run -- -s demos/if.cirru
3437
- run: cargo run -- --emit-binary target/a.calx demos/named.cirru && cargo run -- --eval-binary target/a.calx
3538

3639
- uses: giraffate/clippy-action@v1
3740
with:
3841
reporter: 'github-pr-review'
3942
github_token: ${{ secrets.GITHUB_TOKEN }}
40-

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "calx_vm"
3-
version = "0.1.6"
3+
version = "0.2.0-a1"
44
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
55
edition = "2021"
66
license = "MIT"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ fn main ()
7373

7474
### Instructions
7575

76+
> _TODO_ update to `0.2.x`...
77+
7678
Highly inspired by:
7779

7880
- WASM https://github.com/WebAssembly/design/blob/main/Semantics.md

demos/if.cirru

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11

2-
32
fn main ()
43
const 1
4+
call demo
5+
const 0
6+
call demo
7+
8+
fn demo (($a i64) ->)
9+
local.get $a
10+
511
if (->)
612
do
713
const 11
814
echo
915
do
1016
const 20
1117
echo
18+
const 3
19+
echo

src/vm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ impl CalxVM {
703703
if stack_size < 1 {
704704
return Err(format!("insufficient stack {} to branch", stack_size));
705705
}
706-
stack_size -= 1;
707706

708707
blocks_track.push(BlockData::If {
709708
ret_types: ret_types.to_owned(),
@@ -712,6 +711,7 @@ impl CalxVM {
712711
initial_stack_size: stack_size,
713712
});
714713

714+
stack_size -= 1;
715715
ops.push(CalxInstr::JmpIf(else_at.to_owned()));
716716
}
717717
CalxSyntax::ElseEnd => {
@@ -720,6 +720,7 @@ impl CalxVM {
720720
}
721721

722722
let prev_block = blocks_track.peek_if()?;
723+
723724
if stack_size != prev_block.expected_finish_size() {
724725
return Err(format!("size mismatch for else-end: {} {:?}", stack_size, prev_block));
725726
}

tests/parser_tests.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,5 @@ fn test_extracting() -> Result<(), String> {
3636
))
3737
);
3838

39-
assert_eq!(
40-
Cirru::List(extract_nested(&Cirru::List(vec![
41-
Cirru::leaf("block"),
42-
Cirru::List(vec![
43-
Cirru::leaf("c"),
44-
Cirru::leaf("d"),
45-
Cirru::List(vec![Cirru::leaf("e"), Cirru::leaf("f"),])
46-
])
47-
]))?),
48-
Cirru::List(vec!(Cirru::List(vec![
49-
Cirru::leaf("block"),
50-
Cirru::List(vec![Cirru::leaf("e"), Cirru::leaf("f")]),
51-
Cirru::List(vec![Cirru::leaf("c"), Cirru::leaf("d")])
52-
]),))
53-
);
54-
55-
assert_eq!(
56-
Cirru::List(extract_nested(&Cirru::List(vec![
57-
Cirru::leaf("loop"),
58-
Cirru::List(vec![
59-
Cirru::leaf("c"),
60-
Cirru::leaf("d"),
61-
Cirru::List(vec![Cirru::leaf("e"), Cirru::leaf("f"),])
62-
])
63-
]))?),
64-
Cirru::List(vec!(Cirru::List(vec![
65-
Cirru::leaf("loop"),
66-
Cirru::List(vec![Cirru::leaf("e"), Cirru::leaf("f")]),
67-
Cirru::List(vec![Cirru::leaf("c"), Cirru::leaf("d")])
68-
]),))
69-
);
70-
7139
Ok(())
7240
}

0 commit comments

Comments
 (0)