Skip to content

Commit 9ab9e2f

Browse files
author
Hongbo Zhang
committed
update docs
1 parent e6e672b commit 9ab9e2f

File tree

5 files changed

+184
-204
lines changed

5 files changed

+184
-204
lines changed

docs/Manual.html

+138-151
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ <h1><a href="https://github.com/bloomberg/bucklescript">BuckleScript</a> User Ma
596596
<li><a href="#__bs_no_builtin_ppx_ml_bs_no_builtin_ppx_mli">-bs-no-builtin-ppx-ml, -bs-no-builtin-ppx-mli</a></li>
597597
</ul>
598598
</li>
599-
<li><a href="#_how_to_adapt_your_build_system">How to adapt your build system</a></li>
600599
<li><a href="#_semantics_difference_from_other_backends">Semantics difference from other backends</a>
601600
<ul class="sectlevel2">
602601
<li><a href="#_custom_data_type">Custom data type</a></li>
@@ -611,6 +610,7 @@ <h1><a href="https://github.com/bloomberg/bucklescript">BuckleScript</a> User Ma
611610
<li><a href="#_unsupported_io_primitives">Unsupported IO primitives</a></li>
612611
</ul>
613612
</li>
613+
<li><a href="#_faq">FAQ</a></li>
614614
<li><a href="#_high_level_compiler_workflow">High Level compiler workflow</a>
615615
<ul class="sectlevel2">
616616
<li><a href="#_design_principles">Design Principles</a></li>
@@ -623,7 +623,6 @@ <h1><a href="https://github.com/bloomberg/bucklescript">BuckleScript</a> User Ma
623623
<li><a href="#_simple_ocaml_type">Simple OCaml type</a></li>
624624
</ul>
625625
</li>
626-
<li><a href="#_frequently_asked_questions">Frequently Asked Questions</a></li>
627626
<li><a href="#_integration_with_reason">Integration with Reason</a></li>
628627
<li><a href="#_how_to_contribute">How to contribute</a>
629628
<ul class="sectlevel2">
@@ -3207,77 +3206,6 @@ <h3 id="__bs_no_builtin_ppx_ml_bs_no_builtin_ppx_mli"><a class="anchor" href="#_
32073206
</div>
32083207
</div>
32093208
<div class="sect1">
3210-
<h2 id="_how_to_adapt_your_build_system"><a class="anchor" href="#_how_to_adapt_your_build_system"></a>How to adapt your build system</h2>
3211-
<div class="sectionbody">
3212-
<div class="paragraph">
3213-
<p>The BuckleScript compilation model is the same as the OCaml compiler.</p>
3214-
</div>
3215-
<div class="paragraph">
3216-
<p>If <code>b.ml</code> depends on <code>a.ml</code>, you have to compile <code>a.ml</code> <strong>and</strong> <code>a.mli</code>
3217-
first.</p>
3218-
</div>
3219-
<div class="admonitionblock note">
3220-
<table>
3221-
<tr>
3222-
<td class="icon">
3223-
<div class="title">Note</div>
3224-
</td>
3225-
<td class="content">
3226-
<div class="paragraph">
3227-
<p>The technical reason is that BuckleScript will generate intermediate
3228-
files with the extension <code>.cmj</code> which are later used for cross module
3229-
inlining, arity inference and other information.</p>
3230-
</div>
3231-
</td>
3232-
</tr>
3233-
</table>
3234-
</div>
3235-
<div class="paragraph">
3236-
<p>Here is a simple Makefile to get started:</p>
3237-
</div>
3238-
<div class="listingblock">
3239-
<div class="content">
3240-
<pre class="pygments highlight"><code data-lang="make"><span class="tok-nv">OCAMLC</span><span class="tok-o">=</span>bsc <b class="conum">(1)</b>
3241-
3242-
<span class="tok-nv">OCAMLDEP</span><span class="tok-o">=</span>ocamldep <b class="conum">(2)</b>
3243-
3244-
<span class="tok-nv">SOURCE_LIST</span> <span class="tok-o">:=</span> src_a src_b
3245-
3246-
<span class="tok-nv">SOURCE_MLI</span> <span class="tok-o">=</span> <span class="tok-k">$(</span>addsuffix .mli, <span class="tok-k">$(</span>SOURCE_LIST<span class="tok-k">))</span>
3247-
3248-
<span class="tok-nv">SOURCE_ML</span> <span class="tok-o">=</span> <span class="tok-k">$(</span>addsuffix .ml, <span class="tok-k">$(</span>SOURCE_LIST<span class="tok-k">))</span>
3249-
3250-
<span class="tok-nv">TARGETS</span> <span class="tok-o">:=</span> <span class="tok-k">$(</span>addsuffix .cmj, <span class="tok-k">$(</span>SOURCE_LIST<span class="tok-k">))</span>
3251-
3252-
<span class="tok-nv">INCLUDES</span><span class="tok-o">=</span>
3253-
3254-
<span class="tok-nf">all</span><span class="tok-o">:</span> <span class="tok-k">$(</span><span class="tok-nv">TARGETS</span><span class="tok-k">)</span>
3255-
3256-
<span class="tok-nf">%.cmi</span><span class="tok-o">:</span> %.<span class="tok-n">mli</span>
3257-
<span class="tok-k">$(</span>OCAMLC<span class="tok-k">)</span> <span class="tok-k">$(</span>INCLUDES<span class="tok-k">)</span> <span class="tok-k">$(</span>COMPFLAGS<span class="tok-k">)</span> -c <span class="tok-nv">$&lt;</span>
3258-
3259-
<span class="tok-nf">%.ml</span><span class="tok-o">:</span> %.<span class="tok-n">cmj</span>:
3260-
<span class="tok-k">$(</span>OCAMLC<span class="tok-k">)</span> <span class="tok-k">$(</span>INCLUDES<span class="tok-k">)</span> <span class="tok-k">$(</span>COMPFLAGS<span class="tok-k">)</span> -c <span class="tok-nv">$&lt;</span>
3261-
3262-
<span class="tok-cp">-include .depend</span>
3263-
3264-
<span class="tok-nf">depend</span><span class="tok-o">:</span>
3265-
<span class="tok-k">$(</span>OCAMLDEP<span class="tok-k">)</span> <span class="tok-k">$(</span>INCLUDES<span class="tok-k">)</span> <span class="tok-k">$(</span>SOURCE_ML<span class="tok-k">)</span> <span class="tok-k">$(</span>SOURCE_MLI<span class="tok-k">)</span> <span class="tok-p">|</span> sed -e <span class="tok-s1">&#39;s/\.cmx/.cmj/g&#39;</span> &gt; .depend</code></pre>
3266-
</div>
3267-
</div>
3268-
<div class="colist arabic">
3269-
<ol>
3270-
<li>
3271-
<p>bsc is the BuckleScript compiler</p>
3272-
</li>
3273-
<li>
3274-
<p>ocamldep executable is part of the OCaml compiler installation</p>
3275-
</li>
3276-
</ol>
3277-
</div>
3278-
</div>
3279-
</div>
3280-
<div class="sect1">
32813209
<h2 id="_semantics_difference_from_other_backends"><a class="anchor" href="#_semantics_difference_from_other_backends"></a>Semantics difference from other backends</h2>
32823210
<div class="sectionbody">
32833211
<div class="paragraph">
@@ -3387,6 +3315,143 @@ <h3 id="_unsupported_io_primitives"><a class="anchor" href="#_unsupported_io_pri
33873315
</div>
33883316
</div>
33893317
<div class="sect1">
3318+
<h2 id="_faq"><a class="anchor" href="#_faq"></a>FAQ</h2>
3319+
<div class="sectionbody">
3320+
<div class="qlist qanda">
3321+
<ol>
3322+
<li>
3323+
<p><em>How to adapt your build system?</em></p>
3324+
<p>The BuckleScript compilation model is the same as the OCaml compiler.
3325+
If <code>b.ml</code> depends on <code>a.ml</code>, you have to compile <code>a.ml</code> <strong>and</strong> <code>a.mli</code>
3326+
first.</p>
3327+
<div class="admonitionblock note">
3328+
<table>
3329+
<tr>
3330+
<td class="icon">
3331+
<div class="title">Note</div>
3332+
</td>
3333+
<td class="content">
3334+
<div class="paragraph">
3335+
<p>The technical reason is that BuckleScript will generate intermediate
3336+
files with the extension <code>.cmj</code> which are later used for cross module
3337+
inlining, arity inference and other information.</p>
3338+
</div>
3339+
</td>
3340+
</tr>
3341+
</table>
3342+
</div>
3343+
<div class="paragraph">
3344+
<p>Here is a simple Makefile to get started:</p>
3345+
</div>
3346+
<div class="listingblock">
3347+
<div class="title">Makefile</div>
3348+
<div class="content">
3349+
<pre class="pygments highlight"><code data-lang="make"><span class="tok-nv">OCAMLC</span><span class="tok-o">=</span>bsc <b class="conum">(1)</b>
3350+
<span class="tok-nv">OCAMLDEP</span><span class="tok-o">=</span>ocamldep <b class="conum">(2)</b>
3351+
<span class="tok-nv">SOURCE_LIST</span> <span class="tok-o">:=</span> src_a src_b
3352+
<span class="tok-nv">SOURCE_MLI</span> <span class="tok-o">=</span> <span class="tok-k">$(</span>addsuffix .mli, <span class="tok-k">$(</span>SOURCE_LIST<span class="tok-k">))</span>
3353+
<span class="tok-nv">SOURCE_ML</span> <span class="tok-o">=</span> <span class="tok-k">$(</span>addsuffix .ml, <span class="tok-k">$(</span>SOURCE_LIST<span class="tok-k">))</span>
3354+
<span class="tok-nv">TARGETS</span> <span class="tok-o">:=</span> <span class="tok-k">$(</span>addsuffix .cmj, <span class="tok-k">$(</span>SOURCE_LIST<span class="tok-k">))</span>
3355+
<span class="tok-nv">INCLUDES</span><span class="tok-o">=</span>
3356+
<span class="tok-nf">all</span><span class="tok-o">:</span> <span class="tok-k">$(</span><span class="tok-nv">TARGETS</span><span class="tok-k">)</span>
3357+
<span class="tok-nf">%.cmi</span><span class="tok-o">:</span> %.<span class="tok-n">mli</span>
3358+
<span class="tok-k">$(</span>OCAMLC<span class="tok-k">)</span> <span class="tok-k">$(</span>INCLUDES<span class="tok-k">)</span> <span class="tok-k">$(</span>COMPFLAGS<span class="tok-k">)</span> -c <span class="tok-nv">$&lt;</span>
3359+
<span class="tok-nf">%.ml</span><span class="tok-o">:</span> %.<span class="tok-n">cmj</span>:
3360+
<span class="tok-k">$(</span>OCAMLC<span class="tok-k">)</span> <span class="tok-k">$(</span>INCLUDES<span class="tok-k">)</span> <span class="tok-k">$(</span>COMPFLAGS<span class="tok-k">)</span> -c <span class="tok-nv">$&lt;</span>
3361+
<span class="tok-cp">-include .depend</span>
3362+
<span class="tok-nf">depend</span><span class="tok-o">:</span>
3363+
<span class="tok-k">$(</span>OCAMLDEP<span class="tok-k">)</span> <span class="tok-k">$(</span>INCLUDES<span class="tok-k">)</span> <span class="tok-k">$(</span>SOURCE_ML<span class="tok-k">)</span> <span class="tok-k">$(</span>SOURCE_MLI<span class="tok-k">)</span> <span class="tok-p">|</span> sed -e <span class="tok-s1">&#39;s/\.cmx/.cmj/g&#39;</span> &gt; .depend</code></pre>
3364+
</div>
3365+
</div>
3366+
<div class="colist arabic">
3367+
<ol>
3368+
<li>
3369+
<p>bsc is the BuckleScript compiler</p>
3370+
</li>
3371+
<li>
3372+
<p>ocamldep executable is part of the OCaml compiler installation</p>
3373+
</li>
3374+
</ol>
3375+
</div>
3376+
</li>
3377+
<li>
3378+
<p><em>How does IO work in browser?</em></p>
3379+
<p>In general, it is very hard to simulate IO in browser, we recommend users to write bindings to NodeJS directly for server side, or use <code>Js.log</code> in client side, see disucssions in <a href="https://github.com/bloomberg/bucklescript/issues/748">#748</a></p>
3380+
</li>
3381+
<li>
3382+
<p><em>The compiler does not build?</em></p>
3383+
<p> In production mode, the compiler is a single file in
3384+
<code>jscomp/bin/compiler.ml</code>. If it is not compiling, make sure you have the
3385+
right OCaml compiler version. Currently the OCaml compiler is a
3386+
submodule of BuckleScript. Make sure the exact commit hash matches (we
3387+
only update the compiler occasionally).</p>
3388+
</li>
3389+
<li>
3390+
<p><em>Which version of JavaScript syntax does BuckleScript target?</em></p>
3391+
<p>BuckleScript targets <strong>ES5</strong>.</p>
3392+
</li>
3393+
<li>
3394+
<p><em>What polyfills does BuckleScript need?</em></p>
3395+
<div class="ulist">
3396+
<ul>
3397+
<li>
3398+
<p><em>Math.imul</em>:
3399+
This polyfill is needed for <code>int32</code> multiplication.
3400+
BuckleScript provides this by default(when feature detection returns false), no action is
3401+
required from the user.</p>
3402+
</li>
3403+
<li>
3404+
<p><em>TypedArray</em>:
3405+
The TypedArray polyfill is not provided by BuckleScript and it&#8217;s the
3406+
responsibility of the user to bundle the desired polyfill implementation
3407+
with the BuckleScript generated code.</p>
3408+
<div class="literalblock">
3409+
<div class="content">
3410+
<pre>The following functions from OCaml stdlib
3411+
require the TypedArray polyfill:</pre>
3412+
</div>
3413+
</div>
3414+
<div class="ulist">
3415+
<ul>
3416+
<li>
3417+
<p>Int64.float_of_bits</p>
3418+
</li>
3419+
<li>
3420+
<p>Int64.bits_of_float</p>
3421+
</li>
3422+
<li>
3423+
<p>Int32.float_of_bits</p>
3424+
</li>
3425+
<li>
3426+
<p>Int32.bits_of_float</p>
3427+
<div class="admonitionblock warning">
3428+
<table>
3429+
<tr>
3430+
<td class="icon">
3431+
<div class="title">Warning</div>
3432+
</td>
3433+
<td class="content">
3434+
<div class="paragraph">
3435+
<p>For the current BuckleScript version, if the user does not bundle the
3436+
TypedArray polyfill, the JavaScript engine does not support it and user used
3437+
functions mentioned above, the code will fail at runtime.</p>
3438+
</div>
3439+
</td>
3440+
</tr>
3441+
</table>
3442+
</div>
3443+
</li>
3444+
</ul>
3445+
</div>
3446+
</li>
3447+
</ul>
3448+
</div>
3449+
</li>
3450+
</ol>
3451+
</div>
3452+
</div>
3453+
</div>
3454+
<div class="sect1">
33903455
<h2 id="_high_level_compiler_workflow"><a class="anchor" href="#_high_level_compiler_workflow"></a>High Level compiler workflow</h2>
33913456
<div class="sectionbody">
33923457
<div class="paragraph">
@@ -3829,84 +3894,6 @@ <h3 id="_simple_ocaml_type"><a class="anchor" href="#_simple_ocaml_type"></a>Sim
38293894
</div>
38303895
</div>
38313896
<div class="sect1">
3832-
<h2 id="_frequently_asked_questions"><a class="anchor" href="#_frequently_asked_questions"></a>Frequently Asked Questions</h2>
3833-
<div class="sectionbody">
3834-
<div class="qlist qanda">
3835-
<ol>
3836-
<li>
3837-
<p><em>The compiler does not build?</em></p>
3838-
<p> In production mode, the compiler is a single file in
3839-
<code>jscomp/bin/compiler.ml</code>. If it is not compiling, make sure you have the
3840-
right OCaml compiler version. Currently the OCaml compiler is a
3841-
submodule of BuckleScript. Make sure the exact commit hash matches (we
3842-
only update the compiler occasionally).</p>
3843-
</li>
3844-
<li>
3845-
<p><em>Which version of JavaScript syntax does BuckleScript target?</em></p>
3846-
<p>BuckleScript targets <strong>ES5</strong>.</p>
3847-
</li>
3848-
<li>
3849-
<p><em>What polyfills does BuckleScript need?</em></p>
3850-
<div class="ulist">
3851-
<ul>
3852-
<li>
3853-
<p><em>Math.imul</em>:
3854-
This polyfill is needed for <code>int32</code> multiplication.
3855-
BuckleScript provides this by default(when feature detection returns false), no action is
3856-
required from the user.</p>
3857-
</li>
3858-
<li>
3859-
<p><em>TypedArray</em>:
3860-
The TypedArray polyfill is not provided by BuckleScript and it&#8217;s the
3861-
responsibility of the user to bundle the desired polyfill implementation
3862-
with the BuckleScript generated code.</p>
3863-
<div class="literalblock">
3864-
<div class="content">
3865-
<pre>The following functions from OCaml stdlib
3866-
require the TypedArray polyfill:</pre>
3867-
</div>
3868-
</div>
3869-
<div class="ulist">
3870-
<ul>
3871-
<li>
3872-
<p>Int64.float_of_bits</p>
3873-
</li>
3874-
<li>
3875-
<p>Int64.bits_of_float</p>
3876-
</li>
3877-
<li>
3878-
<p>Int32.float_of_bits</p>
3879-
</li>
3880-
<li>
3881-
<p>Int32.bits_of_float</p>
3882-
<div class="admonitionblock warning">
3883-
<table>
3884-
<tr>
3885-
<td class="icon">
3886-
<div class="title">Warning</div>
3887-
</td>
3888-
<td class="content">
3889-
<div class="paragraph">
3890-
<p>For the current BuckleScript version, if the user does not bundle the
3891-
TypedArray polyfill, the JavaScript engine does not support it and user used
3892-
functions mentioned above, the code will fail at runtime.</p>
3893-
</div>
3894-
</td>
3895-
</tr>
3896-
</table>
3897-
</div>
3898-
</li>
3899-
</ul>
3900-
</div>
3901-
</li>
3902-
</ul>
3903-
</div>
3904-
</li>
3905-
</ol>
3906-
</div>
3907-
</div>
3908-
</div>
3909-
<div class="sect1">
39103897
<h2 id="_integration_with_reason"><a class="anchor" href="#_integration_with_reason"></a>Integration with Reason</h2>
39113898
<div class="sectionbody">
39123899
<div class="paragraph">

site/docsource/CHANGELOG.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[appendix]
33
## CHANGES
4-
:issues: https://github.com/bloomberg/bucklescript/issues
4+
55

66
== 1.02 (dev)
77

site/docsource/FAQ.adoc

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
1-
== Frequently Asked Questions
1+
== FAQ
22

33
[qanda]
44

5+
6+
How to adapt your build system?::
7+
The BuckleScript compilation model is the same as the OCaml compiler.
8+
If `b.ml` depends on `a.ml`, you have to compile `a.ml` *and* `a.mli`
9+
first.
10+
+
11+
[NOTE]
12+
======
13+
The technical reason is that BuckleScript will generate intermediate
14+
files with the extension `.cmj` which are later used for cross module
15+
inlining, arity inference and other information.
16+
======
17+
Here is a simple Makefile to get started:
18+
+
19+
.Makefile
20+
[source,make]
21+
-------------
22+
OCAMLC=bsc # <1>
23+
OCAMLDEP=ocamldep # <2>
24+
SOURCE_LIST := src_a src_b
25+
SOURCE_MLI = $(addsuffix .mli, $(SOURCE_LIST))
26+
SOURCE_ML = $(addsuffix .ml, $(SOURCE_LIST))
27+
TARGETS := $(addsuffix .cmj, $(SOURCE_LIST))
28+
INCLUDES=
29+
all: $(TARGETS)
30+
%.cmi: %.mli
31+
$(OCAMLC) $(INCLUDES) $(COMPFLAGS) -c $<
32+
%.ml: %.cmj:
33+
$(OCAMLC) $(INCLUDES) $(COMPFLAGS) -c $<
34+
-include .depend
35+
depend:
36+
$(OCAMLDEP) $(INCLUDES) $(SOURCE_ML) $(SOURCE_MLI) | sed -e 's/\.cmx/.cmj/g' > .depend
37+
-------------
38+
<1> bsc is the BuckleScript compiler
39+
<2> ocamldep executable is part of the OCaml compiler installation
40+
41+
42+
How does IO work in browser?::
43+
In general, it is very hard to simulate IO in browser, we recommend users to write bindings to NodeJS directly for server side, or use `Js.log` in client side, see disucssions in {issues}/748[#748]
44+
545
The compiler does not build?::
646
In production mode, the compiler is a single file in
747
`jscomp/bin/compiler.ml`. If it is not compiling, make sure you have the

0 commit comments

Comments
 (0)