Browse Source

using the rust implementation: sen-colour

master
Inderjit Gill 1 year ago
parent
commit
d6fb0d7834
30 changed files with 9954 additions and 3745 deletions
  1. 1
    0
      .gitattributes
  2. 6
    3
      .gitignore
  3. 269
    0
      Cargo.lock
  4. 24
    0
      Cargo.toml
  5. 19
    4
      README.md
  6. 0
    641
      assets/index.html
  7. 9
    0
      bootstrap.js
  8. 0
    0
      css/base-min.css
  9. 0
    0
      css/pure-min.css
  10. 0
    0
      css/stylesheet.css
  11. 0
    4
      dist/.gitignore
  12. 0
    0
      favicon.ico
  13. 658
    0
      index.html
  14. 46
    43
      index.js
  15. 8833
    410
      package-lock.json
  16. 6
    11
      package.json
  17. 0
    1202
      src/c/ext/stb_sprintf.h
  18. 0
    832
      src/c/lib/colour.c
  19. 0
    30
      src/c/lib/colour.h
  20. 0
    18
      src/c/lib/config.h
  21. 0
    98
      src/c/lib/mathutil.c
  22. 0
    44
      src/c/lib/mathutil.h
  23. 0
    82
      src/c/lib/printf.c
  24. 0
    15
      src/c/lib/printf.h
  25. 0
    23
      src/c/lib/types.h
  26. 0
    45
      src/c/wasm.c
  27. 0
    28
      src/go/serve.go
  28. 0
    212
      src/js/wasm-loader.js
  29. 73
    0
      src/lib.rs
  30. 10
    0
      webpack.config.js

+ 1
- 0
.gitattributes View File

@@ -0,0 +1 @@
tetris.js -diff

+ 6
- 3
.gitignore View File

