cgen: basic assert

pull/4121/head
Alexander Medvednikov 2020-03-26 10:27:46 +01:00
parent ec4be80bcc
commit 1f3428f282
3 changed files with 18 additions and 4 deletions

View File

@ -527,6 +527,9 @@ pub fn (c mut Checker) array_init(array_init mut ast.ArrayInit) table.Type {
fn (c mut Checker) stmt(node ast.Stmt) { fn (c mut Checker) stmt(node ast.Stmt) {
// c.expected_type = table.void_type // c.expected_type = table.void_type
match mut node { match mut node {
ast.AssertStmt {
c.expr(it.expr)
}
ast.AssignStmt { ast.AssignStmt {
c.assign_stmt(mut it) c.assign_stmt(mut it)
c.expected_type = table.void_type c.expected_type = table.void_type

View File

@ -268,12 +268,21 @@ fn (g mut Gen) stmt(node ast.Stmt) {
// println('cgen.stmt()') // println('cgen.stmt()')
// g.writeln('//// stmt start') // g.writeln('//// stmt start')
match node { match node {
ast.AssignStmt {
g.gen_assign_stmt(it)
}
ast.AssertStmt { ast.AssertStmt {
g.writeln('// assert') g.writeln('// assert')
// TODO g.write('if (!(')
g.expr(it.expr)
g.writeln(')) {')
g.writeln('g_test_fails++;')
g.writeln('puts("FAILED assertion");')
g.writeln('puts("function: $g.fn_decl.name");')
g.writeln('} else {')
g.writeln('g_test_oks++;')
g.writeln('puts("OK $g.fn_decl.name");')
g.writeln('}')
}
ast.AssignStmt {
g.gen_assign_stmt(it)
} }
ast.Attr { ast.Attr {
g.writeln('//[$it.name]') g.writeln('//[$it.name]')

View File

@ -186,6 +186,8 @@ extern wchar_t **_wenviron;
//================================== GLOBALS =================================*/ //================================== GLOBALS =================================*/
byte g_str_buf[1024]; byte g_str_buf[1024];
int g_test_fails = 0;
int g_test_oks = 0;
int load_so(byteptr); int load_so(byteptr);
void reload_so(); void reload_so();
void _vinit(); void _vinit();