Skip to content

Commit

Permalink
gac: improve handling of Assert & Info
Browse files Browse the repository at this point in the history
... by having the comments generated for them be faithful to the
source code, just like for all other statements.
  • Loading branch information
fingolfin committed Jan 2, 2025
1 parent a3ca9fc commit 36347c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
18 changes: 15 additions & 3 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -4915,7 +4915,11 @@ static void CompInfo(Stat stat)
Int narg;
Int i;

Emit( "\n/* Info( ... ); */\n" );
// print a comment
if ( CompPass == 2 ) {
Emit( "\n/* " ); PrintStat( stat ); Emit( " */\n" );
}

sel = CompExpr( ARGI_INFO( stat, 1 ) );
lev = CompExpr( ARGI_INFO( stat, 2 ) );
lst = CVAR_TEMP( NewTemp( "lst" ) );
Expand Down Expand Up @@ -4951,7 +4955,11 @@ static void CompAssert2(Stat stat)
CVar lev; // the level
CVar cnd; // the condition

Emit( "\n/* Assert( ... ); */\n" );
// print a comment
if ( CompPass == 2 ) {
Emit( "\n/* " ); PrintStat( stat ); Emit( " */\n" );
}

lev = CompExpr(READ_STAT(stat, 0));
Emit( "if ( STATE(CurrentAssertionLevel) >= %i ) {\n", lev );
cnd = CompBoolExpr(READ_STAT(stat, 1));
Expand All @@ -4976,7 +4984,11 @@ static void CompAssert3(Stat stat)
CVar cnd; // the condition
CVar msg; // the message

Emit( "\n/* Assert( ... ); */\n" );
// print a comment
if ( CompPass == 2 ) {
Emit( "\n/* " ); PrintStat( stat ); Emit( " */\n" );
}

lev = CompExpr(READ_STAT(stat, 0));
Emit( "if ( STATE(CurrentAssertionLevel) >= %i ) {\n", lev );
cnd = CompBoolExpr(READ_STAT(stat, 1));
Expand Down
18 changes: 9 additions & 9 deletions tst/test-compile/assert.g.dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static Obj HdlrFunc2 (
DoOperation2Args( CallFuncListOper, t_1, NewPlistFromArgs( t_2, t_3 ) );
}

/* Assert( ... ); */
/* Assert( 1, false, "fail-A" ); */
if ( STATE(CurrentAssertionLevel) >= 1 ) {
t_2 = False;
t_1 = (Obj)(UInt)(t_2 != False);
Expand All @@ -62,7 +62,7 @@ static Obj HdlrFunc2 (
}
}

/* Assert( ... ); */
/* Assert( 1, false ); */
if ( STATE(CurrentAssertionLevel) >= 1 ) {
t_2 = False;
t_1 = (Obj)(UInt)(t_2 != False);
Expand All @@ -71,7 +71,7 @@ static Obj HdlrFunc2 (
}
}

/* Assert( ... ); */
/* Assert( 0, true, "fail-B" ); */
if ( STATE(CurrentAssertionLevel) >= 0 ) {
t_2 = True;
t_1 = (Obj)(UInt)(t_2 != False);
Expand All @@ -86,7 +86,7 @@ static Obj HdlrFunc2 (
}
}

/* Assert( ... ); */
/* Assert( 0, true ); */
if ( STATE(CurrentAssertionLevel) >= 0 ) {
t_2 = True;
t_1 = (Obj)(UInt)(t_2 != False);
Expand Down Expand Up @@ -122,7 +122,7 @@ static Obj HdlrFunc2 (
DoOperation2Args( CallFuncListOper, t_1, NewPlistFromArgs( t_2, t_3 ) );
}

/* Assert( ... ); */
/* Assert( 3, false, "fail-C" ); */
if ( STATE(CurrentAssertionLevel) >= 3 ) {
t_2 = False;
t_1 = (Obj)(UInt)(t_2 != False);
Expand All @@ -137,7 +137,7 @@ static Obj HdlrFunc2 (
}
}

/* Assert( ... ); */
/* Assert( 3, false ); */
if ( STATE(CurrentAssertionLevel) >= 3 ) {
t_2 = False;
t_1 = (Obj)(UInt)(t_2 != False);
Expand All @@ -146,7 +146,7 @@ static Obj HdlrFunc2 (
}
}

/* Assert( ... ); */
/* Assert( 2, true, "fail-D" ); */
if ( STATE(CurrentAssertionLevel) >= 2 ) {
t_2 = True;
t_1 = (Obj)(UInt)(t_2 != False);
Expand All @@ -161,7 +161,7 @@ static Obj HdlrFunc2 (
}
}

/* Assert( ... ); */
/* Assert( 2, true ); */
if ( STATE(CurrentAssertionLevel) >= 2 ) {
t_2 = True;
t_1 = (Obj)(UInt)(t_2 != False);
Expand All @@ -170,7 +170,7 @@ static Obj HdlrFunc2 (
}
}

/* Assert( ... ); */
/* Assert( 2, false, "pass!\n" ); */
if ( STATE(CurrentAssertionLevel) >= 2 ) {
t_2 = False;
t_1 = (Obj)(UInt)(t_2 != False);
Expand Down
10 changes: 5 additions & 5 deletions tst/test-compile/info.g.dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static Obj HdlrFunc2 (
DoOperation2Args( CallFuncListOper, t_1, NewPlistFromArgs( t_2, t_3 ) );
}

/* Info( ... ); */
/* Info( InfoDebug, 2, "Do not print" ); */
t_1 = GC_InfoDebug;
CHECK_BOUND( t_1, "InfoDebug" );
t_3 = InfoCheckLevel( t_1, INTOBJ_INT(2) );
Expand All @@ -65,7 +65,7 @@ static Obj HdlrFunc2 (
InfoDoPrint( t_1, INTOBJ_INT(2), t_2 );
}

/* Info( ... ); */
/* Info( InfoDebug, 1, "print this A" ); */
t_1 = GC_InfoDebug;
CHECK_BOUND( t_1, "InfoDebug" );
t_3 = InfoCheckLevel( t_1, INTOBJ_INT(1) );
Expand Down Expand Up @@ -109,7 +109,7 @@ static Obj HdlrFunc2 (
DoOperation2Args( CallFuncListOper, t_1, NewPlistFromArgs( t_2, t_3 ) );
}

/* Info( ... ); */
/* Info( InfoDebug, 3, "Do not print" ); */
t_1 = GC_InfoDebug;
CHECK_BOUND( t_1, "InfoDebug" );
t_3 = InfoCheckLevel( t_1, INTOBJ_INT(3) );
Expand All @@ -122,7 +122,7 @@ static Obj HdlrFunc2 (
InfoDoPrint( t_1, INTOBJ_INT(3), t_2 );
}

/* Info( ... ); */
/* Info( InfoDebug, 2, "print this B" ); */
t_1 = GC_InfoDebug;
CHECK_BOUND( t_1, "InfoDebug" );
t_3 = InfoCheckLevel( t_1, INTOBJ_INT(2) );
Expand All @@ -135,7 +135,7 @@ static Obj HdlrFunc2 (
InfoDoPrint( t_1, INTOBJ_INT(2), t_2 );
}

/* Info( ... ); */
/* Info( InfoDebug, 1, "print ", "this ", "C" ); */
t_1 = GC_InfoDebug;
CHECK_BOUND( t_1, "InfoDebug" );
t_3 = InfoCheckLevel( t_1, INTOBJ_INT(1) );
Expand Down

0 comments on commit 36347c0

Please sign in to comment.