There's another optimization I should add, which is treating something like `(1,2)` as a compile-time constant, rather than something which must call `BUILD_TUPLE` at runtime.
Posts by Tyler (Jones Beach)
Ozark bytecode explorer showing RETURN_VALUE opcode with multiple values passed via tuple.
And the second is a new behavior for RETURN_VALUE, it now supports multiple returns by compiling the values into a tuple.
Ozark bytecode explorer showing UNPACK_SEQUENCE n opcode.
Two new bytecode features!
The first is `UNPACK_SEQUENCE n`.
I should also wire this up to use `__str__` soon-ish, but I don't fully support dunder-overloading in my VM yet.
Not far away though, so maybe this will give me a nudge!
CPython does something a little fancier for format, since there are technically 3 modes. but I only support the default (str) right now.
Python bytecode showing an f-string expression.
Two new opcodes for f-strings! `FORMAT` and `BUILD_STRING n`.
This ended up being a simple but interesting fix.
I had accidentally registered two implementations of float.__sub__, when one of them was supposed to be float.__mul__.
Build Your First REST API in Rust workshop with the ACM at the City College of New York.
Earlier this month, I led a "Build Your First REST API in Rust" workshop for the ACM at the City College of New York.
About 30 students attended, and we built a simple CRUD API together from scratch.
Grateful for the opportunity to be in the room!
Yikes!
memphis 0.1.0 REPL (engine: treewalk) (Type 'exit()' to quit)
>>> 4.1 - 3.01
12.340999999999998
There's a lot of magic behind:
`type(4) is int`
Python explorer showing tokens
Ozark shows tokens now!
fromscratchcode.com/ozark/
Visualizing lexer tokens today.
Found a bug that's existed for a couple years!
Python bytecode showing semicolon separators crossed with a single-line block.
Also support this version now: semicolon separators cross with single-line blocks.
Can't say I've ever written code like this! But it works.
fromscratchcode.com/ozark/?code=...
PHEW. Things are good again.
Python bytecode compiler showing semicolon failure.
EEK! Guess I don't support semicolons yet to separate statements.
Python bytecode without labels.
Python bytecode with labels.
After putting it off for weeks, I finally added assembler labels to Memphis bytecode.
Below is the before and after bytecode for this Python snippet.
s = 0
for i in [2,3,11]:
s = s + i
`JUMP -7` is now `JUMP -> L0`, and `FOR_ITER 6` becomes `FOR_ITER -> L1`. No more mental offset math!
Memphis REPL showing a NameError stack trace.
Sometimes it feels like I'm not as far along as I thought.
#python #buildinpublic #memphis
Python REPL session showing object attribute access.
Today I learned #Python attribute names have different rules in the syntax world `obj.attr` and the runtime world `getattr(obj, "attr")`.
One must be a valid identifier and the other can do whatever it wants!
lol. this was not correct.
Python doesn't allow relative imports using the "import ..." syntax!
The line
import a.b.c.d
would only write to "a" though, so that's something.
This week I wrote about what you’ll learn by writing your first library.
fromscratchcode.com/blog/write-y...
I’m refactoring Memphis imports so I can add selective imports to the bytecode compiler.
Then I hit this gem:
import ...................a.b.c.d
#Python inserts exactly ONE symbol for this line.
Which one do you think it is?
Today I didn’t code much. Friday I FINALLY converted my Rust HTTP server (cairo!) to async.
nice lean approach!
nice job getting this out the door!
I'm hosting a small coding gathering tomorrow!
Since I'm not sharing the details about when or where, I expect to see none of you there.
In the biz, we call this wOrD oF mOuTh.
I wrote a bit on how I added socket support to Memphis. You can have a read here!
fromscratchcode.com/blog/memphis...
Memphis now has a stdlib for handling network requests.
Here's a short demo!
A) github.com/JonesBeach/e...
B) github.com/JonesBeach/c...
C) github.com/JonesBeach/m...
Thanks for taking a look!
A) Building an HTTP server in Python
B) Building an HTTP server in Rust
C) Building a language runtime in Rust...which can run the Python HTTP server
I didn’t plan to build all three, but here we are. Now how to make this a resource.
What would you want to learn from it?
#python #rustlang
Sharing a few notes about one year of building From Scratch!
#substack #buildinpublic