huff_utils/bytecode.rs
1//! Bytecode Traits
2//!
3//! Abstract translating state into bytecode.
4
5use crate::prelude::Statement;
6
7/// A Single Byte
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
9pub struct Byte(pub String);
10
11/// Intermediate Bytecode Representation
12#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
13pub enum IRByte {
14 /// Bytes
15 Byte(Byte),
16 /// Macro Statement to be expanded
17 Statement(Statement),
18 /// A Constant to be referenced
19 Constant(String),
20 /// An Arg Call needs to use the calling macro context
21 ArgCall(String),
22}
23
24/// Full Intermediate Bytecode Representation
25#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
26pub struct IRBytecode(pub Vec<IRByte>);
27
28/// ToIRBytecode
29///
30/// Converts a stateful object to intermediate bytecode
31pub trait ToIRBytecode<E> {
32 /// Translates `self` to intermediate bytecode representation
33 fn to_irbytecode(&self) -> Result<IRBytecode, E>;
34}
35
36/// Full Bytecode
37#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
38pub struct Bytecode(pub String);
39
40/// ToBytecode
41///
42/// Converts a stateful object to bytecode
43pub trait ToBytecode<'a, E> {
44 /// Translates `self` to a bytecode string
45 fn to_bytecode(&self) -> Result<Bytecode, E>;
46}