Package net.hydromatic.morel.compile
Class Compiles
java.lang.Object
net.hydromatic.morel.compile.Compiles
Helpers for
Compiler and TypeResolver.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidacceptBinding(TypeSystem typeSystem, Core.Pat pat, List<Binding> bindings) Visits a pattern, adding bindings to a list.static voidbindDataType(TypeSystem typeSystem, List<Binding> bindings, DataType dataType) (package private) static Compiles.PatternBinderbinding(TypeSystem typeSystem, List<Binding> bindings) (package private) static voidbindPattern(TypeSystem typeSystem, List<Binding> bindings, Core.DatatypeDecl datatypeDecl) (package private) static voidbindPattern(TypeSystem typeSystem, List<Binding> bindings, Core.NamedPat namedPat) (package private) static voidbindPattern(TypeSystem typeSystem, List<Binding> bindings, Core.Pat pat) (package private) static voidbindPattern(TypeSystem typeSystem, List<Binding> bindings, Core.ValDecl valDecl) Richer thanbindPattern(TypeSystem, List, Core.Pat)because we have the expression.private static voidcheckPatternCoverage(TypeSystem typeSystem, Core.Case kase, Consumer<CompileException> errorConsumer, Consumer<CompileException> warningConsumer) private static voidcheckPatternCoverage(TypeSystem typeSystem, Core.Decl decl, Consumer<CompileException> warningConsumer) Checks for exhaustive and redundant patterns, and throws if there are errors/warnings.private static @Nullable Core.NamedPatgetSkipPat(Ast.Decl decl, Core.Decl coreDecl) Returns a pattern that should not be printed, or null.private static CompiledStatementprepareDecl(TypeSystem typeSystem, Session session, Environment env, @Nullable Calcite calcite, Ast.Decl decl, Consumer<CompileException> warningConsumer, Tracer tracer) Validates and compiles a declaration, and compiles it to code that can be evaluated by the interpreter.static CompiledStatementprepareStatement(TypeSystem typeSystem, Session session, Environment env, AstNode statement, @Nullable Calcite calcite, Consumer<CompileException> warningConsumer, Tracer tracer) Validates and compiles a statement (expression or declaration), and compiles it to code that can be evaluated by the interpreter.static Ast.DeclConverts an expression or declaration to a declaration.static Core.ExptoExp(Core.NonRecValDecl decl) static Ast.ValDeclConvertsetoval = e.static Ast.ValDeclConverts an expression or value declaration to a value declaration.static TypeResolver.ResolvedvalidateExpression(AstNode statement, Map<Prop, Object> propMap, Map<String, ForeignValue> valueMap) Validates an expression or declaration, deducing its type and perhaps rewriting the expression to a form that can more easily be compiled.
-
Constructor Details
-
Compiles
public Compiles()
-
-
Method Details
-
validateExpression
public static TypeResolver.Resolved validateExpression(AstNode statement, Map<Prop, Object> propMap, Map<String, ForeignValue> valueMap) Validates an expression or declaration, deducing its type and perhaps rewriting the expression to a form that can more easily be compiled.Used for testing.
-
prepareStatement
public static CompiledStatement prepareStatement(TypeSystem typeSystem, Session session, Environment env, AstNode statement, @Nullable Calcite calcite, Consumer<CompileException> warningConsumer, Tracer tracer) Validates and compiles a statement (expression or declaration), and compiles it to code that can be evaluated by the interpreter. -
prepareDecl
private static CompiledStatement prepareDecl(TypeSystem typeSystem, Session session, Environment env, @Nullable Calcite calcite, Ast.Decl decl, Consumer<CompileException> warningConsumer, Tracer tracer) Validates and compiles a declaration, and compiles it to code that can be evaluated by the interpreter. -
getSkipPat
Returns a pattern that should not be printed, or null.Consider the two declarations:
val it as (x, y) = (5, 6); val (x, y) = (5, 6);coreDeclis the same for both. For the first, we should printval it = (5,6) : int * int val x = 5 : int val x = 6 : intbut for the second we should skip
it, as follows:val x = 5 : int val x = 6 : int -
checkPatternCoverage
private static void checkPatternCoverage(TypeSystem typeSystem, Core.Decl decl, Consumer<CompileException> warningConsumer) Checks for exhaustive and redundant patterns, and throws if there are errors/warnings. -
checkPatternCoverage
private static void checkPatternCoverage(TypeSystem typeSystem, Core.Case kase, Consumer<CompileException> errorConsumer, Consumer<CompileException> warningConsumer) -
toValDecl
Convertsetoval = e. -
toValDecl
Converts an expression or value declaration to a value declaration. -
toDecl
Converts an expression or declaration to a declaration. -
toExp
-
bindPattern
static void bindPattern(TypeSystem typeSystem, List<Binding> bindings, Core.DatatypeDecl datatypeDecl) -
bindPattern
Richer thanbindPattern(TypeSystem, List, Core.Pat)because we have the expression. -
bindPattern
-
bindPattern
-
bindDataType
-
binding
-
acceptBinding
Visits a pattern, adding bindings to a list.If the pattern is an
Core.IdPat, don't use this method: just bind directly.
-