Skip to content

Commit

Permalink
fix!: Rework memory management (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer authored Dec 12, 2020
1 parent 6ada4ea commit 89a2aa8
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 548 deletions.
2 changes: 1 addition & 1 deletion cli/bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = async function run(filename, options) {
let locator = runtime.defaultFileLocator(includeDirs);
let GrainRunner = runtime.buildGrainRunner(locator, {limitMemory: options.limitMemory});
if (options.printOutput) {
let result = await GrainRunner.runFileUnboxed(filename, true);
let result = await GrainRunner.runFileUnboxed(filename);
console.log(runtime.grainToString(GrainRunner, result));
} else {
await GrainRunner.runFile(filename);
Expand Down
6 changes: 5 additions & 1 deletion runtime/src/core/closures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { view, grainModule } from '../runtime';
import { managedMemory, grainModule } from '../runtime';
import { throwGrainError } from '../errors/errors';
import { grainToJSVal, JSToGrainVal } from '../utils/utils';
import { GRAIN_ERR_ARITY_MISMATCH } from '../errors/error-codes';
Expand All @@ -7,6 +7,8 @@ import { print } from '../lib/print';

export class GrainClosure {
constructor(loc) {
const view = managedMemory.view;

this.loc = loc;
this.arity = view[loc];
this.ptr = view[loc + 1];
Expand All @@ -28,6 +30,8 @@ export class GrainClosure {
};

export function printClosure(c) {
const view = managedMemory.view;

c /= 4;
let arity = view[c];
let idx = view[c + 1];
Expand Down
4 changes: 0 additions & 4 deletions runtime/src/core/grain-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ export class GrainModule {
return this.requiredExport("GRAIN$TABLE_SIZE");
}

get cleanupGlobals() {
return this.requiredExport("GRAIN$CLEANUP_GLOBALS");
}

get types() {
if (!this._types) {
let cmi = this.cmi;
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/core/heap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memory, malloc } from '../runtime';
import { memory, managedMemory } from '../runtime';
import { GrainError } from '../errors/errors';

export const heapController = {
Expand Down Expand Up @@ -26,5 +26,5 @@ export function makeMemoryChecker(runner) {

export function grainHeapAllocate(numWords) {
// allocates the number of words
return malloc(numWords * 4)
return managedMemory.malloc(numWords * 4)
}
335 changes: 0 additions & 335 deletions runtime/src/core/malloc.js

This file was deleted.

Loading

0 comments on commit 89a2aa8

Please sign in to comment.