* Modify parser and AST nodes to include let statement
* Implement let variables
* Remove redundant code in fail_match_choice test
* Add comment for has_value_category()
* Apply suggestions from code review
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
* clang-format changes
* Update comments for new BindingPattern methods
* Implement nested vars in patterns
* Apply suggestions from @geoffromer's code review
Co-authored-by: Geoff Romer <gromer@google.com>
* Implement changes from code review.
* Remove maybe_var_pattern grammar rule
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
* Fixed a couple simple crashes surfaced by running a structured fuzzer on executable_semantics parse/type-check/execute logic.
* var a: b: auto; -> var a: auto;
In the process, switch to an unambiguous grammar, using the
precedence-climbing method for operator precedence (suitably modified to
handle a partial precedence order) rather than Bison %precedence /
%prec.
Line 91 has:
```
source_loc_(type_expression->source_loc()) {}
```
Which requires the Expression definition. This probably compiles accidentally due to #include ordering, but I ran into a case that needs correct #includes.
This switches to generating per-file targets such as `//executable_semantics/testdata:tuple/equality_false.carbon.test`, instead of one test covering all files. Essentially this relies on bazel instead of lit to handle test parallelization.
* adding methods to the ast
* pre commit stuff?
* implementation of class functions
* implemented methods
* some cleanup
* more cleanup
* add newlines in test programs
* pre-commit fixups
* added include of return_term.h
* a test of a method calling another method
* replacing Member with Declaration
* removing the member.h etc files
* clarify a type annotation
* update uses of FunctionDeclaration
* remove ReturnTarget, no longer needed
* more cleanup
* more cleanup
* yet more cleanup, playing with pre-commit
* did a pre-commit run --all-files
* fixed const issue
* remove comment
* checking dependencies in BUILD files and headers
* pre-commit working now
* refactor NominalClassType to just hold a pointer to the class declaration
* remove Member from rtti
* responding to Geoffreys review
* change field_types to a non-member function
* Naive pointer implementation
* Bug fixes and better pointer tests
* Remove debug print statement
* Implement changes suggested by @geoffromer
Also add a failing test case that tests applying the address-of operator
to an rvalue.
I think lit_test accrued a bit of cruft as I switched approaches... I still may go further, but this is particularly fixing a bug where `FileCheck` (instead of `%{FileCheck}`) should've failed in tests.
* Initial implementation of block string literals following lexical_conventions/string_literals.md.
Enabled yyinput() in flex to implement parsing.
Added ParseBlockStringLiteral() helper to handler further transformations such as indenting.
Modified formar_grammar to support single-quoted strings to prevent a failure on lexer.lpp.
* Fixed _find_string_end quote parameter type int -> str.
* Update executable_semantics/syntax/BUILD
Co-authored-by: Geoff Romer <gromer@google.com>
* Addressed code review comments - split table-drived test into individual tests, renamed constants to match style guide.
* Addressed code review comments -- using EXPECT_THAT_EXPECTED() in tests, lexer comments and code cleanup.
Co-authored-by: Geoff Romer <gromer@google.com>
This enables us to stop using `Env` in the typechecker. As a byproduct, this commit also restructures the interpreter to handle run-time global initialization as part of ordinary execution, using the Action stack.
This required changing BindingPattern::name() to return `"_"` instead of nullopt when representing a `"_"` binding.
Semi-related drive-by fixes:
- Update BindingPlaceholderValue to expose a NamedEntity instead of a string name, and stop exposing its type.
- Drop the unused SourceLocation parameter of ValueEqual
As a byproduct, replace NamedEntity with a type-erasing wrapper NamedEntityView, eliminate virtual inheritance from the AST, and eliminate interfaces from gen_rtti.
Also explicitly model the types of expressions whose values are class or choice types, and make those be the static_type of the type declaration. This ensures that the static_type of a NamedEntity consistently corresponds to the static type of an IdentifierExpression using that name.
This doesn't actually use the results of name resolution, but it does verify that they are present.
Also ensures that name resolution and type checking are applied to deduced function parameters and the implicit call to `Main()`.
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
- Rename `PointerValue` to `LValue` to reflect how it's actually used. We can introduce a `PointerValue` type when we add support for actual pointer values.
- Remove support for pattern assignment. It's unclear if Carbon will support this, and even if we do, it raises questions that should first be addressed in a language proposal, like "is the left-hand side of `(x, y) = (1, 2)` an lvalue, or a pattern, or both, or something else entirely?"
This enables us to stop treating the return type as a Pattern (which is really isn't), treat return types more consistently with other static types in the typechecker, and drop ReturnTypeContext.
Additional changes:
- Merge TypeCheckFunDef with TypeOfFunDef.
- Handle implicit conversions in `return` statements.
- Require function type literals to have an explicit `->`.
- Move consistency check for omitted returns from TypeChecker to ResolveControlFlow.