Tyler (Jones Beach)

Tyler (Jones Beach)

@fromscratchcode.com

Helping quietly ambitious engineers get unstuck and build real things. Currently building a Python interpreter in Rust. fromscratchcode.com

32 followers26 following199 posts

Pinned

Memphis just accepted its first real network connection. I built a micro web framework (Enid) on top of my own runtime and for the first time it responded to `curl localhost:8080`. And then immediately panicked. Progress! #buildinpublic #rustlang #python

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!

Tyler (Jones Beach)@fromscratchcode.com

CPython does something a little fancier for format, since there are technically 3 modes. but I only support the default (str) right now.

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__.

Tyler (Jones Beach)@fromscratchcode.com

Yikes! memphis 0.1.0 REPL (engine: treewalk) (Type 'exit()' to quit) >>> 4.1 - 3.01 12.340999999999998

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!

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!

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.

Tyler (Jones Beach)@fromscratchcode.com

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?

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?

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

Someone asked me if Memphis was going to be faster than #Python. I said "oh, definitely not!" It's funny how people expect me to pitch why my thing is valuable. It's value is that it's mine and that it works.

I thought getting an HTTP call to work on Memphis would be the hard part. Nope! The real challenge is making these Connection and Socket objects feel like first-class citizens in the type system. Runtime design is fun!

Another day, another blown mind courtesy of Python. I just realized in Memphis, None or {} was returning True. In Python, None or {} returns {}. I hadn't realized boolean operators in Python aren't required to return a bool, they just return whichever value short-circuits first. FUN!

Memphis now supports the Python protocol for the dict() builtin. dict([('b', 4), ('c', 5)]) dict([['a', 1], ['b', 2]]) dict((k, k*k) for k in range(3)) dict(zip(['one', 'two', 'three'], [1, 2, 3])) An iterable containing another iterable which yields exactly 2 elements. This one was fun!

Wow, I'd never actually thought about how this impacts the AST. a == b == c is actually evaluated as (a == b) and (b == c) which is different than something like 1 + 2 + 3 which gets evaluated as (1 + 2) + 3

Realizing that I over-engineered my #Python dict in Memphis in a laughable way. Essentially, when #rustlang compares two keys in a HashMap, it calls ==/PartialEq. I wired mine up to call __eq__ IN PYTHON. You know, in case the two objects provided a custom implementation.