Add licence
[ilari-esolangs.git] / context.h
blob3bd3235d3f43819f0ad3b4dc1ee39ff9c8fce7d1
1 #ifndef _context__h__included__
2 #define _context__h__included__
4 struct vat;
5 struct message;
6 struct object;
7 struct stack;
8 #include <stdlib.h>
9 #include "lock.h"
11 /* Context. */
12 struct context;
14 /******************************************************************************
16 * DESCRIPTION:
17 * Pop object from stack. Popping empty stack gives NULL.
19 * PARAMETERS:
20 * ctx The context.
22 * RETURN VALUE:
23 * The object popped.
25 *****************************************************************************/
26 struct object* context_pop(struct context* ctx);
28 /******************************************************************************
30 * DESCRIPTION:
31 * Push object to stack.
33 * PARAMETERS:
34 * ctx The context.
35 * obj The object to push.
37 *****************************************************************************/
38 void context_push(struct context* ctx, struct object* obj);
40 /******************************************************************************
42 * DESCRIPTION:
43 * Notify context that execution is starting.
45 * PARAMETERS:
46 * ctx The context.
48 * RETURN VALUE:
49 * 1 if suitable message was found, 0 if there is no suitable message.
51 *****************************************************************************/
52 unsigned context_prepare(struct context* ctx);
54 /******************************************************************************
56 * DESCRIPTION:
57 * Notify context that execution is finished.
59 * PARAMETERS:
60 * ctx The context.
62 *****************************************************************************/
63 void context_unprepare(struct context* ctx);
65 /******************************************************************************
67 * DESCRIPTION:
68 * Calculate number of stack slots.
70 * PARAMETERS:
71 * ctx The context.
73 *****************************************************************************/
74 size_t context_stacksize(struct context* ctx);
76 /******************************************************************************
78 * DESCRIPTION:
79 * Single-step context.
81 * PARAMETERS:
82 * ctx The context.
84 *****************************************************************************/
85 void context_singlestep(struct context* ctx);
87 /******************************************************************************
89 * DESCRIPTION:
90 * Create context.
92 * PARAMETERS:
93 * vat The vat to use.
95 * RETURN VALUE:
96 * The context. Pass to free when done.
98 *****************************************************************************/
99 struct context* context_create(struct vat* vat);
101 /******************************************************************************
103 * DESCRIPTION:
104 * Grab context lock.
106 * PARAMETERS:
107 * ctx Context to lock.
109 *****************************************************************************/
110 void context_lock(struct context* ctx);
112 /******************************************************************************
114 * DESCRIPTION:
115 * Ungrab context lock.
117 * PARAMETERS:
118 * ctx Context to unlock.
120 *****************************************************************************/
121 void context_unlock(struct context* ctx);
123 /******************************************************************************
125 * DESCRIPTION:
126 * Queue message into message queue.
128 * PARAMETERS:
129 * context The context to use.
130 * message The message to queue.
132 *****************************************************************************/
133 void context_queue_message(struct context* context, struct message* message);
135 /******************************************************************************
137 * DESCRIPTION:
138 * Execute message handler.
140 * PARAMETERS:
141 * context The context to use.
143 * RETURN VALUE:
144 * 1 if message got handled, 0 if not.
146 *****************************************************************************/
147 unsigned context_execute_msghandler(struct context* ctx);
150 #endif