gpujs / gpu.js

GPU Accelerated JavaScript
https://gpu.rocks
MIT License
15.11k stars 655 forks source link

Handle WithStatement for kernels #804

Open emptyflash opened 1 year ago

emptyflash commented 1 year ago

A GIF or MEME to give some spice of the internet

What is wrong?

When using a javascript with statement, you get Error: unhandled type "WithStatement"

Error: unhandled type "WithStatement"
    at FunctionTracer.scan (gpu-browser.js:8658:15)
    at FunctionTracer.scan (gpu-browser.js:8481:14)
    at gpu-browser.js:8493:16
    at FunctionTracer.newContext (gpu-browser.js:8433:5)
    at FunctionTracer.scan (gpu-browser.js:8492:14)
    at FunctionTracer.scan (gpu-browser.js:8555:16)
    at new FunctionTracer (gpu-browser.js:8392:10)
    at WebGL2FunctionNode.traceFunctionAST (gpu-browser.js:7182:79)
    at WebGL2FunctionNode.getJsAST (gpu-browser.js:7172:10)
    at WebGL2FunctionNode.toString (gpu-browser.js:7281:48)

Where does it happen?

Pretty much any system, just missing functionality

How do we replicate the issue?

const { GPU } = require('gpu.js');
const gpu = new GPU();
const calcCircle = gpu.createKernel(function(r) {
    with (Math) {
      a = PI * r * r;
      x = r * cos(PI);
      y = r * sin(PI / 2);
    }
}).setOutput([512, 512]);

const c = calcCircle(a, b);

How important is this (1-5)?

2-3

Expected behavior (i.e. solution)

It should update the scope to be able to look up variables in the Math namespace.

Other Comments

Mostly just a nice to have, might tackle this issue if I have some free time