about summary refs log tree commit diff
path: root/users/tazjin/rlox (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-02-07 r/3776 fix(users/tazjin): rustfmt code with non-default settingsVincent Ambo8-288/+140
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 Ambo4-1/+22
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 Ambo4-16/+84
... 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 Ambo3-15/+18
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 Ambo2-21/+24
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 Ambo4-25/+31
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 Ambo6-12/+193
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 Ambo4-3/+38
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-10-19 r/2976 chore(tazjin/rlox): Add some old code example filesVincent Ambo8-0/+92
Change-Id: I484b11069286ea2277e9e158fa5c3bd34f84c89e Reviewed-on: https://cl.tvl.fyi/c/depot/+/3464 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-04-10 r/2470 refactor: Move nixpkgs attribute to `third_party.nixpkgs`Vincent Ambo1-2/+2
Please read b/108 to make sense of this. This gets rid of the explicit list of exposed packages from nixpkgs, and instead makes the entire package set available at `third_party.nixpkgs`. To accommodate this, a LOT of things have to be very slightly shuffled around. Some of this was done in already submitted CLs, but this change is unfortunately still quite noisy. Pay extra attention to: * overlay-like functionality that was partially moved to actual overlays (partially as in, the minimum required to get a green build) * modified uses of the package set path, esp. in NixOS systems Special notes: * xanthous has been disabled in CI because of issues with the Haskell overlay * //third_party/nix has been disabled because of other unclear dependency issues Both of these will be tackled in a followup CL. Change-Id: I2f9c60a4d275fdb5209264be0addfd7e06c53118 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2910 Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
2021-03-06 r/2274 feat(tazjin/rlox): Implement global variable accessVincent Ambo4-6/+48
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 Ambo5-15/+80
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 Ambo4-53/+78
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 Ambo3-5/+61
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 Ambo4-19/+65
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-02 r/2262 test(tazjin/rlox): Add simple string assertionsVincent Ambo1-0/+10
Change-Id: I6c60934d57170157d877e71cc87a97ab773342b5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2581 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-03-01 r/2259 feat(tazjin/rlox): Add a simple string internerVincent Ambo3-0/+112
This is based on this matklad post: https://matklad.github.io/2020/03/22/fast-simple-rust-interner.html It's modified slightly to provide a safer interface and slightly more readable implementation: * interned string IDs are wrapped in a newtype that is not publicly constructible * unsafe block is reduced to only the small scope in which it is needed * lookup lifetime is pinned explicitly to make the intent clearer when reading this code Change-Id: Ia3dae988f33f8e5e7d8dc0c1a9216914a945b036 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2578 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-03-01 r/2258 feat(tazjin/rlox): Add initial support for stringsVincent Ambo3-1/+40
... 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 Ambo4-0/+43
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 Ambo4-6/+50
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/2254 refactor(tazjin/rlox): Let binary_op! work on different typesVincent Ambo1-9/+13
This makes it possible to specify the input & output types of the binary_op macro. If only one type is specified, it is assumed that the input and output types are the same. Change-Id: Idfcc9ba462db3976b69379b6693d091e1a525a3b Reviewed-on: https://cl.tvl.fyi/c/depot/+/2573 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-28 r/2253 feat(tazjin/rlox): Implement unary negation operatorVincent Ambo5-0/+32
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 Ambo5-6/+52
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 Ambo6-25/+59
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/2250 test(tazjin/rlox): Add some tests for numerical operationsVincent Ambo2-0/+51
If I was adding any dependencies, this might be a good one for a property-based test thing, but I'm not going to. Change-Id: Ia801d041479d1a88c59ef9e0fe1460b3640382e3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2569 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-28 r/2249 chore(tazjin/rlox): Add stack printing when 'disassemble' is onVincent Ambo1-0/+3
Change-Id: I71ae83101002f8fead3fa6cbd4cb229a2d6e3902 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2568 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 Ambo3-19/+11
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-28 r/2246 fix(tazjin/rlox): Fix identifier order in binary_op macroVincent Ambo1-1/+1
Change-Id: I92253e875436bcb42732a157979a9d1e7ca0cd06 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2565 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2244 chore(tazjin/rlox): Fill in minor missing implementationsVincent Ambo1-20/+21
This should clean up everything in the way of actually running this end-to-end. Change-Id: Ie89d82472a458256a251a4fddc1c36d88d21f5f2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2563 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2243 feat(tazjin/rlox): Print compiled bytecode with disassemble featureVincent Ambo2-0/+11
Change-Id: I42293b334248b5228dd90f13b9a400ccdca20a84 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2562 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2242 feat(tazjin/rlox): Implement parser precedence rulesVincent Ambo1-4/+24
Change-Id: Idcf3c84126603086bbf7e8d54773bccb3ae3b5ab Reviewed-on: https://cl.tvl.fyi/c/depot/+/2561 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2241 feat(tazjin/rlox): Add initial Pratt parser table lookupVincent Ambo1-9/+67
Change-Id: I1b894d2f84d23ddddcd1bb8794f771512b7d677e Reviewed-on: https://cl.tvl.fyi/c/depot/+/2560 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2240 feat(tazjin/rlox): Partial implementation of binary operatorsVincent Ambo1-1/+49
Change-Id: I6f0bc9f58b51dec2673c918e08b199b52e793ed4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2559 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-02-27 r/2239 feat(tazjin/rlox): Set up precedence parsing scaffoldingVincent Ambo1-12/+67
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 Ambo2-6/+26
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 Ambo3-1/+87
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>
2021-02-27 r/2236 chore(tazjin/rlox): Add From<Error> for Vec<Error>Vincent Ambo1-0/+8
This makes it easier to transition between the single/multi error functions via ? Change-Id: Ie027f4700da463a549be6f0d4a0022a9b8dc0d61 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2555 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-02-27 r/2235 style(tazjin/rlox): Set max_width=80Vincent Ambo7-50/+153
Change-Id: Ib64831c0b97c94fdfbdbae64f4dfccc86879ef73 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2554 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-02-27 r/2234 chore(tazjin/rlox): Implement From<ScannerError> for bytecode errorsVincent Ambo2-3/+22
Change-Id: I446c6e38cf239a132882d37df156884d319ca111 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2553 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-01-19 r/2132 refactor(tazjin/rlox): Prepare scanner for shared useVincent Ambo5-12/+35
In the book, the clox interpreter has its own scanner which uses a pull-based model for a single pass compiler. I can't be bothered to write another scanner, or amend this one into pull-mode to work with the treewalk interpreter, so instead I will just reuse it and pull from a vector of tokens. The tokens are shared between both interpreters and the scanner is not what I'm interested in here. Change-Id: Ib07e89127fce2b047f9b3e1ff7e9908d798b3b2b Reviewed-on: https://cl.tvl.fyi/c/depot/+/2420 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-18 r/2129 refactor(tazjin/rlox): Add Interpreter trait for switching implsVincent Ambo8-102/+125
Change-Id: Iae28d64ce879014c5e5d7e145c536c1f16ad307d Reviewed-on: https://cl.tvl.fyi/c/depot/+/2418 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-17 r/2128 feat(tazjin/rlox): Implement simple arithmetic operatorsVincent Ambo4-1/+34
Change-Id: I9873bcd281053f4e9820a5119f5992a0b8cb8cfc Reviewed-on: https://cl.tvl.fyi/c/depot/+/2417 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-01-17 r/2127 feat(tazjin/rlox): Bootstrap VM for Lox bytecodeVincent Ambo7-25/+89
Change-Id: I479e20bf2087e5c4aa20e31b364c57ed0d961bcf Reviewed-on: https://cl.tvl.fyi/c/depot/+/2416 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-01-17 r/2126 chore(tazjin/rlox): Move other modules under treewalk::Vincent Ambo8-22/+22
It's unclear if the second part of the book can reuse anything from the first part (I'm guessing probably the scanner, but I'll move that back if it turns out to be the case). Change-Id: I9411355929e31ac6e953599e51665406b1f48d55 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2415 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-17 r/2125 feat(tazjin/rlox): Track source lines along with bytecodeVincent Ambo2-3/+40
Change-Id: I272e73b9b1c9571fbfe4fa983fb4283ddee02bd4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2414 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-17 r/2124 feat(tazjin/rlox): Initial bytecode representationVincent Ambo4-1/+80
This is significantly simplified from the version in the book, since I'm using Rust's Vec and not implementing dynamic arrays manually. We'll see if I run into issues with that ... Change-Id: Ie3446ac3884b850f3ba73a4b1a6ca14e68054188 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2413 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-17 r/2123 refactor(tazjin/rlox): Move entrypoints into interpretersVincent Ambo5-48/+69
Right now this introduces a simple mechanism to flip between the interpreters. Change-Id: I92ee920c53d76ab6b664ac671993a6d6426af61a Reviewed-on: https://cl.tvl.fyi/c/depot/+/2412 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI