Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize list methods in LoxList #25

Closed
wants to merge 2 commits into from

Conversation

quephird
Copy link
Owner

@quephird quephird commented Mar 20, 2024

  • Created private inner classes inside LoxList, one for representing the append() method and the other for the deleteAt() method, both of which implement LoxCallable and are instantiated and returned when the correspondent LoxList property is retrieved. The two inner classes are passed a reference to the outer LoxList instance such that they can access/mutate its elements.
  • For the time being, the standardLibrary string previously defined in Interpreter is no longer needed, as all necessary plumbing is centralized in LoxList, and so there is no more hidden List class to instantiate. Perhaps in the future, we can reinstate it when we build things on top of existing infrastructure instead of being foundational but needing to access features in the Swift layer that are not expressible in Lox code.
  • Since there is no more List class, there is no need for appendNative and deleteAtNative cases in NativeFunction
  • The LoxValue enum now has a callable case for a third class of functions, for the time being to represent methods of a specialized Lox class. The other two extant cases just didn't quite work:
    • a UserDefinedFunction, although gets passed an Environment through its constructor, also needs to be passed ResolvedStatements as its body, which would be awkward to express in the interpreter when bootstrapping. Moreover, there is no way to express new language features in Lox itself, which is the central to the problem we're trying to solve.
    • a NativeFunction does not have access to an environment and thus no way to get a handle to the instance whose method is being invoked. It really is intended to represent a standalone function like clock(). It also didn't make sense to add a klass property to NativeFunction since it would be nonsensical for things like clock() which are not bound to a class.
  • In order to introduce the callable case into LoxValue, I needed to be able to have the latter conform to Equatable explicitly. This conformance is only meaningful in the context of a unit test, in which I need to be able to compare ASTs in many cases.

@quephird quephird closed this Mar 24, 2024
@quephird quephird deleted the centralize_list_methods_in_loxlist branch March 24, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant