Skip to content

Move preamble out of compiler #85

@ssoelvsten

Description

@ssoelvsten

Currently, in AddAmbientMethods, we add quality-of-life functions that depend on authority. In a teaching context, this allows students to get started using Troupe without getting confused by too many new concepts at once (think static void main in a class in Java).

We would like to make this preamble (1) easier to maintain, (2) easier to swap out, and (3) possible to omit such that only the core language is available ( see also #64 ). To this end, we would like to have the following io.preamble.trp file:

let fun printString x = fwrite (stdout authority) x; fwrite (stdout authority) "\n"
    fun print    x = printString (toString x)
    fun printL   x = printString (toStringL x)

    fun inputLine () = freadln (stdin authority)
in ()
end

Similar to AddAmbientMethods we would, after parsing (and other validation?), replace the in () end with in <program> end.

The compiler would be provided a new flag --include-preamble/--prefix (short -ip/-p?) which takes the given file(s), parses them, and prepends them on the given program.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ code qualityUncle Bob would be proud✨ enhancementNew feature or request📁 ./compilerChanges, errors, and additions for the compiler

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions