obj_gen.c File Reference

Generator objects. More...

#include <string.h>
#include <kuroko/vm.h>
#include <kuroko/value.h>
#include <kuroko/memory.h>
#include <kuroko/util.h>
#include <kuroko/debug.h>
Include dependency graph for obj_gen.c:

Go to the source code of this file.

Data Structures

struct  generator
 Generator object implementation. More...
 

Macros

#define AS_generator(o)   ((struct generator *)AS_OBJECT(o))
 
#define IS_generator(o)   (krk_isInstanceOf(o, KRK_BASE_CLASS(generator)))
 
#define CURRENT_CTYPE   struct generator *
 
#define CURRENT_NAME   self
 

Functions

KrkInstancekrk_buildGenerator (KrkClosure *closure, KrkValue *argsIn, size_t argCount)
 Create a generator object from a closure and set of arguments. More...
 
 FUNC_SIG (generator, __init__)
 
KrkValue _generator___repr__ (int, KrkValue *, int)
 
KrkValue _generator___iter__ (int, KrkValue *, int)
 
KrkValue _generator___call__ (int, KrkValue *, int)
 
KrkValue _generator_send (int, KrkValue *, int)
 
KrkValue _generator___finish__ (int, KrkValue *, int)
 
KrkValue _generator_gi_running (int, KrkValue *, int)
 
int krk_getAwaitable (void)
 Calls await
 
_noexport void _createAndBind_generatorClass (void)
 

Detailed Description

Generator objects.

Generator objects track runtime state so they can be resumed and yielded from. Any function with a yield statement in its body is implicitly transformed into a generator object when called.

Definition in file obj_gen.c.

Function Documentation

◆ krk_buildGenerator()

KrkInstance* krk_buildGenerator ( KrkClosure closure,
KrkValue argsIn,
size_t  argCount 
)

Create a generator object from a closure and set of arguments.

Initializes the generator object, attaches the argument list, and sets up the execution state to point to the start of the function's code object.

Parameters
closureFunction object to transform.
argsInArray of arguments passed to the call.
argCountNumber of arguments in argsIn
Returns
A generator object.

Definition at line 82 of file obj_gen.c.