Mac - A macro processing language
Mac is the general purpose macro processing language for OfflineOS. It is primarily designed to help integrate X64asm, OTIL, MIA and Build but also for general meta-programming.
Concepts
Text-orientation and meta-programming
Mac is entirely dedicated to processing text with a focus on generating/modifying source code before compilation.
Inter-process communication
Variables and Macros can be passed via command line arguments.
Datatypes
- String
- Regular Expression
- Macro
- Hash / List (numeric indices are syntactic sugar)
Syntax
Due to implementation limits of the current Bootstrap version
Embedded contexts
%{ directions }%
Directions is read as instructions to the macro processor rather than outputted.
Requiring files
%{include " path-to-file "}%
Copies the content of another file into the current file.
WARNING: Using this directive to copy in source code rather than macro directives is possible but highly discouraged as it violates the languages' module system.
Simple macros
A simple substitution without arguments
%{def M " String "}%
Standard macros
%{def M ( Arg1 , Arg2 )}%
Code
%{end}%
Sets up a Macro that uses Arg1 and Arg2. Remember that the actual text of Arg1 and Arg2 are passed not their values.
Advanced macros
It is possible to specify macros for more languages with more exotic syntaxes by replacing the macro's name with a format string that includes the arguments names.
E.g.
%{def "Arg1 + Arg2" (Arg1, Arg2)}%
add(Arg1, Arg2)
%{end}%
Nested macros
The quote keyword is used for embedding further directives into a macro. This way you can write macros that generate more macros.
%{quote}%
directives
%{end}%
Variables
%{set( name " textual value ")}%
Sets a text value that can be used in a macro.
Arrays
Conditionals
if
%{if condition }%
code
%{end}%
if / else
%{if condition }%
code
%{else}%
code
%{end}%
equal
Test if two strings are equal in a conditional.
equal( string1 , string2 )
match
Test if a string fits a regular expression in a conditional.
match( string , regex )
Loops
for
Applies a template to each member of a loop
%{for iterator in list }%
Code
%{end}%
Error
Emits an error message and terminates with a given status number
%{error status " error string " }%
Regular Expressions
PCRE2. Do not put in quotes, just slashes.
Macros for specific languages
X64asm Macros
- FuncDef( name , return-type , arguments ) - Used to prepare a name used with the Func macro. Note that name can be in module . function format.
- Func( name ) - Outputs a function name that is compatible with OTIL.