Skip to content

Commit 44f3714

Browse files
authored
Merge pull request #1107 from bloomberg/prepend_data_ffi
allow prepend int/string in positions
2 parents 573ca46 + 3bd1478 commit 44f3714

29 files changed

+7953
-6923
lines changed

docs/Manual.html

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,14 @@ <h1><a href="https://github.com/bloomberg/bucklescript">BuckleScript</a> User Ma
541541
</ul>
542542
</li>
543543
<li><a href="#_splice_calling_convention_bs_splice">Splice calling convention: bs.splice</a></li>
544-
<li><a href="#_special_types_on_external_declarations_bs_string_bs_int_bs_ignore">Special types on external declarations: bs.string, bs.int, bs.ignore</a>
544+
<li><a href="#_special_types_on_external_declarations_bs_string_bs_int_bs_ignore_bs_as">Special types on external declarations: bs.string, bs.int, bs.ignore, bs.as</a>
545545
<ul class="sectlevel3">
546546
<li><a href="#_using_polymorphic_variant_to_model_enums_and_string_types">Using polymorphic variant to model enums and string types</a></li>
547547
<li><a href="#_using_polymorphic_variant_to_model_event_listener">Using polymorphic variant to model event listener</a></li>
548548
<li><a href="#_phantom_arguments_and_ad_hoc_polyrmophism">Phantom Arguments and ad-hoc polyrmophism</a></li>
549549
</ul>
550550
</li>
551+
<li><a href="#_fixed_arguments">Fixed Arguments</a></li>
551552
<li><a href="#_binding_to_nodejs_special_variables_bs_node">Binding to NodeJS special variables: bs.node</a></li>
552553
<li><a href="#_binding_to_callbacks_high_order_function">Binding to callbacks (high-order function)</a>
553554
<ul class="sectlevel3">
@@ -1717,7 +1718,7 @@ <h3 id="_splice_calling_convention_bs_splice"><a class="anchor" href="#_splice_c
17171718
</div>
17181719
</div>
17191720
<div class="sect2">
1720-
<h3 id="_special_types_on_external_declarations_bs_string_bs_int_bs_ignore"><a class="anchor" href="#_special_types_on_external_declarations_bs_string_bs_int_bs_ignore"></a>Special types on external declarations: bs.string, bs.int, bs.ignore</h3>
1721+
<h3 id="_special_types_on_external_declarations_bs_string_bs_int_bs_ignore_bs_as"><a class="anchor" href="#_special_types_on_external_declarations_bs_string_bs_int_bs_ignore_bs_as"></a>Special types on external declarations: bs.string, bs.int, bs.ignore, bs.as</h3>
17211722
<div class="sect3">
17221723
<h4 id="_using_polymorphic_variant_to_model_enums_and_string_types"><a class="anchor" href="#_using_polymorphic_variant_to_model_enums_and_string_types"></a>Using polymorphic variant to model enums and string types</h4>
17231724
<div class="paragraph">
@@ -1921,6 +1922,85 @@ <h4 id="_phantom_arguments_and_ad_hoc_polyrmophism"><a class="anchor" href="#_ph
19211922
</div>
19221923
</div>
19231924
<div class="sect2">
1925+
<h3 id="_fixed_arguments"><a class="anchor" href="#_fixed_arguments"></a>Fixed Arguments</h3>
1926+
<div class="paragraph">
1927+
<p>Contrary to the Phantom arguments, <code>_[@bs.as]</code> is introduced to attach the const
1928+
data.</p>
1929+
</div>
1930+
<div class="paragraph">
1931+
<p>For example:</p>
1932+
</div>
1933+
<div class="listingblock">
1934+
<div class="content">
1935+
<pre class="pygments highlight"><code data-lang="ocaml"><span class="tok-k">external</span> <span class="tok-n">process_on_exit</span> <span class="tok-o">:</span> <span class="tok-o">(_</span> <span class="tok-o">[@</span><span class="tok-n">bs</span><span class="tok-o">.</span><span class="tok-k">as</span> <span class="tok-s2">&quot;exit&quot;</span><span class="tok-o">])</span> <span class="tok-o">-&gt;</span> <span class="tok-o">(</span><span class="tok-kt">int</span> <span class="tok-o">-&gt;</span> <span class="tok-kt">unit</span><span class="tok-o">)</span> <span class="tok-o">-&gt;</span> <span class="tok-kt">unit</span> <span class="tok-o">=</span>
1936+
<span class="tok-s2">&quot;process.on&quot;</span> <span class="tok-o">[@@</span><span class="tok-n">bs</span><span class="tok-o">.</span><span class="tok-k">val</span><span class="tok-o">]</span>
1937+
1938+
<span class="tok-k">let</span> <span class="tok-bp">()</span> <span class="tok-o">=</span>
1939+
<span class="tok-n">process_on_exit</span> <span class="tok-o">(</span><span class="tok-k">fun</span> <span class="tok-n">exit_code</span> <span class="tok-o">-&gt;</span>
1940+
<span class="tok-nn">Js</span><span class="tok-p">.</span><span class="tok-n">log</span><span class="tok-o">(</span> <span class="tok-s2">&quot;error code: &quot;</span> <span class="tok-o">^</span> <span class="tok-n">string_of_int</span> <span class="tok-n">exit_code</span> <span class="tok-o">))</span></code></pre>
1941+
</div>
1942+
</div>
1943+
<div class="paragraph">
1944+
<p>Output</p>
1945+
</div>
1946+
<div class="listingblock">
1947+
<div class="content">
1948+
<pre class="pygments highlight"><code data-lang="js"><span class="tok-nx">process</span><span class="tok-p">.</span><span class="tok-nx">on</span><span class="tok-p">(</span><span class="tok-s2">&quot;exit&quot;</span><span class="tok-p">,</span> <span class="tok-kd">function</span> <span class="tok-p">(</span><span class="tok-nx">exit_code</span><span class="tok-p">)</span> <span class="tok-p">{</span>
1949+
<span class="tok-nx">console</span><span class="tok-p">.</span><span class="tok-nx">log</span><span class="tok-p">(</span><span class="tok-s2">&quot;error code: &quot;</span> <span class="tok-o">+</span> <span class="tok-nx">exit_code</span><span class="tok-p">);</span>
1950+
<span class="tok-k">return</span> <span class="tok-cm">/* () */</span><span class="tok-mi">0</span><span class="tok-p">;</span>
1951+
<span class="tok-p">});</span></code></pre>
1952+
</div>
1953+
</div>
1954+
<div class="paragraph">
1955+
<p>It can also be used in combination with other attributes, for example:</p>
1956+
</div>
1957+
<div class="listingblock">
1958+
<div class="content">
1959+
<pre class="pygments highlight"><code data-lang="ocaml"><span class="tok-k">type</span> <span class="tok-n">process</span>
1960+
1961+
<span class="tok-k">external</span> <span class="tok-n">on_exit</span> <span class="tok-o">:</span> <span class="tok-o">(_</span> <span class="tok-o">[@</span><span class="tok-n">bs</span><span class="tok-o">.</span><span class="tok-k">as</span> <span class="tok-s2">&quot;exit&quot;</span><span class="tok-o">])</span> <span class="tok-o">-&gt;</span> <span class="tok-o">(</span><span class="tok-kt">int</span> <span class="tok-o">-&gt;</span> <span class="tok-kt">unit</span><span class="tok-o">)</span> <span class="tok-o">-&gt;</span> <span class="tok-kt">unit</span> <span class="tok-o">=</span>
1962+
<span class="tok-s2">&quot;on&quot;</span> <span class="tok-o">[@@</span><span class="tok-n">bs</span><span class="tok-o">.</span><span class="tok-n">send</span><span class="tok-o">.</span><span class="tok-n">pipe</span><span class="tok-o">:</span> <span class="tok-n">process</span><span class="tok-o">]</span>
1963+
<span class="tok-k">let</span> <span class="tok-n">register</span> <span class="tok-o">(</span><span class="tok-n">p</span> <span class="tok-o">:</span> <span class="tok-n">process</span><span class="tok-o">)</span> <span class="tok-o">=</span>
1964+
<span class="tok-n">p</span> <span class="tok-o">|&gt;</span> <span class="tok-n">on_exit</span> <span class="tok-o">(</span><span class="tok-k">fun</span> <span class="tok-n">i</span> <span class="tok-o">-&gt;</span> <span class="tok-nn">Js</span><span class="tok-p">.</span><span class="tok-n">log</span> <span class="tok-n">i</span> <span class="tok-o">)</span></code></pre>
1965+
</div>
1966+
</div>
1967+
<div class="paragraph">
1968+
<p>Output</p>
1969+
</div>
1970+
<div class="listingblock">
1971+
<div class="content">
1972+
<pre class="pygments highlight"><code data-lang="js"><span class="tok-kd">function</span> <span class="tok-nx">register</span><span class="tok-p">(</span><span class="tok-nx">p</span><span class="tok-p">)</span> <span class="tok-p">{</span>
1973+
<span class="tok-k">return</span> <span class="tok-nx">p</span><span class="tok-p">.</span><span class="tok-nx">on</span><span class="tok-p">(</span><span class="tok-s2">&quot;exit&quot;</span><span class="tok-p">,</span> <span class="tok-kd">function</span> <span class="tok-p">(</span><span class="tok-nx">i</span><span class="tok-p">)</span> <span class="tok-p">{</span>
1974+
<span class="tok-nx">console</span><span class="tok-p">.</span><span class="tok-nx">log</span><span class="tok-p">(</span><span class="tok-nx">i</span><span class="tok-p">);</span>
1975+
<span class="tok-k">return</span> <span class="tok-cm">/* () */</span><span class="tok-mi">0</span><span class="tok-p">;</span>
1976+
<span class="tok-p">});</span>
1977+
<span class="tok-p">}</span></code></pre>
1978+
</div>
1979+
</div>
1980+
<div class="paragraph">
1981+
<p>Input</p>
1982+
</div>
1983+
<div class="listingblock">
1984+
<div class="content">
1985+
<pre class="pygments highlight"><code data-lang="ocaml"><span class="tok-k">external</span> <span class="tok-n">io_config</span> <span class="tok-o">:</span>
1986+
<span class="tok-n">stdio</span><span class="tok-o">:(</span> <span class="tok-o">_</span> <span class="tok-o">[@</span><span class="tok-n">bs</span><span class="tok-o">.</span><span class="tok-k">as</span> <span class="tok-s2">&quot;inherit&quot;</span><span class="tok-o">])</span> <span class="tok-o">-&gt;</span> <span class="tok-n">cwd</span><span class="tok-o">:</span><span class="tok-kt">string</span> <span class="tok-o">-&gt;</span> <span class="tok-kt">unit</span> <span class="tok-o">-&gt;</span> <span class="tok-o">_</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;&quot;</span> <span class="tok-o">[@@</span><span class="tok-n">bs</span><span class="tok-o">.</span><span class="tok-n">obj</span><span class="tok-o">]</span>
1987+
1988+
<span class="tok-k">let</span> <span class="tok-n">config</span> <span class="tok-o">=</span> <span class="tok-n">io_config</span> <span class="tok-o">~</span><span class="tok-n">cwd</span><span class="tok-o">:</span><span class="tok-s2">&quot;.&quot;</span> <span class="tok-bp">()</span></code></pre>
1989+
</div>
1990+
</div>
1991+
<div class="paragraph">
1992+
<p>Output</p>
1993+
</div>
1994+
<div class="listingblock">
1995+
<div class="content">
1996+
<pre class="pygments highlight"><code data-lang="js"><span class="tok-kd">var</span> <span class="tok-nx">config</span> <span class="tok-o">=</span> <span class="tok-p">{</span>
1997+
<span class="tok-nx">stdio</span><span class="tok-o">:</span> <span class="tok-s2">&quot;inherit&quot;</span><span class="tok-p">,</span>
1998+
<span class="tok-nx">cwd</span><span class="tok-o">:</span> <span class="tok-s2">&quot;.&quot;</span>
1999+
<span class="tok-p">};</span></code></pre>
2000+
</div>
2001+
</div>
2002+
</div>
2003+
<div class="sect2">
19242004
<h3 id="_binding_to_nodejs_special_variables_bs_node"><a class="anchor" href="#_binding_to_nodejs_special_variables_bs_node"></a>Binding to NodeJS special variables: bs.node</h3>
19252005
<div class="paragraph">
19262006
<p>NodeJS has several file local variables: <code><em>dirname</code>, <code></em>filename</code>, <code>module_</code>, and <code>require</code>,

