The Croc Programming Language
Compilation

Macros

#define croc_ex_loadString(t, code, name)   (croc_pushString((t), (code)), croc_pushCurEnvironment(t), croc_ex_loadStringWithEnvStk((t), (name)))
 
#define croc_ex_loadStringStk(t, name)   (croc_pushCurEnvironment(t), croc_ex_loadStringWithEnvStk((t), (name)))
 
#define croc_ex_loadStringWithEnv(t, code, name)   (croc_pushString((t), (code)), croc_swapTop(t), croc_ex_loadStringWithEnvStk((t), (name)))
 
#define croc_ex_runString(t, code, name)   (croc_pushString((t), (code)), croc_pushCurEnvironment(t), croc_ex_runStringWithEnvStk((t), (name)))
 
#define croc_ex_runStringStk(t, name)   (croc_pushCurEnvironment(t), croc_ex_runStringWithEnvStk((t), (name)))
 
#define croc_ex_runStringWithEnv(t, code, name)   (croc_pushString((t), (code)), croc_swapTop(t), croc_ex_runStringWithEnvStk((t), (name)))
 
#define croc_ex_eval(t, code, numReturns)   (croc_pushString((t), (code)), croc_pushCurEnvironment(t), croc_ex_evalWithEnvStk((t), (numReturns)))
 
#define croc_ex_evalStk(t, numReturns)   (croc_pushCurEnvironment(t), croc_ex_evalWithEnvStk((t), (numReturns)))
 
#define croc_ex_evalWithEnv(t, code, numReturns)   (croc_pushString((t), (code)), croc_swapTop(t), croc_ex_evalWithEnvStk((t), (numReturns)))
 

Functions

word_t croc_ex_loadStringWithEnvStk (CrocThread *t, const char *name)
 
void croc_ex_runStringWithEnvStk (CrocThread *t, const char *name)
 
uword_t croc_ex_evalWithEnvStk (CrocThread *t, word_t numReturns)
 
void croc_ex_runModule (CrocThread *t, const char *moduleName, uword_t numParams)
 

Detailed Description

Simpler functions for compiling Croc code.

There are a bunch of variants of some of these functions, and the variants all work the same way. If they have withEnv in their name, the environment to evaluate the code in should be on top of the stack; otherwise it will use the currently executing function's environment (or the global namespace if there is none). If they have Stk in their name, the source code should be a string on top of the stack (or under the environment in the withEnv versions); otherwise, they take the source as a parameter.

Macro Definition Documentation

#define croc_ex_loadString (   t,
  code,
  name 
)    (croc_pushString((t), (code)), croc_pushCurEnvironment(t), croc_ex_loadStringWithEnvStk((t), (name)))

Like croc_ex_loadStringWithEnvStk but uses the current environment and takes the source as the parameter code.

#define croc_ex_loadStringStk (   t,
  name 
)    (croc_pushCurEnvironment(t), croc_ex_loadStringWithEnvStk((t), (name)))

Like croc_ex_loadString but expects the code on top of the stack.

#define croc_ex_loadStringWithEnv (   t,
  code,
  name 
)    (croc_pushString((t), (code)), croc_swapTop(t), croc_ex_loadStringWithEnvStk((t), (name)))

Like croc_ex_loadString but expects the environment on top of the stack.

#define croc_ex_runString (   t,
  code,
  name 
)    (croc_pushString((t), (code)), croc_pushCurEnvironment(t), croc_ex_runStringWithEnvStk((t), (name)))

Like croc_ex_runStringWithEnvStk but uses the current environment and takes the source as the parameter code.

#define croc_ex_runStringStk (   t,
  name 
)    (croc_pushCurEnvironment(t), croc_ex_runStringWithEnvStk((t), (name)))

Like croc_ex_runString but expects the code on top of the stack.

#define croc_ex_runStringWithEnv (   t,
  code,
  name 
)    (croc_pushString((t), (code)), croc_swapTop(t), croc_ex_runStringWithEnvStk((t), (name)))

Like croc_ex_runString but expects the environment on top of the stack.

#define croc_ex_eval (   t,
  code,
  numReturns 
)    (croc_pushString((t), (code)), croc_pushCurEnvironment(t), croc_ex_evalWithEnvStk((t), (numReturns)))

Like croc_ex_evalWithEnvStk but uses the current environment and takes the expression as the parameter code.

#define croc_ex_evalStk (   t,
  numReturns 
)    (croc_pushCurEnvironment(t), croc_ex_evalWithEnvStk((t), (numReturns)))

Like croc_ex_eval but expects the code on top fo the stack.

#define croc_ex_evalWithEnv (   t,
  code,
  numReturns 
)    (croc_pushString((t), (code)), croc_swapTop(t), croc_ex_evalWithEnvStk((t), (numReturns)))

Like croc_ex_eval but expects the environment on top of the stack.

Function Documentation

word_t croc_ex_loadStringWithEnvStk ( CrocThread t,
const char *  name 
)

Expects an environment namespace on top of the stack and a string of code containing zero or more statements under it.

Compiles the code and instantiates the funcdef. Pops the environment and source, and replaces them with the resulting function closure.

Returns
the stack index of the resulting closure.
void croc_ex_runStringWithEnvStk ( CrocThread t,
const char *  name 
)

Like croc_ex_loadStringWithEnvStk but also calls the resulting function, leaving nothing on the stack.

uword_t croc_ex_evalWithEnvStk ( CrocThread t,
word_t  numReturns 
)

Expects an environment namespace on top of the stack and a string of code containing an expression under it.

Compiles and runs the expression, returning numReturns values which replace the code and environment.

Returns
the number of values that were returned from the expression.
void croc_ex_runModule ( CrocThread t,
const char *  moduleName,
uword_t  numParams 
)

Imports the module moduleName, and then calls the Croc modules.runMain function on the resulting module.

Parameters
numParamsis how many parameters you want to pass to the module's main function. There should be this many values on the stack, and they will be popped.