@@ -39,6 +39,9 @@ available for download from https://github.com/benburrill/sphinx
3939Please note however that the ``spasm `` emulator is written in Python, so
4040it should not be relied on for performance-critical applications.
4141
42+ The following examples provide an introduction to Halt is Defeat,
43+ starting from the basics and building up to time travel.
44+
4245Hello world
4346-----------
4447The entry point to Halt is Defeat programs is ``@is_you() ``. The return
@@ -72,21 +75,21 @@ Running under ``spasm`` produces the expected output:
7275 CPU time: 578 clock cycles
7376 Emulator efficiency: 48.78%
7477
75- If you run it yourself, you may notice something a little odd. Once the
76- end of the program is reached, it gets stuck in an infinite loop.
78+ If you run it yourself, you may notice something strange. Even after
79+ the end of the program is reached, ``spasm `` keeps running, apparently
80+ doing nothing.
7781
78- This behavior is necessary in order for Halt is Defeat to ensure that
79- your programs are undefeatable. Since "Halt is Defeat", the program
80- must never halt, so upon returning from ``@is_you() ``, Halt is Defeat
81- code emits the "win" flag (as seen in the output from ``spasm ``) and
82- then loops forever.
82+ Indeed, after returning from ``@is_you() ``, the "win" flag is emitted
83+ (as seen in the output from ``spasm ``), and then the program enters into
84+ an infinite loop.
8385
84- If running under the ``spasm `` emulator, you can always issue a keyboard
85- interrupt (ctrl-c) to forcibly stop the running program. Attempting to
86- stop programs running on a real Sphinx processor is not recommended and
87- may destroy the universe.
86+ The loop is there to guard the past against future defeat, but don't
87+ worry about it. If running under the ``spasm `` emulator, you can always
88+ issue a keyboard interrupt (ctrl-c) to forcibly stop the running
89+ program. Attempting to stop programs running on a real Sphinx processor
90+ is not recommended and may destroy the universe.
8891
89- When the `` win `` flag is encountered, the ``spasm `` emulator displays
92+ When the " win" flag is encountered, the ``spasm `` emulator displays
9093some statistics. The CPU time is the number of Sphinx instructions
9194executed (each instruction takes 1 clock cycle). The emulator
9295efficiency is an implementation detail of the emulator and may be
@@ -224,8 +227,9 @@ jump instruction", which performs a jump if not jumping would lead to
224227halting.
225228
226229Another fun implementation detail is that because Sphinx has no other
227- jump instructions, even ``if `` statements in Halt is Defeat must predict
228- the future, and work by propagating future halts backwards through time.
230+ jump instructions, even ``if `` statements in Halt is Defeat are forced
231+ to predict the future, and work by propagating future halts backwards
232+ through time.
229233We've been solving Sphinx's halting problem since Hello World!
230234
231235Computational astrology
@@ -472,16 +476,20 @@ Errors can also be produced in user code with ``all_is_broken()``.
472476
473477Although many operations in HiD are checked and will produce runtime
474478errors, there is some undefined behavior in the case of dynamically
475- allocated arrays. Dynamically allocated arrays are uninitialized, and
476- the use of uninitialized strings is undefined behavior.
479+ allocated arrays.
480+
481+ Dynamically allocated arrays are uninitialized. Any use of uninitialized
482+ strings (ie obtained from an array of strings) is undefined behavior.
483+ The other scalar types (`int `, `byte `, and `bool `) are safe to use when
484+ uninitialized, but their initial value is otherwise unspecified.
477485
478486Additionally, if the ``--unchecked `` flag is passed, all previously
479487checked operations become undefined behavior:
480488
481489- Division or modulo by 0
482490- Indexing an array or string out of bounds
483- - Stack overflow
484491- Dynamically allocating an array with negative length
492+ - Stack overflow
485493- Calling a preemptive defeat function without providing safety
486494
487495Be aware that HiD's nasal demons can time travel, so undefined behavior
0 commit comments