Changeset 88bc876 for tests/ctrl-flow


Ignore:
Timestamp:
Jul 16, 2024, 5:28:10 PM (5 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
97f9619
Parents:
2363147
Message:

Breaks (and some other control flow) in a loop else clause now work. I also implemented else clauses in printing and code generation.

Location:
tests/ctrl-flow
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/ctrl-flow/.expect/loop_else.txt

    r2363147 r88bc876  
    6363(10 10)(9 9)(8 8)(7 7)(6 6)(5 5)(4 4)(3 3)(2 2)(1 1)(0 0)else
    6464
     65before begin else after
  • tests/ctrl-flow/loop_else.cfa

    r2363147 r88bc876  
    7474                i -= 1.7;
    7575        } else { sout | "else"; }                                                                                                               sout | nl | nl;
    76        
     76
    7777        enum { N = 10 };
    7878        for ( N ) { sout | "N"; } else { sout | "else"; }                                                       sout | nl;
     
    109109        for ( s; (S){0} -~  (S){10,10} ~ (S){1} ) { sout | s; } else { sout | "else"; } sout | nl;
    110110        for ( s; (S){0} -~= (S){10,10} ) { sout | s; } else { sout | "else"; }           sout | nl;
    111         for ( s; (S){0} -~= (S){10,10} ~ (S){1} ) { sout | s; } else { sout | "else"; } sout | nl | nl;
     111        for ( s; (S){0} -~= (S){10,10} ~ (S){1} ) { sout | s; } else { sout | "else"; } sout | nl;
     112        sout | nl;
     113
     114        // A break (or a continue) in an else clause should target an outer loop.
     115        sout | "before";
     116        while ( true ) {
     117                sout | " begin";
     118                while ( false ) {
     119                        sout | "never";
     120                } else {
     121                        sout | " else";
     122                        break;
     123                }
     124                sout | " end";
     125        }
     126        sout | " after" | nl;
    112127}
Note: See TracChangeset for help on using the changeset viewer.