aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2024-12-13 22:47:47 +0000
committerjohannst <johannst@users.noreply.github.com>2024-12-13 22:47:47 +0000
commit550a1794e9460467c474d56554b62942bf911a9c (patch)
tree58215b8e6267b7d4b9b690d031bdad07ab34f6c4
parentdd973aa72be71aac88e5449df3c82d5eeededbb5 (diff)
downloadjuicebox-asm-550a1794e9460467c474d56554b62942bf911a9c.tar.gz
juicebox-asm-550a1794e9460467c474d56554b62942bf911a9c.zip
deploy: 869761849ff64669244b6cbb79cac41f66654041
-rw-r--r--bf/index.html12
-rw-r--r--juicebox_asm/struct.Runtime.html12
-rw-r--r--src/bf/bf.rs.html44
-rw-r--r--src/juicebox_asm/rt.rs.html42
4 files changed, 62 insertions, 48 deletions
diff --git a/bf/index.html b/bf/index.html
index c79704e..a35065a 100644
--- a/bf/index.html
+++ b/bf/index.html
@@ -1,6 +1,5 @@
-<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Brainfuck VM."><title>bf - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b0742ba02757f159.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="bf" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0 (90b35a623 2024-11-26)" data-channel="1.83.0" data-search-js="search-f0d225181b97f9a4.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-f070b9041d14864c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../bf/index.html">bf</a><span class="version">0.1.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>bf</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/bf/bf.rs.html#1-404">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Brainfuck VM.</p>
-<p>This example implements a simple
-<a href="https://en.wikipedia.org/wiki/Brainfuck">brainfuck</a> interpreter
+<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Brainfuck VM."><title>bf - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b0742ba02757f159.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="bf" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0 (90b35a623 2024-11-26)" data-channel="1.83.0" data-search-js="search-f0d225181b97f9a4.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-f070b9041d14864c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../bf/index.html">bf</a><span class="version">0.1.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>bf</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/bf/bf.rs.html#1-411">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Brainfuck VM.</p>
+<p>This example implements a simple <a href="https://en.wikipedia.org/wiki/Brainfuck">brainfuck</a> interpreter
[<code>BrainfuckInterp</code>] and a jit compiler [<code>BrainfuckJit</code>].</p>
<p>Brainfuck is an esoteric programming languge existing of 8 commands.</p>
<ul>
@@ -10,7 +9,10 @@
<li><code>-</code> decrement data at current data pointer.</li>
<li><code>.</code> output data at current data pointer.</li>
<li><code>,</code> read input and store at current data pointer.</li>
-<li><code>[</code> jump behind matching ‘]’ if data at data pointer is zero.</li>
-<li><code>]</code> jump behind matching ‘[’ if data at data pointer is non-zero.</li>
+<li><code>[</code> jump behind matching <code>]</code> if data at data pointer is zero.</li>
+<li><code>]</code> jump behind matching <code>[</code> if data at data pointer is non-zero.</li>
</ul>
+<p>The following is the <code>hello-world</code> program from <a href="https://en.wikipedia.org/wiki/Brainfuck#Hello_World!">wikipedia</a>.</p>
+
+<div class="example-wrap"><pre class="rust rust-example-rendered"><code>++++++++[&gt;++++[&gt;++&gt;+++&gt;+++&gt;+&lt;&lt;&lt;&lt;-]&gt;+&gt;+&gt;-&gt;&gt;+[&lt;]&lt;-]&gt;&gt;.&gt;---.+++++++..+++.&gt;&gt;.&lt;-.&lt;.+++.------.--------.&gt;&gt;+.&gt;++.</code></pre></div>
</div></details></section></div></main></body></html> \ No newline at end of file
diff --git a/juicebox_asm/struct.Runtime.html b/juicebox_asm/struct.Runtime.html
index 8da3fb1..908c529 100644
--- a/juicebox_asm/struct.Runtime.html
+++ b/juicebox_asm/struct.Runtime.html
@@ -1,14 +1,14 @@
-<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A simple `mmap`ed runtime with executable pages."><title>Runtime in juicebox_asm - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b0742ba02757f159.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="juicebox_asm" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0 (90b35a623 2024-11-26)" data-channel="1.83.0" data-search-js="search-f0d225181b97f9a4.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-f070b9041d14864c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../juicebox_asm/index.html">juicebox_<wbr>asm</a><span class="version">0.1.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Runtime</a></h2><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.add_code" title="add_code">add_code</a></li><li><a href="#method.dump" title="dump">dump</a></li><li><a href="#method.new" title="new">new</a></li><li><a href="#method.with_profile" title="with_profile">with_profile</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Drop-for-Runtime" title="Drop">Drop</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Send-for-Runtime" title="!Send">!Send</a></li><li><a href="#impl-Sync-for-Runtime" title="!Sync">!Sync</a></li><li><a href="#impl-Freeze-for-Runtime" title="Freeze">Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-Runtime" title="RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Unpin-for-Runtime" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Runtime" title="UnwindSafe">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow&#60;T&#62;">Borrow&#60;T&#62;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut&#60;T&#62;">BorrowMut&#60;T&#62;</a></li><li><a href="#impl-From%3CT%3E-for-T" title="From&#60;T&#62;">From&#60;T&#62;</a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into&#60;U&#62;">Into&#60;U&#62;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom&#60;U&#62;">TryFrom&#60;U&#62;</a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto&#60;U&#62;">TryInto&#60;U&#62;</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate juicebox_<wbr>asm</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">juicebox_asm</a></span><h1>Struct <span class="struct">Runtime</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/juicebox_asm/rt.rs.html#57-62">source</a> </span></div><pre class="rust item-decl"><code>pub struct Runtime { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A simple <code>mmap</code>ed runtime with executable pages.</p>
-</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Runtime" class="impl"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#64-210">source</a><a href="#impl-Runtime" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#70-91">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h4></section></summary><div class="docblock"><p>Create a new <a href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a>.</p>
+<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A simple `mmap`ed runtime with executable pages."><title>Runtime in juicebox_asm - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b0742ba02757f159.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="juicebox_asm" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0 (90b35a623 2024-11-26)" data-channel="1.83.0" data-search-js="search-f0d225181b97f9a4.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-f070b9041d14864c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../juicebox_asm/index.html">juicebox_<wbr>asm</a><span class="version">0.1.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Runtime</a></h2><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.add_code" title="add_code">add_code</a></li><li><a href="#method.dump" title="dump">dump</a></li><li><a href="#method.new" title="new">new</a></li><li><a href="#method.with_profile" title="with_profile">with_profile</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Drop-for-Runtime" title="Drop">Drop</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-Send-for-Runtime" title="!Send">!Send</a></li><li><a href="#impl-Sync-for-Runtime" title="!Sync">!Sync</a></li><li><a href="#impl-Freeze-for-Runtime" title="Freeze">Freeze</a></li><li><a href="#impl-RefUnwindSafe-for-Runtime" title="RefUnwindSafe">RefUnwindSafe</a></li><li><a href="#impl-Unpin-for-Runtime" title="Unpin">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Runtime" title="UnwindSafe">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow&#60;T&#62;">Borrow&#60;T&#62;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut&#60;T&#62;">BorrowMut&#60;T&#62;</a></li><li><a href="#impl-From%3CT%3E-for-T" title="From&#60;T&#62;">From&#60;T&#62;</a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into&#60;U&#62;">Into&#60;U&#62;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom&#60;U&#62;">TryFrom&#60;U&#62;</a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto&#60;U&#62;">TryInto&#60;U&#62;</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate juicebox_<wbr>asm</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">juicebox_asm</a></span><h1>Struct <span class="struct">Runtime</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/juicebox_asm/rt.rs.html#55-60">source</a> </span></div><pre class="rust item-decl"><code>pub struct Runtime { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A simple <code>mmap</code>ed runtime with executable pages.</p>
+</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Runtime" class="impl"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#62-208">source</a><a href="#impl-Runtime" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#68-93">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h4></section></summary><div class="docblock"><p>Create a new <a href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a>.</p>
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
<p>Panics if the <code>mmap</code> call fails.</p>
-</div></details><details class="toggle method-toggle" open><summary><section id="method.with_profile" class="method"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#102-106">source</a><h4 class="code-header">pub fn <a href="#method.with_profile" class="fn">with_profile</a>() -&gt; <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h4></section></summary><div class="docblock"><p>Create a new <a href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a> which also generates static perf metat data.</p>
+</div></details><details class="toggle method-toggle" open><summary><section id="method.with_profile" class="method"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#104-108">source</a><h4 class="code-header">pub fn <a href="#method.with_profile" class="fn">with_profile</a>() -&gt; <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h4></section></summary><div class="docblock"><p>Create a new <a href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a> which also generates static perf metat data.</p>
<p>For each function added to the <a href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a>, an entry will be generated in the
<code>/tmp/perf-&lt;PID&gt;.map</code> file, which <code>perf report</code> uses to symbolicate unknown addresses.
This is applicable for static runtimes only.</p>
<h5 id="panics-1"><a class="doc-anchor" href="#panics-1">§</a>Panics</h5>
<p>Panics if the <code>mmap</code> call fails.</p>
-</div></details><details class="toggle method-toggle" open><summary><section id="method.add_code" class="method"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#129-155">source</a><h4 class="code-header">pub unsafe fn <a href="#method.add_code" class="fn">add_code</a>&lt;F&gt;(&amp;mut self, code: impl <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;[<a class="primitive" href="https://doc.rust-lang.org/1.83.0/std/primitive.u8.html">u8</a>]&gt;) -&gt; F</h4></section></summary><div class="docblock"><p>Add the block of <code>code</code> to the runtime and a get function pointer of type <code>F</code>.</p>
+</div></details><details class="toggle method-toggle" open><summary><section id="method.add_code" class="method"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#131-157">source</a><h4 class="code-header">pub unsafe fn <a href="#method.add_code" class="fn">add_code</a>&lt;F&gt;(&amp;mut self, code: impl <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;[<a class="primitive" href="https://doc.rust-lang.org/1.83.0/std/primitive.u8.html">u8</a>]&gt;) -&gt; F</h4></section></summary><div class="docblock"><p>Add the block of <code>code</code> to the runtime and a get function pointer of type <code>F</code>.</p>
<h5 id="panics-2"><a class="doc-anchor" href="#panics-2">§</a>Panics</h5>
<p>Panics if the <code>code</code> does not fit on the <code>mmap</code>ed pages or is empty.</p>
<h5 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h5>
@@ -21,13 +21,13 @@ pointer is only valid until the <a href="struct.Runtime.html" title="struct juic
<span class="kw">let </span>nop = <span class="kw">unsafe </span>{ rt.add_code::&lt;<span class="kw">extern </span><span class="string">"C" </span><span class="kw">fn</span>()&gt;(<span class="kw-2">&amp;</span>code) };
nop();</code></pre></div>
-</div></details><details class="toggle method-toggle" open><summary><section id="method.dump" class="method"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#169-173">source</a><h4 class="code-header">pub fn <a href="#method.dump" class="fn">dump</a>(&amp;self)</h4></section></summary><div class="docblock"><p>Dump the code added so far to the runtime into a file called <code>jit.asm</code> in the processes
+</div></details><details class="toggle method-toggle" open><summary><section id="method.dump" class="method"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#171-175">source</a><h4 class="code-header">pub fn <a href="#method.dump" class="fn">dump</a>(&amp;self)</h4></section></summary><div class="docblock"><p>Dump the code added so far to the runtime into a file called <code>jit.asm</code> in the processes
current working directory.</p>
<p>The code can be inspected with a disassembler as for example <code>ndiasm</code> from
<a href="https://nasm.us/index.php">nasm.us</a>.</p>
<div class="example-wrap"><pre class="language-sh"><code>ndisasm -b 64 jit.asm</code></pre></div><h5 id="panics-3"><a class="doc-anchor" href="#panics-3">§</a>Panics</h5>
<p>Panics if writing the file failed.</p>
-</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Drop-for-Runtime" class="impl"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#212-220">source</a><a href="#impl-Drop-for-Runtime" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/drop/trait.Drop.html" title="trait core::ops::drop::Drop">Drop</a> for <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#215-219">source</a><a href="#method.drop" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.83.0/core/ops/drop/trait.Drop.html#tymethod.drop" class="fn">drop</a>(&amp;mut self)</h4></section></summary><div class="docblock"><p>Unmaps the code page. This invalidates all the function pointer returned by
+</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Drop-for-Runtime" class="impl"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#210-219">source</a><a href="#impl-Drop-for-Runtime" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/ops/drop/trait.Drop.html" title="trait core::ops::drop::Drop">Drop</a> for <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl"><a class="src rightside" href="../src/juicebox_asm/rt.rs.html#213-218">source</a><a href="#method.drop" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.83.0/core/ops/drop/trait.Drop.html#tymethod.drop" class="fn">drop</a>(&amp;mut self)</h4></section></summary><div class="docblock"><p>Unmaps the code page. This invalidates all the function pointer returned by
<a href="struct.Runtime.html#method.add_code" title="method juicebox_asm::Runtime::add_code"><code>Runtime::add_code</code></a>.</p>
</div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-Runtime" class="impl"><a href="#impl-Freeze-for-Runtime" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section><section id="impl-RefUnwindSafe-for-Runtime" class="impl"><a href="#impl-RefUnwindSafe-for-Runtime" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section><section id="impl-Send-for-Runtime" class="impl"><a href="#impl-Send-for-Runtime" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section><section id="impl-Sync-for-Runtime" class="impl"><a href="#impl-Sync-for-Runtime" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section><section id="impl-Unpin-for-Runtime" class="impl"><a href="#impl-Unpin-for-Runtime" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section><section id="impl-UnwindSafe-for-Runtime" class="impl"><a href="#impl-UnwindSafe-for-Runtime" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Runtime.html" title="struct juicebox_asm::Runtime">Runtime</a></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.83.0/src/core/any.rs.html#138">source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.83.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.83.0/src/core/any.rs.html#139">source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.83.0/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.83.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.83.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.83.0/src/core/borrow.rs.html#209">source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.83.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T<div class="where">where
diff --git a/src/bf/bf.rs.html b/src/bf/bf.rs.html
index 556b131..8efe643 100644
--- a/src/bf/bf.rs.html
+++ b/src/bf/bf.rs.html
@@ -402,10 +402,16 @@
<a href="#401" id="401">401</a>
<a href="#402" id="402">402</a>
<a href="#403" id="403">403</a>
-<a href="#404" id="404">404</a></pre></div><pre class="rust"><code><span class="doccomment">//! Brainfuck VM.
+<a href="#404" id="404">404</a>
+<a href="#405" id="405">405</a>
+<a href="#406" id="406">406</a>
+<a href="#407" id="407">407</a>
+<a href="#408" id="408">408</a>
+<a href="#409" id="409">409</a>
+<a href="#410" id="410">410</a>
+<a href="#411" id="411">411</a></pre></div><pre class="rust"><code><span class="doccomment">//! Brainfuck VM.
//!
-//! This example implements a simple
-//! [brainfuck](https://en.wikipedia.org/wiki/Brainfuck) interpreter
+//! This example implements a simple [brainfuck][bf] interpreter
//! [`BrainfuckInterp`] and a jit compiler [`BrainfuckJit`].
//!
//! Brainfuck is an esoteric programming languge existing of 8 commands.
@@ -415,8 +421,16 @@
//! - `-` decrement data at current data pointer.
//! - `.` output data at current data pointer.
//! - `,` read input and store at current data pointer.
-//! - `[` jump behind matching ']' if data at data pointer is zero.
-//! - `]` jump behind matching '[' if data at data pointer is non-zero.
+//! - `[` jump behind matching `]` if data at data pointer is zero.
+//! - `]` jump behind matching `[` if data at data pointer is non-zero.
+//!
+//! The following is the `hello-world` program from [wikipedia][hw].
+//! ```
+//! ++++++++[&gt;++++[&gt;++&gt;+++&gt;+++&gt;+&lt;&lt;&lt;&lt;-]&gt;+&gt;+&gt;-&gt;&gt;+[&lt;]&lt;-]&gt;&gt;.&gt;---.+++++++..+++.&gt;&gt;.&lt;-.&lt;.+++.------.--------.&gt;&gt;+.&gt;++.
+//! ```
+//!
+//! [bf]: https://en.wikipedia.org/wiki/Brainfuck
+//! [hw]: https://en.wikipedia.org/wiki/Brainfuck#Hello_World!
</span><span class="kw">use </span>std::collections::HashMap;
<span class="kw">use </span>std::io::Write;
@@ -439,7 +453,7 @@
<span class="kw">fn </span>new(prog: <span class="kw-2">&amp;</span>str) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>, String&gt; {
<span class="comment">// Do a first pass over the bf program to filter whitespace and detect
// invalid tokens. Additionally validate all conditional branches, and
- // compute their branch target.
+ // compute their branch targets.
</span><span class="kw">let </span>(imem, branches) = {
<span class="comment">// Instruction memory holding the final bf program.
</span><span class="kw">let </span><span class="kw-2">mut </span>imem = Vec::new();
@@ -591,8 +605,8 @@
<span class="comment">// Move data memory pointer (argument on jit entry) into correct register.
</span>asm.mov(dmem_base, Reg64::rdi);
- <span class="comment">// Move data memory size into correct register.
- </span>asm.mov(dmem_size, Reg64::rsi);
+ <span class="comment">// Move data memory size (compile time constant) into correct register.
+ </span>asm.mov(dmem_size, Imm64::from(vm.dmem.len()));
<span class="comment">// Clear data memory index.
</span>asm.xor(dmem_idx, dmem_idx);
@@ -720,11 +734,11 @@
</span>pc += <span class="number">1</span>;
}
- <span class="kw">let </span><span class="kw-2">mut </span>ret_epilogue = Label::new();
+ <span class="kw">let </span><span class="kw-2">mut </span>epilogue = Label::new();
<span class="comment">// Successful return from bf program.
</span>asm.xor(Reg64::rax, Reg64::rax);
- asm.bind(<span class="kw-2">&amp;mut </span>ret_epilogue);
+ asm.bind(<span class="kw-2">&amp;mut </span>epilogue);
<span class="comment">// Restore callee saved registers before returning from jit.
</span>asm.pop(dmem_idx);
asm.pop(dmem_size);
@@ -734,12 +748,12 @@
<span class="comment">// Return because of data pointer overflow.
</span>asm.bind(<span class="kw-2">&amp;mut </span>oob_ov);
asm.mov(Reg64::rax, Imm64::from(<span class="number">1</span>));
- asm.jmp(<span class="kw-2">&amp;mut </span>ret_epilogue);
+ asm.jmp(<span class="kw-2">&amp;mut </span>epilogue);
<span class="comment">// Return because of data pointer underflow.
</span>asm.bind(<span class="kw-2">&amp;mut </span>oob_uv);
asm.mov(Reg64::rax, Imm64::from(<span class="number">2</span>));
- asm.jmp(<span class="kw-2">&amp;mut </span>ret_epilogue);
+ asm.jmp(<span class="kw-2">&amp;mut </span>epilogue);
<span class="kw">if </span>!label_stack.is_empty() {
<span class="macro">panic!</span>(<span class="string">"encountered un-balanced brackets, left-over '[' after jitting bf program"</span>)
@@ -747,11 +761,11 @@
<span class="comment">// Get function pointer to jitted bf program.
</span><span class="kw">let </span><span class="kw-2">mut </span>rt = Runtime::new();
- <span class="kw">let </span>bf_entry = <span class="kw">unsafe </span>{ rt.add_code::&lt;<span class="kw">extern </span><span class="string">"C" </span><span class="kw">fn</span>(<span class="kw-2">*mut </span>u8, usize) -&gt; u64&gt;(asm.into_code()) };
+ <span class="kw">let </span>bf_entry = <span class="kw">unsafe </span>{ rt.add_code::&lt;<span class="kw">extern </span><span class="string">"C" </span><span class="kw">fn</span>(<span class="kw-2">*mut </span>u8) -&gt; u64&gt;(asm.into_code()) };
<span class="comment">// Execute jitted bf program.
- </span><span class="kw">match </span>bf_entry(<span class="kw-2">&amp;mut </span>vm.dmem <span class="kw">as </span><span class="kw-2">*mut </span>u8, vm.dmem.len()) {
- <span class="number">0 </span>=&gt; {}
+ </span><span class="kw">match </span>bf_entry(<span class="kw-2">&amp;mut </span>vm.dmem <span class="kw">as </span><span class="kw-2">*mut </span>u8) {
+ <span class="number">0 </span>=&gt; { <span class="comment">/* success */ </span>}
<span class="number">1 </span>=&gt; <span class="macro">panic!</span>(<span class="string">"oob: data pointer overflow"</span>),
<span class="number">2 </span>=&gt; <span class="macro">panic!</span>(<span class="string">"oob: data pointer underflow"</span>),
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(),
diff --git a/src/juicebox_asm/rt.rs.html b/src/juicebox_asm/rt.rs.html
index 039fa77..b0fad10 100644
--- a/src/juicebox_asm/rt.rs.html
+++ b/src/juicebox_asm/rt.rs.html
@@ -266,8 +266,7 @@
<a href="#265" id="265">265</a>
<a href="#266" id="266">266</a>
<a href="#267" id="267">267</a>
-<a href="#268" id="268">268</a>
-<a href="#269" id="269">269</a></pre></div><pre class="rust"><code><span class="doccomment">//! Simple `mmap`ed runtime.
+<a href="#268" id="268">268</a></pre></div><pre class="rust"><code><span class="doccomment">//! Simple `mmap`ed runtime.
//!
//! This runtime supports adding code to executable pages and turn the added code into user
//! specified function pointer.
@@ -275,8 +274,6 @@
</span><span class="attr">#[cfg(not(target_os = <span class="string">"linux"</span>))]
</span><span class="macro">compile_error!</span>(<span class="string">"This runtime is only supported on linux"</span>);
-<span class="kw">use </span>nix::sys::mman::{mmap, mprotect, munmap, MapFlags, ProtFlags};
-
<span class="kw">mod </span>perf {
<span class="kw">use </span>std::fs;
<span class="kw">use </span>std::io::Write;
@@ -298,7 +295,7 @@
<span class="kw">impl </span>PerfMap {
<span class="doccomment">/// Create an empty perf map file.
</span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>new() -&gt; <span class="self">Self </span>{
- <span class="kw">let </span>name = <span class="macro">format!</span>(<span class="string">"/tmp/perf-{}.map"</span>, nix::unistd::getpid());
+ <span class="kw">let </span>name = <span class="macro">format!</span>(<span class="string">"/tmp/perf-{}.map"</span>, <span class="kw">unsafe </span>{ libc::getpid() });
<span class="kw">let </span>file = fs::OpenOptions::new()
.truncate(<span class="bool-val">true</span>)
.create(<span class="bool-val">true</span>)
@@ -338,22 +335,26 @@
/// Panics if the `mmap` call fails.
</span><span class="kw">pub fn </span>new() -&gt; Runtime {
<span class="comment">// Allocate a single page.
- </span><span class="kw">let </span>len = core::num::NonZeroUsize::new(<span class="number">4096</span>).expect(<span class="string">"Value is non zero"</span>);
+ </span><span class="kw">let </span>len = <span class="number">4096</span>;
<span class="kw">let </span>buf = <span class="kw">unsafe </span>{
- mmap(
- <span class="prelude-val">None</span>,
+ libc::mmap(
+ std::ptr::null_mut(),
len,
- ProtFlags::PROT_NONE,
- MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS,
+ libc::PROT_NONE,
+ libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
<span class="number">0</span>, <span class="comment">/* fd */
</span><span class="number">0</span>, <span class="comment">/* off */
- </span>)
- .expect(<span class="string">"Failed to mmap runtime code page"</span>) <span class="kw">as </span><span class="kw-2">*mut </span>u8
+ </span>) <span class="kw">as </span><span class="kw-2">*mut </span>u8
};
+ <span class="macro">assert_ne!</span>(
+ buf.cast(),
+ libc::MAP_FAILED,
+ <span class="string">"Failed to mmap runtime code page"
+ </span>);
Runtime {
buf,
- len: len.get(),
+ len,
idx: <span class="number">0</span>,
perf: <span class="prelude-val">None</span>,
}
@@ -455,12 +456,8 @@
</span><span class="kw">fn </span>protect(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw">unsafe </span>{
<span class="comment">// Remove write permissions from code page and allow to read-execute from it.
- </span>mprotect(
- <span class="self">self</span>.buf.cast(),
- <span class="self">self</span>.len,
- ProtFlags::PROT_READ | ProtFlags::PROT_EXEC,
- )
- .expect(<span class="string">"Failed to RX mprotect runtime code page"</span>);
+ </span><span class="kw">let </span>ret = libc::mprotect(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len, libc::PROT_READ | libc::PROT_EXEC);
+ <span class="macro">assert_eq!</span>(ret, <span class="number">0</span>, <span class="string">"Failed to RX mprotect runtime code page"</span>);
}
}
@@ -472,8 +469,8 @@
</span><span class="kw">fn </span>unprotect(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw">unsafe </span>{
<span class="comment">// Add write permissions to code page.
- </span>mprotect(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len, ProtFlags::PROT_WRITE)
- .expect(<span class="string">"Failed to W mprotect runtime code page"</span>);
+ </span><span class="kw">let </span>ret = libc::mprotect(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len, libc::PROT_WRITE);
+ <span class="macro">assert_eq!</span>(ret, <span class="number">0</span>, <span class="string">"Failed to W mprotect runtime code page"</span>);
}
}
}
@@ -483,7 +480,8 @@
/// [`Runtime::add_code`].
</span><span class="kw">fn </span>drop(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw">unsafe </span>{
- munmap(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len).expect(<span class="string">"Failed to munmap runtime"</span>);
+ <span class="kw">let </span>ret = libc::munmap(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len);
+ <span class="macro">assert_eq!</span>(ret, <span class="number">0</span>, <span class="string">"Failed to munmap runtime"</span>);
}
}
}