Skip to content

Commit

Permalink
fix group id
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx committed Oct 19, 2023
1 parent 7c6d4fa commit 38ce6f6
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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>com.dylibso.chickory</groupId>
<groupId>com.dylibso.chicory</groupId>
<artifactId>chicory</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
Expand Down Expand Up @@ -30,7 +30,7 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.dylibso.chickory</groupId>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
6 changes: 3 additions & 3 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.dylibso.chickory</groupId>
<groupId>com.dylibso.chicory</groupId>
<artifactId>chicory</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
Expand All @@ -12,7 +12,7 @@

<dependencies>
<dependency>
<groupId>com.dylibso.chickory</groupId>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm</artifactId>
</dependency>

Expand All @@ -25,7 +25,7 @@
<build>
<plugins>
<plugin>
<groupId>com.dylibso.chickory</groupId>
<groupId>com.dylibso.chicory</groupId>
<artifactId>test-gen-plugin</artifactId>
<version>${project.version}</version>
<configuration>
Expand Down
6 changes: 6 additions & 0 deletions runtime/src/main/java/com/dylibso/chicory/runtime/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dylibso.chicory.wasm.exceptions.ChicoryException;
import com.dylibso.chicory.wasm.exceptions.InvalidException;
import com.dylibso.chicory.wasm.types.*;
import java.io.InputStream;
import java.util.HashMap;

public class Module {
Expand All @@ -15,6 +16,11 @@ public static Module build(String wasmFile) {
return new Module(parser.parseModule());
}

public static Module build(InputStream inputWasmFile) {
var parser = new Parser(inputWasmFile);
return new Module(parser.parseModule());
}

public static Module build(String wasmFile, ModuleType type) {
switch (type) {
case TEXT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ public void shouldSupportGlobals() {
public void shouldCountVowels() {
var instance = Module.build("src/test/resources/wasm/count_vowels.rs.wasm").instantiate();
var alloc = instance.getExport("alloc");
var dealloc = instance.getExport("dealloc");
var countVowels = instance.getExport("count_vowels");
var memory = instance.getMemory();
var message = "Hello, World!";
var len = message.getBytes().length;
var ptr = alloc.apply(Value.i32(len)).asInt();
memory.put(ptr, message);
var result = countVowels.apply(Value.i32(ptr), Value.i32(len));
dealloc.apply(Value.i32(ptr), Value.i32(len));
assertEquals(3, result.asInt());
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/test/resources/wasm/count_vowels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub extern "C" fn alloc(len: i32) -> *const u8 {
}

#[no_mangle]
pub unsafe extern "C" fn dealloc(ptr: &mut u8) {
let _ = Vec::from_raw_parts(ptr, 0, 1024);
pub unsafe extern "C" fn dealloc(ptr: &mut u8, len: i32) {
let _ = Vec::from_raw_parts(ptr, 0, len as usize);
}

#[no_mangle]
Expand Down
Binary file modified runtime/src/test/resources/wasm/count_vowels.rs.wasm
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion test-gen-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.dylibso.chickory</groupId>
<groupId>com.dylibso.chicory</groupId>
<artifactId>chicory</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion wasm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.dylibso.chickory</groupId>
<groupId>com.dylibso.chicory</groupId>
<artifactId>chicory</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
Expand Down
13 changes: 12 additions & 1 deletion wasm/src/main/java/com/dylibso/chicory/wasm/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dylibso.chicory.wasm.types.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
Expand All @@ -13,6 +14,7 @@

public class Parser {
private String filePath;
private InputStream inputStream;
private ParserListener listener;
private List<Integer> includeSections;

Expand All @@ -24,6 +26,12 @@ public Parser(String filePath) {
this.includeSections = null;
}

public Parser(InputStream inputStream) {
this.inputStream = inputStream;
this.listener = null;
this.includeSections = null;
}

public void setListener(ParserListener listener) {
this.listener = listener;
}
Expand All @@ -36,7 +44,10 @@ public void includeSection(int sectionId) {
private ByteBuffer readByteBuffer() {
try {
// Read the Wasm file into a ByteBuffer
FileInputStream fileInputStream = new FileInputStream(filePath);
var fileInputStream = inputStream;
if (this.inputStream == null) {
fileInputStream = new FileInputStream(filePath);
}
byte[] buf = new byte[fileInputStream.available()];
fileInputStream.read(buf);
fileInputStream.close();
Expand Down

0 comments on commit 38ce6f6

Please sign in to comment.