about summary refs log tree commit diff
path: root/users/tazjin/rlox (follow)
AgeCommit message (Collapse)AuthorFilesLines
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
2021-01-17 r/2120 refactor(tazjin/rlox): Move treewalk interpreter into subdirectoryVincent Ambo7-8/+9
Change-Id: I9163f75db5a1ff75e1b1f81bad78fd9d8ddb104a Reviewed-on: https://cl.tvl.fyi/c/depot/+/2409 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-17 r/2119 fix(tazjin/rlox): Include static globals in resolutionVincent Ambo2-39/+51
Change-Id: Id377ce1fe4c9b9cd65395d15873399d9b6d38af8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2408 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-17 r/2118 refactor(tazjin/rlox): Call resolver from interpreterVincent Ambo4-15/+17
This makes the interpreter API a bit cleaner and allows for tighter integration between the two parts (e.g. for static globals, which are unhandled in the resolver right now). Change-Id: I363714dc2e13cefa7731b54326573e0b871295d6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2407 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-16 r/2114 feat(tazjin/rlox): Use variable depth for env lookupVincent Ambo2-12/+31
Finishes the binding implementation from https://craftinginterpreters.com/resolving-and-binding.html Change-Id: I1e2c1f4139d9e77ce0b99e38db26edd4cdb56ad2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2404 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-16 r/2113 feat(tazjin/rlox): Implement variable depth resolverVincent Ambo5-16/+217
Implements the first part of the resolver from https://craftinginterpreters.com/resolving-and-binding.html This is wired up to the execution paths in main, but not yet in the tests. The resolved depth is also not actually used for variable lookups (yet). Change-Id: I3a8615252b7b9b12d5a290c5ddf85988f61b9184 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2403 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2109 feat(tazjin/rlox): Implement support for closuresVincent Ambo2-24/+57
Change-Id: I0ffc810807a1a6ec90455a4f2d2bd977833005bd Reviewed-on: https://cl.tvl.fyi/c/depot/+/2396 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2108 feat(tazjin/rlox): Implement early return from functionsVincent Ambo3-1/+47
In the book this is implemented via exceptions as control flow, and I'm sticking somewhat closely to that by doing it via an error variant. Change-Id: I9c7b84d6bb28265ab94021ea681df84f16a53da2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2395 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2107 refactor(tazjin/rlox): Let scanner tokens own their lexemeVincent Ambo5-158/+150
This removes the runtime dependency on a borrow into the program source code. It's not yet ideal because there are a lot of tokens where we really don't care about the lexeme, but this is what the book does and I am not going to change that. Change-Id: I888e18f98597766d6f725cbf9241e8eb2bd839e2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2394 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2106 feat(tazjin/rlox): Implement function definitionsVincent Ambo3-5/+28
... with this, functions now work. Note that this bubbled up another weird code structure nit: The parser::Function type should probably not carry its name directly. However this doesn't matter much and I don't care right now. Change-Id: If8e3b23f07033260433b9acd45f37c0e61fd2ff8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2393 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2105 feat(tazjin/rlox): Implement calling user-defined functionsVincent Ambo1-7/+20
This slightly jiggles around interpret_block to let callers pass in an environment. Change-Id: I03112a38be0e8696242d8eae8d41da8c2cc66b48 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2392 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2104 refactor(tazjin/rlox): Thread lifetimes through interpreterVincent Ambo3-48/+59
In order to store a function in the interpreter's representation of a callable, the lifetimes used throughout rlox need to be threaded through properly. This is currently not optimal, for two reasons: * following the design of the book's scanner, the source code slice needs to still be available at runtime. Rust makes this explicit, but it seems unnecessary. * the interpreter's lifetime is now bounded to be smaller than the source's, which means that the REPL no longer persists state between evaluations Both of these can be fixed eventually by diverging the scanner from the book slightly, but right now that's not my priority. Change-Id: Id0bf694541ff59795cfdea3c64a965384a49bfe2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2391 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2103 feat(tazjin/rlox): Parse function declarationsVincent Ambo2-4/+67
Change-Id: I1db4316563827976e5233dc7a626968f80b992ef Reviewed-on: https://cl.tvl.fyi/c/depot/+/2390 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2102 refactor(tazjin/rlox): Add helper method for parsing identifiersVincent Ambo2-16/+19
Change-Id: I9a45f823f16919319d6135225d5bd53ed54c2530 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2388 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2101 refactor(tazjin/rlox): Let Parser::match_token take a single kindVincent Ambo1-24/+22
This is much easier to read & write. It's been annoying me all the way through. Change-Id: Ia91756d3111a2ce3f74e1c14bccc210118d221dd Reviewed-on: https://cl.tvl.fyi/c/depot/+/2387 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2100 test(tazjin/rlox): Add a handful of interpreter testsVincent Ambo2-0/+66
Change-Id: I32dd896d42cc73d68d73093e9cbb74b48d95e041 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2386 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2099 feat(tazjin/rlox): Implement PartialEq for interpreter::ValueVincent Ambo1-0/+10
Values have equality, unless they're functions. Change-Id: Ie5c623081a1fa556e6b7a5251b0ce85af68dd31a Reviewed-on: https://cl.tvl.fyi/c/depot/+/2385 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2098 feat(tazjin/rlox): Always return values from interpreterVincent Ambo1-20/+23
This makes it easier to write interpreter tests, as we don't need to look at output and such. Change-Id: I6f8ce0cb0c482b8c00707d09e6be750c8e534176 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2384 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2097 refactor(tazjin/rlox): Constructor for interpreter with globalsVincent Ambo2-3/+21
Change-Id: Id8242c22500c8e2781cc656d3faabb28d9bdf091 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2383 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2096 feat(tazjin/rlox): Implement function call evaluationVincent Ambo2-2/+34
Change-Id: I6767c3a1a9654475b4066415f8c026b9c5b5907a Reviewed-on: https://cl.tvl.fyi/c/depot/+/2382 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-14 r/2095 feat(tazjin/rlox): Scaffolding for builtin functionsVincent Ambo2-0/+49
... and adds an example builtin which returns the current epoch. The types introduced by this, especially in the interpreter module, are going to be used for user-defined functions, too. Change-Id: I0364a67241e94642cde08489ac711a340e30ebe8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2381 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-13 r/2093 refactor(tazjin/rlox): Wrap interpreter values in new enumVincent Ambo1-25/+52
This makes it possible to distinguish between literal and other values, such as functions. Change-Id: I4d87b96c2988e25a61eecfeeb56188fabfd0dc40 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2367 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-13 r/2092 feat(tazjin/rlox): Parse function callsVincent Ambo2-4/+53
Change-Id: I1836c73dbfd5fc4ca30c2d22bbffee2fb222d566 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2366 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-06 r/2063 feat(tazjin/rlox): Implement for loops via desugaring to whileVincent Ambo1-0/+62
Change-Id: I31a93efcc8e0c2bcb8549e2a2c05bb58d2dc74ca Reviewed-on: https://cl.tvl.fyi/c/depot/+/2326 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-06 r/2062 feat(tazjin/rlox): Parse & interpret while statementsVincent Ambo2-0/+40
Change-Id: Iee772274de95dfd6a6d4af973402859aeda17b1d Reviewed-on: https://cl.tvl.fyi/c/depot/+/2325 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-06 r/2061 feat(tazjin/rlox): Parse & interpret logical operatorsVincent Ambo2-2/+55
Change-Id: I1a7d0eda61f7f077b820dc0d2c2516e204966962 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2324 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2021-01-06 r/2060 feat(tazjin/rlox): Interpret if statementsVincent Ambo1-1/+13
Change-Id: Ic6aed29bec42098eb07e1ba9eb01dbcaae8d11e3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2322 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2021-01-06 r/2059 feat(tazjin/rlox): Parse if statementsVincent Ambo3-1/+45
Change-Id: I2352d75a3f02d65a5a2d04fb2cc4daa50f11ca1e Reviewed-on: https://cl.tvl.fyi/c/depot/+/2321 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2020-12-31 r/2039 refactor(tazjin/rlox): Hold shared environment ptr in interpreterVincent Ambo1-17/+37
Change-Id: Ia4c4ef330be431a344d42bc00d3a518825fb9399 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2305 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>