public abstract class AbstractSignalSourceChooser extends Object
Subclasses may realize time-dependent choice by providing a selector signal source, and associate an input signal source with each of the valid selector values.
Efficient compilation is ensured by collecting the code branches to choose
from in an int
-indexed table that can be used with a switch
statement.
Since signals have no means to communicate errors, the choice should be
total, that is defined at all times. Since this is technically difficult to
ensure statically, signal sources derived from this base class are permitted
to fail when no input can be chosen. It is recommended that IndexOutOfBoundsException
be thrown if an invalid selector value has
occurred, but that the default value of the signal type is produced if no
input signal source has been associated with the current, valid selector
value.
Constructor and Description |
---|
AbstractSignalSourceChooser() |
Modifier and Type | Method and Description |
---|---|
static <E extends Throwable> |
alwaysThrow(E throwable) |
protected abstract Consumer<CompilationContext> |
compileConvertToInt()
Returns a code generator for converting a value that represents the current
selection to an index of type
int . |
Consumer<CompilationContext> |
compileDataFlow() |
protected abstract Consumer<CompilationContext> |
compileDefaultValue()
Returns a code generator for loading the default value of the signal type
on the operand stack.
|
protected Consumer<CompilationContext> |
compileOrDefault(VariableContext.Variable result,
CompilableDataFlow branch) |
protected abstract Map<Integer,Consumer<CompilationContext>> |
getCases(VariableContext.Variable result)
Returns a map with
int -indexed code generators for branches to
choose from. |
protected abstract CompilableDataFlow |
getSelector()
Returns an entity that can be compiled to code that outputs a
value that represents the current selection.
|
protected abstract CompilableDataFlow getSelector()
CompilableDataFlow.getValueClass()
protected abstract Consumer<CompilationContext> compileConvertToInt()
int
.protected abstract Consumer<CompilationContext> compileDefaultValue()
public Consumer<CompilationContext> compileDataFlow()
protected abstract Map<Integer,Consumer<CompilationContext>> getCases(VariableContext.Variable result)
int
-indexed code generators for branches to
choose from. The returned map should contain an entry for every valid
index. The method compileOrDefault(eu.bandm.tools.lljava.live.VariableContext.Variable, eu.bandm.sig.adlib2.compile.CompilableDataFlow)
may be used to populate the map.result
- the variable that all branches should output tocompileConvertToInt()
protected Consumer<CompilationContext> compileOrDefault(VariableContext.Variable result, CompilableDataFlow branch)