mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-24 17:52:41 +00:00
Add support for compound assignment and increment (#2526)
Add support for user-defined assignment, as well as compound assignment and increment, following the design direction in pending proposal #2511. Some of this isn't fully testable yet: because explorer doesn't properly support `impl` specialization, the blanket `impl`s in the prelude prevent types from customizing assignment.
This commit is contained in:
1 parent
f1a0645551
commit
2fd7e2b65d
32 files changed
+975
-215
No files matched your search
@@ -1937,6 +1937,13 @@ auto Interpreter::StepStmt() -> ErrorOr<Success> {
|
||||
}
|
||||
case StatementKind::Assign: {
|
||||
const auto& assign = cast<Assign>(stmt);
|
||||
if (auto rewrite = assign.rewritten_form()) {
|
||||
if (act.pos() == 0) {
|
||||
return todo_.Spawn(std::make_unique<ExpressionAction>(*rewrite));
|
||||
} else {
|
||||
return todo_.FinishAction();
|
||||
}
|
||||
}
|
||||
if (act.pos() == 0) {
|
||||
// { {(lv = e) :: C, E, F} :: S, H}
|
||||
// -> { {lv :: ([] = e) :: C, E, F} :: S, H}
|
||||
@@ -1958,6 +1965,15 @@ auto Interpreter::StepStmt() -> ErrorOr<Success> {
|
||||
return todo_.FinishAction();
|
||||
}
|
||||
}
|
||||
case StatementKind::IncrementDecrement: {
|
||||
const auto& inc_dec = cast<IncrementDecrement>(stmt);
|
||||
if (act.pos() == 0) {
|
||||
return todo_.Spawn(
|
||||
std::make_unique<ExpressionAction>(*inc_dec.rewritten_form()));
|
||||
} else {
|
||||
return todo_.FinishAction();
|
||||
}
|
||||
}
|
||||
case StatementKind::If:
|
||||
if (act.pos() == 0) {
|
||||
// { {(if (e) then_stmt else else_stmt) :: C, E, F} :: S, H}
|
||||
|
||||
Reference in new issue
Block a user