1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00
janet/thread.h
2017-03-14 15:55:50 -04:00

48 lines
1.8 KiB
C

#ifndef thread_h_INCLUDED
#define thread_h_INCLUDED
#include "datatypes.h"
/* Get the current stack frame */
#define gst_thread_stack(t) ((t)->data + (t)->count)
/* Create a new thread */
GstThread *gst_thread(Gst *vm, GstValue callee, uint32_t capacity);
/* Ensure that the thread has enough EXTRA capacity */
void gst_thread_ensure_extra(Gst *vm, GstThread *thread, uint32_t extra);
/* Push a value on the current stack frame*/
void gst_thread_push(Gst *vm, GstThread *thread, GstValue x);
/* Push n nils onto the stack */
void gst_thread_pushnil(Gst *vm, GstThread *thread, uint32_t n);
/* Package up extra args after and including n into tuple at n*/
void gst_thread_tuplepack(Gst *vm, GstThread *thread, uint32_t n);
/* Expand a callee on the stack frame to its delegate function. This means that
* objects and userdata that have a "call" attribut in their class will be
* replaced with their delegate function. Call this before pushing any
* arguments to the stack. Returns the new stack. */
GstValue *gst_thread_expand_callable(Gst *vm, GstThread *thread, GstValue callee);
/* Push a stack frame to a thread, with space for arity arguments. Returns the new
* stack. */
GstValue *gst_thread_beginframe(Gst *vm, GstThread *thread, GstValue callee, uint32_t arity);
/* After pushing arguments to a stack frame created with gst_thread_beginframe, call this
* to finalize the frame before starting a function call. */
void gst_thread_endframe(Gst *vm, GstThread *thread);
/* Pop a stack frame from the thread. Returns the new stack frame, or
* NULL if there are no more frames */
GstValue *gst_thread_popframe(Gst *vm, GstThread *thread);
/* Move the current stack frame over its parent stack frame, allowing
* for primitive tail calls. Return new stack. */
GstValue *gst_thread_tail(Gst *vm, GstThread *thread);
#endif // thread_h_INCLUDED