Serene Runtime 1.0.0-dev
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:73

Definition at line 84 of file context.h.

◆ ALLOCN

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

Definition at line 85 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 73 of file context.c.

73 {
74 PANIC_IF_NULL(ctx);
75 return srn_mm_allocate_in_block_aligned(ctx->engine->mm, ctx->block_id, size, alignment);
76}
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:396
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:65
#define PANIC_IF_NULL(ptr)
Definition utils.h:66
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 39 of file context.c.

39 {
40 PANIC_IF_NULL(engine);
41 srn_block_id_t block_id = srn_mm_allocate_block(engine->mm);
42 srn_context_t *ctx = srn_mm_allocate_in_block(engine->mm, block_id, srn_context_t);
43 PANIC_IF_NULL(ctx);
44 ctx->parent = nullptr;
45 ctx->engine = engine;
46 ctx->block_id = block_id;
47 return ctx;
48}
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:426
#define srn_mm_allocate_in_block(mm, id, T)
Definition interface.h:180
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 64 of file context.c.

64 {
65 PANIC_IF_NULL(ctx);
66 if (ctx->block_id != SRN_BLOCK_NO_ID) {
67 CTX_LOG("Releasing block: %zu", ctx->block_id);
69 }
70 return 0;
71}
#define CTX_LOG(FMT,...)
Definition context.c:36
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:451
#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 78 of file context.c.

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