Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
engine.h File Reference
#include <stddef.h>
#include <stdint.h>
#include "serene/rt/impl/hashmap.h"
#include "serene/utils.h"
Include dependency graph for engine.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  srn_engine_t
 Engine is a structure to own the long living and main pieces of the compiler. More...
 

Macros

#define SRN_HASH_TYPE   uint32_t
 
#define SRN_SEED_TYPE   uint32_t
 
#define ENGINE_FIRST_OBJECT_ID   100
 Start allocating IDs from 100, earlier IDs are reserved.
 

Typedefs

typedef struct hmap_t hmap_t
 
typedef struct srn_scheduler_t srn_scheduler_t
 
typedef uint64_t srn_object_id_t
 
typedef struct srn_engine_t srn_engine_t
 Engine is a structure to own the long living and main pieces of the compiler.
 

Functions

srn_engine_tsrn_engine_make (srn_mm_t *mm)
 
void srn_engine_shutdown (srn_engine_t *engine)
 
srn_object_id_t srn_allocate_object_id (srn_engine_t *engine)
 
srn_hash_t srn_hash (const srn_engine_t *engine, const void *data, size_t len)
 

Macro Definition Documentation

◆ ENGINE_FIRST_OBJECT_ID

#define ENGINE_FIRST_OBJECT_ID   100

Start allocating IDs from 100, earlier IDs are reserved.

Definition at line 42 of file engine.h.

◆ SRN_HASH_TYPE

#define SRN_HASH_TYPE   uint32_t

Definition at line 27 of file engine.h.

◆ SRN_SEED_TYPE

#define SRN_SEED_TYPE   uint32_t

Definition at line 28 of file engine.h.

Typedef Documentation

◆ hmap_t

typedef struct hmap_t hmap_t

Definition at line 32 of file engine.h.

◆ srn_engine_t

typedef struct srn_engine_t srn_engine_t

Engine is a structure to own the long living and main pieces of the compiler.

There will be only oe instance of the engine at anytime.

◆ srn_object_id_t

typedef uint64_t srn_object_id_t

Definition at line 40 of file engine.h.

◆ srn_scheduler_t

typedef struct srn_scheduler_t srn_scheduler_t

Definition at line 38 of file engine.h.

Function Documentation

◆ srn_allocate_object_id()

srn_object_id_t srn_allocate_object_id ( srn_engine_t * engine)

Definition at line 137 of file engine.c.

137 {
138 PANIC_IF_NULL(engine);
139 return atomic_fetch_add_explicit(&engine->object_id_counter, 1, memory_order_relaxed);
140}
_Atomic srn_object_id_t object_id_counter
An unsigned counter to allocate object ids atomically.
Definition engine.h:55
#define PANIC_IF_NULL(ptr)
Definition utils.h:64
Here is the caller graph for this function:

◆ srn_engine_make()

srn_engine_t * srn_engine_make ( srn_mm_t * mm)

Definition at line 92 of file engine.c.

92 {
93 PANIC_IF_NULL(mm);
95
96 if (engine == nullptr) {
97 return nullptr;
98 }
99
100 engine->seed = srn_generate_seed();
101 // Just reserving 0..100 for any unpredicted needs
102 engine->mm = mm;
103
104#ifdef SRN_WITH_SERENE
105 engine->jit = srn_jit_make(mm);
106#endif
107 engine->scheduler = srn_sched_init(engine);
108
109#ifdef SRN_WITH_SERENE
110 // Both registries start empty. An empty hmap_t is just {.len = 0,
111 // .root = nullptr} and matches what hmap_empty would return, so we can
112 // initialize them inline without needing a context here.
113 engine->namespaces = (hmap_t){.len = 0, .root = nullptr};
114 srn_spinlock_init(&engine->ns_lock);
115 engine->keywords = (hmap_t){.len = 0, .root = nullptr};
116 srn_spinlock_init(&engine->keywords_lock);
117#endif
118 atomic_init(&engine->object_id_counter, ENGINE_FIRST_OBJECT_ID);
119
120 return engine;
121}
static srn_seed_t srn_generate_seed()
Definition engine.c:63
#define ENGINE_FIRST_OBJECT_ID
Start allocating IDs from 100, earlier IDs are reserved.
Definition engine.h:42
#define srn_mm_immortal_allocate(mm, T)
Definition interface.h:169
srn_jit_t * srn_jit_make(srn_mm_t *mm)
Definition jit.c:44
srn_scheduler_t * srn_sched_init(srn_engine_t *engine)
Definition scheduler.c:246
Engine is a structure to own the long living and main pieces of the compiler.
Definition engine.h:49
srn_scheduler_t * scheduler
The fiber scheduler, set by srn_sched_init.
Definition engine.h:67
srn_seed_t seed
We use the seed for hashing and the value will be generated at random for each new context.
Definition engine.h:75
srn_mm_t * mm
Memory manager.
Definition engine.h:58
static void srn_spinlock_init(srn_spinlock_t *lock)
Definition utils.h:281
Here is the call graph for this function:
Here is the caller graph for this function:

◆ srn_engine_shutdown()

void srn_engine_shutdown ( srn_engine_t * engine)

Definition at line 123 of file engine.c.

123 {
124 PANIC_IF_NULL(engine);
126#ifdef SRN_WITH_SERENE
127 srn_jit_shutdown(engine->jit);
128#endif
129}
int srn_jit_shutdown(srn_jit_t *jit)
Definition jit.c:75
void srn_sched_shutdown(srn_scheduler_t *sched)
The one stop tear down of the fiber subsystem, should be called once srn_sched_run has returned.
Definition scheduler.c:314
Here is the call graph for this function:
Here is the caller graph for this function:

◆ srn_hash()

srn_hash_t srn_hash ( const srn_engine_t * engine,
const void * data,
size_t len )

Definition at line 131 of file engine.c.

131 {
132 // NULL pointers are only valid if the length is zero
133 size_t length = (data == nullptr) ? 0 : len;
134 return XXH32(data, length, engine->seed);
135}
Here is the caller graph for this function: