Commit Graph
67 Commits
Author SHA1 Message Date
Jon Meow d7b2c9b580 Remove uses of rules_cc (#776)
Per https://github.com/bazelbuild/rules_cc this still isn't necessary. There's no build-time enforcement, so usage is inconsistent/incorrect. Rather than letting this linger, remove it pending Bazel tooling enforcing it.
2021-08-24 08:55:17 -07:00
Jon MeowandGeoff Romer 0619b4ce6a Provide a BisonWrap for default construction (#761)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-19 12:31:25 -07:00
Jon Meow 367f9e4e94 Rename struct to class per #651 (#765) 2021-08-19 12:15:20 -07:00
Jon Meow 925c60b669 Change Declaration passing to use Ptr (#758) 2021-08-19 11:33:32 -07:00
Jon MeowandGeoff Romer c6ebe0db67 Add Ptr and RawNew for migration (#751)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-17 13:37:29 -07:00
Jon Meow 1eeaa208f2 Move paren_contents under ast and restrict syntax BUILD visibility (#756)
Trying to straighten out the BUILD graph; the dependency of ast pieces on paren_contents makes me think this is the right direction.
2021-08-17 12:52:53 -07:00
Jon Meow 9a9ccd8b7d Exclude tab in string literals (#734)
Noticed this while working on #732, seemed easiest to split changes though.
2021-08-12 09:53:04 -07:00
Jon Meow d3c7ca3131 Remove FunctionDefinition's default constructor (#735)
This opens up a path for switching `int line_num` to a `Location loc`, which I want to do for tracking filenames of code. But I don't think we should have a default constructor on `Location` to avoid mistakes, and switching FunctionDefinition to an arena alloc seems more consistent anyways.
2021-08-12 09:52:32 -07:00
Jon MeowandGeoff Romer 250ce4ab00 Add string parsing and a print builtin (#721)
It was in my mind to add String in order to support libraries in `package`.  `print` is added in order to have a String go to stdout. I've tried to do `print` in a way that won't be too hard to add other printable types, but it's probably also somewhat optional here -- that is, if desired, I could remove it. But it was a lot easier to doublecheck `\n` behavior with it, and I suspect it'll be helpful in other tests if it supports more value types.

On the side, this also fixes dereferencing in Pattern/Expression Print() calls, which I was noticing printing pointers instead of values. This may be another argument for moving away from passing pointers, since this seems to be a difficult-to-catch error.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-11 13:14:05 -07:00
Jon Meow d5564280ab Switch Statement to use inheritance+cast (#718) 2021-08-10 13:10:05 -07:00
Jon MeowandGeoff Romer dbcd6ad20d Switch Expression to use inheritance+cast (#712)
Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-06 15:43:25 -07:00
Jon Meow 4e0307efbc Switch Member to use inheritance+cast (#713) 2021-08-06 15:27:31 -07:00
Jon Meow 6164cdfd6d Verify that provision/omission of return types matches (#717)
This is finishing #678
2021-08-06 15:18:39 -07:00
Jon Meow c1148caf7d Switch Declaration to use inheritance+cast (#714) 2021-08-06 14:57:44 -07:00
Jon Meow 2e9e4f4cb3 Migrate remaining exits to FATAL_*_ERROR calls (#704)
Adds FATAL for things that are most likely programming errors in executable_semantics.
2021-08-06 13:06:25 -07:00
Jon MeowandGeoff Romer 2620ba066d Move Int parsing to i32 for #543 (#700)
Note this doesn't support other sizes or types, it just errors on them.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-08-05 09:34:12 -07:00
Geoff Romer de91afcf25 Rename ::yy::parser to ::Carbon::Parser. (#697)
Not only is this more consistent with our style rules, it lets us omit a lot of noisy qualifiers in parser.ypp
2021-08-03 12:09:42 -07:00
Jon Meow 6ae9cc3cf8 Add support for return; (#678)
This creates a ReturnExpression. A separate change should enforce that an implicit return of `()` is only allowed in functions that have an implicit return type of `()`, and I think the structure taken here should ease that.
2021-08-02 16:30:08 -07:00
Jon Meow 9829f188b7 Move all new's to global_arena, and remove ASAN disabling (#690)
Note this changes identifiers from char* to string to avoid malloc.

Fixes #580
2021-08-02 11:08:22 -07:00
Geoff RomerandJon Meow 6ac3adfa53 Factor out a Pattern sum type from Expression (#685)
`Pattern` is intended to pilot some changes I would like to apply to all our sum types:
- The alternatives are expressed as derived classes rather than members of a `std::variant`.
- The alternatives are classes in the [style guide sense](https://google.github.io/styleguide/cppguide.html#Structs_vs._Classes), meaning they can have invariants, but can't have public data members.
- Creating an object is expressed using a constructor rather than a factory function.
- Accessing an alternative is expressed as a cast (using LLVM's RTTI system) rather than `std::get` or a `Get` method.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-07-30 12:24:12 -07:00
Jon Meow a930717202 Require braces on control flow statements (#683)
This implements #623
2021-07-28 10:55:14 -07:00
Jon MeowandChandler Carruth f0af3cb795 Switch from llvm::errs()+exit() to FATAL_USER_ERROR() stream-based handling. (#670)
This is intended to:

- Standardize use of line_num (and highlight where no line_num is available).
- Standardize indications of runtime/compilation errors.
- Make it incrementally easier to write new errors.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-07-28 10:47:33 -07:00
Jeremy G. SiekandJon Meow 864b3bde02 Generic functions, first baby step (#658)
* generic functions: progress on parser and AST

* finished first baby step

* revisions based on reviews

* Update executable_semantics/interpreter/interpreter.cpp

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>

* Symbol => VariableType

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-07-22 15:16:56 -04:00
Jon Meow 034f3600e3 Add a FatalUserError macro to help print user-caused errors. (#668) 2021-07-21 12:38:56 -07:00
Jon Meow f3cbfc04c6 Move tracing_flag into a common directory (#669)
Intended to combine well with #668, so neither is alone.
2021-07-21 09:57:54 -07:00
Jon Meow 8fccecadeb Refactor output to be more streaming-focused. (#666)
- Switch code to llvm::raw_ostream as part of standardizing output forms.
    - Preferring llvm::raw_ostream over std::ostream because other tooling code should be expected to rely on llvm more closely, and an overall preference towards library consistency.
    - There are a couple spots in syntax/ that still use std streams, but I'd prefer to take a separate PR to see how best to address those.
    - std::boolalpha doesn't work with llvm, so I've implemented equivalent in a couple places (not enough that it felt like worth making a helper function).
- Implement Print(ostream) as consistently as we can, as an instance member.
    - This facilitates the use of the common/ostream.h template to provide operators.
    - Preferring this approach so that Print is easily accessible via gdb, per suggestion on #executable-semantics.
- Switch code currently calling `type->Print(ostream)` to instead do `ostream << *type`.
- Remove the unused `PrintTypeEnv`, nothing used it and the declaration didn't match the definition.
2021-07-20 13:16:48 -07:00
Jon Meow 368fc0063c Handle invalid chars better, and do small cleanups around error output. (#657)
This adds a test for invalid characters (that would've failed before, because the printed char isn't escaped). Not sure if there's a good way to test the PrintDiagnostic code, as it appears to occur on bison parser errors, which I'm just not sure how to trigger.
2021-07-20 12:04:45 -07:00
Geoff RomerandJon Meow d5124256a2 Split interpreter into smaller modules (#662)
- Move Heap and Frame/Scope to their own headers.
- Move some functions to more appropriate headers (e.g. CopyValue -> value.h).
- Define a separate Bazel rule for each header/cpp pair.
- Modify PrintValue to not print the frames of a ContinuationValue. This was necessary to break a dependency cycle between PrintValue, PrintFrame, and Action::Print.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-07-19 13:51:35 -07:00
Geoff RomerandJon Meow def98d1182 Add support for _ placeholder. (#661)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-07-19 10:33:06 -07:00
Jon Meow acb33932cb Migrate Declaration to variant (#644)
Note this makes some structural choices that I'm not sure how popular they'll be... Most notably, I could remove `DeclarationKind` because I'm using `std::visit` and `Declaration::Visitor` in reality. I could go to `switch(tag())` instead, but I'm wondering if this approach will be well received for the separation of ownership. Alternatively, I could move `Declaration` around so that it actually implements the things like `TopLevel` -- I did feel weird with the old structure of typecheck.cpp implementing members of declaration.h, though.
2021-07-15 16:22:56 -07:00
Jon Meow ada2be2d16 Switch Member to variant in anticipation of more kinds. (#656)
Note this overlaps a little with #644's Member changes, but not too badly.
2021-07-15 15:23:52 -07:00
Jon Meow ef785bb6e3 Refactor FunctionDefinition towards instance methods (#654)
It felt weird to have a `Make` method in this case.
2021-07-15 14:55:44 -07:00
Jon Meow 0960c51d20 Switch Statement to std::variant (#639)
Aligns Assign/Assignment, If/IfStatement naming to favor the name in the enum.
2021-07-13 13:54:38 -07:00
Geoff Romer b3d4c56ef2 Rename "PatternVariable" names for clarity (#630)
Pretty much any names will be awkward, since these types represent cases where an `Expression` is not an expression, and a `Value` is not a value, but we can at least be more explicit about the fact that they represent bindings rather than variable usages.
2021-07-09 10:11:01 -07:00
Geoff Romer a80ce2c566 Consistent naming for Expression and Value. (#621)
- `Kind` enumerator names always match the corresponding factory function, accessor, and type names (if any).
- All abbreviations in those names are expanded.
- Those names always have a suffix to disambiguate expressions from values.

`VarTV` is excluded from these changes because there's a pending PR to remove it.
2021-07-07 11:32:33 -07:00
Geoff Romer 7218e8a69e Eliminate MakeUnOp and MakeBinOp (#622)
This ensures that the factory functions correspond 1:1 with expression kinds, and MakeOp covers their use cases with minimal syntactic overhead now that it can take initializer list arguments.
2021-07-07 10:49:02 -07:00
Geoff Romer 047dfd692e Revert to handling Expression by const pointer (#616)
This reverts the bulk of #606, #607, and #611, as well as parts of #588, #605, and #614.
2021-07-01 12:33:16 -07:00
Geoff Romer fa5b9cd553 Migrate declaration parsing to value semantics (#614)
* Use Expression by value in FunctionDefinition
* Migrate choice declarations to value semantics
* Migrate Declaration parsing to value semantics
2021-06-30 13:09:12 -07:00
Geoff Romer 7e70a0335e Pass Expressions by value in Statement factories. (#611) 2021-06-30 11:10:36 -07:00
Geoff Romer 19e4bc55ce Migrate remaining Expression alternatives to IndirectValue (#607) 2021-06-28 17:03:14 -07:00
Geoff Romer 056da4dd5c Migrate PrimitiveOperator to value semantics (#606)
* Make PrimitiveOperator.arguments a value.
* Make operator factory functions take Expressions by value.
2021-06-28 15:58:32 -07:00
Geoff Romer 276880ae83 Migrate Tuple and FieldInitializer to value semantics (#605)
* Store tuple elements by value.
* Update FieldInitializer to use IndirectValue.
2021-06-28 15:57:54 -07:00
Geoff Romer 1916258e9b Refactor Expression to use std::variant instead of a union (#586) 2021-06-22 12:19:49 -07:00
Richard SmithandGeoff Romer 89e21113c3 Add 3 '*' operators: one prefix, one infix, and one postfix, per #523. (#582)
The presence or absence of whitespace is used to determine which
operator is in use, following the rules described in #520.

Support for prefix * dereference operator follows #523.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-06-21 17:09:34 -07:00
Geoff Romer 31f37f54fe Fix golden tests to use the "target" Bazel configuration (#581)
In practice, this means that `executable_semantics` will be built and run using the configuration specified on the command line, rather than e.g. always using `-c opt`.

Also fix a bug exposed by this change.
2021-06-16 16:33:19 -07:00
Richard Smith 567b9bb5a4 Reverse 'type: identifier' to 'identifier: type' in executable
semantics.
2021-06-02 11:33:50 -07:00
Richard Smith da403db9ff Revert "Remove : from vars in exec semantics (#504)"
This reverts commit 05663633d3.
2021-06-02 11:33:50 -07:00
Jon MeowandGeoff Romer 05663633d3 Remove : from vars in exec semantics (#504)
Going through tests, funptr1.6c is the main spot I see a real change, I added parens to get around an issue parsing fnty.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-05-06 14:21:31 -07:00
Jeremy G. Siek 8924f5620b Private unions (#492)
* changed union of Statement to be private

* changed the union in Expression to be private

* changed union in Value to be private

* changed AST constructors to be static methods

* updates to syntax unit tests
2021-04-27 14:29:13 -04:00
Geoff Romer 1933cfeeeb Stop using std::pair in the implementation of tuples (#479) 2021-04-26 11:43:06 -07:00