Commit Graph
34 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 Meow 0ca914a17a Remove outdated bison comment (#695) 2021-08-02 18:26:27 -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
Jon MeowandGeoff Romer 165651c75c Add script to automate mass test updates (#674)
Trying to simplify the process of updating golden output, and ensuring that we aren't missing any tests. With this script, it should be roughly "Add the .carbon file, then run tests.py --update_all"

Co-authored-by: Geoff Romer <gromer@google.com>
2021-07-26 14:57:00 -07:00
Jeremy G. Siek a1c164f598 added a test for definition-side checking with expected failure (#673) 2021-07-23 11:42:07 -04:00
Jon Meow f35cda7a99 Move ASAN_OPTIONS to executable_semantics, local to the leak. (#672) 2021-07-23 08:37:59 -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 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 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 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 467b58abe9 Add --trace tests overlapping with normal tests. (#650)
Modifies golden_test to support this, and shuffles it a little to make the result easier to read.
2021-07-15 15:12:16 -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
Jon Meow b1d11bae7e Fix 6c -> carbon ext (#536)
Chandler reminded me of this, the `.carbon` extension is noted here:
https://github.com/carbon-language/carbon-lang/tree/trunk/docs/design/code_and_name_organization#overview
2021-05-17 08:15:07 -07:00
Jeremy G. Siek 56b47bcfa9 Type computation tests (#511)
* test of a little type computation

* another test and some bug fixes
2021-05-05 14:46:10 -04:00
Jeremy G. Siek 5946d9c033 Tuple restrictions (#486)
* implement tuple restrictions: (1) named fields after positional, (2) order matters

* after_named_member => seen_named_member
2021-04-22 17:51:43 -04:00
Jeremy G. SiekandGeoff Romer e89b8daad7 more tests of tuples, mixing positional and explicit field names (#480)
* more tests of tuples, especially mixing positional and explicit field names

* test of match with nested tuple

* Update executable_semantics/testdata/fun_named_params2.6c

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

Co-authored-by: Geoff Romer <gromer@google.com>
2021-04-21 17:23:16 -04:00
Jeremy G. SiekandGeoff Romer c1d651fc15 Fix equality for tuples (#446)
* fix tuple equality, added test cases

* added a comment to an old function

* Update executable_semantics/interpreter/value.cpp

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

* fix error in Geoffrey's edit

Co-authored-by: Geoff Romer <gromer@google.com>
2021-04-21 17:12:10 -04:00
Jeremy G. SiekandGeoff Romer 27fd9de5bf improved checking for liveness when reading and writing memory (#448)
* improved checking for liveness when reading and writing memory

* moving some functions to be methods of State

* finished moving functions into State

* Update executable_semantics/interpreter/interpreter.h

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

* moved some comments, other minor edits

Co-authored-by: Geoff Romer <gromer@google.com>
2021-04-21 14:10:42 -04:00
3fa72d2984 Experimental control-flow operator (#368)
* AST and syntax for delimited control

* stashing for later

* a little more progress

* progress on delimited continuations

* delimit, suspend, and resume implemented (draft)

* example that generates the natural numbers

* fixes

* tinkering

* changed demo to experimental

* comments and name changes

* describe delimited continuations in the README

* renamed Snapshot to Continuation, edits to comments

* Update executable_semantics/ast/statement.h

improve comment for MakeDelimitStmt

Co-authored-by: Dave Abrahams <dabrahams@google.com>

* Update executable_semantics/interpreter/interpreter.cpp

remove snake_case

Co-authored-by: Dave Abrahams <dabrahams@google.com>

* edits to comments, change name of variable

* updates to handle review edits

* trailing whitespace

* fixes to delimited continuations, added more tests, also fixed assignment to do a copy

* improvements from Geoffrey

* new test from Geoffrey, fix for empty blocks

* more suggestions from Geoffrey

* more tests for delimited continuations, renaming some of them

* renamed test files

* improve a comment

* sketch of creating continuation

* initial implementation of shift/reset style continuations

* more documentation

* fix some camel case

* implemented deep copy of continuations, added a test case for it

* fixed a bug and got the recursive test case working

* removed __delimit, polished up __continuation

* back to shallow copy for continuations

* suggestions from Geoffrey

* removed structured binding (for now)

* Update executable_semantics/ast/expression.cpp

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

* responses to Geoffrey

Co-authored-by: Dave Abrahams <dabrahams@google.com>
Co-authored-by: Geoff Romer <gromer@google.com>
2021-03-26 11:22:48 -04:00
Jeremy G. SiekandJon Meow 7c4fcd3fa5 turn off tracing by default, change golden (#381)
* turn off tracing by default, change golden

* Update executable_semantics/main.cpp

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

* Update executable_semantics/main.cpp

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

* merge with trunk, update goldens

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-03-16 09:03:10 -04:00
Jeremy G. Siek ced98ef021 Global variables (#378)
* global variables

* implemented type checking of global variable, added test case

* added a comment

* improvements based on Dave's suggestions

* improvements based on Jon's suggestions

* added test cases about global variable ordering
2021-03-15 16:06:27 -04:00
Dave Abrahams 45c487de70 executable semantics/syntax: move to a subpackage. 2021-03-04 18:45:54 -08:00
fd96e0e630 add command-line flag to enable/disable tracing output (#325)
* add command-line flag to enable/disable tracing output

* adding missing exit for pattern variable in wrong context and a test case for it (#324)

* Update executable_semantics/interpreter/interpreter.cpp

comment on separate line as code

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

* fix interpreter's handling of optional else of if statement (#323)

* Update pattern_variable_fail.golden due to error (#334)

* Use llvm's CommandLine for parsing (#332)

* GitHub testing action (#331)

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>

* add copyright

* Create a Dictionary abstraction over the raw Cons list. (#327)

* Create a Dictionary abstraction over the raw Cons list.

* renamed Cons and some methods of Dictionary, various other cleanup

* Update executable_semantics/tracing_flag.cpp

added namespace comment

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

* added a comment to cpp file

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
Co-authored-by: Dave Abrahams <dabrahams@google.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2021-03-03 16:01:59 -05:00
Jon Meow 30648724c9 Use llvm's CommandLine for parsing (#332) 2021-03-02 15:16:17 -08:00
Jeremy G. Siek 5457916abb fix interpreter's handling of optional else of if statement (#323) 2021-03-02 13:04:49 -05:00
Jeremy G. Siek b2c9203143 adding missing exit for pattern variable in wrong context and a test case for it (#324) 2021-03-02 12:51:03 -05:00
Dave Abrahams f5300a84e5 Revert "improve abstraction for AssocList, fix bug in optional else (#315)" (#320)
This reverts commit bf6bb800c4.
2021-03-01 12:26:56 -05:00
Geoff RomerandJeremy G. Siek 8b3bb7c5e9 Fix type errors in function calls (#308)
* Make `field_list` always a list.

* Create separate `paren_expression` and `tuple` nonterminals

* Rename expression_or_field_list.* to field_list.*

Co-authored-by: Jeremy G. Siek <jsiek@indiana.edu>
2021-03-01 10:13:53 -05:00
Jeremy G. Siek bf6bb800c4 improve abstraction for AssocList, fix bug in optional else (#315)
* improve abstraction for AssocList, fix bug in optional else

* add flag for tracing output, clean up code for output

* turned off tracing by default, updated goldens, removed two examples that use pointers, shouldn't have been there yet
2021-03-01 10:00:02 -05:00
Dave Abrahams 2afbfd6146 [executable semantics] silence known, and detect new, crashes (#312)
* Add assertion to detect UB in interpreter.cpp

This change, applied to 6e5070d ("Adapting jsiek's executable semantics tooling
for commit. (#237)"), causes the if2.6c test to segfault.  Becase the assertion
fires only when `stmt == nullptr` and no code has permission to change `stmt`
(it is `const`) before it is dereferenced in the `switch`, and nothiing in
`PrintStatement` is supposed to exit the program, the assertion is a valid
change that detects a bug.

The crash was originally manifest in 29a5994 ("Executable Semantics: 1st-class
stacks (#296)").

* Temporarily disable the if2 test pending #311

See https://github.com/carbon-language/carbon-lang/issues/311

* [executable semantics] Record exit code on expected error.

This will prevent a final segfault from sneaking by, detected as a passing test.
A more principled follow-up commit would bottleneck detected error exit
reporting and have it write something to std::cerr that can be recognized.
2021-02-27 18:52:22 -08:00
Chandler Carruth 39aea3c45d Add Bazel repositories for Flex and Bison. (#279)
This makes executable semantics build and pass tests for me without
installing either Bison or Flex. We just use the primitive toolchain
with the existing genrule as the packaged rules don't quite fit how
we're building and organizing the code.

Currently, this points at forks of the upstream rule repositories while
PRs I have sent there are going through, but this should be functional
for now and there doesn't seem to be any reason to wait for those PRs to
go through.
2021-02-25 19:03:38 -08:00
Jeremy G. Siek 3ea84c9276 adding optional else to executable semantics (#295)
* adding comments and some newlines

* added optonal else
2021-02-25 18:07:50 -05:00
Jon Meow 6e5070de18 Adapting jsiek's executable semantics tooling for commit. (#237)
Notes versus what jsiek wrote:

- This adopts Bazel for building.
    - System-local versions of bison/flex are used. I found https://github.com/jmillikin/rules_bison, but those print a lot of warnings (things like -Wsign-compare IIRC) which makes builds hard to read. Plus I think the underlying bison_cc_library rule didn't work, so this would really only get a hermetic bison/flex build (helpful, but didn't seem worth more time).
    - I'm adding in a .bazeliskrc to push a somewhat more standard choice of bazel versions. I noticed I was getting unstable versions by default, possible Google-specific, but seemed good to include.
    - The `-lpthread` kludge.
- Turn all of the examples into golden tests.
    - Including adding a golden test rule.
- Fixed various style guide issues. For example:
    - Fixing function names to be CamelCase instead of snake_case (https://google.github.io/styleguide/cppguide.html#Function_Names)
    - Removed exception use (https://google.github.io/styleguide/cppguide.html#Exceptions)
    - File name fixes (https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/cpp_style_guide.md#file-names)
- Dropped `using` of `std` names -- I believe this is preferred (maybe we should be explicit about this in the Carbon style guide)
- Switched `enum` uses to `enum class` for ease-of-identification.
- Spent some time breaking out files to hopefully be easier to read/edit pieces, and understand relations between structs.
- Added `code requires` to `syntax.ypp` to address include issues

Possibly other things -- but the fundamental structure is, I believe, unchanged. I put in the golden tests pretty early to ensure I wasn't mutating output/results.
2021-02-19 15:25:43 -08:00