-
Notifications
You must be signed in to change notification settings - Fork 0
Preprocessor
Trin Wasinger edited this page Apr 6, 2024
·
9 revisions
MTSC includes a heavily modified C/C++ preprocessor based on Boost Wave. For compatibility, it is gated behind the -p/--preprocessor
CLI flag. Since #abc
is already valid JavaScript for ES6 private class fields, MTSC instead looks for preprocessor directives within single-line triple-slash comments (e.g. ///#define ...
).
Unless otherwise stated, the following directives behave like their C/C++ counterparts. Unknown directives raise a warning.
-
///#define
- Variadics and placemarkers are supported
///#undef
-
///#if
- Supports
defined()
and__has_include()
- Supports
///#ifdef
///#ifndef
///#else
///#elif
///#endif
///#include
///#include_next
///#error
///#warning
///#line
///#pragma
-
///#embed
- Only supports the
///#embed "path/to/file..."
form - The byte contents of the relative file are inserted as comma separated hex literals
- Only supports the
The forms ///#pragma arg
, _Pragma(arg)
, and __pragma(arg)
all work as normal. Unless otherwise stated, the following pragma options behave like their C/C++ counterparts. Unknown pragma options raise a warning.
///#pragma once
-
///#pragma region
- Accepted, but does nothing
-
///#pragma endregion
- Accepted, but does nothing
-
///#pragma mtsc line(arg)
- Acts as an extended form of
///#line
- If
arg
starts with a+
or-
, the current line number is shifted down or up respectively by the number of lines following the sign - If
arg
has no sign, this sets the current line number to the value ofarg
- Because of this,
line(123)
,line(+123)
, andline(-123)
all act different
- Acts as an extended form of
-
///#pragma mtsc eval(arg)
- Experimental and not yet documented
Unless otherwise stated, the following macros behave like their C/C++ counterparts.
__LINE__
__FILE__
__BASE_FILE__
__DATE__
__TIME__
__INCLUDE_LEVEL__
-
__MTSC_VERSION__
- A string constant with the current version number (e.g.,
"5.4.2"
)
- A string constant with the current version number (e.g.,
-
__NEWLINE__
- Holds a newline token to allow embedding newlines in macro values
-
__MAIN__
-
1
if in__BASE_FILE__
and0
otherwise - Can be used with
///#if
to make a script executable or act as a library depending on compilation
-