Serene Runtime 1.0.0
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 35 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 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}