| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | data/examples/blackjack/global.fate | 2 | ||||
| -rw-r--r-- | data/examples/blackjack/main.fate | 10 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/lang/Variable.java | 25 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 | 3 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/parser/FateParser.g4 | 59 | ||||
| -rw-r--r-- | src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java | 13 | 
6 files changed, 90 insertions, 22 deletions
| diff --git a/data/examples/blackjack/global.fate b/data/examples/blackjack/global.fate index 16574e6..c49642d 100644 --- a/data/examples/blackjack/global.fate +++ b/data/examples/blackjack/global.fate @@ -34,3 +34,5 @@        )     )  ) + +(declare_input_event escape) diff --git a/data/examples/blackjack/main.fate b/data/examples/blackjack/main.fate index 342a663..67b70b1 100644 --- a/data/examples/blackjack/main.fate +++ b/data/examples/blackjack/main.fate @@ -24,16 +24,18 @@ Just between you and me, someone left those laying around, they aren't mine.  Now, you're all set to go... unless you don't know how to play?  (player_choice -   (option -      ( As it happens, I do not. ) +   (option ( As it happens, I do not. )        (visit rules_of_blackjack)        (text_effect action_description           You leave the counter and approach one of the tables.        )        (visit play_a_game)     ) -   (option -      ( I am familiar with BlackJack. ) +   (event (escape) +      You suddenly disappear. +      (end) +   ) +   (option ( I am familiar with BlackJack. )        (text_effect action_description           You leave the counter and approach one of the tables.        ) diff --git a/src/core/src/tonkadur/fate/v1/lang/Variable.java b/src/core/src/tonkadur/fate/v1/lang/Variable.java index 3a8b761..bb72565 100644 --- a/src/core/src/tonkadur/fate/v1/lang/Variable.java +++ b/src/core/src/tonkadur/fate/v1/lang/Variable.java @@ -28,7 +28,8 @@ public class Variable extends DeclaredEntity               * Use of a space necessary to avoid conflicting with a user created               * type.               */ -            "undetermined variable" +            "undetermined variable", +            true           );     } @@ -48,6 +49,7 @@ public class Variable extends DeclaredEntity     /**** MEMBERS **************************************************************/     /***************************************************************************/     protected final Type type; +   protected final boolean is_external;     /***************************************************************************/     /**** PUBLIC ***************************************************************/ @@ -58,12 +60,14 @@ public class Variable extends DeclaredEntity     (        final Origin origin,        final Type type, -      final String name +      final String name, +      final boolean is_external     )     {        super(origin, name);        this.type = type; +      this.is_external = is_external;     }     /**** Accessors ************************************************************/ @@ -72,6 +76,11 @@ public class Variable extends DeclaredEntity        return type;     } +   public boolean is_external () +   { +      return is_external; +   } +     @Override     public DeclaredEntity generate_comparable_to (final DeclaredEntity de)     { @@ -87,7 +96,7 @@ public class Variable extends DeclaredEntity        new_type = (Type) type.generate_comparable_to(v.type); -      return new Variable(origin, new_type, name); +      return new Variable(origin, new_type, name, v.is_external());     }     /**** Misc. ****************************************************************/ @@ -100,7 +109,9 @@ public class Variable extends DeclaredEntity           v = (Variable) de; -         return !type.can_be_used_as(v.type); +         return +            !type.can_be_used_as(v.type) +            || (is_external() != v.is_external());        }        return true; @@ -115,6 +126,12 @@ public class Variable extends DeclaredEntity        sb.append(type.get_name());        sb.append(" Variable ");        sb.append(name); + +      if (is_external()) +      { +         sb.append(" (external)"); +      } +        sb.append(")");        return sb.toString(); diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index b1dbd75..29048d2 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -42,6 +42,7 @@ DECLARE_INPUT_EVENT_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'input'US'event  DECLARE_TEXT_EFFECT_KW: L_PAREN ('declare'|'define'|'def')US'text'US'effect' SEP+;  DECLARE_VARIABLE_KW: L_PAREN 'global' SEP+;  LOCAL_KW: L_PAREN 'local' SEP+; +EXTERNAL_KW: L_PAREN 'extern'('al'?) SEP+;  DEFAULT_KW: L_PAREN 'default' SEP+;  DEFINE_SEQUENCE_KW: L_PAREN ('declare'|'define'|'def')US(('seq'('uence')?)|('proc'('edure'?))) SEP+;  DIVIDE_KW: L_PAREN ('divide'|'/'|'div') SEP+; @@ -115,7 +116,7 @@ PUSH_RIGHT_KW: L_PAREN 'push'US'right' SEP+;  IMP_PUSH_RIGHT_KW: L_PAREN 'push'US'right!' SEP+;  PLAYER_CHOICE_KW: L_PAREN ('choice'|'user'US'choice'|'player'US'choice') SEP+;  PLAYER_OPTION_KW: L_PAREN ('option'|'user'US'option'|'player'US'option') SEP+; -PLAYER_EVENT_KW: L_PAREN ('event'|'user'US'event'|'player'US'event') SEP+; +PLAYER_EVENT_KW: L_PAREN ('user'US'event'|'player'US'event') SEP+;  PLUS_KW: L_PAREN ('plus'|'+') SEP+;  POWER_KW: L_PAREN ('power'|'^'|'**'|'pow') SEP+;  RANGE_KW: L_PAREN 'range' SEP+; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index 4859c85..d618513 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -187,7 +187,37 @@ first_level_fate_instr:           (              start_origin,              ($type.result), -            ($name.result) +            ($name.result), +            false +         ); + +      WORLD.variables().add(new_variable); +   } + +   | EXTERNAL_KW +      type +      WS+ +      name=new_reference_name +      WS* +   R_PAREN +   { +      final Origin start_origin, type_origin; +      final Variable new_variable; + +      start_origin = +         CONTEXT.get_origin_at +         ( +            ($EXTERNAL_KW.getLine()), +            ($EXTERNAL_KW.getCharPositionInLine()) +         ); + +      new_variable = +         new Variable +         ( +            start_origin, +            ($type.result), +            ($name.result), +            true           );        WORLD.variables().add(new_variable); @@ -551,7 +581,8 @@ returns [Instruction result]           (              start_origin,              ($type.result), -            ($name.result) +            ($name.result), +            false           );        variable_map = LOCAL_VARIABLES.peekFirst(); @@ -1511,7 +1542,8 @@ returns [Instruction result]                    ($FOR_EACH_KW.getCharPositionInLine())                 ),                 elem_type, -               ($new_reference_name.result) +               ($new_reference_name.result), +               false              );           variable_map = LOCAL_VARIABLES.peekFirst(); @@ -2027,7 +2059,7 @@ returns [Instruction result]           );     } -   | PLAYER_EVENT_KW +   | (EVENT_KW | PLAYER_EVENT_KW)        L_PAREN WS* WORD WS* R_PAREN WS+        {           HIERARCHICAL_VARIABLES.push(new ArrayList()); @@ -2048,8 +2080,8 @@ returns [Instruction result]        origin =           CONTEXT.get_origin_at           ( -            ($PLAYER_EVENT_KW.getLine()), -            ($PLAYER_EVENT_KW.getCharPositionInLine()) +            ($L_PAREN.getLine()), +            ($L_PAREN.getCharPositionInLine())           );        event = WORLD.input_events().get(origin, ($WORD.text)); @@ -2063,7 +2095,7 @@ returns [Instruction result]           );     } -   | PLAYER_EVENT_KW +   | (EVENT_KW | PLAYER_EVENT_KW)        L_PAREN WS* WORD WS+ value_list WS* R_PAREN WS+        {           HIERARCHICAL_VARIABLES.push(new ArrayList()); @@ -2084,8 +2116,8 @@ returns [Instruction result]        origin =           CONTEXT.get_origin_at           ( -            ($PLAYER_EVENT_KW.getLine()), -            ($PLAYER_EVENT_KW.getCharPositionInLine()) +            ($L_PAREN.getLine()), +            ($L_PAREN.getCharPositionInLine())           );        event = WORLD.input_events().get(origin, ($WORD.text)); @@ -2213,7 +2245,8 @@ returns [Instruction result]                    ($FOR_EACH_KW.getCharPositionInLine())                 ),                 elem_type, -               ($new_reference_name.result) +               ($new_reference_name.result), +               false              );           variable_map = LOCAL_VARIABLES.peekFirst(); @@ -2770,7 +2803,8 @@ returns [List<Cons<Variable, Computation>> result]                    ($L_PAREN.getCharPositionInLine())                 ),                 ($value.result).get_type(), -               var_name +               var_name, +               false              );           if (variables.containsKey(var_name)) @@ -2863,7 +2897,8 @@ returns [VariableList result]              (                 origin,                 next_type, -               ($new_reference_name.result) +               ($new_reference_name.result), +               false              )           );        } diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java index 79004b2..6319be6 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/Compiler.java @@ -90,8 +90,10 @@ public class Compiler     )     throws Throwable     { +      final List<Instruction> ignored_instr;        final List<Instruction> init_instr; +      ignored_instr = new ArrayList<Instruction>();        init_instr = new ArrayList<Instruction>();        for @@ -104,7 +106,16 @@ public class Compiler           final Register r;           t = TypeCompiler.compile(this, variable.get_type()); -         r = registers.register(t, variable.get_name(), init_instr); + +         if (variable.is_external()) +         { +            r = registers.register(t, variable.get_name(), ignored_instr); +         } +         else +         { +            r = registers.register(t, variable.get_name(), init_instr); +         } +           wyrd_world.add_register(r);        } | 


