Skip to content

Commit

Permalink
Lots of refs, cesium-nebula, seperation of concerns, condensation of …
Browse files Browse the repository at this point in the history
…related items
  • Loading branch information
OnlyF0uR committed Nov 6, 2024
1 parent 4165f98 commit a675b0a
Show file tree
Hide file tree
Showing 49 changed files with 493 additions and 687 deletions.
46 changes: 15 additions & 31 deletions Cargo.lock

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

15 changes: 6 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ members = [
# Inner libs
"crates/cesium-crypto",
"crates/cesium-storage",
"crates/cesium-material",
"crates/cesium-mempool",
"crates/cesium-state",
"crates/cesium-proc",
"crates/cesium-nucleus",
"crates/cesium-nebula",
"crates/selenide-sdk",
"crates/selenide-sdk-macros",
"crates/selenide-wasm",
"crates/selenide-runtime",

# Contracts
"contracts/state",
"contracts/state_sdk",
"contracts/nomisma",

# Executables
"cesium-node",
Expand Down Expand Up @@ -61,11 +59,10 @@ dashmap = "6.1.0"
# Inner libs
cesium-crypto = { path = "crates/cesium-crypto" }
cesium-storage = { path = "crates/cesium-storage" }
cesium-material = { path = "crates/cesium-material" }
cesium-mempool = { path = "crates/cesium-mempool" }
cesium-state = { path = "crates/cesium-state" }
cesium-runtime = { path = "crates/cesium-runtime" }
cesium-proc = { path = "crates/cesium-proc" }
cesium-nucleus = { path = "crates/cesium-nucleus" }
cesium-nebula = { path = "crates/cesium-nebula" }
selenide-sdk = { path = "crates/selenide-sdk" }
selenide-sdk-macros = { path = "crates/selenide-sdk-macros" }
selenide-wasm = { path = "crates/selenide-wasm" }
selenide-runtime = { path = "crates/selenide-runtime" }
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
all: build wasm
# Build the specific packages with the default target
build:
cargo build --exclude selenide-sdk --exclude state --exclude state-sdk --exclude nomisma --workspace --verbose
cargo build --exclude selenide-sdk --exclude state --exclude state-sdk --workspace
# Build the WASM packages
wasm:
cargo build --target wasm32-unknown-unknown --release --package selenide-sdk
cargo build --target wasm32-unknown-unknown --release --package state
cargo build --target wasm32-unknown-unknown --release --package state-sdk
cargo build --target wasm32-unknown-unknown --release --package nomisma
ifeq ($(OS),Windows_NT)
@echo "Compiling nomisma-c on Windows is currently not supported"
@echo "Compiling example-c on Windows is currently not supported"
else
$(MAKE) -C contracts/nomisma-c
$(MAKE) -C contracts/example-c
endif
test:
cargo test --exclude selenide-sdk --exclude state --exclude state-sdk --exclude nomisma --workspace --verbose
cargo test --exclude selenide-sdk --exclude state --exclude state-sdk --workspace
# Build both
all: build wasm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Compiler and flags
EMCC = emcc
C_FILES = contract.c convert.c
OUTPUT = ../../target/nomisma-c.wasm
OUTPUT = ../../target/example-c.wasm
OPTIMIZATION = -O3
EXPORTED_FUNCTIONS = -s "EXPORTED_FUNCTIONS=['_initialize', '_create']"
WASM_FLAG = -s WASM=1
Expand Down
54 changes: 27 additions & 27 deletions contracts/nomisma-c/contract.c → contracts/example-c/contract.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "convert.h"

__attribute__((import_module("env"), import_name("h_gen_id")))
extern int64_t h_gen_id();

int32_t initialize() {
return 0;
}

int32_t create() {
int64_t big_ptr = h_gen_id();

// Get the pointer and length from the combined value
const uint8_t *ptr;
size_t length;

unfold_ptr(big_ptr, &ptr, &length);

// Get the char* from the pointer
const char *str = (const char *)ptr;

return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "convert.h"

__attribute__((import_module("env"), import_name("h_gen_id")))
extern int64_t h_gen_id();

int32_t initialize() {
return 0;
}

int32_t create() {
int64_t big_ptr = h_gen_id();

// Get the pointer and length from the combined value
const uint8_t *ptr;
size_t length;

unfold_ptr(big_ptr, &ptr, &length);

// Get the char* from the pointer
const char *str = (const char *)ptr;

return 0;
}
26 changes: 13 additions & 13 deletions contracts/nomisma-c/convert.c → contracts/example-c/convert.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "convert.h"

void unfold_ptr(int64_t combined, const uint8_t **ptr, size_t *length) {
*length = (size_t)(combined >> 32); // Extract length from the upper 32 bits
*ptr = (const uint8_t *)(uintptr_t)(combined & 0xFFFFFFFF); // Extract pointer from the lower 32 bits
}

void unfold_ptrs(__int128 encoded, UnfoldedPtrs *result) {
result->ptr1 = (uint32_t)(encoded & 0xFFFFFFFF); // Extract ptr1
result->len1 = (uint32_t)((encoded >> 32) & 0xFFFFFFFF); // Extract len1
result->ptr2 = (uint32_t)((encoded >> 64) & 0xFFFFFFFF); // Extract ptr2
result->len2 = (uint32_t)((encoded >> 96) & 0xFFFFFFFF); // Extract len2
}
#include "convert.h"

void unfold_ptr(int64_t combined, const uint8_t **ptr, size_t *length) {
*length = (size_t)(combined >> 32); // Extract length from the upper 32 bits
*ptr = (const uint8_t *)(uintptr_t)(combined & 0xFFFFFFFF); // Extract pointer from the lower 32 bits
}

void unfold_ptrs(__int128 encoded, UnfoldedPtrs *result) {
result->ptr1 = (uint32_t)(encoded & 0xFFFFFFFF); // Extract ptr1
result->len1 = (uint32_t)((encoded >> 32) & 0xFFFFFFFF); // Extract len1
result->ptr2 = (uint32_t)((encoded >> 64) & 0xFFFFFFFF); // Extract ptr2
result->len2 = (uint32_t)((encoded >> 96) & 0xFFFFFFFF); // Extract len2
}
44 changes: 22 additions & 22 deletions contracts/nomisma-c/convert.h → contracts/example-c/convert.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// convert.h
#ifndef CONVERT_H
#define CONVERT_H

#include <stdint.h>
#include <stddef.h>

// Struct to hold the unpacked values for `unfold_ptrs`
typedef struct {
uint32_t ptr1;
uint32_t len1;
uint32_t ptr2;
uint32_t len2;
} UnfoldedPtrs;

// Function to unpack a 64-bit integer into a pointer and length
void unfold_ptr(int64_t combined, const uint8_t **ptr, size_t *length);

// Function to unpack a 128-bit integer into four 32-bit values
void unfold_ptrs(__int128 encoded, UnfoldedPtrs *result);

#endif // CONVERT_H
// convert.h
#ifndef CONVERT_H
#define CONVERT_H

#include <stdint.h>
#include <stddef.h>

// Struct to hold the unpacked values for `unfold_ptrs`
typedef struct {
uint32_t ptr1;
uint32_t len1;
uint32_t ptr2;
uint32_t len2;
} UnfoldedPtrs;

// Function to unpack a 64-bit integer into a pointer and length
void unfold_ptr(int64_t combined, const uint8_t **ptr, size_t *length);

// Function to unpack a 128-bit integer into four 32-bit values
void unfold_ptrs(__int128 encoded, UnfoldedPtrs *result);

#endif // CONVERT_H
10 changes: 0 additions & 10 deletions contracts/nomisma/Cargo.toml

This file was deleted.

85 changes: 0 additions & 85 deletions contracts/nomisma/src/lib.rs

This file was deleted.

Loading

0 comments on commit a675b0a

Please sign in to comment.