use std::{ffi::c_long, sync::LazyLock};
use ahash::AHashMap;
use crate::types::{ArithOp, Function::*, Instr, MemOp, Value};
unsafe extern "C" {
pub(crate) fn syscall(num: c_long, ...) -> c_long;
}
pub(crate) fn pow(x: Value, y: Value) -> Option<Value> {
Some(x.wrapping_pow(y.try_into().ok()?))
}
pub static FUNCTIONS: LazyLock<AHashMap<&str, Instr>> = LazyLock::new(|| {
AHashMap::from([
("+", Instr::Arith(ArithOp::Add)),
("-", Instr::Arith(ArithOp::Sub)),
("*", Instr::Arith(ArithOp::Mul)),
("/", Instr::Arith(ArithOp::Div)),
("%", Instr::Arith(ArithOp::Rem)),
("<", Instr::Arith(ArithOp::Lt)),
("**", Instr::Arith(ArithOp::Pow)),
("read8", Instr::Mem(MemOp::Read8)),
("write8", Instr::Mem(MemOp::Write8)),
("read_native", Instr::Mem(MemOp::ReadNative)),
("write_native", Instr::Mem(MemOp::WriteNative)),
("width_native", Instr::Mem(MemOp::WidthNative)),
("syscall", Instr::Syscall),
("drop_range", Instr::DropRange),
])
});