V8 JavaScript Engine on Windows (MinGW) - javascript

The build instructions of V8 JavaScript Engine mention only Visual Studio 2005 and 2008. Has anybody been successful with MinGW on Windows XP/Vista?

You just need to change Scons a bit.
Take a look at C:\YourPythonFolder\Lib\site-packages\scons-YourSconsVersion\SCons\Script__ init__.py and go to line 560.
Change the linker to gnulink, the c compiler to mingw and the c++ compiler to g++.
Eventually it should look like this:
linkers = ['gnulink', 'mslink', 'ilink', 'linkloc', 'ilink32' ]
c_compilers = ['mingw', 'msvc', 'gcc', 'intelc', 'icl', 'icc', 'cc', 'bcc32' ]
cxx_compilers = ['g++', 'msvc', 'intelc', 'icc', 'c++', 'bcc32' ]
Now MingW is activated by default :)

There is a patch for MinGW support: http://codereview.chromium.org/18309
See also:
http://code.google.com/p/v8/issues/detail?id=64

I've tried, but seems it automatically detect the WIN32 platform and tries to invoke the vc++ compiler, I tried to adding to the PATH the mingw-gcc compiler (I've not vc++ installed) and the build script correctly sees it, but doesn't compile out of the box.
I suppose deleting the "WIN32 flag" will do the work, since for successfully compiling under mingw the compiler needs to thinks to be on unix enviroment, but then even if it compiles probably it will have some problems due to the different platform.

V8 seems to use different parts of its code (especialy for the file system stuff) for different platforms.
I made a build under Cygwin which puts out a beautiful linux lib, which runs on linux but doesn't on Win. I think partwise this will be the same with MinGW if you erase the WIN32 flag!
At the moment I just can see 2 possibilities. One is simple: Use Visual Studio, it's free.
The second is very hard: write a makefile :)

Related

How can I run JavaScript in Dart?

Dart officially provides JavaScript language support through the Dart web platform but for projects not using the web platform, there's unofficial support through a project called JSParser.
Due to my unfamiliarity with the language combined with sparse documentation, I'm not sure how to use this JSParser library. The example looks like this:
import 'package:parsejs/parsejs.dart';
void main() {
new File('test.js').readAsString().then((String code) {
Program ast = parsejs(code, filename: 'test.js')
// Use the AST for something
})
}
After installing the ParseJS library, the above code compiles just fine. But how do I interact with "the AST"? The IDE's code hinting doesn't seem to help either.
Looking back on the history of this project, it seems to have exchanged hands multiple times however all seem to be missing an example of what is done with the ast object afterward.
2014 - 2017: Managed by asgerf/parsejs.dart
2019 - 2019: Managed by anuragvohraec/parsejs.dart
2020 - 2020: Forked by ELEOS-MAP/parsejs.dart
2019 - 2019: A fork from a fork by anuragvohraec/dartJSEngine
Steps I've done:
Installed flutter
Installed and configured IntelliJ to use the flutter runtime I've installed
Installed the beta Desktop support for flutter
Installed the library and try to run the example
Are these libraries too old or am I just using them wrong? How would I know? I'm on Dart 2.11
After combining a few examples, notably this GitHub project and this unit test, I can get the interpreter to work.
dependencies:
dartjsengine: ^1.0.1
jsparser: ^2.0.1
Note, this uses JSEngine().visitProgram(...) combined with the parsejs() function from JSParser.
import 'package:dartjsengine/dartjsengine.dart';
import 'package:jsparser/jsparser.dart';
main() {
JsObject myObj = JSEngine().visitProgram(parsejs('var a = "red"; var b = "blue"; print(a); b;', filename: 'ignore'));
print('${myObj?.valueOf}');
}
Outputs:
red
blue
Some major caveats:
There's no alias from print() -> console.log(...), so the example uses the undocumented print(...) (aliased from Dart I guess?)
Several language features seem to be missing, importing an existing file as-is likely to fail.

Compile C to wasm, with same settings as WasmFiddle

Looking at the following WasmFiddle, once compiled to wasm the file is 259bytes. I'm trying to from WasmFiddle move to my local environment, so i've downloaded and installed the Emscripten compiler.
Now, since the Emscripten environment adds extra features same code is 22KB.
Q: How can I compile the c code on my local machine, and keep it lean?
Even better how can I have the same output as the WasmFiddle?
You can see the sourcecode for the server-side component that WasmFiddle uses for compilation here:
https://github.com/wasdk/wasmexplorer-service/blob/master/scripts/compile.sh
It is very similar to c2wasm, which also provides a minimal output:
https://github.com/tpimh/wasm-toolchain
A couple options using Emscripten's emcc can keep your outputted wasm file lean.
Optimization:
-Oz
Only my code (removes Emscripten framework code):
-s ONLY_MY_CODE=1
These flags should bring you very close to your desired 259 bytes.

