Skip to content

Commit

Permalink
Add effector parameters to model map
Browse files Browse the repository at this point in the history
- changes to the *.map files output with *.model files
  - include parameter types and raw parameter tokens per effector
  - reorder artifacts (signals,fields,transducers,effector/parameters)

Signed-off-by: jrte <[email protected]>
  • Loading branch information
jrte committed Aug 20, 2023
1 parent 1ed9233 commit a730338
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 79 deletions.
89 changes: 50 additions & 39 deletions TCompile.map
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
version ribose-0.0.2
target com.characterforming.ribose.TCompile
transducer Automaton 0
signal nul 256
signal nil 257
signal eol 258
signal eos 259
effector 0 0
effector 1 1
effector paste 2
effector select 3
effector copy 4
effector cut 5
effector clear 6
effector count 7
effector signal 8
effector in 9
effector out 10
effector mark 11
effector reset 12
effector start 13
effector pause 14
effector stop 15
effector msum 16
effector mproduct 17
effector mscan 18
effector header 19
effector transition 20
effector automaton 21
field 0
field * 1
field version 2
field tapes 3
field transitions 4
field states 5
field symbols 6
field from 7
field to 8
field tape 9
field length 10
field symbol 11
signal nul 256
signal nil 257
signal eol 258
signal eos 259
field 0
field * 1
field version 2
field tapes 3
field transitions 4
field states 5
field symbols 6
field from 7
field to 8
field tape 9
field length 10
field symbol 11
transducer Automaton 0
effector 0 0
effector 1 1
effector paste 2 [ IToken[] ]
effector select 3 [ Integer ]
`~version`
`~tapes`
`~transitions`
`~states`
`~symbols`
`~from`
`~to`
`~tape`
`~length`
`~symbol`
effector copy 4 [ Integer ]
effector cut 5 [ Integer ]
effector clear 6 [ Integer ]
effector count 7 [ int[] ]
`~length` `!eol`
effector signal 8 [ Integer ]
effector in 9 [ IToken[] ]
effector out 10 [ IToken[] ]
effector mark 11
effector reset 12
effector start 13 [ Integer ]
effector pause 14
effector stop 15
effector msum 16 [ long[] ]
effector mproduct 17 [ int[] ]
effector mscan 18 [ Integer ]
effector header 19
effector transition 20
effector automaton 21
3 changes: 1 addition & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@

<target name="javadoc" unless="javadoc.uptodate" depends="check-javadoc">
<delete dir="javadoc" includes="**/*"/>
<javadoc executable="${jdk}/bin/javadoc" access="protected" overview="overview.html" sourcepath="src" destdir="javadoc" splitindex="false"
use="true" version="true" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" verbose="false"
<javadoc executable="${jdk}/bin/javadoc" access="protected" overview="overview.html" sourcepath="src" destdir="javadoc" verbose="false"
packagenames="com.characterforming.ribose.base,com.characterforming.ribose"
doctitle="The General Idea" failonerror="false" failonwarning="false">
<group title="Ribose" packages="com.characterforming.ribose*"/>
Expand Down
5 changes: 5 additions & 0 deletions src/com/characterforming/jrte/engine/BaseFieldEffector.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public Integer compileParameter(final IToken[] parameterList) throws TargetBindi
}
return parameterList[0].getSymbolOrdinal();
}

