blob: 5014d07e1747128472154f8a01bb860a7424cad9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package org.zwobble.hobgoblin.compiler.interpreter;
import org.zwobble.hobgoblin.compiler.ast.typed.*;
import org.zwobble.hobgoblin.compiler.types.TypeLevelValueType;
import java.util.List;
public class Interpreter<TValue> {
private final InterpreterConfig<TValue> config;
public Interpreter(InterpreterConfig<TValue> config) {
this.config = config;
}
public TValue evalStatements(
List<TypedStatementNode> statements
) {
for (var statement : statements) {
switch (statement) {
case TypedReturnNode return_ -> {
return evalExpression(return_.expression());
}
}
}
throw new UnsupportedOperationException("TODO: missing return");
}
public TValue evalExpression(
TypedExpressionNode expression
) {
if (expression.type() instanceof TypeLevelValueType typeLevelValue) {
return config.typeLevelValueToValue(typeLevelValue.value());
}
throw new UnsupportedOperationException("TODO");
}
}
|