mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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>
This commit is contained in:
committed by
GitHub
co-authored by
Dave Abrahams
Geoff Romer
parent
6df0d51516
commit
3fa72d2984
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "executable_semantics/ast/statement.h"
|
||||
#include "executable_semantics/interpreter/stack.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
@@ -38,69 +39,94 @@ enum class ValKind {
|
||||
TupleTV,
|
||||
StructTV,
|
||||
ChoiceTV,
|
||||
ContinuationTV, // The type of a continuation.
|
||||
VarPatV,
|
||||
AltConsV
|
||||
AltConsV,
|
||||
ContinuationV // A first-class continuation value.
|
||||
};
|
||||
|
||||
struct Frame; // used by continuation
|
||||
|
||||
struct Value {
|
||||
ValKind tag;
|
||||
union {
|
||||
int integer;
|
||||
bool boolean;
|
||||
|
||||
struct {
|
||||
std::string* name;
|
||||
const Value* param;
|
||||
Statement* body;
|
||||
} fun;
|
||||
|
||||
struct {
|
||||
const Value* type;
|
||||
const Value* inits;
|
||||
} struct_val;
|
||||
|
||||
struct {
|
||||
std::string* alt_name;
|
||||
std::string* choice_name;
|
||||
} alt_cons;
|
||||
|
||||
struct {
|
||||
std::string* alt_name;
|
||||
std::string* choice_name;
|
||||
Address argument;
|
||||
} alt;
|
||||
|
||||
struct {
|
||||
std::vector<std::pair<std::string, Address>>* elts;
|
||||
} tuple;
|
||||
|
||||
Address ptr;
|
||||
std::string* var_type;
|
||||
|
||||
struct {
|
||||
std::string* name;
|
||||
const Value* type;
|
||||
} var_pat;
|
||||
|
||||
struct {
|
||||
const Value* param;
|
||||
const Value* ret;
|
||||
} fun_type;
|
||||
|
||||
struct {
|
||||
const Value* type;
|
||||
} ptr_type;
|
||||
|
||||
struct {
|
||||
std::string* name;
|
||||
VarValues* fields;
|
||||
VarValues* methods;
|
||||
} struct_type;
|
||||
|
||||
struct {
|
||||
std::string* name;
|
||||
VarValues* fields;
|
||||
} tuple_type;
|
||||
|
||||
struct {
|
||||
std::string* name;
|
||||
VarValues* alternatives;
|
||||
} choice_type;
|
||||
|
||||
struct {
|
||||
std::list<std::string*>* params;
|
||||
const Value* type;
|
||||
} implicit;
|
||||
|
||||
struct {
|
||||
std::vector<Frame*>* stack;
|
||||
} continuation;
|
||||
|
||||
} u;
|
||||
};
|
||||
|
||||
// Return a first-class continuation represented by the
|
||||
// given stack, down to the nearest enclosing `__continuation`.
|
||||
auto MakeContinuation(std::vector<Frame*> stack) -> Value*;
|
||||
auto MakeIntVal(int i) -> const Value*;
|
||||
auto MakeBoolVal(bool b) -> const Value*;
|
||||
auto MakeFunVal(std::string name, const Value* param, Statement* body)
|
||||
@@ -117,6 +143,7 @@ auto MakeVarPatVal(std::string name, const Value* type) -> const Value*;
|
||||
|
||||
auto MakeVarTypeVal(std::string name) -> const Value*;
|
||||
auto MakeIntTypeVal() -> const Value*;
|
||||
auto MakeContinuationTypeVal() -> const Value*;
|
||||
auto MakeAutoTypeVal() -> const Value*;
|
||||
auto MakeBoolTypeVal() -> const Value*;
|
||||
auto MakeTypeTypeVal() -> const Value*;
|
||||
|
||||
Reference in New Issue
Block a user