added table get
This commit is contained in:
parent
4faabe0d9c
commit
9b0335e8d6
5 changed files with 54 additions and 4 deletions
|
@ -530,6 +530,17 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
|
|||
}
|
||||
return reg.register;
|
||||
},
|
||||
ASTPart::TableGet(tbl_get) => {
|
||||
let table_reg = do_ast_op(*tbl_get.table, op_count, ops, variables, next_var_id, strings, next_string_id, functions, next_function_id, registers);
|
||||
let key_reg = do_ast_op(*tbl_get.key, op_count, ops, variables, next_var_id, strings, next_string_id, functions, next_function_id, registers);
|
||||
let reg = allocate_register(registers);
|
||||
if reg.unbind_before {
|
||||
ops.push(Operation { opcode: 8, arg1: Some(reg.register), arg2: None, arg3: None });
|
||||
}
|
||||
ops.push(Operation { opcode: 30, arg1: Some(table_reg), arg2: Some(key_reg as i64), arg3: Some(reg.register) });
|
||||
set_register(registers, RegisterState { id: reg.register, used: true, variable: 0, last_used: *op_count });
|
||||
return reg.register;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -114,6 +114,13 @@ fn log_ast_part(part: &ASTPart, prefix: String) {
|
|||
log_ast_part(&table_value.value, format!("{} ", prefix));
|
||||
}
|
||||
},
|
||||
ASTPart::TableGet(tbl_get) => {
|
||||
println!("{}{}: Table Get:", prefix, tbl_get.pos);
|
||||
println!("{} Table:", prefix);
|
||||
log_ast_part(&tbl_get.table, format!("{} ", prefix));
|
||||
println!("{} Key:", prefix);
|
||||
log_ast_part(&tbl_get.key, format!("{} ", prefix));
|
||||
},
|
||||
ASTPart::NOOP => println!("{}NOOP", prefix)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ pub enum ASTPart {
|
|||
Continue(AstContinue),
|
||||
Return(AstReturn),
|
||||
Table(AstTable),
|
||||
TableGet(AstTableGet),
|
||||
NOOP
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -133,6 +134,12 @@ pub struct TableValue {
|
|||
pub value: ASTPart,
|
||||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstTableGet {
|
||||
pub table: Box<ASTPart>,
|
||||
pub key: Box<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
|
||||
fn is_end(input: &Token, end: &Vec<Token>) -> bool {
|
||||
for token in end {
|
||||
|
@ -207,6 +214,9 @@ fn shunt(input: Vec<ASTPart>) -> ASTPart {
|
|||
ASTPart::Table(_) => {
|
||||
output.push(part);
|
||||
},
|
||||
ASTPart::TableGet(_) => {
|
||||
output.push(part);
|
||||
},
|
||||
ASTPart::Operation(op) => {
|
||||
if *op.left != ASTPart::NOOP && *op.right != ASTPart::NOOP {
|
||||
output.push(part);
|
||||
|
@ -418,6 +428,27 @@ fn read_exp(pos: &mut usize, input: &Vec<Token>, ends: &Vec<Token>, parse_ends:
|
|||
if next_token.typ == TokenType::SEPARATOR && next_token.value == "(" {
|
||||
let var = ASTPart::VarRead(AstVarRead { variable: token.value.clone(), pos: token.pos });
|
||||
expressions.push(read_call(var, pos, input));
|
||||
} else if next_token.typ == TokenType::SEPARATOR && next_token.value == "[" {
|
||||
let var_pos = token.pos;
|
||||
let key_ends: Vec<Token> = vec![
|
||||
Token { typ: TokenType::SEPARATOR, value: String::from("]"), pos: 0 }
|
||||
];
|
||||
*pos += 1;
|
||||
let keyy = read_exp(pos, input, &key_ends, &key_ends);
|
||||
match keyy {
|
||||
ASTPart::Table(_) => {
|
||||
panic!("Table keys cannot be tables at {}", input[*pos].pos);
|
||||
},
|
||||
ASTPart::Function(_) => {
|
||||
panic!("Table keys cannot be functions at {}", input[*pos].pos);
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
if input[*pos].typ != TokenType::SEPARATOR || input[*pos].value != "]" {
|
||||
panic!("Unexpected end of key at {}", input[*pos].pos);
|
||||
}
|
||||
*pos += 1;
|
||||
expressions.push(ASTPart::TableGet(AstTableGet { table: Box::new(ASTPart::VarRead(AstVarRead { variable: token.value.clone(), pos: var_pos })), key: Box::new(keyy), pos: var_pos+1 }));
|
||||
} else {
|
||||
expressions.push(ASTPart::VarRead(AstVarRead { variable: token.value.clone(), pos: token.pos }));
|
||||
}
|
||||
|
|
|
@ -44,8 +44,7 @@ pub struct VMMemoryTable {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct TableValue {
|
||||
pub key: VMMemory,
|
||||
pub value: VMMemory,
|
||||
pub pos: usize
|
||||
pub value: VMMemory
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -196,7 +195,7 @@ fn set_mem_tbl_val(tbl: &mut VMMemoryTable, key: VMMemory, value: VMMemory) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
tbl.values.push(TableValue { key, value, pos: tbl.values.len() });
|
||||
tbl.values.push(TableValue { key, value });
|
||||
}
|
||||
|
||||
fn get_mem_tbl_val(tbl: &VMMemoryTable, key: VMMemory) -> Option<&VMMemory> {
|
||||
|
@ -423,6 +422,7 @@ fn load_func(data: Vec<u8>, offset: &mut usize) -> DecompiledFunction {
|
|||
arg3: arg3 as u8,
|
||||
});
|
||||
}
|
||||
println!("Variables: {:?}", variables);
|
||||
return DecompiledFunction {
|
||||
body: body,
|
||||
variables: variables,
|
||||
|
|
3
test.as
3
test.as
|
@ -1 +1,2 @@
|
|||
gethelj a = {1,2,3}
|
||||
gethelj a = {1,2,3}
|
||||
gethelj b = a[0]
|
Loading…
Add table
Add a link
Reference in a new issue