Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different results from JSC_Eval to JSC_Eval_Bytecode #15

Open
TristonStuart opened this issue May 28, 2020 · 10 comments
Open

Different results from JSC_Eval to JSC_Eval_Bytecode #15

TristonStuart opened this issue May 28, 2020 · 10 comments

Comments

@TristonStuart
Copy link

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.

@mbbill
Copy link
Owner

mbbill commented May 28, 2020

#10 (comment)

@TristonStuart
Copy link
Author

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.

@mbbill
Copy link
Owner

mbbill commented May 28, 2020

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.

@TristonStuart
Copy link
Author

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

@mbbill
Copy link
Owner

mbbill commented May 28, 2020

unless I do another update and try again.

@TristonStuart
Copy link
Author

ah is that hard to do?

@mbbill
Copy link
Owner

mbbill commented May 29, 2020

not hard, just takes time

@TristonStuart
Copy link
Author

Are you planning on updating it soon?

@mbbill
Copy link
Owner

mbbill commented May 29, 2020

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

@TristonStuart
Copy link
Author

Would be very nice! Thanks for your hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants