minid.compiler
This module contains the public interface to the MiniD
compiler
.
License:
Copyright (c) 2008 Jarrett Billingsley
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the
use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software in a
product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
- class
Compiler
: minid.compilertypes.ICompiler;
- This class encapsulates all the functionality needed for compiling MiniD code.
-
None
- Do not generate code for any optional features.
-
TypeConstraints
- Generate code to check parameter type constraints.
-
Asserts
- Generate code for assert statements.
-
Debug
- Generate debug info. Currently always on.
-
All
- Generate code for all optional features.
- this(MDThread* t, uint flags = All);
- Constructs a compiler. The given thread will be used to hold temporary data structures,
to throw exceptions, and to return the functions that result from compilation.
Params:
MDThread* t |
The thread with which this compiler will be associated. |
uint flags |
A bitwise or of any code-generation flags you want to use for this compiler.
Defaults to All. |
- void
setFlags
(uint flags);
- Set the compiler's code-generation flags.
- bool
asserts
();
- Returns whether or not code for
asserts
should be generated.
- bool
typeConstraints
();
- Returns whether or not code for parameter type constraint checking should be generated.
- bool
isEof
();
- Returns whether or not the most recently-thrown exception was thrown due to an unexpected end-of-file.
As an example, this is used by MDCL (that is, minid.commandline) to detect when more code must be entered
to complete a code segment. A simple example of use:
scope c = new Compiler(t);
try
c.compileExpression(someCode, "test" );
catch (MDException e)
{
auto ex = catchException(t);
if (c.isEof ())
{
}
}
- bool
isLoneStmt
();
- Returns whether or not the most recently-thrown exception was thrown due to a no-effect expression being used
as a statement (yes, this method has a horrible name). Its use is identical to isEof().
- int
compileModule
(char[] filename);
- Compile a source code file into a function closure. Takes the path to the source file, compiles
that file, and pushes the top-level closure onto the stack. The environment of the closure is
just set to the global namespace of the compiler's thread; you must create and set a namespace
for the module function before calling it.
You shouldn't have to deal with this function that much. Most of the time the compilation of
modules should be handled for you by the import system.
Params:
char[] filename |
The filename of the source file to compile. |
Returns:
The stack index of the newly-pushed function closure that represents the top-level function
of the module.
- int
compileModule
(char[] source, char[] name);
- Same as above, but compiles from a string holding the source rather than from a file.
Params:
char[] source |
The source code as a string. |
char[] name |
The name which should be used as the source name in compiler error message. Takes the
place of the filename when compiling from a source file. |
Returns:
The stack index of the newly-pushed function closure that represents the top-level function
of the module.
- int
compileStatements
(char[] source, char[] name);
- Compile a list of statements into a function which takes a variadic number of arguments. The environment
of the compiled function closure is set to the globals of the compiler's thread.
Params:
char[] source |
The source code as a string. |
char[] name |
The name to use as the source name for compilation errors. |
Returns:
The stack index of the newly-pushed function closure.
- int
compileExpression
(char[] source, char[] name);
- Compile a single expression into a function which returns the value of that expression when called.
Params:
char[] source |
The source code as a string. |
char[] name |
The name to use as the source name for compilation errors. |
Returns:
The stack index of the newly-pushed function closure.
|