mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 11:10:10 +01:00
`Pattern` is intended to pilot some changes I would like to apply to all our sum types: - The alternatives are expressed as derived classes rather than members of a `std::variant`. - The alternatives are classes in the [style guide sense](https://google.github.io/styleguide/cppguide.html#Structs_vs._Classes), meaning they can have invariants, but can't have public data members. - Creating an object is expressed using a constructor rather than a factory function. - Accessing an alternative is expressed as a cast (using LLVM's RTTI system) rather than `std::get` or a `Get` method. Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
45 lines
1.3 KiB
C++
45 lines
1.3 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 "common/ostream.h"
|
|
#include "executable_semantics/ast/declaration.h"
|
|
#include "executable_semantics/ast/expression.h"
|
|
#include "executable_semantics/ast/pattern.h"
|
|
#include "executable_semantics/interpreter/frame.h"
|
|
#include "executable_semantics/interpreter/heap.h"
|
|
#include "executable_semantics/interpreter/stack.h"
|
|
#include "executable_semantics/interpreter/value.h"
|
|
|
|
namespace Carbon {
|
|
|
|
using Env = Dictionary<std::string, Address>;
|
|
|
|
struct State {
|
|
Stack<Frame*> stack;
|
|
Heap heap;
|
|
};
|
|
|
|
extern State* state;
|
|
|
|
void InitEnv(const Declaration& d, Env* env);
|
|
void PrintStack(const Stack<Frame*>& ls, llvm::raw_ostream& out);
|
|
void PrintEnv(Env values);
|
|
|
|
/***** Interpreters *****/
|
|
|
|
auto InterpProgram(std::list<Declaration>* fs) -> int;
|
|
auto InterpExp(Env values, const Expression* e) -> const Value*;
|
|
auto InterpPattern(Env values, const Pattern* p) -> const Value*;
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // EXECUTABLE_SEMANTICS_INTERPRETER_INTERPRETER_H_
|