mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-29 19:24:59 +01:00
As a follow up to #2825 this pr implements size deduction for nested arrays. E.g. `var x: [[i32;];] = ((1,2), (3,4));`. Also updated the pattern matching logic for arrays, now it also checks element types of the tuple size being deduced from. As a result code like `var x: [i32;] = ("foo", "bar");`(note, that it tries to init an array of i32 with a tuple of strings) fails to compile with a pattern match error instead of an implicit cast failed error. Moved some common type-related logic used in type_checker.cpp and interpreter.cpp to the separate file.
32 lines
1.2 KiB
C++
32 lines
1.2 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 CARBON_EXPLORER_INTERPRETER_INTERPRETER_H_
|
|
#define CARBON_EXPLORER_INTERPRETER_INTERPRETER_H_
|
|
|
|
#include "common/ostream.h"
|
|
#include "explorer/ast/ast.h"
|
|
#include "explorer/ast/expression.h"
|
|
#include "explorer/ast/value.h"
|
|
#include "explorer/base/trace_stream.h"
|
|
|
|
namespace Carbon {
|
|
|
|
// Interprets the program defined by `ast`, allocating values on `arena` and
|
|
// printing traces if `trace` is true.
|
|
auto InterpProgram(const AST& ast, Nonnull<Arena*> arena,
|
|
Nonnull<TraceStream*> trace_stream,
|
|
Nonnull<llvm::raw_ostream*> print_stream) -> ErrorOr<int>;
|
|
|
|
// Interprets `e` at compile-time, allocating values on `arena` and
|
|
// printing traces if `trace` is true. The caller must ensure that all the
|
|
// code this evaluates has been typechecked.
|
|
auto InterpExp(Nonnull<const Expression*> e, Nonnull<Arena*> arena,
|
|
Nonnull<TraceStream*> trace_stream,
|
|
Nonnull<llvm::raw_ostream*> print_stream)
|
|
-> ErrorOr<Nonnull<const Value*>>;
|
|
} // namespace Carbon
|
|
|
|
#endif // CARBON_EXPLORER_INTERPRETER_INTERPRETER_H_
|