Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-paul committed Dec 31, 2024
0 parents commit 1858e50
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
52 changes: 52 additions & 0 deletions README.md
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
34 changes: 34 additions & 0 deletions pom.xml
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
example.spi.ExampleInstructionStore
example.spi.ExampleInstructionStore2
23 changes: 23 additions & 0 deletions src/example/spi/ExampleInstructionStore.java
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"));
}
}
);
}
}
23 changes: 23 additions & 0 deletions src/example/spi/ExampleInstructionStore2.java
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"));
}
}
);
}
}

0 comments on commit 1858e50

Please sign in to comment.