minid.compiler
The MiniD
compiler
. This is, unsurprisingly, the largest part of the implementation,
although it has a very small public interface.
License:
Copyright (c) 2007 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.
- MDModuleDef
compileModule
(char[] filename);
- Compile a source code file into a binary module. Takes the path to the source file and returns
the compiled module, which can be loaded into a context.
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 in MDContext.
- MDModuleDef
compileModule
(dchar[] source, char[] name);
- Compile a module from a string containing the source code.
Params:
dchar[] 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 compiled module.
- MDFuncDef
compileStatements
(dchar[] source, char[] name);
- Compile a list of statements into a function body which takes a variadic number of arguments. Kind
of like a module without the module statement.
Params:
dchar[] source |
The source code as a string. |
char[] name |
The name to use as the source name for compilation errors. |
atEOF |
(Optional) This parameter is useful for writing interactive interpreters. Try to call
this function with this parameter set to an output, and if you catch any compilation exceptions,
you can check this output to see if typing more could result in the code compiling correctly.
That is, you can collect input from the user one line at a time, compiling each time they hit
enter, and if the atEOF output is true, keep letting them input code and recompiling until
it works. You can see the source of mdcl for an example of using this. |
Returns:
The compiled function.
- MDFuncDef
compileExpression
(dchar[] source, char[] name);
- Compile a single expression into a function which returns the value of that expression when called.
Params:
dchar[] source |
The source code as a strng. |
char[] name |
The name to use as the source name for compilation errors. |
Returns:
The compiled function.
- MDValue
loadJSON
(dchar[] source);
- Parses a JSON string into a MiniD value and returns that value. Just like the MiniD baselib
function.
|