SETD, and fix for assigning to a param

This commit is contained in:
Alon Zakai 2014-09-22 21:28:02 -07:00
Родитель 2ff7d1702c
Коммит 4878f915f5
2 изменённых файлов: 18 добавлений и 4 удалений

Просмотреть файл

@ -44,6 +44,7 @@ OPCODES = { # l, lx, ly etc - one of 256 locals
'40': 'SHL', # [lx, ly, lz] lx = ly << lz
'41': 'ASHR', # [lx, ly, lz] lx = ly >> lz
'42': 'LSHR', # [lx, ly, lz] lx = ly >>> lz
'60': 'SETD', # [lx, ly, lz] lx = ly (double)
'100': 'LOAD8', # [lx, ly, 0] lx = HEAP8[ly >> 0]
'110': 'LOAD16', # [lx, ly, 0] lx = HEAP16[ly >> 1]
'120': 'LOAD32', # [lx, ly, 0] lx = HEAP32[ly >> 2]
@ -123,6 +124,7 @@ CASES[ROPCODES['XOR']] = get_access('lx') + ' = (' + get_coerced_access('ly') +
CASES[ROPCODES['SHL']] = get_access('lx') + ' = (' + get_coerced_access('ly') + ') << (' + get_coerced_access('lz') + ');'
CASES[ROPCODES['ASHR']] = get_access('lx') + ' = (' + get_coerced_access('ly') + ') >> (' + get_coerced_access('lz') + ');'
CASES[ROPCODES['LSHR']] = get_access('lx') + ' = (' + get_coerced_access('ly') + ') >>> (' + get_coerced_access('lz') + ');'
CASES[ROPCODES['SETD']] = get_access('lx', s='d') + ' = ' + get_coerced_access('ly', s='d') + ';'
CASES[ROPCODES['LOAD8']] = get_access('lx') + ' = ' + 'HEAP8[' + get_access('ly') + ' >> 0];'
CASES[ROPCODES['LOAD16']] = get_access('lx') + ' = ' + 'HEAP16[' + get_access('ly') + ' >> 1];'
CASES[ROPCODES['LOAD32']] = get_access('lx') + ' = ' + 'HEAP32[' + get_access('ly') + ' >> 2];'

Просмотреть файл

@ -1896,7 +1896,8 @@ function getCombinedType(node1, node2, asmData, hint) {
var ASM_FLEXIBLE = 0; // small constants can be signed or unsigned, variables are also flexible
var ASM_SIGNED = 1;
var ASM_UNSIGNED = 2
var ASM_UNSIGNED = 2;
var ASM_NONSIGNED = 3;
function detectSign(node) {
if (node[0] === 'binary') {
@ -5755,9 +5756,15 @@ function emterpretify(ast) {
// local
var reg = getReg(value);
var type = asmData.vars[name];
assert(type !== ASM_DOUBLE); // TODO: SETD
if (type === undefined) type = asmData.params[name];
// TODO: detect when the last operation in reg[1] assigns in its arg x, in which case we can avoid the SET and make it assign to us
return [locals[name], reg[1].concat(['SET', locals[name], releaseIfFree(reg[0]), 0])];
var opcode;
if (type === ASM_INT) {
opcode = 'SET';
} else if (type === ASM_DOUBLE) {
opcode = 'SETD';
} else throw 'ick';
return [locals[name], reg[1].concat([opcode, locals[name], releaseIfFree(reg[0]), 0])];
} else {
switch(name) {
case 'STACKTOP': {
@ -5821,7 +5828,12 @@ function emterpretify(ast) {
throw 'todo';
}
case 'unary-prefix': {
// TODO: double coercions
if (node[1] === '+') {
// double operation
return getReg(node[2], dropIt, ASM_DOUBLE, ASM_NONSIGNED);
}
// not a simple coercion
assert(!dropIt);
switch (node[1]) {