mirror of
https://github.com/janet-lang/janet
synced 2024-11-29 11:29:54 +00:00
Make env optional for compile.
This commit is contained in:
parent
0378ba78cc
commit
411fc77ecf
@ -26,6 +26,7 @@
|
|||||||
#include "emit.h"
|
#include "emit.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "state.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
JanetFopts janetc_fopts_default(JanetCompiler *c) {
|
JanetFopts janetc_fopts_default(JanetCompiler *c) {
|
||||||
@ -716,8 +717,12 @@ JanetCompileResult janet_compile(Janet source, JanetTable *env, const uint8_t *w
|
|||||||
|
|
||||||
/* C Function for compiling */
|
/* C Function for compiling */
|
||||||
static Janet cfun(int32_t argc, Janet *argv) {
|
static Janet cfun(int32_t argc, Janet *argv) {
|
||||||
janet_arity(argc, 2, 3);
|
janet_arity(argc, 1, 3);
|
||||||
JanetTable *env = janet_gettable(argv, 1);
|
JanetTable *env = argc > 1 ? janet_gettable(argv, 1) : janet_vm_fiber->env;
|
||||||
|
if (NULL == env) {
|
||||||
|
env = janet_table(0);
|
||||||
|
janet_vm_fiber->env = env;
|
||||||
|
}
|
||||||
const uint8_t *source = NULL;
|
const uint8_t *source = NULL;
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
source = janet_getstring(argv, 2);
|
source = janet_getstring(argv, 2);
|
||||||
@ -740,7 +745,7 @@ static Janet cfun(int32_t argc, Janet *argv) {
|
|||||||
static const JanetReg compile_cfuns[] = {
|
static const JanetReg compile_cfuns[] = {
|
||||||
{
|
{
|
||||||
"compile", cfun,
|
"compile", cfun,
|
||||||
JDOC("(compile ast env [, source])\n\n"
|
JDOC("(compile ast &opt env source)\n\n"
|
||||||
"Compiles an Abstract Syntax Tree (ast) into a janet function. "
|
"Compiles an Abstract Syntax Tree (ast) into a janet function. "
|
||||||
"Pair the compile function with parsing functionality to implement "
|
"Pair the compile function with parsing functionality to implement "
|
||||||
"eval. Returns a janet function and does not modify ast. Throws an "
|
"eval. Returns a janet function and does not modify ast. Throws an "
|
||||||
|
Loading…
Reference in New Issue
Block a user