Commit Graph
278 Commits
Author SHA1 Message Date
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
Geoff Romer a9bb06ca14 Make NamedEntityInterface non-movable (#946) 2021-11-10 09:33:00 -08:00
Jon Meow e8d9b7675b Merge ClassDefinition and ClassDeclaration (#940) 2021-11-09 15:24:22 -08:00
Jon Meow 73eea8e47a Merge UnwindTo and UnwindPast logic (#926)
Also shifts the DeallocateScope concept into UnwindTodoTop since that's how it's used.
2021-11-08 09:22:38 -08:00
Chandler Carruth b990bab452 Fix main names that got past CI to fix tests. (#945)
#939 switch to `Main`, but #919 predated it and didn't get updated
before merging. Its tests passed on the PR branch as a consequence, but
failed when landed.

This just updates the test cases. Trivial fix forward.
2021-11-04 22:08:23 -07:00
Chandler Carruth 65ac59eb2a Add a script to compute minimal roots for check_deps. (#932)
This avoids needing to have nearly as many rules here which should
reduce its churn.

I've tested that this reaches the exact same set of transitive
dependencies.

Note, only the last commit here is new.
2021-11-03 12:53:54 -07:00
Jon Meow 2f15a64a6b Move a little logic into TypeChecker to narrow what's exposed. (#938) 2021-11-03 10:36:12 -07:00
Jon MeowandGeoff Romer 27e084d37a Start populating named entities in relevant locations. (#919)
This starts detecting naming collisions as a consequence of being able to determine when the name is declared twice in a given scope.



Co-authored-by: Geoff Romer <gromer@google.com>
2021-11-03 08:04:13 -07:00
Chandler Carruth 5f67029479 Use upstream GoogleTest and add related test utils. (#876)
This moves over to the vanilla upstream GoogleTest pulled in the more
expected manner with Bazel. It also adds Abseil and Google Benchmark
libraries in the same fashion (there are cross dependencies here).

As part of this, also introduce a dependency check test that can enforce
basic layering of dependencies. For example, this lets us ensure that
non-test Carbon code only depends on LLVM and Clang despite having other
libraries available. There remains some cleanup to improve the way these
dependency tests work, but this at least ensures we don't regress.

I've also provided workarounds to allow both Carbon code and LLVM code
to freely be used with GoogleTest (and other `std::ostream` based
output code). This is done by extending the code in
`//common/ostream.h`. One downside is that it requires opening the
`llvm` namespace and adding an ADL_found overload there. I think on
balance this is still a win and doesn't make me too nervous.

The new version of GoogleTest requires printing more often from matchers
and so I've also added several printing routines to types that
previously didn't require them. Otherwise, most of the updates are just
using the more conventional upstream style of including the headers and
adding `ostream.h` where it is needed.

I did consider moving code over to use `std::ostream` instead of LLVM's
`raw_ostream`, but the advantages of not doing virtual dispatch still
seem significant, and it also seems good to retain access to LLVM's
formatting utilities built around `raw_ostream` given that we can't pull
arbitrary dependencies into Carbon code outside of test code.

All of this was slightly motivated by requests for newer features in
GoogleTest, but much more-so by my desire to have access to Google
Benchmark and Abseil when writing benchmarks. For example, using
Abseil's random number generator seems extremely helpful when generating
inputs for benchmarks. The growing dependencies between these packages
further motivated me to just pull them all in and ensure they worked
well.
2021-11-02 20:14:12 -07:00
Jon Meow 6d822ababb Rename main to Main for Carbon style consistency (#939)
Main() is more consistency with Carbon's naming guidelines. C# offers some precedent: https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/main-command-line
2021-11-02 14:53:18 -07:00