diff --git a/examples/buffer.html b/examples/buffer.html
deleted file mode 100644
index a9e46ee..0000000
--- a/examples/buffer.html
+++ /dev/null
@@ -1,51 +0,0 @@
-
-
-
-Examples - Buffer
-
-
-Buffer
-
-List - Source - WebAssembly
-
-
-
-
-
-
-
-
-
diff --git a/examples/buffer.py b/examples/buffer.py
deleted file mode 100644
index 8fe6570..0000000
--- a/examples/buffer.py
+++ /dev/null
@@ -1,7 +0,0 @@
-@exported
-def index(inp: bytes, idx: u32) -> u8:
- return inp[idx]
-
-@exported
-def length(inp: bytes) -> u32:
- return len(inp)
diff --git a/examples/crc32.html b/examples/crc32.html
index e78505c..c176fdf 100644
--- a/examples/crc32.html
+++ b/examples/crc32.html
@@ -2,245 +2,68 @@
Examples - CRC32
+
-Buffer
+ Examples - CRC32
-List - Source - WebAssembly
-
-Note: This tests performs some timing comparison, please wait a few seconds for the results.
-
+
-Measurement log
-AMD Ryzen 7 3700X 8-Core, Ubuntu 20.04, Linux 5.4.0-124-generic
-After optimizing fold over bytes by inlineing __subscript_bytes__
-
-
- Test
- Interpreter
- Setup
- WebAssembly
- Javascript
-
-
- Lynx * 65536
- Chromium 104.0.5112.101
- DevTools closed
- 5.70
- 12.45
-
-
- Lynx * 65536
- Firefox 103
- DevTools closed
- 5.16
- 5.72
-
-
- Lynx * 1048576
- Chromium 104.0.5112.101
- DevTools closed
- 95.65
- 203.60
-
-
- Lynx * 1048576
- Firefox 103
- DevTools closed
- 83.34
- 92.38
-
-
-Before optimizing fold over bytes by inlineing __subscript_bytes__
-
-
- Test
- Interpreter
- Setup
- WebAssembly
- Javascript
-
-
- Lynx * 65536
- Chromium 104.0.5112.101
- DevTools closed
- 9.35
- 12.56
-
-
- Lynx * 65536
- Chromium 104.0.5112.101
- DevTools open
- 14.71
- 12.72
-
-
- Lynx * 65536
- Chromium 104.0.5112.101
- Record page load
- 9.44
- 12.69
-
-
- Lynx * 65536
- Firefox 103
- DevTools closed
- 9.02
- 5.86
-
-
- Lynx * 65536
- Firefox 103
- DevTools open
- 9.01
- 5.83
-
-
- Lynx * 65536
- Firefox 103
- Record page load
- 72.41
- 5.85
-
+
+
+ This example shows a fold implementation of a cyclic redundancy check .
+ There are actually many variations of these CRCs - this one is specifically know as CRC-32/ISO-HDLC.
+
+
-
- Lynx * 1048576
- Chromium 104.0.5112.101
- DevTools closed
- 149.24
- 202.36
-
-
- Lynx * 1048576
- Firefox 103
- DevTools closed
- 145.01
- 91.44
-
-
+ Try it out!
+
+
+ Calculate
+
+
-Notes
-- Firefox seems faster than Chromium in my setup for Javascript, WebAssembly seems about the same.
-- Having DevTools open in Chromium seems to slow down the WebAssembly by about 30%, but not when doing a recording of the page load.
-- WebAssembly in Firefox seems to slow down when doing a recording of the page load, which makes sense, but the Javascript does not.
+
+
+ crc32("123456789") = cbf43926
+ crc32("Hello, world!") = ebe6c6e6
+ crc32("The quick brown fox jumps over the lazy dog") = 414fa339
+
-
+
-
+
diff --git a/examples/fib.html b/examples/fib.html
index 35c6109..f11a97d 100644
--- a/examples/fib.html
+++ b/examples/fib.html
@@ -1,55 +1,62 @@
+
Examples - Fibonacci
+
-Fibonacci
+ Examples - Fibonacci
- List - Source - WebAssembly
+
-
+
+ Try it out!
+
+
+ Calculate
+
+
-
-
+ for(let exmpl of document.querySelectorAll('a[data-n]') ) {
+ exmpl.addEventListener('click', event => {
+ exampleN.value = exmpl.getAttribute('data-n');
+ exampleClick.click();
+ });
+ }
+
diff --git a/examples/fib.py b/examples/fib.py
index af435c1..86898bb 100644
--- a/examples/fib.py
+++ b/examples/fib.py
@@ -13,7 +13,3 @@ def fib(n: u64) -> u64:
return 1
return helper(n - 1, 0, 1)
-
-@exported
-def testEntry() -> u64:
- return fib(40)
diff --git a/examples/fold.html b/examples/fold.html
deleted file mode 100644
index 0a9f93f..0000000
--- a/examples/fold.html
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-Examples - Fold
-
-
-Fold
-
-List - Source - WebAssembly
-
-
-
-
-
-
-
-
diff --git a/examples/fold.py b/examples/fold.py
deleted file mode 100644
index 58b4b83..0000000
--- a/examples/fold.py
+++ /dev/null
@@ -1,6 +0,0 @@
-def u8_or(l: u8, r: u8) -> u8:
- return l | r
-
-@exported
-def foldl_u8_or_1(b: bytes) -> u8:
- return foldl(u8_or, 1, b)
diff --git a/examples/imported.html b/examples/imported.html
deleted file mode 100644
index b0a6957..0000000
--- a/examples/imported.html
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-Examples - Imported
-
-
-Imported
-
-List - Source - WebAssembly
-
-
-
-
-
-
-
-
diff --git a/examples/imported.py b/examples/imported.py
deleted file mode 100644
index 4083986..0000000
--- a/examples/imported.py
+++ /dev/null
@@ -1,7 +0,0 @@
-@imported
-def log(no: i32) -> None:
- pass
-
-@exported
-def mult_and_log(a: i32, b: i32) -> None:
- return log(a * b)
diff --git a/examples/include.js b/examples/include.js
index 50f9324..fb8569e 100644
--- a/examples/include.js
+++ b/examples/include.js
@@ -1,3 +1,6 @@
+/***
+ * Allocates the given string in the given application's memory
+ */
function alloc_bytes(app, data)
{
let stdlib_types___alloc_bytes__ = app.instance.exports['stdlib.types.__alloc_bytes__']
@@ -14,85 +17,12 @@ function alloc_bytes(app, data)
return offset;
}
-function run_times(times, callback, tweak)
+/**
+ * WebAssembly's interface only gets you signed integers
+ *
+ * Getting unsigned values out requires some work.
+ */
+function i32_to_u32(n)
{
- let sum = 0;
- let max = 0;
- let min = 1000000000000000000;
- let values = [];
- for(let idx = 0; idx < times; idx += 1) {
- if( tweak ) {
- tweak();
- }
-
- const t0 = performance.now();
- let result = callback();
- const t1 = performance.now();
- let time = t1 - t0;
- sum += time;
- values.push({'time': time, 'result': result});
- max = max < time ? time : max;
- min = min > time ? time : min;
- }
- return {
- 'min': min,
- 'avg': sum / times,
- 'max': max,
- 'sum': sum,
- 'values': values,
- }
-}
-
-function test_result(is_pass, data)
-{
- data = data || {};
-
- let result_details = document.createElement('details');
-
- let result_summary = document.createElement('summary');
- result_summary.textContent =
- (is_pass ? 'Test passed: ' : 'Test failed: ')
- + (data.summary ?? '(no summary)')
- ;
- result_summary.setAttribute('style', is_pass ? 'background: green' : 'background: red');
- result_details.appendChild(result_summary);
-
- if( data.attributes ) {
- result_table(data, result_details);
- }
-
- let results = document.getElementById('results');
- results.appendChild(result_details);
-}
-
-function result_table(attributes, parent)
-{
- let table = document.createElement('table');
-
- Object.keys(attributes).forEach(idx => {
- let td0 = document.createElement('td');
- td0.setAttribute('style', 'vertical-align: top;');
- td0.textContent = idx;
- let td1 = document.createElement('td');
- if( typeof(attributes[idx]) == 'object' ) {
- let result_details = document.createElement('details');
-
- let result_summary = document.createElement('summary');
- result_summary.textContent = 'Show me';
- result_details.appendChild(result_summary);
-
- result_table(attributes[idx], result_details);
-
- td1.appendChild(result_details);
- } else {
- td1.textContent = attributes[idx];
- }
-
- let tr = document.createElement('tr');
- tr.appendChild(td0);
- tr.appendChild(td1);
-
- table.appendChild(tr);
- });
- parent.append(table);
+ return n >>> 0;
}
diff --git a/examples/index.html b/examples/index.html
index 96afa50..da397d3 100644
--- a/examples/index.html
+++ b/examples/index.html
@@ -1,19 +1,16 @@
+
Examples
+
Examples
-Standard
+
+Functions
-Technical
-
diff --git a/examples/main.css b/examples/main.css
new file mode 100644
index 0000000..dd97fef
--- /dev/null
+++ b/examples/main.css
@@ -0,0 +1,31 @@
+:root {
+ /* CSS HEX */
+ --seasalt: #fcfafaff;
+ --silver: #c8d3d5ff;
+ --powder-blue: #a4b8c4ff;
+ --slate-gray: #6e8387ff;
+ --dark-pastel-green: #0cca4aff;
+}
+
+body {
+ background-color: var(--seasalt);
+ color: var(--slate-gray);
+}
+
+a {
+ color: var(--dark-pastel-green);
+ text-decoration: none;
+ font-weight: bold;
+}
+
+.menu {
+ border: 1px solid var(--powder-blue);
+ border-width: 1px 0px;
+ padding: 0.2em;
+ margin: 0.2em 0;
+}
+
+h3 {
+ border-top: 1px solid var(--powder-blue);
+ padding-top: 0.3em;
+}
diff --git a/tests/integration/test_examples/test_buffer.py b/tests/integration/test_examples/test_buffer.py
deleted file mode 100644
index 95549ac..0000000
--- a/tests/integration/test_examples/test_buffer.py
+++ /dev/null
@@ -1,20 +0,0 @@
-import pytest
-
-from ..helpers import Suite
-
-
-@pytest.mark.slow_integration_test
-def test_index():
- with open('examples/buffer.py', 'r', encoding='ASCII') as fil:
- code_py = "\n" + fil.read()
-
- result = Suite(code_py).run_code(b'Hello, world!', 5, func_name='index')
- assert 44 == result.returned_value
-
-@pytest.mark.slow_integration_test
-def test_length():
- with open('examples/buffer.py', 'r', encoding='ASCII') as fil:
- code_py = "\n" + fil.read()
-
- result = Suite(code_py).run_code(b'Hello, world!', func_name='length')
- assert 13 == result.returned_value
diff --git a/tests/integration/test_examples/test_fib.py b/tests/integration/test_examples/test_fib.py
index 0e25ea3..d804c26 100644
--- a/tests/integration/test_examples/test_fib.py
+++ b/tests/integration/test_examples/test_fib.py
@@ -8,6 +8,6 @@ def test_fib():
with open('./examples/fib.py', 'r', encoding='UTF-8') as fil:
code_py = "\n" + fil.read()
- result = Suite(code_py).run_code()
+ result = Suite(code_py).run_code(40, func_name='fib')
assert 102334155 == result.returned_value