SLaks.Blog

Making the world a better place, one line of code at a time

Programming without errors – ErrorFree

Posted on Tuesday, April 01, 2014

Errors are one of the most common and annoying problems in programming. Whether it’s the parser, the compiler, the type system, the runtime, or even system memory, everything you work with seems to have some way of complaining to you and refusing to run your code. Programmers spend more time fixing errors than any other task when developing applications [citation needed].

But what if you could program without any errors?

To avoid these troublesome errors, I am proud to present a new language called ErrorFree. This language cannot have any errors, anywhere. In fact, every possible file, of any length, is a valid ErrorFree program that can compile and run successfully.

Design Philosophy

Avoiding every possible kind of error (while maintaining Turing-completeness) presents a number of challenges:

Conventions

Every byte in an ErrorFree source file will either push a value to the stack (a value byte) or will perform an operation involving the stack (an operator byte). For convenience, operator bytes are chosen based on their ASCII values. Operator bytes fall into three categories:

In addition to the stack, ErrorFree provides a heap, which can store numbers (double-precision floating point, just like the stack) at any positive or negative integral index. The heap can be used to store data, allowing you to build arrays, linked lists, or other more complex data structures. Like the stack, the heap is initialized to zero at every location.

ErrorFree does not provide a memory manager, so blocks of heap memory must be tracked by hand. Similarly, ErrorFree does not provide a call stack, so function calls and return pointers must also be tracked by hand in the heap.

Since raw bytes cannot be displayed as-is, ErrorFree source code should be displayed for reading as sequences of bytes in hexadecimal. For better readability, operator bytes should be displayed as their single ASCII representation, preceded by a space to maintain alignment. Newlines are meaningless, and can be used to group operations. For example:

01 02  +
04  * 05  *
0E  +

This code pushes the number 74 ((((1 + 2) * 4) * 5) + 0xE = 0x4A) on to the stack. (4A cannot be pushed directly, since J is an operator byte.) A simpler alternative would be 4B 01  -.

Operators

ErrorFree supports the following operators:

Arithmetic operators

All arithmetic operators will pop the values they read.

Pure operators

Impure Operators

Sample program

This 19-byte program prints the squares of numbers 1 through 0x42. It stores the loop index at heap location 0.

00  L 01  + 00  S
00  L  d  *  N
00  L 42  <
01  +  J
00

Here is a line-by-line explanation:

  1. Increment the value at heap location 0.
    (Load, add one, store)
  2. Print the square of said value. (Load, duplicate, multiply, print)
  3. Compare the value at heap location 0 to 0x42, pushing 1 if it’s less than 42 and 0 if it’s greater or equal. (Load, push comparand, compare)
  4. Jump forward by two bytes if it was less (thus wrapping around to the beginning of the file), or one byte if it’s time to exit the loop. (add one, jump)
  5. A final byte to jump to to exit the program. Without this byte, jumping forward would either wrap around (for 1) or remain at the jump instruction (for 0), so the program would hang after finishing the loop.

Other notes

It is impossible to make non-breaking changes to the ErrorFree language once it’s released, since any new code you want to allow already has an existing meaning. Instead, newer versions must be explicitly specified when invoking the compiler/interpreter.

ErrorFree does not include a built-in syntax for comments. Instead, you can simply write your comments directly in the code, then precede them by jump operators so that they don’t execute. When displaying code, comments can be written like operators. Care must be taken to ensure that no other jump instructions end up jumping into the middle of a comment. For example:

01 02  +
12  J  T  h  i  s     i  s     a     c  o  m  m  e  n  t
04  +

Categories: ErrorFree, programming-languages, april-fools Tweet this post

comments powered by Disqus