Binding external functions using the classic syntax
We can also bind external functions with the classic
syntax. The classic
syntax is a little different from the jsdoc
syntax. It uses ##
to register functions. A typical registration body is as follows:
##register function_name: function_type ##args(argment_list) { //function body }
In classic
syntax, test2.js
will contain the following code:
##opa-type Student ##opa-type list('a) ##extern-type llarray('a) ##register func1: opa[Student] -> void ##args(stu) { console.log("func1: "+ stu.name +" , "+stu.sex+", "+stu.age); } ##register func2: opa[list(string)] -> void ##args(lst) { var lst2 = list2js(lst); for(var i=0; i<lst2.length; i++) console.log("func2: " + lst2[i]); } ##register func3: llarray(int) -> void ##args(arr) { for(var i=0; i<arr.length; i++) console.log("func3: " + arr[i]); }
We can now compile the rewritten file using the following command:
opa test2.js 601.opa --js-bypass...