summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-06-21 17:53:59 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-06-21 17:53:59 -0400
commitac6e0671373351c07ee05e5217108a636cb707cc (patch)
tree8d1327b1b59795b0036a2b5460fbef7dd36e1aba
parent692d13cc1a6fda2776d0ad0b34e9fbff0bc2c55c (diff)
oops gitignore was ignoring docs
-rw-r--r--.gitignore2
-rw-r--r--docs/00.html71
-rw-r--r--docs/01.html31
-rw-r--r--docs/contents.html16
4 files changed, 118 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 2d2c79d..c5f345e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,8 +10,6 @@ tags
std/*.c
std/*.o
*.so
-README.html
-docs/*.html
*.dll
*.exp
*.lib
diff --git a/docs/00.html b/docs/00.html
new file mode 100644
index 0000000..b32be13
--- /dev/null
+++ b/docs/00.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="docs.css">
+<title>Declarations</title>
+</head>
+<body>
+<h2>Declarations</h2>
+
+<p><a href="contents.html">Table of contents</a> &middot; <a href="01.html">Next</a></p>
+
+Variable declarations have the following syntax:
+<pre>
+&lt;name&gt; :[:] [type] [= expression];
+</pre>
+
+<p>The square brackets (<c>[]</c>) indicate something optional.</p>
+
+<p>
+All of the following statements
+declare an new variable <c>x</c> which is an integer, and has a value of 0:
+<pre>
+x : int;
+x : int = 0;
+x := 0;
+</pre>
+Note that in the first of those statements, although no expression
+is specified, it defaults to 0.
+</p>
+
+<p>If you wanted <c>x</c> to be a floating-point number, you could use:</p>
+
+<pre>
+x : float;
+x : float = 0;
+x := 0.0;
+</pre>
+
+<p>Note that <c>0</c> can be used as both a <c>float</c> and an <c>int</c>eger, but
+when no type is specified, it defaults to an <c>int</c>, whereas <c>0.0</c>
+defaults to a <c>float</c>.</p>
+
+<p>Here are all of toc's basic builtin types and their ranges of values:</p>
+
+<ul>
+<li><c>int</c> - A 64-bit signed integer (always), -9223372036854775808 to 9223372036854775807</li>
+<li><c>i8</c> - An 8-bit signed integer, -128 to 128</li>
+<li><c>i16</c> - 16-bit signed integer, -32768 to 32767</li>
+<li><c>i32</c> - 32-bit signed integer, -2147483648 to 2147483647</li>
+<li><c>i64</c> - 64-bit signed integer (same as <c>int</c>, but more explicit about the size), -9223372036854775808 to 9223372036854775807</li>
+<li><c>u8</c> - An 8-bit unsigned integer, 0 to 255</li>
+<li><c>u16</c> - 16-bit unsigned integer, 0 to 65535</li>
+<li><c>u32</c> - 32-bit unsigned integer, 0 to 4294967295</li>
+<li><c>u64</c> - 64-bit unsigned integer, 0 to 18446744073709551615</li>
+<li><c>float</c> - A 32-bit floating-point number, -3.40282347e+38 to 3.40282347e+38</li>
+<li><c>f32</c> - A 32-bit floating-point number (same as <c>float</c>, but more explicit about the size)</li>
+<li><c>f64</c> - A 64-bit floating-point number, -1.7976931348623157e+308 to 1.7976931348623157e+308</li>
+<li><c>bool</c> - A boolean value, either <c>false</c> or <c>true</c>.</li>
+<li><c>char</c> - A character (usually either -128 to 127 or 0 to 255).</li>
+</ul>
+
+<p>To make declarations constant, use <c>::</c> instead of <c>:</c>. e.g.</p>
+
+<p><c>
+x ::= 5+3;
+y :: float = 5.123;
+</c></p>
+
+<p>Here, "constant" means constant at compile time, not read-only as it does in C. One interesting thing about toc is that normal functions can run at compile time, so pretty much any expression is a valid initializer for a constant, e.g. doing <c>x ::= some_function();</c> runs <c>some_function</c> at compile time, not at run time.</p>
+</body>
+</html>
diff --git a/docs/01.html b/docs/01.html
new file mode 100644
index 0000000..f520805
--- /dev/null
+++ b/docs/01.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="docs.css">
+<title>A first program</title>
+</head>
+<body>
+<h2>A first program</h2>
+
+<p><a href="contents.html">Table of contents</a> &middot; <a href="00.html">Prev</a></p>
+
+<p>The <c>main</c> function in toc corresponds to the <c>main</c> function in C. This function is called when your program is run. So, this is a valid toc program which does nothing:</p>
+
+<pre>
+main ::= fn() {
+}
+</pre>
+
+<p>It declares a constant, <c>main</c>, which is a function with an empty body. Note that the syntax for declaring functions is the same as the syntax for declaring constants (it isn't something like <c>fn main() { ... }</c>).</p>
+
+<p>Note that you do not need a semicolon at the end of this declaration (for convenience, if a declaration ends with a closing brace (<c>}</c>), you do not need a semicolon).</p>
+
+<p>Assuming you have compiled the compiler (see <c>README.md</c> for instructions about that), you can compile it with</p>
+
+<pre>
+toc &lt;your filename&gt;
+</pre>
+
+<p>You will get a file called <c>out.c</c>, which you can then put through your C compiler to get an executable file which does nothing. Congratulations! You've written your first toc program.</p>
+</body>
+</html>
diff --git a/docs/contents.html b/docs/contents.html
new file mode 100644
index 0000000..d5afb65
--- /dev/null
+++ b/docs/contents.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="docs.css">
+<title>Contents</title>
+</head>
+<body>
+<h2>Contents</h2>
+
+<ul>
+<li><a href="00.html">Declarations</a></li>
+<li><a href="01.html">A first program</a></li>
+</ul>
+
+</body>
+</html>