Skip to content

Commit

Permalink
Clean up exception reporting + bug fixes
Browse files Browse the repository at this point in the history
Bug: ribose run output not directed to file specified on command line

- fix up @throws for javadoc
- remove exceptions declared but not thrown per method
- bug fixes
  - delete jar files in clean-ribose target in build.xml
  - Model.java @ line 360 (fix array length growth factor)
  - ModelLoader.java @ line 164 (direct transductor output)
  - send InputStack log output to runtime log instead of compile log

Signed-off-by: jrte <jrte.project@gmail.com>
  • Loading branch information
jrte committed Sep 20, 2023
1 parent 13e5db0 commit 2e307db
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 46 deletions.
10 changes: 4 additions & 6 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@
<pathelement location="${jars.dir}/${ribose.version}.jar"/>
</path>

<target name="clean" depends="clean-ribose,clean-test">
<target name="clean" depends="clean-ribose,clean-test,clean-javadoc">
<delete failonerror="false" dir="build"/>
<delete failonerror="false" verbose="true">
<fileset dir="." includes="ribose-*.log*"/>
</delete>
<delete failonerror="false" dir="." includes="ribose-*.log*"/>
</target>

<target name="clean-ribose" depends="clean-javadoc">
<target name="clean-ribose">
<delete failonerror="false" dir="${jars.dir}" includes="*"/>
<delete failonerror="false" dir="${build.java.classes}/com"/>
<delete failonerror="false" dir="${build.compiler.model}"/>
<delete failonerror="false" dir="/tmp" includes="*.ginrout,*.ginrerr"/>
</target>

<target name="clean-javadoc">
<delete failonerror="false" file="${jars.dir}/${ribose.version}-api.jar"/>
<delete failonerror="false" dir="javadoc" includes="**/*"/>
</target>

