Skip to content

Commit e089772

Browse files
committed
Add /reset /memory
Fix error line numbers in include files Add help
1 parent 00d1bdf commit e089772

4 files changed

Lines changed: 281 additions & 184 deletions

File tree

src/gc.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include <sys/mman.h>
77
#include "gc.h"
88

9-
extern void error(char *fmt, ...);
9+
extern void error(char *fmt, int line_num, ...);
10+
extern filepos_t filepos;
1011

1112
// The pointer pointing to the beginning of the current heap
1213
void *memory;
@@ -15,7 +16,7 @@ void *memory;
1516
static void *from_space;
1617

1718
// The number of bytes allocated from the heap
18-
static size_t mem_nused = 0;
19+
size_t mem_nused = 0;
1920

2021
// Flags to debug GC
2122
bool gc_running = false;
@@ -63,7 +64,7 @@ Obj *alloc(void *root, int type, size_t size) {
6364
// Terminate the program if we couldn't satisfy the memory request. This can happen if the
6465
// requested size was too large or the from-space was filled with too many live objects.
6566
if (MEMORY_SIZE < mem_nused + size)
66-
error("Memory exhausted");
67+
error("Memory exhausted", filepos.line_num);
6768

6869
// Allocate the object.
6970
Obj *obj = memory + mem_nused;
@@ -115,6 +116,11 @@ void *alloc_semispace() {
115116
return mmap(NULL, MEMORY_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
116117
}
117118

119+
void free_semispace(void *ptr){
120+
if (ptr) munmap(ptr, MEMORY_SIZE);
121+
mem_nused = 0;
122+
}
123+
118124
// Copies the root objects.
119125
static void forward_root_objects(void *root) {
120126
Symbols = forward(Symbols);

0 commit comments

Comments
 (0)