diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 5 | ||||
-rw-r--r-- | src/preamble.js | 1 | ||||
-rw-r--r-- | src/runtime.js | 25 |
3 files changed, 16 insertions, 15 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 10f3851f..66beb0bf 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -545,10 +545,9 @@ function JSify(data) { makeFuncLineZyme('alloca', function(item) { dprint('alloca', dump(item)); if (pointingLevels(item.allocatedType.text) == 0 && isStructType(item.allocatedType.text)) { - // TODO: allocate on a stack, not on the heap (we currently leak all this) - return makePointer(JSON.stringify(makeEmptyStruct(item.allocatedType.text)), null, 'ALLOC_STACK'); + return RuntimeGenerator.stackAlloc(makeEmptyStruct(item.allocatedType.text).length); } else { - return makePointer('[0]', null, 'ALLOC_STACK'); + return RuntimeGenerator.stackAlloc(1); } }); makeFuncLineZyme('phi', function(item) { diff --git a/src/preamble.js b/src/preamble.js index 33c9515d..a2efad57 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -39,7 +39,6 @@ function assert(condition, text) { if (!condition) { var text = "Assertion failed: " + text; print(text + ':\n' + (new Error).stack); - if (this[alert]) alert(text) throw "Assertion: " + text; } } diff --git a/src/runtime.js b/src/runtime.js index 541f4756..08e42362 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -1,20 +1,23 @@ +////////////QUANTUM_SIZE = GUARD_STACK = 1; // Generates code that can be placed inline in generated code. // This is not the cleanest way to write this kind of code - it is // optimized for generating fast inline code. RuntimeGenerator = { - alloc: function(target, size, type) { - var ret = target + ' = ' + type + 'TOP; ' + type + 'TOP += ' + size + ';'; + alloc: function(size, type) { + var ret = type + 'TOP'; +// ret += '; for (var i = 0; i < ' + size + '; i++) HEAP[' + type + 'TOP+i] = 0'; + ret += '; ' + type + 'TOP += ' + size; if (QUANTUM_SIZE > 1) { - ret += RuntimeGenerator.alignMemory(type + 'TOP'); + ret += ';' + RuntimeGenerator.alignMemory(type + 'TOP'); } return ret; }, // An allocation that lives as long as the current function call - stackAlloc: function(target, size) { - var ret = RuntimeGenerator.alloc(target, size, 'STACK'); + stackAlloc: function(size) { + var ret = RuntimeGenerator.alloc(size, 'STACK'); if (GUARD_STACK) { - ret += ' assert(STACKTOP < STACK_ROOT + STACK_MAX);'; + ret += '; assert(STACKTOP < STACK_ROOT + STACK_MAX)'; } return ret; }, @@ -28,8 +31,8 @@ RuntimeGenerator = { }, // An allocation that cannot be free'd - staticAlloc: function(target, size) { - return RuntimeGenerator.alloc(target, size, 'STATIC'); + staticAlloc: function(size) { + return RuntimeGenerator.alloc(size, 'STATIC'); }, alignMemory: function(target) { @@ -38,8 +41,8 @@ RuntimeGenerator = { }; function unInline(name_, params) { - var src = '(function ' + name_ + '(' + params + ') { var ret; ' + RuntimeGenerator[name_].apply(null, ['ret'].concat(params)) + ' return ret; })'; - print('src: ' + src); + var src = '(function ' + name_ + '(' + params + ') { var ret = ' + RuntimeGenerator[name_].apply(null, params) + '; return ret; })'; + //print('src: ' + src); return eval(src); } @@ -57,6 +60,6 @@ function getRuntime() { for (i in Runtime) { ret += Runtime[i].toString() + '\n'; } - return ret; + return ret + '\n'; } |