begin coroutine
This commit is contained in:
parent
17ffb11f34
commit
e09a4fc2d4
3 changed files with 64 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::{collections::HashMap, fs, io::{stdin, BufReader, Read, Write}, net::{self, TcpListener, TcpStream}, process, thread::sleep, time::{Duration, UNIX_EPOCH}, vec};
|
||||
|
||||
use crate::{decompiler::DecompiledOperation, errors::{create_error, print_error, ErrorSubType, ErrorType}, virtualmachine::{Machine, TableValue, VMMemory, VMMemoryBoolean, VMMemoryNativeFunction, VMMemoryNull, VMMemoryNumber, VMMemoryString, VMMemoryTable}};
|
||||
use crate::{decompiler::{DecompiledFunction, DecompiledOperation}, errors::{create_error, print_error, ErrorSubType, ErrorType}, virtualmachine::{Machine, TableValue, VMMemory, VMMemoryBoolean, VMMemoryNativeFunction, VMMemoryNull, VMMemoryNumber, VMMemoryString, VMMemoryTable, VMState}, Context};
|
||||
|
||||
fn get_string_from_vmmem(mem: &VMMemory) -> String {
|
||||
let mut out = String::new();
|
||||
|
@ -967,6 +967,43 @@ fn intezo_irj(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemor
|
|||
return VMMemory::Null(VMMemoryNull { variable_id: 0 });
|
||||
}
|
||||
|
||||
fn krumpli_varj(machine: &mut Machine, _op: &DecompiledOperation, _args: Vec<VMMemory>) -> VMMemory {
|
||||
machine.state = VMState::Paused;
|
||||
return VMMemory::Null(VMMemoryNull { variable_id: 0 });
|
||||
}
|
||||
fn add_func(n_funcs: &mut Vec<DecompiledFunction>, n_ctx: &mut Vec<Context>, machine: &mut Machine, func: usize, pos: &mut usize) {
|
||||
let mut exe_func = machine.functions[func].clone();
|
||||
let func_clone = machine.functions.clone();
|
||||
n_ctx.push(machine.ctx[func].clone());
|
||||
for (fid, fpos) in &func_clone[func].functions {
|
||||
*pos += 1;
|
||||
add_func(n_funcs, n_ctx, machine, *fpos as usize, pos);
|
||||
exe_func.functions.insert(*fid, *pos as u32);
|
||||
}
|
||||
n_funcs.push(exe_func);
|
||||
}
|
||||
fn krumpli_letrehoz(machine: &mut Machine, op: &DecompiledOperation, args: Vec<VMMemory>) -> VMMemory {
|
||||
arg_expect(&args, 0, "function", machine, op);
|
||||
let func = match &args[0] {
|
||||
VMMemory::Function(func) => func.clone(),
|
||||
_ => {
|
||||
error(String::from("Expected a function"), machine, op);
|
||||
return VMMemory::Null(VMMemoryNull { variable_id: 0 });
|
||||
}
|
||||
};
|
||||
let mut n_funcs: Vec<DecompiledFunction> = vec![];
|
||||
let mut n_ctx: Vec<Context> = vec![];
|
||||
add_func(&mut n_funcs, &mut n_ctx, machine, func.id, &mut 0);
|
||||
println!("{:?}", n_funcs);
|
||||
println!("{:?}", n_ctx);
|
||||
let mut vm = Machine::new(n_ctx);
|
||||
vm.load_functions(n_funcs);
|
||||
vm.memory = machine.memory.clone();
|
||||
let cor_id = machine.storage.len();
|
||||
machine.storage.push(Box::new(vm));
|
||||
return VMMemory::Number(VMMemoryNumber { value: cor_id as f64, variable_id: 0 });
|
||||
}
|
||||
|
||||
pub fn generate() -> HashMap<String, VMMemory> {
|
||||
let mut mem: HashMap<String, VMMemory> = HashMap::new();
|
||||
|
||||
|
@ -1134,5 +1171,17 @@ pub fn generate() -> HashMap<String, VMMemory> {
|
|||
];
|
||||
mem.insert(String::from("intéző"), VMMemory::Table(VMMemoryTable { values: intezo, variable_id: 0 }));
|
||||
|
||||
let krumpli: Vec<TableValue> = vec![
|
||||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("várj"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: krumpli_varj, variable_id: 0 }),
|
||||
},
|
||||
TableValue {
|
||||
key: VMMemory::String(VMMemoryString { value: String::from("létrehoz"), variable_id: 0 }),
|
||||
value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: krumpli_letrehoz, variable_id: 0 }),
|
||||
},
|
||||
];
|
||||
mem.insert(String::from("krumpli"), VMMemory::Table(VMMemoryTable { values: krumpli, variable_id: 0 }));
|
||||
|
||||
return mem;
|
||||
}
|
|
@ -74,7 +74,7 @@ pub enum VMState {
|
|||
|
||||
pub struct Machine {
|
||||
pub memory: Vec<VMMemory>,
|
||||
functions: Vec<DecompiledFunction>,
|
||||
pub functions: Vec<DecompiledFunction>,
|
||||
pub stack: Vec<VMMemory>,
|
||||
pub registers: Vec<Register>,
|
||||
pub call_stack: Vec<CallStack>,
|
||||
|
@ -445,6 +445,11 @@ impl Machine {
|
|||
self.state = VMState::Paused
|
||||
}
|
||||
|
||||
pub fn load_functions(&mut self, functions: Vec<DecompiledFunction>) {
|
||||
self.functions = functions;
|
||||
self.state = VMState::Paused;
|
||||
}
|
||||
|
||||
pub fn resume(&mut self) {
|
||||
match self.state {
|
||||
VMState::Paused => {},
|
||||
|
|
9
test.asl
9
test.asl
|
@ -1 +1,8 @@
|
|||
gethelj test = szaft"a"szaft
|
||||
lőcsve test() {
|
||||
lőcsve toast() {
|
||||
ugass(2)
|
||||
}
|
||||
toast()
|
||||
ugass(1)
|
||||
}
|
||||
krumpli.létrehoz(test)
|
Loading…
Add table
Add a link
Reference in a new issue