KrkClosure Struct Reference

Function object. More...

#include <object.h>

Inheritance diagram for KrkClosure:

Public Member Functions

KrkInstancekrk_buildGenerator (KrkClosure *function, KrkValue *arguments, size_t argCount)
 Convert a function into a generator with the given arguments. More...
 
KrkClosurekrk_newClosure (KrkCodeObject *function, KrkValue globals)
 Create a new function object. More...
 

Data Fields

KrkCodeObjectfunction
 The codeobject containing the bytecode run when this function is called.
 
KrkUpvalue ** upvalues
 Array of upvalues collected from the surrounding context when the closure was created.
 
size_t upvalueCount
 Number of entries in upvalues.
 
KrkValue annotations
 Dictionary of type hints.
 
KrkTable fields
 Object attributes table.
 
KrkValue globalsOwner
 Owner of the globals table for this function.
 
KrkTableglobalsTable
 Pointer to globals table with owner object.
 
- Data Fields inherited from KrkObj
uint16_t type
 Tag indicating core type.
 
uint16_t flags
 General object flags, mostly related to garbage collection.
 
uint32_t hash
 Cached hash value for table keys.
 
struct KrkObjnext
 Invasive linked list of all objects in the VM.
 

Protected Attributes

KrkObj obj
 Base.
 

Detailed Description

Function object.

Not to be confused with code objects, a closure is a single instance of a function.

Definition at line 195 of file object.h.

Member Function Documentation

◆ krk_buildGenerator()

KrkInstance * krk_buildGenerator ( KrkClosure function,
KrkValue arguments,
size_t  argCount 
)

Convert a function into a generator with the given arguments.

Converts the function function to a generator object and provides it arguments (of length argCount) as its initial arguments. The generator object is returned.

Parameters
functionFunction to convert.
argumentsArguments to pass to the generator.
argCountNumber of arguments in arguments
Returns
A new generator object.

Definition at line 82 of file obj_gen.c.

◆ krk_newClosure()

KrkClosure * krk_newClosure ( KrkCodeObject function,
KrkValue  globals 
)

Create a new function object.

Function objects are the callable first-class objects representing functions in managed code. Each function object has an associated code object, which may be sured with other function objects, such as when a function is used to create a closure.

Parameters
functionCode object to assign to the new function object.

Definition at line 290 of file object.c.


The documentation for this struct was generated from the following file: