Skip to content

Commit ffff362

Browse files
authored
feat(zink): tests for all examples (#163)
* feat(filetests): generate tests for all cases * feat(zink): generate module path for tests in macro * fix(codegen): dispatcher shift for the last function * chore(codegen): reorder the PC of return and call in dispatcher * ci(main): run example tests * fix(codegen): add up pc offset while shifting * fix(codegen): clean stack while loading data from data section * feat(codegen): make external function select embedded * docs(zink): addition example in README * bump(zink): v0.1.5 * chore(lock): update Cargo.lock
1 parent 1fa6722 commit ffff362

File tree

29 files changed

+514
-329
lines changed

29 files changed

+514
-329
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ jobs:
2525
run: cargo build --examples --target wasm32-unknown-unknown --release
2626

2727
- name: Run Tests
28-
run: cargo nextest run --all --no-fail-fast --release
28+
run: cargo nextest run --workspace --no-fail-fast --release
29+
30+
- name: Run Example Tests
31+
run: cargo nextest run --workspace --no-fail-fast --release --examples
2932

3033
check:
3134
name: Check

Cargo.lock

Lines changed: 28 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ members = [
88
"codegen/opcodes",
99
"compiler",
1010
"compiler/filetests",
11-
# "tests",
1211
"zink/codegen",
1312
"zint",
1413
]
1514
resolver = "2"
1615

1716
[workspace.package]
18-
version = "0.1.5-pre.2"
17+
version = "0.1.5"
1918
authors = ["clearloop"]
2019
edition = "2021"
2120
license = "GPL-3.0-only"
@@ -54,16 +53,16 @@ wasm-opt = "0.113.0"
5453
wasmparser = "0.107.0"
5554
wat = "1.0.75"
5655

57-
elko = { path = "cli/elko", version = "=0.1.5-pre.2" }
56+
elko = { path = "cli/elko", version = "=0.1.5" }
5857
opcodes = { package = "evm-opcodes", path = "codegen/opcodes", version = "=0.0.3", features = ["data"] }
59-
zabi = { path = "abi", version = "=0.1.5-pre.2" }
60-
zinkup = { path = "cli", version = "=0.1.5-pre.2" }
61-
zingen = { path = "codegen", version = "=0.1.5-pre.2" }
62-
zinkc = { path = "compiler", version = "=0.1.5-pre.2" }
63-
zinkc-filetests = { path = "compiler/filetests", version = "=0.1.5-pre.2" }
64-
zink = { path = ".", version = "=0.1.5-pre.2" }
65-
zink-codegen = { path = "zink/codegen", version = "=0.1.5-pre.2" }
66-
zint = { path = "zint", version = "=0.1.5-pre.2" }
58+
zabi = { path = "abi", version = "=0.1.5" }
59+
zinkup = { path = "cli", version = "=0.1.5" }
60+
zingen = { path = "codegen", version = "=0.1.5" }
61+
zinkc = { path = "compiler", version = "=0.1.5" }
62+
zinkc-filetests = { path = "compiler/filetests", version = "=0.1.5" }
63+
zink = { path = ".", version = "=0.1.5" }
64+
zink-codegen = { path = "zink/codegen", version = "=0.1.5" }
65+
zint = { path = "zint", version = "=0.1.5" }
6766

6867
[profile]
6968
dev = { panic = "abort"}

RELEASES.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22

33
### Added
44

5-
- Crate `zabi`
65
- Function dispatcher
7-
- new `proc-macro` `zink::external`
8-
- `dispatcher` flag for `elko` and `zinkc`
9-
- Jump with offset in jump table
6+
- Crate `zabi`
7+
- Host function `emit_abi`
8+
- new `proc-macro` `zink::external`
9+
- `dispatcher` flag for `elko` and `zinkc`
10+
- Jump with offset in jump table
1011
- `Contract` instance in `zint`
11-
- Host function `emit_abi`
12-
- filetests for the compiler
12+
- Built-in tests for all examples
13+
- filetests of the compiler
1314

14-
## Changed
15+
### Changed
1516

1617
- Map functions in codegen for different usages
1718
- Move `zink` to the top level
1819
- Move previous compiler tests to the top level
1920
- Move examples out of crates
21+
- The PC order of return and callee labels
22+
23+
#### Fixed
24+
25+
- Add up original PC offset while shifting themselves in PC relocation
26+
- clean stack on loading data from data section
2027

2128
---
2229

codegen/src/asm.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ impl Assembler {
4242

4343
/// Increment stack pointer
4444
pub fn increment_sp(&mut self, items: u8) -> Result<()> {
45+
if items == 0 {
46+
return Ok(());
47+
}
48+
49+
tracing::trace!(
50+
"increment stack pointer {}({items}) -> {}",
51+
self.sp,
52+
self.sp + items
53+
);
4554
self.sp += items;
4655

4756
// TODO: fix this limitation: should be 1024. (#127)
@@ -54,12 +63,20 @@ impl Assembler {
5463

5564
/// Decrement stack pointer
5665
pub fn decrement_sp(&mut self, items: u8) -> Result<()> {
66+
if items == 0 {
67+
return Ok(());
68+
}
69+
70+
tracing::trace!(
71+
"decrement stack pointer {}({items}) -> {}",
72+
self.sp,
73+
self.sp - items
74+
);
5775
self.sp = self
5876
.sp
5977
.checked_sub(items)
6078
.ok_or(Error::StackUnderflow(self.sp, items))?;
6179

62-
// tracing::debug!("decrement sp: {items} -> {}", self.sp);
6380
Ok(())
6481
}
6582

codegen/src/code/func.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,3 @@ pub struct ExtFunc {
2525
/// The bytecode of the external function.
2626
pub bytecode: Vec<u8>,
2727
}
28-
29-
impl ExtFunc {
30-
/// Function select.
31-
pub fn select() -> Self {
32-
Self {
33-
stack_in: 2,
34-
stack_out: 1,
35-
bytecode: [
36-
OpCode::POP,
37-
OpCode::PUSH1,
38-
OpCode::Data(0x06),
39-
OpCode::ADD,
40-
OpCode::JUMP,
41-
]
42-
.to_bytes(),
43-
}
44-
}
45-
}

codegen/src/code/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Code {
2929

3030
/// Shift the code section.
3131
pub fn shift(&mut self, offset: u16) {
32-
tracing::debug!("shift code section by 0x{:x} bytes.", offset);
32+
tracing::trace!("shift code section by 0x{:x} bytes.", offset);
3333
let offset = offset as usize;
3434
self.offset += offset;
3535
self.funcs.values_mut().for_each(|pc| *pc += offset);
@@ -61,7 +61,7 @@ impl Code {
6161
pub fn finish(&self) -> Vec<u8> {
6262
let mut code = Vec::new();
6363
for func in self.funcs.keys() {
64-
tracing::debug!("add function to code section: {:?}", func);
64+
tracing::trace!("add function to code section: {:?}", func);
6565
code.extend(func.bytecode.clone());
6666
}
6767
code

codegen/src/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl CodeGen {
105105
validator.define_locals(validation_offset, count, val)?;
106106
}
107107

108-
tracing::debug!("{:?}", self.locals);
108+
tracing::trace!("{:?}", self.locals);
109109
Ok(())
110110
}
111111

0 commit comments

Comments
 (0)