masak / alma

ALgoloid with MAcros -- a language with Algol-family syntax where macros take center stage
Artistic License 2.0
139 stars 15 forks source link

Termination requirement #537

Open masak opened 5 years ago

masak commented 5 years ago

We don't have too many things on our wishlist describing changes to the compilation process itself, so here's one: importing a module to forbid potentially infinite loops and recursion:

import semantics.termination;

{
    import syntax.stmt.loop;

    loop { # COMPILE ERROR
    }
}

func foo() {
    foo();    # COMPILE ERROR
}

In other words, if a loop or a recursive call is obviously non-terminating (as the two above), it produces a compile-time error.

Of course, this runs headlong into the Halting Problem (and things become a lot less obvious)... so the module flags up all potentially infinite loops and recursions as compile-time errors.

I think this should be tempered with two mechanisms for making the program compile again.