From 28391f0287483b8e10397cb24cbc7d6ad0fb8faa 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 --- src/vm/macroasm.rs | 37 +++++++++++++++++++++++++++++++++++++ src/vm/mod.rs | 2 ++ 2 files changed, 39 insertions(+) create mode 100644 src/vm/macroasm.rs diff --git a/src/vm/macroasm.rs b/src/vm/macroasm.rs new file mode 100644 index 00000000..4d7bcc3f --- /dev/null +++ b/src/vm/macroasm.rs @@ -0,0 +1,37 @@ +// 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 ::rgb::vm::RgbIsa; + $crate::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..82a1578a 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -30,6 +30,8 @@ mod op_contract; mod op_timechain; mod script; mod runtime; +#[macro_use] +mod macroasm; pub use isa::RgbIsa; pub use op_contract::ContractOp;