| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
- // Exceptions. See /LICENSE for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- #include <iostream>
- #include <iterator>
- #include <map>
- #include <optional>
- #include <utility>
- #include <vector>
- #include "executable_semantics/ast/expression.h"
- #include "executable_semantics/ast/function_definition.h"
- #include "executable_semantics/interpreter/interpreter.h"
- #include "executable_semantics/interpreter/stack.h"
- #include "executable_semantics/interpreter/typecheck.h"
- namespace Carbon {
- void PrintAct(Action* act, std::ostream& out) {
- switch (act->tag) {
- case ActionKind::DeleteTmpAction:
- std::cout << "delete_tmp(" << act->u.delete_tmp << ")";
- break;
- case ActionKind::ExpToLValAction:
- out << "exp=>lval";
- break;
- case ActionKind::LValAction:
- case ActionKind::ExpressionAction:
- PrintExp(act->u.exp);
- break;
- case ActionKind::StatementAction:
- PrintStatement(act->u.stmt, 1);
- break;
- case ActionKind::ValAction:
- PrintValue(act->u.val, out);
- break;
- }
- out << "<" << act->pos << ">";
- if (act->results.size() > 0) {
- out << "(";
- for (auto& result : act->results) {
- if (result) {
- PrintValue(result, out);
- }
- out << ",";
- }
- out << ")";
- }
- }
- void PrintActList(Stack<Action*> ls, std::ostream& out) {
- if (!ls.IsEmpty()) {
- PrintAct(ls.Pop(), out);
- if (!ls.IsEmpty()) {
- out << " :: ";
- PrintActList(ls, out);
- }
- }
- }
- auto MakeExpAct(const Expression* e) -> Action* {
- auto* act = new Action();
- act->tag = ActionKind::ExpressionAction;
- act->u.exp = e;
- act->pos = 0;
- return act;
- }
- auto MakeLvalAct(const Expression* e) -> Action* {
- auto* act = new Action();
- act->tag = ActionKind::LValAction;
- act->u.exp = e;
- act->pos = 0;
- return act;
- }
- auto MakeStmtAct(const Statement* s) -> Action* {
- auto* act = new Action();
- act->tag = ActionKind::StatementAction;
- act->u.stmt = s;
- act->pos = 0;
- return act;
- }
- auto MakeValAct(const Value* v) -> Action* {
- auto* act = new Action();
- act->tag = ActionKind::ValAction;
- act->u.val = v;
- act->pos = 0;
- return act;
- }
- auto MakeExpToLvalAct() -> Action* {
- auto* act = new Action();
- act->tag = ActionKind::ExpToLValAction;
- act->pos = 0;
- return act;
- }
- auto MakeDeleteAct(Address a) -> Action* {
- auto* act = new Action();
- act->tag = ActionKind::DeleteTmpAction;
- act->pos = 0;
- act->u.delete_tmp = a;
- return act;
- }
- } // namespace Carbon
|