JSC.js icon indicating copy to clipboard operation
JSC.js copied to clipboard

Different results from JSC_Eval to JSC_Eval_Bytecode

Open TristonStuart opened this issue 4 years ago • 10 comments

I am getting different results when evaluation js vs compiling that js and evaluating it with jsc_eval_bytecode. Here is the code :

function add(x, y){
  return x + y;
}
function subtract(x, y){
  return x - y;
}
function multiply(x, y){
  return x * y;
}
function devide(x, y){
  return x / y;
}
function pow(x, y){
  return Math.pow(x, y);
}
class NMath{
  constructor(){
    this.add = add;
    this.subtract = subtract;
    this.multiply = multiply;
    this.devide = devide;
    this.pow = pow;
  }

  smors(x){
    var arr = x.split('');
    var narr = [];
    var total = 1;
    for (let i=0; i < arr.length; i++){
      narr.push(this.multiply(arr[i].charCodeAt(), 2));
    }
    for (let i=0; i < narr.length; i++){
      total = total + narr[i] - this.devide((narr[i - 1])? narr[i-1] : 1, 3);
    }
    return total;
  }
}
let pp = new NMath();
pp.smors('hello');

If I do Module.cwrap('jsc_eval', 'string', ['string']) I get 784 as the result. If I compile it and evaluate that I get this error :

Exception: SyntaxError: Unexpected identifier ''. Expected an opening '(' before a method's parameter list.

No idea what is causing this as I am just using the string returned from Module.cwrap('jsc_compile') to feed to jsc_eval.

TristonStuart avatar May 28 '20 03:05 TristonStuart

https://github.com/mbbill/JSC.js/issues/10#issuecomment-629558789

mbbill avatar May 28 '20 05:05 mbbill

Have you seen this https://webkit.org/blog/9329/a-new-bytecode-format-for-javascriptcore/ ? I have no idea about webkit and compiling to bytecode. But if there is anyway you could check if there is a fix for this that would be amazing.

TristonStuart avatar May 28 '20 06:05 TristonStuart

The link you posted is the foundation of JSC.js's bytecode compiler. If you look at the code JSC.js is basically calling into the bytecode compiler to dump the code cache and then output as binary array. It's was not possible before JSC introduce that feature, and that's why I started this project years ago but only tested bytecode compiler since last year.

mbbill avatar May 28 '20 06:05 mbbill

Ah so you don’t know if they have updated it?

TristonStuart avatar May 28 '20 15:05 TristonStuart

unless I do another update and try again.

mbbill avatar May 28 '20 20:05 mbbill

ah is that hard to do?

TristonStuart avatar May 29 '20 06:05 TristonStuart

not hard, just takes time

mbbill avatar May 29 '20 06:05 mbbill

Are you planning on updating it soon?

TristonStuart avatar May 29 '20 18:05 TristonStuart

maybe not very soon, but I'll try to find some time when possible

mbbill avatar May 29 '20 18:05 mbbill

Would be very nice! Thanks for your hard work!

TristonStuart avatar May 29 '20 19:05 TristonStuart