mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-25 19:10:12 +01:00
* interfaces, impls, and constrained generics (basics) * separate type checking into declare vs. type check, removing redundancy * external impls * added impl scopes to handle generics calling generics * cleanup * more cleanup * Update executable_semantics/testdata/interface/external_impl_point_vector.carbon Co-authored-by: josh11b <josh11b@users.noreply.github.com> * Update executable_semantics/testdata/interface/generic_call_generic.carbon Co-authored-by: josh11b <josh11b@users.noreply.github.com> * Update executable_semantics/testdata/interface/tuple_vector_add_scale.carbon Co-authored-by: josh11b <josh11b@users.noreply.github.com> * Update executable_semantics/testdata/interface/vector_point_add_scale.carbon Co-authored-by: josh11b <josh11b@users.noreply.github.com> * change ImplementationDeclaration to ImplDeclaration * remove impl_type_value * split NamedEntity into two * changed GetName to be a free function * adding comments * more edits to respond to review * introduce ImplBinding, remove punning on GenericBinding * new test case and some minor edits * refactor GetMember and GetField to move impl logic to interpreter * remove commennt * change EntityView to ImplBinding in FieldAccess... * move ImplBinding * review response * added example to impl_scope.h * minor edits * Update executable_semantics/interpreter/field_path.h Co-authored-by: Geoff Romer <gromer@google.com> * Update executable_semantics/interpreter/value.cpp Co-authored-by: Geoff Romer <gromer@google.com> * Update executable_semantics/interpreter/interpreter.cpp Co-authored-by: Geoff Romer <gromer@google.com> * Update executable_semantics/ast/expression.h Co-authored-by: Geoff Romer <gromer@google.com> * Update executable_semantics/ast/expression.h Co-authored-by: Geoff Romer <gromer@google.com> * Update executable_semantics/ast/generic_binding.h Co-authored-by: Geoff Romer <gromer@google.com> * more edits from review * review response * Update executable_semantics/ast/static_scope.h Co-authored-by: Geoff Romer <gromer@google.com> * remove ImplType, renamed node_view to value_node Co-authored-by: josh11b <josh11b@users.noreply.github.com> Co-authored-by: Geoff Romer <gromer@google.com>
63 lines
2.1 KiB
C++
63 lines
2.1 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_HEAP_H_
|
|
#define EXECUTABLE_SEMANTICS_INTERPRETER_HEAP_H_
|
|
|
|
#include <vector>
|
|
|
|
#include "common/ostream.h"
|
|
#include "executable_semantics/ast/source_location.h"
|
|
#include "executable_semantics/common/nonnull.h"
|
|
#include "executable_semantics/interpreter/address.h"
|
|
#include "executable_semantics/interpreter/heap_allocation_interface.h"
|
|
#include "executable_semantics/interpreter/value.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// A Heap represents the abstract machine's dynamically allocated memory.
|
|
class Heap : public HeapAllocationInterface {
|
|
public:
|
|
// Constructs an empty Heap.
|
|
explicit Heap(Nonnull<Arena*> arena) : arena_(arena){};
|
|
|
|
Heap(const Heap&) = delete;
|
|
auto operator=(const Heap&) -> Heap& = delete;
|
|
|
|
// Returns the value at the given address in the heap after
|
|
// checking that it is alive.
|
|
auto Read(const Address& a, SourceLocation source_loc) const
|
|
-> Nonnull<const Value*>;
|
|
|
|
// Writes the given value at the address in the heap after
|
|
// checking that the address is alive.
|
|
void Write(const Address& a, Nonnull<const Value*> v,
|
|
SourceLocation source_loc);
|
|
|
|
// Put the given value on the heap and mark it as alive.
|
|
auto AllocateValue(Nonnull<const Value*> v) -> AllocationId override;
|
|
|
|
// Marks this allocation, and all of its sub-objects, as dead.
|
|
void Deallocate(AllocationId allocation) override;
|
|
|
|
// Print all the values on the heap to the stream `out`.
|
|
void Print(llvm::raw_ostream& out) const;
|
|
|
|
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
|
|
|
|
auto arena() const -> Arena& override { return *arena_; }
|
|
|
|
private:
|
|
// Signal an error if the allocation is no longer alive.
|
|
void CheckAlive(AllocationId allocation, SourceLocation source_loc) const;
|
|
|
|
Nonnull<Arena*> arena_;
|
|
std::vector<Nonnull<const Value*>> values_;
|
|
std::vector<bool> alive_;
|
|
};
|
|
|
|
} // namespace Carbon
|
|
|
|
#endif // EXECUTABLE_SEMANTICS_INTERPRETER_HEAP_H_
|