From a730338e954b21b3f93a842f76a24e62a5f99e76 Mon Sep 17 00:00:00 2001 From: jrte Date: Sun, 20 Aug 2023 07:41:17 -0300 Subject: [PATCH] Add effector parameters to model map - 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 --- TCompile.map | 89 +++++++++++-------- build.xml | 3 +- .../jrte/engine/BaseFieldEffector.java | 5 ++ .../jrte/engine/BaseInputOutputEffector.java | 7 +- .../characterforming/jrte/engine/Model.java | 43 +++++---- .../jrte/engine/Transductor.java | 49 +++++++--- .../ribose/IParameterizedEffector.java | 15 +++- src/com/characterforming/ribose/IToken.java | 2 +- .../base/BaseParameterizedEffector.java | 21 +++-- 9 files changed, 155 insertions(+), 79 deletions(-) diff --git a/TCompile.map b/TCompile.map index 1d6f5d4..6200f42 100755 --- a/TCompile.map +++ b/TCompile.map @@ -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 diff --git a/build.xml b/build.xml index 4607da3..ef57652 100755 --- a/build.xml +++ b/build.xml @@ -169,8 +169,7 @@ - diff --git a/src/com/characterforming/jrte/engine/BaseFieldEffector.java b/src/com/characterforming/jrte/engine/BaseFieldEffector.java index cbbb581..6d1379c 100644 --- a/src/com/characterforming/jrte/engine/BaseFieldEffector.java +++ b/src/com/characterforming/jrte/engine/BaseFieldEffector.java @@ -59,4 +59,9 @@ public Integer compileParameter(final IToken[] parameterList) throws TargetBindi } return parameterList[0].getSymbolOrdinal(); } + + @Override + public String showParameterType(int parameterIndex) { + return "Integer"; + } } diff --git a/src/com/characterforming/jrte/engine/BaseInputOutputEffector.java b/src/com/characterforming/jrte/engine/BaseInputOutputEffector.java index 767e5d6..2bc83c0 100644 --- a/src/com/characterforming/jrte/engine/BaseInputOutputEffector.java +++ b/src/com/characterforming/jrte/engine/BaseInputOutputEffector.java @@ -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", @@ -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[]"; + } } diff --git a/src/com/characterforming/jrte/engine/Model.java b/src/com/characterforming/jrte/engine/Model.java index af69455..1fc9f0e 100644 --- a/src/com/characterforming/jrte/engine/Model.java +++ b/src/com/characterforming/jrte/engine/Model.java @@ -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 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 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 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 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 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 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) { @@ -557,7 +566,7 @@ Map 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"; } diff --git a/src/com/characterforming/jrte/engine/Transductor.java b/src/com/characterforming/jrte/engine/Transductor.java index e5ef2b5..e0cb03b 100644 --- a/src/com/characterforming/jrte/engine/Transductor.java +++ b/src/com/characterforming/jrte/engine/Transductor.java @@ -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 { @@ -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); @@ -972,8 +977,7 @@ 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) { @@ -981,13 +985,11 @@ public int[] compileParameter(final IToken[] parameterList) throws TargetBinding 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))); } @@ -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 { @@ -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 { @@ -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; @@ -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++) { @@ -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) diff --git a/src/com/characterforming/ribose/IParameterizedEffector.java b/src/com/characterforming/ribose/IParameterizedEffector.java index 7bbe145..2f56422 100644 --- a/src/com/characterforming/ribose/IParameterizedEffector.java +++ b/src/com/characterforming/ribose/IParameterizedEffector.java @@ -119,10 +119,19 @@ public interface IParameterizedEffector 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); } diff --git a/src/com/characterforming/ribose/IToken.java b/src/com/characterforming/ribose/IToken.java index 26d8520..8d7addf 100644 --- a/src/com/characterforming/ribose/IToken.java +++ b/src/com/characterforming/ribose/IToken.java @@ -52,7 +52,7 @@ enum Type { } /** - * Get the type of the token + * Get the type of the token. * * @return the type of the token */ diff --git a/src/com/characterforming/ribose/base/BaseParameterizedEffector.java b/src/com/characterforming/ribose/base/BaseParameterizedEffector.java index d473ed0..1f92f76 100644 --- a/src/com/characterforming/ribose/base/BaseParameterizedEffector.java +++ b/src/com/characterforming/ribose/base/BaseParameterizedEffector.java @@ -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