2018-01-20 16:04:30 +00:00
|
|
|
/*
|
2020-01-12 16:50:37 +00:00
|
|
|
* Copyright (c) 2020 Calvin Rose
|
2018-01-20 16:04:30 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
#ifndef JANET_STATE_H_defined
|
|
|
|
#define JANET_STATE_H_defined
|
2018-01-20 16:04:30 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
/* The VM state. Rather than a struct that is passed
|
2018-05-20 01:16:00 +00:00
|
|
|
* around, the vm state is global for simplicity. If
|
2019-01-06 08:23:03 +00:00
|
|
|
* at some point a global state object, or context,
|
|
|
|
* is required to be passed around, this is what would
|
|
|
|
* be in it. However, thread local global variables for interpreter
|
|
|
|
* state should allow easy multi-threading. */
|
2018-01-20 16:04:30 +00:00
|
|
|
|
2020-01-29 05:38:52 +00:00
|
|
|
typedef struct JanetScratch JanetScratch;
|
|
|
|
|
2019-12-02 10:15:22 +00:00
|
|
|
/* Cache the core environment */
|
|
|
|
extern JANET_THREAD_LOCAL JanetTable *janet_vm_core_env;
|
2019-12-02 02:28:12 +00:00
|
|
|
|
2018-03-04 23:56:13 +00:00
|
|
|
/* How many VM stacks have been entered */
|
2018-09-06 02:18:42 +00:00
|
|
|
extern JANET_THREAD_LOCAL int janet_vm_stackn;
|
2018-03-04 23:56:13 +00:00
|
|
|
|
2018-05-14 13:55:34 +00:00
|
|
|
/* The current running fiber on the current thread.
|
2018-09-06 02:18:42 +00:00
|
|
|
* Set and unset by janet_run. */
|
|
|
|
extern JANET_THREAD_LOCAL JanetFiber *janet_vm_fiber;
|
2020-02-10 01:04:34 +00:00
|
|
|
extern JANET_THREAD_LOCAL JanetFiber *janet_vm_root_fiber;
|
2018-05-14 13:55:34 +00:00
|
|
|
|
2019-02-01 16:56:25 +00:00
|
|
|
/* The current pointer to the inner most jmp_buf. The current
|
|
|
|
* return point for panics. */
|
|
|
|
extern JANET_THREAD_LOCAL jmp_buf *janet_vm_jmp_buf;
|
|
|
|
extern JANET_THREAD_LOCAL Janet *janet_vm_return_reg;
|
|
|
|
|
2019-01-06 08:23:03 +00:00
|
|
|
/* The global registry for c functions. Used to store meta-data
|
2018-06-12 18:24:45 +00:00
|
|
|
* along with otherwise bare c function pointers. */
|
2018-09-06 02:18:42 +00:00
|
|
|
extern JANET_THREAD_LOCAL JanetTable *janet_vm_registry;
|
2020-03-14 15:25:39 +00:00
|
|
|
|
|
|
|
/* Registry for abstract abstract types that can be marshalled.
|
|
|
|
* We need this to look up the constructors when unmarshalling. */
|
|
|
|
extern JANET_THREAD_LOCAL JanetTable *janet_vm_abstract_registry;
|
2018-06-12 18:24:45 +00:00
|
|
|
|
2018-01-20 16:04:30 +00:00
|
|
|
/* Immutable value cache */
|
2018-09-06 02:18:42 +00:00
|
|
|
extern JANET_THREAD_LOCAL const uint8_t **janet_vm_cache;
|
|
|
|
extern JANET_THREAD_LOCAL uint32_t janet_vm_cache_capacity;
|
|
|
|
extern JANET_THREAD_LOCAL uint32_t janet_vm_cache_count;
|
|
|
|
extern JANET_THREAD_LOCAL uint32_t janet_vm_cache_deleted;
|
2018-01-20 16:04:30 +00:00
|
|
|
|
2018-03-31 20:40:36 +00:00
|
|
|
/* Garbage collection */
|
2018-09-06 02:18:42 +00:00
|
|
|
extern JANET_THREAD_LOCAL void *janet_vm_blocks;
|
2020-01-03 04:02:57 +00:00
|
|
|
extern JANET_THREAD_LOCAL size_t janet_vm_gc_interval;
|
|
|
|
extern JANET_THREAD_LOCAL size_t janet_vm_next_collection;
|
2018-09-06 02:18:42 +00:00
|
|
|
extern JANET_THREAD_LOCAL int janet_vm_gc_suspend;
|
2018-03-31 20:40:36 +00:00
|
|
|
|
2018-09-23 21:53:55 +00:00
|
|
|
/* GC roots */
|
|
|
|
extern JANET_THREAD_LOCAL Janet *janet_vm_roots;
|
2020-01-03 04:02:57 +00:00
|
|
|
extern JANET_THREAD_LOCAL size_t janet_vm_root_count;
|
|
|
|
extern JANET_THREAD_LOCAL size_t janet_vm_root_capacity;
|
2018-01-20 16:04:30 +00:00
|
|
|
|
2019-06-02 03:31:39 +00:00
|
|
|
/* Scratch memory */
|
2020-01-29 05:38:52 +00:00
|
|
|
extern JANET_THREAD_LOCAL JanetScratch **janet_scratch_mem;
|
2019-06-02 03:31:39 +00:00
|
|
|
extern JANET_THREAD_LOCAL size_t janet_scratch_cap;
|
|
|
|
extern JANET_THREAD_LOCAL size_t janet_scratch_len;
|
|
|
|
|
2020-04-24 21:18:31 +00:00
|
|
|
/* Recursionless traversal of data structures */
|
|
|
|
typedef struct {
|
|
|
|
JanetGCObject *self;
|
|
|
|
JanetGCObject *other;
|
|
|
|
int32_t index;
|
|
|
|
int32_t index2;
|
|
|
|
} JanetTraversalNode;
|
|
|
|
extern JANET_THREAD_LOCAL JanetTraversalNode *janet_vm_traversal;
|
|
|
|
extern JANET_THREAD_LOCAL JanetTraversalNode *janet_vm_traversal_top;
|
|
|
|
extern JANET_THREAD_LOCAL JanetTraversalNode *janet_vm_traversal_base;
|
|
|
|
|
2019-12-05 03:44:53 +00:00
|
|
|
/* Setup / teardown */
|
|
|
|
#ifdef JANET_THREADS
|
|
|
|
void janet_threads_init(void);
|
|
|
|
void janet_threads_deinit(void);
|
|
|
|
#endif
|
|
|
|
|
2018-09-06 02:18:42 +00:00
|
|
|
#endif /* JANET_STATE_H_defined */
|