added table set
This commit is contained in:
parent
7276312961
commit
9a915cd274
4 changed files with 52 additions and 5 deletions
|
@ -540,7 +540,13 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
|
|||
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;
|
||||
}
|
||||
},
|
||||
ASTPart::TableSet(tbl_set) => {
|
||||
let table_reg = do_ast_op(*tbl_set.table, op_count, ops, variables, next_var_id, strings, next_string_id, functions, next_function_id, registers);
|
||||
let key_reg = do_ast_op(*tbl_set.key, op_count, ops, variables, next_var_id, strings, next_string_id, functions, next_function_id, registers);
|
||||
let value_reg = do_ast_op(*tbl_set.value, op_count, ops, variables, next_var_id, strings, next_string_id, functions, next_function_id, registers);
|
||||
ops.push(Operation { opcode: 31, arg1: Some(table_reg), arg2: Some(key_reg as i64), arg3: Some(value_reg) });
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
return 0;
|
||||
|
@ -578,6 +584,7 @@ fn compile_function(ast: Vec<ASTPart>, args: Option<Vec<String>>, registers: &mu
|
|||
var.end = ops.len() - 1;
|
||||
}
|
||||
}
|
||||
println!("Compiled operations: {:?}", ops);
|
||||
|
||||
return Compiled {
|
||||
operations: ops,
|
||||
|
|
|
@ -121,6 +121,15 @@ fn log_ast_part(part: &ASTPart, prefix: String) {
|
|||
println!("{} Key:", prefix);
|
||||
log_ast_part(&tbl_get.key, format!("{} ", prefix));
|
||||
},
|
||||
ASTPart::TableSet(tbl_set) => {
|
||||
println!("{}{}: Table Set:", prefix, tbl_set.pos);
|
||||
println!("{} Table:", prefix);
|
||||
log_ast_part(&tbl_set.table, format!("{} ", prefix));
|
||||
println!("{} Key:", prefix);
|
||||
log_ast_part(&tbl_set.key, format!("{} ", prefix));
|
||||
println!("{} Value:", prefix);
|
||||
log_ast_part(&tbl_set.value, format!("{} ", prefix));
|
||||
},
|
||||
ASTPart::NOOP => println!("{}NOOP", prefix)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ pub enum ASTPart {
|
|||
Return(AstReturn),
|
||||
Table(AstTable),
|
||||
TableGet(AstTableGet),
|
||||
TableSet(AstTableSet),
|
||||
NOOP
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -140,6 +141,13 @@ pub struct AstTableGet {
|
|||
pub key: Box<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AstTableSet {
|
||||
pub table: Box<ASTPart>,
|
||||
pub key: Box<ASTPart>,
|
||||
pub value: Box<ASTPart>,
|
||||
pub pos: usize
|
||||
}
|
||||
|
||||
fn is_end(input: &Token, end: &Vec<Token>) -> bool {
|
||||
for token in end {
|
||||
|
@ -629,6 +637,31 @@ fn next_operation(pos: &mut usize, input: &Vec<Token>, op_ends: &Vec<Token>, par
|
|||
if next_token.typ == TokenType::SEPARATOR && next_token.value == "(" {
|
||||
let var = ASTPart::VarRead(AstVarRead { variable: token.value.clone(), pos: token.pos });
|
||||
return read_call(var, pos, input);
|
||||
} else if next_token.typ == TokenType::SEPARATOR && next_token.value == "[" {
|
||||
*pos += 1;
|
||||
let key_ends: Vec<Token> = vec![
|
||||
Token { typ: TokenType::SEPARATOR, value: String::from("]"), pos: 0 }
|
||||
];
|
||||
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;
|
||||
if input[*pos].typ != TokenType::SEPARATOR || input[*pos].value != "=" {
|
||||
panic!("Expected = after key at {}", input[*pos].pos);
|
||||
}
|
||||
*pos += 1;
|
||||
let value = read_exp(pos, input, op_ends, parse_ends);
|
||||
return ASTPart::TableSet(AstTableSet { table: Box::new(ASTPart::VarRead(AstVarRead { variable: token.value.clone(), pos: token.pos })), key: Box::new(keyy), value: Box::new(value), pos: token.pos });
|
||||
} else if next_token.typ == TokenType::SEPARATOR && next_token.value == "=" {
|
||||
*pos += 1;
|
||||
let value = read_exp(pos, input, op_ends, parse_ends);
|
||||
|
|
6
test.as
6
test.as
|
@ -1,4 +1,2 @@
|
|||
gethelj a = lőcsve(m) {
|
||||
gethelj b = m
|
||||
}
|
||||
a(69)
|
||||
gethelj a = {1,2,3}
|
||||
a[0] = 4
|
Loading…
Add table
Add a link
Reference in a new issue