Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ let dfinity-repo = import (builtins.fetchGit {
rev = "ab9d9d6ccba33748fc92f6e8d631327f7f25aead";
}) { system = nixpkgs.system; }; in

let sdk = import (builtins.fetchGit {
url = "ssh://git@github.com/dfinity-lab/sdk";
ref = "paulyoung/ts-user-library";
rev = "42f15621bc5b228c7fd349cb52f265917d33a3a0";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to update this before merging. Will be able to point to master soon.

}) { system = nixpkgs.system; }; in

let esm = builtins.fetchTarball {
sha256 = "116k10q9v0yzpng9bgdx3xrjm2kppma2db62mnbilbi66dvrvz9q";
url = "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz";
}; in

let real-dvm =
if dvm == null
then dev.dvm
Expand All @@ -46,8 +57,7 @@ let real-drun =
then dfinity-repo.dfinity.drun
else drun; in

# Include js-client
let js-client = dev.js-dfinity-client; in
let js-user-library = sdk.js-user-library; in

let haskellPackages = nixpkgs.haskellPackages.override {
overrides = self: super: {
Expand Down Expand Up @@ -269,11 +279,12 @@ rec {
nixpkgs.getconf
nixpkgs.nodejs-10_x
filecheck
js-client
js-user-library
dvm
drun
qc-actorscript
lsp-int
esm
] ++
llvmBuildInputs;

Expand All @@ -283,7 +294,8 @@ rec {
export ASC=asc
export AS_LD=as-ld
export DIDC=didc
export JSCLIENT=${js-client}
export ESM=${esm}
export JS_USER_LIBRARY=${js-user-library}
asc --version
make parallel
qc-actorscript${nixpkgs.lib.optionalString (replay != 0)
Expand Down Expand Up @@ -552,8 +564,9 @@ rec {
));

shellHook = llvmEnv;
ESM=esm;
JS_USER_LIBRARY=js-user-library;
TOMMATHSRC = libtommath;
JSCLIENT = js-client;
NIX_FONTCONFIG_FILE = users-guide.NIX_FONTCONFIG_FILE;
} else null;

Expand Down
41 changes: 27 additions & 14 deletions src/idllib/compile_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let rec pp_typ ppf t =
| OptT t -> str ppf "IDL.Opt("; pp_typ ppf t; str ppf ")";
| VariantT ts -> str ppf "IDL.Variant({"; concat ppf pp_field "," ts; str ppf "})";
| FuncT (ms, t1, t2) ->
str ppf "IDL.Message(";
str ppf "IDL.Func(";
pp_fields ppf t1;
kwd ppf ",";
pp_fields ppf t2;
Expand Down Expand Up @@ -169,28 +169,40 @@ let pp_rec ppf x =
pp_close_box ppf ();
pp_print_cut ppf ()

let pp_actor ppf actor =
let pp_actor ppf actor recs =
pp_open_hovbox ppf 1;
kwd ppf "const";
(match actor.it with
| ActorD (x, t) ->
let x = ("actor_" ^ x.it) @@ x.at in
match t.it with
| ServT tp ->
id ppf x; space ppf (); kwd ppf "="; kwd ppf "new";
str ppf "IDL.ActorInterface({";
concat ppf pp_meth "," tp;
str ppf "})"
| VarT var -> id ppf x; space ppf (); kwd ppf "="; id ppf var
| _ -> assert false
(match t.it with
| ServT tp ->
id ppf x; space ppf (); kwd ppf "="; kwd ppf "new";
str ppf "IDL.ActorInterface({";
concat ppf pp_meth "," tp;
str ppf "});"
| VarT var ->
id ppf x; space ppf (); kwd ppf "=";
if TS.mem var.it recs then
str ppf (var.it ^ ".__typ;")
else
str ppf var.it;
| _ -> assert false
);
pp_force_newline ppf ();
kwd ppf "return"; id ppf x; str ppf ";"
);
pp_close_box ppf ()

let pp_header ppf () =
pp_open_vbox ppf 0;
str ppf "const IDL = require('IDL')";
str ppf "export default ({ IDL }) => {";
pp_close_box ppf ()


let pp_footer ppf () =
pp_force_newline ppf ();
pp_print_string ppf "};"

let pp_prog ppf env prog =
match prog.it.actor with
| None -> ()
Expand All @@ -205,8 +217,9 @@ let pp_prog ppf env prog =
pp_open_vbox ppf 0;
TS.iter (pp_rec ppf) recs;
List.iter (pp_dec ppf) env_list;
pp_actor ppf actor;
pp_close_box ppf ()
pp_actor ppf actor recs;
pp_close_box ppf ();
pp_footer ppf ()

let compile (scope : Typing.scope) (prog : Syntax.prog) =
let buf = Buffer.create 100 in
Expand Down
12 changes: 7 additions & 5 deletions test/idl/ok/actor.js.ok
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const o = IDL.Rec()
const f = IDL.Message(IDL.Obj({'0': IDL.Int8}), IDL.Obj({'0': IDL.Int8}))
const h = IDL.Message(IDL.Obj({'0': f}), IDL.Obj({'0': f}))
const f = IDL.Func(IDL.Obj({'0': IDL.Int8}), IDL.Obj({'0': IDL.Int8}))
const h = IDL.Func(IDL.Obj({'0': f}), IDL.Obj({'0': f}))
const g = f
o.fill(IDL.Opt(o))
const actor_g = new IDL.ActorInterface({
'f': IDL.Message(IDL.Obj({'0': IDL.Nat}), IDL.Obj({'0': h})), 'g': f,
'h': g, 'o': IDL.Message(IDL.Obj({'0': o}), IDL.Obj({'0': o}))})
'f': IDL.Func(IDL.Obj({'0': IDL.Nat}), IDL.Obj({'0': h})), 'g': f, 'h': g,
'o': IDL.Func(IDL.Obj({'0': o}), IDL.Obj({'0': o}))});
return actor_g;
};
8 changes: 5 additions & 3 deletions test/idl/ok/cyclic.js.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const A = IDL.Rec()
const C = A
const B = IDL.Opt(C)
Expand All @@ -8,5 +8,7 @@ const Y = Z
const X = Y
const actor_S = new IDL.ActorInterface({
'f':
IDL.Message(IDL.Obj({'0': A, '1': B, '2': C, '3': X, '4': Y, '5': Z}),
IDL.Obj({}))})
IDL.Func(IDL.Obj({'0': A, '1': B, '2': C, '3': X, '4': Y, '5': Z}),
IDL.Obj({}))});
return actor_S;
};
7 changes: 5 additions & 2 deletions test/idl/ok/diamond.js.ok
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const t = IDL.Nat
const t2 = IDL.Arr(t)
const t3 = IDL.Opt(t)
const t1 = IDL.Obj({'0': t2, '1': t3, '2': t})
const actor_S = new IDL.ActorInterface({
'f': IDL.Message(IDL.Obj({'0': t, '1': t2, '2': t3}), IDL.Obj({'0': t1}))})
'f': IDL.Func(IDL.Obj({'0': t, '1': t2, '2': t3}), IDL.Obj({'0': t1}))});

