Mon 16 Mar 11:09:06 CET 2026

This commit is contained in:
sbosse 2026-03-16 11:10:01 +01:00
parent e48c212e0d
commit 9fec172b3a

55
src/mem.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef _MEM_H
#define _MEM_H
/*
Code segment occupied by a task, required for cleanup on task end and code memory partitioning.
Forked tasks inherit segment from parent task.
A task can use more than one segment, e.g., there is only one context (task)
which handles the main programm and single line statements modifying the state of the task (and heap).
*/
typedef struct {
int8_t used;
address_t bottom; // start
address_t top; // end
index_t refcount; // contains function and procedures referenced by heap;
// no disposal of segment allowed if > 0
#if PROFILE>0
index_t ntoken;
unsigned long micros;
#endif
} segment_t;
/*
Shared data and code memory
-------
heap |
v
^
code |
-----.
*/
typedef struct {
unsigned char *data; // entire heap
int size;
int top; // top of heap, growing down
int bottom; // top of code, growing up
segment_t segments[MAXTASKS]; // parts of the heap
segment_t *segment; // current segment (used by code compiler)
} mem_t;
#define ADDRESS(M,addr) *(address_t*)(&M->data[addr])
#define CHAR(M,addr) M->data[addr]
#define INDEX(M,addr) *(index_t*)(&M->data[addr])
#define NUMBER(M,addr) *(number_t*)(&M->data[addr])
#define CHECKHEAP(M,addr) (addr>M->top && addr<M->size)
void MemInit(mem_t *M,int size,unsigned char *data);
void MemReset(mem_t *M);
segment_t *AllocSegment(mem_t *M);
int ReleaseSegment(mem_t *M, segment_t *S);
#endif