Commit Graph
61 Commits
Author SHA1 Message Date
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
Geoff Romer c903eb3133 Remove Void (#540)
Implements resolution of #443.
2021-06-01 12:48:04 -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
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 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 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
Geoff Romer e022ff106f Factor Heap class out of State (#491)
Additional miscellaneous cleanup:

- Use the term "deallocate" instead of "kill" in function names, for symmetry with "allocate".
- Drop an unnecessary memory allocation in `AllocateValue`.
- Implement `PrintHeap` in terms of `PrintAddress`, so that dead values are flagged with `!!`.
2021-04-23 13:25:51 -07: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. Siek 928b92a428 a raw access to the heap field slipped through somehow, fixing that (#483) 2021-04-21 19:11:13 -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
Jeremy G. Siek 34f1a03f7b change all expression and statement pointers to be const (#449)
* change all expression and statement pointers to be const

* const in paren tests
2021-04-19 21:47:19 -04:00
Geoff Romer cf7c97bf28 Unify tuple types with tuples-of-types in the interpreter (#442) 2021-04-12 16:13:00 -07:00
Geoff Romer 22656c8e09 Remove unused code from ValueEqual, and make unsupported cases explicit. (#434) 2021-04-09 15:09:37 -07:00
Chandler Carruth 7a00f6e15b Add ASan config and enable it in fastbuild. (#437)
Adds all the necessary machinery to our toolchain and Bazel
configuration to support ASan. This includes ensuring sufficient debug
information is available for backtraces, etc.

As part of ASan, it enables UBSan to catch more basic undefined behavior
in C++. It also enables more complete checking in ASan for lifetime
bugs.

These configs can be enabled in any build mode with `--config=asan`.
They are also enabled by default in `-c fastbuild` where asserts are
also enabled. The goal is to have a single build mode that catches the
overwhelming majority of correctness issues.

Leak checking is part of ASan and finds leaks in `executable_semantics`
code that probably aren't interesting to fix right now. I've disabled
leak checking in the `BUILD` file for the test that showed this --
everything else passed. If more things need this disabled, the same
`BUILD` change should be easily replicated.

If you see unsymbolized backtraces, you may need to either put
`llvm-symbolizer` on your path, or point the `ASAN_SYMBOLIZER_PATH`
environment variable at it. For example, in the project root you could
do something like the following to use the downloaded toolchain's
symbolizer:
```bash export
ASAN_SYMBOLIZER_PATH=$PWD/bazel-clang-toolchain/bin/llvm-symbolizer
```
I'll try to update documentation soon with this as well.
2021-04-08 12:42:13 -07:00
Geoff Romer e324935139 Miscellaneous parser cleanup (#429)
- Give unary `-` and `not` the same precedence as in C++
- Add detail to parse error messages, and make the --trace flag also enable parser debug tracing
- Make any new shift-reduce conflicts into build errors
- Use `%precedence` rather than `%nonassoc` where possible, in order to catch more grammar bugs at build time
2021-04-06 10:09:03 -07:00
Geoff Romer 80f035874d Restructure handling of paren expressions (#417)
* Move nontrivial logic out of `parser.ypp` into `FieldList`, rename it to `ParenContents`, make it a class, and add tests
* Use a `FieldInitializer` struct instead of `std::pair<std::string, Expression*>` to represent the fields of a tuple
2021-04-05 10:49:25 -07:00
Geoff RomerandDave Abrahams 98a6477233 Change Doxygen-style /// comments to // (see https://google.github.io/styleguide/cppguide.html#Comment_Style) (#330)
Co-authored-by: Dave Abrahams <dabrahams@google.com>
2021-04-05 10:11:48 -07:00
Jeremy G. Siek 3d02412f2f rename env and ct_env (#419)
* change env to types, ct_env to values in type checker, change env to values in interpreter

* fix bazeliskrc, change to use latest (#420)
2021-03-30 13:41:24 -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
Dave Abrahams dd4e37e761 const-ify Value*s in preparation for value semantic transformation (#409)
Making Values const allows us to separate the actual mutations (search for "*&" in this change) from places where the Value is effectively passed by-value.
2021-03-21 09:00:00 -07:00
Jeremy G. SiekandDave Abrahams 1da97fc9cf Separate alive flag from the Value class (#408)
* separate the alive flag from the Value class

* restored KillValue, added KillAddress

* added comments

* Update executable_semantics/interpreter/interpreter.cpp

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

* Update executable_semantics/interpreter/interpreter.cpp

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

* Update executable_semantics/interpreter/interpreter.cpp

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

* finish edits from Dave

Co-authored-by: Dave Abrahams <dabrahams@google.com>
2021-03-20 16:14:31 -04:00
Jeremy G. Siek b2455d8dba renames ExecutionEnvironment, fixes #394 (#395) 2021-03-18 22:19:31 -04:00
Dave Abrahams 7e1721dc01 lowerCamelCase => snake_case (#396) 2021-03-17 13:09:58 -07:00
Dave Abrahams 71a8d072b4 Remove unused bazel rule (#376) 2021-03-17 10:51:16 -07:00
Dave Abrahams c4252d1c6d Remove obsolete TODO (#375) 2021-03-17 10:27:33 -07:00
Dave Abrahams 5ca6e21e11 Remove an unused function (#380) 2021-03-17 09:58:34 -07: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 120e0145ce [executable semantics] Use type-safe variant in C++ parser (#364)
We're now one step away from eliminating bare pointers in semantic actions.

There are plenty of other cleanups and modernizations that can be made in the
parser, but the elimination of bare pointers is the one that has the highest
impact for the codebase.
2021-03-09 21:17:06 -08:00
Dave Abrahams 436a9dda79 [executable semantics] Minimal cxx parser (#363)
Makes a minimal transition to using C++ in the parser.
2021-03-09 20:46:52 -08:00
Dave AbrahamsandGeoff Romer 07a37933c6 [executable semantics] Add Syntax driver (#362)
Slowly bringing this into line with Bison's C++ example parser
so we can use strong semantic values for symbols rather than
leaking pointers.  First step is to thread a `ParseAndLexContext` 
object through the whole syntactic analysis state, like the 
example has.  In the example, it's called `driver`.

Co-authored-by: Geoff Romer <gromer@google.com>
2021-03-09 19:46:30 -08:00
05db2012ab replace uses of AssocList with Dictionary (#344)
Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Dave Abrahams <dabrahams@google.com>
2021-03-06 08:06:05 -08:00
Dave Abrahams 2f83c4be48 Separate parsing from type-checking and evaluation. (#345)
This change caused the syntax error in undef2.6c ("fun" instead of "fn") to be
detected as one would expect, thus the changed golden file.
2021-03-05 15:00:44 -08:00
Dave Abrahams 5884aa1a5c Give syntax files more useful and mnemonic names.
Distinguishes parts that come from the parser and lexer. It used to be that all
the files were called "syntax*", but lexing and parsing are distinct phases that
are easier to keep track of when distinguished.  syntax.yy.cpp being the source
file generated by flex, containing the lexer was particularly confusing, because
the yy tends to indicate it is a yacc/Bison product, and the ".tab." substring,
indicating "tables" is not really useful to the developer.

These names also match up with what Bison's C++ example uses, which will make
the transition easier.
2021-03-04 18:45:54 -08:00
Dave Abrahams 45c487de70 executable semantics/syntax: move to a subpackage. 2021-03-04 18:45:54 -08:00
Dave Abrahams 81dc56b312 [executable semantics] Trivial lexer cleanup (#341)
- turn off unneeded legacy flex parts.
- a couple of comments
2021-03-04 09:49:52 -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
Jeremy G. Siek cd18e24176 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
2021-03-03 13:03:23 -05:00
Jon Meow 30648724c9 Use llvm's CommandLine for parsing (#332) 2021-03-02 15:16:17 -08:00
Jon Meow d48b17adc7 Update pattern_variable_fail.golden due to error (#334) 2021-03-02 15:09:54 -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
Geoff Romer 9d0b48478f Fix compilation errors in choice1.6c (#322) 2021-03-01 15:50:50 -08:00
Jeremy G. Siek 675c1056bf update goldens to match fixes in PR #308 (#321) 2021-03-01 17:21:21 -05:00
Geoff Romer fe328b2a7b Add test coverage for a trailing comma in the alternatives list, and empty parentheses in an alternative declaration. (#305) 2021-03-01 10:34:50 -08: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