honeypony / jaylox Goto Github PK
View Code? Open in Web Editor NEWA compiler/transpiler targetting C, for the Lox language from Crafting Interpreters
A compiler/transpiler targetting C, for the Lox language from Crafting Interpreters
gc: trace 000001eb00505328 = instance (-1512 rel to high_ptr)
-- instance->class: 000001eb00504b40 -> 000001eb00505370
gc: copy 000001eb005050e0 -> 000001eb00505910 (216 bytes)
gc: copy table
-- instance->table: 000001eb005050e0 -> 000001eb00505910
^^^ return size = 24
gc: trace 000001eb00505340 = instance (-1704 rel to high_ptr)
gc: copy 000001eb00505340 -> 000001eb005059e8 (24 bytes)
gc: copy instance
-- instance->class: 000001eb00505340 -> 000001eb005059e8
-- instance->table: 0000000000000000 -> 0000000000000000
runtime error: unknown garbage collection type
This output shows that an instance's ->class is somehow set t the same pointer (ending in 340) and so when it copies that value over, it ends up causing a problem for itself.
Now, strictly speaking, if an object is pointing at itself when we visit it, we shouldn't copy it -- so more than one thing is going wrong here..?
The idea here is that, instead of having specialized functions for things like arithmetic operations, we just directly generate code like:
// expr: subtract
jay_check_numerical(jay_stack_ptr[-2]);
jay_check_numerical(jay_stack_ptr[-1]);
jay_stack_ptr[-2] = JAY_AS_NUMBER(jay_stack_ptr[-2]) - JAY_AS_NUMBER(jay_stack_ptr[-1]);
jay_stack_ptr -= 1;
Then, we can very easily check if one if the inner expressions is an expression that MUST produce a number, and simply elide that 'check'. Obviously, this is still a little bit slower than if we don't go through the stack at all, but it's an easy optimization.
In fact, it should be relatively straightforward to bridge from doing that to just checking the operands in a larger expression and then directly generating an arithmetic expression. But this simple optimization could be done just with some very basic pattern matching in the compiler.
I want to get jaylox in a state where it runs sort of "head to head" with clox before I start adding too many other optimizations.
Once all these features are done, it would be interesting to benchmark clox vs jaylox. Then, I can start implementing new optimizations.
This would allow for any optimizations to locals, such as type-flow analysis / fence-elision / whatever, to be automatically applied to any variables that are only accessed in main, without any otherwise special logic.
It can be hard to keep track of which tests are failing, so I want to write them down.
Known failing tests at the moment: None!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.