about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/bytecode/compiler.rs (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-02-07 r/3776 fix(users/tazjin): rustfmt code with non-default settingsVincent Ambo1-62/+27
rustfmt only sometimes detects path-based nested config files (probably some kind of race?), so my users folder uses a separate formatting check for rustfmt to avoid flaky CI. Enough flakes around already ... Change-Id: Ifd862f9974f071b3a256643dd8e56c019116156a Reviewed-on: https://cl.tvl.fyi/c/depot/+/5242 Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
2021-10-22 r/2987 feat(tazjin/rlox): Implement else clausesVincent Ambo1-0/+14
Change-Id: I0bc2333c0b4dd3e2e584a90d0d15b28c48130f03 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3740 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-10-22 r/2986 feat(tazjin/rlox): Implement simple conditionalsVincent Ambo1-14/+51
... basically just optional blocks (no else). Change-Id: If091c6b8fdeb6c13a5f3dd284d0a9a87f9f4228d Reviewed-on: https://cl.tvl.fyi/c/depot/+/3739 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-10-22 r/2985 refactor(tazjin/rlox): Return index after adding operationsVincent Ambo1-12/+12
Change-Id: I100eb9b55ace37e5c7c878d3c224b567ee8d1e36 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3738 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-10-20 r/2981 refactor(tazjin/rlox): Remove use of sentinel valuesVincent Ambo1-19/+20
The C code from which this is translated uses sentinel values for various things, this commit replaces them with standard Rust types instead (amongst a bunch of other small improvements). Change-Id: I892811a7afebb5a0f3b825824fc493ab0b399e44 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3735 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-10-20 r/2980 refactor(tazjin/rlox): Introduce newtypes for various indicesVincent Ambo1-12/+12
Since this code is essentially a fairly plain translation from C, it is a bit confusing to deal with the original untyped code. This is an attempt to try and clean some of it up. Change-Id: Icd21f531932e1a811c0d6dbf2e9acba61ca9c45d Reviewed-on: https://cl.tvl.fyi/c/depot/+/3734 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-10-19 r/2978 feat(tazjin/rlox): Support local variablesVincent Ambo1-6/+157
WIP Change-Id: I78fbc885faaac165c380cbd9aa98b4b64a9b8274 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3685 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-10-19 r/2977 feat(tazjin/rlox): Global variable assignmentVincent Ambo1-2/+10
Needed for example code compatibility. Change-Id: Id83210eaaad7dcfef5aa238dd3a7ec159f6935e9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3684 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-03-06 r/2274 feat(tazjin/rlox): Implement global variable accessVincent Ambo1-5/+25
This also includes a fix for an issue where the identifiers of variables were pushed onto the stack, which is incorrect. Change-Id: Id89b388268efad295f29978d767aa4b33c4ded14 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2594 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-03-06 r/2273 feat(tazjin/rlox): Implement global variable definitionVincent Ambo1-13/+61
identifier_str might look a bit overengineered, but we want to reuse this bit of code and it needs a reference to the token from which to pick the identifier. The problem with this is that the token would be owned by self, but the function needs to mutate (the interner), so this implementation is the most straightforward way of acquiring and working with an immutable reference to the token before interning the identifier. Change-Id: I618ce8f789cb59b3a9c5b79a13111ea6d00b2424 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2592 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-03-06 r/2272 refactor(tazjin/rlox): Refactor Compiler::consume into a macroVincent Ambo1-18/+21
Making this function a macro instead makes it possible to match arbitrary token kinds, even the ones that carry data, without changing the syntax too much. Change-Id: I5cda9e36d6833bd9c259f7d4d8340db6e783b4e8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2593 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-03-06 r/2271 fix(tazjin/rlox): Resynchronise after panickingVincent Ambo1-1/+32
Change-Id: I60939f7a2c523b6ca1e9782e58c97959da38cfff Reviewed-on: https://cl.tvl.fyi/c/depot/+/2591 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-03-03 r/2265 feat(tazjin/rlox): Implement expression statementsVincent Ambo1-3/+13
These aren't particularly useful without side effects, but one step at a time. This diverges slightly from the book, in that OpPop retains the last value it "forgot" from the stack in a special field on the interpreter. This makes it possible to return values from expression statements, which helps in cases where Lox is embedded as a scripting language (please don't do this ever) or in tests. Change-Id: Ided0bc04c6e80ddb23ba4693d61ac9e08b002d58 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2584 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-03-03 r/2264 feat(tazjin/rlox): Add support for print statementVincent Ambo1-5/+39
Change-Id: Ic3e7e722325c8784b848c0bcd573c2e51e123c40 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2583 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-03-02 r/2263 feat(tazjin/rlox): Intern all string constantsVincent Ambo1-10/+12
This is again a step closer to the book, but there are some notable differences: * Only constants encountered by the compiler are interned, all other string operations (well, concatenation) happen with heap objects. * OpReturn will always ensure that a returned string value is newly heap allocated and does not reference the interner. Change-Id: If4f04309446e01b8ff2db51094e9710d465dbc50 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2582 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-03-01 r/2258 feat(tazjin/rlox): Add initial support for stringsVincent Ambo1-0/+16
... including concatenation. This diverges significantly from the book, as I'm using std::String instead of implementing the book's whole heap object management system. It's possible that Lox in Rust actually doesn't need a GC and the ownership model works just fine. Change-Id: I374a0461d627cfafc26b2b54bfefac8b7c574d00 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2577 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-02-28 r/2256 feat(tazjin/rlox): Implement comparison operatorsVincent Ambo1-0/+28
Change-Id: I03b751db52a3bd502fb4fbda6e89cad087ccad74 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2575 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-28 r/2255 feat(tazjin/rlox): Implement equality operatorVincent Ambo1-0/+16
Change-Id: I5587a11646e228c5af4dc7ca6da026bb4a2592a6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2574 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-28 r/2253 feat(tazjin/rlox): Implement unary negation operatorVincent Ambo1-0/+5
Change-Id: I9a5bd3581d4ed05371651697ec496341eb7971ae Reviewed-on: https://cl.tvl.fyi/c/depot/+/2572 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-28 r/2252 feat(tazjin/rlox): Support trivial literals in bytecode compilerVincent Ambo1-2/+28
Adds support for true, false & nil. These each come with a new separate opcode and are pushed directly on the stack. Change-Id: I405b5b09496dcf99d514d3411c083e0834377167 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2571 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-28 r/2251 refactor(tazjin/rlox): Represent VM values as enumsVincent Ambo1-1/+1
Introduces a new enum which represents the different types of possible values, and modifies the rest of the existing code to wrap/unwrap these enum variants correctly. Notably in the vm module, a new macro has been introduced that makes it possible to encode a type expectation and return a runtime error in case of a type mismatch. Change-Id: I325b5e31e395c62d8819ab2af6d398e1277333c0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2570 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-28 r/2248 fix(tazjin/rlox): Fix selection of next parser precedence ruleVincent Ambo1-1/+1
Without this fix we would keep parsing in the same precedence level and get weird things like: 10 - -10 + 10 => 10 Change-Id: If2bed4569fbf566027011037165a9b3c09b7427c Reviewed-on: https://cl.tvl.fyi/c/depot/+/2567 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-28 r/2247 feat(tazjin/rlox): Wire up bytecode interpreter & print resultsVincent Ambo1-0/+287
This makes the bytecode interpreter actually usable. Change-Id: I24afc7ce461c6673dc42581378f6e14da7aece5c Reviewed-on: https://cl.tvl.fyi/c/depot/+/2566 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2239 feat(tazjin/rlox): Set up precedence parsing scaffoldingVincent Ambo1-101/+0
Defines a new precedence levels enum which can be used to restrict the parser precedence in any given location. As an example, unary expressions and grouping are implemented, as these have a different precedence from e.g. expression() Change-Id: I91f299fc77530f76c3aba717f638985428104ee5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2558 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2238 chore(tazjin/rlox): Set up some scaffolding for panic modeVincent Ambo1-5/+22
This lets us suppress reporting of additional errors from the compiler until a synchronisation point is reached. Change-Id: Iacf90949f868fbdb4349750065b5e458cf74d32a Reviewed-on: https://cl.tvl.fyi/c/depot/+/2557 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2237 feat(tazjin/rlox): Bootstrap rough shape of bytecode compilerVincent Ambo1-0/+84
This one necessarily has to diverge more from the book than the treewalk interpreter did, so some of this is expected to change, but I'm happy with the rough shape. Since we're reusing the old scanner, the compiler/parser struct owns an iterator over all tokens with which the pull-scanner from the bytecode chapters is simulated. Change-Id: Icfa0bd4729d9df786e08f7e49a25cba1b9989a91 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2556 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>