This isn't exactly a creative project, in being a game or story, but it's a programming project and I wanted to share it, so this seemed to be the most logical place.
SUBLEQ Interpreter 0.7This is a project I've been working on for the past few months with C++. It's basically what inspired me to pick it back up again after I got frustrated and quit. It can load and interpret
SUBLEQ code in a user-neutral interface (that is to say, the interface sucks). It's not pretty, but it works.
The interface on startupDisplaying SUBLEQ basics for those not familiarLoading, then running some code! I also showcase the memory-dump feature. (You can replicate this screenshot, it's the included for-loop example).
If you are annoyed by "the noise", silent mode cuts almost all of that out.It's certainly not the best program ever, but I think it's pretty cool and have had a fun time playing around with it.
About Cross-Platform-ness:I honestly don't know how cross-platform it is. It solely uses the C++ standard libarary, and is compiled with GCC in Vista. I don't have much experience with OS'es other than Windows (shame on me, I know), but if a Linux/Mac guy would offer to compile it for me I'd gladly hand over the source. Just give me the program afterwards so I can host it up here for other people. And don't judge me on organazation.
I've included the text from the in-program tutorials here, as well as in the download if console text is to hard to read.
Command list:
help- herp derp
safem- toggle safe mode, which prevents infinite loops caused by an instruction jumping to itself. On by default. Does not prevent all infinite loops, just ones like line 0 unconditionally jumping to line 0
sil- toggle silent mode, where b and the write values will not be printed. Defaults to to off.
clm - Clear memory
clr - Clear ROM
prog- General tips on programming in SUBLEQ in general, and in this particular interpreter
cred - Credits, how fun
peek- Print value of a memory address
poke- Set a memory address to a value
load- Run the instructions loaded in ROM
test- load the first line and test it
set- Set an address in ROM equal to a value
sub- load individual SUBLEQ instructions into ROM- deprecated, use write instead
dump- for debugging, dump the contents of mem[0-255]
dr- dump the contents of ROM, for debugging a program
write- load the file specified, or if def the "sources.txt" in the .exe's directory into ROM
q- quit
There's also a few secret debugging instructions, don't be too suprised if you
get strange results, expecially by appending anything to 'test'.
The language interpreted by this interpreter is a OISC, or One Instruction Set Computer variant known as SUBLEQ. It's called an OISC because a computer implementing the SUBLEQ instruction as it's only instruction would be theoretically Turing-complete, meaning it can do any operation given unbounded time and memory. The name SUBLEQ is a mnemonic for what the instruction does, which is to SUbtract and Branch if Less than or EQual to zero. The instruction takes three operands, a, b, and c. It then performs the statement if(b-a <= 0){program_line= c;} In the beginning, this doesn't seem to useful. How would you set a variable to another variable, even? However, with the clever use of temp (holder) variables, every operation is possible.
The format for this interpreter is simple. Just write your instructions like so: a,b,c;.
It's important to remember that a and b are not constants, but memory addresses. Put each instruction on a new line.
When referring to line numbers with the c operand, remember that the first line is line 0.
The problem of spaghetti code is much worse in SUBLEQ, which is hard to understand even when it first comes off the keyboard. To improve your code's readability, use comments: any line prefixed with a forward slash (/) will be ignored. Additionally, leaving text after the line-terminating semicolon is allowed.
If your program relies on memory-inserted constants (for instance, my for-loop program which relies on -1), you can have them automatically inserted by using the pre-processor '@' instruction. For instance, to set memory[4] to -1 automatically, use @,4,-1. You can use the '@' instruction inline, but I consider it cheating.
Ok, here's the real attraction.
>Download<.7z~86kb. No viruses, obviously.
The code is
NOT included. If you want to take a peek, or compile it on a different system for me, I'll be happy to hand it over, but I figured for now I'd keep the download a bit smaller by leaving it out. It you do take a look, be warned it includes "gems" like
b = memory[(ROM[pc][1])];
and in general the code is quite ugly. I've done a bit of cleaning up on it, but there's more to do.
Future plans:
I have only a few features I want to add, namely two:
-More robust debugging
-A 'compile to executable' function (this counts as +0.2, so that's why it's only at 0.7 when there's just two remaining features)
Then I'll probably move on to other, more game oriented programs.
(Hint: Space station. Roguelike. Random disasters. SPACE WIZARDS)