Progress, but it still doesn't build. I think I'm close, now...
This commit is contained in:
parent
00997d3c90
commit
04bf001652
12 changed files with 58 additions and 47 deletions
|
|
@ -17,6 +17,11 @@
|
|||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* wide characters
|
||||
*/
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
/**
|
||||
* @brief Print messages debugging memory allocation.
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ struct pso_header {
|
|||
char mnemonic[TAGLENGTH];
|
||||
/** size class for this object */
|
||||
uint8_t size_class;
|
||||
} tag;
|
||||
} bytes;
|
||||
/** the tag considered as a number */
|
||||
uint32_t value;
|
||||
} tag;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
* since managed objects require a two word header; it's unlikely that
|
||||
* these undersized size classes will be used at all.
|
||||
*/
|
||||
#define MAX_SIZE_CLASS = 0xf
|
||||
#define MAX_SIZE_CLASS 0xf
|
||||
|
||||
int initialise_memory( );
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "debug.h"
|
||||
#include "memory/memory.h"
|
||||
#include "memory/node.h"
|
||||
#include "memory/page.h"
|
||||
|
|
@ -36,13 +39,13 @@
|
|||
* to hold the number of pages we *might* create at start up time. We need a
|
||||
* way to grow the number of pages, while keeping access to them cheap.
|
||||
*/
|
||||
struct page * pages[NPAGES];
|
||||
union page * pages[NPAGES];
|
||||
|
||||
/**
|
||||
* @brief the number of pages which have thus far been allocated.
|
||||
*
|
||||
*/
|
||||
uint32_t npages_allocated = 0
|
||||
uint32_t npages_allocated = 0;
|
||||
|
||||
/**
|
||||
* @brief private to allocate_page; do not use.
|
||||
|
|
@ -51,10 +54,11 @@ uint32_t npages_allocated = 0
|
|||
* @param page_index its location in the pages[] array;
|
||||
* @param size_class the size class of objects in this page;
|
||||
* @param freelist the freelist for objects of this size class.
|
||||
* @return struct cons_pointer the new head for the freelist for this size_class,
|
||||
* @return struct pso_pointer the new head for the freelist for this size_class,
|
||||
*/
|
||||
struct cons_pointer initialise_page( struct page * page_addr, uint16_t page_index, uint8_t size_class, pso_pointer freelist) {
|
||||
struct cons_pointer result = freelist;
|
||||
struct pso_pointer initialise_page( union page* page_addr, uint16_t page_index,
|
||||
uint8_t size_class, struct pso_pointer freelist) {
|
||||
struct pso_pointer result = freelist;
|
||||
int obj_size = pow(2, size_class);
|
||||
int obj_bytes = obj_size * sizeof(uint64_t);
|
||||
int objs_in_page = PAGE_BYTES/obj_bytes;
|
||||
|
|
@ -64,16 +68,14 @@ struct cons_pointer initialise_page( struct page * page_addr, uint16_t page_inde
|
|||
// `nil` and the next on for `t`.
|
||||
for (int i = objs_in_page - 1; i >= 0; i--) {
|
||||
// it should be safe to cast any pso object to a pso2
|
||||
struct pso2* object = (pso2 *)(page_addr + (i * obj_bytes));
|
||||
struct pso2* object = (struct pso2 *)(page_addr + (i * obj_bytes));
|
||||
|
||||
object->header.tag.size_class = size_class;
|
||||
strncpy( (char *)(object->header.tag.mnemonic), FREETAG, TAGLENGTH);
|
||||
object->header.tag.bytes.size_class = size_class;
|
||||
strncpy( (char *)(object->header.tag.bytes.mnemonic), FREETAG, TAGLENGTH);
|
||||
object->payload.free.next = result;
|
||||
|
||||
result = make_pointer( node_index, page_index, (uint16_t)( i * obj_size));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,8 +91,8 @@ struct cons_pointer initialise_page( struct page * page_addr, uint16_t page_inde
|
|||
* @param size_class an integer in the range 0...MAX_SIZE_CLASS.
|
||||
* @return t on success, an exception if an error occurred.
|
||||
*/
|
||||
struct cons_pointer allocate_page( uint8_t size_class ) {
|
||||
struct cons_pointer result = t;
|
||||
struct pso_pointer allocate_page( uint8_t size_class ) {
|
||||
struct pso_pointer result = t;
|
||||
|
||||
if ( npages_allocated == 0) {
|
||||
for (int i = 0; i < NPAGES; i++) {
|
||||
|
|
@ -101,17 +103,17 @@ struct cons_pointer allocate_page( uint8_t size_class ) {
|
|||
|
||||
if ( npages_allocated < NPAGES) {
|
||||
if ( size_class >= 2 && size_class <= MAX_SIZE_CLASS ) {
|
||||
result = malloc( sizeof( page ) );
|
||||
void* pg = malloc( sizeof( union page ) );
|
||||
|
||||
if ( result != NULL ) {
|
||||
memset( result, 0, sizeof( page ) );
|
||||
pages[ npages_allocated] = result;
|
||||
if ( pg != NULL ) {
|
||||
memset( pg, 0, sizeof( union page ) );
|
||||
pages[ npages_allocated] = pg;
|
||||
debug_printf( DEBUG_ALLOC, 0,
|
||||
L"Allocated page %d for objects of size class %x.\n",
|
||||
npages_allocated, size_class);
|
||||
|
||||
freelists[size_class] =
|
||||
initialise_page( result, npages_allocated, size_class, freelists[size_class] );
|
||||
initialise_page( (union page*)pg, npages_allocated, size_class, freelists[size_class] );
|
||||
|
||||
debug_printf( DEBUG_ALLOC, 0,
|
||||
L"Initialised page %d; freelist for size class %x updated.\n",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#ifndef __psse_memory_page_h
|
||||
#define __psse_memory_page_h
|
||||
|
||||
#include "memory/pointer.h"
|
||||
#include "memory/pso2.h"
|
||||
#include "memory/pso3.h"
|
||||
#include "memory/pso4.h"
|
||||
|
|
@ -38,7 +39,7 @@
|
|||
*/
|
||||
#define NPAGES 64
|
||||
|
||||
extern struct page *pages[NPAGES];
|
||||
extern union page *pages[NPAGES];
|
||||
|
||||
/**
|
||||
* @brief A page is a megabyte of memory which contains objects all of which
|
||||
|
|
@ -53,22 +54,25 @@ extern struct page *pages[NPAGES];
|
|||
* collection they will be returned to that freelist.
|
||||
*/
|
||||
union page {
|
||||
uint8_t[PAGE_BYTES] bytes;
|
||||
uint64_t[PAGE_BYTES / 8] words;
|
||||
struct pso2[PAGE_BYTES / 32] pso2s;
|
||||
struct pso3[PAGE_BYTES / 64] pso3s;
|
||||
struct pso4[PAGE_BYTES / 128] pso4s;
|
||||
struct pso5[PAGE_BYTES / 256] pso5s;
|
||||
struct pso6[PAGE_BYTES / 512] pso6s;
|
||||
struct pso7[PAGE_BYTES / 1024] pso7s;
|
||||
struct pso8[PAGE_BYTES / 2048] pso8s;
|
||||
struct pso9[PAGE_BYTES / 4096] pso9s;
|
||||
struct psoa[PAGE_BYTES / 8192] psoas;
|
||||
struct psob[PAGE_BYTES / 16384] psobs;
|
||||
struct psoc[PAGE_BYTES / 32768] psocs;
|
||||
struct psod[PAGE_BYTES / 65536] psods;
|
||||
struct psoe[PAGE_BYTES / 131072] psoes;
|
||||
struct psof[PAGE_BYTES / 262144] psofs;
|
||||
uint8_t bytes[PAGE_BYTES];
|
||||
uint64_t words[PAGE_BYTES / 8];
|
||||
struct pso2 pso2s[PAGE_BYTES / 32];
|
||||
struct pso3 pso3s[PAGE_BYTES / 64];
|
||||
struct pso4 pso4s[PAGE_BYTES / 128];
|
||||
struct pso5 pso5s[PAGE_BYTES / 256];
|
||||
struct pso6 pso6s[PAGE_BYTES / 512];
|
||||
struct pso7 pso7s[PAGE_BYTES / 1024];
|
||||
struct pso8 pso8s[PAGE_BYTES / 2048];
|
||||
struct pso9 pso9s[PAGE_BYTES / 4096];
|
||||
struct psoa psoas[PAGE_BYTES / 8192];
|
||||
struct psob psobs[PAGE_BYTES / 16384];
|
||||
struct psoc psocs[PAGE_BYTES / 32768];
|
||||
struct psod psods[PAGE_BYTES / 65536];
|
||||
struct psoe psoes[PAGE_BYTES / 131072];
|
||||
struct psof psofs[PAGE_BYTES / 262144];
|
||||
};
|
||||
|
||||
struct pso_pointer initialise_page( union page * page_addr, uint16_t page_index,
|
||||
uint8_t size_class, struct pso_pointer freelist);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include "payloads/special.h"
|
||||
#include "payloads/string.h"
|
||||
#include "payloads/symbol.h"
|
||||
#include "payloads/time.h"
|
||||
// #include "payloads/time.h"
|
||||
#include "payloads/vector_pointer.h"
|
||||
#include "payloads/write_stream.h"
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ struct pso2 {
|
|||
struct lambda_payload lambda;
|
||||
// struct special_payload special;
|
||||
struct stream_payload stream;
|
||||
struct time_payload time;
|
||||
// struct time_payload time;
|
||||
struct vectorp_payload vectorp;
|
||||
} payload;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "memory/node.h"
|
||||
#include "memory/pointer.h"
|
||||
#include "memory/pso.h"
|
||||
#include "memory/pso2.h"
|
||||
#include "payloads/cons.h"
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,12 +8,10 @@
|
|||
*/
|
||||
|
||||
#include "memory/node.h"
|
||||
#include "memory/pso.h"
|
||||
#include "memory/pso2.h"
|
||||
#include "memory/pso4.h"
|
||||
#include "payloads/stack.h"
|
||||
|
||||
#define STACKTAG "STK"
|
||||
#define STACKTV 4936787
|
||||
|
||||
/**
|
||||
* @brief The maximum depth of stack before we throw an exception.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@
|
|||
#define __psse_payloads_stack_h
|
||||
|
||||
#include "memory/pointer.h"
|
||||
#include "memory/pso2.h"
|
||||
#include "memory/pso4.h"
|
||||
|
||||
#define STACKTAG "STK"
|
||||
#define STACKTV 4936787
|
||||
|
||||
/*
|
||||
* number of arguments stored in a stack frame
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
* convenience, 14Bn years before 1st Jan 1970 (the UNIX epoch))
|
||||
*/
|
||||
struct time_payload {
|
||||
unsigned __int128 value;
|
||||
unsigned __int128_t value;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ int main( int argc, char *argv[] ) {
|
|||
|
||||
initialise_node( 0 );
|
||||
|
||||
repl( );
|
||||
// repl( );
|
||||
|
||||
exit( 0 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "debug.h"
|
||||
#include "memory/memory.h"
|
||||
#include "memory/stack.h"
|
||||
#include "payloads/stack.h"
|
||||
#include "version.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue