-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first class js object support so people can create js object
- Loading branch information
Hongbo Zhang
committed
Aug 9, 2016
1 parent
29bc22b
commit b97930c
Showing
15 changed files
with
250 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
var Mt = require("./mt"); | ||
var Block = require("../../lib/js/block"); | ||
|
||
var suites = [/* [] */0]; | ||
|
||
var test_id = [0]; | ||
|
||
function eq(loc, param) { | ||
var y = param[1]; | ||
var x = param[0]; | ||
test_id[0] = test_id[0] + 1 | 0; | ||
suites[0] = /* :: */[ | ||
/* tuple */[ | ||
loc + (" id " + test_id[0]), | ||
function () { | ||
return /* Eq */Block.__(0, [ | ||
x, | ||
y | ||
]); | ||
} | ||
], | ||
suites[0] | ||
]; | ||
return /* () */0; | ||
} | ||
|
||
var v = { | ||
x: function () { | ||
return 3; | ||
}, | ||
say: function (x) { | ||
var self = this ; | ||
return x * self.x(); | ||
}, | ||
hi: function (x, y) { | ||
var self = this ; | ||
return self.say(x) + y; | ||
} | ||
}; | ||
|
||
eq('File "ppx_this_obj.ml", line 25, characters 5-12', /* tuple */[ | ||
11, | ||
v.hi(3, 2) | ||
]); | ||
|
||
Mt.from_pair_suites("ppx_this_obj.ml", suites[0]); | ||
|
||
exports.suites = suites; | ||
exports.test_id = test_id; | ||
exports.eq = eq; | ||
exports.v = v; | ||
/* v Not a pure module */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
let suites : Mt.pair_suites ref = ref [] | ||
let test_id = ref 0 | ||
let eq loc (x, y) = | ||
incr test_id ; | ||
suites := | ||
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites | ||
|
||
let v = | ||
let x = 3. in | ||
object (self) | ||
method x () = x | ||
method say x = x *. self## x () | ||
method hi x y = self##say x +. y | ||
end [@bs] | ||
(** compile infer | ||
class type js_obj = object | ||
method x : unit -> float | ||
method say : float -> float | ||
method hi : float -> float -> float | ||
end [@bs] | ||
val js_obj : js_obj Js.t | ||
*) | ||
|
||
let () = | ||
eq __LOC__ (11., v##hi 3. 2.) | ||
|
||
let () = Mt.from_pair_suites __FILE__ !suites |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters