Macros | |
#define | croc_compiler_compileModuleEx(t, name, modName) |
#define | croc_compiler_compileStmtsEx(t, name) |
#define | croc_compiler_compileExprEx(t, name) |
#define | croc_compiler_compileModuleDTEx(t, name, modName) |
#define | croc_compiler_compileStmtsDTEx(t, name) |
Functions | |
uword_t | croc_compiler_setFlags (CrocThread *t, uword_t flags) |
uword_t | croc_compiler_getFlags (CrocThread *t) |
int | croc_compiler_compileModule (CrocThread *t, const char *name, const char **modName) |
int | croc_compiler_compileStmts (CrocThread *t, const char *name) |
int | croc_compiler_compileExpr (CrocThread *t, const char *name) |
int | croc_compiler_compileModuleDT (CrocThread *t, const char *name, const char **modName) |
int | croc_compiler_compileStmtsDT (CrocThread *t, const char *name) |
word_t | croc_compiler_processDocComment (CrocThread *t) |
word_t | croc_compiler_parseDocCommentText (CrocThread *t) |
The interface to the Croc compiler.
#define croc_compiler_compileModuleEx | ( | t, | |
name, | |||
modName | |||
) |
Like croc_compiler_compileModule, but if compilation failed, rethrows the exception.
Also returns nothing.
#define croc_compiler_compileStmtsEx | ( | t, | |
name | |||
) |
Like croc_compiler_compileStmts, but if compilation failed, rethrows the exception.
Also returns nothing.
#define croc_compiler_compileExprEx | ( | t, | |
name | |||
) |
Like croc_compiler_compileExpr, but if compilation failed, rethrows the exception.
Also returns nothing.
#define croc_compiler_compileModuleDTEx | ( | t, | |
name, | |||
modName | |||
) |
Like croc_compiler_compileModuleDT, but if compilation failed, rethrows the exception.
Also returns nothing.
#define croc_compiler_compileStmtsDTEx | ( | t, | |
name | |||
) |
Like croc_compiler_compileStmtsDT, but if compilation failed, rethrows the exception.
Also returns nothing.
uword_t croc_compiler_setFlags | ( | CrocThread * | t, |
uword_t | flags | ||
) |
Enable and disable VM-wide compiler flags.
These control whether or not code is generated for various optional language features.
flags | must be an or-ing together of the members of the CrocCompilerFlags enum. The flags are as follows:
|
the previous value of the compiler flags. This is so you can set the flags, compile something, then put the flags back the way they were, like so:
uword_t croc_compiler_getFlags | ( | CrocThread * | t | ) |
int croc_compiler_compileModule | ( | CrocThread * | t, |
const char * | name, | ||
const char ** | modName | ||
) |
Compiles the module whose source is a string on top of the stack.
The top slot will be replaced with the result of compilation.
name | is the filename that will be used in locations such as compilation errors and debug info. | |
[out] | modName | is required, and will be assigned a string which is the name of the module as given in the module's 'module' statement. You can use this to see if the module name matches the name it was imported as. |
different things depending on whether compilation was successful or not.
If it was successful, returns a positive stack slot of the resulting function definition, which will have replaced the source code on top of the stack.
If it failed, returns one of the CrocCompilerReturn values explaining why compilation failed. In this case, the source on top of the stack will be replaced with an exception object which you can then rethrow if you want to.
If you don't care about handling compilation failure, use croc_compiler_compileModuleEx instead.
int croc_compiler_compileStmts | ( | CrocThread * | t, |
const char * | name | ||
) |
Very similar to croc_compiler_compileModule, but the source will be parsed as a list of statements without a 'module'
statement at the beginning.
There is no modName
parameter as a result.
If you don't care about handling compilation failure, use croc_compiler_compileStmtsEx instead.
int croc_compiler_compileExpr | ( | CrocThread * | t, |
const char * | name | ||
) |
Compiles a single Croc expression as a string on top of the stack into a funcdef which takes variadic arguments and returns the result of evaluating that expression.
Just like with the other compilation functions, the source stack slot is replaced by either the funcdef on success or the exception object on failure.
If you don't care about handling compilation failure, use croc_compiler_compileExprEx instead.
int croc_compiler_compileModuleDT | ( | CrocThread * | t, |
const char * | name, | ||
const char ** | modName | ||
) |
Similar to croc_compiler_compileModule, but additionally extracts the module's top-level documentation table as described in the spec.
When you use this function, doc comments are parsed and turned into doctables, regardless of whether the compiler's CrocCompilerFlags_Docs flag is enabled. The CrocCompilerFlags_Docs compiler flag only controls whether or not runtime doc decorators are attached to program items.
If you don't care about handling compilation failure, use croc_compiler_compileModuleDTEx instead.
int croc_compiler_compileStmtsDT | ( | CrocThread * | t, |
const char * | name | ||
) |
Just like croc_compiler_compileStmts, but extracts the top-level documentation table like croc_compiler_compileModuleDT, leaving it on the stack under the funcdef the same way.
If you don't care about handling compilation failure, use croc_compiler_compileStmtsDTEx instead.
word_t croc_compiler_processDocComment | ( | CrocThread * | t | ) |
This is a low-level interface to the documentation comment parser.
It expects two values on top of the stack: the doc comment text as a string on top, and a doctable below it which only has the members "file"
, "line"
, "kind"
, and "name"
filled in. It will parse the doc comment, filling in the other fields of the doctable. The comment source will then be popped, leaving just the doctable on top of the stack.
word_t croc_compiler_parseDocCommentText | ( | CrocThread * | t | ) |
Expects a string on top of the stack which will be parsed into a doc comment paragraph list.
This doesn't actually parse a whole doc comment like croc_compiler_processDocComment does, so section commands are not allowed, but span and structure commands are.
The source slot will be replaced by the resulting paragraph list (an array as described in the doc comment spec).