error system now works for multiple functions
This commit is contained in:
parent
414b740ebc
commit
867799fec3
4 changed files with 59 additions and 41 deletions
|
@ -676,9 +676,10 @@ fn bin_to_num(bin: String) -> usize {
|
|||
return num;
|
||||
}
|
||||
|
||||
fn compile_body(compiled: Compiled, fpos: &mut usize, ctx: &Context) -> Vec<u8> {
|
||||
fn compile_body(compiled: Compiled, fpos: &mut usize, ctx: &Context) -> (Vec<u8>, Vec<Context>) {
|
||||
let mut output: Vec<u8> = vec![];
|
||||
let mut additional: Vec<Vec<u8>> = vec![];
|
||||
let mut contexts: Vec<Context> = vec![ctx.clone()];
|
||||
//function
|
||||
//function headers
|
||||
append_be_num(&mut output, 4, compiled.variables.len());
|
||||
|
@ -698,7 +699,12 @@ fn compile_body(compiled: Compiled, fpos: &mut usize, ctx: &Context) -> Vec<u8>
|
|||
*fpos += 1;
|
||||
append_be_num(&mut output, 3, *funcs as usize);
|
||||
append_be_num(&mut output, 4, *fpos);
|
||||
additional.push(compile_body(compiled.functions[funcs].clone(), fpos, ctx));
|
||||
let (compiled, mut context) = compile_body(compiled.functions[funcs].clone(), fpos, ctx);
|
||||
for c in &mut context {
|
||||
c.c_funcid = *fpos
|
||||
}
|
||||
contexts.extend_from_slice(&context);
|
||||
additional.push(compiled);
|
||||
}
|
||||
//function body
|
||||
append_be_num(&mut output, 4, compiled.operations.len());
|
||||
|
@ -727,10 +733,10 @@ fn compile_body(compiled: Compiled, fpos: &mut usize, ctx: &Context) -> Vec<u8>
|
|||
output.extend_from_slice(&addition);
|
||||
}
|
||||
|
||||
return output;
|
||||
return (output, contexts);
|
||||
}
|
||||
|
||||
pub fn compile(ast: Vec<ASTPart>, ctx: &Context) -> Vec<u8> {
|
||||
pub fn compile(ast: Vec<ASTPart>, ctx: &Context) -> (Vec<u8>, Vec<Context>) {
|
||||
let mut next_var_id: u32 = 1;
|
||||
let mut registers: Vec<RegisterState> = vec![];
|
||||
for i in 0..17 {
|
||||
|
@ -758,7 +764,7 @@ pub fn compile(ast: Vec<ASTPart>, ctx: &Context) -> Vec<u8> {
|
|||
output.push(0);
|
||||
//functions
|
||||
let mut fpos = 0;
|
||||
let body = compile_body(compiled, &mut fpos, ctx);
|
||||
let (body, contexts) = compile_body(compiled, &mut fpos, ctx);
|
||||
output.extend_from_slice(&body);
|
||||
|
||||
//update function count
|
||||
|
@ -768,5 +774,5 @@ pub fn compile(ast: Vec<ASTPart>, ctx: &Context) -> Vec<u8> {
|
|||
output[8] = ((fpos >> 8) & 0xFF) as u8;
|
||||
output[9] = (fpos & 0xFF) as u8;
|
||||
|
||||
return output;
|
||||
return (output, contexts);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue