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
18 changes: 10 additions & 8 deletions document/core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spectec:

SPECTECPAT = $(SPECTECSPEC)/*.$(SPECTECEXT)
SPECTECFILES = $(shell ls $(SPECTECPAT))
RSTDIRS = $(shell ls -d [a-z]*/ util/[a-z]*/)
RSTDIRS = $(shell ls -d [a-z]*/ util/[a-z]*/ | grep -v util/katex)
RSTFILES = $(shell ls -d *.rst [a-z]*/*.rst) $(GENERATED)
CTRLFILES = $(shell ls Makefile *.* util/*.* util/bikeshed/*.*) $(shell ls static/*)
ALLFILES = $(RSTDIRS) $(CTRLFILES) _splice #$(RSTFILES)
Expand All @@ -97,12 +97,9 @@ $(SPLICEDIR)/$(BUILDDIR): $(SPLICEDIR)
$(BUILDDIR): $(SPLICEDIR)/$(BUILDDIR)
ln -s $< $@

$(RSTDIRS:%=$(SPLICEDIR)/%):: $(SPLICEDIR)
$(RSTDIRS:%=$(SPLICEDIR)/%): $(SPLICEDIR)
mkdir -p $@

$(SPLICEDIR)/util/katex:: util/katex
cp -R $< $@ # F it!

$(SPLICEDIR)/_splice: $(SPLICEDIR) $(RSTFILES) $(SPECTECFILES)
@echo Modified $?
@echo ${if ${filter %.$(SPECTECEXT), $?}, $(RSTFILES), ${filter %.rst, $?}} >$@
Expand Down Expand Up @@ -184,13 +181,16 @@ singlehtml: $(SPLICEDFILES)
singlehtml-nested: $(GENERATED)
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml

.PHONY: bikeshed bikeshed-nested
.PHONY: bikeshed bikshed-fixup bikeshed-nested
bikeshed: $(SPLICEDFILES)
(cd util/katex/ && yarn && yarn build && npm install --only=prod)
mkdir -p $(SPLICEDIR)/util/katex
cp -Rf util/katex/* $(SPLICEDIR)/util/katex
(cd $(SPLICEDIR) && make bikeshed-nested)
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/html/bikeshed/."

bikeshed-nested: $(GENERATED)
bikeshed-fixup: $(GENERATED)
$(SPHINXBUILD) -b singlehtml -c util/bikeshed \
$(ALLSPHINXOPTS) $(BUILDDIR)/bikeshed_singlehtml
python3 util/bikeshed_fixup.py $(BUILDDIR)/bikeshed_singlehtml/index.html \
Expand All @@ -201,10 +201,12 @@ bikeshed-nested: $(GENERATED)
@tail -n10 _build/bikeshed_singlehtml/index_fixed.html
@echo
@echo =========================================================================

bikeshed-nested: bikeshed-fixup
mkdir -p $(BUILDDIR)/bikeshed_mathjax/
bikeshed spec --md-status=$(W3C_STATUS) --md-deadline=$(DEADLINE) index.bs $(BUILDDIR)/bikeshed_mathjax/index.html
mkdir -p $(BUILDDIR)/html/bikeshed/
(cd util/katex/ && yarn && yarn build && npm install --only=prod)
# (cd util/katex/ && yarn && yarn build && npm install --only=prod)
python3 util/mathjax2katex.py $(BUILDDIR)/bikeshed_mathjax/index.html \
>$(BUILDDIR)/html/bikeshed/index.html
mkdir -p $(BUILDDIR)/html/bikeshed/katex/dist/
Expand Down
7 changes: 7 additions & 0 deletions document/core/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,5 +518,12 @@
'macros': {
'multicolumn': ['', 2] # Bummer, MathJax can't handle multicolumn, ignore it
}
},
'options': {
'menuOptions': {
'settings': {
'enrich': False, # Activating this apparently increases page load times by 4x
}
}
}
}
4 changes: 2 additions & 2 deletions document/core/util/bikeshed_fixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def Main():
# an error — which in turn causes the W3C pubrules checker to refuse to
# autopublish the resulting bikeshed output.
data = data.replace(
"""\href{#binary-sint}{\href{#syntax-int}""",
"""{\href{#syntax-int}""")
"""\\href{#binary-sint}{\\href{#syntax-int}""",
"""{\\href{#syntax-int}""")

# Strip the entire <head> element from the the sphinx output — because it
# contains several <meta>, <script>, and <link> elements that are unnecessary
Expand Down
1 change: 1 addition & 0 deletions document/core/util/mathjax2katex.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def ReplaceMath(cache, data):
data = data.replace('\\mbox', '\\text')
data = data.replace('\\begin{split}', '\\begin{aligned}')
data = data.replace('\\end{split}', '\\end{aligned}')
data = re.sub('\\\\multicolumn\\{[0-9]*\\}\\{[a-z]*\\}', '', data) # Katex can't handle it
data = data.replace('&amp;', '&') # Messed up by Bikeshed
data = data.replace('&lt;', '<') # Messed up by Bikeshed
data = data.replace('&gt;', '>') # Messed up by Bikeshed
Expand Down
2 changes: 1 addition & 1 deletion document/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h3>Legacy Extensions</h3>
<li><a href="legacy/exceptions/core/_download/WebAssembly-Legacy-Exceptions.pdf">PDF version</a></li>
</ul>
</li>
<li><p><b>JavaScirpt Embedding</b></p>
<li><p><b>JavaScript Embedding</b></p>
<ul>
<li><a href="legacy/exceptions/js-api/">W3C version</a></li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions document/web-api/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ additional APIs that are implemented by Web user agents but are outside the scop
<pre class="idl">
[Exposed=(Window,Worker)]
partial namespace WebAssembly {
Promise&lt;Module> compileStreaming(Promise&lt;Response> source, optional WebAssemblyCompileOptions options);
Promise&lt;Module> compileStreaming(Promise&lt;Response> source, optional WebAssemblyCompileOptions options = {});
Promise&lt;WebAssemblyInstantiatedSource> instantiateStreaming(
Promise&lt;Response> source, optional object importObject, optional WebAssemblyCompileOptions options);
Promise&lt;Response> source, optional object importObject, optional WebAssemblyCompileOptions options = {});
};
</pre>

Expand Down
2 changes: 1 addition & 1 deletion specification/wasm-1.0/A-binary.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ grammar Bmut : mut =
| 0x01 => MUT

grammar Blimits : limits =
| 0x00 n:Bu32 => `[n .. ]
| 0x00 n:Bu32 => `[n .. eps]
| 0x01 n:Bu32 m:Bu32 => `[n .. m]

grammar Bglobaltype : globaltype =
Expand Down
2 changes: 1 addition & 1 deletion specification/wasm-2.0/A-binary.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ grammar Bmut : mut =
| 0x01 => MUT

grammar Blimits : limits =
| 0x00 n:Bu32 => `[n .. ]
| 0x00 n:Bu32 => `[n .. eps]
| 0x01 n:Bu32 m:Bu32 => `[n .. m]

grammar Bglobaltype : globaltype =
Expand Down
4 changes: 2 additions & 2 deletions specification/wasm-3.0/5.2-binary.types.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ grammar Brectype : rectype =
;; External types

grammar Blimits : (addrtype, limits) =
| 0x00 n:Bu64 => (I32, `[n .. ])
| 0x00 n:Bu64 => (I32, `[n .. eps])
| 0x01 n:Bu64 m:Bu64 => (I32, `[n .. m])
| 0x04 n:Bu64 => (I64, `[n .. ])
| 0x04 n:Bu64 => (I64, `[n .. eps])
| 0x05 n:Bu64 m:Bu64 => (I64, `[n .. m])

grammar Btagtype : tagtype =
Expand Down
2 changes: 1 addition & 1 deletion specification/wasm-3.0/6.2-text.types.spectec
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ grammar Taddrtype/abbrev : addrtype = ... | eps == "i32"


grammar Tlimits : limits =
| n:Tu64 => `[n .. ]
| n:Tu64 => `[n .. eps]
| n:Tu64 m:Tu64 => `[n .. m]


Expand Down
Binary file modified spectec/doc/example/output/NanoWasm.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions spectec/src/backend-interpreter/runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ let num_parse_fail = ref 0
let is_long_test path =
List.mem (Filename.basename path)
[ "memory_copy.wast";
"memory_copy64.wast";
"memory_fill.wast";
"memory_fill64.wast";
"memory_grow.wast";
"memory_grow64.wast";
"call_indirect.wast";
"call_indirect64.wast";
"return_call.wast";
"return_call_indirect.wast";
"return_call_ref.wast"
Expand Down
60 changes: 33 additions & 27 deletions spectec/src/backend-latex/render.ml
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ and expand_arg env ctxt a =
* and the function `render` for rendering the resulting expression.
* If no hint can be found, fall back to the default of rendering `f`.
*)
let render_expand render env (show : hints ref) macro id args f : string * arg list =
let rec render_expand render env (show : hints ref) macro id args possibly_flattened f : string * arg list =
match Map.find_opt id.it !show with
| None ->
(*
Expand All @@ -841,11 +841,19 @@ Printf.printf "[expand attempt %s %s] %s\n%!" id.it m (El.Print.string_of_exp sh
let env' = local_env env in
let ctxt = {macro; templ; args; next = ref 1; max = ref 0} in
let e = expand_exp env' ctxt showexp in
let args' = Lib.List.drop (!(ctxt.max) + 1) args in
(* Avoid cyclic expansion *)
show := Map.remove id.it !show;
Fun.protect (fun () -> render env' e, args')
~finally:(fun () -> show := Map.add id.it showexps !show)
if possibly_flattened && !(ctxt.max) < List.length args - 1 then
(* Not all args used, retry with unflattened tail *)
let args1, args2 = Lib.List.split !(ctxt.max) args in
let at = Source.over_region (List.map Source.at args2) in
render_expand render env show macro id
(args1 @ [ref (ExpA (SeqE (List.map exp_of_arg args2) $ at)) $ at])
true f
else
let args' = Lib.List.drop (!(ctxt.max) + 1) args in
(* Avoid cyclic expansion *)
show := Map.remove id.it !show;
Fun.protect (fun () -> render env' e, args')
~finally:(fun () -> show := Map.add id.it showexps !show)
with Arity_mismatch -> attempt showexps'
(* HACK: Ignore arity mismatches, such that overloading notation works,
* e.g., using CONST for both instruction and relation. *)
Expand All @@ -858,7 +866,7 @@ Printf.printf "[expand attempt %s %s] %s\n%!" id.it m (El.Print.string_of_exp sh
let render_apply render_id render_exp env show macro id args =
(* Pre-render id here, since we cannot distinguish it from other id classes later. *)
let arg0 = arg_of_exp (LatexE (render_id env id) $ id.at) in
render_expand render_exp env show macro id (arg0::args)
render_expand render_exp env show macro id (arg0::args) false
(fun () ->
let n = count_sub id.it in
if n > 0 && n <= List.length args then
Expand Down Expand Up @@ -949,7 +957,7 @@ let rec render_id_sub style show macro env first at = function
if String.for_all is_digit s3 then s3 else
if not first then render_id' env style s2 None else
render_expand !render_exp_fwd env show macro
(s3 $ at) [ref (ExpA (VarE (s3 $ at, []) $ at)) $ at]
(s3 $ at) [ref (ExpA (VarE (s3 $ at, []) $ at)) $ at] false
(fun () -> render_id' env style s2 (macro_template env macro s3)) |> fst
in
let s5 = s4 ^ ticks in
Expand Down Expand Up @@ -1002,7 +1010,7 @@ let render_atom env atom =
let open Atom in
let id = typed_id atom in
let arg = arg_of_exp (AtomE atom $ atom.at) in
render_expand !render_exp_fwd env env.show_atom env.macro_atom id [arg]
render_expand !render_exp_fwd env env.show_atom env.macro_atom id [arg] false
(fun () ->
(*
if env.config.macros_for_ids then
Expand Down Expand Up @@ -1268,22 +1276,18 @@ and render_exp env e =
(match List.find_opt (is_atom_exp_with_show env) es with
| Some {it = AtomE atom; _} ->
let args = List.map arg_of_exp es in
(*
if atom.it = Atom.Atom "X" && String.contains e.at.left.file 'A' then
Printf.eprintf "[render %s:X @ %s] try expansion\n%!" (Source.string_of_region e.at) atom.note.Atom.def;
*)
(match render_expand render_exp env env.show_atom env.macro_atom
(typed_id atom) args (fun () -> render_exp_seq env es)
(typed_id atom) args true (fun () -> render_exp_seq env e.at es)
with
| _, args' when List.length args' + 1 = List.length args ->
(* HACK for nullary contructors *)
(* TODO(4, rossberg): handle inner constructors more generally *)
render_exp_seq env es
render_exp_seq env e.at es
| s, _ -> s
)
| _ -> render_exp_seq env es
| _ -> render_exp_seq env e.at es
)
| ListE es -> "{}[" ^ render_exp_seq env es ^ "]"
| ListE es -> "{}[" ^ render_exp_seq env e.at es ^ "]"
| IdxE (e1, e2) -> render_exp env e1 ^ "{}[" ^ render_exp env e2 ^ "]"
| SliceE (e1, e2, e3) ->
render_exp env e1 ^
Expand Down Expand Up @@ -1319,7 +1323,7 @@ Printf.eprintf "[render %s:X @ %s] try expansion\n%!" (Source.string_of_region e
let id = typed_id atom in
let ea = AtomE atom $ atom.at in
let args = List.map arg_of_exp ([e1; ea] @ as_seq_exp e2) in
render_expand render_exp env env.show_atom env.macro_atom id args
render_expand render_exp env env.show_atom env.macro_atom id args false
(fun () ->
(* Handle subscripting and unary uses *)
(match Atom.is_sub atom, (as_arith_exp e1).it with
Expand All @@ -1330,7 +1334,7 @@ Printf.eprintf "[render %s:X @ %s] try expansion\n%!" (Source.string_of_region e
) ^
(match Atom.is_sub atom, e2.it with
| true, SeqE (e21::e22::es2) ->
"{" ^ render_exps "," env (as_tup_exp e21) ^ "} " ^ render_exp_seq env (e22::es2)
"{" ^ render_exps "," env (as_tup_exp e21) ^ "} " ^ render_exp_seq env e2.at (e22::es2)
| true, _ -> "{" ^ render_exps "," env (as_tup_exp e2) ^ "} {}"
| false, _ -> render_exp env e2
)
Expand All @@ -1340,7 +1344,7 @@ Printf.eprintf "[render %s:X @ %s] try expansion\n%!" (Source.string_of_region e
let el = AtomE l $ l.at in
let er = AtomE r $ r.at in
let args = List.map arg_of_exp ([el] @ as_seq_exp e1 @ [er]) in
render_expand render_exp env env.show_atom env.macro_atom id args
render_expand render_exp env env.show_atom env.macro_atom id args true
(fun () -> render_atom env l ^ space (render_exp env) e1 ^ render_atom env r) |> fst
| CallE (id, [arg]) when id.it = "" -> (* expansion result only *)
render_arg env arg
Expand Down Expand Up @@ -1368,29 +1372,31 @@ Printf.eprintf "[render %s:X @ %s] try expansion\n%!" (Source.string_of_region e
and render_exps sep env es =
concat sep (List.filter ((<>) "") (List.map (render_exp env) es))

and render_exp_seq env = function
and render_exp_seq env at = function
| [] -> ""
| es when env.config.display && (List.hd es).at.left.line < (Lib.List.last es).at.right.line ->
"\\begin{array}[t]{@{}l@{}} " ^ render_exp_seq' env es ^ " \\end{array}"
| es -> render_exp_seq' env es
"\\begin{array}[t]{@{}l@{}} " ^ render_exp_seq' env at es ^ " \\end{array}"
| es -> render_exp_seq' env at es

and render_exp_seq' env = function
and render_exp_seq' env at = function
| [] -> ""
| e1::e2::es when ends_sub_exp e1 ->
(* Handle subscripting *)
let s1 =
"{" ^ render_exp env e1 ^ "}_{" ^
render_exps "," env (as_tup_exp e2) ^ "}"
in
let s2 = render_exp_seq' env es in
let s2 = render_exp_seq' env at es in
if s1 <> "" && s2 <> "" then s1 ^ "\\," ^ s2 else s1 ^ s2
| e1::e2::es when is_atom_exp_with_show env e2 && es <> [] ->
render_exp_seq' env at [e1; SeqE (e2::es) $ at]
| e1::e2::es when env.config.display && e1.at.right.line < e2.at.left.line ->
let s1 = render_exp env e1 in
let s2 = render_exp_seq' env (e2::es) in
let s2 = render_exp_seq' env at (e2::es) in
s1 ^ " \\\\\n " ^ s2
| e1::es ->
let s1 = render_exp env e1 in
let s2 = render_exp_seq' env es in
let s2 = render_exp_seq' env at es in
if s1 <> "" && s2 <> "" then s1 ^ "~" ^ s2 else s1 ^ s2

and render_expfield env (atom, e) =
Expand Down
8 changes: 3 additions & 5 deletions spectec/src/frontend/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ and short_alt_prod' = function
%right EQ NE LT GT LE GE MEM EQSUB
%right ARROW ARROWSUB
%left SEMICOLON
%left DOTDOTDOT
%left DOT DOTDOT DOTDOTDOT
%left PLUS MINUS CAT
%left STAR SLASH BACKSLASH

Expand Down Expand Up @@ -308,10 +308,6 @@ atom_escape :
| BOT { Atom.Bot }
| TOP { Atom.Top }
| INFINITY { Atom.Infinity }
| DOT { Atom.Dot }
| DOTDOT { Atom.Dot2 }
| TICK DOT { Atom.Dot }
| TICK DOTDOT { Atom.Dot2 }

varid_bind_with_suffix :
| varid { $1 }
Expand Down Expand Up @@ -364,6 +360,8 @@ check_atom :
%inline infixop :
| infixop_ { $1 $$ $sloc }
%inline infixop_ :
| DOT { Atom.Dot }
| DOTDOT { Atom.Dot2 }
| DOTDOTDOT { Atom.Dot3 }
| SEMICOLON { Atom.Semicolon }
| BACKSLASH { Atom.Backslash }
Expand Down
Loading
Loading