return actor_S;
};
8 changes: 5 additions & 3 deletions test/idl/ok/fields.js.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const A = IDL.Obj({'0': IDL.Nat, '1': IDL.Nat, '2': IDL.Nat})
const B =
IDL.Obj({'0': IDL.Arr(IDL.Nat8), '35': IDL.Arr(IDL.Nat8), '36': IDL.Nat,
Expand All @@ -15,5 +15,7 @@ const nest_record =
'5': IDL.Nat, '6': IDL.Nat, '7': A, '8': B, '9': C, '10': IDL.Nat})
const actor_S = new IDL.ActorInterface({
'f':
IDL.Message(IDL.Obj({'0': A, '1': B, '2': C, '3': nest_record}),
IDL.Obj({}))})
IDL.Func(IDL.Obj({'0': A, '1': B, '2': C, '3': nest_record}), IDL.Obj({}))
});
return actor_S;
};
9 changes: 6 additions & 3 deletions test/idl/ok/import.js.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const t = IDL.Arr(IDL.Nat8)
const t1 = t
const UserId = IDL.Nat
Expand All @@ -13,7 +13,10 @@ const IdErr = IDL.Obj({'idErr': OpEntId})
const Inventory = IDL.Obj({'produce_id': IDL.Nat, 'quantity': IDL.Nat})
const actor_S = new IDL.ActorInterface({
'f':
IDL.Message(IDL.Obj({'0': t, '1': t1, '2': t2}),
IDL.Func(IDL.Obj({'0': t, '1': t1, '2': t2}),
IDL.Obj({'0': list, '1': IdErr})),
'getInventory':
IDL.Message(IDL.Obj({'producer_id': IDL.Nat}), IDL.Obj({'0': Inventory}))})
IDL.Func(IDL.Obj({'producer_id': IDL.Nat}), IDL.Obj({'0': Inventory}))});

return actor_S;
};
6 changes: 4 additions & 2 deletions test/idl/ok/import1.js.ok
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const t = IDL.Arr(IDL.Nat8)
const t1 = t
const UserId = IDL.Nat
const t2 = UserId
const actor_S = new IDL.ActorInterface({
'f': IDL.Message(IDL.Obj({'0': t, '1': t1, '2': t2}), IDL.Obj({}))})
'f': IDL.Func(IDL.Obj({'0': t, '1': t1, '2': t2}), IDL.Obj({}))});
return actor_S;
};
14 changes: 8 additions & 6 deletions test/idl/ok/import3.js.ok
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const B = IDL.Rec()
const list = IDL.Rec()
const s = IDL.Rec()
const stream = IDL.Rec()
const tree = IDL.Rec()
const t = IDL.Message(IDL.Obj({'server': s}), IDL.Obj({}))
const t = IDL.Func(IDL.Obj({'server': s}), IDL.Obj({}))
const node = IDL.Obj({'head': IDL.Nat, 'tail': list})
list.fill(IDL.Opt(node))
stream.fill(
IDL.Opt(
IDL.Obj({'head': IDL.Nat,
'next': IDL.Message(IDL.Obj({}), IDL.Obj({'0': stream}))}))
'next': IDL.Func(IDL.Obj({}), IDL.Obj({'0': stream}))}))
)
tree.fill(
IDL.Variant({
Expand All @@ -21,6 +21,8 @@ B.fill(IDL.Opt(A))
s.fill(
new IDL.ActorInterface({'f': t,
'g':
IDL.Message(IDL.Obj({'0': list}),
IDL.Obj({'2': stream, '1': tree, '0': B}))}))
const actor_S = s
IDL.Func(IDL.Obj({'0': list}), IDL.Obj({'2': stream, '1': tree, '0': B}))
}))
const actor_S = s.__typ;
return actor_S;
};
10 changes: 6 additions & 4 deletions test/idl/ok/integer.js.ok
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const actor_num = new IDL.ActorInterface({
'f': IDL.Message(IDL.Obj({'0': IDL.Nat8}), IDL.Obj({'0': IDL.Int16})),
'g': IDL.Message(IDL.Obj({'0': IDL.Nat64}), IDL.Obj({'0': IDL.Int64})),
'h': IDL.Message(IDL.Obj({'0': IDL.Int8}), IDL.Obj({'0': IDL.Nat}))})
'f': IDL.Func(IDL.Obj({'0': IDL.Nat8}), IDL.Obj({'0': IDL.Int16})),
'g': IDL.Func(IDL.Obj({'0': IDL.Nat64}), IDL.Obj({'0': IDL.Int64})),
'h': IDL.Func(IDL.Obj({'0': IDL.Int8}), IDL.Obj({'0': IDL.Nat}))});
return actor_num;
};
8 changes: 5 additions & 3 deletions test/idl/ok/px.js.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const UserId = IDL.Nat
const RegionId = IDL.Nat
const ProducerId = IDL.Nat
Expand All @@ -14,5 +14,7 @@ const OpEntId = IDL.Opt(EntId)
const IdErr = IDL.Obj({'idErr': OpEntId})
const actor_ProduceExchange = new IDL.ActorInterface({
'getInventory':
IDL.Message(IDL.Obj({'producer_id': IDL.Nat, '3667444713': UserInfo}),
IDL.Obj({'0': Inventory, '1': IdErr}))})
IDL.Func(IDL.Obj({'producer_id': IDL.Nat, '3667444713': UserInfo}),
IDL.Obj({'0': Inventory, '1': IdErr}))});
return actor_ProduceExchange;
};
14 changes: 8 additions & 6 deletions test/idl/ok/recursion.js.ok
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const B = IDL.Rec()
const list = IDL.Rec()
const s = IDL.Rec()
const stream = IDL.Rec()
const tree = IDL.Rec()
const t = IDL.Message(IDL.Obj({'server': s}), IDL.Obj({}))
const t = IDL.Func(IDL.Obj({'server': s}), IDL.Obj({}))
const node = IDL.Obj({'head': IDL.Nat, 'tail': list})
list.fill(IDL.Opt(node))
stream.fill(
IDL.Opt(
IDL.Obj({'head': IDL.Nat,
'next': IDL.Message(IDL.Obj({}), IDL.Obj({'0': stream}))}))
'next': IDL.Func(IDL.Obj({}), IDL.Obj({'0': stream}))}))
)
tree.fill(
IDL.Variant({
Expand All @@ -21,6 +21,8 @@ B.fill(IDL.Opt(A))
s.fill(
new IDL.ActorInterface({'f': t,
'g':
IDL.Message(IDL.Obj({'0': list}),
IDL.Obj({'2': stream, '1': tree, '0': B}))}))
const actor_A = s
IDL.Func(IDL.Obj({'0': list}), IDL.Obj({'2': stream, '1': tree, '0': B}))
}))
const actor_A = s.__typ;
return actor_A;
};
21 changes: 11 additions & 10 deletions test/idl/ok/test.js.ok
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const my_type = IDL.Nat
const B = my_type
const message = IDL.Obj({'25': B, '26': IDL.None, 'name': IDL.Text})
const broker =
new IDL.ActorInterface({
'find':
IDL.Message(IDL.Obj({'name': IDL.Text}),
IDL.Func(IDL.Obj({'name': IDL.Text}),
IDL.Obj({
'0':
new IDL.ActorInterface({'up': IDL.Message(IDL.Obj({}), IDL.Obj({})),
'current': IDL.Message(IDL.Obj({}), IDL.Obj({'0': IDL.Nat}))})
new IDL.ActorInterface({'up': IDL.Func(IDL.Obj({}), IDL.Obj({})),
'current': IDL.Func(IDL.Obj({}), IDL.Obj({'0': IDL.Nat}))})
}))
})
const actor_server = new IDL.ActorInterface({
'addUser':
IDL.Message(IDL.Obj({'name': IDL.Text, 'age': IDL.Nat8}),
IDL.Func(IDL.Obj({'name': IDL.Text, 'age': IDL.Nat8}),
IDL.Obj({'id': IDL.Nat64})),
'userName':
IDL.Message(IDL.Obj({'id': IDL.Nat64}), IDL.Obj({'0': IDL.Text})),
'userAge': IDL.Message(IDL.Obj({'id': IDL.Nat64}), IDL.Obj({'0': IDL.Nat8})),
'deleteUser': IDL.Message(IDL.Obj({'id': IDL.Nat64}), IDL.Obj({})),
'f': IDL.Message(IDL.Obj({'0': message}), IDL.Obj({'0': broker}))})
'userName': IDL.Func(IDL.Obj({'id': IDL.Nat64}), IDL.Obj({'0': IDL.Text})),
'userAge': IDL.Func(IDL.Obj({'id': IDL.Nat64}), IDL.Obj({'0': IDL.Nat8})),
'deleteUser': IDL.Func(IDL.Obj({'id': IDL.Nat64}), IDL.Obj({})),
'f': IDL.Func(IDL.Obj({'0': message}), IDL.Obj({'0': broker}))});
return actor_server;
};
12 changes: 7 additions & 5 deletions test/idl/ok/unicode.js.ok
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const IDL = require('IDL')
export default ({ IDL }) => {
const A =
IDL.Obj({'': IDL.Nat, '📦🍦': IDL.Nat, '字段名': IDL.Nat,
'字 段 名2': IDL.Nat})
const B =
IDL.Variant({'': IDL.Unit, '空的': IDL.Unit, ' 空的 ': IDL.Unit,
'1⃣️2⃣️3⃣️': IDL.Unit})
const actor_C = new IDL.ActorInterface({
'函数名': IDL.Message(IDL.Obj({'0': A}), IDL.Obj({'0': B})),
'': IDL.Message(IDL.Obj({'0': IDL.Nat}), IDL.Obj({'0': IDL.Nat})),
'👀': IDL.Message(IDL.Obj({'0': IDL.Nat}), IDL.Obj({'0': IDL.Nat})),
'✈️ 🚗 ⛱️ ': IDL.Message(IDL.Obj({}), IDL.Obj({}))})
'函数名': IDL.Func(IDL.Obj({'0': A}), IDL.Obj({'0': B})),
'': IDL.Func(IDL.Obj({'0': IDL.Nat}), IDL.Obj({'0': IDL.Nat})),
'👀': IDL.Func(IDL.Obj({'0': IDL.Nat}), IDL.Obj({'0': IDL.Nat})),
'✈️ 🚗 ⛱️ ': IDL.Func(IDL.Obj({}), IDL.Obj({}))});
return actor_C;
};
Loading