use sexp::SourcePosition; use crate::asm::data::{Rd, RdObj, Wr, RdWr}; use crate::asm::data::literal::{DebugMsg, Label, RoutineName}; use crate::asm::instr::Op; use crate::asm::instr::op::OpKind; #[derive(Debug)] pub enum Barrier { /// Barrier that logically opens a section that cannot be jumped into, typically a routine Open(Label), /// Closing counterpart to the Open barrier Close(Label), /// Stand-alone barrier Standalone, } #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum SleepUnit { Usec, Msec, Sec } impl SleepUnit { pub fn micros(self) -> u64 { match self { SleepUnit::Usec => 1, SleepUnit::Msec => 1000, SleepUnit::Sec => 1000000, } } } #[derive(Clone, Debug, PartialEq)] pub enum LdsValue { Values(Vec), Chars(String), } #[derive(Debug)] pub enum BuiltinOp { /// Do nothing (costs one cycle) Nop, /// Stop execution Halt, /// Sleep Sleep { count: Rd, unit_us: SleepUnit, }, /// Mark a jump target. Label(Label), /// Jump to a label Jump(Label), /// Mark a far jump target (can be jumped to from another routine). /// This label is preserved in optimized code. FarLabel(Label), /// Jump to a label that can be in another function FarJump(Label), /// Call a routine with arguments. /// The arguments are passed as argX. Return values are stored in resX registers. Call(RoutineName, Vec), /// Exit the current routine with return values Ret(Vec), /// Mark a routine entry point (call target). /// The RoutineName struct includes its arity Routine(RoutineName), /// Skip backward or forward. The skip count can be defined by an argument. Skip(Rd), /// Deny jumps, skips and run across this address, producing a run-time fault. Barrier { kind: Barrier, msg: Option, }, /// Generate a run-time fault with a debugger message Fault(Option), /// Deallocate an extension object. /// The object is released and the handle becomes invalid. Delete(RdObj), /// Move a value Move { dst: Wr, src: Rd }, /// Move lower 32 bits Move32 { dst: RdWr, src: Rd }, /// Move lower 16 bits Move16 { dst: RdWr, src: Rd }, /// Move lower 8 bits Move8 { dst: RdWr, src: Rd }, /// Move N values MoveMultiple { dst: Wr, src: Rd, count: Rd }, /// Move values from a string or integer list MoveSequence { dst: Wr, value: LdsValue }, /// Swap two registers Exchange { a: RdWr, b: RdWr }, /// Store runtime status to a register StoreFlags { dst: Wr }, /// Load runtime status from a register LoadFlags { src: Rd }, } impl BuiltinOp { pub fn into_op(self: BuiltinOp, pos: SourcePosition) -> Op { Op { kind: self.into(), pos, cond: None, } } } impl From for OpKind { fn from(bo: BuiltinOp) -> Self { OpKind::BuiltIn(bo) } }