Hey everyone! In this tutorial, we’ll add PID tracking to the Iridium VM. Please ensure you are starting from https://gitlab.com/subnetzero/iridium/tags/0.0.17. == PIDs There are two components we need to unique identify:
Hey everyone! In this tutorial, we’re going to start adding in multithreading to the Iridium VM. Please make sure you are starting from this point in the code: https://gitlab.com/subnetzero/iridium/tags/0.0.16. Going forward, I’m going to make a tag per tutorial so that everyone starts from a common point. === A Note on Assumed Knowledge I write these tutorials target towards more advanced users. I sometimes skip small steps, such as "add in this line to file X".
This is going to be a longer post. In it, we’ll wrap up our two-pass assembler, add a
PRTS opcode for printing, and tie up some other loose ends. At the end, we should have an interpreter with a good amount of functionality and a simple assembly language. We are, of course, far from done with the project. I want to work on a different tutorial series for a bit, then we’ll continue with Iridium.
=== Quick Change
Add the following dependencies in your Cargo.toml. We’ll need them later:
Having to start the interpreter, then type
.load_file, etc is cumbersome. Let’s change it so that the VM tries to execute the file given to it as an argument. There’s a super handy-dandy crate called
clap in Rust that will make this trivial. The behavior we want is:
If the user types
iridiumand nothing else, they will go directly to a
If the user types
iridium /path/to/valid/*.iasm, that is, they want to execute a file of code directly, it should do that then exitNote
Welcome back! When we last left our intrepid readers, we were about to write an assembler struct.
But why? What does it do?
What does it all mean?! Why don’t more people love interrobangs?! Ahem.
What are Strings?
This may shock you, but they are a bit more complicated than they might seem. Since a computer cares about bytes, it has no concept of the letter
!or any other letter. These having meaning to us humans. But we want our users to be able to give input and read output without having to do it all in hex. The solution is to use some sort of character encoding. This maps a particular character to a number. You’ll hear two common encodings mentioned these days: ASCII and UTF. I’m not going to go into an exhaustive history of them; for that, check out this article for ASCII and this article for UTF-8. I will cover enough for us to put in support for strings, though.
Improving the Assembler
Our assembler right now can recognize one opcode,
load. We need to teach it to recognize all the rest. There’s a couple ways we can do that:
We can write a parser for each opcode
We can write a parser that recognizes the letters
a-zand then check if they are a valid Opcode.
Let’s go with option #2, since it will require much less copy-paste. It also gives us an excuse to implement
From<CompleteStr<_>>for our opcodes! == The
instruction.rs, below the block where we implemented
From<u8>, put this:1/3 »