| summaryrefslogtreecommitdiff |
diff options
16 files changed, 670 insertions, 133 deletions
diff --git a/data/examples/monster_battle/battle.fate b/data/examples/monster_battle/battle.fate index 1bc023a..3efd210 100644 --- a/data/examples/monster_battle/battle.fate +++ b/data/examples/monster_battle/battle.fate @@ -1,5 +1,5 @@ (fate_version 1) (define_sequence start_battle () - (end) + (end!) ) diff --git a/data/examples/monster_battle/in_your_room.fate b/data/examples/monster_battle/in_your_room.fate index 5ca456b..85411e1 100644 --- a/data/examples/monster_battle/in_your_room.fate +++ b/data/examples/monster_battle/in_your_room.fate @@ -10,8 +10,7 @@ (require battle.fate) (define_sequence in_your_room () - (ifelse - (is_member visited_your_room progress) + (if_else (is_member visited_your_room progress) (text_effect narrator You room is still a mess. You don't have time to clean things up, though. @@ -25,15 +24,15 @@ make the cut. ) ) - (add visited_your_room progress) - (player_choice - ( + (add! visited_your_room progress) + (player_choice! + (option ( Look for healing items ) - (jump_to look_for_healing_items) + (jump_to! look_for_healing_items) ) - ( + (option ( No time! Let's go adventuring! ) - (jump_to leave_your_room) + (jump_to! leave_your_room) ) ) ) @@ -44,7 +43,7 @@ of mess for healing items. (newline) ) - (ifelse + (if_else (=< (rand 0 99) 25) ( (text_effect surprise @@ -52,13 +51,13 @@ Oh! You found something! ) ) - (call get_item (ref (var potion))) + (call! get_item (ref (var potion))) ) (text_effect narrator No, you don't find anything. ) ) - (jump_to in_your_room) + (jump_to! in_your_room) ) (define_sequence leave_your_room () @@ -66,12 +65,12 @@ As you rush through the door of your room, you fail to notice the obstacle in your path and trip on something that was clearly meant for you. ) - (event pause) + (event! pause) (text_effect narrator It's a monster-holder! There's a note, too. ) - (set player.creature (eval random_creature)) - (event pause) + (set! player.creature (eval random_creature)) + (event! pause) (text_effect note_reading Hey sleepyhead. I couldn't wake you up for your big day, but lucky you, someone noticed that you weren't going to make it in time and got this for @@ -88,5 +87,5 @@ immediately get challenged by some grinning kid who clearly knew you haven't had time to train and wants to score an easy victory. ) - (jump_to start_battle) + (jump_to! start_battle) ) diff --git a/data/examples/monster_battle/include/creatures.fate b/data/examples/monster_battle/include/creatures.fate index 393473e..1cb8d1d 100644 --- a/data/examples/monster_battle/include/creatures.fate +++ b/data/examples/monster_battle/include/creatures.fate @@ -2,24 +2,12 @@ (require types/creature.fate) -(global creature monster_0) -(global creature monster_1) -(global creature monster_2) -(global creature monster_3) -(global creature monster_4) -(global creature monster_5) +(global (list creature) monster_templates) (global (lambda creature ()) random_creature) (set random_creature - (lambda () - (switch (rand 0 5) - (0 (var monster_0)) - (1 (var monster_0)) - (2 (var monster_0)) - (3 (var monster_0)) - (4 (var monster_0)) - (var monster_5) - ) - ) + (lambda () (access (rand 0 (size monster_templates)) monster_templates)) ) + +( diff --git a/data/examples/monster_battle/main.fate b/data/examples/monster_battle/main.fate index a10fd48..89988ae 100644 --- a/data/examples/monster_battle/main.fate +++ b/data/examples/monster_battle/main.fate @@ -10,16 +10,16 @@ Today was supposed to be glorious! At long last, you were going on your life-defining adventure with a powerful companion. ) -(event pause) +(event! pause) (text_effect narrator ... ) -(event pause) +(event! pause) (text_effect narrator Maybe you should stop daydreaming and see what can be salvaged at this point. ) -(event pause) +(event! pause) (text_effect narrator You stand in your room, having just dressed. ) -(jump_to in_your_room) +(jump_to! in_your_room) diff --git a/data/unit-testing/allocate_and_free.fate b/data/unit-testing/allocate_and_free.fate index cf05414..8998236 100644 --- a/data/unit-testing/allocate_and_free.fate +++ b/data/unit-testing/allocate_and_free.fate @@ -1,8 +1,10 @@ (fate_version 1) (local (ptr int) p0) +(local (list (ptr int)) lp0) (allocate! p0) + (set! (at p0) 72) (assert! (= (at p0) 72) @@ -11,6 +13,15 @@ (free! (at p0)) +(add! (default (ptr int)) lp0) +(add! (default (ptr int)) lp0) +(add! (default (ptr int)) lp0) +(add! (default (ptr int)) lp0) + +(allocate! lp0.0) +(allocate! (at (access_pointer 1 lp0))) +(allocate! (access_pointer 1 lp0))) + [COMPLETED] (end!) diff --git a/src/core/src/tonkadur/fate/v1/error/UnknownDictionaryFieldException.java b/src/core/src/tonkadur/fate/v1/error/UnknownStructureFieldException.java index f5e67f2..7c02bc2 100644 --- a/src/core/src/tonkadur/fate/v1/error/UnknownDictionaryFieldException.java +++ b/src/core/src/tonkadur/fate/v1/error/UnknownStructureFieldException.java @@ -7,25 +7,25 @@ import tonkadur.error.ErrorLevel; import tonkadur.parser.Origin; import tonkadur.parser.ParsingError; -import tonkadur.fate.v1.lang.type.DictType; +import tonkadur.fate.v1.lang.type.StructType; import tonkadur.fate.v1.lang.type.Type; -public class UnknownDictionaryFieldException extends ParsingError +public class UnknownStructureFieldException extends ParsingError { /***************************************************************************/ /**** MEMBERS **************************************************************/ /***************************************************************************/ protected final String field_name; - protected final DictType dict; + protected final StructType dict; /***************************************************************************/ /**** PUBLIC ***************************************************************/ /***************************************************************************/ - public UnknownDictionaryFieldException + public UnknownStructureFieldException ( final Origin origin, final String field_name, - final DictType dict + final StructType dict ) { super(ErrorLevel.ERROR, ErrorCategory.INVALID_USE, origin); diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/AtReference.java b/src/core/src/tonkadur/fate/v1/lang/computation/AtReference.java index d61dbed..7e68f11 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/AtReference.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/AtReference.java @@ -7,7 +7,7 @@ import tonkadur.parser.Origin; import tonkadur.error.ErrorManager; import tonkadur.fate.v1.error.InvalidTypeException; -import tonkadur.fate.v1.error.UnknownDictionaryFieldException; +import tonkadur.fate.v1.error.UnknownStructureFieldException; import tonkadur.fate.v1.lang.Variable; diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/FieldAccess.java b/src/core/src/tonkadur/fate/v1/lang/computation/FieldAccess.java index bc0d6b5..3c4279d 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/FieldAccess.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/FieldAccess.java @@ -8,13 +8,13 @@ import tonkadur.parser.Origin; import tonkadur.error.ErrorManager; import tonkadur.fate.v1.error.InvalidTypeException; -import tonkadur.fate.v1.error.UnknownDictionaryFieldException; +import tonkadur.fate.v1.error.UnknownStructureFieldException; import tonkadur.fate.v1.lang.meta.ComputationVisitor; import tonkadur.fate.v1.lang.meta.Reference; import tonkadur.fate.v1.lang.meta.Computation; -import tonkadur.fate.v1.lang.type.DictType; +import tonkadur.fate.v1.lang.type.StructType; import tonkadur.fate.v1.lang.type.Type; public class FieldAccess extends Computation @@ -55,7 +55,7 @@ public class FieldAccess extends Computation ) throws InvalidTypeException, - UnknownDictionaryFieldException + UnknownStructureFieldException { Type current_type; @@ -67,7 +67,7 @@ public class FieldAccess extends Computation current_type = parent.get_type(); } - if (!(current_type instanceof DictType)) + if (!(current_type instanceof StructType)) { ErrorManager.handle ( @@ -84,7 +84,7 @@ public class FieldAccess extends Computation } else { - current_type = ((DictType) current_type).get_field_type(origin, field); + current_type = ((StructType) current_type).get_field_type(origin, field); } return new FieldAccess(origin, parent, current_type, field); @@ -98,7 +98,7 @@ public class FieldAccess extends Computation ) throws InvalidTypeException, - UnknownDictionaryFieldException + UnknownStructureFieldException { for (final String field: field_sequence) { diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java b/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java index 942077c..1c9a592 100644 --- a/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java +++ b/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java @@ -8,13 +8,13 @@ import tonkadur.parser.Origin; import tonkadur.error.ErrorManager; import tonkadur.fate.v1.error.InvalidTypeException; -import tonkadur.fate.v1.error.UnknownDictionaryFieldException; +import tonkadur.fate.v1.error.UnknownStructureFieldException; import tonkadur.fate.v1.lang.meta.ComputationVisitor; import tonkadur.fate.v1.lang.meta.Reference; import tonkadur.fate.v1.lang.meta.Computation; -import tonkadur.fate.v1.lang.type.DictType; +import tonkadur.fate.v1.lang.type.StructType; import tonkadur.fate.v1.lang.type.Type; public class FieldReference extends Reference @@ -55,7 +55,7 @@ public class FieldReference extends Reference ) throws InvalidTypeException, - UnknownDictionaryFieldException + UnknownStructureFieldException { Type current_type; @@ -67,7 +67,7 @@ public class FieldReference extends Reference current_type = parent.get_type(); } - if (!(current_type instanceof DictType)) + if (!(current_type instanceof StructType)) { ErrorManager.handle ( @@ -84,7 +84,7 @@ public class FieldReference extends Reference } else { - current_type = ((DictType) current_type).get_field_type(origin, field); + current_type = ((StructType) current_type).get_field_type(origin, field); } return new FieldReference(origin, parent, current_type, field); @@ -98,7 +98,7 @@ public class FieldReference extends Reference ) throws InvalidTypeException, - UnknownDictionaryFieldException + UnknownStructureFieldException { for (final String field: field_sequence) { diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java b/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java index 522ad9b..97a7777 100644 --- a/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java +++ b/src/core/src/tonkadur/fate/v1/lang/meta/VariableFromWord.java @@ -20,7 +20,7 @@ import tonkadur.fate.v1.lang.computation.VariableReference; import tonkadur.fate.v1.lang.type.CollectionType; import tonkadur.fate.v1.lang.type.PointerType; -import tonkadur.fate.v1.lang.type.DictType; +import tonkadur.fate.v1.lang.type.StructType; import tonkadur.fate.v1.lang.type.Type; public class VariableFromWord @@ -81,7 +81,7 @@ public class VariableFromWord Constant.build(origin, subref) ); } - else if (t instanceof DictType) + else if (t instanceof StructType) { result = FieldReference.build diff --git a/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java b/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java new file mode 100644 index 0000000..a1f6041 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/lang/type/DictionaryType.java @@ -0,0 +1,152 @@ +package tonkadur.fate.v1.lang.type; + +import tonkadur.error.ErrorManager; +import tonkadur.parser.ParsingError; + +import tonkadur.parser.Origin; + +import tonkadur.fate.v1.error.InvalidTypeException; + +import tonkadur.fate.v1.lang.meta.DeclaredEntity; + +public class DictionaryType extends Type +{ + /***************************************************************************/ + /**** MEMBERS **************************************************************/ + /***************************************************************************/ + protected final Type key_type; + protected final Type value_type; + + /***************************************************************************/ + /**** PUBLIC ***************************************************************/ + /***************************************************************************/ + + /**** Constructors *********************************************************/ + public static DictionaryType build + ( + final Origin origin, + final Type key_type, + final Type value_type, + final String name + ) + throws InvalidTypeException + { + if (!Type.COMPARABLE_TYPES.contains(key_type.get_act_as_type())) + { + ErrorManager.handle + ( + new InvalidTypeException(origin, key_type, Type.COMPARABLE_TYPES) + ); + } + + return new DictionaryType(origin, key_type, value_type, name); + } + + + /**** Accessors ************************************************************/ + public Type get_key_type () + { + return key_type; + } + + public Type get_value_type () + { + return value_type; + } + + @Override + public Type get_act_as_type () + { + return Type.DICT; + } + + /**** Compatibility ********************************************************/ + @Override + public boolean can_be_used_as (final Type t) + { + if (t instanceof DictionaryType) + { + final DictionaryType ct; + + ct = (DictionaryType) t; + + return + ( + key_type.can_be_used_as(ct.key_type) + && value_type.can_be_used_as(ct.value_type) + ); + } + + 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) + { + final DictionaryType ct; + + if (!(de instanceof DictionaryType)) + { + return Type.ANY; + } + + ct = (DictionaryType) de; + + return + new DictionaryType + ( + get_origin(), + ((Type) key_type.generate_comparable_to(ct.key_type)), + ((Type) value_type.generate_comparable_to(ct.value_type)), + name + ); + } + + + /**** Misc. ****************************************************************/ + @Override + public Type generate_alias (final Origin origin, final String name) + { + return new DictionaryType(origin, key_type, value_type, name); + } + + @Override + public String toString () + { + final StringBuilder sb = new StringBuilder(); + + sb.append("(Dict "); + sb.append(key_type.toString()); + sb.append(" "); + sb.append(value_type.toString()); + sb.append(")::"); + sb.append(name); + + return sb.toString(); + } + + /***************************************************************************/ + /**** PROTECTED ************************************************************/ + /***************************************************************************/ + + /**** Constructors *********************************************************/ + protected DictionaryType + ( + final Origin origin, + final Type key_type, + final Type value_type, + final String name + ) + { + super(origin, null, name); + + this.key_type = key_type; + this.value_type = value_type; + } +} diff --git a/src/core/src/tonkadur/fate/v1/lang/type/DictType.java b/src/core/src/tonkadur/fate/v1/lang/type/StructType.java index d3ce314..c44e7f4 100644 --- a/src/core/src/tonkadur/fate/v1/lang/type/DictType.java +++ b/src/core/src/tonkadur/fate/v1/lang/type/StructType.java @@ -9,11 +9,11 @@ import tonkadur.parser.Origin; import tonkadur.error.ErrorManager; -import tonkadur.fate.v1.error.UnknownDictionaryFieldException; +import tonkadur.fate.v1.error.UnknownStructureFieldException; import tonkadur.fate.v1.lang.meta.DeclaredEntity; -public class DictType extends Type +public class StructType extends Type { /***************************************************************************/ /**** MEMBERS **************************************************************/ @@ -25,7 +25,7 @@ public class DictType extends Type /***************************************************************************/ /**** Constructors *********************************************************/ - public DictType + public StructType ( final Origin origin, final Map<String, Type> field_types, @@ -39,7 +39,7 @@ public class DictType extends Type /**** Accessors ************************************************************/ public Type get_field_type (final Origin call_origin, final String t) - throws UnknownDictionaryFieldException + throws UnknownStructureFieldException { final Type result; @@ -49,7 +49,7 @@ public class DictType extends Type { ErrorManager.handle ( - new UnknownDictionaryFieldException(call_origin, t, this) + new UnknownStructureFieldException(call_origin, t, this) ); return Type.ANY; @@ -67,11 +67,11 @@ public class DictType extends Type @Override public boolean can_be_used_as (final Type t) { - if (t instanceof DictType) + if (t instanceof StructType) { - final DictType dt; + final StructType dt; - dt = (DictType) t; + dt = (StructType) t; for (final Map.Entry<String, Type> own_field: get_fields()) { @@ -107,14 +107,14 @@ public class DictType extends Type { final Map<String, Type> result_field_types; final Set<String> result_field_names; - final DictType dt; + final StructType dt; - if (!(de instanceof DictType)) + if (!(de instanceof StructType)) { return Type.ANY; } - dt = (DictType) de; + dt = (StructType) de; result_field_names = new HashSet<String>(); result_field_types = new HashMap<String, Type>(); @@ -148,7 +148,7 @@ public class DictType extends Type result_field_types.put(field_name, result_field_type); } - return new DictType(get_origin(), result_field_types, name); + return new StructType(get_origin(), result_field_types, name); } @Override @@ -161,7 +161,7 @@ public class DictType extends Type @Override public Type generate_alias (final Origin origin, final String name) { - return new DictType(origin, field_types, name); + return new StructType(origin, field_types, name); } @Override @@ -169,7 +169,7 @@ public class DictType extends Type { final StringBuilder sb = new StringBuilder(); - sb.append("(Dict "); + sb.append("(Struct "); for (final Map.Entry<String, Type> field: get_fields()) { diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 index 9c1cdb7..9d822a7 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 @@ -16,6 +16,7 @@ R_PAREN: ')'; ABS_KW: L_PAREN 'abs'('olute'?) SEP+; +DICT_KW: L_PAREN 'dict'('ionary'?) SEP+; ACCESS_KW: L_PAREN 'access' SEP+; ACCESS_POINTER_KW: L_PAREN 'access'US('ptr'|'pointer') SEP+; ADD_KW: L_PAREN 'add'(US'element')? SEP+; @@ -37,8 +38,8 @@ CONS_KW: L_PAREN 'cons' SEP+; COUNT_KW: L_PAREN 'count' SEP+; DECLARE_ALIAS_TYPE_KW: L_PAREN ((('declare'|'define'|'def')US(('sub'|'alias')US)?'type')|'typedef') SEP+; -DECLARE_DICT_TYPE_KW: L_PAREN - ('declare'|'define'|'def')US('dict'|('struct''ure'?))(US'type')? SEP+; +DECLARE_STRUCT_TYPE_KW: L_PAREN + ('declare'|'define'|'def')US('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+; @@ -50,6 +51,44 @@ 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+; +DICT_TO_LIST_KW: + L_PAREN + (('dict'('ionary'?)US'to'US'list')|('list'US'from'US'dict'('ionary'?))) + SEP+; +DICT_FROM_LIST_KW: + L_PAREN + (('dict'('ionary'?)US'from'US'list')|('list'US'to'US'dict'('ionary'?))) + SEP+; +DICT_KEYS_KW: L_PAREN (('get'US)?'dict'('ionary'?)US'keys') SEP+; +DICT_VALUES_KW: L_PAREN (('get'US)?'dict'('ionary'?)US'values') SEP+; +DICT_MERGE_KW: L_PAREN ('dict'('ionary'?)US'merge') SEP+; +DICT_MAP_KW: L_PAREN ('dict'('ionary'?)US'map') SEP+; +DICT_FILTER_KW: L_PAREN ('dict'('ionary'?)US'filter') SEP+; +DICT_SET_KW: L_PAREN ('dict'('ionary'?)US'set') SEP+; +DICT_REMOVE_KW: L_PAREN ('dict'('ionary'?)US'remove') SEP+; +DICT_HAS_KW: L_PAREN ('dict'('ionary'?)US'has') SEP+; +DICT_GET_KW: L_PAREN ('dict'('ionary'?)US'get') SEP+; +DICT_GET_POINTER_KW: L_PAREN ('dict'('ionary'?)US'get'US('ptr'|'pointer')) SEP+; + +IMP_DICT_TO_LIST_KW: + L_PAREN + (('dict'('ionary'?)US'to'US'list')|('list'US'from'US'dict'('ionary'?)))'!' + SEP+; +IMP_DICT_FROM_LIST_KW: + L_PAREN + (('dict'('ionary'?)US'from'US'list')|('list'US'to'US'dict'('ionary'?)))'!' + SEP+; +IMP_DICT_KEYS_KW: L_PAREN (('get'US)?'dict'('ionary'?)US'keys')'!' SEP+; +IMP_DICT_VALUES_KW: L_PAREN (('get'US)?'dict'('ionary'?)US'values')'!' SEP+; +IMP_DICT_MERGE_KW: L_PAREN ('dict'('ionary'?)US'merge')'!' SEP+; +IMP_DICT_MAP_KW: L_PAREN ('dict'('ionary'?)US'map')'!' SEP+; +IMP_DICT_FILTER_KW: L_PAREN ('dict'('ionary'?)US'filter')'!' SEP+; +IMP_DICT_SET_KW: L_PAREN ('dict'('ionary'?)US'set')'!' SEP+; +IMP_DICT_REMOVE_KW: L_PAREN ('dict'('ionary'?)US'remove')'!' SEP+; +IMP_DICT_HAS_KW: L_PAREN ('dict'('ionary'?)US'has')'!' SEP+; +IMP_DICT_GET_KW: L_PAREN ('dict'('ionary'?)US'get')'!' SEP+; +IMP_DICT_GET_POINTER_KW: + L_PAREN ('dict'('ionary'?)US'get'US('ptr'|'pointer'))'!' SEP+; DO_WHILE_KW: L_PAREN ('do'US'while') SEP+; ENABLE_TEXT_EFFECT_KW: L_PAREN 'text'US'effect' SEP+; END_KW: L_PAREN 'end'('!'?) SEP* R_PAREN; diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 index 1596104..a467b2d 100644 --- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 +++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 @@ -57,29 +57,34 @@ options /******************************************************************************/ /******************************************************************************/ /******************************************************************************/ -fate_file [Context context, Deque<Map<String, Variable>> local_variables, World world] - @init - { - CONTEXT = context; - WORLD = world; +fate_file +[ + Context context, + Deque<Map<String, Variable>> local_variables, + World world +] +@init +{ + CONTEXT = context; + WORLD = world; - if (local_variables == null) - { - LOCAL_VARIABLES = new ArrayDeque<Map<String, Variable>>(); - LOCAL_VARIABLES.push(new HashMap<String, Variable>()); - } - else - { - LOCAL_VARIABLES = local_variables; - } + if (local_variables == null) + { + LOCAL_VARIABLES = new ArrayDeque<Map<String, Variable>>(); + LOCAL_VARIABLES.push(new HashMap<String, Variable>()); + } + else + { + LOCAL_VARIABLES = local_variables; + } - HIERARCHICAL_VARIABLES = new ArrayDeque<List<String>>(); - BREAKABLE_LEVELS = 0; + HIERARCHICAL_VARIABLES = new ArrayDeque<List<String>>(); + BREAKABLE_LEVELS = 0; - HIERARCHICAL_VARIABLES.push(new ArrayList<String>()); - CHOICE_LIMITED_VARIABLES = new ArrayDeque<Collection<String>>(); - } - : + HIERARCHICAL_VARIABLES.push(new ArrayList<String>()); + CHOICE_LIMITED_VARIABLES = new ArrayDeque<Collection<String>>(); +} +: WS* FATE_VERSION_KW WORD WS* R_PAREN WS* ( ( @@ -118,24 +123,24 @@ returns [List<Instruction> result] first_level_fate_instr: DEFINE_SEQUENCE_KW - new_reference_name - WS* - ( - L_PAREN WS* variable_list WS* R_PAREN - { - final Map<String, Variable> variable_map; + new_reference_name + WS* + ( + L_PAREN WS* variable_list WS* R_PAREN + { + final Map<String, Variable> variable_map; - variable_map = new HashMap<String, Variable>(); + variable_map = new HashMap<String, Variable>(); - variable_map.putAll(($variable_list.result).as_map()); + variable_map.putAll(($variable_list.result).as_map()); - LOCAL_VARIABLES.push(variable_map); - } - ) - pre_sequence_point=WS+ - general_fate_sequence - WS* - R_PAREN + LOCAL_VARIABLES.push(variable_map); + } + ) + pre_sequence_point=WS+ + general_fate_sequence + WS* + R_PAREN { final Origin start_origin, sequence_origin; final Sequence new_sequence; @@ -172,11 +177,11 @@ first_level_fate_instr: } | DECLARE_VARIABLE_KW - type - WS+ - name=new_reference_name - WS* - R_PAREN + type + WS+ + name=new_reference_name + WS* + R_PAREN { final Origin start_origin, type_origin; final Variable new_variable; @@ -201,11 +206,11 @@ first_level_fate_instr: } | EXTERNAL_KW - type - WS+ - name=new_reference_name - WS* - R_PAREN + type + WS+ + name=new_reference_name + WS* + R_PAREN { final Origin start_origin, type_origin; final Variable new_variable; @@ -229,17 +234,17 @@ first_level_fate_instr: WORLD.variables().add(new_variable); } - | IGNORE_ERROR_KW WORD WS+ first_level_fate_instr WS* R_PAREN + | IMP_IGNORE_ERROR_KW WORD WS+ first_level_fate_instr WS* R_PAREN { /* TODO: temporarily disable an compiler error category */ } | DECLARE_TEXT_EFFECT_KW - new_reference_name - WS+ - params=type_list - WS* - R_PAREN + new_reference_name + WS+ + params=type_list + WS* + R_PAREN { final Origin start_origin; final TextEffect new_text_effect; @@ -317,7 +322,7 @@ first_level_fate_instr: WORLD.types().add(new_type); } - | DECLARE_DICT_TYPE_KW + | DECLARE_STRUCT_TYPE_KW new_reference_name WS* variable_list @@ -342,12 +347,12 @@ first_level_fate_instr: start_origin = CONTEXT.get_origin_at ( - ($DECLARE_DICT_TYPE_KW.getLine()), - ($DECLARE_DICT_TYPE_KW.getCharPositionInLine()) + ($DECLARE_STRUCT_TYPE_KW.getLine()), + ($DECLARE_STRUCT_TYPE_KW.getCharPositionInLine()) ); new_type = - new DictType + new StructType ( start_origin, field_types, @@ -732,13 +737,30 @@ returns [Instruction result] ); } + | IMP_DICT_SET_KW key=value WS+ val=value WS+ value_reference WS* R_PAREN + { + // TODO + $result = null; + /* + SetEntry.build + ( + CONTEXT.get_origin_at + ( + ($IMP_DICT_SET_KW.getLine()), + ($IMP_DICT_SET_KW.getCharPositionInLine()) + ), + ($key.result), + ($val.result) + ); + */ + } + | IMP_ADD_KW value_list WS+ value_reference WS* R_PAREN { final List<Instruction> add_instrs; add_instrs = new ArrayList<Instruction>(); - for (final Computation value: ($value_list.result)) { add_instrs.add @@ -838,6 +860,27 @@ returns [Instruction result] $result = ($general_fate_instr.result); } + | IMP_DICT_REMOVE_KW + value WS+ + value_reference WS* + R_PAREN + { + // TODO + $result = null; + /* + RemoveEntry.build + ( + CONTEXT.get_origin_at + ( + ($IMP_DICT_REMOVE_KW.getLine()), + ($IMP_DICT_REMOVE_KW.getCharPositionInLine()) + ), + ($value.result), + ($value_reference.result) + ); + */ + } + | IMP_REMOVE_ONE_KW value WS+ value_reference WS* @@ -1000,6 +1043,26 @@ returns [Instruction result] ); } + | IMP_DICT_MAP_KW non_text_value WS+ value_reference WS* R_PAREN + { + // TODO + $result = null; + /* + DictMap.build + ( + CONTEXT.get_origin_at + ( + ($IMP_DICT_MAP_KW.getLine()), + ($IMP_DICT_MAP_KW.getCharPositionInLine()) + ), + ($non_text_value.result), + ($value_reference.result), + new ArrayList() + ); + */ + } + + | IMP_MAP_KW non_text_value WS+ value_reference WS+ value_list WS* R_PAREN { $result = @@ -1052,6 +1115,55 @@ returns [Instruction result] ); } + | IMP_DICT_MERGE_KW + fun=non_text_value WS+ + inv1=non_text_value WS+ + value_reference WS* + R_PAREN + { + // TODO + $result = null; + /* + DictMerge.build + ( + CONTEXT.get_origin_at + ( + ($IMP_DICT_MERGE_KW.getLine()), + ($IMP_DICT_MERGE_KW.getCharPositionInLine()) + ), + ($fun.result), + ($inv1.result), + ($value_reference.result), + new ArrayList() + ); + */ + } + + | IMP_DICT_MERGE_KW + fun=non_text_value WS+ + inv1=non_text_value WS+ + value_reference WS+ + value_list WS* + R_PAREN + { + // TODO + $result = null; + /* + DictMerge.build + ( + CONTEXT.get_origin_at + ( + ($IMP_DICT_MERGE_KW.getLine()), + ($IMP_DICT_MERGE_KW.getCharPositionInLine()) + ), + ($fun.result), + ($inv1.result), + ($value_reference.result), + ($value_list.result) + ); + */ + } + | IMP_MERGE_KW fun=non_text_value WS+ inv1=non_text_value WS+ @@ -2107,6 +2219,119 @@ returns [Instruction result] CHOICE_LIMITED_VARIABLES.pop(); } + | IMP_DICT_TO_LIST_KW non_text_value WS+ value_reference WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_FROM_LIST_KW non_text_value WS+ value_reference WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_KEYS_KW non_text_value WS+ value_reference WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_VALUES_KW non_text_value WS+ value_reference WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_MERGE_KW + dict0r=value_reference WS+ + dict1=non_text_value WS+ + fun=non_text_value WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_MERGE_KW + dict0r=value_reference WS+ + dict1=non_text_value WS+ + fun=non_text_value WS+ + value_list WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_FILTER_KW + dict0r=value_reference WS+ + fun=non_text_value WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_FILTER_KW + dict0r=value_reference WS+ + fun=non_text_value WS+ + value_list WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_SET_KW + key=value WS+ + val=value WS+ + dict0r=value_reference WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_REMOVE_KW key=value WS+ dict0r=value_reference WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | IMP_DICT_HAS_KW + key=value WS+ + dict0=non_text_value WS+ + value_reference WS* + R_PAREN + { + + /* TODO */ + $result = null; + } + + | IMP_DICT_GET_KW + key=value WS+ + dict0=non_text_value WS+ + value_reference WS* + R_PAREN + { + + /* TODO */ + $result = null; + } + + | IMP_DICT_GET_POINTER_KW + key=value WS+ + dict0=non_text_value WS+ + value_reference WS* + R_PAREN + { + + /* TODO */ + $result = null; + } + | paragraph { $result = @@ -2970,6 +3195,33 @@ returns [Type result] ); } + | DICT_KW key_type=type WS+ val_type=type WS* R_PAREN + { + final Origin start_origin; + + start_origin = + CONTEXT.get_origin_at + ( + ($DICT_KW.getLine()), + ($DICT_KW.getCharPositionInLine()) + ); + + $result = + DictionaryType.build + ( + start_origin, + ($key_type.result), + ($val_type.result), + ( + "anonymous (" + + ($key_type.result) + + " " + + $val_type.result + + ") dictionary type" + ) + ); + } + | SET_KW type WS* R_PAREN { final Origin start_origin; @@ -5452,6 +5704,102 @@ returns [Computation result] ); } + | DICT_TO_LIST_KW non_text_value WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_FROM_LIST_KW non_text_value WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_KEYS_KW non_text_value WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_VALUES_KW non_text_value WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_MERGE_KW + dict0=non_text_value WS+ + dict1=non_text_value WS+ + fun=non_text_value WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_MERGE_KW + dict0=non_text_value WS+ + dict1=non_text_value WS+ + fun=non_text_value WS+ + value_list WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_FILTER_KW + dict0=non_text_value WS+ + fun=non_text_value WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_FILTER_KW + dict0=non_text_value WS+ + fun=non_text_value WS+ + value_list WS* + R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_SET_KW key=value WS+ val=value WS+ dict0=non_text_value WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_REMOVE_KW key=value WS+ dict0=non_text_value WS* R_PAREN + { + /* TODO */ + $result = null; + } + + | DICT_HAS_KW key=value WS+ dict0=non_text_value WS* R_PAREN + { + + /* TODO */ + $result = null; + } + + | DICT_GET_KW key=value WS+ dict0=non_text_value WS* R_PAREN + { + + /* TODO */ + $result = null; + } + + | DICT_GET_POINTER_KW key=value WS+ dict0=non_text_value WS* R_PAREN + { + + /* TODO */ + $result = null; + } | SHUFFLE_KW non_text_value WS* R_PAREN { diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java index 2b0efaf..405d32a 100644 --- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java +++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java @@ -495,7 +495,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ( compiler, ( - (tonkadur.fate.v1.lang.type.DictType) + (tonkadur.fate.v1.lang.type.StructType) n.get_parent().get_type() ).get_field_type(null, n.get_field_name()) ) @@ -526,7 +526,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor ( compiler, ( - (tonkadur.fate.v1.lang.type.DictType) + (tonkadur.fate.v1.lang.type.StructType) n.get_parent().get_type() ).get_field_type(null, n.get_field_name()) ) 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 8dcd70d..1b97e10 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 @@ -22,13 +22,13 @@ public class TypeCompiler ) throws Error { - if (fate_type instanceof tonkadur.fate.v1.lang.type.DictType) + if (fate_type instanceof tonkadur.fate.v1.lang.type.StructType) { return compile_dict_type ( compiler, - (tonkadur.fate.v1.lang.type.DictType) fate_type + (tonkadur.fate.v1.lang.type.StructType) fate_type ); } @@ -119,7 +119,7 @@ public class TypeCompiler protected static Type compile_dict_type ( final Compiler compiler, - final tonkadur.fate.v1.lang.type.DictType fate_dict_type + final tonkadur.fate.v1.lang.type.StructType fate_dict_type ) throws Error { |


