♻️ refactor: extract module

main
_ 2023-09-26 16:47:51 -05:00
parent 5466e6ec56
commit 448ecc08d2
5 changed files with 80 additions and 75 deletions

65
src/instruction.rs Normal file
View File

@ -0,0 +1,65 @@
#[derive (Debug, PartialEq)]
pub enum Instruction {
Add (u8, u8, u8),
Call (u8, u8, u8),
Closure (u8, u32),
// Equals Constant?
EqK (u8, u8, bool),
ExtraArg (u32),
// Get Immediate?
GetI (u8, u8, u8),
// Get Table, Upvalue
GetTabUp (u8, u8, u8),
GetUpVal (u8, u8),
// Jump
Jmp (i32),
// Load F (Float?)
LoadF (u8, i32),
LoadFalse (u8),
// Load Integer?
LoadI (u8, i32),
// Load Constant
LoadK (u8, u32),
LoadNil (u8),
LoadTrue (u8),
// MetaMethod, Binary
MmBin (u8, u8, u8),
Move (u8, u8),
Mul (u8, u8, u8),
NewTable (u8),
Not (u8, u8),
// (A, B, _C, k) Return B - 1 registers starting with A
Return (u8, u8, u8, bool),
Return0,
// Return just one register
Return1 (u8),
SetTabUp (u8, u8, u8),
TailCall (u8, u8, u8, bool),
Test (u8, bool),
VarArgPrep (i32),
}

View File

@ -1,9 +1,11 @@
use std::io::Read; use std::io::Read;
use crate::state::{ use crate::{
Block, instruction::Instruction as Inst,
Chunk, state::{
Instruction as Inst, Block,
Chunk,
}
}; };
/// Invoke `luac` as a subprocess /// Invoke `luac` as a subprocess

View File

@ -1,3 +1,4 @@
mod instruction;
mod loader; mod loader;
mod state; mod state;
mod value; mod value;

View File

@ -1,77 +1,14 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::value::{ use crate::{
BogusClosure, instruction::Instruction,
Table, value::{
Value, BogusClosure,
Table,
Value,
},
}; };
#[derive (Debug, PartialEq)]
pub enum Instruction {
Add (u8, u8, u8),
Call (u8, u8, u8),
Closure (u8, u32),
// Equals Constant?
EqK (u8, u8, bool),
ExtraArg (u32),
// Get Immediate?
GetI (u8, u8, u8),
// Get Table, Upvalue
GetTabUp (u8, u8, u8),
GetUpVal (u8, u8),
// Jump
Jmp (i32),
// Load F (Float?)
LoadF (u8, i32),
LoadFalse (u8),
// Load Integer?
LoadI (u8, i32),
// Load Constant
LoadK (u8, u32),
LoadNil (u8),
LoadTrue (u8),
// MetaMethod, Binary
MmBin (u8, u8, u8),
Move (u8, u8),
Mul (u8, u8, u8),
NewTable (u8),
Not (u8, u8),
// (A, B, _C, k) Return B - 1 registers starting with A
Return (u8, u8, u8, bool),
Return0,
// Return just one register
Return1 (u8),
SetTabUp (u8, u8, u8),
TailCall (u8, u8, u8, bool),
Test (u8, bool),
VarArgPrep (i32),
}
pub struct Block { pub struct Block {
pub instructions: Vec <Instruction>, pub instructions: Vec <Instruction>,
pub constants: Vec <Value>, pub constants: Vec <Value>,

View File

@ -1,11 +1,11 @@
use std::hash::Hash; use std::hash::Hash;
use crate::{ use crate::{
instruction::Instruction as Inst,
loader, loader,
state::{ state::{
Block, Block,
Chunk, Chunk,
Instruction as Inst,
State, State,
}, },
value::Value, value::Value,