Return to Menu
= = = DUO COMPACT PISTON COMPILER = = =
Architecture and Compiler by Jack Eisenmann
Now with error checking!

Piston Code:

Fabrication Code:



= PISTON CODE SYNTAX =

Piston is a higher level language to be compiled into fabrication code. The language will facilitate the creation of software for the DUO Compact.

There are 3 data types in Piston.

Numbers, bars, and pointers are stored in a scope space. The exact position for each value is pre-allocated. When the scope level decreases, the numbers, bars, and pointers are deallocated.

Number and pointer variables are declared by placing a type letter (N or P) and a variable name separated by a space. Example:

N count
P groceries

A bar variable declaration must specify the size of the bar. Place a close curly brace (}) between the data type B and the variable name:

B}10 text

Store a value in a variable by placing the |<< operator between the variable name and the value. Example:

N count
count |<< 16
count |<< 7

A bar variable will be constant if the letter C is included before the variable's declaration. Bar literals are represented by comma separated values enclosed by a forward slash and an underscore. Alternatively, write a string of ASCII characters in quotation marks. Example:

C B}4 positions
positions |<< /5, 3, 2, 2_
C B}20 text
text |<< "Hello, world!"

Note that bar literals can only be directly stored in constant bar variables.

To retrieve the length of any bar, place its variable name between question marks. Example:

B}4 items
N amount
amount |<< ?items?

To call a function, place the function name and a bar literal separated by a space. The bar contains the argument values to pass into the function. Example:

N num
num |<< increment /4_

Function calls may not be embedded.

Code blocks are enclosed by brackets. Example:

N result
result |<< 3
N bool
bool |<< equal /68, 21_
if /bool_ [
result |<< 4
]

Functions are declared with the following syntax:

(declaration) /(declaration), (declaration), (declaration)... _ [
(code)
]

The declaration outside of the bar literal defines the function return type and name. Use V for a void return value. The declarations inside of the bar literal define the argument types and names. To set the return value in the code block, use |<< with the function name. Example:

N doubleAndDecrement /N num_ [
N temp
temp |<< shiftRight /num_
doubleAndDecrement |<< decrement /temp_
]
N value
value |<< doubleAndDecrement /4_

Neither overloading nor recursive calls are permitted.

Note that a bar cannot be passed from scope to scope. Use the reference function to obtain a pointer to an existing bar.

Label names are placed between asterisks. A label may be used as the argument for the jump function. Example:

N value
value |<< 8
*test*
P pointy
pointy |<< pair /6, 192_
output /pointy, value_
value |<< not /value_
jump /test_

Labels may also be used as an operand of |<<, but not as an argument for any other functions. This may be fixed in the future.

Use a triple at sign (@@@) to include comments in code. Example:

@@@ Declare a variable.
N count
@@@ Store a value.
count |<< 99

The wiring of your screen data bus to the I/O port may have an unusual order. To accommodate this, place screen# before any screen data bus constant. Example:

P pointy
pointy |<< pair /0, 192_
output /pointy, screen#36_

The particular connections of my own machine are shown in the diagram below:

I recommend that you also use this connection scheme. If you do not follow this convention, you will need to tweak the Piston compiler. Search for the variable named customScreenDataBitOrder in the source code.

By default, all quoted strings have the byte screen#3 appended to the end. To include this halting byte in other positions, use the tilde character (~).

There are several directives you may pass to the fabricator. These include:

BUFFER [number]
SEQUENCE [value] [value] [value]...
FLASH

To declare the start of a new program, use the METASCOPE keyword:

[...code...]
METASCOPE [name]
[...code...]

A metascope separates the variable names between programs and resets the relative address of labels. Note that the first metascope is visible globally so it may offer functions to all other programs.

= DEFAULT PISTON FUNCTIONS =

Arithmetic operations:

N increment /N num_
N decrement /N num_

Bitwise logical operations:

N and /N data1, N data2_
N or /N data1, N data2_
N not /N data_
N shiftRight /N data_
N shiftLeft /N data_

Flow control:

V if /N number_ [block]
V ifNot /N number_ [block]
V while /N number_ [block]
V whileNot /N number_ [block]
V jump /P address_

Pointer operations:

P pair /N num1, N num2_
N first /P pointer_
N second /P pointer_
V setFirst /P pointer, N num_
V setSecond /P pointer, N num_
P reference /B bar_

Memory operations:

N read /P address_
V write /P address, N data_
V output /P address, N data_

Return to Menu
Return to the Ostracod Pond