mirror of
https://github.com/janet-lang/janet
synced 2025-01-15 18:05:41 +00:00
Move declarations around.
This commit is contained in:
parent
f264cb0b18
commit
37a430c97c
@ -37,6 +37,7 @@ static void fiber_reset(JanetFiber *fiber) {
|
|||||||
fiber->child = NULL;
|
fiber->child = NULL;
|
||||||
fiber->flags = JANET_FIBER_MASK_YIELD | JANET_FIBER_RESUME_NO_USEVAL | JANET_FIBER_RESUME_NO_SKIP;
|
fiber->flags = JANET_FIBER_MASK_YIELD | JANET_FIBER_RESUME_NO_USEVAL | JANET_FIBER_RESUME_NO_SKIP;
|
||||||
fiber->env = NULL;
|
fiber->env = NULL;
|
||||||
|
fiber->waiting = NULL;
|
||||||
janet_fiber_set_status(fiber, JANET_STATUS_NEW);
|
janet_fiber_set_status(fiber, JANET_STATUS_NEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,6 +285,9 @@ static void janet_deinit_block(JanetGCObject *mem) {
|
|||||||
break;
|
break;
|
||||||
case JANET_MEMORY_FIBER:
|
case JANET_MEMORY_FIBER:
|
||||||
free(((JanetFiber *)mem)->data);
|
free(((JanetFiber *)mem)->data);
|
||||||
|
#ifdef JANET_EV
|
||||||
|
free(((JanetFiber *)mem)->waiting);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case JANET_MEMORY_BUFFER:
|
case JANET_MEMORY_BUFFER:
|
||||||
janet_buffer_deinit((JanetBuffer *) mem);
|
janet_buffer_deinit((JanetBuffer *) mem);
|
||||||
|
@ -472,6 +472,59 @@ typedef void *JanetAbstract;
|
|||||||
#define JANET_TFLAG_CALLABLE (JANET_TFLAG_FUNCTION | JANET_TFLAG_CFUNCTION | \
|
#define JANET_TFLAG_CALLABLE (JANET_TFLAG_FUNCTION | JANET_TFLAG_CFUNCTION | \
|
||||||
JANET_TFLAG_LENGTHABLE | JANET_TFLAG_ABSTRACT)
|
JANET_TFLAG_LENGTHABLE | JANET_TFLAG_ABSTRACT)
|
||||||
|
|
||||||
|
/* Event Loop Types */
|
||||||
|
#ifdef JANET_EV
|
||||||
|
#define JANET_POLL_FLAG_CLOSED 0x1
|
||||||
|
#define JANET_POLL_FLAG_SOCKET 0x2
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
JANET_ASYNC_EVENT_INIT,
|
||||||
|
JANET_ASYNC_EVENT_MARK,
|
||||||
|
JANET_ASYNC_EVENT_DEINIT,
|
||||||
|
JANET_ASYNC_EVENT_CLOSE,
|
||||||
|
JANET_ASYNC_EVENT_READ,
|
||||||
|
JANET_ASYNC_EVENT_WRITE,
|
||||||
|
JANET_ASYNC_EVENT_TIMEOUT
|
||||||
|
} JanetAsyncEvent;
|
||||||
|
|
||||||
|
#define JANET_ASYNC_LISTEN_READ (1 << JANET_ASYNC_EVENT_READ)
|
||||||
|
#define JANET_ASYNC_LISTEN_WRITE (1 << JANET_ASYNC_EVENT_WRITE)
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
JANET_ASYNC_STATUS_NOT_DONE,
|
||||||
|
JANET_ASYNC_STATUS_DONE
|
||||||
|
} JanetAsyncStatus;
|
||||||
|
|
||||||
|
/* Typedefs */
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
typedef HANDLE JanetPollType;
|
||||||
|
#else
|
||||||
|
typedef int JanetPollType;
|
||||||
|
#endif
|
||||||
|
typedef struct JanetListenerState JanetListenerState;
|
||||||
|
typedef struct JanetPollable JanetPollable;
|
||||||
|
typedef JanetAsyncStatus(*JanetListener)(JanetListenerState *state, JanetAsyncEvent event);
|
||||||
|
|
||||||
|
/* Wrapper around file descriptors and HANDLEs that can be polled. */
|
||||||
|
struct JanetPollable {
|
||||||
|
JanetPollType handle;
|
||||||
|
uint32_t flags;
|
||||||
|
JanetListenerState *state;
|
||||||
|
/* internal */
|
||||||
|
int _mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Interface for state machine based event loop */
|
||||||
|
struct JanetListenerState {
|
||||||
|
JanetListener machine;
|
||||||
|
JanetFiber *fiber;
|
||||||
|
JanetPollable *pollable;
|
||||||
|
/* internal */
|
||||||
|
int _mask;
|
||||||
|
JanetListenerState *_next;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/* We provide three possible implementations of Janets. The preferred
|
/* We provide three possible implementations of Janets. The preferred
|
||||||
* nanboxing approach, for 32 or 64 bits, and the standard C version. Code in the rest of the
|
* nanboxing approach, for 32 or 64 bits, and the standard C version. Code in the rest of the
|
||||||
* application must interact through exposed interface. */
|
* application must interact through exposed interface. */
|
||||||
@ -739,11 +792,16 @@ struct JanetFiber {
|
|||||||
int32_t frame; /* Index of the stack frame */
|
int32_t frame; /* Index of the stack frame */
|
||||||
int32_t stackstart; /* Beginning of next args */
|
int32_t stackstart; /* Beginning of next args */
|
||||||
int32_t stacktop; /* Top of stack. Where values are pushed and popped from. */
|
int32_t stacktop; /* Top of stack. Where values are pushed and popped from. */
|
||||||
int32_t capacity;
|
int32_t capacity; /* How big is the stack memory */
|
||||||
int32_t maxstack; /* Arbitrary defined limit for stack overflow */
|
int32_t maxstack; /* Arbitrary defined limit for stack overflow */
|
||||||
JanetTable *env; /* Dynamic bindings table (usually current environment). */
|
JanetTable *env; /* Dynamic bindings table (usually current environment). */
|
||||||
Janet *data;
|
Janet *data; /* Dynamically resized stack memory */
|
||||||
JanetFiber *child; /* Keep linked list of fibers for restarting pending fibers */
|
JanetFiber *child; /* Keep linked list of fibers for restarting pending fibers */
|
||||||
|
#ifdef JANET_EV
|
||||||
|
JanetListenerState **waiting;
|
||||||
|
#else
|
||||||
|
void *waiting;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Mark if a stack frame is a tail call for debugging */
|
/* Mark if a stack frame is a tail call for debugging */
|
||||||
@ -1141,57 +1199,7 @@ extern enum JanetInstructionType janet_instructions[JOP_INSTRUCTION_COUNT];
|
|||||||
|
|
||||||
/***** START SECTION MAIN *****/
|
/***** START SECTION MAIN *****/
|
||||||
|
|
||||||
/* Event Loop */
|
|
||||||
#ifdef JANET_EV
|
#ifdef JANET_EV
|
||||||
#define JANET_POLL_FLAG_CLOSED 0x1
|
|
||||||
#define JANET_POLL_FLAG_SOCKET 0x2
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
JANET_ASYNC_EVENT_INIT,
|
|
||||||
JANET_ASYNC_EVENT_MARK,
|
|
||||||
JANET_ASYNC_EVENT_DEINIT,
|
|
||||||
JANET_ASYNC_EVENT_CLOSE,
|
|
||||||
JANET_ASYNC_EVENT_READ,
|
|
||||||
JANET_ASYNC_EVENT_WRITE,
|
|
||||||
JANET_ASYNC_EVENT_TIMEOUT
|
|
||||||
} JanetAsyncEvent;
|
|
||||||
|
|
||||||
#define JANET_ASYNC_LISTEN_READ (1 << JANET_ASYNC_EVENT_READ)
|
|
||||||
#define JANET_ASYNC_LISTEN_WRITE (1 << JANET_ASYNC_EVENT_WRITE)
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
JANET_ASYNC_STATUS_NOT_DONE,
|
|
||||||
JANET_ASYNC_STATUS_DONE
|
|
||||||
} JanetAsyncStatus;
|
|
||||||
|
|
||||||
/* Typedefs */
|
|
||||||
#ifdef JANET_WINDOWS
|
|
||||||
typedef HANDLE JanetPollType;
|
|
||||||
#else
|
|
||||||
typedef int JanetPollType;
|
|
||||||
#endif
|
|
||||||
typedef struct JanetListenerState JanetListenerState;
|
|
||||||
typedef struct JanetPollable JanetPollable;
|
|
||||||
typedef JanetAsyncStatus(*JanetListener)(JanetListenerState *state, JanetAsyncEvent event);
|
|
||||||
|
|
||||||
/* Wrapper around file descriptors and HANDLEs that can be polled. */
|
|
||||||
struct JanetPollable {
|
|
||||||
JanetPollType handle;
|
|
||||||
uint32_t flags;
|
|
||||||
JanetListenerState *state;
|
|
||||||
/* internal */
|
|
||||||
int _mask;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Interface for state machine based event loop */
|
|
||||||
struct JanetListenerState {
|
|
||||||
JanetListener machine;
|
|
||||||
JanetFiber *fiber;
|
|
||||||
JanetPollable *pollable;
|
|
||||||
/* internal */
|
|
||||||
int _mask;
|
|
||||||
JanetListenerState *_next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Run the event loop */
|
/* Run the event loop */
|
||||||
JANET_API void janet_loop(void);
|
JANET_API void janet_loop(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user