@@ -1,3 +1,6 @@
/node_modules
serve.exe
serve
/target
**/*.rs.bk

/node_modules/

wasm_themacs*

+ 269
- 0
Cargo.lock View File

@@ -0,0 +1,269 @@
[[package]]
name = "backtrace"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "backtrace-sys"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "cc"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "cfg-if"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "dtoa"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "failure"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "failure_derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
"synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "itoa"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "libc"
version = "0.2.40"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "proc-macro2"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "quote"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rustc-demangle"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "sen-colour"
version = "0.2.0"
dependencies = [
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "serde"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "serde_derive"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "serde_json"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.11.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "syn"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "synstructure"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "wasm-bindgen"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wasm-bindgen-macro 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-backend"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-macro"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-backend 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-shared 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm-bindgen-shared"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "wasm_themacs"
version = "0.1.0"
dependencies = [
"sen-colour 0.2.0",
"wasm-bindgen 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "winapi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[metadata]
"checksum backtrace 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea58cd16fd6c9d120b5bcb01d63883ae4cc7ba2aed35c1841b862a3c7ef6639"
"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
"checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba"
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum serde 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "c9bc5ad5d354bc43e8ba78885f81650e6d4467a55716271b49d7ceeba739e21e"
"checksum serde_derive 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "a0b9c70a763b79f976e7147322d6c523da0705b3d20e57fd764172d0741c50f2"
"checksum serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ad6d546e765177cf3dded3c2e424a8040f870083a0e64064746b958ece9cb1"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)" = "61b8f1b737f929c6516ba46a3133fd6d5215ad8a62f66760f851f7048aebedfb"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum wasm-bindgen 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b0271974d38e09a1e102d95a34a6b27a104ee77541c0314be7e91e026bff9e89"
"checksum wasm-bindgen-backend 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8e9a4a55017ec67b697893292efd05eb5f7e0ae26ddb4d9879eee6d60e66eb2b"
"checksum wasm-bindgen-macro 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "87e37cc5c09b0b58897ea69be6f81d1effb7ab22b34eb48626267471d8c4ec9e"
"checksum wasm-bindgen-shared 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "a629526dde66833247cfeb5fa2d5ea88f116cb05146f5039f6085784fdea679b"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

+ 24
- 0
Cargo.toml View File

@@ -0,0 +1,24 @@
[package]
name = "wasm_themacs"
version = "0.1.0"
authors = ["Inderjit Gill <inderjit.gill@gmail.com>"]

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2.8"
sen-colour = { path = "../sen-colour" }

[profile.release]
# Include function names in the `.wasm` for better debugging and
# profiling. Comment this out if you're trying to create the smallest `.wasm`
# binaries you can.
debug = true

# # Uncomment these lines to create smaller `.wasm` binaries, at the cost of
# # longer compile times.
# codegen-units = 1
# incremental = false
# lto = true
# opt-level = "z"

+ 19
- 4
README.md View File

@@ -1,7 +1,22 @@
Themacs
======

## Overview


$ npm install

$ npm run build:wasm
$ go build src/go/serve.go
## ensure that the correct toolchain is installed
```sh
$ rustup update
$ rustup install nightly
$ rustup target add wasm32-unknown-unknown --toolchain nightly
```

## npm bollocks
```sh
$ npm install
$ npm run build-debug
$ npm run serve
```

$ ./serve
can now visit http://localhost:8080

+ 0
- 641
assets/index.html View File

@@ -1,662 +0,0 @@
<!doctype html>
<html>
<head>
<title>Themacs</title>
<meta charset="utf-8">
<link rel="stylesheet" href="base-min.css">
<link rel="stylesheet" href="pure-min.css">
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<h1>Themacs</h1>


<div class="pure-g">
<div class="pure-u-1-2">
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
<li class="pure-menu-item pure-menu-selected"><a href="#" class="pure-menu-link pure-button" id="export-button">Export</a></li>
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
<a href="#" id="menuLink1" class="pure-menu-link">Emacs Mode</a>
<ul class="pure-menu-children">
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="show-c-mode">C</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="show-haskell-mode">Haskell</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="show-org-mode">Org</a></li>
</ul>
</li>
</ul>
</div>

<table id="colour-table" class="pure-table pure-table-horizontal">
<tr>
<th>Property</th>
<th>col</th>
<th>hex</th>
<th>H</th>
<th>S</th>
<th>L</th>
</tr>
</table>

<table class="pure-table pure-table-horizontal">
<tr>
<th>delta</th><th>value</th>
</tr>
<tr>
<td>bg hsl-1</td><td><input id="bg-hsl-l-delta" type="number" value="4"></td>
</tr>
<tr>
<td>fg hsl-1</td><td><input id="fg-hsl-l-delta" type="number" value="10"></td>
</tr>
<tr>
<td>func darkness</td><td><input id="func-darkness" type="number" value="10"></td>
</tr>
<tr>
<td>func saturate</td><td><input id="func-saturate" type="number" value="10"></td>
</tr>
<tr>
<td>comment darkness</td><td><input id="comment-darkness" type="number" value="15"></td>
</tr>
</table>


</div>
<div class="pure-u-1-2">
<div id="mode-container">
<pre id="mode-c" class="mode">
<span class="preprocessor">#include</span> <span class="string">"vm_compiler.h"</span>
<span class="preprocessor">#include</span> <span class="string">"colour.h"</span>
<span class="preprocessor">#include</span> <span class="string">"genetic.h"</span>
<span class="preprocessor">#include</span> <span class="string">"keyword_iname.h"</span>
<span class="preprocessor">#include</span> <span class="string">"lang.h"</span>
<span class="preprocessor">#include</span> <span class="string">"mathutil.h"</span>

<span class="preprocessor">#include</span> <span class="string">&lt;string.h&gt;</span>

<span class="type">i32</span> <span class="variable-name">opcode_offset</span>[] = {
<span class="preprocessor">#define</span> <span class="function-name">OPCODE</span>(<span class="variable-name">_</span>, <span class="variable-name">offset</span>) offset,
<span class="preprocessor">#include</span> <span class="string">"opcodes.h"</span>
<span class="preprocessor">#undef</span> OPCODE
};

<span class="type">bool</span> <span class="variable-name">g_use_genes</span>;
<span class="type">seni_program</span>* <span class="variable-name">g_preamble_program</span>;

<span class="type">void</span> <span class="function-name">compile_vector</span>(<span class="type">seni_node</span>* <span class="variable-name">ast</span>, <span class="type">seni_program</span>* <span class="variable-name">program</span>);
<span class="type">void</span> <span class="function-name">clear_global_mappings</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>);
<span class="type">void</span> <span class="function-name">clear_local_mappings</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>);
<span class="type">void</span> <span class="function-name">register_top_level_preamble</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>);
<span class="type">void</span> <span class="function-name">compile_preamble</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>);
seni_bytecode* program_emit_opcode_i32(seni_program* program, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">i32</span> <span class="variable-name">arg0</span>, <span class="type">i32</span> <span class="variable-name">arg1</span>);

<span class="type">void</span> <span class="function-name">compiler_subsystem_startup</span>() {
<span class="type">i32</span> <span class="variable-name">program_max_size</span> = 100; <span class="comment-delimiter">// </span><span class="comment">???
</span> <span class="type">seni_program</span>* <span class="variable-name">program</span> = program_allocate(program_max_size);

clear_global_mappings(program);
clear_local_mappings(program);
program-&gt;current_fn_info = <span class="constant">NULL</span>;

register_top_level_preamble(program);
compile_preamble(program);

<span class="comment-delimiter">// </span><span class="comment">slap a stop onto the end of this program
</span> program_emit_opcode_i32(program, STOP, 0, 0);

g_preamble_program = program;
}

<span class="type">void</span> <span class="function-name">compiler_subsystem_shutdown</span>() { program_free(g_preamble_program); }

<span class="type">seni_program</span>* <span class="function-name">get_preamble_program</span>() { <span class="keyword">return</span> g_preamble_program; }

<span class="type">void</span> <span class="function-name">gene_assign_to_node</span>(<span class="type">seni_genotype</span>* <span class="variable-name">genotype</span>, <span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="keyword">if</span> (node-&gt;alterable) {
<span class="keyword">if</span> (node-&gt;type == NODE_VECTOR) {
<span class="comment-delimiter">// </span><span class="comment">grab a gene for every element in this vector
</span> <span class="keyword">for</span> (<span class="type">seni_node</span>* <span class="variable-name">n</span> = safe_first_child(node); n != <span class="constant">NULL</span>; n = safe_next(n)) {
n-&gt;gene = genotype_pull_gene(genotype);
}
} <span class="keyword">else</span> {
node-&gt;gene = genotype_pull_gene(genotype);
}

} <span class="keyword">else</span> {
node-&gt;gene = <span class="constant">NULL</span>;

<span class="keyword">if</span> (get_node_value_in_use(node-&gt;type) == USE_FIRST_CHILD) {
<span class="type">seni_node</span>* <span class="variable-name">first_child</span> = safe_first(node-&gt;value.first_child);
<span class="keyword">if</span> (first_child) {
gene_assign_to_node(genotype, first_child);
}
}
}

<span class="comment-delimiter">// </span><span class="comment">todo: is it safe to assume that node-&gt;next will always be valid? and that
</span> <span class="comment-delimiter">// </span><span class="comment">leaf nodes will have next == null?
</span> <span class="keyword">if</span> (node-&gt;next) {
gene_assign_to_node(genotype, node-&gt;next);
}
}

<span class="type">bool</span> <span class="function-name">genotype_assign_to_ast</span>(<span class="type">seni_genotype</span>* <span class="variable-name">genotype</span>, <span class="type">seni_node</span>* <span class="variable-name">ast</span>) {
genotype-&gt;current_gene = genotype-&gt;genes;
gene_assign_to_node(genotype, ast);

<span class="comment-delimiter">// </span><span class="comment">current gene should be null since traversing the ast
</span> <span class="comment-delimiter">// </span><span class="comment">and assigning genes to alterable nodes should have
</span> <span class="comment-delimiter">// </span><span class="comment">resulted in all of the genes being assigned
</span> <span class="comment-delimiter">//</span><span class="comment">
</span> <span class="type">seni_gene</span>* <span class="variable-name">gene</span> = genotype-&gt;current_gene;
<span class="keyword">if</span> (gene != <span class="constant">NULL</span>) {
SENI_ERROR(<span class="string">"genotype_assign_to_ast: genes remaining after assigning "</span>
<span class="string">"genotype to ast"</span>);
<span class="keyword">return</span> <span class="constant">false</span>;
}

<span class="keyword">return</span> <span class="constant">true</span>;
}

<span class="type">i32</span> <span class="function-name">get_node_value_i32_from_gene</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="type">seni_gene</span>* <span class="variable-name">gene</span> = node-&gt;gene;
<span class="keyword">if</span> (gene == <span class="constant">NULL</span>) {
SENI_ERROR(<span class="string">"null gene returned"</span>);
<span class="keyword">return</span> 0;
}

<span class="keyword">return</span> gene-&gt;var-&gt;value.i;
}

<span class="type">f32</span> <span class="function-name">get_node_value_f32_from_gene</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="type">seni_gene</span>* <span class="variable-name">gene</span> = node-&gt;gene;
<span class="keyword">if</span> (gene == <span class="constant">NULL</span>) {
SENI_ERROR(<span class="string">"null gene returned"</span>);
<span class="keyword">return</span> 0.0f;
}

<span class="keyword">return</span> gene-&gt;var-&gt;value.f;
}

<span class="type">bool</span> <span class="function-name">alterable</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) { <span class="keyword">return</span> node-&gt;alterable &amp;&amp; g_use_genes; }

<span class="type">i32</span> <span class="function-name">get_node_value_i32</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="keyword">if</span> (alterable(node)) {
<span class="keyword">return</span> get_node_value_i32_from_gene(node);
} <span class="keyword">else</span> {
<span class="keyword">return</span> node-&gt;value.i;
}
}

<span class="type">f32</span> <span class="function-name">get_node_value_f32</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="keyword">if</span> (alterable(node)) {
<span class="keyword">return</span> get_node_value_f32_from_gene(node);
} <span class="keyword">else</span> {
<span class="keyword">return</span> node-&gt;value.f;
}
}

<span class="comment-delimiter">// </span><span class="comment">a temporary message for unimplemented alterable nodes
</span><span class="type">void</span> <span class="function-name">warn_if_alterable</span>(<span class="type">char</span>* <span class="variable-name">msg</span>, <span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="keyword">if</span> (node-&gt;alterable) {
SENI_ERROR(<span class="string">"warn_if_alterable: %s"</span>, msg);
}
}

<span class="type">seni_bytecode</span>*
<span class="function-name">program_emit_opcode</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">seni_var</span>* <span class="variable-name">arg0</span>, <span class="type">seni_var</span>* <span class="variable-name">arg1</span>) {
<span class="keyword">if</span> (program-&gt;code_size &gt;= program-&gt;code_max_size) {
SENI_ERROR(<span class="string">"%s %d program has reached max size"</span>, __FILE__, __LINE__);
<span class="keyword">return</span> <span class="constant">NULL</span>;
}

<span class="type">seni_bytecode</span>* <span class="variable-name">b</span> = &amp;(program-&gt;code[program-&gt;code_size++]);
b-&gt;op = op;
var_copy(&amp;(b-&gt;arg0), arg0);
var_copy(&amp;(b-&gt;arg1), arg1);

program-&gt;opcode_offset += opcode_offset[op];

<span class="keyword">return</span> b;
}

<span class="comment-delimiter">// </span><span class="comment">emits an &lt;opcode, i32, i32&gt; triplet
</span><span class="type">seni_bytecode</span>* <span class="function-name">program_emit_opcode_i32</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">i32</span> <span class="variable-name">arg0</span>, <span class="type">i32</span> <span class="variable-name">arg1</span>) {
<span class="keyword">if</span> (program-&gt;code_size &gt;= program-&gt;code_max_size) {
SENI_ERROR(<span class="string">"%s %d program has reached max size"</span>, __FILE__, __LINE__);
<span class="keyword">return</span> <span class="constant">NULL</span>;
}

<span class="type">seni_bytecode</span>* <span class="variable-name">b</span> = &amp;(program-&gt;code[program-&gt;code_size++]);
b-&gt;op = op;
i32_as_var(&amp;(b-&gt;arg0), arg0);
i32_as_var(&amp;(b-&gt;arg1), arg1);

program-&gt;opcode_offset += opcode_offset[op];

<span class="keyword">return</span> b;
}

<span class="comment-delimiter">// </span><span class="comment">emits an &lt;opcode, i32, name&gt; triplet
</span><span class="type">seni_bytecode</span>*
<span class="function-name">program_emit_opcode_i32_name</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">i32</span> <span class="variable-name">arg0</span>, <span class="type">i32</span> <span class="variable-name">name</span>) {
<span class="keyword">if</span> (program-&gt;code_size &gt;= program-&gt;code_max_size) {
SENI_ERROR(<span class="string">"%s %d program has reached max size"</span>, __FILE__, __LINE__);
<span class="keyword">return</span> <span class="constant">NULL</span>;
}

<span class="type">seni_bytecode</span>* <span class="variable-name">b</span> = &amp;(program-&gt;code[program-&gt;code_size++]);
b-&gt;op = op;
i32_as_var(&amp;(b-&gt;arg0), arg0);
name_as_var(&amp;(b-&gt;arg1), name);

program-&gt;opcode_offset += opcode_offset[op];

<span class="keyword">return</span> b;
}

<span class="comment-delimiter">// </span><span class="comment">emits an &lt;opcode, i32, f32&gt; triplet
</span><span class="type">seni_bytecode</span>*
<span class="function-name">program_emit_opcode_i32_f32</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">i32</span> <span class="variable-name">arg0</span>, <span class="type">f32</span> <span class="variable-name">arg1</span>) {
<span class="keyword">if</span> (program-&gt;code_size &gt;= program-&gt;code_max_size) {
SENI_ERROR(<span class="string">"%s %d program has reached max size"</span>, __FILE__, __LINE__);
<span class="keyword">return</span> <span class="constant">NULL</span>;
}

<span class="type">seni_bytecode</span>* <span class="variable-name">b</span> = &amp;(program-&gt;code[program-&gt;code_size++]);
b-&gt;op = op;
i32_as_var(&amp;(b-&gt;arg0), arg0);
f32_as_var(&amp;(b-&gt;arg1), arg1);

program-&gt;opcode_offset += opcode_offset[op];

<span class="keyword">return</span> b;
}
</pre> <!-- mode-c -->

<pre id="mode-haskell" class="mode">
<span class="haskell-pragma"><span class="sp-show-pair-match">{</span></span><span class="haskell-pragma">-# LANGUAGE BangPatterns, CPP, ScopedTypeVariables #-</span><span class="haskell-pragma"><span class="sp-show-pair-match">}</span></span>
<span class="doc">-- |
--
--
</span>
<span class="haskell-keyword">module</span> <span class="haskell-constructor">Data.Attoparsec.Internal</span>
( compareResults
, prompt
, demandInput
, demandInput_
, wantInput
, endOfInput
, atEnd
, satisfyElem
, concatReverse
) <span class="haskell-keyword">where</span>

<span class="preprocessor">#if !MIN_VERSION_base(4,8,0)
</span><span class="haskell-keyword">import</span> <span class="haskell-constructor">Control.Applicative</span> ((<span class="haskell-operator">&lt;$&gt;</span>))
<span class="haskell-keyword">import</span> <span class="haskell-constructor">Data.Monoid</span> (<span class="haskell-constructor">Monoid</span>, mconcat)
<span class="preprocessor">#endif
</span><span class="haskell-keyword">import</span> <span class="haskell-constructor">Data.Attoparsec.Internal.Types</span>
<span class="haskell-keyword">import</span> <span class="haskell-constructor">Data.ByteString</span> (<span class="haskell-constructor">ByteString</span>)
<span class="haskell-keyword">import</span> <span class="haskell-constructor">Data.Text</span> (<span class="haskell-constructor">Text</span>)
<span class="haskell-keyword">import</span> <span class="haskell-constructor">Prelude</span> <span class="haskell-keyword">hiding</span> (succ)

<span class="doc">-- | Compare two 'IResult' values for equality.
--
</span><span class="haskell-definition">compareResults</span> <span class="haskell-operator">::</span> (<span class="haskell-type">Eq</span> i, <span class="haskell-type">Eq</span> r) <span class="haskell-operator">=&gt;</span> <span class="haskell-type">IResult</span> i r <span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> i r <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Maybe</span> <span class="haskell-type">Bool</span>
<span class="haskell-definition">compareResults</span> (<span class="haskell-constructor">Fail</span> t0 ctxs0 msg0) (<span class="haskell-constructor">Fail</span> t1 ctxs1 msg1) <span class="haskell-operator">=</span>
<span class="haskell-constructor">Just</span> (t0 <span class="haskell-operator">==</span> t1 <span class="haskell-operator">&amp;&amp;</span> ctxs0 <span class="haskell-operator">==</span> ctxs1 <span class="haskell-operator">&amp;&amp;</span> msg0 <span class="haskell-operator">==</span> msg1)
<span class="haskell-definition">compareResults</span> (<span class="haskell-constructor">Done</span> t0 r0) (<span class="haskell-constructor">Done</span> t1 r1) <span class="haskell-operator">=</span>
<span class="haskell-constructor">Just</span> (t0 <span class="haskell-operator">==</span> t1 <span class="haskell-operator">&amp;&amp;</span> r0 <span class="haskell-operator">==</span> r1)
<span class="haskell-definition">compareResults</span> (<span class="haskell-constructor">Partial</span> <span class="haskell-keyword">_</span>) (<span class="haskell-constructor">Partial</span> <span class="haskell-keyword">_</span>) <span class="haskell-operator">=</span> <span class="haskell-constructor">Nothing</span>
<span class="haskell-definition">compareResults</span> <span class="haskell-keyword">_</span> <span class="haskell-keyword">_</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Just</span> <span class="haskell-constructor">False</span>

<span class="doc">-- | Ask for input. If we receive any, pass the augmented input to a
</span><span class="haskell-definition">prompt</span> <span class="haskell-operator">::</span> <span class="haskell-type">Chunk</span> t
<span class="haskell-operator">=&gt;</span> <span class="haskell-type">State</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Pos</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">More</span>
<span class="haskell-operator">-&gt;</span> (<span class="haskell-type">State</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Pos</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">More</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> t r)
<span class="haskell-operator">-&gt;</span> (<span class="haskell-type">State</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Pos</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">More</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> t r)
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> t r
<span class="haskell-definition">prompt</span> t pos _more lose succ <span class="haskell-operator">=</span> <span class="haskell-constructor">Partial</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>s <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">if</span> nullChunk s
<span class="haskell-keyword">then</span> lose t pos <span class="haskell-constructor">Complete</span>
<span class="haskell-keyword">else</span> succ (pappendChunk t s) pos <span class="haskell-constructor">Incomplete</span>
<span class="haskell-pragma">{-# SPECIALIZE prompt :: State ByteString -&gt; Pos -&gt; More
-&gt; (State ByteString -&gt; Pos -&gt; More
-&gt; IResult ByteString r)
-&gt; (State ByteString -&gt; Pos -&gt; More
-&gt; IResult ByteString r)
-&gt; IResult ByteString r #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE prompt :: State Text -&gt; Pos -&gt; More
-&gt; (State Text -&gt; Pos -&gt; More -&gt; IResult Text r)
-&gt; (State Text -&gt; Pos -&gt; More -&gt; IResult Text r)
-&gt; IResult Text r #-}</span>

<span class="doc">-- | Immediately demand more input via a 'Partial' continuation
</span><span class="haskell-definition">demandInput</span> <span class="haskell-operator">::</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t <span class="haskell-constructor">()</span>
<span class="haskell-definition">demandInput</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> more <span class="haskell-keyword">of</span>
<span class="haskell-constructor">Complete</span> <span class="haskell-operator">-&gt;</span> lose t pos more <span class="haskell-constructor">[]</span> <span class="string">"not enough input"</span>
<span class="haskell-keyword">_</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-keyword">let</span> lose' <span class="haskell-keyword">_</span> pos' more' <span class="haskell-operator">=</span> lose t pos' more' <span class="haskell-constructor">[]</span> <span class="string">"not enough input"</span>
succ' t' pos' more' <span class="haskell-operator">=</span> succ t' pos' more' <span class="haskell-constructor">()</span>
<span class="haskell-keyword">in</span> prompt t pos more lose' succ'
<span class="haskell-pragma">{-# SPECIALIZE demandInput :: Parser ByteString () #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE demandInput :: Parser Text () #-}</span>

<span class="doc">-- | Immediately demand more input via a 'Partial' continuation
</span><span class="haskell-definition">demandInput_</span> <span class="haskell-operator">::</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t t
<span class="haskell-definition">demandInput_</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> more <span class="haskell-keyword">of</span>
<span class="haskell-constructor">Complete</span> <span class="haskell-operator">-&gt;</span> lose t pos more <span class="haskell-constructor">[]</span> <span class="string">"not enough input"</span>
<span class="haskell-keyword">_</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-constructor">Partial</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>s <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">if</span> nullChunk s
<span class="haskell-keyword">then</span> lose t pos <span class="haskell-constructor">Complete</span> <span class="haskell-constructor">[]</span> <span class="string">"not enough input"</span>
<span class="haskell-keyword">else</span> succ (pappendChunk t s) pos more s
<span class="haskell-pragma">{-# SPECIALIZE demandInput_ :: Parser ByteString ByteString #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE demandInput_ :: Parser Text Text #-}</span>

<span class="doc">-- | This parser always succeeds. It returns 'True' if any input is
</span><span class="haskell-definition">wantInput</span> <span class="haskell-operator">::</span> <span class="haskell-keyword">forall</span> t <span class="haskell-operator">.</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t <span class="haskell-type">Bool</span>
<span class="haskell-definition">wantInput</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more _lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> <span class="haskell-constructor">()</span> <span class="haskell-keyword">of</span>
<span class="haskell-keyword">_</span> <span class="haskell-operator">|</span> pos <span class="haskell-operator">&lt;</span> atBufferEnd (undefined <span class="haskell-operator">::</span> t) t <span class="haskell-operator">-&gt;</span> succ t pos more <span class="haskell-constructor">True</span>
<span class="haskell-operator">|</span> more <span class="haskell-operator">==</span> <span class="haskell-constructor">Complete</span> <span class="haskell-operator">-&gt;</span> succ t pos more <span class="haskell-constructor">False</span>
<span class="haskell-operator">|</span> otherwise <span class="haskell-operator">-&gt;</span> <span class="haskell-keyword">let</span> lose' t' pos' more' <span class="haskell-operator">=</span> succ t' pos' more' <span class="haskell-constructor">False</span>
succ' t' pos' more' <span class="haskell-operator">=</span> succ t' pos' more' <span class="haskell-constructor">True</span>
<span class="haskell-keyword">in</span> prompt t pos more lose' succ'
<span class="haskell-pragma">{-# INLINE wantInput #-}</span>

<span class="doc">-- | Match only if all input has been consumed.
</span><span class="haskell-definition">endOfInput</span> <span class="haskell-operator">::</span> <span class="haskell-keyword">forall</span> t <span class="haskell-operator">.</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t <span class="haskell-constructor">()</span>
<span class="haskell-definition">endOfInput</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> <span class="haskell-constructor">()</span> <span class="haskell-keyword">of</span>
<span class="haskell-keyword">_</span><span class="haskell-operator">|</span> pos <span class="haskell-operator">&lt;</span> atBufferEnd (undefined <span class="haskell-operator">::</span> t) t <span class="haskell-operator">-&gt;</span> lose t pos more <span class="haskell-constructor">[]</span> <span class="string">"endOfInput"</span>
<span class="haskell-operator">|</span> more <span class="haskell-operator">==</span> <span class="haskell-constructor">Complete</span> <span class="haskell-operator">-&gt;</span> succ t pos more <span class="haskell-constructor">()</span>
<span class="haskell-operator">|</span> otherwise <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">let</span> lose' t' pos' more' _ctx _msg <span class="haskell-operator">=</span> succ t' pos' more' <span class="haskell-constructor">()</span>
succ' t' pos' more' _a <span class="haskell-operator">=</span> lose t' pos' more' <span class="haskell-constructor">[]</span> <span class="string">"endOfInput"</span>
<span class="haskell-keyword">in</span> runParser demandInput t pos more lose' succ'
<span class="haskell-pragma">{-# SPECIALIZE endOfInput :: Parser ByteString () #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE endOfInput :: Parser Text () #-}</span>

<span class="doc">-- | Return an indication of whether the end of input has been
</span><span class="haskell-definition">atEnd</span> <span class="haskell-operator">::</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t <span class="haskell-type">Bool</span>
<span class="haskell-definition">atEnd</span> <span class="haskell-operator">=</span> not <span class="haskell-operator">&lt;$&gt;</span> wantInput
<span class="haskell-pragma">{-# INLINE atEnd #-}</span>

<span class="haskell-definition">satisfySuspended</span> <span class="haskell-operator">::</span> <span class="haskell-keyword">forall</span> t r <span class="haskell-operator">.</span> <span class="haskell-type">Chunk</span> t
<span class="haskell-operator">=&gt;</span> (<span class="haskell-type">ChunkElem</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Bool</span>)
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">State</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Pos</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">More</span>
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">Failure</span> t (<span class="haskell-type">State</span> t) r
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">Success</span> t (<span class="haskell-type">State</span> t) (<span class="haskell-type">ChunkElem</span> t) r
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> t r
<span class="haskell-definition">satisfySuspended</span> p t pos more lose succ <span class="haskell-operator">=</span>
runParser (demandInput <span class="haskell-operator">&gt;&gt;</span> go) t pos more lose succ
<span class="haskell-keyword">where</span> go <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t' pos' more' lose' succ' <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> bufferElemAt (undefined <span class="haskell-operator">::</span> t) pos' t' <span class="haskell-keyword">of</span>
<span class="haskell-constructor">Just</span> (e, l) <span class="haskell-operator">|</span> p e <span class="haskell-operator">-&gt;</span> succ' t' (pos' <span class="haskell-operator">+</span> <span class="haskell-constructor">Pos</span> l) more' e
<span class="haskell-operator">|</span> otherwise <span class="haskell-operator">-&gt;</span> lose' t' pos' more' <span class="haskell-constructor">[]</span> <span class="string">"satisfyElem"</span>
<span class="haskell-constructor">Nothing</span> <span class="haskell-operator">-&gt;</span> runParser (demandInput <span class="haskell-operator">&gt;&gt;</span> go) t' pos' more' lose' succ'
<span class="haskell-pragma">{-# SPECIALIZE satisfySuspended :: (ChunkElem ByteString -&gt; Bool)
-&gt; State ByteString -&gt; Pos -&gt; More
-&gt; Failure ByteString (State ByteString) r
-&gt; Success ByteString (State ByteString)
(ChunkElem ByteString) r
-&gt; IResult ByteString r #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE satisfySuspended :: (ChunkElem Text -&gt; Bool)
-&gt; State Text -&gt; Pos -&gt; More
-&gt; Failure Text (State Text) r
-&gt; Success Text (State Text)
(ChunkElem Text) r
-&gt; IResult Text r #-}</span>

<span class="doc">-- | The parser @satisfyElem p@ succeeds for any chunk element for which the
</span><span class="haskell-definition">satisfyElem</span> <span class="haskell-operator">::</span> <span class="haskell-keyword">forall</span> t <span class="haskell-operator">.</span> <span class="haskell-type">Chunk</span> t
<span class="haskell-operator">=&gt;</span> (<span class="haskell-type">ChunkElem</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Bool</span>) <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Parser</span> t (<span class="haskell-type">ChunkElem</span> t)
<span class="haskell-definition">satisfyElem</span> p <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> bufferElemAt (undefined <span class="haskell-operator">::</span> t) pos t <span class="haskell-keyword">of</span>
<span class="haskell-constructor">Just</span> (e, l) <span class="haskell-operator">|</span> p e <span class="haskell-operator">-&gt;</span> succ t (pos <span class="haskell-operator">+</span> <span class="haskell-constructor">Pos</span> l) more e
<span class="haskell-operator">|</span> otherwise <span class="haskell-operator">-&gt;</span> lose t pos more <span class="haskell-constructor">[]</span> <span class="string">"satisfyElem"</span>
<span class="haskell-constructor">Nothing</span> <span class="haskell-operator">-&gt;</span> satisfySuspended p t pos more lose succ
<span class="haskell-pragma">{-# INLINE satisfyElem #-}</span>

<span class="doc">-- | Concatenate a monoid after reversing its elements. Used to
</span><span class="haskell-definition">concatReverse</span> <span class="haskell-operator">::</span> <span class="haskell-type">Monoid</span> m <span class="haskell-operator">=&gt;</span> [m] <span class="haskell-operator">-&gt;</span> m
<span class="haskell-definition">concatReverse</span> [x] <span class="haskell-operator">=</span> x
<span class="haskell-definition">concatReverse</span> xs <span class="haskell-operator">=</span> mconcat (reverse xs)
<span class="haskell-pragma">{-# INLINE concatReverse #-}</span>
</pre> <!-- mode-haskell -->

<pre id="mode-org" class="mode">
<span class="org-level-1">* web-app</span>...
<span class="org-level-1">* todo</span>...
<span class="org-level-1">* historically important people</span>
<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Zeno&gt;&gt;</span><span class="org-level-2"> of Elea</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

<span class="org-link"><a href="Aristotle">Aristotle</a></span> called him the inventor of the dialectic. He is best known for his paradoxes, which Bertrand Russell has described as "immeasurably subtle and profound."

Zeno's arguments are perhaps the first examples of a method of proof called reductio ad absurdum also known as proof by contradiction. They are also credited as a source of the dialectic method used by Socrates.

Suppose Homer wishes to walk to the end of a path. Before he can get there, he must get halfway there. Before he can get halfway there, he must get a quarter of the way there. Before traveling a quarter, he must travel one-eighth; before an eighth, one-sixteenth; and so on.
This description requires one to complete an infinite number of tasks, which Zeno maintains is an impossibility

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Aristotle&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

"We are what we repeatedly do. Excellence, then, is not an act, but a habit."
"It is the mark of an educated mind to be able to entertain a thought without accepting it."
"What is a friend? A single soul dwelling in two bodies."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Epicurus&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

For Epicurus, the purpose of philosophy was to attain the happy, tranquil life, characterized by ataraxia&#8212;peace and freedom from fear&#8212;and aponia&#8212;the absence of pain&#8212;and by living a self-sufficient life surrounded by friends. He taught that pleasure and pain are measures of what is good and evil; death is the end of both body and soul and therefore should not be feared; the gods neither reward nor punish humans; the universe is infinite and eternal; and events in the world are ultimately based on the motions and interactions of atoms moving in empty space.

In contrast to the Stoics, Epicureans showed little interest in participating in the politics of the day, since doing so leads to trouble. He instead advocated seclusion. This principle is epitomised by the phrase lathe bi&#333;sas (&#955;&#940;&#952;&#949; &#946;&#953;&#974;&#963;&#945;&#962;), meaning "live in obscurity", "get through life without drawing attention to yourself", i.e., live without pursuing glory or wealth or power, but anonymously, enjoying little things like food, the company of friends, etc. Plutarch elaborated on this theme in his essay Is the Saying "Live in Obscurity" Right?

<span class="org-link"><a href="http://slatestarcodex.com/2017/09/06/predictive-processing-and-perceptual-control/">http://slatestarcodex.com/2017/09/06/predictive-processing-and-perceptual-control/</a></span>
Epicurus gathered a bunch of philosophers and mathematicians into a small cult around him, who lived together in co-ed group houses preaching atheism and materialism and &#8211; as per the rumors &#8211; having orgies. If we&#8217;d just agreed he was right about everything from the start, we wouldn&#8217;t have had to laboriously reinvent his whole system.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Zeno of Citium&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Zeno was the original founder of the Stoic school of philosophy, which he taught in Athens from about 300 BCE. Based on the moral ideas of the Cynics, Stoicism laid great emphasis on goodness and peace of mind, gained from living a life of Virtue in accordance with Nature. It proved very successful, and flourished as the dominant philosophy from the Hellenistic period through to the Roman era.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Euclid&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Euclid was a Greek mathematician, often referred to as the "father of geometry". He was active in Alexandria during the reign of Ptolemy I (323-283 BCE). His Elements is one of the most influential works in the history of mathematics, serving as the main textbook for teaching mathematics (especially geometry) from the time of its publication until the late 19th or early 20th century. In the Elements, Euclid deduced the principles of what is now called Euclidean geometry from a small set of axioms. Euclid also wrote works on perspective, conic sections, spherical geometry, number theory and rigor.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Chrysippus of Soli&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

A Greek Stoic philosopher. He was a native of Soli, Cilicia, but moved to Athens as a young man, where he became a pupil of Cleanthes in the Stoic school. When Cleanthes died, around 230 BCE, Chrysippus became the third head of the school. A prolific writer, Chrysippus expanded the fundamental doctrines of <span class="org-link"><a href="Zeno of Citium">Zeno of Citium</a></span>, the founder of the school, which earned him the title of Second Founder of Stoicism.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Seneca&gt;&gt;</span><span class="org-level-2"> The Younger</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

A Roman Stoic philosopher, statesman, dramatist, and in one work humorist of the Silver Age of Latin literature. As a tragedian, he is best-known for his Medea and Thyestes.

He was a tutor and later advisor to emperor Nero. He was forced to take his own life for alleged complicity in the Pisonian conspiracy to assassinate Nero, in which he was likely to have been innocent. His stoic and calm suicide has become the subject of numerous paintings.

"Luck is what happens when preparation meets opportunity."

"Every new beginning comes from some other beginning's end."

"If one does not know to which port one is sailing, no wind is favorable."

"All cruelty springs from weakness."

"We are more often frightened than hurt; and we suffer more from imagination than from reality."

"Religion is regarded by the common people as true, by the wise as false, and by the rulers as useful."

"Sometimes even to live is an act of courage."

"Wherever there is a human being, there is an opportunity for a kindness."

"As is a tale, so is life: not how long it is, but how good it is, is what matters."

"It's not because things are difficult that we dare not venture. It's because we dare not venture that they are difficult."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Epictetus&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Epictetus was a Greek Stoic philosopher

To Epictetus, all external events are beyond our control; we should accept calmly and dispassionately whatever happens. However, individuals are responsible for their own actions, which they can examine and control through rigorous self-discipline

Epictetus maintains that the foundation of all philosophy is self-knowledge, that is, the conviction of our ignorance and gullibility ought to be the first subject of our study. Logic provides valid reasoning and certainty in judgment, but it is subordinate to practical needs.
- The first and most necessary part of philosophy concerns the application of doctrine, for example, that people should not lie.
- The second concerns reasons, e.g. why people should not lie.
- While the third, lastly, examines and establishes the reasons.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Augustine&gt;&gt;</span><span class="org-level-2"> of Hippo</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Augustine of Hippo, also known as Saint Augustine, Saint Austin, Blessed Augustine, and the Doctor of Grace, was an early Christian theologian and philosopher whose writings influenced the development of Western Christianity and Western philosophy.

"The world is a book, and those who do not travel read only a page."
"Faith is to believe what you do not yet see; the reward for this faith is to see what you believe."
"Since love grows within you, so beauty grows. For love is the beauty of the soul."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Cicero&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Marcus Tullius Cicero was a Roman philosopher, politician, lawyer, orator, political theorist, consul, and constitutionalist

"Gratitude is not only the greatest of virtues, but the parent of all others."
"A room without books is like a body without a soul."
"The life of the dead is placed in the memory of the living."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Marcus Aurelius&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Marcus Aurelius was Roman emperor from 161 to 180, ruling jointly with Lucius Verus until Verus' death in 169 and jointly with his son, Commodus, from 177. He was the last of the so-called Five Good Emperors.

He was a practitioner of Stoicism, and his untitled writing, commonly known as Meditations, is a significant source of our modern understanding of ancient Stoic philosophy. It is considered by many commentators to be one of the greatest works of philosophy.

His death in 180 is considered the end of the Pax Romana and the increasing instability in the west that followed has traditionally been seen as the beginning of the eventual Fall of the Western Roman Empire.

While on campaign between 170 and 180, Aurelius wrote his Meditations in Greek as a source for his own guidance and self-improvement. The original title of this work, if it had one, is unknown. "Meditations" as well as others, including "To Himself" were adopted later. He had a logical mind and his notes were representative of Stoic philosophy and spirituality. Meditations is still revered as a literary monument to a government of service and duty. The book was a favourite of Frederick the Great, John Stuart Mill, Matthew Arnold, and Goethe.


"We should always have these two rules in readiness: one, to do only whatever the reason of the ruling and legislating faculty [i.e. our rationality] may suggest for our use; the other, to change your opinion, if anyone sets you right and dissuades you from any opinion." (Meditations IV.12)

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Machiavelli&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Niccol&#242; di Bernardo dei Machiavelli was an Italian diplomat, politician, historian, philosopher, humanist, and writer of the Renaissance period. He has often been called the father of modern political science. He was for many years a senior official in the Florentine Republic, with responsibilities in diplomatic and military affairs. He also wrote comedies, carnival songs, and poetry. He was secretary to the Second Chancery of the Republic of Florence from 1498 to 1512, when the Medici were out of power. He wrote his most renowned work The Prince (Il Principe) in 1513.

"Machiavellianism" is a widely used negative term to characterize unscrupulous politicians of the sort Machiavelli described most famously in The Prince. Machiavelli described immoral behavior, such as dishonesty and killing innocents, as being normal and effective in politics. He even seemed to endorse it in some situations. The book itself gained notoriety when some readers claimed that the author was teaching evil, and providing "evil recommendations to tyrants to help them maintain their power". The term "Machiavellian" is often associated with political deceit, deviousness, and realpolitik. On the other hand, many commentators, such as Baruch Spinoza, Jean-Jacques Rousseau and Denis Diderot, have argued that Machiavelli was actually a republican, even when writing The Prince, and his writings were an inspiration to Enlightenment proponents of modern democratic political philosophy.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Hobbes&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Thomas Hobbes, was an English philosopher who is considered one of the founders of modern political philosophy. Hobbes is best known for his 1651 book Leviathan, which established the social contract theory that has served as the foundation for most later Western political philosophy. In addition to political philosophy, Hobbes also contributed to a diverse array of other fields, including history, jurisprudence, geometry, the physics of gases, theology, ethics, and general philosophy.

Though on rational grounds a champion of absolutism for the sovereign, Hobbes also developed some of the fundamentals of European liberal thought: the right of the individual; the natural equality of all men; the artificial character of the political order (which led to the later distinction between civil society and the state); the view that all legitimate political power must be "representative" and based on the consent of the people; and a liberal interpretation of law that leaves people free to do whatever the law does not explicitly forbid. His understanding of humans as being matter and motion, obeying the same physical laws as other matter and motion, remains influential; and his account of human nature as self-interested cooperation, and of political communities as being based upon a "social contract" remains one of the major topics of political philosophy.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Descartes&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Ren&#233; Descartes was a French philosopher, mathematician, and scientist. Dubbed the father of modern western philosophy, much of subsequent Western philosophy is a response to his writings, which are studied closely to this day

"It is not enough to have a good mind; the main thing is to use it well."
"The reading of all good books is like a conversation with the finest minds of past centuries."
"If you would be a real seeker after truth, it is necessary that at least once in your life you doubt, as far as possible, all things."

<span class="org-level-3">*** The Neuroscience of Consciousness &#8211; with Anil Seth</span>
<span class="org-link"><a href="https://www.youtube.com/watch?v=xRel1JKOEbI">https://www.youtube.com/watch?v=xRel1JKOEbI</a></span>

Descartes made the distinction between mind and matter:
res extensa - matter stuff (desk, clothes, brains)
res cogitans - the stuff of thought, feelings, consciousness

He said that only humans have minds and therefore moral status. Other animals were 'beast machines' - physiological machines, morally equivalent to plants or rocks.
This statement was disputed by Anil Seth in his talk
<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Locke&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

John Locke was an English philosopher and physician, widely regarded as one of the most influential of Enlightenment thinkers and commonly known as the "Father of Liberalism". Considered one of the first of the British empiricists, following the tradition of Sir Francis Bacon, he is equally important to social contract theory. His work greatly affected the development of epistemology and political philosophy. His writings influenced Voltaire and Jean-Jacques Rousseau, many Scottish Enlightenment thinkers, as well as the American revolutionaries. His contributions to classical republicanism and liberal theory are reflected in the United States Declaration of Independence.

Locke's theory of mind is often cited as the origin of modern conceptions of identity and the self, figuring prominently in the work of later philosophers such as David Hume, Rousseau, and Immanuel Kant. Locke was the first to define the self through a continuity of consciousness. He postulated that, at birth, the mind was a blank slate or tabula rasa. Contrary to Cartesian philosophy based on pre-existing concepts, he maintained that we are born without innate ideas, and that knowledge is instead determined only by experience derived from sense perception, This is now known as empiricism. An example of Locke belief in Empiricism can be seen in his quote : "whatever I write, as soon as I discover it not to be true, my hand shall be the forwardest to throw it into the fire". This shows the ideology of science in his observations in that something must be capable of being tested repeatedly and that nothing is exempt from being disproven. Challenging the work of others Locke is said to have established the method of Introspection (Observing the emotions and behaviours of one's self)

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Spinoza&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Baruch Spinoza born Benedito de Espinosa was a Dutch philosopher of Sephardi/Portuguese origin. By laying the groundwork for the 18th-century Enlightenment and modern biblical criticism, including modern conceptions of the self and the universe, he came to be considered one of the great rationalists of 17th-century philosophy.

Spinoza's magnum opus, the posthumous Ethics, in which he opposed <span class="org-link"><a href="Descartes">Descartes</a></span>' mind-body dualism, has earned him recognition as one of Western philosophy's most important thinkers. In the Ethics, "Spinoza wrote the last indisputable Latin masterpiece, and one in which the refined conceptions of medieval philosophy are finally turned against themselves and destroyed entirely." Hegel said, "You are either a Spinozist or not a philosopher at all." His philosophical accomplishments and moral character prompted 20th-century philosopher Gilles Deleuze to name him "the 'prince' of philosophers".

"Peace is not an absence of war, it is a virtue, a state of mind, a disposition for benevolence, confidence, justice."
"All things excellent are as difficult as they are rare."
"I have striven not to laugh at human actions, not to weep at them, nor to hate them, but to understand them."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Newton&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Isaac Newton was an English mathematician, astronomer, theologian and physicist (described in his own day as a "natural philosopher") who is widely recognised as one of the most influential scientists of all time and a key figure in the scientific revolution. His book Philosophi&#230; Naturalis Principia Mathematica ("Mathematical Principles of Natural Philosophy"), first published in 1687, laid the foundations of classical mechanics. Newton also made pathbreaking contributions to optics, and he shares credit with Gottfried Wilhelm <span class="org-link"><a href="Leibniz">Leibniz</a></span> for developing the infinitesimal calculus.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Leibniz&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Gottfried Wilhelm (von) Leibniz was a German polymath and philosopher who occupies a prominent place in the history of mathematics and the history of philosophy, having developed differential and integral calculus independently of Isaac Newton. Leibniz's notation has been widely used ever since it was published. It was only in the 20th century that his Law of Continuity and Transcendental Law of Homogeneity found mathematical implementation (by means of non-standard analysis). He became one of the most prolific inventors in the field of mechanical calculators. While working on adding automatic multiplication and division to Pascal's calculator, he was the first to describe a pinwheel calculator in 1685 and invented the Leibniz wheel, used in the arithmometer, the first mass-produced mechanical calculator. He also refined the binary number system, which is the foundation of virtually all digital computers.

In philosophy, Leibniz is most noted for his optimism, i.e. his conclusion that our Universe is, in a restricted sense, the best possible one that God could have created, an idea that was often lampooned by others such as <span class="org-link"><a href="Voltaire">Voltaire</a></span>. Leibniz, along with <span class="org-link"><a href="Ren&#233; Descartes">Ren&#233; Descartes</a></span> and Baruch <span class="org-link"><a href="Spinoza">Spinoza</a></span>, was one of the three great 17th-century advocates of rationalism. The work of Leibniz anticipated modern logic and analytic philosophy, but his philosophy also looks back to the scholastic tradition, in which conclusions are produced by applying reason to first principles or prior definitions rather than to empirical evidence.

Leibniz made major contributions to physics and technology, and anticipated notions that surfaced much later in philosophy, probability theory, biology, medicine, geology, psychology, linguistics, and computer science. He wrote works on philosophy, politics, law, ethics, theology, history, and philology. Leibniz also contributed to the field of library science. While serving as overseer of the Wolfenb&#252;ttel library in Germany, he devised a cataloging system that would serve as a guide for many of Europe's largest libraries. Leibniz's contributions to this vast array of subjects were scattered in various learned journals, in tens of thousands of letters, and in unpublished manuscripts. He wrote in several languages, but primarily in Latin, French, and German.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Hume&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Hume held that passion rather than reason governs human behaviour and argued against the existence of innate ideas, positing that all human knowledge is ultimately founded solely in experience; Hume thus held that genuine knowledge must either be directly traceable to objects perceived in experience, or result from abstract reasoning about relations between ideas which are derived from experience, calling the rest "nothing but sophistry and illusion", a dichotomy later given the name Hume's fork.

<span class="org-link"><a href="https://www.youtube.com/watch?v=_DGdDQrXv5U">https://www.youtube.com/watch?v=_DGdDQrXv5U</a></span>
You can never change someone's mind with just reasoning and logic

Since practical reason is supposed to regulate our actions (in theory), Hume denied practical reason on the grounds that reason cannot directly oppose passions. As Hume puts it, "Reason is, and ought only to be the slave of the passions, and can never pretend to any other office than to serve and obey them." Reason is less significant than any passion because reason has no original influence, while "A passion is an original existence, or, if you will, modification of existence".

The way of changing someone's mind is to first speak to their intuitions and affections

--------------------------------------------------

<span class="org-link"><a href="https://www.theatlantic.com/magazine/archive/2017/01/what-makes-things-cool/508772/">https://www.theatlantic.com/magazine/archive/2017/01/what-makes-things-cool/508772/</a></span>
David Hume, the 18th-century philosopher, considered the search for formulas to be absurd, because the perception of beauty was purely subjective, residing in individuals, not in the fabric of the universe. "To seek the real beauty, or real deformity," he said, "is as fruitless an enquiry, as to pretend to ascertain the real sweet or real bitter."

--------------------------------------------------

Peter Singer claims that Hume's argument that morals cannot have a rational basis alone "would have been enough to earn him a place in the history of ethics"
</pre> <!-- mode-org -->

</div> <!-- mode-container -->

</div>
</div>


<script src="js/main.js"></script>
<script src="js/wasm-loader.js"></script>
</body>
</html>

+ 9
- 0
bootstrap.js View File

@@ -0,0 +1,9 @@
const index = import("./index");
index.then(() => {
console.log("Loaded...");
});


document.addEventListener('DOMContentLoaded', () => {
console.log('DOMContentLoaded');
}, false);

assets/base-min.css → css/base-min.css View File


assets/pure-min.css → css/pure-min.css View File


assets/stylesheet.css → css/stylesheet.css View File


+ 0
- 4
dist/.gitignore View File

@@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

assets/favicon.ico → favicon.ico View File


+ 658
- 0
index.html View File

@@ -0,0 +1,658 @@
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
<title>Themacs</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/base-min.css">
<link rel="stylesheet" href="css/pure-min.css">
<link rel="stylesheet" href="css/stylesheet.css">
</head>
<body>
<h1>Themacs</h1>
<div class="pure-g">
<div class="pure-u-1-2">
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
<li class="pure-menu-item pure-menu-selected"><a href="#" class="pure-menu-link pure-button" id="export-button">Export</a></li>
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
<a href="#" id="menuLink1" class="pure-menu-link">Emacs Mode</a>
<ul class="pure-menu-children">
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="show-c-mode">C</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="show-haskell-mode">Haskell</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="show-org-mode">Org</a></li>
</ul>
</li>
</ul>
</div>

<table id="colour-table" class="pure-table pure-table-horizontal">
<tr>
<th>Property</th>
<th>col</th>
<th>hex</th>
<th>H</th>
<th>S</th>
<th>L</th>
</tr>
</table>

<table class="pure-table pure-table-horizontal">
<tr>
<th>delta</th><th>value</th>
</tr>
<tr>
<td>bg hsl-1</td><td><input id="bg-hsl-l-delta" type="number" value="4"></td>
</tr>
<tr>
<td>fg hsl-1</td><td><input id="fg-hsl-l-delta" type="number" value="10"></td>
</tr>
<tr>
<td>func darkness</td><td><input id="func-darkness" type="number" value="10"></td>
</tr>
<tr>
<td>func saturate</td><td><input id="func-saturate" type="number" value="10"></td>
</tr>
<tr>
<td>comment darkness</td><td><input id="comment-darkness" type="number" value="15"></td>
</tr>
</table>


</div>
<div class="pure-u-1-2">
<div id="mode-container">
<pre id="mode-c" class="mode">
<span class="preprocessor">#include</span> <span class="string">"vm_compiler.h"</span>
<span class="preprocessor">#include</span> <span class="string">"colour.h"</span>
<span class="preprocessor">#include</span> <span class="string">"genetic.h"</span>
<span class="preprocessor">#include</span> <span class="string">"keyword_iname.h"</span>
<span class="preprocessor">#include</span> <span class="string">"lang.h"</span>
<span class="preprocessor">#include</span> <span class="string">"mathutil.h"</span>

<span class="preprocessor">#include</span> <span class="string">&lt;string.h&gt;</span>

<span class="type">i32</span> <span class="variable-name">opcode_offset</span>[] = {
<span class="preprocessor">#define</span> <span class="function-name">OPCODE</span>(<span class="variable-name">_</span>, <span class="variable-name">offset</span>) offset,
<span class="preprocessor">#include</span> <span class="string">"opcodes.h"</span>
<span class="preprocessor">#undef</span> OPCODE
};

<span class="type">bool</span> <span class="variable-name">g_use_genes</span>;
<span class="type">seni_program</span>* <span class="variable-name">g_preamble_program</span>;

<span class="type">void</span> <span class="function-name">compile_vector</span>(<span class="type">seni_node</span>* <span class="variable-name">ast</span>, <span class="type">seni_program</span>* <span class="variable-name">program</span>);
<span class="type">void</span> <span class="function-name">clear_global_mappings</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>);
<span class="type">void</span> <span class="function-name">clear_local_mappings</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>);
<span class="type">void</span> <span class="function-name">register_top_level_preamble</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>);
<span class="type">void</span> <span class="function-name">compile_preamble</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>);
seni_bytecode* program_emit_opcode_i32(seni_program* program, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">i32</span> <span class="variable-name">arg0</span>, <span class="type">i32</span> <span class="variable-name">arg1</span>);

<span class="type">void</span> <span class="function-name">compiler_subsystem_startup</span>() {
<span class="type">i32</span> <span class="variable-name">program_max_size</span> = 100; <span class="comment-delimiter">// </span><span class="comment">???
</span> <span class="type">seni_program</span>* <span class="variable-name">program</span> = program_allocate(program_max_size);

clear_global_mappings(program);
clear_local_mappings(program);
program-&gt;current_fn_info = <span class="constant">NULL</span>;

register_top_level_preamble(program);
compile_preamble(program);

<span class="comment-delimiter">// </span><span class="comment">slap a stop onto the end of this program
</span> program_emit_opcode_i32(program, STOP, 0, 0);

g_preamble_program = program;
}

<span class="type">void</span> <span class="function-name">compiler_subsystem_shutdown</span>() { program_free(g_preamble_program); }

<span class="type">seni_program</span>* <span class="function-name">get_preamble_program</span>() { <span class="keyword">return</span> g_preamble_program; }

<span class="type">void</span> <span class="function-name">gene_assign_to_node</span>(<span class="type">seni_genotype</span>* <span class="variable-name">genotype</span>, <span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="keyword">if</span> (node-&gt;alterable) {
<span class="keyword">if</span> (node-&gt;type == NODE_VECTOR) {
<span class="comment-delimiter">// </span><span class="comment">grab a gene for every element in this vector
</span> <span class="keyword">for</span> (<span class="type">seni_node</span>* <span class="variable-name">n</span> = safe_first_child(node); n != <span class="constant">NULL</span>; n = safe_next(n)) {
n-&gt;gene = genotype_pull_gene(genotype);
}
} <span class="keyword">else</span> {
node-&gt;gene = genotype_pull_gene(genotype);
}

} <span class="keyword">else</span> {
node-&gt;gene = <span class="constant">NULL</span>;

<span class="keyword">if</span> (get_node_value_in_use(node-&gt;type) == USE_FIRST_CHILD) {
<span class="type">seni_node</span>* <span class="variable-name">first_child</span> = safe_first(node-&gt;value.first_child);
<span class="keyword">if</span> (first_child) {
gene_assign_to_node(genotype, first_child);
}
}
}

<span class="comment-delimiter">// </span><span class="comment">todo: is it safe to assume that node-&gt;next will always be valid? and that
</span> <span class="comment-delimiter">// </span><span class="comment">leaf nodes will have next == null?
</span> <span class="keyword">if</span> (node-&gt;next) {
gene_assign_to_node(genotype, node-&gt;next);
}
}

<span class="type">bool</span> <span class="function-name">genotype_assign_to_ast</span>(<span class="type">seni_genotype</span>* <span class="variable-name">genotype</span>, <span class="type">seni_node</span>* <span class="variable-name">ast</span>) {
genotype-&gt;current_gene = genotype-&gt;genes;
gene_assign_to_node(genotype, ast);

<span class="comment-delimiter">// </span><span class="comment">current gene should be null since traversing the ast
</span> <span class="comment-delimiter">// </span><span class="comment">and assigning genes to alterable nodes should have
</span> <span class="comment-delimiter">// </span><span class="comment">resulted in all of the genes being assigned
</span> <span class="comment-delimiter">//</span><span class="comment">
</span> <span class="type">seni_gene</span>* <span class="variable-name">gene</span> = genotype-&gt;current_gene;
<span class="keyword">if</span> (gene != <span class="constant">NULL</span>) {
SENI_ERROR(<span class="string">"genotype_assign_to_ast: genes remaining after assigning "</span>
<span class="string">"genotype to ast"</span>);
<span class="keyword">return</span> <span class="constant">false</span>;
}

<span class="keyword">return</span> <span class="constant">true</span>;
}

<span class="type">i32</span> <span class="function-name">get_node_value_i32_from_gene</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="type">seni_gene</span>* <span class="variable-name">gene</span> = node-&gt;gene;
<span class="keyword">if</span> (gene == <span class="constant">NULL</span>) {
SENI_ERROR(<span class="string">"null gene returned"</span>);
<span class="keyword">return</span> 0;
}

<span class="keyword">return</span> gene-&gt;var-&gt;value.i;
}

<span class="type">f32</span> <span class="function-name">get_node_value_f32_from_gene</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="type">seni_gene</span>* <span class="variable-name">gene</span> = node-&gt;gene;
<span class="keyword">if</span> (gene == <span class="constant">NULL</span>) {
SENI_ERROR(<span class="string">"null gene returned"</span>);
<span class="keyword">return</span> 0.0f;
}

<span class="keyword">return</span> gene-&gt;var-&gt;value.f;
}

<span class="type">bool</span> <span class="function-name">alterable</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) { <span class="keyword">return</span> node-&gt;alterable &amp;&amp; g_use_genes; }

<span class="type">i32</span> <span class="function-name">get_node_value_i32</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="keyword">if</span> (alterable(node)) {
<span class="keyword">return</span> get_node_value_i32_from_gene(node);
} <span class="keyword">else</span> {
<span class="keyword">return</span> node-&gt;value.i;
}
}

<span class="type">f32</span> <span class="function-name">get_node_value_f32</span>(<span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="keyword">if</span> (alterable(node)) {
<span class="keyword">return</span> get_node_value_f32_from_gene(node);
} <span class="keyword">else</span> {
<span class="keyword">return</span> node-&gt;value.f;
}
}

<span class="comment-delimiter">// </span><span class="comment">a temporary message for unimplemented alterable nodes
</span><span class="type">void</span> <span class="function-name">warn_if_alterable</span>(<span class="type">char</span>* <span class="variable-name">msg</span>, <span class="type">seni_node</span>* <span class="variable-name">node</span>) {
<span class="keyword">if</span> (node-&gt;alterable) {
SENI_ERROR(<span class="string">"warn_if_alterable: %s"</span>, msg);
}
}

<span class="type">seni_bytecode</span>*
<span class="function-name">program_emit_opcode</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">seni_var</span>* <span class="variable-name">arg0</span>, <span class="type">seni_var</span>* <span class="variable-name">arg1</span>) {
<span class="keyword">if</span> (program-&gt;code_size &gt;= program-&gt;code_max_size) {
SENI_ERROR(<span class="string">"%s %d program has reached max size"</span>, __FILE__, __LINE__);
<span class="keyword">return</span> <span class="constant">NULL</span>;
}

<span class="type">seni_bytecode</span>* <span class="variable-name">b</span> = &amp;(program-&gt;code[program-&gt;code_size++]);
b-&gt;op = op;
var_copy(&amp;(b-&gt;arg0), arg0);
var_copy(&amp;(b-&gt;arg1), arg1);

program-&gt;opcode_offset += opcode_offset[op];

<span class="keyword">return</span> b;
}

<span class="comment-delimiter">// </span><span class="comment">emits an &lt;opcode, i32, i32&gt; triplet
</span><span class="type">seni_bytecode</span>* <span class="function-name">program_emit_opcode_i32</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">i32</span> <span class="variable-name">arg0</span>, <span class="type">i32</span> <span class="variable-name">arg1</span>) {
<span class="keyword">if</span> (program-&gt;code_size &gt;= program-&gt;code_max_size) {
SENI_ERROR(<span class="string">"%s %d program has reached max size"</span>, __FILE__, __LINE__);
<span class="keyword">return</span> <span class="constant">NULL</span>;
}

<span class="type">seni_bytecode</span>* <span class="variable-name">b</span> = &amp;(program-&gt;code[program-&gt;code_size++]);
b-&gt;op = op;
i32_as_var(&amp;(b-&gt;arg0), arg0);
i32_as_var(&amp;(b-&gt;arg1), arg1);

program-&gt;opcode_offset += opcode_offset[op];

<span class="keyword">return</span> b;
}

<span class="comment-delimiter">// </span><span class="comment">emits an &lt;opcode, i32, name&gt; triplet
</span><span class="type">seni_bytecode</span>*
<span class="function-name">program_emit_opcode_i32_name</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">i32</span> <span class="variable-name">arg0</span>, <span class="type">i32</span> <span class="variable-name">name</span>) {
<span class="keyword">if</span> (program-&gt;code_size &gt;= program-&gt;code_max_size) {
SENI_ERROR(<span class="string">"%s %d program has reached max size"</span>, __FILE__, __LINE__);
<span class="keyword">return</span> <span class="constant">NULL</span>;
}

<span class="type">seni_bytecode</span>* <span class="variable-name">b</span> = &amp;(program-&gt;code[program-&gt;code_size++]);
b-&gt;op = op;
i32_as_var(&amp;(b-&gt;arg0), arg0);
name_as_var(&amp;(b-&gt;arg1), name);

program-&gt;opcode_offset += opcode_offset[op];

<span class="keyword">return</span> b;
}

<span class="comment-delimiter">// </span><span class="comment">emits an &lt;opcode, i32, f32&gt; triplet
</span><span class="type">seni_bytecode</span>*
<span class="function-name">program_emit_opcode_i32_f32</span>(<span class="type">seni_program</span>* <span class="variable-name">program</span>, <span class="type">seni_opcode</span> <span class="variable-name">op</span>, <span class="type">i32</span> <span class="variable-name">arg0</span>, <span class="type">f32</span> <span class="variable-name">arg1</span>) {
<span class="keyword">if</span> (program-&gt;code_size &gt;= program-&gt;code_max_size) {
SENI_ERROR(<span class="string">"%s %d program has reached max size"</span>, __FILE__, __LINE__);
<span class="keyword">return</span> <span class="constant">NULL</span>;
}

<span class="type">seni_bytecode</span>* <span class="variable-name">b</span> = &amp;(program-&gt;code[program-&gt;code_size++]);
b-&gt;op = op;
i32_as_var(&amp;(b-&gt;arg0), arg0);
f32_as_var(&amp;(b-&gt;arg1), arg1);

program-&gt;opcode_offset += opcode_offset[op];

<span class="keyword">return</span> b;
}
</pre> <!-- mode-c -->

<pre id="mode-haskell" class="mode">
<span class="haskell-pragma"><span class="sp-show-pair-match">{</span></span><span class="haskell-pragma">-# LANGUAGE BangPatterns, CPP, ScopedTypeVariables #-</span><span class="haskell-pragma"><span class="sp-show-pair-match">}</span></span>
<span class="doc">-- |
-- Module : Data.Attoparsec.Internal
-- Copyright : Bryan O'Sullivan 2007-2015
-- License : BSD3
--
-- Maintainer : bos@serpentine.com
-- Stability : experimental
-- Portability : unknown
--
-- Simple, efficient parser combinators, loosely based on the Parsec
-- library.
</span>
<span class="haskell-keyword">module</span> <span class="haskell-constructor">Data.Attoparsec.Internal</span>
( compareResults
, prompt
, demandInput
, demandInput_
, wantInput
, endOfInput
, atEnd
, satisfyElem
, concatReverse
) <span class="haskell-keyword">where</span>

<span class="preprocessor">#if !MIN_VERSION_base(4,8,0)
</span><span class="haskell-keyword">import</span> <span class="haskell-constructor">Control.Applicative</span> ((<span class="haskell-operator">&lt;$&gt;</span>))
<span class="haskell-keyword">import</span> <span class="haskell-constructor">Data.Monoid</span> (<span class="haskell-constructor">Monoid</span>, mconcat)
<span class="preprocessor">#endif
</span><span class="haskell-keyword">import</span> <span class="haskell-constructor">Data.Attoparsec.Internal.Types</span>
<span class="haskell-keyword">import</span> <span class="haskell-constructor">Data.ByteString</span> (<span class="haskell-constructor">ByteString</span>)
<span class="haskell-keyword">import</span> <span class="haskell-constructor">Data.Text</span> (<span class="haskell-constructor">Text</span>)
<span class="haskell-keyword">import</span> <span class="haskell-constructor">Prelude</span> <span class="haskell-keyword">hiding</span> (succ)

<span class="doc">-- | Compare two 'IResult' values for equality.
--
-- If both 'IResult's are 'Partial', the result will be 'Nothing', as
-- they are incomplete and hence their equality cannot be known.
-- (This is why there is no 'Eq' instance for 'IResult'.)
</span><span class="haskell-definition">compareResults</span> <span class="haskell-operator">::</span> (<span class="haskell-type">Eq</span> i, <span class="haskell-type">Eq</span> r) <span class="haskell-operator">=&gt;</span> <span class="haskell-type">IResult</span> i r <span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> i r <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Maybe</span> <span class="haskell-type">Bool</span>
<span class="haskell-definition">compareResults</span> (<span class="haskell-constructor">Fail</span> t0 ctxs0 msg0) (<span class="haskell-constructor">Fail</span> t1 ctxs1 msg1) <span class="haskell-operator">=</span>
<span class="haskell-constructor">Just</span> (t0 <span class="haskell-operator">==</span> t1 <span class="haskell-operator">&amp;&amp;</span> ctxs0 <span class="haskell-operator">==</span> ctxs1 <span class="haskell-operator">&amp;&amp;</span> msg0 <span class="haskell-operator">==</span> msg1)
<span class="haskell-definition">compareResults</span> (<span class="haskell-constructor">Done</span> t0 r0) (<span class="haskell-constructor">Done</span> t1 r1) <span class="haskell-operator">=</span>
<span class="haskell-constructor">Just</span> (t0 <span class="haskell-operator">==</span> t1 <span class="haskell-operator">&amp;&amp;</span> r0 <span class="haskell-operator">==</span> r1)
<span class="haskell-definition">compareResults</span> (<span class="haskell-constructor">Partial</span> <span class="haskell-keyword">_</span>) (<span class="haskell-constructor">Partial</span> <span class="haskell-keyword">_</span>) <span class="haskell-operator">=</span> <span class="haskell-constructor">Nothing</span>
<span class="haskell-definition">compareResults</span> <span class="haskell-keyword">_</span> <span class="haskell-keyword">_</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Just</span> <span class="haskell-constructor">False</span>

<span class="doc">-- | Ask for input. If we receive any, pass the augmented input to a
-- success continuation, otherwise to a failure continuation.
</span><span class="haskell-definition">prompt</span> <span class="haskell-operator">::</span> <span class="haskell-type">Chunk</span> t
<span class="haskell-operator">=&gt;</span> <span class="haskell-type">State</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Pos</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">More</span>
<span class="haskell-operator">-&gt;</span> (<span class="haskell-type">State</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Pos</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">More</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> t r)
<span class="haskell-operator">-&gt;</span> (<span class="haskell-type">State</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Pos</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">More</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> t r)
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> t r
<span class="haskell-definition">prompt</span> t pos _more lose succ <span class="haskell-operator">=</span> <span class="haskell-constructor">Partial</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>s <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">if</span> nullChunk s
<span class="haskell-keyword">then</span> lose t pos <span class="haskell-constructor">Complete</span>
<span class="haskell-keyword">else</span> succ (pappendChunk t s) pos <span class="haskell-constructor">Incomplete</span>
<span class="haskell-pragma">{-# SPECIALIZE prompt :: State ByteString -&gt; Pos -&gt; More
-&gt; (State ByteString -&gt; Pos -&gt; More
-&gt; IResult ByteString r)
-&gt; (State ByteString -&gt; Pos -&gt; More
-&gt; IResult ByteString r)
-&gt; IResult ByteString r #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE prompt :: State Text -&gt; Pos -&gt; More
-&gt; (State Text -&gt; Pos -&gt; More -&gt; IResult Text r)
-&gt; (State Text -&gt; Pos -&gt; More -&gt; IResult Text r)
-&gt; IResult Text r #-}</span>

<span class="doc">-- | Immediately demand more input via a 'Partial' continuation
-- result.
</span><span class="haskell-definition">demandInput</span> <span class="haskell-operator">::</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t <span class="haskell-constructor">()</span>
<span class="haskell-definition">demandInput</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> more <span class="haskell-keyword">of</span>
<span class="haskell-constructor">Complete</span> <span class="haskell-operator">-&gt;</span> lose t pos more <span class="haskell-constructor">[]</span> <span class="string">"not enough input"</span>
<span class="haskell-keyword">_</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-keyword">let</span> lose' <span class="haskell-keyword">_</span> pos' more' <span class="haskell-operator">=</span> lose t pos' more' <span class="haskell-constructor">[]</span> <span class="string">"not enough input"</span>
succ' t' pos' more' <span class="haskell-operator">=</span> succ t' pos' more' <span class="haskell-constructor">()</span>
<span class="haskell-keyword">in</span> prompt t pos more lose' succ'
<span class="haskell-pragma">{-# SPECIALIZE demandInput :: Parser ByteString () #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE demandInput :: Parser Text () #-}</span>

<span class="doc">-- | Immediately demand more input via a 'Partial' continuation
-- result. Return the new input.
</span><span class="haskell-definition">demandInput_</span> <span class="haskell-operator">::</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t t
<span class="haskell-definition">demandInput_</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> more <span class="haskell-keyword">of</span>
<span class="haskell-constructor">Complete</span> <span class="haskell-operator">-&gt;</span> lose t pos more <span class="haskell-constructor">[]</span> <span class="string">"not enough input"</span>
<span class="haskell-keyword">_</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-constructor">Partial</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>s <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">if</span> nullChunk s
<span class="haskell-keyword">then</span> lose t pos <span class="haskell-constructor">Complete</span> <span class="haskell-constructor">[]</span> <span class="string">"not enough input"</span>
<span class="haskell-keyword">else</span> succ (pappendChunk t s) pos more s
<span class="haskell-pragma">{-# SPECIALIZE demandInput_ :: Parser ByteString ByteString #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE demandInput_ :: Parser Text Text #-}</span>

<span class="doc">-- | This parser always succeeds. It returns 'True' if any input is
-- available either immediately or on demand, and 'False' if the end
-- of all input has been reached.
</span><span class="haskell-definition">wantInput</span> <span class="haskell-operator">::</span> <span class="haskell-keyword">forall</span> t <span class="haskell-operator">.</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t <span class="haskell-type">Bool</span>
<span class="haskell-definition">wantInput</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more _lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> <span class="haskell-constructor">()</span> <span class="haskell-keyword">of</span>
<span class="haskell-keyword">_</span> <span class="haskell-operator">|</span> pos <span class="haskell-operator">&lt;</span> atBufferEnd (undefined <span class="haskell-operator">::</span> t) t <span class="haskell-operator">-&gt;</span> succ t pos more <span class="haskell-constructor">True</span>
<span class="haskell-operator">|</span> more <span class="haskell-operator">==</span> <span class="haskell-constructor">Complete</span> <span class="haskell-operator">-&gt;</span> succ t pos more <span class="haskell-constructor">False</span>
<span class="haskell-operator">|</span> otherwise <span class="haskell-operator">-&gt;</span> <span class="haskell-keyword">let</span> lose' t' pos' more' <span class="haskell-operator">=</span> succ t' pos' more' <span class="haskell-constructor">False</span>
succ' t' pos' more' <span class="haskell-operator">=</span> succ t' pos' more' <span class="haskell-constructor">True</span>
<span class="haskell-keyword">in</span> prompt t pos more lose' succ'
<span class="haskell-pragma">{-# INLINE wantInput #-}</span>

<span class="doc">-- | Match only if all input has been consumed.
</span><span class="haskell-definition">endOfInput</span> <span class="haskell-operator">::</span> <span class="haskell-keyword">forall</span> t <span class="haskell-operator">.</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t <span class="haskell-constructor">()</span>
<span class="haskell-definition">endOfInput</span> <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> <span class="haskell-constructor">()</span> <span class="haskell-keyword">of</span>
<span class="haskell-keyword">_</span><span class="haskell-operator">|</span> pos <span class="haskell-operator">&lt;</span> atBufferEnd (undefined <span class="haskell-operator">::</span> t) t <span class="haskell-operator">-&gt;</span> lose t pos more <span class="haskell-constructor">[]</span> <span class="string">"endOfInput"</span>
<span class="haskell-operator">|</span> more <span class="haskell-operator">==</span> <span class="haskell-constructor">Complete</span> <span class="haskell-operator">-&gt;</span> succ t pos more <span class="haskell-constructor">()</span>
<span class="haskell-operator">|</span> otherwise <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">let</span> lose' t' pos' more' _ctx _msg <span class="haskell-operator">=</span> succ t' pos' more' <span class="haskell-constructor">()</span>
succ' t' pos' more' _a <span class="haskell-operator">=</span> lose t' pos' more' <span class="haskell-constructor">[]</span> <span class="string">"endOfInput"</span>
<span class="haskell-keyword">in</span> runParser demandInput t pos more lose' succ'
<span class="haskell-pragma">{-# SPECIALIZE endOfInput :: Parser ByteString () #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE endOfInput :: Parser Text () #-}</span>

<span class="doc">-- | Return an indication of whether the end of input has been
-- reached.
</span><span class="haskell-definition">atEnd</span> <span class="haskell-operator">::</span> <span class="haskell-type">Chunk</span> t <span class="haskell-operator">=&gt;</span> <span class="haskell-type">Parser</span> t <span class="haskell-type">Bool</span>
<span class="haskell-definition">atEnd</span> <span class="haskell-operator">=</span> not <span class="haskell-operator">&lt;$&gt;</span> wantInput
<span class="haskell-pragma">{-# INLINE atEnd #-}</span>

<span class="haskell-definition">satisfySuspended</span> <span class="haskell-operator">::</span> <span class="haskell-keyword">forall</span> t r <span class="haskell-operator">.</span> <span class="haskell-type">Chunk</span> t
<span class="haskell-operator">=&gt;</span> (<span class="haskell-type">ChunkElem</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Bool</span>)
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">State</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Pos</span> <span class="haskell-operator">-&gt;</span> <span class="haskell-type">More</span>
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">Failure</span> t (<span class="haskell-type">State</span> t) r
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">Success</span> t (<span class="haskell-type">State</span> t) (<span class="haskell-type">ChunkElem</span> t) r
<span class="haskell-operator">-&gt;</span> <span class="haskell-type">IResult</span> t r
<span class="haskell-definition">satisfySuspended</span> p t pos more lose succ <span class="haskell-operator">=</span>
runParser (demandInput <span class="haskell-operator">&gt;&gt;</span> go) t pos more lose succ
<span class="haskell-keyword">where</span> go <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t' pos' more' lose' succ' <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> bufferElemAt (undefined <span class="haskell-operator">::</span> t) pos' t' <span class="haskell-keyword">of</span>
<span class="haskell-constructor">Just</span> (e, l) <span class="haskell-operator">|</span> p e <span class="haskell-operator">-&gt;</span> succ' t' (pos' <span class="haskell-operator">+</span> <span class="haskell-constructor">Pos</span> l) more' e
<span class="haskell-operator">|</span> otherwise <span class="haskell-operator">-&gt;</span> lose' t' pos' more' <span class="haskell-constructor">[]</span> <span class="string">"satisfyElem"</span>
<span class="haskell-constructor">Nothing</span> <span class="haskell-operator">-&gt;</span> runParser (demandInput <span class="haskell-operator">&gt;&gt;</span> go) t' pos' more' lose' succ'
<span class="haskell-pragma">{-# SPECIALIZE satisfySuspended :: (ChunkElem ByteString -&gt; Bool)
-&gt; State ByteString -&gt; Pos -&gt; More
-&gt; Failure ByteString (State ByteString) r
-&gt; Success ByteString (State ByteString)
(ChunkElem ByteString) r
-&gt; IResult ByteString r #-}</span>
<span class="haskell-pragma">{-# SPECIALIZE satisfySuspended :: (ChunkElem Text -&gt; Bool)
-&gt; State Text -&gt; Pos -&gt; More
-&gt; Failure Text (State Text) r
-&gt; Success Text (State Text)
(ChunkElem Text) r
-&gt; IResult Text r #-}</span>

<span class="doc">-- | The parser @satisfyElem p@ succeeds for any chunk element for which the
-- predicate @p@ returns 'True'. Returns the element that is
-- actually parsed.
</span><span class="haskell-definition">satisfyElem</span> <span class="haskell-operator">::</span> <span class="haskell-keyword">forall</span> t <span class="haskell-operator">.</span> <span class="haskell-type">Chunk</span> t
<span class="haskell-operator">=&gt;</span> (<span class="haskell-type">ChunkElem</span> t <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Bool</span>) <span class="haskell-operator">-&gt;</span> <span class="haskell-type">Parser</span> t (<span class="haskell-type">ChunkElem</span> t)
<span class="haskell-definition">satisfyElem</span> p <span class="haskell-operator">=</span> <span class="haskell-constructor">Parser</span> <span class="haskell-operator">$</span> <span class="haskell-operator">\</span>t pos more lose succ <span class="haskell-operator">-&gt;</span>
<span class="haskell-keyword">case</span> bufferElemAt (undefined <span class="haskell-operator">::</span> t) pos t <span class="haskell-keyword">of</span>
<span class="haskell-constructor">Just</span> (e, l) <span class="haskell-operator">|</span> p e <span class="haskell-operator">-&gt;</span> succ t (pos <span class="haskell-operator">+</span> <span class="haskell-constructor">Pos</span> l) more e
<span class="haskell-operator">|</span> otherwise <span class="haskell-operator">-&gt;</span> lose t pos more <span class="haskell-constructor">[]</span> <span class="string">"satisfyElem"</span>
<span class="haskell-constructor">Nothing</span> <span class="haskell-operator">-&gt;</span> satisfySuspended p t pos more lose succ
<span class="haskell-pragma">{-# INLINE satisfyElem #-}</span>

<span class="doc">-- | Concatenate a monoid after reversing its elements. Used to
-- glue together a series of textual chunks that have been accumulated
-- \"backwards\".
</span><span class="haskell-definition">concatReverse</span> <span class="haskell-operator">::</span> <span class="haskell-type">Monoid</span> m <span class="haskell-operator">=&gt;</span> [m] <span class="haskell-operator">-&gt;</span> m
<span class="haskell-definition">concatReverse</span> [x] <span class="haskell-operator">=</span> x
<span class="haskell-definition">concatReverse</span> xs <span class="haskell-operator">=</span> mconcat (reverse xs)
<span class="haskell-pragma">{-# INLINE concatReverse #-}</span>
</pre> <!-- mode-haskell -->

<pre id="mode-org" class="mode">
<span class="org-level-1">* web-app</span>...
<span class="org-level-1">* todo</span>...
<span class="org-level-1">* historically important people</span>
<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Zeno&gt;&gt;</span><span class="org-level-2"> of Elea</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

<span class="org-link"><a href="Aristotle">Aristotle</a></span> called him the inventor of the dialectic. He is best known for his paradoxes, which Bertrand Russell has described as "immeasurably subtle and profound."

Zeno's arguments are perhaps the first examples of a method of proof called reductio ad absurdum also known as proof by contradiction. They are also credited as a source of the dialectic method used by Socrates.

Suppose Homer wishes to walk to the end of a path. Before he can get there, he must get halfway there. Before he can get halfway there, he must get a quarter of the way there. Before traveling a quarter, he must travel one-eighth; before an eighth, one-sixteenth; and so on.
This description requires one to complete an infinite number of tasks, which Zeno maintains is an impossibility

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Aristotle&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

"We are what we repeatedly do. Excellence, then, is not an act, but a habit."
"It is the mark of an educated mind to be able to entertain a thought without accepting it."
"What is a friend? A single soul dwelling in two bodies."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Epicurus&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

For Epicurus, the purpose of philosophy was to attain the happy, tranquil life, characterized by ataraxia&#8212;peace and freedom from fear&#8212;and aponia&#8212;the absence of pain&#8212;and by living a self-sufficient life surrounded by friends. He taught that pleasure and pain are measures of what is good and evil; death is the end of both body and soul and therefore should not be feared; the gods neither reward nor punish humans; the universe is infinite and eternal; and events in the world are ultimately based on the motions and interactions of atoms moving in empty space.

In contrast to the Stoics, Epicureans showed little interest in participating in the politics of the day, since doing so leads to trouble. He instead advocated seclusion. This principle is epitomised by the phrase lathe bi&#333;sas (&#955;&#940;&#952;&#949; &#946;&#953;&#974;&#963;&#945;&#962;), meaning "live in obscurity", "get through life without drawing attention to yourself", i.e., live without pursuing glory or wealth or power, but anonymously, enjoying little things like food, the company of friends, etc. Plutarch elaborated on this theme in his essay Is the Saying "Live in Obscurity" Right?

<span class="org-link"><a href="http://slatestarcodex.com/2017/09/06/predictive-processing-and-perceptual-control/">http://slatestarcodex.com/2017/09/06/predictive-processing-and-perceptual-control/</a></span>
Epicurus gathered a bunch of philosophers and mathematicians into a small cult around him, who lived together in co-ed group houses preaching atheism and materialism and &#8211; as per the rumors &#8211; having orgies. If we&#8217;d just agreed he was right about everything from the start, we wouldn&#8217;t have had to laboriously reinvent his whole system.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Zeno of Citium&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Zeno was the original founder of the Stoic school of philosophy, which he taught in Athens from about 300 BCE. Based on the moral ideas of the Cynics, Stoicism laid great emphasis on goodness and peace of mind, gained from living a life of Virtue in accordance with Nature. It proved very successful, and flourished as the dominant philosophy from the Hellenistic period through to the Roman era.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Euclid&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Euclid was a Greek mathematician, often referred to as the "father of geometry". He was active in Alexandria during the reign of Ptolemy I (323-283 BCE). His Elements is one of the most influential works in the history of mathematics, serving as the main textbook for teaching mathematics (especially geometry) from the time of its publication until the late 19th or early 20th century. In the Elements, Euclid deduced the principles of what is now called Euclidean geometry from a small set of axioms. Euclid also wrote works on perspective, conic sections, spherical geometry, number theory and rigor.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Chrysippus of Soli&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

A Greek Stoic philosopher. He was a native of Soli, Cilicia, but moved to Athens as a young man, where he became a pupil of Cleanthes in the Stoic school. When Cleanthes died, around 230 BCE, Chrysippus became the third head of the school. A prolific writer, Chrysippus expanded the fundamental doctrines of <span class="org-link"><a href="Zeno of Citium">Zeno of Citium</a></span>, the founder of the school, which earned him the title of Second Founder of Stoicism.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Seneca&gt;&gt;</span><span class="org-level-2"> The Younger</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

A Roman Stoic philosopher, statesman, dramatist, and in one work humorist of the Silver Age of Latin literature. As a tragedian, he is best-known for his Medea and Thyestes.

He was a tutor and later advisor to emperor Nero. He was forced to take his own life for alleged complicity in the Pisonian conspiracy to assassinate Nero, in which he was likely to have been innocent. His stoic and calm suicide has become the subject of numerous paintings.

"Luck is what happens when preparation meets opportunity."

"Every new beginning comes from some other beginning's end."

"If one does not know to which port one is sailing, no wind is favorable."

"All cruelty springs from weakness."

"We are more often frightened than hurt; and we suffer more from imagination than from reality."

"Religion is regarded by the common people as true, by the wise as false, and by the rulers as useful."

"Sometimes even to live is an act of courage."

"Wherever there is a human being, there is an opportunity for a kindness."

"As is a tale, so is life: not how long it is, but how good it is, is what matters."

"It's not because things are difficult that we dare not venture. It's because we dare not venture that they are difficult."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Epictetus&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Epictetus was a Greek Stoic philosopher

To Epictetus, all external events are beyond our control; we should accept calmly and dispassionately whatever happens. However, individuals are responsible for their own actions, which they can examine and control through rigorous self-discipline

Epictetus maintains that the foundation of all philosophy is self-knowledge, that is, the conviction of our ignorance and gullibility ought to be the first subject of our study. Logic provides valid reasoning and certainty in judgment, but it is subordinate to practical needs.
- The first and most necessary part of philosophy concerns the application of doctrine, for example, that people should not lie.
- The second concerns reasons, e.g. why people should not lie.
- While the third, lastly, examines and establishes the reasons.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Augustine&gt;&gt;</span><span class="org-level-2"> of Hippo</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Augustine of Hippo, also known as Saint Augustine, Saint Austin, Blessed Augustine, and the Doctor of Grace, was an early Christian theologian and philosopher whose writings influenced the development of Western Christianity and Western philosophy.

"The world is a book, and those who do not travel read only a page."
"Faith is to believe what you do not yet see; the reward for this faith is to see what you believe."
"Since love grows within you, so beauty grows. For love is the beauty of the soul."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Cicero&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Marcus Tullius Cicero was a Roman philosopher, politician, lawyer, orator, political theorist, consul, and constitutionalist

"Gratitude is not only the greatest of virtues, but the parent of all others."
"A room without books is like a body without a soul."
"The life of the dead is placed in the memory of the living."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Marcus Aurelius&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Marcus Aurelius was Roman emperor from 161 to 180, ruling jointly with Lucius Verus until Verus' death in 169 and jointly with his son, Commodus, from 177. He was the last of the so-called Five Good Emperors.

He was a practitioner of Stoicism, and his untitled writing, commonly known as Meditations, is a significant source of our modern understanding of ancient Stoic philosophy. It is considered by many commentators to be one of the greatest works of philosophy.

His death in 180 is considered the end of the Pax Romana and the increasing instability in the west that followed has traditionally been seen as the beginning of the eventual Fall of the Western Roman Empire.

While on campaign between 170 and 180, Aurelius wrote his Meditations in Greek as a source for his own guidance and self-improvement. The original title of this work, if it had one, is unknown. "Meditations" as well as others, including "To Himself" were adopted later. He had a logical mind and his notes were representative of Stoic philosophy and spirituality. Meditations is still revered as a literary monument to a government of service and duty. The book was a favourite of Frederick the Great, John Stuart Mill, Matthew Arnold, and Goethe.


"We should always have these two rules in readiness: one, to do only whatever the reason of the ruling and legislating faculty [i.e. our rationality] may suggest for our use; the other, to change your opinion, if anyone sets you right and dissuades you from any opinion." (Meditations IV.12)

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Machiavelli&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Niccol&#242; di Bernardo dei Machiavelli was an Italian diplomat, politician, historian, philosopher, humanist, and writer of the Renaissance period. He has often been called the father of modern political science. He was for many years a senior official in the Florentine Republic, with responsibilities in diplomatic and military affairs. He also wrote comedies, carnival songs, and poetry. He was secretary to the Second Chancery of the Republic of Florence from 1498 to 1512, when the Medici were out of power. He wrote his most renowned work The Prince (Il Principe) in 1513.

"Machiavellianism" is a widely used negative term to characterize unscrupulous politicians of the sort Machiavelli described most famously in The Prince. Machiavelli described immoral behavior, such as dishonesty and killing innocents, as being normal and effective in politics. He even seemed to endorse it in some situations. The book itself gained notoriety when some readers claimed that the author was teaching evil, and providing "evil recommendations to tyrants to help them maintain their power". The term "Machiavellian" is often associated with political deceit, deviousness, and realpolitik. On the other hand, many commentators, such as Baruch Spinoza, Jean-Jacques Rousseau and Denis Diderot, have argued that Machiavelli was actually a republican, even when writing The Prince, and his writings were an inspiration to Enlightenment proponents of modern democratic political philosophy.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Hobbes&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Thomas Hobbes, was an English philosopher who is considered one of the founders of modern political philosophy. Hobbes is best known for his 1651 book Leviathan, which established the social contract theory that has served as the foundation for most later Western political philosophy. In addition to political philosophy, Hobbes also contributed to a diverse array of other fields, including history, jurisprudence, geometry, the physics of gases, theology, ethics, and general philosophy.

Though on rational grounds a champion of absolutism for the sovereign, Hobbes also developed some of the fundamentals of European liberal thought: the right of the individual; the natural equality of all men; the artificial character of the political order (which led to the later distinction between civil society and the state); the view that all legitimate political power must be "representative" and based on the consent of the people; and a liberal interpretation of law that leaves people free to do whatever the law does not explicitly forbid. His understanding of humans as being matter and motion, obeying the same physical laws as other matter and motion, remains influential; and his account of human nature as self-interested cooperation, and of political communities as being based upon a "social contract" remains one of the major topics of political philosophy.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Descartes&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Ren&#233; Descartes was a French philosopher, mathematician, and scientist. Dubbed the father of modern western philosophy, much of subsequent Western philosophy is a response to his writings, which are studied closely to this day

"It is not enough to have a good mind; the main thing is to use it well."
"The reading of all good books is like a conversation with the finest minds of past centuries."
"If you would be a real seeker after truth, it is necessary that at least once in your life you doubt, as far as possible, all things."

<span class="org-level-3">*** The Neuroscience of Consciousness &#8211; with Anil Seth</span>
<span class="org-link"><a href="https://www.youtube.com/watch?v=xRel1JKOEbI">https://www.youtube.com/watch?v=xRel1JKOEbI</a></span>

Descartes made the distinction between mind and matter:
res extensa - matter stuff (desk, clothes, brains)
res cogitans - the stuff of thought, feelings, consciousness

He said that only humans have minds and therefore moral status. Other animals were 'beast machines' - physiological machines, morally equivalent to plants or rocks.
This statement was disputed by Anil Seth in his talk
<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Locke&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

John Locke was an English philosopher and physician, widely regarded as one of the most influential of Enlightenment thinkers and commonly known as the "Father of Liberalism". Considered one of the first of the British empiricists, following the tradition of Sir Francis Bacon, he is equally important to social contract theory. His work greatly affected the development of epistemology and political philosophy. His writings influenced Voltaire and Jean-Jacques Rousseau, many Scottish Enlightenment thinkers, as well as the American revolutionaries. His contributions to classical republicanism and liberal theory are reflected in the United States Declaration of Independence.

Locke's theory of mind is often cited as the origin of modern conceptions of identity and the self, figuring prominently in the work of later philosophers such as David Hume, Rousseau, and Immanuel Kant. Locke was the first to define the self through a continuity of consciousness. He postulated that, at birth, the mind was a blank slate or tabula rasa. Contrary to Cartesian philosophy based on pre-existing concepts, he maintained that we are born without innate ideas, and that knowledge is instead determined only by experience derived from sense perception, This is now known as empiricism. An example of Locke belief in Empiricism can be seen in his quote : "whatever I write, as soon as I discover it not to be true, my hand shall be the forwardest to throw it into the fire". This shows the ideology of science in his observations in that something must be capable of being tested repeatedly and that nothing is exempt from being disproven. Challenging the work of others Locke is said to have established the method of Introspection (Observing the emotions and behaviours of one's self)

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Spinoza&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Baruch Spinoza born Benedito de Espinosa was a Dutch philosopher of Sephardi/Portuguese origin. By laying the groundwork for the 18th-century Enlightenment and modern biblical criticism, including modern conceptions of the self and the universe, he came to be considered one of the great rationalists of 17th-century philosophy.

Spinoza's magnum opus, the posthumous Ethics, in which he opposed <span class="org-link"><a href="Descartes">Descartes</a></span>' mind-body dualism, has earned him recognition as one of Western philosophy's most important thinkers. In the Ethics, "Spinoza wrote the last indisputable Latin masterpiece, and one in which the refined conceptions of medieval philosophy are finally turned against themselves and destroyed entirely." Hegel said, "You are either a Spinozist or not a philosopher at all." His philosophical accomplishments and moral character prompted 20th-century philosopher Gilles Deleuze to name him "the 'prince' of philosophers".

"Peace is not an absence of war, it is a virtue, a state of mind, a disposition for benevolence, confidence, justice."
"All things excellent are as difficult as they are rare."
"I have striven not to laugh at human actions, not to weep at them, nor to hate them, but to understand them."

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Newton&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Isaac Newton was an English mathematician, astronomer, theologian and physicist (described in his own day as a "natural philosopher") who is widely recognised as one of the most influential scientists of all time and a key figure in the scientific revolution. His book Philosophi&#230; Naturalis Principia Mathematica ("Mathematical Principles of Natural Philosophy"), first published in 1687, laid the foundations of classical mechanics. Newton also made pathbreaking contributions to optics, and he shares credit with Gottfried Wilhelm <span class="org-link"><a href="Leibniz">Leibniz</a></span> for developing the infinitesimal calculus.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Leibniz&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Gottfried Wilhelm (von) Leibniz was a German polymath and philosopher who occupies a prominent place in the history of mathematics and the history of philosophy, having developed differential and integral calculus independently of Isaac Newton. Leibniz's notation has been widely used ever since it was published. It was only in the 20th century that his Law of Continuity and Transcendental Law of Homogeneity found mathematical implementation (by means of non-standard analysis). He became one of the most prolific inventors in the field of mechanical calculators. While working on adding automatic multiplication and division to Pascal's calculator, he was the first to describe a pinwheel calculator in 1685 and invented the Leibniz wheel, used in the arithmometer, the first mass-produced mechanical calculator. He also refined the binary number system, which is the foundation of virtually all digital computers.

In philosophy, Leibniz is most noted for his optimism, i.e. his conclusion that our Universe is, in a restricted sense, the best possible one that God could have created, an idea that was often lampooned by others such as <span class="org-link"><a href="Voltaire">Voltaire</a></span>. Leibniz, along with <span class="org-link"><a href="Ren&#233; Descartes">Ren&#233; Descartes</a></span> and Baruch <span class="org-link"><a href="Spinoza">Spinoza</a></span>, was one of the three great 17th-century advocates of rationalism. The work of Leibniz anticipated modern logic and analytic philosophy, but his philosophy also looks back to the scholastic tradition, in which conclusions are produced by applying reason to first principles or prior definitions rather than to empirical evidence.

Leibniz made major contributions to physics and technology, and anticipated notions that surfaced much later in philosophy, probability theory, biology, medicine, geology, psychology, linguistics, and computer science. He wrote works on philosophy, politics, law, ethics, theology, history, and philology. Leibniz also contributed to the field of library science. While serving as overseer of the Wolfenb&#252;ttel library in Germany, he devised a cataloging system that would serve as a guide for many of Europe's largest libraries. Leibniz's contributions to this vast array of subjects were scattered in various learned journals, in tens of thousands of letters, and in unpublished manuscripts. He wrote in several languages, but primarily in Latin, French, and German.

<span class="org-level-2">** </span><span class="org-target">&lt;&lt;Hume&gt;&gt;</span>
<span class="org-special-keyword"> :PROPERTIES:</span>...

Hume held that passion rather than reason governs human behaviour and argued against the existence of innate ideas, positing that all human knowledge is ultimately founded solely in experience; Hume thus held that genuine knowledge must either be directly traceable to objects perceived in experience, or result from abstract reasoning about relations between ideas which are derived from experience, calling the rest "nothing but sophistry and illusion", a dichotomy later given the name Hume's fork.

<span class="org-link"><a href="https://www.youtube.com/watch?v=_DGdDQrXv5U">https://www.youtube.com/watch?v=_DGdDQrXv5U</a></span>
You can never change someone's mind with just reasoning and logic

Since practical reason is supposed to regulate our actions (in theory), Hume denied practical reason on the grounds that reason cannot directly oppose passions. As Hume puts it, "Reason is, and ought only to be the slave of the passions, and can never pretend to any other office than to serve and obey them." Reason is less significant than any passion because reason has no original influence, while "A passion is an original existence, or, if you will, modification of existence".

The way of changing someone's mind is to first speak to their intuitions and affections

--------------------------------------------------

<span class="org-link"><a href="https://www.theatlantic.com/magazine/archive/2017/01/what-makes-things-cool/508772/">https://www.theatlantic.com/magazine/archive/2017/01/what-makes-things-cool/508772/</a></span>
David Hume, the 18th-century philosopher, considered the search for formulas to be absurd, because the perception of beauty was purely subjective, residing in individuals, not in the fabric of the universe. "To seek the real beauty, or real deformity," he said, "is as fruitless an enquiry, as to pretend to ascertain the real sweet or real bitter."

--------------------------------------------------

Peter Singer claims that Hume's argument that morals cannot have a rational basis alone "would have been enough to earn him a place in the history of ethics"
</pre> <!-- mode-org -->

</div> <!-- mode-container -->

</div>
</div>

<script src='./bootstrap.js'></script>
</body>
</html>

src/js/main.js → index.js View File

@@ -1,3 +1,18 @@
import { r_from_hsluv,
g_from_hsluv,
b_from_hsluv,
h_from_rgb,
s_from_rgb,
l_from_rgb } from "./wasm_themacs";

// const play = () => {
// const h = h_from_rgb(1.0, 0.8, 0.6);
// console.log(`h = ${h}`);
// };

// play();



// important values:
//
@@ -7,7 +22,6 @@
// clock12 hue
// clock12 saturation

const Wasm = {};
let colourTable = undefined;

const ui = {
@@ -67,21 +81,6 @@ const model = {
"const", "comment", "str", "type"]
};

function initWasmModule(wasmInstance)
{
Wasm.instance = wasmInstance;

Wasm.loadRGB = wasmInstance.exports.load_rgb;
Wasm.loadHSLuv = wasmInstance.exports.load_hsluv;

Wasm.getR = wasmInstance.exports.get_r;
Wasm.getG = wasmInstance.exports.get_g;
Wasm.getB = wasmInstance.exports.get_b;
Wasm.getH = wasmInstance.exports.get_h;
Wasm.getS = wasmInstance.exports.get_s;
Wasm.getL = wasmInstance.exports.get_l;
}

function initModel(model)
{
for (let key in model.colours) {
@@ -186,7 +185,7 @@ function clickEventExport(event)
function hide(selector)
{
// hide all elements that match this selector
matches = document.querySelectorAll(selector);
const matches = document.querySelectorAll(selector);
matches.forEach(m => {
m.classList.add("hidden");
});
@@ -195,7 +194,7 @@ function hide(selector)
function show(selector)
{
// show all elements that match this selector
matches = document.querySelectorAll(selector);
const matches = document.querySelectorAll(selector);
matches.forEach(m => {
m.classList.remove("hidden");
});
@@ -311,22 +310,26 @@ function clamp(value, min, max)

function rgbToHsl(rgb)
{
Wasm.loadRGB(rgb[0] / 255.0, rgb[1] / 255.0, rgb[2] / 255.0);
const r = rgb[0] / 255.0;
const g = rgb[1] / 255.0;
const b = rgb[2] / 255.0;

let h = Math.round(Wasm.getH() * 10) / 10;
let s = Math.round(Wasm.getS() * 10) / 10;
let l = Math.round(Wasm.getL() * 10) / 10;
let h = Math.round(h_from_rgb(r, g, b) * 10) / 10;
let s = Math.round(s_from_rgb(r, g, b) * 10) / 10;
let l = Math.round(l_from_rgb(r, g, b) * 10) / 10;

return [h, s, l];
}

function hslToRgb(hsl)
{
Wasm.loadHSLuv(hsl[0], hsl[1], hsl[2]);
const h = hsl[0];
const s = hsl[1];
const l = hsl[2];

let r = Math.floor(clamp(Wasm.getR(), 0, 1) * 255);
let g = Math.floor(clamp(Wasm.getG(), 0, 1) * 255);
let b = Math.floor(clamp(Wasm.getB(), 0, 1) * 255);
let r = Math.floor(clamp(r_from_hsluv(h, s, l), 0, 1) * 255);
let g = Math.floor(clamp(g_from_hsluv(h, s, l), 0, 1) * 255);
let b = Math.floor(clamp(b_from_hsluv(h, s, l), 0, 1) * 255);

return [r, g, b];
}
@@ -851,22 +854,22 @@ function onMIDIFailure(e) {
updateUI(colourTable, model, ui);
}

document.addEventListener('DOMContentLoaded', () => {
function init() {
console.log('init');
colourTable = document.querySelector("#colour-table");
loadWASM('dist/themacs.wasm', {}).then(wasmInstance => {
initWasmModule(wasmInstance);
initModel(model);
initUI(model, ui);
colourTable.onchange = changeEventHandler;

// request MIDI access
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess({
sysex: false
}).then(onMIDISuccess(ui), onMIDIFailure);
} else {
updateUI(colourTable, model, ui);
}
});

}, false);
initModel(model);
initUI(model, ui);
colourTable.onchange = changeEventHandler;

// request MIDI access
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess({
sysex: false
}).then(onMIDISuccess(ui), onMIDIFailure);
} else {
updateUI(colourTable, model, ui);
}
}

init();

+ 8833
- 410
package-lock.json
File diff suppressed because it is too large
View File


+ 6
- 11
package.json View File

@@ -1,17 +1,12 @@
{
"name": "themacs",
"version": "1.0.0",
"description": "theming emacs",
"main": "index.js",
"scripts": {
"format": "clang-format src/c/wasm.c --glob=src/c/lib/*.[ch] -i -style=LLVM",
"build:wasm": "wa compile -D SENI_BUILD_WASM -o dist/themacs.wasm src/c/wasm.c -i src/c/lib/printf.c -i src/c/lib/mathutil.c -i src/c/lib/colour.c -I src/c",
"clean": "rm dist/*.js"
"serve": "webpack-dev-server",
"build-debug": "cargo +nightly build --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/debug/wasm_themacs.wasm --out-dir .",
"build-release": "cargo +nightly build --release --target wasm32-unknown-unknown && wasm-bindgen target/wasm32-unknown-unknown/release/wasm_themacs.wasm --out-dir ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"webassembly": "^0.11.0",
"clang-format": "^1.1.0"
"webpack": "^4.0.1",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.0"
}
}

+ 0
- 1202
src/c/ext/stb_sprintf.h
File diff suppressed because it is too large
View File


+ 0
- 832
src/c/lib/colour.c View File

@@ -1,832 +0,0 @@
#include "colour.h"

#include "mathutil.h"

#include <stdlib.h>
// float.h for FLT_MAX
#include <float.h>
#include <math.h>

#define COLOUR_UNIT_ANGLE (360.0f / 12.0f)
#define COLOUR_COMPLIMENTARY_ANGLE (COLOUR_UNIT_ANGLE * 6.0f)
#define COLOUR_TRIAD_ANGLE (COLOUR_UNIT_ANGLE * 4)

typedef struct seni_colour_64 {
seni_colour_format format;
f64 element[4];
} seni_colour_64;

const f64 ref_u = 0.19783000664283680764;
const f64 ref_v = 0.46831999493879100370;

// http://www.brucelindbloom.com/index.html?Equations.html
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

// we're using an sRGB working space with a D65 reference white

// https://uk.mathworks.com/help/images/ref/whitepoint.html
// the D65 whitepoint
#define WHITEPOINT_0 0.9504
#define WHITEPOINT_1 1.0
#define WHITEPOINT_2 1.0888

#define CIE_EPSILON 0.008856
#define CIE_KAPPA 903.3

// intent from the CIE
//
// #define CIE_EPSILON (216.0f / 24389.0f)
// #define CIE_KAPPA (24389.0f / 27.0f)

// RGB to XYZ (M)
// 0.4124564 0.3575761 0.1804375