Do you want BlueJ as an IDE for an assembly language? If not, screw you! I do!
BlueBird is the functional BlueJ assembly language that combines visual clarity with system calls.
Now turing complete!
The language is expressed in java class files and uses static fields as instructions. They are then linked together with arrows (they extend each other) and are executed in a chain starting from the class named main
.
Specifications for the language and compiled binary can be found in specification.md
.
Factorial example and running instructions for it can be found below.
Usage (after cloning):
Compile: cargo run --bin bluebird_compiler [path_to_BlueJ_folder]
Run: cargo run --bin bluebird_emulator [binary_name].bb
This example program adds 15 to the number requested as input when run.
Click Inspect
on the main method in BlueJ shows the call tree for that execution chain.
// main.java
public class main extends Class1
{
static int call = 5; // get input
}
// Class1.java
public class Class1 extends Class2
{
static int addi = 15; // add 15 (immediate)
}
// Class2.java
public class Class2
{
static int call = 1; // print output
}
Factorial of n >= 2
implemented in BlueBird. It works for numbers up to 12 (output is within 32 bit integer).
Each "column" in the first image is roughly equivalent to each line in the following Python code:
def factorialWithoutMul(inp5):
ans6 = inp5 # variable to store the final factorial
outer1 = 1 # outer loop counter
while True:
sum3 = 0
inner2 = 0 # inner loop counter
while True:
sum3 += ans6
inner2 += 1
if inner2 == outer1:
break
ans6 = sum3
outer1 += 1
if outer1 == inp5:
break
return ans6
The following instructions require you to have
cargo
installed
- Clone this repository (then cd into that folder)
- Extract the
factorial.zip
file to a folder calledfactorial
- Execute
cargo run --bin bluebird_compiler factorial
to compile - Execute
cargo run --bin bluebird_emulator factorial.bb
to run the program - Type an integer, press enter
- PROFIT!!! (the factorial is printed)
The project factorial.zip
can of course be opened in BlueJ to edit and display the program.
- Create a BlueJ project
- Create a class named
main
(this will be the entry point) - Add classes with static fields as instructions
- Draw arrows from main to those classes
- Compile with
bluebird_compile [FOLDER]
that points to the BlueJ project folder - Run the program with
bluebird_emulator [BINARY]
that points to the.bb
binary from step 5
The output of the previous command is automatically piped to the next command, following the arrows in BlueJ. This applies for functions in BlueBird too.
Field name is anything except whitespace. If multiple are present, the first valid one is parsed with precedence shown below with the jump operation beeing parsed first. The static field can start with either private
, public
or nothing.
static int [field_name] = [value]
value := integer
(keywords like Infinity
are not accepted)
static String [field_name] = [value]
value := "text"
Note: each block/class needs a static field for the whole program to work. Use syscall 0 to do notning as a label to jump to.
call
=int
- System call code to apply (takes in integer)save
=int
- Save previous output to register with idload
=int
- Load value from register with idjump
=String
- Jump to block with classname (cannot be done from detached chain)add
=int
- Add the value from the register with idint
addi
=int
- Add a the immediateint
skipeq
=int
Skip next instruction if output equals value in register with id
0
- Do nothing (use this as a jump label)1
- Print output5
- Read input10
- Exit program
0
- Zero constant1
- Temporary register 12
- Temporary register 23
- Temporary register 34
- Reserved by assembler5
- "Persistent" register 16
- "Persistent" register 27
- "Persistent" register 38
- "Persistent" register 4...
Note: all registers are initialized with value
0
Note: persistent registers are exactly the same as the temporary ones