Skip to content

Commit

Permalink
feat(zink): tests for all examples (#163)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
clearloop authored Oct 27, 2023
1 parent 1fa6722 commit ffff362
Show file tree
Hide file tree
Showing 29 changed files with 514 additions and 329 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ jobs:
run: cargo build --examples --target wasm32-unknown-unknown --release

- name: Run Tests
run: cargo nextest run --all --no-fail-fast --release
run: cargo nextest run --workspace --no-fail-fast --release

- name: Run Example Tests
run: cargo nextest run --workspace --no-fail-fast --release --examples

check:
name: Check
Expand Down
55 changes: 28 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ members = [
"codegen/opcodes",
"compiler",
"compiler/filetests",
# "tests",
"zink/codegen",
"zint",
]
resolver = "2"

[workspace.package]
version = "0.1.5-pre.2"
version = "0.1.5"
authors = ["clearloop"]
edition = "2021"
license = "GPL-3.0-only"
Expand Down Expand Up @@ -54,16 +53,16 @@ wasm-opt = "0.113.0"
wasmparser = "0.107.0"
wat = "1.0.75"

elko = { path = "cli/elko", version = "=0.1.5-pre.2" }
elko = { path = "cli/elko", version = "=0.1.5" }
opcodes = { package = "evm-opcodes", path = "codegen/opcodes", version = "=0.0.3", features = ["data"] }
zabi = { path = "abi", version = "=0.1.5-pre.2" }
zinkup = { path = "cli", version = "=0.1.5-pre.2" }
zingen = { path = "codegen", version = "=0.1.5-pre.2" }
zinkc = { path = "compiler", version = "=0.1.5-pre.2" }
zinkc-filetests = { path = "compiler/filetests", version = "=0.1.5-pre.2" }
zink = { path = ".", version = "=0.1.5-pre.2" }
zink-codegen = { path = "zink/codegen", version = "=0.1.5-pre.2" }
zint = { path = "zint", version = "=0.1.5-pre.2" }
zabi = { path = "abi", version = "=0.1.5" }
zinkup = { path = "cli", version = "=0.1.5" }
zingen = { path = "codegen", version = "=0.1.5" }
zinkc = { path = "compiler", version = "=0.1.5" }
zinkc-filetests = { path = "compiler/filetests", version = "=0.1.5" }
zink = { path = ".", version = "=0.1.5" }
zink-codegen = { path = "zink/codegen", version = "=0.1.5" }
zint = { path = "zint", version = "=0.1.5" }

[profile]
dev = { panic = "abort"}
Expand Down
21 changes: 14 additions & 7 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@

### Added

- Crate `zabi`
- Function dispatcher
- new `proc-macro` `zink::external`
- `dispatcher` flag for `elko` and `zinkc`
- Jump with offset in jump table
- Crate `zabi`
- Host function `emit_abi`
- new `proc-macro` `zink::external`
- `dispatcher` flag for `elko` and `zinkc`
- Jump with offset in jump table
- `Contract` instance in `zint`
- Host function `emit_abi`
- filetests for the compiler
- Built-in tests for all examples
- filetests of the compiler

## Changed
### Changed

- Map functions in codegen for different usages
- Move `zink` to the top level
- Move previous compiler tests to the top level
- Move examples out of crates
- The PC order of return and callee labels

#### Fixed

- Add up original PC offset while shifting themselves in PC relocation
- clean stack on loading data from data section

---

Expand Down
19 changes: 18 additions & 1 deletion codegen/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ impl Assembler {

/// Increment stack pointer
pub fn increment_sp(&mut self, items: u8) -> Result<()> {
if items == 0 {
return Ok(());
}

tracing::trace!(
"increment stack pointer {}({items}) -> {}",
self.sp,
self.sp + items
);
self.sp += items;

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

/// Decrement stack pointer
pub fn decrement_sp(&mut self, items: u8) -> Result<()> {
if items == 0 {
return Ok(());
}

tracing::trace!(
"decrement stack pointer {}({items}) -> {}",
self.sp,
self.sp - items
);
self.sp = self
.sp
.checked_sub(items)
.ok_or(Error::StackUnderflow(self.sp, items))?;

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

Expand Down
18 changes: 0 additions & 18 deletions codegen/src/code/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,3 @@ pub struct ExtFunc {
/// The bytecode of the external function.
pub bytecode: Vec<u8>,
}

impl ExtFunc {
/// Function select.
pub fn select() -> Self {
Self {
stack_in: 2,
stack_out: 1,
bytecode: [
OpCode::POP,
OpCode::PUSH1,
OpCode::Data(0x06),
OpCode::ADD,
OpCode::JUMP,
]
.to_bytes(),
}
}
}
4 changes: 2 additions & 2 deletions codegen/src/code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Code {

/// Shift the code section.
pub fn shift(&mut self, offset: u16) {
tracing::debug!("shift code section by 0x{:x} bytes.", offset);
tracing::trace!("shift code section by 0x{:x} bytes.", offset);
let offset = offset as usize;
self.offset += offset;
self.funcs.values_mut().for_each(|pc| *pc += offset);
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Code {
pub fn finish(&self) -> Vec<u8> {
let mut code = Vec::new();
for func in self.funcs.keys() {
tracing::debug!("add function to code section: {:?}", func);
tracing::trace!("add function to code section: {:?}", func);
code.extend(func.bytecode.clone());
}
code
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl CodeGen {
validator.define_locals(validation_offset, count, val)?;
}

tracing::debug!("{:?}", self.locals);
tracing::trace!("{:?}", self.locals);
Ok(())
}

Expand Down
Loading

0 comments on commit ffff362

Please sign in to comment.