naegling/src/memory.h
Simon Brooke 7e9dc12766 Initial commit.
This first sketch of the memory layout isn't working because I'm
not succeeding in packing the bitfields, so I intend to rip it up
and start again.
2026-04-05 12:22:48 +01:00

94 lines
2.2 KiB
C

/**
* memory.h
*
* Grendel: a compiling Beowulf reimplementation.
*
* The memory management subsystem.
*
* (c) 2026 Simon Brooke <simon@journeyman.cc>
* Licensed under GPL version 2.0, or, at your option, any later version.
*/
#ifndef __grendel_memory_h
#define __grendel_memory_h
#include <stdint.h>
/* Tags for 32 bit objects, with 3 bits of tag an one mark bit */
/**
* This pointer object is an actual pointer -- an offset into consspace.
*/
#define OFFSETTV 0
/**
* This pointer object is actually a 28 bit integer value.
*/
#define INTEGERTV 1
/*
* Values 2..6 inclusive reserved further data types, including maybe
* implementing reals later.
*/
/**
* This is not actually a pointer at all but the first word of a cell.
*/
#define CELLTV 7
/**
* Half of a cons cell. The mark bit is first, so that the ptag can be
* considered as part of the CTAG.
*/
struct pointer {
/* mark bit for mark and sweep garbage collector. Yes, this is normally
* thought of as part of the cell, but bear with me. */
unsigned int mark : 1;
/* pointer tag, interpretations as above */
unsigned int ptag : 3;
/* the actual payload of the pointer object */
union {
unsigned int offset : 28;
int value : 28;
} payload;
};
struct cons_payload {
struct pointer pointers[2];
};
struct symbol_payload {
/* this is the same mark bit as the one in the `address` pointer of the
* cons_payload. */
unsigned int mark : 1;
unsigned int tag : 7;
char symbol[7];
};
/* Tags for 64 bit objects. Note that, as the 64 bit object may be made up
* of two 32 bit objects (pointers*, the 64 bit tag is stored in bits 4..7
* inclusive. The first three bits are the first three bits of a 32 bit object,
* and thus for 64bit objects will always b 111.*/
/* this 64 bit object is a cons cell */
#define CONSTV 7
/* this 64 bit object is a seven character atom */
#define ATOMTV 8
/* There are potentially another 119 types of object we could store in a 64
* bit object, but I can't think of any we need just now. */
struct cell {
union {
struct cons_payload cons;
struct symbol_payload symbol;
} payload;
};
#define CONSSPACESIZE 65536
/**
* The entire array of cells available to the system.
*/
struct cell consspace[CONSSPACESIZE];
#endif