@Override
public String showParameterType(int parameterIndex) {
return "Integer";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public IToken[][] allocateParameters(int parameterCount) {
return new IToken[parameterCount][];
}

@Override // @see com.characterforming.ribose.IParameterizedEffector#setParameter(int, byte[][])
@Override // @see com.characterforming.ribose.IParameterizedEffector#compileParameter(IToken[])
public IToken[] compileParameter(final IToken[] parameterList) throws TargetBindingException {
if (parameterList.length < 1) {
throw new TargetBindingException(String.format("%1$s.%2$s: effector requires at least one parameter",
Expand All @@ -66,4 +66,9 @@ public IToken[] compileParameter(final IToken[] parameterList) throws TargetBind
}
return parameterList;
}

@Override // @see com.characterforming.ribose.IParameterizedEffector#showParameterType(int)
public String showParameterType(int parameterIndex) {
return "IToken[]";
}
}
43 changes: 26 additions & 17 deletions src/com/characterforming/jrte/engine/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,33 +392,42 @@ private void saveMapFile(File mapFile) {
try (PrintWriter mapWriter = new PrintWriter(mapFile)) {
mapWriter.println(String.format("version\t%1$s", this.modelVersion));
mapWriter.println(String.format("target\t%1$s", this.proxyTarget.getClass().getName()));
Bytes[] transducerIndex = new Bytes[this.transducerOrdinalMap.size()];
for (Map.Entry<Bytes, Integer> m : this.transducerOrdinalMap.entrySet()) {
transducerIndex[m.getValue()] = m.getKey();
}
for (int i = 0; i < (transducerIndex.length - 1); i++) {
mapWriter.println("transducer\t" + transducerIndex[i] + "\t" + i);
}
Bytes[] signalIndex = new Bytes[this.signalOrdinalMap.size()];
for (Map.Entry<Bytes, Integer> m : this.signalOrdinalMap.entrySet()) {
signalIndex[m.getValue()] = m.getKey();
}
for (int i = Base.RTE_SIGNAL_BASE; i < signalIndex.length; i++) {
mapWriter.println("signal\t" + signalIndex[i] + "\t" + i);
}
Bytes[] effectorIndex = new Bytes[this.effectorOrdinalMap.size()];
for (Map.Entry<Bytes, Integer> m : this.effectorOrdinalMap.entrySet()) {
effectorIndex[m.getValue()] = m.getKey();
}
for (int i = 0; i < effectorIndex.length; i++) {
mapWriter.println("effector\t" + effectorIndex[i] + "\t" + i);
mapWriter.printf("%1$-32s%2$-6d%n", String.format("signal %1$s", signalIndex[i]), i);
}
Bytes[] fieldIndex = new Bytes[this.fieldOrdinalMap.size()];
for (Map.Entry<Bytes, Integer> m : this.fieldOrdinalMap.entrySet()) {
fieldIndex[m.getValue()] = m.getKey();
}
for (int i = 0; i < fieldIndex.length; i++) {
mapWriter.println("field\t" + fieldIndex[i] + "\t" + i);
mapWriter.printf("%1$-32s%2$-6d%n", String.format("field %1$s", fieldIndex[i]), i);
}
Bytes[] transducerIndex = new Bytes[this.transducerOrdinalMap.size()];
for (Map.Entry<Bytes, Integer> m : this.transducerOrdinalMap.entrySet()) {
transducerIndex[m.getValue()] = m.getKey();
}
for (int i = 0; i < (transducerIndex.length - 1); i++) {
mapWriter.printf("%1$-32s%2$-6d%n", String.format("transducer %1$s", transducerIndex[i]), i);
}
Bytes[] effectorIndex = new Bytes[this.effectorOrdinalMap.size()];
for (Map.Entry<Bytes, Integer> m : this.effectorOrdinalMap.entrySet()) {
effectorIndex[m.getValue()] = m.getKey();
}
for (int i = 0; i < effectorIndex.length; i++) {
mapWriter.printf("%1$-32s%2$-6d", String.format("effector %1$s", effectorIndex[i]), i);
if (this.proxyEffectors[i] instanceof IParameterizedEffector) {
BaseParameterizedEffector<?, ?> effector = (BaseParameterizedEffector<?, ?>) this.proxyEffectors[i];
mapWriter.printf("[ %1$s ]%n", effector.showParameterType(i));
for (int j = 0; j < effector.getParameterCount(); j++) {
mapWriter.printf("\t%1$s%n", effector.showParameterTokens(j));
}
} else {
mapWriter.println();
}
}
mapWriter.flush();
} catch (final IOException e) {
Expand Down Expand Up @@ -557,7 +566,7 @@ Map<Bytes,Integer> getFieldMap() {
public String showParameter(int effectorOrdinal, int parameterIndex) {
if (this.proxyEffectors[effectorOrdinal] instanceof IParameterizedEffector) {
IParameterizedEffector<?,?> effector = (IParameterizedEffector<?,?>)this.proxyEffectors[effectorOrdinal];
return effector.showParameter(parameterIndex);
return effector.showParameterTokens(parameterIndex);
}
return "VOID";
}
Expand Down
49 changes: 38 additions & 11 deletions src/com/characterforming/jrte/engine/Transductor.java
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,11 @@ public Integer compileParameter(final IToken[] parameterList) throws TargetBindi
token.toString(), IToken.TYPE_REFERENCE_SIGNAL));
}
}

@Override
public String showParameterType(int parameterIndex) {
return "Integer";
}
}

private final class InEffector extends BaseInputOutputEffector {
Expand Down Expand Up @@ -954,7 +959,7 @@ public int[][] allocateParameters(int parameterCount) {
return new int[parameterCount][];
}

@Override
@Override
public int invoke(final int parameterIndex) throws EffectorException {
assert (transducer == transducerStack.peek()) || (transducer == transducerStack.get(transducerStack.tos()-1));
System.arraycopy(super.getParameter(parameterIndex), 0, transducer.countdown, 0, 2);
Expand All @@ -972,22 +977,19 @@ public int[] compileParameter(final IToken[] parameterList) throws TargetBinding
super.getTarget().getName(), super.getName()));
}
int count = -1;
switch (parameterList[0].getType()) {
case FIELD:
if (parameterList[0].getType() == IToken.Type.FIELD) {
Bytes fieldName = new Bytes(parameterList[0].getSymbolName());
int fieldOrdinal = getFieldOrdinal(fieldName);
if (fieldOrdinal < 0) {
throw new TargetBindingException(String.format("%1$s.%2$s: Field %3$s not found",
super.getTarget().getName(), super.getName(), fieldName.toString()));
}
count = -1 - fieldOrdinal;
break;
case LITERAL:
} else if (parameterList[0].getType() == IToken.Type.LITERAL) {
byte[] value = parameterList[0].getLiteralValue();
count = Base.decodeInt(value, value.length);
break;
default:
value = parameterList[0].getLiteralValue();
} else {
byte[] value = parameterList[0].getLiteralValue();
throw new TargetBindingException(String.format("%1$s.%2$s: invalid field|counter '%3$%s' for count effector",
super.getTarget().getName(), super.getName(), Bytes.decode(super.getDecoder(), value, value.length)));
}
Expand All @@ -1001,6 +1003,11 @@ public int[] compileParameter(final IToken[] parameterList) throws TargetBinding
super.getTarget().getName(), super.getName(), Bytes.decode(super.getDecoder(), value, value.length)));
}
}

