Commit Graph
51 Commits
Author SHA1 Message Date
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
Jeremy G. SiekandGeoff Romer b60ef90d62 Merge HandleValue into the Step functions (#598)
* moved most of logic from HandleValue into the Step functions

* removed the HandleValue function

* added some comments

* responses to Geoffrey

* move increment of act->pos out of the step logic for value actions

* changed act->pos to start at 0 and not have any gaps

* Update executable_semantics/interpreter/action.h

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

* update comment based on Geoffrey's suggestion

Co-authored-by: Geoff Romer <gromer@google.com>
2021-06-29 09:44:40 -04: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
Jon Meow 6c259dd5de Switch from assert to a CHECK macro to run in all build modes. (#595) 2021-06-24 12:32:01 -07:00
Geoff Romer 6ca6822157 Implement IndirectValue (#588)
Also updates `FieldAccess` to use `IndirectValue`, as an example.
2021-06-24 11:26:28 -07:00
Geoff Romer 85cfb3b930 Use string values instead of string pointers in Expression. (#591) 2021-06-24 11:01:13 -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
Geoff Romer c903eb3133 Remove Void (#540)
Implements resolution of #443.
2021-06-01 12:48:04 -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 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
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 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
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
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
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
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
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 102ea3ccaf Value semantics for Declaration. (#313)
This change creates an unpleasant amount of boilerplate where `Declaration` is declared, in exchange for being able to—very pleasantly—treat it as a simple value that composes with other values everywhere it is used. Applying this technique broadly will pay off in code comprehensibility; once it has been done for all things being new'd, pointers disappear and references are only needed as an idiomatic approximation of inout. The unpleasant code grows only when new polymorphic operations are added, and then only a bit, and is an idiom whose details can readily be ignored once in place. The pleasant code pervades the codebase.

Too bad we don't have existential types in C++ ;-)
2021-02-28 11:29:38 -08: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
Dave Abrahams 2205fd52ce [executable semantics] class-ify Declaration (#307)
* [executable semantics] class-ify Declaration

NFC (no functional change).

Proof of concept that we can simplify code by replacing unions with safer, more
regular types.  Hand-rolled existentials (type-erasing CoW wrappers) are a follow-on
step that will further simplify usage.

Began adding `const` where possible, and replacing `std::string*` with
`std::string`.  Most `const`s can disappear as we replace reference semantics
with value semantics, but in the meantime it's an important step in the right
direction.
2021-02-27 13:32:03 -08:00
Dave Abrahams 29a59944fa Executable Semantics: 1st-class stacks (#296)
Replaces low-level uses of `Cons` with a first-class `Stack` data structure.  Also removes an unused algorithm.
Co-authored-by: Jeremy Siek <jsiek@indiana.edu>

Possible next step: use `std::stack` instead.
2021-02-26 09:46:32 -08:00
Jeremy G. SiekandJon Meow a93ec369cb adding comments and some newlines (#294)
* adding comments and some newlines

* Update executable_semantics/interpreter/typecheck.cpp

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

* Update executable_semantics/interpreter/typecheck.cpp

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

* Update executable_semantics/interpreter/typecheck.cpp

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

* Update executable_semantics/interpreter/typecheck.cpp

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

* Update executable_semantics/interpreter/typecheck.cpp

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

* changed comment style

* Update executable_semantics/interpreter/typecheck.cpp

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

* Update executable_semantics/interpreter/typecheck.cpp

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

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-02-25 17:57:00 -05:00