Skip to content

Commit

Permalink
refactor: rename miden-prelude to miden-stdlib-sys in SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Jun 26, 2024
1 parent 13af81c commit 4b01c5a
Show file tree
Hide file tree
Showing 42 changed files with 173 additions and 176 deletions.
6 changes: 3 additions & 3 deletions docs/src/guides/develop_miden_in_rust.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Developing Miden Programs In Rust

This chapter will walk through how to develop Miden programs in Rust using the prelude and standard library provided by the `miden-prelude` crate (see the [README](https://github.com/0xPolygonMiden/compiler/sdk/prelude/README.md)).
This chapter will walk through how to develop Miden programs in Rust using the standard library provided by the `miden-stdlib-sys` crate (see the [README](https://github.com/0xPolygonMiden/compiler/sdk/stdlib-sys/README.md)).

## Getting Started

Import the prelude and standard library from the `miden-prelude` crate:
Import the standard library from the `miden-stdlib-sys` crate:

```rust
use miden_prelude::*;
use miden_stdlib_sys::*;
```

## Using `Felt` (field element) type
Expand Down
2 changes: 1 addition & 1 deletion frontend-wasm/src/intrinsics/felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use midenc_hir::{Felt, FunctionIdent, Immediate, InstBuilder, SourceSpan, Type::

use crate::module::function_builder_ext::FunctionBuilderExt;

pub(crate) const PRELUDE_INTRINSICS_FELT_MODULE_NAME: &str = "miden:prelude/intrinsics_felt";
pub(crate) const INTRINSICS_FELT_MODULE_NAME: &str = "miden:stdlib/intrinsics_felt";

/// Convert a call to a felt op intrinsic function into instruction(s)
pub(crate) fn convert_felt_intrinsics(
Expand Down
4 changes: 2 additions & 2 deletions frontend-wasm/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn modules() -> &'static HashSet<&'static str> {
static MODULES: OnceLock<HashSet<&'static str>> = OnceLock::new();
MODULES.get_or_init(|| {
let mut s = HashSet::default();
s.insert(felt::PRELUDE_INTRINSICS_FELT_MODULE_NAME);
s.insert(felt::INTRINSICS_FELT_MODULE_NAME);
s
})
}
Expand All @@ -28,7 +28,7 @@ pub fn convert_intrinsics_call(
span: SourceSpan,
) -> Vec<Value> {
match func_id.module.as_symbol().as_str() {
felt::PRELUDE_INTRINSICS_FELT_MODULE_NAME => {
felt::INTRINSICS_FELT_MODULE_NAME => {
felt::convert_felt_intrinsics(func_id, args, builder, span)
}
_ => panic!("No intrinsics found for {}", func_id),
Expand Down
2 changes: 1 addition & 1 deletion frontend-wasm/src/miden_abi/stdlib/crypto/dsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ pub(crate) fn signatures() -> ModuleFunctionTypeMap {
RPO_FALCON512_VERIFY,
FunctionType::new([Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt], []),
);
m.insert("miden:prelude/std_crypto_dsa", funcs);
m.insert("miden:stdlib/std_crypto_dsa", funcs);
m
}
2 changes: 1 addition & 1 deletion frontend-wasm/src/miden_abi/stdlib/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ pub(crate) fn signatures() -> ModuleFunctionTypeMap {
],
),
);
m.insert("miden:prelude/std_mem", funcs);
m.insert("miden:stdlib/std_mem", funcs);
m
}
12 changes: 6 additions & 6 deletions sdk/Cargo.lock

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

2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"
members = [
"prelude",
"stdlib-sys",
"tx-kernel",
"sdk",
]
Expand Down
6 changes: 3 additions & 3 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ The Miden SDK is a set of Rust crates that provide libraries for developing Mide

The SDK is composed of the following crates:

## Miden Prelude
## Miden Standard Library

The `miden-prelude` crate provides a `Felt` type that represents field element in the Miden VM and a standard library for developing Miden programs.
The `miden-stdlib-sys` crate provides a `Felt` type that represents field element in the Miden VM and a standard library for developing Miden programs.

See [README](prelude/README.md)
See [README](stdlib-sys/README.md)

## Miden SDK

Expand Down
2 changes: 1 addition & 1 deletion sdk/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ edition.workspace = true
crate-type = ["rlib"]

[dependencies]
miden-prelude = { path = "../prelude" }
miden-stdlib-sys = { path = "../stdlib-sys" }
miden-sdk-tx-kernel = { path = "../tx-kernel" }
2 changes: 1 addition & 1 deletion sdk/sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![no_std]

pub use miden_prelude::*;
pub use miden_sdk_tx_kernel::*;
pub use miden_stdlib_sys::*;
4 changes: 2 additions & 2 deletions sdk/prelude/Cargo.toml → sdk/stdlib-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miden-prelude"
description = "Miden Prelude: intrinsics and standard library for Miden"
name = "miden-stdlib-sys"
description = "Low-level Rust bindings for the Miden standard library"
version.workspace = true
rust-version.workspace = true
authors.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions sdk/prelude/README.md → sdk/stdlib-sys/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Miden Prelude
# Miden Standard Library

The `miden-prelude` crate provides a `Felt` type that represents field element in the Miden VM and a standard library for developing Miden programs.
The `miden-stdlib-sys` crate provides a `Felt` type that represents field element in the Miden VM and a standard library for developing Miden programs.

## Miden VM instructions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};

#[link(wasm_import_module = "miden:prelude/intrinsics_felt")]
#[link(wasm_import_module = "miden:stdlib/intrinsics_felt")]
extern "C" {
#[link_name = "from_u64_unchecked"]
fn extern_from_u64_unchecked(value: u64) -> Felt;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Felt, Word};

#[link(wasm_import_module = "miden:prelude/std_crypto_dsa")]
#[link(wasm_import_module = "miden:stdlib/std_crypto_dsa")]
extern "C" {
#[link_name = "rpo_falcon512_verify<0x0000000000000000000000000000000000000000000000000000000000000000>"]
fn extern_rpo_falcon512_verify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! value per element.
use crate::Felt;

// #[link(wasm_import_module = "miden:prelude/std_crypto_hashes")]
#[link(wasm_import_module = "std::crypto_hashes")]
extern "C" {
/// Computes BLAKE3 1-to-1 hash.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloc::vec::Vec;

use crate::{Felt, Word};

#[link(wasm_import_module = "miden:prelude/std_mem")]
#[link(wasm_import_module = "miden:stdlib/std_mem")]
extern "C" {

/// Moves an arbitrary number of words from the advice stack to memory.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sdk/tx-kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ edition.workspace = true
crate-type = ["rlib"]

[dependencies]
miden-prelude = { path = "../prelude" }
miden-stdlib-sys = { path = "../stdlib-sys" }
2 changes: 1 addition & 1 deletion sdk/tx-kernel/src/externs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use miden_prelude::Felt;
use miden_stdlib_sys::Felt;

use crate::{AccountId, CoreAsset, NoteId, NoteType, Tag};

Expand Down
2 changes: 1 addition & 1 deletion sdk/tx-kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern crate alloc;

use alloc::vec::Vec;

use miden_prelude::Felt;
use miden_stdlib_sys::Felt;

/// Get the account ID of the currently executing note account.
pub fn get_id() -> AccountId {
Expand Down
2 changes: 1 addition & 1 deletion sdk/tx-kernel/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use miden_prelude::{Felt, Word};
use miden_stdlib_sys::{Felt, Word};

#[repr(transparent)]
#[derive(Copy, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/add_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $add_felt.wasm
(type (;0;) (func (param f64 f64) (result f64)))
(import "miden:prelude/intrinsics_felt" "add" (func $miden_prelude::intrinsics::felt::extern_add (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "add" (func $miden_stdlib_sys::intrinsics::felt::extern_add (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result f64)
local.get 0
local.get 1
call $miden_prelude::intrinsics::felt::extern_add
call $miden_stdlib_sys::intrinsics::felt::extern_add
)
(table (;0;) 1 1 funcref)
(memory (;0;) 16)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/div_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $div_felt.wasm
(type (;0;) (func (param f64 f64) (result f64)))
(import "miden:prelude/intrinsics_felt" "div" (func $miden_prelude::intrinsics::felt::extern_div (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "div" (func $miden_stdlib_sys::intrinsics::felt::extern_div (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result f64)
local.get 0
local.get 1
call $miden_prelude::intrinsics::felt::extern_div
call $miden_stdlib_sys::intrinsics::felt::extern_div
)
(table (;0;) 1 1 funcref)
(memory (;0;) 16)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/eq_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $eq_felt.wasm
(type (;0;) (func (param f64 f64) (result i32)))
(import "miden:prelude/intrinsics_felt" "eq" (func $miden_prelude::intrinsics::felt::extern_eq (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "eq" (func $miden_stdlib_sys::intrinsics::felt::extern_eq (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result i32)
local.get 0
local.get 1
call $miden_prelude::intrinsics::felt::extern_eq
call $miden_stdlib_sys::intrinsics::felt::extern_eq
i32.const 1
i32.eq
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/ge_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $ge_felt.wasm
(type (;0;) (func (param f64 f64) (result i32)))
(import "miden:prelude/intrinsics_felt" "ge" (func $miden_prelude::intrinsics::felt::extern_ge (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "ge" (func $miden_stdlib_sys::intrinsics::felt::extern_ge (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result i32)
local.get 0
local.get 1
call $miden_prelude::intrinsics::felt::extern_ge
call $miden_stdlib_sys::intrinsics::felt::extern_ge
i32.const 0
i32.ne
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/gt_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $gt_felt.wasm
(type (;0;) (func (param f64 f64) (result i32)))
(import "miden:prelude/intrinsics_felt" "gt" (func $miden_prelude::intrinsics::felt::extern_gt (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "gt" (func $miden_stdlib_sys::intrinsics::felt::extern_gt (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result i32)
local.get 0
local.get 1
call $miden_prelude::intrinsics::felt::extern_gt
call $miden_stdlib_sys::intrinsics::felt::extern_gt
i32.const 0
i32.ne
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/le_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $le_felt.wasm
(type (;0;) (func (param f64 f64) (result i32)))
(import "miden:prelude/intrinsics_felt" "le" (func $miden_prelude::intrinsics::felt::extern_le (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "le" (func $miden_stdlib_sys::intrinsics::felt::extern_le (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result i32)
local.get 1
local.get 0
call $miden_prelude::intrinsics::felt::extern_le
call $miden_stdlib_sys::intrinsics::felt::extern_le
i32.const 0
i32.ne
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/lt_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $lt_felt.wasm
(type (;0;) (func (param f64 f64) (result i32)))
(import "miden:prelude/intrinsics_felt" "lt" (func $miden_prelude::intrinsics::felt::extern_lt (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "lt" (func $miden_stdlib_sys::intrinsics::felt::extern_lt (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result i32)
local.get 1
local.get 0
call $miden_prelude::intrinsics::felt::extern_lt
call $miden_stdlib_sys::intrinsics::felt::extern_lt
i32.const 0
i32.ne
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/mul_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $mul_felt.wasm
(type (;0;) (func (param f64 f64) (result f64)))
(import "miden:prelude/intrinsics_felt" "mul" (func $miden_prelude::intrinsics::felt::extern_mul (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "mul" (func $miden_stdlib_sys::intrinsics::felt::extern_mul (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result f64)
local.get 0
local.get 1
call $miden_prelude::intrinsics::felt::extern_mul
call $miden_stdlib_sys::intrinsics::felt::extern_mul
)
(table (;0;) 1 1 funcref)
(memory (;0;) 16)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expected/neg_felt.wat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(module $neg_felt.wasm
(type (;0;) (func (param f64 f64) (result f64)))
(import "miden:prelude/intrinsics_felt" "sub" (func $miden_prelude::intrinsics::felt::extern_sub (;0;) (type 0)))
(import "miden:stdlib/intrinsics_felt" "sub" (func $miden_stdlib_sys::intrinsics::felt::extern_sub (;0;) (type 0)))
(func $entrypoint (;1;) (type 0) (param f64 f64) (result f64)
local.get 0
local.get 1
call $miden_prelude::intrinsics::felt::extern_sub
call $miden_stdlib_sys::intrinsics::felt::extern_sub
)
(table (;0;) 1 1 funcref)
(memory (;0;) 16)
Expand Down
Loading

0 comments on commit 4b01c5a

Please sign in to comment.