| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
6 files changed, 162 insertions, 1 deletions
| diff --git a/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java b/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java new file mode 100644 index 0000000..8c48380 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/type/ExtraType.java @@ -0,0 +1,92 @@ +package tonkadur.fate.v1.lang.type; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.lang.meta.DeclaredEntity; + +public class ExtraType extends Type +{ +   /***************************************************************************/ +   /**** MEMBERS **************************************************************/ +   /***************************************************************************/ + +   /***************************************************************************/ +   /**** PUBLIC ***************************************************************/ +   /***************************************************************************/ + +   /**** Constructors *********************************************************/ +   public ExtraType +   ( +      final Origin origin, +      final String name +   ) +   { +      super(origin, null, name); +   } + +   public ExtraType +   ( +      final Origin origin, +      final ExtraType parent, +      final String name +   ) +   { +      super(origin, parent, name); +   } + +   /**** Accessors ************************************************************/ + +   /**** Compatibility ********************************************************/ +   @Override +   public boolean can_be_used_as (final Type t) +   { +      if (t instanceof ExtraType) +      { +         final ExtraType e; + +         e = (ExtraType) t; + +         return get_base_type().get_name().equals(e.get_base_type().get_name()); + +      } + +      return false; +   } + +   /* +    * This is for the very special case where a type is used despite not being +    * even a sub-type of the expected one. Using this rather expensive function, +    * the most restrictive shared type will be returned. If no such type exists, +    * the ANY time is returned. +    */ +   @Override +   public DeclaredEntity generate_comparable_to (final DeclaredEntity de) +   { +      return Type.ANY; +   } + +   @Override +   public Type get_act_as_type () +   { +      return get_base_type(); +   } + +   /**** Misc. ****************************************************************/ + +   @Override +   public Type generate_alias (final Origin origin, final String name) +   { +      return new ExtraType(origin, this, name); +   } + +   @Override +   public String toString () +   { +      final StringBuilder sb = new StringBuilder(); + +      sb.append("ExtraType::"); +      sb.append(name); + +      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 7accac5..9c1cdb7 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -41,6 +41,7 @@ DECLARE_DICT_TYPE_KW: L_PAREN     ('declare'|'define'|'def')US('dict'|('struct''ure'?))(US'type')? SEP+;  DECLARE_EXTRA_INSTRUCTION_KW: L_PAREN ('declare'|'define'|'def')US'extra'US'instruction' SEP+;  DECLARE_EXTRA_COMPUTATION_KW: L_PAREN ('declare'|'define'|'def')US'extra'US'computation' SEP+; +DECLARE_EXTRA_TYPE_KW: L_PAREN ('declare'|'define'|'def')US'extra'US'type' SEP+;  DECLARE_EVENT_TYPE_KW: L_PAREN ('declare'|'define'|'def')(US'input')?US'event'(US'type')? SEP+;  DECLARE_TEXT_EFFECT_KW: L_PAREN ('declare'|'define'|'def')US'text'US'effect' SEP+;  DECLARE_VARIABLE_KW: L_PAREN 'global' SEP+; @@ -126,7 +127,7 @@ PUSH_LEFT_KW: L_PAREN 'push'US'left' SEP+;  IMP_PUSH_LEFT_KW: L_PAREN 'push'US'left!' SEP+;  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_CHOICE_KW: L_PAREN ('choice'|'user'US'choice'|'player'US'choice')'!' SEP+;  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+;  PLUS_KW: L_PAREN ('plus'|'+') SEP+; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index 43b970c..1596104 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -357,6 +357,27 @@ first_level_fate_instr:        WORLD.types().add(new_type);     } +   | DECLARE_EXTRA_TYPE_KW new_reference_name WS* R_PAREN +   { +      final Origin start_origin; + +      start_origin = +         CONTEXT.get_origin_at +         ( +            ($DECLARE_EXTRA_TYPE_KW.getLine()), +            ($DECLARE_EXTRA_TYPE_KW.getCharPositionInLine()) +         ); + +      WORLD.types().add +      ( +         new ExtraType +         ( +            start_origin, +            ($new_reference_name.result) +         ) +      ); +   } +     | DECLARE_EXTRA_INSTRUCTION_KW new_reference_name WS* R_PAREN     {        final Origin start_origin; diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java index 572fa19..8dcd70d 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java @@ -73,6 +73,17 @@ public class TypeCompiler           return Type.INT;        } +      if (fate_type instanceof tonkadur.fate.v1.lang.type.ExtraType) +      { +         final ExtraType result; + +         result = new ExtraType(fate_type.get_base_type().get_name()); + +         compiler.world().add_extra_type(result); + +         return result; +      } +        fate_type = fate_type.get_base_type();        if (fate_type.equals(tonkadur.fate.v1.lang.type.Type.BOOL)) diff --git a/src/core/src/tonkadur/wyrd/v1/lang/World.java b/src/core/src/tonkadur/wyrd/v1/lang/World.java index cd4bf70..e1316c6 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/World.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/World.java @@ -11,6 +11,7 @@ import java.util.Set;  import tonkadur.wyrd.v1.lang.Register;  import tonkadur.wyrd.v1.lang.type.DictType; +import tonkadur.wyrd.v1.lang.type.ExtraType;  import tonkadur.wyrd.v1.lang.meta.Instruction; @@ -24,6 +25,7 @@ public class World     /* This solves the issue of using other yet undefined dict types. */     protected final List<DictType> dict_types_in_order; +   protected final Set<String> extra_types;     protected final List<Instruction> code; @@ -35,6 +37,7 @@ public class World        sequence_labels = new HashMap<String, Integer>();        dict_types = new HashMap<String, DictType>();        dict_types_in_order = new ArrayList<DictType>(); +      extra_types = new HashSet<String>();        code = new ArrayList<Instruction>();     } @@ -59,12 +62,22 @@ public class World        return dict_types_in_order;     } +   public Set<String> get_extra_types () +   { +      return extra_types; +   } +     public void add_dict_type (final DictType dict_type)     {        dict_types.put(dict_type.get_name(), dict_type);        dict_types_in_order.add(dict_type);     } +   public void add_extra_type (final ExtraType type) +   { +      extra_types.add(type.get_name()); +   } +     public Collection<Register> get_registers ()     {        return registers; diff --git a/src/core/src/tonkadur/wyrd/v1/lang/type/ExtraType.java b/src/core/src/tonkadur/wyrd/v1/lang/type/ExtraType.java new file mode 100644 index 0000000..58ce8b3 --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/lang/type/ExtraType.java @@ -0,0 +1,23 @@ +package tonkadur.wyrd.v1.lang.type; + +public class ExtraType extends Type +{ +   public ExtraType (final String name) +   { +      super(name); +   } + +   @Override +   public String toString () +   { +      final StringBuilder sb; + +      sb = new StringBuilder(); + +      sb.append("(ExtraType "); +      sb.append(name); +      sb.append(")"); + +      return sb.toString(); +   } +} | 