@Override
public String showParameterType(int parameterIndex) {
return "int[]";
}
}

private final class StartEffector extends BaseParameterizedEffector<Transductor, Integer> {
Expand Down Expand Up @@ -1042,6 +1049,11 @@ public int invoke(final int parameterIndex) throws EffectorException {
}
return IEffector.RTX_START;
}

@Override
public String showParameterType(int parameterIndex) {
return "Integer";
}
}

private final class PauseEffector extends BaseEffector<Transductor> {
Expand Down Expand Up @@ -1096,7 +1108,12 @@ public long[] compileParameter(final IToken[] parameterList) throws TargetBindin
}

@Override
public String showParameter(int parameterIndex) {
public String showParameterType(int parameterIndex) {
return "long[]";
}

@Override
public String showParameterTokens(int parameterIndex) {
long[] sum = super.getParameter(parameterIndex);
StringBuilder sb = new StringBuilder();
int endBit = 0, startBit = -1;
Expand Down Expand Up @@ -1176,7 +1193,12 @@ public int[] compileParameter(final IToken[] parameterList) throws TargetBinding
}

@Override
public String showParameter(int parameterIndex) {
public String showParameterType(int parameterIndex) {
return "int[]";
}

@Override
public String showParameterTokens(int parameterIndex) {
int[] product = super.getParameter(parameterIndex);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < product.length; j++) {
Expand Down Expand Up @@ -1224,7 +1246,12 @@ public Integer compileParameter(final IToken[] parameterList) throws TargetBindi
}

@Override
public String showParameter(int parameterIndex) {
public String showParameterType(int parameterIndex) {
return "Integer";
}

@Override
public String showParameterTokens(int parameterIndex) {
int scanbyte = super.getParameter(parameterIndex);
return 32 < scanbyte && 127 > scanbyte
? String.format(" %c", (char)scanbyte)
Expand Down
15 changes: 12 additions & 3 deletions src/com/characterforming/ribose/IParameterizedEffector.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,19 @@ public interface IParameterizedEffector<T extends ITarget, P> extends IEffector<
void setParameters(Object proxy);

/**
* Render a parameter object in a printable format, to support decompilation
* Return the type of object compiled from, to support decompilation
*
* @param parameterIndex the parameter index
* @return a printable string
* @return a printable string representing the effector's parameter object type
*/
String showParameter(int parameterIndex);
String showParameterType(int parameterIndex);

/**
* Render tokens for a parameter object in a printable format, to support
* decompilation
*
* @param parameterIndex the parameter index
* @return a printable string of space-delimited raw parameter tokens
*/
String showParameterTokens(int parameterIndex);
}
2 changes: 1 addition & 1 deletion src/com/characterforming/ribose/IToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum Type {
}

/**
* Get the type of the token
* Get the type of the token.
*
* @return the type of the token
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,32 @@ public void setParameters(Object proxy) {
}

@Override
public String showParameter(int parameterIndex) {
public String showParameterTokens(int parameterIndex) {
StringBuilder sb = new StringBuilder(256);
for (IToken token : getParameterTokens(parameterIndex)) {
if (sb.length() > 0)
sb.append(' ');
final byte[] name = token.getLiteralValue();
byte[] name = token.getLiteralValue();
sb.append(sb.length() > 0 ? " `" : "`");
sb.append(Bytes.decode(super.getDecoder(), name, name.length));
sb.append("`");
}
return sb.toString();
}

/**
* Get the number of parameters for this effector (after parameter compilation
* is complete)
*
* @return the parameter count
* @see #compileParameters(IToken[][])
*/
public int getParameterCount() {
return this.parameters != null ? this.parameters.length : 0;
}

/**
* Allocate and populate the {@code parameters} array with precompiled
* parameter ({@code P}) instances, compiled from a list of parameter
* token arrays. This method is for internal use only.
* token arrays. This method is for internal use only.
*
* @param parameterTokens an array of byte[][] (raw effector parameter tokens)
* @throws TargetBindingException if a parameter fails to compile
Expand Down

0 comments on commit a730338

Please sign in to comment.