Commit Graph
287 Commits
Author SHA1 Message Date
20b272446f Let variables (#1095)
* 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>
2022-03-11 16:30:24 -05:00
Geoff Romer 93842ad878 Eliminate run-time errors from PatternMatch (#1126) 2022-03-10 16:46:43 -08:00
pk19604014 2ea7de8a17 Fixed a couple crashes surfaced by running a structured fuzzer on executable_semantics parse/type-check/execute logic. (#1106)
* 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;
2022-03-04 14:45:50 -05:00
Richard Smith 2325c50b3b Support for if ... then ... else following #911. (#944) 2022-03-03 16:34:34 -08:00
Richard Smith 8c60ad2e19 Implement the current set of rules for precedence partial ordering (#1096)
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.
2022-03-03 13:36:35 -08:00
7cce1bd124 interfaces, impls, and constrained generics (basics) (#1073)
* interfaces, impls, and constrained generics (basics)

* separate type checking into declare vs. type check, removing redundancy

* external impls

* added impl scopes to handle generics calling generics

* cleanup

* more cleanup

* Update executable_semantics/testdata/interface/external_impl_point_vector.carbon

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* Update executable_semantics/testdata/interface/generic_call_generic.carbon

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* Update executable_semantics/testdata/interface/tuple_vector_add_scale.carbon

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* Update executable_semantics/testdata/interface/vector_point_add_scale.carbon

Co-authored-by: josh11b <josh11b@users.noreply.github.com>

* change ImplementationDeclaration to ImplDeclaration

* remove impl_type_value

* split NamedEntity into two

* changed GetName to be a free function

* adding comments

* more edits to respond to review

* introduce ImplBinding, remove punning on GenericBinding

* new test case and some minor edits

* refactor GetMember and GetField to move impl logic to interpreter

* remove commennt

* change EntityView to ImplBinding in FieldAccess...

* move ImplBinding

* review response

* added example to impl_scope.h

* minor edits

* Update executable_semantics/interpreter/field_path.h

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/interpreter/value.cpp

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/interpreter/interpreter.cpp

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/ast/expression.h

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/ast/expression.h

Co-authored-by: Geoff Romer <gromer@google.com>

* Update executable_semantics/ast/generic_binding.h

Co-authored-by: Geoff Romer <gromer@google.com>

* more edits from review

* review response

* Update executable_semantics/ast/static_scope.h

Co-authored-by: Geoff Romer <gromer@google.com>

* remove ImplType, renamed node_view to value_node

Co-authored-by: josh11b <josh11b@users.noreply.github.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2022-03-02 15:58:45 -05:00
Jon Meow 066bf10df3 Fix return_term dep on Expression (#1091)
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.
2022-02-18 16:35:39 -08:00
Geoff Romer 74c054c86e Document monotonic mutability of the AST (#1079)
Also document an important precondition on `InterpExp` and `InterpPattern`
2022-02-16 09:42:47 -08:00
Jon Meow 385ac7da86 Refactor lit testing to generate per-file tests. (#1063)
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.
2022-02-08 11:01:27 -08:00
Jeremy G. Siek ac0b810bf3 Adds basic support for class functions and methods. (#1057)
* 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
2022-02-05 12:30:13 -05:00
Darshal Shetty 4479c55305 Pointers (#1060)
* 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.
2022-02-05 10:27:54 -05:00
Geoff Romer 6c3e1f6d7c Revise README and add subdir READMEs (#1023) 2022-01-28 11:33:32 -08:00
Jon Meow 9009ae5e1b Cleanup up lit_test and require explicit tool paths (#1049)
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.
2022-01-27 16:27:30 -08:00
Jon Meow d76fe462f6 Have FileCheck dump all input on errors. (#1050)
I'm hoping this improves debugability.
2022-01-27 12:49:44 -08:00
Jon Meow eda43faa5a Note namespace and static recommendations in C++ style guide (#1041) 2022-01-27 11:26:47 -08:00
Jon Meow 7dcb7a3be8 Drop line because it's a set so arbitrary sorting applies (#1043) 2022-01-26 15:13:26 -08:00
Geoff RomerandJon Meow 1723b4e0b2 Hide Interpreter in .cpp (#1036)
This improves encapsulation, and makes Interpreter lifetimes clearer (and shorter).

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2022-01-26 09:57:55 -08:00
pk19604014andGeoff Romer 2017eb4da0 Initial implementation of block string literals following lexical_conventions/string_literals.md. (#1028)
* 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>
2022-01-21 13:11:18 -05:00
Geoff RomerandJon Meow c311c8849c Use static name resolution in Interpreter (#1022)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2022-01-21 09:48:11 -08:00
Jon Meow ffc2be92d6 Add carbon to a couple python imports for correctness (#1033) 2022-01-20 08:37:47 -08:00
Geoff Romer b954542d06 Reorganize and document Action (#1024) 2022-01-18 13:29:44 -08:00
Geoff Romer 461e178273 Store named constant values in the AST (#1011)
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.
2022-01-13 11:07:28 -08:00
Jon Meow d88f95ad31 Add missing syntax deps (#1014) 2022-01-10 14:25:16 -08:00
Jon MeowandGeoff Romer 1b4c81fa69 Add script for generating missing C++ deps (#1012)
Co-authored-by: Geoff Romer <gromer@google.com>
2022-01-07 14:44:40 -08:00
Jon Meow b7df523dc8 Fix cross-file links in non-proposal files (#1010) 2022-01-07 11:00:21 -08:00
Geoff Romer e533442028 Use /* instead of #if 0 for NamedEntity interface (#1006) 2022-01-06 10:00:10 -08:00
Geoff Romer 50263483d8 Add name accessor to NamedEntityView (#994)
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
2022-01-04 15:53:11 -08:00
Geoff Romer c89ce1d570 Handle identifier value category properly. (#986) 2021-12-15 13:27:36 -08:00
Geoff Romer daf8729a75 Use static names in typechecker. (#985) 2021-12-14 11:26:53 -08:00
Geoff Romer 8e6c209a28 Use resolved names in typechecker (#974)
As a byproduct, replace NamedEntity with a type-erasing wrapper NamedEntityView, eliminate virtual inheritance from the AST, and eliminate interfaces from gen_rtti.
2021-12-13 16:35:30 -08:00
Geoff Romer fd45b089e9 Add typechecking of type declarations (#984)
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.
2021-12-13 16:19:52 -08:00
Geoff Romer e65e85b15d Use AST nodes as generic arg deduction keys (#982) 2021-12-10 12:19:06 -08:00
Geoff Romer 021e83a4f4 Ensure all NamedEntities have static types (#968) 2021-12-07 12:27:47 -08:00
Jon Meow beea60d0b8 Switch prelude to a file and refactor lit testing to pass commands directly. (#966) 2021-12-03 14:23:13 -08:00
Geoff Romer f75b4d322f Handle use-before-declare in static name lookup (#967)
Also remove inheritance from NamedEntity for some classes that don't need it.
2021-12-03 13:52:31 -08:00
Jon Meow 3c76b0ab01 Test --trace directly (#933) 2021-12-02 13:54:35 -08:00
Jon Meow 92903afbd5 clang-tidy pass on executable_semantics (#963) 2021-12-02 12:21:18 -08:00
Geoff Romer 29bef42f7d Fix broken build (#961) 2021-11-30 16:04:17 -08:00
Geoff RomerandJon Meow 17e0a1afb9 Implement static name resolution (#958)
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>
2021-11-30 13:33:54 -08:00
Geoff RomerandJon Meow dc5e62fc7a Support parsing and testing unimplemented expressions (#957)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-11-30 12:29:15 -08:00
Geoff Romer be0c1e9da6 Move value-category checking to compile time (#960) 2021-11-29 17:07:50 -08:00
Geoff Romer 3e188c8562 Express prelude using Carbon syntax (#955)
This should be clearer, more maintainable, and more scalable than building the prelude AST by hand.
2021-11-29 13:56:55 -08:00
Geoff Romer b14c97d0d7 Clean up remaining uses of old spelling main (#959) 2021-11-24 14:32:39 -08:00
Geoff Romer 3f7e1cd3fb Clarify and simplify handling of lvalues (#956)
- 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?"
2021-11-23 14:13:08 -08:00
Geoff Romer 6ae85bd13a Initial batch of AST matchers. (#953)
Also fixes an issue where llvm casts wouldn't work on AstNode.
2021-11-23 12:34:55 -08:00
Geoff Romer ec2f8e64e2 Support parsing Carbon files from strings. (#954)
Also, pass file names as string_view for greater convenience.
2021-11-23 10:44:39 -08:00
Geoff Romer 9642d7ad05 Factor out ActionStack from Interpreter (#951) 2021-11-17 12:59:16 -08:00
Geoff Romer 7a5b8434c8 Define a base class for all AST nodes. (#947)
Also implement code-generation to manage the resulting boilerplate.
2021-11-16 11:54:47 -08:00
Geoff Romer d854fb93cb Factor out AST node for function return types. (#912)
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.
2021-11-12 11:30:31 -08:00
Geoff RomerandJon Meow a4aff26821 Stop allocating Actions on the Arena (#934)
This enables us to manage local variables in Carbon using C++ RAII.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-11-10 16:35:06 -08:00