DEV Community

Thomas Leathers
Thomas Leathers

Posted on

Ternary, Trytes, and Python: The Story of a VM.

Introduction

SBTCVM, that's Simple Balanced Ternary Computer Virtual Machine, is just that. A virtual machine that uses 3-state logic. but What drove me to write such a program? Well, the story of SBTCVM starts with a rather simple program. SBTCVM would not be possible if it wasn't for a particular python module called libbaltcalc. The origin of it is a Balanced ternary calculator, sure enough called BalTcalc.

How it all Started

It was over a year and a half ago... late may to early June, 2016. I was reading Wikipedia article after Wikipedia article, as sometimes happens to many of us, and happened across Balanced Ternary. A nonstandard variant of Base 3. I don't recall exactly what caught my eye about it, but something did, as in early June i put a balanced ternary calculator on GitHub.

this calculator wasn't much, just simple add, subtract, multiply and integer division, along with 2-way base conversion to decimal. It was only usable in a terminal. It did however, leave me with a library that could work with balanced ternary integers, and convert them to and from decimal, and It is this library that would power the most complex python project i have ever worked on...

Enter the VM:

TDA Mark 1 was no Ternary supercomputer, the D in TDA literally stood for "Demonstration". It featured 4-trit instructions and 6-trit data. It didn't have a lot of the features SBTCVM has today, but what Mark 1 did introduce helped pave the way for SBTCVM. TDA did introduce a text encoding, and what eventually evolved into SBTCVM's assembler.

SBTCVM Mark 1.1 was more of a revival than anything else, but the most important feature It introduced was Full rewritable program memory, as until 1.1, the program memory was treated as ROM.

SBTCVM Mark 2 is the latest in the original branch of SBTCVM, and has been in development for around 10 months, has thousands of lines of code, and even a framebuffered display. It features 6-trit instructions, and 9-trit data, unlike its two predecessors. Mark 2 also marks when SBTCVM became more of a suite of utilities, centered around the VM itself. The assembler is more capable than ever, and while not as flexible as what the next codebase will bring, It is still quite useful in the meantime.

The future:

SBTCVM's next generation codebase is in early development. And while the new codebase has a vastly different design under the hood, It builds on what was learned with the old codebase, while looking towards the future.

What I learned:

Working on the SBTCVM project has taught me some important lessons:

Documentation can be boring, but it is endlessly useful. Even if you designed most of the working of a program, and think you will remember, write it down. It will help both you, others helping you, and the user.

Don't be afraid to try new ideas. Even if you wind up being the only project of its kind on GitHub, don't let that stop you. The best way to get your ideas realized is to get coding!

Don't pretend there is a deadline when there isn't. Taking one's time can really help. You will do much better on your projects if you just take the time to stop, think, and read over your code.

You Never know where a program will take you. Programming is both predicable, and as unpredictable as a random number generator. Often at the same time. Whats most important is to keep working at your ideas, and you might just get there.

Top comments (0)