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) {
// c.expected_type = table.void_type
match mut node {
ast.AssertStmt {
c.expr(it.expr)
}
ast.AssignStmt {
c.assign_stmt(mut it)
c.expected_type = table.void_type

View File

@ -268,12 +268,21 @@ fn (g mut Gen) stmt(node ast.Stmt) {
// println('cgen.stmt()')
// g.writeln('//// stmt start')
match node {
ast.AssignStmt {
g.gen_assign_stmt(it)
}
ast.AssertStmt {
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 {
g.writeln('//[$it.name]')

View File

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