mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:44:41 +01:00
Migrate PrimitiveOperator to value semantics (#606)
* Make PrimitiveOperator.arguments a value. * Make operator factory functions take Expressions by value.
This commit is contained in:
@@ -746,11 +746,11 @@ void StepExp() {
|
||||
frame->todo.Push(MakeValAct(Value::MakeBoolVal(exp->GetBoolean())));
|
||||
break;
|
||||
case ExpressionKind::PrimitiveOp:
|
||||
if (exp->GetPrimitiveOperator().arguments->size() > 0) {
|
||||
if (exp->GetPrimitiveOperator().arguments.size() > 0) {
|
||||
// { {op(e :: es) :: C, E, F} :: S, H}
|
||||
// -> { e :: op([] :: es) :: C, E, F} :: S, H}
|
||||
frame->todo.Push(
|
||||
MakeExpAct(exp->GetPrimitiveOperator().arguments->front()));
|
||||
MakeExpAct(&exp->GetPrimitiveOperator().arguments.front()));
|
||||
act->pos++;
|
||||
} else {
|
||||
// { {v :: op(]) :: C, E, F} :: S, H}
|
||||
@@ -1205,11 +1205,11 @@ void HandleValue() {
|
||||
}
|
||||
case ExpressionKind::PrimitiveOp: {
|
||||
if (act->pos !=
|
||||
static_cast<int>(exp->GetPrimitiveOperator().arguments->size())) {
|
||||
static_cast<int>(exp->GetPrimitiveOperator().arguments.size())) {
|
||||
// { {v :: op(vs,[],e,es) :: C, E, F} :: S, H}
|
||||
// -> { {e :: op(vs,v,[],es) :: C, E, F} :: S, H}
|
||||
const Expression* arg =
|
||||
(*exp->GetPrimitiveOperator().arguments)[act->pos];
|
||||
&exp->GetPrimitiveOperator().arguments[act->pos];
|
||||
frame->todo.Pop(1);
|
||||
frame->todo.Push(MakeExpAct(arg));
|
||||
} else {
|
||||
|
||||
@@ -85,7 +85,7 @@ auto ReifyType(const Value* t, int line_num) -> const Expression* {
|
||||
return Expression::MakeVar(0, *t->GetChoiceType().name);
|
||||
case ValKind::PointerTV:
|
||||
return Expression::MakeUnOp(
|
||||
0, Operator::Ptr, ReifyType(t->GetPointerType().type, line_num));
|
||||
0, Operator::Ptr, *ReifyType(t->GetPointerType().type, line_num));
|
||||
default:
|
||||
std::cerr << line_num << ": expected a type, not ";
|
||||
PrintValue(t, std::cerr);
|
||||
@@ -314,14 +314,14 @@ auto TypeCheckExp(const Expression* e, TypeEnv types, Env values,
|
||||
case ExpressionKind::Boolean:
|
||||
return TCResult(e, Value::MakeBoolTypeVal(), types);
|
||||
case ExpressionKind::PrimitiveOp: {
|
||||
auto es = new std::vector<const Expression*>();
|
||||
std::vector<Expression> es;
|
||||
std::vector<const Value*> ts;
|
||||
auto new_types = types;
|
||||
for (auto& argument : *e->GetPrimitiveOperator().arguments) {
|
||||
auto res = TypeCheckExp(argument, types, values, nullptr,
|
||||
for (const Expression& argument : e->GetPrimitiveOperator().arguments) {
|
||||
auto res = TypeCheckExp(&argument, types, values, nullptr,
|
||||
TCContext::ValueContext);
|
||||
new_types = res.types;
|
||||
es->push_back(res.exp);
|
||||
es.push_back(*res.exp);
|
||||
ts.push_back(res.type);
|
||||
}
|
||||
auto new_e =
|
||||
|
||||
Reference in New Issue
Block a user