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.
This commit is contained in:
Simon Brooke 2026-04-05 12:22:48 +01:00
parent d743b6787e
commit 7e9dc12766
4 changed files with 155 additions and 0 deletions

5
.gitignore vendored
View file

@ -52,3 +52,8 @@ Module.symvers
Mkfile.old
dkms.conf
# Eclipse artefacts
.cproject
.project
.settings/
build/

33
Makefile Normal file
View file

@ -0,0 +1,33 @@
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
OBJS = grendel.o
ifeq ($(BUILD_MODE),debug)
CFLAGS += -g -O0
else ifeq ($(BUILD_MODE),run)
CFLAGS += -O2
else ifeq ($(BUILD_MODE),profile)
CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
LDFLAGS += -pg -fprofile-arcs -ftest-coverage
EXTRA_CLEAN += grendel.gcda grendel.gcno $(PROJECT_ROOT)gmon.out
EXTRA_CMDS = rm -rf grendel.gcda
else
$(error Build mode $(BUILD_MODE) not supported by this Makefile)
endif
SRC_DIR=$(PROJECT_ROOT)/src
all: grendel
grendel: $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $^
$(EXTRA_CMDS)
# %.o: $(SRC_DIR)/%.cpp
# $(CXX) -c $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -o $@ $<
%.o: $(SRC_DIR)/%.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
clean:
rm -fr grendel $(OBJS) $(EXTRA_CLEAN)

23
src/grendel.c Normal file
View file

@ -0,0 +1,23 @@
/**
*
* grendel.c
*
* 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.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "memory.h"
int main(int argc, char **argv) {
printf( "Grendel: size of pointer: %d, size of cell %d\n", sizeof( struct pointer), sizeof( struct cell));
return 0;
}

94
src/memory.h Normal file
View file

@ -0,0 +1,94 @@
/**
* 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