| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2022-01-15 00:31:14 +0100 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2022-01-15 00:31:14 +0100 |
| commit | b748936e7ec1e39b664b6933c66912e77d570f99 (patch) | |
| tree | 19ec0388581b0fd8963e43ffa1bc1b9c00c2d4b1 | |
| parent | 48659c28bf6a6fbcff2c8e67247680afaa023de9 (diff) | |
Adds prompt_float instruction.
9 files changed, 345 insertions, 26 deletions
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/PromptFloat.java b/src/core/src/tonkadur/fate/v1/lang/instruction/PromptFloat.java new file mode 100644 index 0000000..d468931 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/instruction/PromptFloat.java @@ -0,0 +1,122 @@ +package tonkadur.fate.v1.lang.instruction; + +import tonkadur.parser.Origin; +import tonkadur.parser.ParsingError; + +import tonkadur.fate.v1.lang.type.Type; +import tonkadur.fate.v1.lang.type.PointerType; + +import tonkadur.fate.v1.lang.meta.InstructionVisitor; +import tonkadur.fate.v1.lang.meta.Instruction; +import tonkadur.fate.v1.lang.meta.Computation; +import tonkadur.fate.v1.lang.meta.RecurrentChecks; + +public class PromptFloat extends Instruction +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation target; + protected final Computation min; + protected final Computation max; + protected final Computation label; + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + protected PromptFloat + ( + final Origin origin, + final Computation target, + final Computation min, + final Computation max, + final Computation label + ) + { + super(origin); + + this.target = target; + this.min = min; + this.max = max; + this.label = label; + } + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public static PromptFloat build + ( + final Origin origin, + final Computation target, + final Computation min, + final Computation max, + final Computation label + ) + throws ParsingError + { + target.expect_non_string(); + min.expect_non_string(); + max.expect_non_string(); + label.expect_string(); + + RecurrentChecks.assert_can_be_used_as(min, Type.INT); + RecurrentChecks.assert_can_be_used_as(max, Type.INT); + RecurrentChecks.assert_can_be_used_as(label, Type.TEXT); + RecurrentChecks.assert_can_be_used_as + ( + target, + new PointerType(origin, Type.INT, "auto generated") + ); + + return new PromptFloat(origin, target, min, max, label); + } + + /**** Accessors ************************************************************/ + @Override + public void get_visited_by (final InstructionVisitor iv) + throws Throwable + { + iv.visit_prompt_float(this); + } + + public Computation get_target () + { + return target; + } + + public Computation get_max () + { + return max; + } + + public Computation get_min () + { + return min; + } + + public Computation get_label () + { + return label; + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(PromptFloat "); + sb.append(target.toString()); + sb.append(" "); + sb.append(min.toString()); + sb.append(" "); + sb.append(max.toString()); + sb.append(" "); + sb.append(label.toString()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java b/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java index 12188d2..32640fb 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java @@ -40,6 +40,9 @@ public interface InstructionVisitor public void visit_instruction_list (final InstructionList n) throws Throwable; + public void visit_prompt_float (final PromptFloat n) + throws Throwable; + public void visit_prompt_integer (final PromptInteger n) throws Throwable; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 4cb4774..63975bb 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -132,6 +132,7 @@ PLAYER_CHOICE_KW: TEXT_OPTION_KW: L_PAREN ('option'|'user'US'option'|'player'US'option') SEP+; EVENT_OPTION_KW: L_PAREN ('event'|'user'US'event'|'player'US'event') SEP+; PROMPT_STRING_KW: L_PAREN 'prompt'US'str''ing'?'!' SEP+; +PROMPT_FLOAT_KW: L_PAREN 'prompt'US'float!' SEP+; PROMPT_INTEGER_KW: L_PAREN 'prompt'US'int''eger'?'!' SEP+; PROMPT_COMMAND_KW: L_PAREN 'prompt'US('cmd'|'command')'!' SEP+; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index 52a661e..8d150e8 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -1174,6 +1174,28 @@ returns [Instruction result] ); } + | PROMPT_FLOAT_KW + targetv=computation[true] WS+ + min_size=computation[true] WS+ + max_size=computation[true] WS+ + paragraph WS* + R_PAREN + { + $result = + PromptFloat.build + ( + PARSER.get_origin_at + ( + ($PROMPT_FLOAT_KW.getLine()), + ($PROMPT_FLOAT_KW.getCharPositionInLine()) + ), + ($targetv.result), + ($min_size.result), + ($max_size.result), + ($paragraph.result) + ); + } + | PROMPT_INTEGER_KW targetv=computation[true] WS+ min_size=computation[true] WS+ diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java index 85d0927..77acc81 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java @@ -35,6 +35,7 @@ import tonkadur.wyrd.v1.lang.instruction.Display; import tonkadur.wyrd.v1.lang.instruction.End; import tonkadur.wyrd.v1.lang.instruction.Initialize; import tonkadur.wyrd.v1.lang.instruction.PromptCommand; +import tonkadur.wyrd.v1.lang.instruction.PromptFloat; import tonkadur.wyrd.v1.lang.instruction.PromptInteger; import tonkadur.wyrd.v1.lang.instruction.PromptString; import tonkadur.wyrd.v1.lang.instruction.Remove; @@ -1504,6 +1505,69 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor } @Override + public void visit_prompt_float + ( + final tonkadur.fate.v1.lang.instruction.PromptFloat n + ) + throws Throwable + { + /* + * Fate: (prompt_integer target min max label) + * Wyrd: (prompt_integer target min max label) + */ + final ComputationCompiler target_cc, min_cc, max_cc, label_cc; + + target_cc = new ComputationCompiler(compiler); + min_cc = new ComputationCompiler(compiler); + max_cc = new ComputationCompiler(compiler); + label_cc = new ComputationCompiler(compiler); + + n.get_target().get_visited_by(target_cc); + + if (target_cc.has_init()) + { + result.add(target_cc.get_init()); + } + + n.get_min().get_visited_by(min_cc); + + if (min_cc.has_init()) + { + result.add(min_cc.get_init()); + } + + n.get_max().get_visited_by(max_cc); + + if (max_cc.has_init()) + { + result.add(max_cc.get_init()); + } + + n.get_label().get_visited_by(label_cc); + + if (label_cc.has_init()) + { + result.add(label_cc.get_init()); + } + + result.add + ( + new PromptFloat + ( + target_cc.get_computation(), + min_cc.get_computation(), + max_cc.get_computation(), + label_cc.get_computation() + ) + ); + + target_cc.release_registers(result); + min_cc.release_registers(result); + max_cc.release_registers(result); + label_cc.release_registers(result); + } + + @Override public void visit_prompt_integer ( final tonkadur.fate.v1.lang.instruction.PromptInteger n diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/PromptFloat.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/PromptFloat.java new file mode 100644 index 0000000..a1c5ad5 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/PromptFloat.java @@ -0,0 +1,81 @@ +package tonkadur.wyrd.v1.lang.instruction; + +import tonkadur.wyrd.v1.lang.meta.Computation; +import tonkadur.wyrd.v1.lang.meta.Instruction; +import tonkadur.wyrd.v1.lang.meta.InstructionVisitor; + +public class PromptFloat extends Instruction +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Computation target; + protected final Computation min, max, label; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + /**** Constructors *********************************************************/ + public PromptFloat + ( + final Computation target, + final Computation min, + final Computation max, + final Computation label + ) + { + this.target = target; + this.min = min; + this.max = max; + this.label = label; + } + + /**** Accessors ************************************************************/ + public Computation get_target () + { + return target; + } + + public Computation get_min () + { + return min; + } + + public Computation get_max () + { + return max; + } + + public Computation get_label () + { + return label; + } + + @Override + public void get_visited_by (final InstructionVisitor iv) + throws Throwable + { + iv.visit_prompt_float(this); + } + + /**** Misc. ****************************************************************/ + @Override + public String toString () + { + final StringBuilder sb; + + sb = new StringBuilder(); + + sb.append("(PromptFloat "); + sb.append(target.toString()); + sb.append(" "); + sb.append(min.toString()); + sb.append(" "); + sb.append(max.toString()); + sb.append(" "); + sb.append(label.toString()); + sb.append(")"); + + return sb.toString(); + } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/meta/InstructionVisitor.java b/src/core/src/tonkadur/wyrd/v1/lang/meta/InstructionVisitor.java index 0338625..7da7253 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/meta/InstructionVisitor.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/meta/InstructionVisitor.java @@ -40,6 +40,9 @@ public interface InstructionVisitor public void visit_prompt_command (final PromptCommand n) throws Throwable; + public void visit_prompt_float (final PromptFloat n) + throws Throwable; + public void visit_prompt_integer (final PromptInteger n) throws Throwable; diff --git a/src/json-export/src/tonkadur/jsonexport/ComputationCompiler.java b/src/json-export/src/tonkadur/jsonexport/ComputationCompiler.java index 538fbde..e9146d7 100644 --- a/src/json-export/src/tonkadur/jsonexport/ComputationCompiler.java +++ b/src/json-export/src/tonkadur/jsonexport/ComputationCompiler.java @@ -45,9 +45,9 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "add_text_effect"); - result.put("effect", n.get_effect_name()); + result.put("name", n.get_effect_name()); result.put("parameters", params); - result.put("content", content); + result.put("values", content); } public void visit_cast (final Cast n) @@ -62,9 +62,9 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "cast"); - result.put("from", Translator.compile_type(n.get_parent().get_type())); - result.put("to", Translator.compile_type(n.get_type())); - result.put("content", cc.get_result()); + result.put("from", n.get_parent().get_type().get_name()); + result.put("to", n.get_type().get_name()); + result.put("value", cc.get_result()); } public void visit_constant (final Constant n) @@ -73,7 +73,7 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "constant"); - result.put("type", Translator.compile_type(n.get_type())); + result.put("type", n.get_type().get_name()); result.put("value", n.get_as_string()); } @@ -93,7 +93,7 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "if_else"); - result.put("type", Translator.compile_type(n.get_type())); + result.put("type", n.get_type().get_name()); result.put("condition", cond_cc.get_result()); result.put("if_true", if_true_cc.get_result()); result.put("if_false", if_false_cc.get_result()); @@ -105,7 +105,7 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "get_allocable_address"); - result.put("target", Translator.compile_type(n.get_target_type())); + result.put("type", n.get_target_type().get_name()); } public void visit_newline (final Newline n) @@ -137,7 +137,7 @@ public class ComputationCompiler implements ComputationVisitor result.put("category", "operation"); result.put("operator", n.get_operator()); - result.put("type", Translator.compile_type(n.get_type())); + result.put("type", n.get_type().get_name()); result.put("x", cc.get_result()); if (n.get_second_parameter() != null) @@ -162,8 +162,8 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "address"); - result.put("target_type", Translator.compile_type(n.get_type())); - result.put("address", cc.get_result()); + result.put("type", n.get_type().get_name()); + result.put("value_or_target", cc.get_result()); } public void visit_relative_address (final RelativeAddress n) @@ -180,8 +180,8 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "relative_address"); - result.put("type", Translator.compile_type(n.get_type())); - result.put("base", cc.get_result()); + result.put("type", n.get_type().get_name()); + result.put("target", cc.get_result()); result.put("extra", param_cc.get_result()); } @@ -206,7 +206,7 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "text"); - result.put("content", content); + result.put("values", content); } public void visit_size (final Size n) @@ -221,7 +221,7 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "size"); - result.put("reference", cc.get_result()); + result.put("value", cc.get_result()); } public void visit_extra_computation (final ExtraComputation n) @@ -261,8 +261,8 @@ public class ComputationCompiler implements ComputationVisitor result = new JSONObject(); result.put("category", "value_of"); - result.put("type", Translator.compile_type(n.get_type())); - result.put("reference", cc.get_result()); + result.put("type", n.get_type().get_name()); + result.put("target", cc.get_result()); } public JSONObject get_result () diff --git a/src/json-export/src/tonkadur/jsonexport/InstructionCompiler.java b/src/json-export/src/tonkadur/jsonexport/InstructionCompiler.java index 79cb4ea..39a07af 100644 --- a/src/json-export/src/tonkadur/jsonexport/InstructionCompiler.java +++ b/src/json-export/src/tonkadur/jsonexport/InstructionCompiler.java @@ -24,7 +24,7 @@ public class InstructionCompiler implements InstructionVisitor result = new JSONObject(); result.put("category", "add_text_option"); - result.put("label", label_cc.get_result()); + result.put("value", label_cc.get_result()); } public void visit_add_event_option (final AddEventOption n) @@ -48,7 +48,7 @@ public class InstructionCompiler implements InstructionVisitor result = new JSONObject(); result.put("category", "add_event_option"); - result.put("event", n.get_name()); + result.put("name", n.get_name()); result.put("parameters", params); } @@ -82,7 +82,7 @@ public class InstructionCompiler implements InstructionVisitor result = new JSONObject(); result.put("category", "display"); - result.put("content", cc.get_result()); + result.put("value", cc.get_result()); } public void visit_end (final End n) @@ -130,7 +130,7 @@ public class InstructionCompiler implements InstructionVisitor result = new JSONObject(); result.put("category", "remove"); - result.put("reference", cc.get_result()); + result.put("target", cc.get_result()); } public void visit_resolve_choice (final ResolveChoice n) @@ -191,7 +191,7 @@ public class InstructionCompiler implements InstructionVisitor result = new JSONObject(); result.put("category", "set_value"); - result.put("reference", ref_cc.get_result()); + result.put("target", ref_cc.get_result()); result.put("value", val_cc.get_result()); } @@ -207,7 +207,7 @@ public class InstructionCompiler implements InstructionVisitor result = new JSONObject(); result.put("category", "initialize"); - result.put("reference", ref_cc.get_result()); + result.put("target", ref_cc.get_result()); result.put("type", Translator.compile_type(n.get_type())); } @@ -232,9 +232,32 @@ public class InstructionCompiler implements InstructionVisitor result.put("target", target_cc.get_result()); result.put("min", min_cc.get_result()); result.put("max", max_cc.get_result()); - result.put("label", label_cc.get_result()); + result.put("message", label_cc.get_result()); } + public void visit_prompt_float (final PromptFloat n) + throws Throwable + { + final ComputationCompiler target_cc, min_cc, max_cc, label_cc; + + target_cc = new ComputationCompiler(); + min_cc = new ComputationCompiler(); + max_cc = new ComputationCompiler(); + label_cc = new ComputationCompiler(); + + n.get_target().get_visited_by(target_cc); + n.get_min().get_visited_by(min_cc); + n.get_max().get_visited_by(max_cc); + n.get_label().get_visited_by(label_cc); + + result = new JSONObject(); + + result.put("category", "prompt_float"); + result.put("target", target_cc.get_result()); + result.put("min", min_cc.get_result()); + result.put("max", max_cc.get_result()); + result.put("message", label_cc.get_result()); + } public void visit_prompt_integer (final PromptInteger n) throws Throwable @@ -257,7 +280,7 @@ public class InstructionCompiler implements InstructionVisitor result.put("target", target_cc.get_result()); result.put("min", min_cc.get_result()); result.put("max", max_cc.get_result()); - result.put("label", label_cc.get_result()); + result.put("message", label_cc.get_result()); } public void visit_prompt_string (final PromptString n) @@ -281,7 +304,7 @@ public class InstructionCompiler implements InstructionVisitor result.put("target", target_cc.get_result()); result.put("min", min_cc.get_result()); result.put("max", max_cc.get_result()); - result.put("label", label_cc.get_result()); + result.put("message", label_cc.get_result()); } public JSONObject get_result () |


