How do I use the results of WP in another plug-in? - ocaml

I am working on writing a Frama-C plug-in and I would like to know if it is possible to get the weakest precondition of something using WP from within my plug-in, and if so, how exactly? In the past I've used Db.Value, for example, to use the results of the EVA plug-in in my own plug-in. Is there something similar to Db.Value for WP?

The WP plugin exposes its API in the WP.mli file, that is generated by collecting the interfaces of the higher-level modules composing Wp. you can find it in src/plugins/wp/Wp.mli.
However, you should be aware that this API should not be considered stable, and non-backward compatible changes may be introduced in newer Frama-C versions.

Related

How can I use CommonJS modules with Oracle's new Nashorn JS Engine?

I'm looking for a module system for Nashorn. From what I can tell, CommonJS is the way to go concerning modules for JS. I have looked through the list (here and here) and have found little in the way of a CommonJS implementation for Java.
Narwhal is no longer active and it's documentation is no longer hosted on GitHub. Is there an existing CommonJS implementation which supports Java or should I start a new project?
Have a look at jvm-npm here https://github.com/nodyn/jvm-npm. This project is used by nodyn as the CommonJS module system. It is NPM-aware, meaning you can load modules directly from NPM, but it does not provide any of the Node.js API.
Here is a simple example usage:
$ npm install pegjs
npm http GET https://registry.npmjs.org/pegjs
npm http 200 https://registry.npmjs.org/pegjs
pegjs#0.8.0 node_modules/pegjs
$ jrunscript
nashorn> typeof require
undefined
nashorn> load('./jvm-npm.js')
nashorn> typeof require
function
nashorn> var PEG = require('pegjs');
nashorn> typeof PEG
object
It is primarily all Javascript, but the actual loading of files from the filesystem and such is done using Java.
I asked a very similar question on the Nashorn mailing list a little while back, here's Sundar's (Nashorn Engineer) reply:
From: A. Sundararaj​an
To: nashorn-dev#openjdk.java.net
I forgot to add. Nashorn does not contain any builtin module system.
But, if a module system is pure JS + Java, it must be possible to run
on nashorn.
Nashorn supports "load" (loads scripts from URL, File, resources) and
"loadWithNewGlobal" (loads script but into a fresh global scope)
primitives in addition to the good old 'eval'. So, it should be
possible for any module system to be implemented on top of nashorn in
pure JS or perhaps with a bit of Java code.
-Sundar
I've been looking for such an implementation for a while. I've been using a little patched version of Rhino-Require. Although Rhino claimed to be CommonJS compatible, AFAIK, it implemented only modules and not packages (package.json) can't be parsed.
RingoJS should be compatible. But Nashorn will never be see.
Laterly, Oracle announced project Avatar which relies on Avatar.js or here. It's the official project of what was unofficially called Node.jar. But as of now, you have to compile it by yourself. The project is very young.
Another very young project is Nodyn which relies on dyn.js.
So, if understood well, CommonJs should work with avatar-js and nodyn, but those two are still pretty young. I don't understand why avatar-js in not fully distributed along with nashorn though.
A kind of solution would be to add a CommonJS compatibility script like the one for Rhino which adds importClass/importPackage (mozilla_compat.js) which would add CommonJS compatibility into nashorn, kind of Rhino-Require shim thoroughly tested.
I had the same need, and I used jvm-npm for a while, but I needed something that would work even without allowing usage of Java packages inside JavaScript, so I wrote my own version here: https://github.com/coveo/nashorn-commonjs-modules
It's implemented entirely in Java and supports loading modules from elsewhere than the filesystem (Java resources, a custom database, etc.)
It's published on Maven Central if someone wants to use it.
There's also nashorn-require, you can get that off of github too. I've used it, I was able to do
engine.eval(reader("src/main/javascript/nashorn-require.js"),bindings);
engine.eval("var initRequire = load('src/main/javascript/nashorn-require.js');",bindings);
engine.eval("initRequire({mainFile : 'src/main/javascript/foo', debug : true})", bindings);
engine.eval("var babel = require('babel');",bindings);
and then transpile JSX React components to ES5 with
Buffer input = findTemplateSource(fileLocation,context);
bindings.put("input",input.toString());
result = engine.eval("babel.transform(input,{ presets: ['react', 'es2015'] }).code;",bindings);
Then when I pulled react and react-dom into my browser and loaded the resulting js components, things worked fine, so I'm sure Babel was perfectly happy, though I'm not sure about if it will find 3rd-party plugins or not...

How can I simply test the XPCOM component in the latest firefox?

