-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1858e50
Showing
6 changed files
with
135 additions
and
0 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 @@ | ||
target/ |
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,52 @@ | ||
# Aya Java Library Example | ||
|
||
## How to use | ||
|
||
You can either download the jar from the releases page or build the library yourself (see below) | ||
|
||
Then in aya, use the `:(library.load)` operator to load the jar. Make sure to use the correct path to where you have the jar saved | ||
|
||
`:(library.load)` will return a list of loaded operators. In this case, there are 2. | ||
|
||
``` | ||
aya> "target/aya-library-example-1.0-SNAPSHOT.jar" :(library.load) | ||
[ ":(example.instruction)" ":(example.instruction2)" ] | ||
aya> :(example.instruction) | ||
"hello, world" | ||
aya> :(example.instruction2) | ||
"foo bar" | ||
aya> | ||
``` | ||
|
||
## Building | ||
|
||
### Install Aya | ||
|
||
To build, first install [Aya](https://github.com/aya-lang/aya/). To install, clone the repo, then from inside the aya dir, run `mvn install` | ||
|
||
``` | ||
git clone https://github.com/aya-lang/aya.git | ||
cd aya | ||
mvn install | ||
``` | ||
|
||
### Build | ||
|
||
To build this library, run the package command | ||
|
||
``` | ||
mvn package | ||
``` | ||
|
||
## Adding more Instructions | ||
|
||
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). | ||
|
||
## Contributors | ||
|
||
- @BlazingTwist | ||
- @nick-paul |
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,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.github.blazingtwist</groupId> | ||
<artifactId>aya-library-example</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<sourceDirectory>src</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>resources</directory> | ||
</resource> | ||
</resources> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>co.npaul.aya</groupId> | ||
<artifactId>aya</artifactId> | ||
<version>0.6.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
2 changes: 2 additions & 0 deletions
2
resources/META-INF/services/aya.instruction.named.NamedInstructionStore
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,2 @@ | ||
example.spi.ExampleInstructionStore | ||
example.spi.ExampleInstructionStore2 |
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,23 @@ | ||
package example.spi; | ||
|
||
import aya.eval.BlockEvaluator; | ||
import aya.instruction.named.NamedInstructionStore; | ||
import aya.instruction.named.NamedOperator; | ||
import aya.obj.list.List; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
public class ExampleInstructionStore implements NamedInstructionStore { | ||
@Override | ||
public Collection<NamedOperator> getNamedInstructions() { | ||
return Arrays.asList( | ||
new NamedOperator("example.instruction", "Pushes 'hello, world' onto the stack") { | ||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package example.spi; | ||
|
||
import aya.eval.BlockEvaluator; | ||
import aya.instruction.named.NamedInstructionStore; | ||
import aya.instruction.named.NamedOperator; | ||
import aya.obj.list.List; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
public class ExampleInstructionStore2 implements NamedInstructionStore { | ||
@Override | ||
public Collection<NamedOperator> getNamedInstructions() { | ||
return Arrays.asList( | ||
new NamedOperator("example.instruction2", "Pushes 'foo bar' onto the stack") { | ||
@Override | ||
public void execute(BlockEvaluator blockEvaluator) { | ||
blockEvaluator.push(List.fromString("foo bar")); | ||
} | ||
} | ||
); | ||
} | ||
} |