Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
context.c File Reference
Include dependency graph for context.c:

Go to the source code of this file.

Macros

#define CTX_LOG(FMT, ...)

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

◆ CTX_LOG

#define CTX_LOG ( FMT,
... )

Definition at line 36 of file context.c.

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}