From 1612b680cb6785331d06888a16d397584ecd28e0 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 17 Dec 2023 10:36:40 +0100 Subject: [PATCH] vm: provide macro assembly in-line compiler --- Cargo.lock | 2 +- src/vm/macroasm.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/vm/mod.rs | 3 +++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/vm/macroasm.rs diff --git a/Cargo.lock b/Cargo.lock index 6f9d3752..2f969970 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,7 @@ version = 3 [[package]] name = "aluvm" version = "0.11.0-beta.1" -source = "git+https://github.com/AluVM/rust-aluvm?branch=v0.11#4077ebb1e68aaf42e6fa721d503db6cf236be52f" +source = "git+https://github.com/AluVM/rust-aluvm?branch=v0.11#34894fe14cbbd3312122a7854072056756798a03" dependencies = [ "amplify", "baid58", diff --git a/src/vm/macroasm.rs b/src/vm/macroasm.rs new file mode 100644 index 00000000..0aa25aed --- /dev/null +++ b/src/vm/macroasm.rs @@ -0,0 +1,39 @@ +// RGB Core Library: consensus layer for RGB smart contracts. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Written in 2019-2023 by +// Dr Maxim Orlovsky +// +// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved. +// Copyright (C) 2019-2023 Dr Maxim Orlovsky. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[macro_export] +macro_rules! rgbasm { + ($( $tt:tt )+) => {{ #[allow(unused_imports)] { + use $crate::vm::{RgbIsa, ContractOp, TimechainOp}; + use $crate::vm::aluasm_isa; + use $crate::isa_instr; + aluasm_isa! { RgbIsa => $( $tt )+ } + } }}; +} + +#[macro_export] +macro_rules! isa_instr { + (ldg $t:literal, $no:literal,s16[$s_idx:literal]) => {{ RgbIsa::Contract(ContractOp::LdG($t.into(), $no, RegS::from($s_idx))) }}; + (lds $t:literal, $no:literal,s16[$s_idx:literal]) => {{ RgbIsa::Contract(ContractOp::LdS($t.into(), $no, RegS::from($s_idx))) }}; + (ldp $t:literal, $no:literal,s16[$s_idx:literal]) => {{ RgbIsa::Contract(ContractOp::LdP($t.into(), $no, RegS::from($s_idx))) }}; + ($op:ident $($tt:tt)+) => {{ compile_error!(concat!("unknown RGB assembly opcode `", stringify!($op), "`")) }}; +} diff --git a/src/vm/mod.rs b/src/vm/mod.rs index b4b43fd2..f535a188 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -30,7 +30,10 @@ mod op_contract; mod op_timechain; mod script; mod runtime; +#[macro_use] +mod macroasm; +pub use aluvm::aluasm_isa; pub use isa::RgbIsa; pub use op_contract::ContractOp; pub use op_timechain::TimechainOp;