Skip to content

Commit

Permalink
Tagged at v0.1.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcuth committed Oct 29, 2014
1 parent 7b4b7cd commit d30fd22
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"email": "paul.cuthbertson@gamesys.co.uk"
}
],
"version": "0.1.2",
"version": "0.1.3",
"engines": {
"node": ">=0.8.x"
},
Expand Down
Binary file modified test/as/runner.swf
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test-package.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions vm/moonshine-module.js

Large diffs are not rendered by default.

98 changes: 51 additions & 47 deletions vm/moonshine.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

(function () {
var originalValue = window.shine;

window.shine = {
noConflict: function () {
window.shine = originalValue;
return this;
}
};

})();



Expand Down Expand Up @@ -3248,16 +3260,17 @@ shine.File.prototype.dispose = function () {


function callR (register, index, c, argStart, argEnd) {
var args, result;
var result, i, limit,
args = createArray();

if (!argStart) {
args = createArray();
} else if (!argEnd) {
args = register.slice(argStart);
} else {
args = register.slice(argStart, argEnd);
if (argStart) {
limit = argEnd? argEnd : register.length;

for (i = argStart; i < limit; i++) {
args.push(register[i]);
}
}

result = call_internal(register[index],args);

register.length = index;
Expand All @@ -3267,7 +3280,7 @@ shine.File.prototype.dispose = function () {

if (!(result instanceof Array)) {
setR(register, index, result);

} else {
result.unshift(index, 0);
Array.prototype.splice.apply(register, result);
Expand Down Expand Up @@ -3421,7 +3434,7 @@ shine.File.prototype.dispose = function () {
var SET_REG_PATTERN = /^setR\(R,(\d+),([^;]*?)\);$/,
gc = shine.gc,
Function_apply = shine.Function.prototype.apply,
compileQueue = [],
compileQueue = gc.createArray(),
frameCounter = 0,
waitingToCompile = false,
getNow = Date['now']? Date['now'] : function () { return new Date().getTime(); },
Expand Down Expand Up @@ -3484,15 +3497,15 @@ shine.File.prototype.dispose = function () {

function createRunner (instance, data, compiled) {
return function (context, args) {
var closure = shine.gc.createObject(),
var closure = gc.createObject(),
retvals;

closure._vm = instance._vm;
closure._globals = instance._globals;
closure._upvalues = instance._upvalues;
closure._constants = data.constants;
closure._functions = data.functions;
closure._localsUsedAsUpvalues = shine.gc.createArray();
closure._localsUsedAsUpvalues = gc.createArray();

return compiled.apply(closure, args);
};
Expand Down Expand Up @@ -3559,7 +3572,11 @@ shine.File.prototype.dispose = function () {
waitingToCompile = false;
shine.jit.onCompile();

while (compileQueue.length) compile.apply(null, compileQueue.shift());
while (compileQueue.length) {
var item = compileQueue.shift()
compile(item[0], item[1]);
gc.collect(item);
}
}


Expand All @@ -3578,21 +3595,8 @@ shine.File.prototype.dispose = function () {
******************************************************************/


/**
* Create a comma delimited string of consecutive numbers.
* @param {number} last The number on which to end the sequence.
* @param {string} [prefix=''] Optional prefix to each number in the string.
* @param {number} [first=0] Optional start number.
* @returns {string} Comma delimited string.
*/
function createNumberString (last, prefix, first) {
prefix = '' + (prefix || '');
var x = first || 0;
if (last < x) return '';
return Array(last - x + 1).join().replace(new RegExp('','g'), function () { return prefix + x++; });
}


var NEWLINE_PATTERN = /\n/g,
APOS_PATTERN = /'/g;


/**
Expand All @@ -3602,8 +3606,8 @@ shine.File.prototype.dispose = function () {
*/
function formatValue (value) {
if (typeof value == 'string') {
value = value.replace(/\n/g, '\\n');
value = value.replace(/'/g, '\\\'');
value = value.replace(NEWLINE_PATTERN, '\\n');
value = value.replace(APOS_PATTERN, '\\\'');
return "'" + value + "'";
}

Expand Down Expand Up @@ -3634,24 +3638,20 @@ shine.File.prototype.dispose = function () {


function translate_move (a, b) {
// return 'R' + a + '=R' + b + ';';
// return 'setupval(' + a + ',register[' + b + ']);';
return 'setR(R,' + a + ',R[' + b + ']);';
}




function translate_loadk (a, bx) {
// return 'R' + a + '=' + formatValue(this.getConstant(bx)) + ';';
return 'setR(R,' + a + ',' + formatValue(this.getConstant(bx)) + ');';
}




function translate_loadbool (a, b, c) {
// var result = 'decr(register[' + a + ']);register[' + a + ']=' + !!b + ';',
var result = 'setR(R,' + a + ',' + !!b + ');',
pc;

Expand Down Expand Up @@ -3690,8 +3690,6 @@ shine.File.prototype.dispose = function () {

function translate_getglobal (a, b) {
var key = this.getConstant(b);

// return 'R' + a + '=cl._globals' + ((key == '_G')? '' : '[' + formatValue(key) + ']') + ';';
return 'setR(R,' + a + ',shine_g' + ((key == '_G')? '' : '[' + formatValue(key) + ']') + ');';
}

Expand Down Expand Up @@ -4152,13 +4150,12 @@ shine.File.prototype.dispose = function () {
* @param {shine.Function} func The input Moonshine function definition.
* @returns {function} A JavaScript representation of the function.
*/
// shine.jit.compile = function (func) {
// var js = shine.jit.toJS(func);
// return shine.operations.evaluateInScope(js);
// };
shine.jit.compile = function (func, callback) {
if (shine.jit.MIN_FPS_TO_COMPILE) {
compileQueue.push(arguments);
var args = gc.createArray();
args.push(func, callback);

compileQueue.push(args);
enableCompileTimer();

} else {
Expand Down Expand Up @@ -4201,17 +4198,18 @@ shine.File.prototype.dispose = function () {
pc: pc,
code: gc.createArray(),
vars: gc.createArray(),
jumpDestinations: [1],
jumpDestinations: gc.createArray(),

_constants: func._data.constants,
_instructions: func._data.instructions,

getConstant: function (index) {
if (this._constants[index] === null) return;
return this._constants[index];
var val = this._constants[index];
return this._constants[index] === null? void 0 : val;
}
};

state.jumpDestinations.push(1);

// Get code representation of instructions
l = instructions.length / 4;
Expand Down Expand Up @@ -4266,9 +4264,13 @@ shine.File.prototype.dispose = function () {
// return 'function(){' + code.join('\n') + '}';
result = 'function(' + paramNames.join() + '){' + code.join('\n') + '}';


gc.collect(code);
gc.collect(paramNames);

gc.collect(state.code);
gc.collect(state.vars);
gc.collect(state.jumpDestinations);

gc.collect(state);

return result;
Expand Down Expand Up @@ -4600,6 +4602,7 @@ if (typeof module != 'undefined') module.exports = shine.jit;
var found = (index === undefined),
numValues = table.__shine.numValues,
keys,
key, value,
i, l;

if (found || (typeof index == 'number' && index > 0 && index == index >> 0)) {
Expand All @@ -4615,8 +4618,9 @@ if (typeof module != 'undefined') module.exports = shine.jit;
found = true;
}

if (found && (i = keys[i]) !== undefined && numValues[i] !== undefined) {
return [i >>= 0, numValues[i]];
if (found) {
while ((key = keys[i]) !== void 0 && (value = numValues[key]) === void 0) i++;
if (value !== void 0) return [i >>= 0, value];
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion vm/moonshine.min.js

Large diffs are not rendered by default.

Binary file modified vm/moonshine.swc
Binary file not shown.

0 comments on commit d30fd22

Please sign in to comment.