Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
context.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for context.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  srn_context_t
 

Macros

#define SRN_HASH_TYPE   uint32_t
 
#define SRN_SEED_TYPE   uint32_t
 
#define ALLOC(ctx, T)
 
#define ALLOCN(ctx, T, N)
 

Typedefs

typedef size_t srn_block_id_t
 The block id is effectively just an index in the blocks array in srn_mm_t.
 
typedef uintptr_t object_id_t
 
typedef SRN_HASH_TYPE srn_hash_t
 
typedef SRN_SEED_TYPE srn_seed_t
 
typedef struct srn_context_t srn_context_t
 

Functions

srn_context_tsrn_context_make (srn_engine_t *engine)
 Make an empty context, by allocating a new memory block.
 
int srn_context_release (srn_context_t *ctx)
 
void * srn_allocate (const srn_context_t *ctx, size_t size, size_t alignment)
 
void srn_release (const srn_context_t *ctx, void *ptr)
 

Macro Definition Documentation

◆ ALLOC

#define ALLOC ( ctx,
T )
Value:
(T *)srn_allocate(ctx, sizeof(T), alignof(T))
void * srn_allocate(const srn_context_t *ctx, size_t size, size_t alignment)
Definition context.c:72

Definition at line 82 of file context.h.

◆ ALLOCN

#define ALLOCN ( ctx,
T,
N )
Value:
(T *)srn_allocate(ctx, sizeof(T) * (N), alignof(T))

Definition at line 83 of file context.h.

◆ SRN_HASH_TYPE

#define SRN_HASH_TYPE   uint32_t

Definition at line 41 of file context.h.

◆ SRN_SEED_TYPE

#define SRN_SEED_TYPE   uint32_t

Definition at line 42 of file context.h.

Typedef Documentation

◆ object_id_t

typedef uintptr_t object_id_t

Definition at line 39 of file context.h.

◆ srn_block_id_t

typedef size_t srn_block_id_t

The block id is effectively just an index in the blocks array in srn_mm_t.

NOTE: We use the value SIZE_MAX to indicate NO BLOCK ID. For example, when embedding a srn_block_id_t field in a data structure. If the value of the field is SIZE_MAX ((size_t) -1), it indicates that no block id is present.

Definition at line 38 of file context.h.

◆ srn_context_t

typedef struct srn_context_t srn_context_t

◆ srn_hash_t

Definition at line 44 of file context.h.

◆ srn_seed_t

Definition at line 45 of file context.h.

Function Documentation

◆ srn_allocate()

void * srn_allocate ( const srn_context_t * ctx,
size_t size,
size_t alignment )

Definition at line 72 of file context.c.

72 {
73 PANIC_IF_NULL(ctx);
74 return srn_mm_allocate_in_block_aligned(ctx->engine->mm, ctx->block_id, size, alignment);
75}
void * srn_mm_allocate_in_block_aligned(srn_mm_t *mm, srn_block_id_t block_id, size_t size, size_t alignment)
Allocate memory on a block with the given block_id.
Definition default.c:347
srn_engine_t * engine
Long term state of the compiler.
Definition context.h:49
srn_block_id_t block_id
Where to allocate memory from.
Definition context.h:53
srn_mm_t * mm
Memory manager.
Definition engine.h:58
#define PANIC_IF_NULL(ptr)
Definition utils.h:64
Here is the call graph for this function:
Here is the caller graph for this function:

◆ srn_context_make()

srn_context_t * srn_context_make ( srn_engine_t * engine)

Make an empty context, by allocating a new memory block.

The returning context is a root context (no parent).

Definition at line 38 of file context.c.

38 {
39 PANIC_IF_NULL(engine);
40 srn_block_id_t block_id = srn_mm_allocate_block(engine->mm);
41 srn_context_t *ctx = srn_mm_allocate_in_block(engine->mm, block_id, srn_context_t);
42 PANIC_IF_NULL(ctx);
43 ctx->parent = nullptr;
44 ctx->engine = engine;
45 ctx->block_id = block_id;
46 return ctx;
47}
size_t srn_block_id_t
The block id is effectively just an index in the blocks array in srn_mm_t.
Definition context.h:38
srn_block_id_t srn_mm_allocate_block(srn_mm_t *mm)
Allocate a new block in the memory manager and return its ID.
Definition default.c:364
#define srn_mm_allocate_in_block(mm, id, T)
Definition interface.h:166
struct srn_context_t * parent
Definition context.h:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ srn_context_release()

int srn_context_release ( srn_context_t * ctx)

Definition at line 63 of file context.c.

63 {
64 PANIC_IF_NULL(ctx);
65 if (ctx->block_id != SRN_BLOCK_NO_ID) {
66 CTX_LOG("Releasing block: %lu", ctx->block_id)
67 srn_mm_release_block(ctx->engine->mm, ctx->block_id);
68 }
69 return 0;
70}
#define CTX_LOG(FMT,...)
Definition context.c:35
void srn_mm_release_block(srn_mm_t *mm, srn_block_id_t id)
Release the given block id and free the memory for later allocations.
Definition default.c:388
#define SRN_BLOCK_NO_ID
Definition interface.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ srn_release()

void srn_release ( const srn_context_t * ctx,
void * ptr )

Definition at line 77 of file context.c.

77 {
78 // No Op.
79 // This is just for future proofing
80}