summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/PromptFloat.java122
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java3
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateLexer.g41
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g422
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java64
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/instruction/PromptFloat.java81
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/meta/InstructionVisitor.java3
7 files changed, 296 insertions, 0 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;