jscomp/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ SYNTAX_SRCS=ast_derive_constructor ast_derive_util ast_exp ast_external ast_lift
212212
ast_derive ast_comb ast_attributes ast_core_type ast_derive_dyn\
213213
ast_derive_projector \
214214
ast_ffi_types\
215-
ast_external_attributes \
216-
ast_util ppx_entry
215+
ast_external_attributes\
216+
ast_util\
217+
ppx_entry
218+
# not a good name ast_util
217219
SYNTAX_CMXS=$(addprefix syntax/, $(addsuffix .cmx, $(SYNTAX_SRCS)))
218220
DEPENDS_SRCS= depends_post_process bs_exception ast_extract binary_ast
219221
DEPENDS_CMXS=$(addprefix depends/, $(addsuffix .cmx, $(DEPENDS_SRCS)))

jscomp/all.depend

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ syntax/ast_derive.cmx : ext/string_map.cmx ext/literals.cmx \
167167
syntax/ast_signature.cmx syntax/ast_payload.cmx syntax/ast_derive.cmi
168168
syntax/ast_comb.cmx : ext/ext_list.cmx syntax/ast_literal.cmx \
169169
syntax/ast_comb.cmi
170-
syntax/ast_attributes.cmx : ext/ext_string.cmx syntax/ast_payload.cmx \
171-
syntax/ast_attributes.cmi
170+
syntax/ast_attributes.cmx : ext/ext_string.cmx common/bs_warnings.cmx \
171+
syntax/ast_payload.cmx syntax/ast_attributes.cmi
172172
syntax/ast_core_type.cmx : ext/ext_list.cmx syntax/ast_comb.cmx \
173173
syntax/ast_core_type.cmi
174174
syntax/ast_derive_dyn.cmx : syntax/ast_structure.cmx \
@@ -190,12 +190,12 @@ syntax/ast_util.cmx : ext/literals.cmx ext/ext_list.cmx \
190190
syntax/ast_core_type.cmx syntax/ast_comb.cmx syntax/ast_attributes.cmx \
191191
syntax/ast_util.cmi
192192
syntax/ppx_entry.cmx : ext/string_map.cmx ext/literals.cmx \
193-
ext/ext_string.cmx ext/ext_ref.cmx ext/ext_list.cmx \
194-
common/bs_warnings.cmx syntax/ast_util.cmx syntax/ast_structure.cmx \
195-
syntax/ast_signature.cmx syntax/ast_payload.cmx syntax/ast_literal.cmx \
196-
syntax/ast_external_attributes.cmx syntax/ast_derive_projector.cmx \
197-
syntax/ast_derive_dyn.cmx syntax/ast_derive.cmx syntax/ast_comb.cmx \
198-
syntax/ast_attributes.cmx syntax/ppx_entry.cmi
193+
ext/ext_string.cmx ext/ext_ref.cmx ext/ext_list.cmx syntax/ast_util.cmx \
194+
syntax/ast_structure.cmx syntax/ast_signature.cmx syntax/ast_payload.cmx \
195+
syntax/ast_literal.cmx syntax/ast_external_attributes.cmx \
196+
syntax/ast_derive_projector.cmx syntax/ast_derive_dyn.cmx \
197+
syntax/ast_derive.cmx syntax/ast_comb.cmx syntax/ast_attributes.cmx \
198+
syntax/ppx_entry.cmi
199199
syntax/ast_exp.cmi :
200200
syntax/ast_external.cmi :
201201
syntax/ast_lift.cmi :
@@ -487,7 +487,7 @@ core/lam_compile_external_call.cmx : core/lam_dispatch_primitive.cmx \
487487
core/lam_compile_env.cmx core/lam_compile_defs.cmx core/js_op.cmx \
488488
core/js_of_lam_variant.cmx core/js_of_lam_option.cmx core/js_exp_make.cmx \
489489
core/js_arr.cmx core/js_analyzer.cmx core/j.cmx ext/ext_list.cmx \
490-
ext/ext_ident.cmx syntax/ast_ffi_types.cmx syntax/ast_core_type.cmx \
490+
ext/ext_ident.cmx syntax/ast_ffi_types.cmx \
491491
core/lam_compile_external_call.cmi
492492
core/lam_compile_primitive.cmx : core/lam_util.cmx \
493493
core/lam_compile_external_call.cmx core/lam_compile_defs.cmx core/lam.cmx \