Expand Down
2 changes: 1 addition & 1 deletion src/com/characterforming/jrte/engine/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static int getOutBufferSize() {
* @param bytes The UTF-8 byte array
* @param length The number of bytes to decode, starting from 0
* @return the decoded integer
* @throws NumberFormatException on error
* @throws NumberFormatException if things don't work out
*/
public static int decodeInt(final byte[] bytes, int length) throws NumberFormatException {
int value = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/com/characterforming/jrte/engine/InputStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class FreeStack extends LinkedList<byte[]> {
}

InputStack(final int initialSize) {
this.logger = Base.getCompileLogger();
this.logger = Base.getRuntimeLogger();
this.stack = Input.stack(initialSize);
this.markList = Input.stack(initialSize);
this.markState = InputStack.CLEAR;
Expand Down
8 changes: 4 additions & 4 deletions src/com/characterforming/jrte/engine/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.characterforming.ribose.base.Bytes;
import com.characterforming.ribose.base.CompilationException;
import com.characterforming.ribose.base.ModelException;
import com.characterforming.ribose.base.Signal;

/**
* @author Kim Briggs
Expand Down Expand Up @@ -351,17 +352,16 @@ protected int addSignal(Bytes signalName) {

protected int addTransducer(Bytes transducerName) {
Integer ordinal = this.transducerOrdinalMap.get(transducerName);
assert ordinal == null || transducerName.equals(this.transducerNameIndex[ordinal]);
if (ordinal == null) {
ordinal = this.transducerOrdinalMap.size();
this.transducerOrdinalMap.put(transducerName, ordinal);
if (ordinal >= this.transducerNameIndex.length) {
int length = ordinal + (ordinal << 1);
int length = ordinal + (Math.max(ordinal, 4) >> 1);
this.transducerNameIndex = Arrays.copyOf(this.transducerNameIndex, length);
this.transducerOffsetIndex = Arrays.copyOf(this.transducerOffsetIndex, length);
}
this.transducerNameIndex[ordinal] = transducerName;
} else {
assert this.transducerNameIndex[ordinal].equals(transducerName);
}
return ordinal;
}
Expand Down Expand Up @@ -510,7 +510,7 @@ protected long[] readTransitionMatrix() throws ModelException {
final int nStates = this.io.readInt();
final int nInputs = this.io.readInt();
matrix = new long[nStates * nInputs];
// preset all cells to invoke nul() effector on domain error
// preset all cells to signal NUL without changing state
for (int state = 0; state < nStates; state++) {
final int toState = state * nInputs;
final long nul = Transducer.transition(toState, 0);
Expand Down
3 changes: 2 additions & 1 deletion src/com/characterforming/jrte/engine/ModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private ModelLoader(final File modelPath)
*
* @param modelFile the model file
* @return the loaded model instance
* @throws ModelException on error
* @throws ModelException if things don't work out
*/
public static ModelLoader loadModel(File modelPath)
throws ModelException {
Expand Down Expand Up @@ -161,6 +161,7 @@ public boolean stream(Bytes transducer, ITarget target, Signal prologue, InputSt
int position = read;
if (read > 0) {
ITransductor trex = transductor(target);
trex.output(out);
if (prologue != null)
trex.signal(prologue);
if (trex.push(bytes, read).start(transducer).status().isRunnable()) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/characterforming/jrte/engine/Transductor.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public final class Transductor implements ITransductor, IOutput {
* Constructor
*
* @param model The runtime model
* @throws ModelException on error
* @throws ModelException if things don't work out
*/
Transductor(final Model model) {
super();
Expand Down
11 changes: 4 additions & 7 deletions src/com/characterforming/jrte/test/FileRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharsetDecoder;
Expand All @@ -40,18 +39,16 @@
import com.characterforming.ribose.ITransductor;
import com.characterforming.ribose.ITransductor.Metrics;
import com.characterforming.ribose.base.Bytes;
import com.characterforming.ribose.base.RiboseException;
import com.characterforming.ribose.base.Signal;

public class FileRunner {

/**
* @param args
* @throws InterruptedException on error
* @throws RiboseException on error
* @throws IOException on error
* Shell interface.
*
* @param args arguments from the shell
*/
public static void main(final String[] args) throws InterruptedException, RiboseException, IOException {
public static void main(final String[] args) {
final boolean nil = args[0].compareTo("--nil") == 0;
int arg = nil ? 1 : 0;
if ((args.length - arg) < 3) {
Expand Down
12 changes: 4 additions & 8 deletions src/com/characterforming/jrte/test/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.characterforming.jrte.test;

import java.io.File;
import java.io.IOException;
import java.nio.CharBuffer;
import java.nio.charset.CharsetEncoder;
import java.util.logging.Level;
Expand All @@ -33,19 +32,16 @@
import com.characterforming.ribose.ITransductor;
import com.characterforming.ribose.ITransductor.Status;
import com.characterforming.ribose.base.Bytes;
import com.characterforming.ribose.base.RiboseException;
import com.characterforming.ribose.base.Signal;

public class TestRunner {

/**
* @param args
* @throws InterruptedException on error
* @throws RiboseException on error
* @throws IOException on error
* @throws SecurityException on error
* Shell interface.
*
* @param args arguments from the shell
*/
public static void main(final String[] args) throws InterruptedException, RiboseException, SecurityException, IOException {
public static void main(final String[] args) {
if (args.length == 0) {
System.out.println(String.format("Usage: java -cp <classpath> %1$s <model-path> [wait-ms]", TestRunner.class.getName()));
System.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/com/characterforming/ribose/IEffector.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public interface IEffector<T extends ITarget> {
* This method is invoked at runtime when triggered by an input transition.
*
* @return user-defined effectors should return {@code IEffector.RTX_NONE}
* @throws EffectorException on error
* @throws EffectorException if things don't work out
*/
int invoke() throws EffectorException;

Expand Down
12 changes: 6 additions & 6 deletions src/com/characterforming/ribose/IModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface IModel extends AutoCloseable {
* @param riboseModelFile path indicating where to create the model file
* @return true if the model was created successfully
* @throws ClassNotFoundException if {@code targetClassname} not found
* @throws ModelException if compilation
* @throws ModelException if compilation fails
*/
public static boolean compileRiboseModel(String targetClassname, File ginrAutomataDirectory, File riboseModelFile)
throws ClassNotFoundException, ModelException {
Expand Down Expand Up @@ -94,7 +94,7 @@ public static IModel loadRiboseModel(File riboseModelFile)
*
* @param target the target instance to bind to the transductor
* @return a new transductor
* @throws ModelException on error
* @throws ModelException if things don't work out
* @see ITransductor
*/
ITransductor transductor(ITarget target)
Expand Down Expand Up @@ -123,7 +123,7 @@ ITransductor transductor(ITarget target)
* @param in the input stream to transduce (eg, {@code System.in})
* @param out the output stream to render output to (eg, {@code System.out})
* @return true if transduction is complete, otherwise false
* @throws RiboseException on error
* @throws RiboseException if things don't work out
*/
boolean stream(Bytes transducer, Signal prologue, InputStream in, OutputStream out)
throws RiboseException;
Expand All @@ -139,7 +139,7 @@ boolean stream(Bytes transducer, Signal prologue, InputStream in, OutputStream o
* @param in the input stream to transduce (eg, {@code System.in})
* @param out the output stream to render output to (eg, {@code System.out})
* @return true if target is an instance of the model target class and transduction is complete
* @throws RiboseException on error
* @throws RiboseException if things don't work out
*/
boolean stream(Bytes transducer, ITarget target, Signal prologue, InputStream in, OutputStream out)
throws RiboseException;
Expand All @@ -148,7 +148,7 @@ boolean stream(Bytes transducer, ITarget target, Signal prologue, InputStream in
* Decompile a transducer to System.out
*
* @param transducerName the transducer name as aUnicode string
* @throws ModelException on error
* @throws ModelException if things don't work out
*/
void decompile(String transducerName)
throws ModelException;
Expand All @@ -163,7 +163,7 @@ void decompile(String transducerName)
/**
* Close the runtime model and file.
*
* @throws ModelException on error
* @throws ModelException if things don't work out
*/
@Override
void close()
Expand Down
4 changes: 2 additions & 2 deletions src/com/characterforming/ribose/IOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public interface IOutput {
*
* @param fieldName the name of the field (UTF-8 bytes, withouy `~` prefix in lead byte)
* @return a field instance or null
* @throws TargetBindingException on error
* @throws TargetBindingException if things don't work out
*/
IField getField(Bytes fieldName) throws TargetBindingException;

Expand All @@ -82,7 +82,7 @@ public interface IOutput {
*
* @param fieldName the name of the field (UTF-8 bytes, without `~` prefix in lead byte)
* @return the ordinal number of the field
* @throws TargetBindingException on error
* @throws TargetBindingException if things don't work out
*/
int getFieldOrdinal(Bytes fieldName) throws TargetBindingException;

Expand Down
4 changes: 2 additions & 2 deletions src/com/characterforming/ribose/IParameterizedEffector.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public interface IParameterizedEffector<T extends ITarget, P> extends IEffector<
*
* @param parameterIndex the index of the parameter object to be applied
* @return user-defined effectors should return 0 (RTX_SI)
* @throws EffectorException on error
* @throws EffectorException if things don't work out
*/
int invoke(int parameterIndex) throws EffectorException;

Expand All @@ -124,7 +124,7 @@ public interface IParameterizedEffector<T extends ITarget, P> extends IEffector<
*
* @param parameterTokens an array of parameters, where each parameter is an array of bytes.
* @return the compiled parameter value object
* @throws TargetBindingException on error
* @throws TargetBindingException if things don't work out
*/
P compileParameter(IToken[] parameterTokens) throws TargetBindingException;

Expand Down
2 changes: 1 addition & 1 deletion src/com/characterforming/ribose/ITarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public interface ITarget {
* the interaction is driven from an effector invokation.
*
* @return an array of IEffector instances bound to the target instance
* @throws TargetBindingException on error
* @throws TargetBindingException if things don't work out
*/
IEffector<?>[] getEffectors() throws TargetBindingException;
}
6 changes: 3 additions & 3 deletions src/com/characterforming/ribose/ITransductor.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void update(Metrics accumulator) {
*
* @param transducer the name of the transducer to push
* @return this ITransductor
* @throws ModelException on error
* @throws ModelException if things don't work out
*/
ITransductor start(Bytes transducer) throws ModelException;

Expand All @@ -339,8 +339,8 @@ public void update(Metrics accumulator) {
* if the transduction involves backtracking with mark/reset.
*
* @return this ITransductor
* @throws EffectorException on error
* @throws DomainErrorException on error
* @throws EffectorException if an effector invocation fails
* @throws DomainErrorException if no transition defined for current input
* @see #recycle(byte[])
* @see #status()
*/
Expand Down
2 changes: 1 addition & 1 deletion src/com/characterforming/ribose/Ribose.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private static boolean execDecompile(final String[] args) {
} catch (ModelException e) {
final String format = "Failed to decompile %1$s";
rteLogger.log(Level.SEVERE, e, () -> String.format(format,
transducerName));
transducerName));
} finally {
Base.endLogging();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public final void setParameters(IParameterizedEffector<?,?> proxyEffector) {
assert proxyEffector instanceof BaseParameterizedEffector<?,?>;
if (proxyEffector instanceof BaseParameterizedEffector<?,?> proxy) {
this.parameters = (P[])proxy.parameters;
this.tokens = proxy.tokens;
}
}

Expand Down

0 comments on commit 2e307db

Please sign in to comment.