diff --git a/plugins/b-mode.el b/plugins/b-mode.el index 641e22b..42ac9e1 100644 --- a/plugins/b-mode.el +++ b/plugins/b-mode.el @@ -2,7 +2,8 @@ (define-generic-mode 'b-mode '(("/*" . "*/")) - '("return" "auto" "extrn" "eof" "while" "if" "else" "goto" "switch" "break" "case" "default") + '("return" "auto" "extrn" "eof" "while" "if" "else" "goto" "switch" "break" + "case" "default" "#import") '(("\\b[0-9]+\\b" . font-lock-constant-face)) '("\\.b$") '() ;; TODO: Highlight string & char literals here diff --git a/run_tests.sh b/run_tests.sh index a009bb6..9bfd85f 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,6 +1,7 @@ #!/bin/sh # TODO: Replace this with a B program +set -e for f in test/*; do cargo -q run --release -- -r $f diff --git a/src/codegen.rs b/src/codegen.rs index 2e733a2..1a9d2e3 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -1113,6 +1113,7 @@ fn gen_statement( Statement::Break(pos) => { match c.break_dest_stack.last() { Some(label) => { + instructions.push(format!("# break")); instructions.push(format!("jmp {}", label)); Ok(()) }, @@ -1123,6 +1124,7 @@ fn gen_statement( Statement::Goto(pos, name) => { match c.labels.get(name) { Some(label) => { + instructions.push(format!("# goto {}", label)); instructions.push(format!("jmp {}", label)); Ok(()) }, @@ -1137,10 +1139,14 @@ fn gen_statement( Ok(()) }, Statement::Return => { + instructions.push(format!("# return")); gen_return(instructions); Ok(()) }, - Statement::ReturnExpr(expr) => gen_return_expr(c, instructions, expr), + Statement::ReturnExpr(expr) => { + instructions.push(format!("# return")); + gen_return_expr(c, instructions, expr) + }, Statement::Block(statements) => { c.new_scope(); for statement in statements { @@ -1149,17 +1155,35 @@ fn gen_statement( c.drop_scope(); Ok(()) }, - Statement::Auto(pos, vars) => gen_auto(c, instructions, pos, vars), - Statement::Extern(pos, vars) => gen_extern(c, pos, vars), + Statement::Auto(pos, vars) => { + instructions.push(format!("# auto")); + gen_auto(c, instructions, pos, vars) + }, + Statement::Extern(pos, vars) => { + instructions.push(format!("# extrn")); + gen_extern(c, pos, vars) + }, Statement::Expr(expr) => { + instructions.push(format!("# Expression statement")); gen_expr(c, instructions, expr)?; Ok(()) }, - Statement::If(cond, if_body, None) => gen_if(c, instructions, cond, if_body), - Statement::While(cond, body) => gen_while(c, instructions, cond, body), - Statement::If(cond, if_body, Some(else_body)) => - gen_if_else(c, instructions, cond, if_body, else_body), - Statement::Switch(cond, body) => gen_switch(c, instructions, cond, body), + Statement::If(cond, if_body, None) => { + instructions.push(format!("# if")); + gen_if(c, instructions, cond, if_body) + }, + Statement::If(cond, if_body, Some(else_body)) => { + instructions.push(format!("# if")); + gen_if_else(c, instructions, cond, if_body, else_body) + }, + Statement::While(cond, body) => { + instructions.push(format!("# while")); + gen_while(c, instructions, cond, body) + }, + Statement::Switch(cond, body) => { + instructions.push(format!("# switch")); + gen_switch(c, instructions, cond, body) + }, } } diff --git a/test/call.b b/test/call.b new file mode 100644 index 0000000..63d917b --- /dev/null +++ b/test/call.b @@ -0,0 +1,18 @@ +#import "../assets/best.b"; + +main() { + foo(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); +} + +foo(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { + assert_eq_int(0, a0); + assert_eq_int(1, a1); + assert_eq_int(2, a2); + assert_eq_int(3, a3); + assert_eq_int(4, a4); + assert_eq_int(5, a5); + assert_eq_int(6, a6); + assert_eq_int(7, a7); + assert_eq_int(8, a8); + assert_eq_int(9, a9); +}