jscomp/bin/bsb.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7046,7 +7046,7 @@ type t =
70467046

70477047

70487048
let magic_number = "BS_DEP_INFOS_20161116"
7049-
let bsb_version = "20160119+dev"
7049+
let bsb_version = "20160121+dev"
70507050

70517051
let write (fname : string) (x : t) =
70527052
let oc = open_out_bin fname in

jscomp/bin/bsdep.d

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ bin/bsdep.ml : ext/string_map.ml
4747
bin/bsdep.ml : ext/string_map.mli
4848
bin/bsdep.ml : syntax/ast_payload.ml
4949
bin/bsdep.ml : syntax/ast_payload.mli
50+
bin/bsdep.ml : ext/ext_pervasives.ml
51+
bin/bsdep.ml : ext/ext_pervasives.mli
52+
bin/bsdep.ml : ext/literals.ml
53+
bin/bsdep.ml : ext/literals.mli
54+
bin/bsdep.ml : ext/ext_filename.ml
55+
bin/bsdep.ml : ext/ext_filename.mli
56+
bin/bsdep.ml : common/js_config.ml
57+
bin/bsdep.ml : common/js_config.mli
58+
bin/bsdep.ml : common/bs_warnings.ml
59+
bin/bsdep.ml : common/bs_warnings.mli
5060
bin/bsdep.ml : syntax/ast_attributes.ml
5161
bin/bsdep.ml : syntax/ast_attributes.mli
5262
bin/bsdep.ml : syntax/ast_literal.ml
@@ -59,8 +69,6 @@ bin/bsdep.ml : syntax/ast_signature.ml
5969
bin/bsdep.ml : syntax/ast_signature.mli
6070
bin/bsdep.ml : syntax/ast_structure.ml
6171
bin/bsdep.ml : syntax/ast_structure.mli
62-
bin/bsdep.ml : ext/literals.ml
63-
bin/bsdep.ml : ext/literals.mli
6472
bin/bsdep.ml : syntax/ast_derive.ml
6573
bin/bsdep.ml : syntax/ast_derive.mli
6674
bin/bsdep.ml : syntax/ast_derive_util.ml
@@ -70,18 +78,10 @@ bin/bsdep.ml : syntax/ast_derive_projector.ml
7078
bin/bsdep.ml : syntax/ast_derive_projector.mli
7179
bin/bsdep.ml : syntax/ast_core_type.ml
7280
bin/bsdep.ml : syntax/ast_core_type.mli
73-
bin/bsdep.ml : ext/ext_pervasives.ml
74-
bin/bsdep.ml : ext/ext_pervasives.mli
7581
bin/bsdep.ml : syntax/ast_ffi_types.ml
7682
bin/bsdep.ml : syntax/ast_ffi_types.mli
7783
bin/bsdep.ml : common/bs_loc.ml
7884
bin/bsdep.ml : common/bs_loc.mli
79-
bin/bsdep.ml : ext/ext_filename.ml
80-
bin/bsdep.ml : ext/ext_filename.mli
81-
bin/bsdep.ml : common/js_config.ml
82-
bin/bsdep.ml : common/js_config.mli
83-
bin/bsdep.ml : common/bs_warnings.ml
84-
bin/bsdep.ml : common/bs_warnings.mli
8585
bin/bsdep.ml : common/lam_methname.ml
8686
bin/bsdep.ml : common/lam_methname.mli
8787
bin/bsdep.ml : syntax/ast_external_attributes.ml

0 commit comments

Comments
 (0)