-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from aya-lang/named-instruction-spi-v0.6
Load new operators at runtime
- Loading branch information
Showing
22 changed files
with
921 additions
and
754 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
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,36 @@ | ||
## Adding more Instructions | ||
|
||
You can add more Instructions by loading a `.jar` file with `:(library.load)` | ||
|
||
A jar can provide one or more `NamedInstructionStore` implementations. | ||
This is done by adding the fully qualified class name(s) to this file: | ||
`META-INF/services/aya.instruction.named.NamedInstructionStore` | ||
|
||
For more information, you should look up 'Java SPI' (Service Provider Interface). | ||
|
||
### Example | ||
|
||
This adds an instruction `:{example.instruction}` which pushes the String `hello, world` onto the stack. | ||
|
||
```java | ||
package my.instruction; | ||
|
||
import aya.eval.BlockEvaluator; | ||
import aya.instruction.named.NamedInstructionStore; | ||
import aya.instruction.named.NamedOperator; | ||
import aya.obj.list.List; | ||
|
||
public class MyInstructionStore implements NamedInstructionStore { | ||
@Override | ||
public Collection<NamedOperator> getNamedInstructions() { | ||
return Arrays.asList( | ||
new NamedOperator("example.instruction") { | ||
@Override | ||
public void execute(BlockEvaluator blockEvaluator) { | ||
blockEvaluator.push(List.fromString("hello, world")); | ||
} | ||
} | ||
); | ||
} | ||
} | ||
``` |
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
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.