Typescript Intellisense not working when combining js files

I found the TypeScript Build tab in the properties of a typescript project. And on that tab was an interesting feature called: 'Combine JavaScript output into file: '. This seems to work like intended but it seems to mess up intellisense for some reason.
When the option to combine the js output files is on, intellisense stops working (ctrl+space doesn't do anything). But syntax highlighting, building, and refactoring still works. It does this until the option is turned off and VS has restarted.
I installed the Visual Studio 2013 Update 2 CTP 2 and removed the original typescript plugin (because it's included in the update?). Web Essentials is enabled, it doesn't crash any more with the new update, and disabling it doesn't fix the intellisense.
What is going on? How do I get this to work?
For what it's worth, this issue seems to be solved in newer versions of typescript. What version of typescript are you using?
If you can't upgrade your typescript version, does using something outside of the built in single file output work for you? If so, you should look into using grunt-ts-bundle.
grunt.initConfig({
bundle: {
main: {
rootModule: 'plat',
license: './license.txt',
version: '<%= pkg.version %>',
src: './index.html',
dest: [
'./out.ts'
],
preSave: function (data, done) {
done(data);
}
}
}
});
grunt.loadNpmTasks('grunt-ts-bundle');
This is just a grunt task for running ts-bundle:
https://github.com/Platypi/ts-bundle
Then you can wrap files in your src (`./index.html) like this:
<!-- ts-bundle-start -->
<script src="app/models/user.model.js"></script>
<script src="app/controllers/users.controller.js"></script>
<!-- ts-bundle-end -->
This would combine your user.model.js and users.controller.js file into one out.js file.
If this does work for you and you have any other questions or need clarification just let me know - Good luck!
I ran into similar issues with Typescript and VS2013 and different versions of typescript. I had stayed with older, . 95, of typescript for quite some time to avoid this issue.
I am happy to report that this issue has gone away with the most recent builds of the ts plugin.
Combine into one file, compile on save and intellisense all now work together for me.

Is there a way to use sourcemap sequentially more than 2 times? [duplicate]

Has any one had any success with this?
I think it's more or less an unsolved problem:
https://github.com/jashkenas/coffee-script/issues/2779 . Last meanigingful comment was from jwalton, a month ago.
Still, it doesn't seem rocket science to add support for it, so it will probably come soon.
Michael Ficarra (creator of CoffeeScript Redux) suggested using https://github.com/michaelficarra/commonjs-everywhere .
Two caveats:
It only works for bundling CommonJS modules.
It uses CoffeeScript Redux, which is still in beta (although working quite well it seems), and not 100% compatible with original CoffeeScript compiler.
So this does not work for what you ask for specifically, "concatenation".
Added April 14
You might have luck with these: combine-source-map and/or generate-sourcemap, both by same author.
Added April 26
This looks really simple: https://npmjs.org/package/mapcat . You just have to feed it the individual source map files generated by the coffee compiler.
Added May 16
Mariusz Nowak has just released webmake-coffee. Like CommonJS Everywhere, it requires code to be organized as CommonJS modules. Unlike CommonJS everywhere, it uses regular CoffeeScript.
It also seems the Grunt Coffee-Script plugin has had source-map support for concatenated files for quite a while (two months), effectively proving my original answer to be incorrect.
The upcoming version 2.0 of Snockets will have support for it too.
I ended up going with browserify using coffeeify as the transform option, and enabling browserify's debug option. I bundle up the app on each request for my main.js file, and any runtime errors show up in my original source with pretty decent accuracy.
Sure beats mapping runtime errors in the concatenated/compiled js back to the coffee source with my eyeballs!
I needed to annotate AngularJS code before minification, but grunt-ng-annotate didn't accept input source maps, thus I would not be able to use maps generated by the CoffeeScript compiler.
Apparently, with gulp-sourcemaps this is not an issue:
var gulp = require('gulp');
var $ = require('gulp-load-plugins')(); // loading gulp plugins lazily
// remember to include them in the package.json
gulp.task('appJS', function() {
// concatenate compiled .coffee files and js files into build/app.js
gulp.src(['./app/**/*.js','./app/**/*.coffee'])
.pipe($.sourcemaps.init())
.pipe($['if'](/[.]coffee$/, $.coffee({bare: true}).on('error', $.util.log)))
.pipe($.concat('app.js'))
.pipe($.ngAnnotate())
.pipe($.uglify())
.pipe($.sourcemaps.write())
.pipe(gulp.dest('./build'))
});
The same approach works in other situations, too. In my case, this is the only approach that worked.
I have written a grunt task that does this flawless. Check it out

Use Emscripten with Fortran: LAPACK binding

My goal is to use LAPACK with Emscripten.
My question is: how to port LAPACK to JS? The are two ways I can think of: CLAPACK to JS where my question is: does anybody know an unofficial version that is later than 3.2.1? And the other way to think of is: how to port FORTRAN to JS?
Emscripten is capable of transforming C code to JavaScript. But unfortunately, LAPACK 3.5.0 (http://www.netlib.org/lapack/) is only available in FORTRAN95.
The CLAPACK project (http://www.netlib.org/clapack/) is basically what I want: a C version of LAPACK. But this one is outdated; the latest is 3.2.1.
F2C only works up to FORTRAN 77. LAPACK 3.5.0 was written in FORTRAN 95.
So my question now is: why is there no newer port of LAPACK to C?
The optimal way would be to directly transform the FORTRAN95 code of LAPACK to javascript with clang and emscripten. But I just don't know where to start.
Emscripten currently does not support FORTRAN. But it handles LLVM bitcode, so it should not be a problem to use clang to generate LLVM bc from a FORTRAN file.
For testing purpose, I have this file:
program hello
print *, "Hello World!"
end program hello
It compiles just fine with "clang hello.f -o hello -lgfortran". I am not capable of transforming this into valid bitcode.
clang -c -emit-llvm hello.f
clang -S -emit-llvm hello.f -o hello.bc -lgfortran
None of these approaches works, because emscripten keeps telling me
emcc -c hello.o -o hello.js
hello.o is not valid LLVM bitcode
I am not sure anyways if this would be even possible, because LAPACK obviously needs libgfortran to work. And I can't merge a library into javascript code...
Thanks in advance!
Edit:
I almost managed it to convert BLAS from LAPACK 3.5.0 to JS. I used dragonegg to accomplish this.
gfortran caxpy.f -flto -S -fplugin=/usr/lib/gcc/x86_64-linux-gnu/4.6/plugin/dragonegg.so
gfortran cgerc.f ...
...
After gaining LLVM bitcode from that:
emcc caxpy.s.ll cgerc.s.ll cher.s.ll ... -o blas.js -s EXPORTED_FUNCTIONS="['_caxpy_', ... , '_ztpsv_']"
But emscripten still leaves me with the following errors:
warning: unresolved symbol: _gfortran_st_write
warning: unresolved symbol: _gfortran_string_len_trim
warning: unresolved symbol: _gfortran_transfer_character_write
warning: unresolved symbol: _gfortran_transfer_integer_write
warning: unresolved symbol: _gfortran_st_write_done
warning: unresolved symbol: _gfortran_stop_string
warning: unresolved symbol: cabs
warning: unresolved symbol: cabsf
AssertionError: Did not receive forwarded data in an output - process failed?
The problem is that lgfortran is precompiled I think.
Thank you for your reply!
Indeed I did make progress on this. Finally it is working. I was very close, just follow these steps:
gfortran caxpy.f -S -flto -m32 -fplugin=dragonegg.so
mv caxpy.s caxpy.ll
llvm-as caxpy.ll -o caxpy.o
Note the "m32" flag which I missed earlier.
Warnings like
warning: unresolved symbol: _gfortran_st_write
can be ignored safely. Emscripten creates empty functions in the JavaScript file with this name so if these functions are not called at all there is no problem. If they get called you can easily substitute them with your own functions; the names are somewhat descriptive. Additionally you can have a look at the libgfortran source code (be aware it is GPL).
With this Emscripten source can be extended by hand to support Fortran files. Someday I may publish this on github!
I actually pulled this off recently (https://github.com/harveywi/arpack-js). The Github repo is mostly barren except for the output JS files, but I will be uploading source code, Makefiles, and other instructions soon. After wrangling unsuccessfully with dragonegg for a while, I found a different approach (not as great, but sufficient) which did the trick.
Here is roughly how I did it:
Download the ARPACK source code.
Run f2c on all of the Fortran files to convert them to C.
(This might be the trickiest part): Modify the Makefiles to use Emscripten and LLVM toolchains.
Make the project to produce an LLVM binary.
Use Emscripten again to transpile the LLVM binary to JS.

Categories