Skip to content

Commit

Permalink
vm: provide macro assembly in-line compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 17, 2023
1 parent 5547a09 commit 1612b68
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

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

39 changes: 39 additions & 0 deletions src/vm/macroasm.rs
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
//
// 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), "`")) }};
}
3 changes: 3 additions & 0 deletions src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1612b68

Please sign in to comment.