Skip to content

Commit

Permalink
feat(zink): ffi for push N
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Feb 3, 2024
1 parent c43bfda commit 88b00ec
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 51 deletions.
3 changes: 0 additions & 3 deletions examples/mapping.rs

This file was deleted.

48 changes: 0 additions & 48 deletions zink/src/ffi.rs

This file was deleted.

29 changes: 29 additions & 0 deletions zink/src/ffi/asm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Assembly FFI.
#[link(wasm_import_module = "zinkc")]
#[allow(improper_ctypes)]
extern "C" {
/// Push a 8-bit signed integer to the stack.
pub fn push_i8(val: i8);

/// Push a 8-bit unsigned integer to the stack.
pub fn push_u8(val: u8);

/// Push a 16-bit signed integer to the stack.
pub fn push_i16(val: i16);

/// Push a 16-bit unsigned integer to the stack.
pub fn push_u16(val: u16);

/// Push a 32-bit signed integer to the stack.
pub fn push_i32(val: i32);

/// Push a 32-bit unsigned integer to the stack.
pub fn push_u32(val: u32);

/// Push a 64-bit signed integer to the stack.
pub fn push_i64(val: i64);

/// Push a 64-bit unsigned integer to the stack.
pub fn push_u64(val: u64);
}
136 changes: 136 additions & 0 deletions zink/src/ffi/evm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//! EVM FFI
#[link(wasm_import_module = "evm")]
#[allow(improper_ctypes)]
extern "C" {
/// Push 1 byte to the stack.
pub fn push0();

/// Push 1 byte to the stack.
pub fn push1(val: u8);

/// Push 2 bytes to the stack.
pub fn push2(val: u8);

/// Push 3 bytes to the stack.
pub fn push3(val: u8);

/// Push 4 bytes to the stack.
pub fn push4(val: u8);

/// Push 5 bytes to the stack.
pub fn push5(val: u8);

/// Push 6 bytes to the stack.
pub fn push6(val: u8);

/// Push 7 bytes to the stack.
pub fn push7(val: u8);

/// Push 8 bytes to the stack.
pub fn push8(val: u8);

/// Push 9 bytes to the stack.
pub fn push9(val: u8);

/// Push 10 bytes to the stack.
pub fn push10(val: u8);

/// Push 11 bytes to the stack.
pub fn push11(val: u8);

/// Push 12 bytes to the stack.
pub fn push12(val: u8);

/// Push 13 bytes to the stack.
pub fn push13(val: u8);

/// Push 14 bytes to the stack.
pub fn push14(val: u8);

/// Push 15 bytes to the stack.
pub fn push15(val: u8);

/// Push 16 bytes to the stack.
pub fn push16(val: u8);

/// Push 17 bytes to the stack.
pub fn push17(val: u8);

/// Push 18 bytes to the stack.
pub fn push18(val: u8);

/// Push 19 bytes to the stack.
pub fn push19(val: u8);

/// Push 20 bytes to the stack.
pub fn push20(val: u8);

/// Push 21 bytes to the stack.
pub fn push21(val: u8);

/// Push 22 bytes to the stack.
pub fn push22(val: u8);

/// Push 23 bytes to the stack.
pub fn push23(val: u8);

/// Push 24 bytes to the stack.
pub fn push24(val: u8);

/// Push 25 bytes to the stack.
pub fn push25(val: u8);

/// Push 26 bytes to the stack.
pub fn push26(val: u8);

/// Push 27 bytes to the stack.
pub fn push27(val: u8);

/// Push 28 bytes to the stack.
pub fn push28(val: u8);

/// Push 29 bytes to the stack.
pub fn push29(val: u8);

/// Push 30 bytes to the stack.
pub fn push30(val: u8);

/// Push 31 bytes to the stack.
pub fn push31(val: u8);

/// Push 32 bytes to the stack.
pub fn push32(val: u8);

/// Store a value in the storage
pub fn sstore(value: i32, key: i32);

/// Load a value from the storage
pub fn sload(key: i32) -> i32;

/// Append log record with no topics
pub fn log0(name: &'static [u8]);

/// Append log record with one topics
pub fn log1(name: &'static [u8], topic1: &'static [u8]);

/// Append log record with two topics
pub fn log2(name: &'static [u8], topic1: &'static [u8], topic2: &'static [u8]);

/// Append log record with three topics
pub fn log3(
name: &'static [u8],
topic1: &'static [u8],
topic2: &'static [u8],
topic3: &'static [u8],
);

/// Append log record with four topics
pub fn log4(
name: &'static [u8],
topic1: &'static [u8],
topic2: &'static [u8],
topic3: &'static [u8],
topic4: &'static [u8],
);
}
12 changes: 12 additions & 0 deletions zink/src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Zink FFI.
pub mod asm;
pub mod evm;

#[link(wasm_import_module = "zinkc")]
#[allow(improper_ctypes)]
extern "C" {
/// Emit ABI to host state.
pub fn emit_abi(ptr: u32, len: u32);

}
1 change: 1 addition & 0 deletions zink/src/storage/mapping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! Zink storage mapping implementation.
2 changes: 2 additions & 0 deletions zink/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Zink storage implementation.
mod mapping;

/// Storage trait. Currently not for public use
pub trait Storage<T> {
const STORAGE_KEY: i32;
Expand Down

0 comments on commit 88b00ec

Please sign in to comment.