Options - Manhunter07/MFL GitHub Wiki

Options define the compiler's behaviour in certain ways. They can be defined at runtime using the special opt command. Each option has an initial value and can be changed to a individual set of alternative values. Option names are no evaluable identifiers to be used in standard code and can therefore not be accessed from outside opt commands.

The generic syntax for these statements goes as follows:

opt OptionName = Value

The option name must be one of these pre-defined compiler option names:

  • Warnings: Defines whether warnings are to be shown. If set to False, warnings will be ignored.
  • Optimization: Defines whether the compiler should try to optimize the code at some places without changing its behaviour.
  • Allowed: Defines which kinds of expressions are permitted after this command. Note that disallowing option commands here, changes to this will not be possible anymore. Use with caution therefore!
  • InitialType: Defines which data type will be assigned to implicitely-initialized variables. The compiler will assign any variables you declare with the empty-value of that data type (ie. 0 for numbers).
  • PackagePaths: Defines where the compiler should look for packages to link with the script. If empty, it is only possible to link standard packages or packages in the same directory using link.
  • PackageFileExt: Defines the implicit file extension for package script files when loaded.
  • ImplicitStdPackages: Defines whether standard packages should be linked implicitely or not when manually linked using the link command. The system package is not affected by this because it cannot be linked manually.
  • ExceptionManager: Defines an object (variable, function or type with constructor) that handles any exceptions the compiler or the program may throw. If it refers to a variable, the exception message will be written into it as a string. If it refers to a function, it will be called. If it refers to a type it will be instantiated, using its constructor (if declared, otherwise an exception is thrown). If the function or type's constructor accepts one or more arguments, the compiler initiates this call with the exception message as a string argument. Otherwise, the call is done without arguments. If the function or constructor demands more than one argument at least, an exception is thrown.

Custom option names are not supported and any other names will cause an exception. Each option supports a strictly-defined set of values or value types it can have. Unsupported values can cause exceptions.

Name Type Supported values Default
Warnings Boolean True or False True
Optimization Boolean True or False True
Allowed integer array Array with integers from 0 to 15 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
InitialType integer NullType, ReferenceType, BooleanType, NumberType, StringType, ArrayType or RecordType NumberType
PackagePaths string array Array with strings of any length []
PackageFileExt string String of any length, should start with a dot (".") ".mfl"
ImplicitStdPackages Boolean True or False False
ExceptionManager References Type with constructor or function, with zero or one argument, or variable Nil

Remember to only override these options when really needed. It is often enough to simply alter a function or existing code. Use opt statements with caution!

Retrieving values of options at runtime

The built-in function Option returns the value of any option at runtime. The option's name must be passed as argument and the function will return the value of that option as specified above.