mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 06:15:01 +01:00
This also eliminates the ctad wrapper for Stack: I think the leaning is to remove it. It felt worth keeping the constructor because constructing with a single element is a common use-case. Adds a single-argument constructor for Scope because the `std::list<std::string>()` is common, and eliding it is consistent with what we've done for things like tuples. I was considering a vector constructor due to the double-Push on line 1139, but thought the Push() semantics may mean that it's better not to provide.
50 lines
1.6 KiB
C++
50 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 "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<Ptr<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, llvm::raw_ostream& out);
|
|
|
|
/***** Interpreters *****/
|
|
|
|
// Attempts to match `v` against the pattern `p`. If matching succeeds, returns
|
|
// the bindings of pattern variables to their matched values.
|
|
auto PatternMatch(const Value* p, const Value* v, int line_num)
|
|
-> std::optional<Env>;
|
|
|
|
auto InterpProgram(const std::list<Ptr<const 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_
|