Demo of my Swift Interpreter that uses SwiftSyntax

Hey guys, I've been working on a Swift Interpreter for a while, and the results are starting to look good. It works by parsing the Swift code using SwiftSyntax then then traversing the AST tree. Here's a demo of it working!

Note: right now the repo is private. If you'd like to help or use it, message me and I can get you access.


Are you still working on this? I was curious to try it.

I’m about to start an open source rewrite after discovering a good hack for initing generics. I’ll update the thread when it’s up.


Yes, I realize this is taking forever. (Who knew writing an interpreter would be hard? :wink:) Anyways, here's two updates on the rewrite.

1. My generics hack

Here's the repo. The most important feature is the ability to construct any generic you want at runtime. i.e. the following types can be constructed at runtime without being explicitly there at compile-time.

// compile time struct
struct MyStruct<T, U> {}
// ... later one at runtime the following can be constructed
MyStruct<Int, Double>
MyStruct<MyClass, SomeOtherType>

This generics hack is what is going to allow the interpreter to construct PATs, generic types, and call generic functions even when specific types of the values which the interpreter will create and pass around are not known at compile time. The demo video of the old interpreter in my OP has no real notion of types, and so it relied on type-eraser to handle generics.

2. A Swift bytecode compiler in the works

The rewrite is a bytecode interpreter, not just a simple AST-walker. Here's a screenshot of it going from source to bytecode.

There's still a lot to implement, but I will release it open source once I get it running simple Swift programs. No promises on when that will be.


This is honestly the coolest project.

Terms of Service

Privacy Policy

Cookie Policy