diff --git a/examples/bug.noja b/examples/bug.noja deleted file mode 100644 index 8057b51..0000000 --- a/examples/bug.noja +++ /dev/null @@ -1,6 +0,0 @@ -a = []; -i = 0; -while(i<10000):{ - a[i]= "ciao mondo mmododooddododododododododododdodododododd"; - i = i+1; -} \ No newline at end of file diff --git a/examples/bug2.noja b/examples/bug2.noja deleted file mode 100644 index 8dffb40..0000000 --- a/examples/bug2.noja +++ /dev/null @@ -1,2 +0,0 @@ -fun f() return 1, 2; -print((a, b) = f(), '\n'); \ No newline at end of file diff --git a/examples/json.noja b/examples/json.noja index 48f00eb..1846e9c 100644 --- a/examples/json.noja +++ b/examples/json.noja @@ -243,9 +243,21 @@ fun parseAny(ctx) { tests = [ - '', '1', '10', - '1.@10', '1.10', '"jeje"', - '[]', '[1,2,3]', ' [ ] ', ' [ 1 , 2 , 3 ]', '{}', ' { } ', '{"hoy":4}', ' { "hoy" : 4 } ']; + '', + '1', + '10', + '1.@10', + '1.10', + '"jeje"', + '[]', + '[1,2,3]', + ' [ ] ', + ' [ 1 , 2 , 3 ]', + '{}', + ' { } ', + '{"hoy":4}', + ' { "hoy" : 4 } ' +]; i = 0; while i < count(tests): { diff --git a/src/objects/heap.c b/src/objects/heap.c index 28f102e..b4123e6 100644 --- a/src/objects/heap.c +++ b/src/objects/heap.c @@ -38,18 +38,20 @@ ** | The collection algorithm is move-and-compact. The allocator is a | ** | bump-pointer allocator. When the base pool of memory is filled up, | ** | further allocations are forwarded to the stdlib's malloc, but are kept | -** | track of by putting them in a linked list. When the parent system decides| -** | to free up some memory, a new heap is allocated and the live objects are | -** | moved to it, then the old heap is freed. The references between live | -** | objects are updated when moving them.Some objects implement destructors | -** | that must be called when a new heap is allocated and they're not moved | -** | to it. An auxiliary list of allocated objects with destructors is stored | -** | alongside the heap. When the live objects are moved and the ones to be | -** | destroyed are left in the old one, the list of objects with destructors | -** | is iterated over and the objects in it that weren't moved are destroied | -** | and removed from the list. This approach becomes linearly slower with | -** | the number of allocated objects with destructors, but it's assumed that | -** | not many of them implement them. | +** | track of by putting them in a linked list. When the language's runtime | +** | system decides to free up some memory, a new heap is allocated and the | +** | live objects are moved to it, then the old heap is freed. The references | +** | between live objects are updated when moving them. Some objects implement| +** | destructors that must be called when a new heap is allocated and they're | +** | not moved to it. An auxiliary list of allocated objects with destructors | +** | is stored alongside the heap. When the live objects are moved and the | +** | ones to be destroyed are left in the old one, the list of objects with | +** | destructors is iterated over and the objects in it that weren't moved are| +** | destroied and removed from the list. This approach becomes linearly | +** | slower with the number of allocated objects with destructors, but it's | +** | assumed that not many of them implement them. | +** | If during a collection the new memory pool is filled up, then an error is| +** | thrown to the parent system. | ** | | ** | HOW ARE POINTERS UPDATED? | ** | Basically, when an object is moved from the old to the new heap, the | @@ -291,6 +293,12 @@ void *Heap_RawMalloc(Heap *heap, int size, Error *err) if(heap->used + size > heap->size) { + if(heap->collecting) + { + Error_Report(err, 1, "Out of heap"); + return NULL; + } + OflowAlloc *oflow = malloc(sizeof(OflowAlloc) + size); if(oflow == 0)