Minimeg - Spicery/Nutmeg GitHub Wiki

Minimeg is a small subset of Nutmeg that is suitable for writing configuration files.

Nutmeg regards configuration files as nothing more than source-code that are loaded at start-up time. But simply loading arbitrary source code into a compiled program would be very unsafe as it could add arbitrary behaviour. So configuration files are limited to the Minimeg subset, which is safe to load.

To use a configuration file, the Nutmeg compiler must be given a configuration file template that defines the variables that the configuration file will supply at run-time. A template is simply an ordinary configuration file with example values. These should have the file extension '.minimeg', which the compiler recognises specially. For example if we have a configuration file that declares a couple of connection-strings it might look like this:

### Contents of myconfig.minimeg
mainConnectionString := "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"
altConnectionString := "Server=myAltServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;"

You would then add that file to your program using the nutmegc command e.g.

% nutmegc --bundle=myprogram.bundle myconfig.minimeg

At run-time, Nutmeg will look for matching configuration files in the same folder as the compiled bundle. It will then load those files up, ensuring that they only declare the variables that were declared in the template file and they have matching types, although additional private variables are allowed. If the loaded code depends on any compiled functions, those functions will be checked that they are declared as @mini i.e. that they are written in the Minimeg subset.

It is important to note that Minimeg can define functions, which is is very useful but raises the possibility of non-terminating or expensive computation. The Minimeg subset does not protect against this directly. Instead the compiler will arrange that the functions are executed in a special mode that has a limited budget. This budget is only renewed when the call-stack contains no instances of a configuration function. By default the budget is automatically estimated by the compiler when running unit tests, which have an unlimited budget. The estimation process is based on the number of backward jumps and procedure calls.

% nutmeg unittest mytest.bundle --update-budget

You can override the budget with the --set-budget option.

% nutmegc --bundle=myprogram.bundle --set-budget=1000000