Hedgehog-Computing / hedgehog-lab

Run, compile and execute JavaScript for Scientific Computing and Data Visualization TOTALLY TOTALLY TOTALLY in your BROWSER! An open source scientific computing environment for JavaScript TOTALLY in your browser, matrix operations with GPU acceleration, TeX support, data visualization and symbolic computation.
https://hlab.app
Apache License 2.0
2.36k stars 142 forks source link

Extract Hedgehog Runtime (transpiler, internal classes Mat and Sym, math and linear algebra functions, preprocessor) as a separate JavaScript runtime & package #41

Open lidangzzz opened 4 years ago

promer94 commented 4 years ago

I have made my attempt at https://github.com/promer94/hedgehog-lab-core

install

npm i hedgehog-lab-core-test babel-template

And use it at my fork

promer94 commented 4 years ago

currently, i can't make babel-template being compiled correctly. But if it works, we can write web workers like this.

importScripts("https://unpkg.com/comlink/dist/umd/comlink.js");
importScripts("https://unpkg.com/core/dist/umd/core.js");
const compiler = {
  compile(source) {
    return core.compile(source)
  },
};
Comlink.expose(obj)

you can just use it without installing it and using worker-loader in your webpack

promer94 commented 4 years ago

@lidangzzz can you upgrade babel-template to @babel/template, because i can't compile babel-template correctly but @babel/template works well. Upgrading to @babel/template will break current operator-overload.js because

path.node.hasOwnProperty('_fromTemplate')

is always false, so recursion will not stop.

And i found a operator-overload-plugin might help you to rewrite the current code

lidangzzz commented 4 years ago

Hi @promer94 ,

I will try to upgrade babel template later, could you explain a little bit more about what's the compiling error? Also my implementation of operator overload is TOTALLY different from Rob's implementation( https://github.com/rob-blackbourn/babel-operator-overload-plugin ). Here are all scenarios that we need to consider:

Mat_object [op] Mat_object

Mat_object [op] scalar

Mat_object [op] 1D/2D_array_of_number

number [op] Mat_object

1D/2D Array of number [op] Mat_object

Sym_object [op] scalar

scalar [op] Sym_object

Sym_object [op] Sym_object

So when we are trying to implement a Babel plugin, it's NOT an operator overload of ClassFoo [op] ClassFoo. Instead it should always cover all possible combination above.

Here is a reference: https://zhuanlan.zhihu.com/p/159128811