about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/interpreter.rs
AgeCommit message (Collapse)AuthorFilesLines
2021-01-17 r/2119 fix(tazjin/rlox): Include static globals in resolutionVincent Ambo1-28/+33
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 Ambo1-6/+12
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 Ambo1-11/+27
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 Ambo1-2/+2
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 Ambo1-24/+35
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 Ambo1-1/+18
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 Ambo1-41/+41
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 Ambo1-2/+9
... 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 Ambo1-35/+38
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 Ambo1-0/+1
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/2100 test(tazjin/rlox): Add a handful of interpreter testsVincent Ambo1-0/+3
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 Ambo1-1/+19
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 Ambo1-2/+33
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 Ambo1-0/+24
... 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 Ambo1-0/+1
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/2062 feat(tazjin/rlox): Parse & interpret while statementsVincent Ambo1-0/+9
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 Ambo1-0/+15
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 Ambo1-0/+1
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>
2020-12-31 r/2038 feat(tazjin/rlox): Implement block scope in interpreterVincent Ambo1-1/+28
This is currently a bit hacky because of the environment wrapping/unwrapping, will refactor this to just keep a single Rc around instead. Change-Id: Iad1cbbe35112d0329248d4655a09260fc60644c8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2304 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2020-12-31 r/2037 feat(tazjin/rlox): Implement block parsingVincent Ambo1-2/+3
Change-Id: I1b7235ed71fa36120984a36f22cd564f59581352 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2303 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-31 r/2036 refactor(tazjin/rlox): Unify parser::Statement & parser::DeclarationVincent Ambo1-12/+10
Change-Id: I6f21b246eb9d3bf760edb3220ce6be5de5b05b08 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2302 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-31 r/2035 feat(tazjin/rlox): Add support for scoped environmentsVincent Ambo1-8/+26
Adds scoped environments using a sophisticated structure known as an SRPT, which stands for "shitty parent pointer tree". Change-Id: I62f66aabe6eb32ea01c4cabcca5b03cfefcc28ee Reviewed-on: https://cl.tvl.fyi/c/depot/+/2301 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-31 r/2034 refactor(tazjin/rlox): Separate assignment and definitionVincent Ambo1-1/+14
So that: > var a = 15; > b = 12; Error in program: Error { line: 0, kind: UndefinedVariable("b") } > a = 12; print a; Number(12.0) Change-Id: I687e95ccc2d3084e39a71bd452656ae981c95191 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2300 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-31 r/2033 feat(tazjin/rlox): Implement mutable variable assignmentVincent Ambo1-31/+38
Change-Id: I56db10a5ac26958ae27a8d4c8fa7b8f8285bc7e1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2299 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-31 r/2032 refactor(tazjin/rlox): Retain interpreter state in REPLVincent Ambo1-28/+3
Change-Id: Id60760e241ad0e45871b48e499f58e9831d57316 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2298 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2020-12-31 r/2031 feat(tazjin/rlox): Add global variable support in interpreterVincent Ambo1-76/+135
Change-Id: I4134cf78dc3934a517ad0c848ae1d3729abaf882 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2297 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
2020-12-22 r/2027 feat(tazjin/rlox): Parse variable assignment & accessVincent Ambo1-0/+2
Change-Id: I9894d76716d739e85a4757d9e658f884228e7f52 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2290 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-22 r/2025 refactor(tazjin/rlox): Introduce declarations in parserVincent Ambo1-10/+18
Change-Id: I873fdd53319ec36da18926d9477e809a69dbace7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2288 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-22 r/2024 feat(tazjin/rlox): Add support for statementsVincent Ambo1-17/+25
First part of https://craftinginterpreters.com/statements-and-state.html Supports print statements, as well as evaluation for the sake of it (i.e. future side-effects). Change-Id: Ic6653b568f98d6cfe3f297615b7113c0ba1d9a70 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2287 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-20 r/2019 feat(tazjin/rlox): Add runtime type error handlingVincent Ambo1-14/+31
Change-Id: I0d52bc9ff5be6421cb4131265ed28ce1ea7d8ff3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2282 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-20 r/2018 feat(tazjin/rlox): Implement tree-walk interpreter of exprsVincent Ambo1-3/+67
This is only a subset of the Lox spec so far. It implements the language up to the runtime error chapter on https://craftinginterpreters.com/evaluating-expressions.html Change-Id: I295dbf4b6544420d6fe80b6aaba661fb21acdea6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2281 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-06 r/1991 feat(tazjin/rlox): Synchronise parser state after errorsVincent Ambo1-1/+1
This lets the parser collect multiple errors instead of returning after the first one, with some optimistic synchronisation after encountering something that looks wonky. Change-Id: Ie9d0ce8de9dcc7a3d1e7aa2abe15f74cab0ab96b Reviewed-on: https://cl.tvl.fyi/c/depot/+/2236 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-12-06 r/1990 feat(tazjin/rlox): Wire up parser to the REPLVincent Ambo1-2/+10
Change-Id: I940448c63ce105d53a0f281b6320ffb01378f207 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2235 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-11-28 r/1956 refactor(tazjin/rlox): Thread through scanner errorsVincent Ambo1-2/+17
... and show them to users, very crudely. Change-Id: If4491b14db1124313f6ab7e5fbfdce9fea501d11 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2193 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-11-28 r/1952 fix(tazjin/rlox): Clear previous line in REPL modeVincent Ambo1-2/+3
Change-Id: I8acc5b0d07b2c656f9bba76a6ddac6b9088ea563 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2189 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-11-27 r/1927 chore(tazjin/rlox): Wire scanner to interpreter to reduce warningsVincent Ambo1-1/+5
... they're just noisy at the moment. This isn't complete because it doesn't thread through scanner errors. Change-Id: I0f75d2b20fa3f57be1af5d1d8aa8059856855825 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2162 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
2020-11-23 r/1913 feat(tazjin/rlox): Add basic program structureVincent Ambo1-0/+4
... as well as a Nix derivation, because why not. Change-Id: Iaf2591ab72676fe0732c3f807b3aa0cff13fb4ef Reviewed-on: https://cl.tvl.fyi/c/depot/+/2143 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI