The Croc Programming Language
Variables

Macros

#define croc_pushCurEnvironment(t)   (croc_pushEnvironment((t), 0))
 

Functions

word_t croc_pushEnvironment (CrocThread *t, uword_t depth)
 
void croc_setUpval (CrocThread *t, uword_t idx)
 
word_t croc_pushUpval (CrocThread *t, uword_t idx)
 
void croc_newGlobal (CrocThread *t, const char *name)
 
void croc_newGlobalStk (CrocThread *t)
 
word_t croc_pushGlobal (CrocThread *t, const char *name)
 
word_t croc_pushGlobalStk (CrocThread *t)
 
void croc_setGlobal (CrocThread *t, const char *name)
 
void croc_setGlobalStk (CrocThread *t)
 

Detailed Description

Globals, upvalues, and environments.

Macro Definition Documentation

#define croc_pushCurEnvironment (   t)    (croc_pushEnvironment((t), 0))

Pushes the environment namespace of the currently-executing function.

Function Documentation

word_t croc_pushEnvironment ( CrocThread t,
uword_t  depth 
)

Pushes the environment namespace of the function at the given call stack depth.

A depth of 0 means the currently-executing function; 1 means the function which called this one; and so on. If you pass a depth greater than the call stack depth, pushes the global namespace instead.

It is an error to get the environment of a call stack index which was overwritten by a tailcall.

Returns
the stack slot of the pushed value.
void croc_setUpval ( CrocThread t,
uword_t  idx 
)

Inside a native function which had upvalues associated with it at creation, you can use this to set the upvalue with the given index.

This expects one value on top of the stack. That value is set as the new value of upvalue idx, and then the value is popped.

word_t croc_pushUpval ( CrocThread t,
uword_t  idx 
)

Inside a native function which had upvalues associated with it at creation, pushes the upvalue with the given index.

Returns
the stack slot of the pushed value.
void croc_newGlobal ( CrocThread t,
const char *  name 
)

Expects a value on top of the stack.

Pops the value and creates a new global named name in the current function's environment, just like declaring a global in Croc.

void croc_newGlobalStk ( CrocThread t)

Expects two values on top of the stack: the value on top, and the name of the global to create below that.

Creates the global and pops both values.

word_t croc_pushGlobal ( CrocThread t,
const char *  name 
)

Pushes the value of the global variable named name, just like accessing a global in Croc.

Returns
the stack slot of the pushed value.
word_t croc_pushGlobalStk ( CrocThread t)

Expects a string on top of the stack as the name of the global to get.

Replaces the top of the stack with the value of the global.

Returns
the stack slot of the pushed value.
void croc_setGlobal ( CrocThread t,
const char *  name 
)

Expects a value on top of the stack.

Pops the value and assigns it into the global named name in the current function's environment, just like setting a global in Croc.

void croc_setGlobalStk ( CrocThread t)

Expects two values on top of the stack: the value on top, and the name of the global to set below that.

Sets the global and pops both values.