Files
carbon-lang/executable_semantics/interpreter/interpreter.h
T
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

62 lines
1.6 KiB
C++

// 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
#ifndef EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_
#define EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_
#include <list>
#include <utility>
#include <vector>
#include "executable_semantics/ast/declaration.h"
#include "executable_semantics/interpreter/action.h"
#include "executable_semantics/interpreter/dictionary.h"
#include "executable_semantics/interpreter/stack.h"
#include "executable_semantics/interpreter/value.h"
namespace Carbon {
using Env = Dictionary<std::string, Address>;
/***** Scopes *****/
struct Scope {
Scope(Env e, std::list<std::string> l) : env(e), locals(std::move(l)) {}
Env env;
std::list<std::string> locals;
};
/***** Frames and State *****/
struct Frame {
std::string name;
Stack<Scope*> scopes;
Stack<Action*> todo;
Frame(std::string n, Stack<Scope*> s, Stack<Action*> c)
: name(std::move(std::move(n))), scopes(s), todo(c) {}
};
struct State {
Stack<Frame*> stack;
std::vector<const Value*> heap;
std::vector<bool> alive;
};
extern State* state;
void PrintEnv(Env env);
auto AllocateValue(const Value* v) -> Address;
auto CopyVal(const Value* val, int line_num) -> const Value*;
auto ToInteger(const Value* v) -> int;
/***** Interpreters *****/
auto InterpProgram(std::list<Declaration>* fs) -> int;
auto InterpExp(Env env, Expression* e) -> const Value*;
} // namespace Carbon
#endif // EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_