-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds macro evaluator implementation (#924)
- Loading branch information
Showing
4 changed files
with
1,000 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package com.amazon.ion.impl.macro | ||
|
||
/** | ||
* An `Environment` contains variable bindings for a given macro evaluation. | ||
* | ||
* The [arguments] is a list of expressions for the arguments that were passed to the current macro. | ||
* It may also contain other expressions if the current macro invocation is part of a larger evaluation. | ||
* | ||
* The [argumentIndices] is a mapping from parameter index to the start of the corresponding expression in [arguments]. | ||
* | ||
* The [parentEnvironment] is an environment to use if any of the expressions in this environment | ||
* contains a variable that references something from an outer macro invocation. | ||
*/ | ||
data class Environment private constructor( | ||
// Any variables found here have to be looked up in [parentEnvironment] | ||
val arguments: List<Expression>, | ||
// TODO: Replace with IntArray | ||
val argumentIndices: List<Int>, | ||
val parentEnvironment: Environment?, | ||
) { | ||
fun createChild(arguments: List<Expression>, argumentIndices: List<Int>) = Environment(arguments, argumentIndices, this) | ||
companion object { | ||
@JvmStatic | ||
val EMPTY = Environment(emptyList(), emptyList(), null) | ||
@JvmStatic | ||
fun create(arguments: List<Expression>, argumentIndices: List<Int>) = Environment(arguments, argumentIndices, null) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.