In the latest firefox, I found that, when you try to use the following code in web console:
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
[10:33:00.787] Use of enablePrivilege is deprecated.
Please use code that runs with the system principal (e.g. an extension) instead.
For the firefox 3.6, I always use this way to simply test some of my XPCOM components, it's very convenient. But in the latest firefox, I found that i cannot be used anymore.
So If currently I have written a C++ XPCOM component, is there a simple way that I can try to test it besides having to write and register another test component?
Of course, any suggestion is very appreciated.
Binary (C++) XPCOM usage is very heavily discouraged (or to put it more firmly, DEAD DEAD DEAD) in recent Firefox builds:
http://adblockplus.org/blog/binary-xpcom-components-are-dead-js-ctypes-is-the-way-to-go
http://starkravingfinkle.org/blog/2011/07/add-ons-binary-components-and-js-ctypes/
http://hackademix.net/2011/07/14/killing-binary-xpcom-in-add-ons-is-javascript-fit/
MDN specifies alternatives for getting binary XPCOM components, although I don't know if any are an improvement for your scenario:
https://developer.mozilla.org/En/Firefox_addons_developer_guide/Using_XPCOM—Implementing_advanced_processes
Formerly binary components should now use js-ctypes:
https://developer.mozilla.org/en/js-ctypes

OpenCv and Ruby on Rails

Can I use OpenCV with Ruby on Rails? If so, how can I do that? Or, what resources do you recommend for that?
Thanks.
There is also an open CV gem, fwiw -- https://github.com/ruby-opencv/ruby-opencv.
Sure you can!
It just depends on what do you need as there is no "one" silver bullet.
If you want to create an online home surveillance, for example, then you would probably have least effort by writing:
C++ image-processing command-line application on top of OpenCV that would write the surveillance events and/or images to SQLite database.
Read the database directly from Rails.
For anything more complex, you'd need a more complex architecture.
Whatever you do, pick the best tools for the purpose:
Let OpenCV do what it is best at (image processing)
Let Rails to it's magic (simple, less demanding online access to some resources)
In order to link OpenCV and Ruby together, you could create a dedicated Ruby-to-C++ bridge because none of the existing ones can match diverse needs and most frameworks will do for a few specialized (i.e. designed by you) function-calls through your bridge.
This link would be a good start to pick a framework for a bridge - just go for one and see what comes out.
You could write a program using OpenCV in C++, and then just process your data with it, by using CGI (Common Gateway Interface http://en.wikipedia.org/wiki/Common_Gateway_Interface). I don't think you can bind native code to Ruby like you can do in Java (JNI)

How does node.js/[my own library/plugin] run on v8?

Does it use any libraries like this:
http://code.google.com/p/v8-juice
http://ui.ajax.org/#o3
https://github.com/tsa/vu8
Or has it written its own libraries? If v8 is written for executing javascript, why do node.js libraries use C code? Just for the filesystem/event stuff? If so, why was that necessary, doesn't v8 need events and filesystem stuff itself?
If I want to work with a database that only supports a C api, how would I go about doing that? Right now I'd probably write a v8-juice plugin.
node.js includes its own embedded version of v8 (not sure if it is customized or not, but it could be).
Javascript itself provides no interface to things like file system I/O, so that you as the embedder (in this case node) have to provide native code objects to expose that functionality. The browser does the same thing for DOM and network features, by the way.
If I want to work with a database that only supports a C api, how would I go about doing that?
You'd need a node.js extension for this (a native code plugin). If you are lucky, someone has already made on for your database system, if not, look at the source code for a similar extension as to how those are written. And here is an introduction article. You'd need to be familiar with writing a v8 extension, because that is what a node extension basically is.
If you are talking to the database over a network connection, and feel like implementing the wire protocol yourself, you could also try to do that in pure Javascript, like someone did for MySQL.

Controlling Firefox from C/C++

I'm thinking of creating an application that can use Firefox as a download manager. Is there any way to control Firefox (add downloads, start/stop downloads, etc) from an external program in C/C++?
If that is not possible, then perhaps an extension that can do that? If an extension is the only way, then how do I communicate with the extension from outside of Firefox?
You're starting with a solution, not a problem. The easier idea is to use XulRunner, the platform on which FireFox is built. You'd effectively implement your own application as a XulRunner plugin and use Necko (the network layer of XulRunner and FireFox) from there.
First of all I suggest that you familiarize yourself with developer.mozilla.org
As far as I understand, most Mozilla platform functions are available through a cross language API known as XPCOM. There's also a plugin API but it's primary aim is to visualize stuff (used by Flash, etc.).
Take a look at Gecko API. It allows third party developers to use the same technology as found in Mozilla.
For downloading files no need to use Firefox. Consider using libcurl.
Take a look at wget.