summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/World.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/Access.java2
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/Cast.java2
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java2
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/Operation.java2
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/Break.java37
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java5
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java3
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java12
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/type/DictType.java7
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/type/RefType.java7
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/type/Type.java9
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateLexer.g42
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g451
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java29
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java574
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java47
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java1
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/util/InstructionManager.java29
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/computation/New.java3
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java3
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/instruction/AddChoice.java12
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/instruction/End.java25
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/type/MapType.java4
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/type/PointerType.java26
-rw-r--r--src/core/src/tonkadur/wyrd/v1/lang/type/Type.java2
33 files changed, 797 insertions, 147 deletions
diff --git a/src/core/src/tonkadur/fate/v1/lang/World.java b/src/core/src/tonkadur/fate/v1/lang/World.java
index d6c8ac0..7b15f3f 100644
--- a/src/core/src/tonkadur/fate/v1/lang/World.java
+++ b/src/core/src/tonkadur/fate/v1/lang/World.java
@@ -270,11 +270,11 @@ public class World
try
{
type_collection.add(Type.BOOLEAN);
- type_collection.add(Type.DICT);
+ //type_collection.add(Type.DICT);
type_collection.add(Type.FLOAT);
type_collection.add(Type.INT);
- type_collection.add(Type.LIST);
- type_collection.add(Type.SET);
+ //type_collection.add(Type.LIST);
+ //type_collection.add(Type.SET);
type_collection.add(Type.STRING);
}
catch (final Throwable t)
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Access.java b/src/core/src/tonkadur/fate/v1/lang/computation/Access.java
index 7aae4ca..f99d04b 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/Access.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/Access.java
@@ -61,7 +61,7 @@ public class Access extends Reference
current_type = parent.get_type();
- if (current_type.get_base_type().equals(Type.REF))
+ if (current_type.get_act_as_type().equals(Type.REF))
{
parent = AtReference.build(origin, parent);
current_type = parent.get_type();
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Cast.java b/src/core/src/tonkadur/fate/v1/lang/computation/Cast.java
index 98e9746..10ccd1b 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/Cast.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/Cast.java
@@ -130,7 +130,7 @@ public class Cast extends Computation
(
allowed_type_changes.get(to).contains
(
- value.get_type().get_base_type()
+ value.get_type().get_act_as_type()
)
)
)
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java
index e53f748..56d4cac 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/CountOperator.java
@@ -61,11 +61,7 @@ public class CountOperator extends Computation
collection_type = collection.get_type();
- if
- (
- !Type.COLLECTION_TYPES.contains(collection_type.get_base_type())
- || !(collection_type instanceof CollectionType)
- )
+ if (!(collection_type instanceof CollectionType))
{
ErrorManager.handle
(
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 57d4836..6ca0024 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/FieldReference.java
@@ -60,7 +60,7 @@ public class FieldReference extends Reference
current_type = parent.get_type();
- if (current_type.get_base_type().equals(Type.REF))
+ if (current_type.get_act_as_type().equals(Type.REF))
{
parent = AtReference.build(origin, parent);
current_type = parent.get_type();
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java
index 687be29..73123f6 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/IndexOfOperator.java
@@ -61,11 +61,7 @@ public class IndexOfOperator extends Computation
collection_type = collection.get_type();
- if
- (
- !Type.COLLECTION_TYPES.contains(collection_type.get_base_type())
- || !(collection_type instanceof CollectionType)
- )
+ if (!(collection_type instanceof CollectionType))
{
ErrorManager.handle
(
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java b/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java
index b23fcc4..ce110ab 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/IsMemberOperator.java
@@ -61,11 +61,7 @@ public class IsMemberOperator extends Computation
collection_type = collection.get_type();
- if
- (
- !Type.COLLECTION_TYPES.contains(collection_type.get_base_type())
- || !(collection_type instanceof CollectionType)
- )
+ if (!(collection_type instanceof CollectionType))
{
ErrorManager.handle
(
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Operation.java b/src/core/src/tonkadur/fate/v1/lang/computation/Operation.java
index d67fa1d..d83fe85 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/Operation.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/Operation.java
@@ -91,7 +91,7 @@ public class Operation extends Computation
operand_type = operand.get_type();
- if (!allowed_base_types.contains(operand_type.get_base_type()))
+ if (!allowed_base_types.contains(operand_type.get_act_as_type()))
{
ErrorManager.handle
(
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java
index 792a68f..c60b87d 100644
--- a/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/AddElement.java
@@ -62,11 +62,7 @@ public class AddElement extends Instruction
collection_type = collection.get_type();
- if
- (
- !Type.COLLECTION_TYPES.contains(collection_type.get_base_type())
- || !(collection_type instanceof CollectionType)
- )
+ if (!(collection_type instanceof CollectionType))
{
ErrorManager.handle
(
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/Break.java b/src/core/src/tonkadur/fate/v1/lang/instruction/Break.java
new file mode 100644
index 0000000..653061d
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/Break.java
@@ -0,0 +1,37 @@
+package tonkadur.fate.v1.lang.instruction;
+
+import tonkadur.parser.Origin;
+
+import tonkadur.fate.v1.lang.meta.InstructionVisitor;
+import tonkadur.fate.v1.lang.meta.Instruction;
+
+public class Break extends Instruction
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
+ public Break (final Origin origin)
+ {
+ super(origin);
+ }
+
+ /**** Accessors ************************************************************/
+ @Override
+ public void get_visited_by (final InstructionVisitor iv)
+ throws Throwable
+ {
+ iv.visit_break(this);
+ }
+
+ /**** Misc. ****************************************************************/
+ @Override
+ public String toString ()
+ {
+ return "(Break)";
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java b/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java
index 5d036fa..fd8090f 100644
--- a/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/Clear.java
@@ -48,7 +48,10 @@ public class Clear extends Instruction
{
if
(
- !Type.COLLECTION_TYPES.contains(collection.get_type().get_base_type())
+ !Type.COLLECTION_TYPES.contains
+ (
+ collection.get_type().get_act_as_type()
+ )
)
{
ErrorManager.handle
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java
index 0aeb614..acce7d0 100644
--- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveAllOfElement.java
@@ -63,11 +63,7 @@ public class RemoveAllOfElement extends Instruction
collection_type = collection.get_type();
- if
- (
- !Type.COLLECTION_TYPES.contains(collection_type.get_base_type())
- || !(collection_type instanceof CollectionType)
- )
+ if (!(collection_type instanceof CollectionType))
{
ErrorManager.handle
(
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java
index b067e9d..d721614 100644
--- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElement.java
@@ -62,11 +62,7 @@ public class RemoveElement extends Instruction
collection_type = collection.get_type();
- if
- (
- !Type.COLLECTION_TYPES.contains(collection_type.get_base_type())
- || !(collection_type instanceof CollectionType)
- )
+ if (!(collection_type instanceof CollectionType))
{
ErrorManager.handle
(
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java
index 89d0649..3bf0104 100644
--- a/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/RemoveElementAt.java
@@ -58,11 +58,7 @@ public class RemoveElementAt extends Instruction
collection_type = collection.get_type();
- if
- (
- !Type.COLLECTION_TYPES.contains(collection_type.get_base_type())
- || !(collection_type instanceof CollectionType)
- )
+ if (!(collection_type instanceof CollectionType))
{
ErrorManager.handle
(
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 ef3fe3e..7550895 100644
--- a/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java
+++ b/src/core/src/tonkadur/fate/v1/lang/meta/InstructionVisitor.java
@@ -11,6 +11,9 @@ public interface InstructionVisitor
public void visit_assert (final Assert a)
throws Throwable;
+ public void visit_break (final Break n)
+ throws Throwable;
+
public void visit_free (final Free n)
throws Throwable;
diff --git a/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java b/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java
index 830cd03..bf2fc90 100644
--- a/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java
+++ b/src/core/src/tonkadur/fate/v1/lang/type/CollectionType.java
@@ -34,7 +34,7 @@ public class CollectionType extends Type
(
!Type.SIMPLE_BASE_TYPES.contains
(
- content_type.get_base_type()
+ content_type.get_act_as_type()
)
)
{
@@ -64,6 +64,12 @@ public class CollectionType extends Type
return is_set;
}
+ @Override
+ public Type get_act_as_type ()
+ {
+ return is_set? Type.SET : Type.LIST;
+ }
+
/**** Compatibility ********************************************************/
@Override
public boolean can_be_used_as (final Type t)
@@ -106,7 +112,7 @@ public class CollectionType extends Type
new CollectionType
(
get_origin(),
- ((Type) content_type.generate_comparable_to (ct.content_type)),
+ ((Type) content_type.generate_comparable_to(ct.content_type)),
(ct.is_set || is_set),
name
);
@@ -148,7 +154,7 @@ public class CollectionType extends Type
final String name
)
{
- super(origin, (is_set ? Type.SET : Type.LIST), name);
+ super(origin, null, name);
this.is_set = is_set;
this.content_type = content_type;
diff --git a/src/core/src/tonkadur/fate/v1/lang/type/DictType.java b/src/core/src/tonkadur/fate/v1/lang/type/DictType.java
index 93b9106..ce84863 100644
--- a/src/core/src/tonkadur/fate/v1/lang/type/DictType.java
+++ b/src/core/src/tonkadur/fate/v1/lang/type/DictType.java
@@ -32,7 +32,7 @@ public class DictType extends Type
final String name
)
{
- super(origin, Type.DICT, name);
+ super(origin, null, name);
this.field_types = field_types;
}
@@ -151,6 +151,11 @@ public class DictType extends Type
return new DictType(get_origin(), result_field_types, name);
}
+ @Override
+ public Type get_act_as_type ()
+ {
+ return Type.DICT;
+ }
/**** Misc. ****************************************************************/
@Override
diff --git a/src/core/src/tonkadur/fate/v1/lang/type/RefType.java b/src/core/src/tonkadur/fate/v1/lang/type/RefType.java
index 277e369..15d9c53 100644
--- a/src/core/src/tonkadur/fate/v1/lang/type/RefType.java
+++ b/src/core/src/tonkadur/fate/v1/lang/type/RefType.java
@@ -23,7 +23,7 @@ public class RefType extends Type
final String name
)
{
- super(origin, Type.REF, name);
+ super(origin, null, name);
this.referenced_type = referenced_type;
}
@@ -74,6 +74,11 @@ public class RefType extends Type
return new RefType(get_origin(), resulting_referenced_type, name);
}
+ @Override
+ public Type get_act_as_type ()
+ {
+ return Type.REF;
+ }
/**** Misc. ****************************************************************/
@Override
diff --git a/src/core/src/tonkadur/fate/v1/lang/type/Type.java b/src/core/src/tonkadur/fate/v1/lang/type/Type.java
index aa3e01c..71bf900 100644
--- a/src/core/src/tonkadur/fate/v1/lang/type/Type.java
+++ b/src/core/src/tonkadur/fate/v1/lang/type/Type.java
@@ -118,7 +118,7 @@ public class Type extends DeclaredEntity
)
throws InvalidTypeException
{
- if (!SIMPLE_BASE_TYPES.contains(parent.get_base_type()))
+ if (!SIMPLE_BASE_TYPES.contains(parent.get_act_as_type()))
{
ErrorManager.handle
(
@@ -135,6 +135,11 @@ public class Type extends DeclaredEntity
return true_type;
}
+ public Type get_act_as_type ()
+ {
+ return true_type;
+ }
+
public boolean is_base_type ()
{
return (parent == null);
@@ -163,7 +168,7 @@ public class Type extends DeclaredEntity
/**** Compatibility ********************************************************/
public boolean can_be_used_as (final Type t)
{
- if (!true_type.equals(t.true_type))
+ if (!get_act_as_type().equals(t.get_act_as_type()))
{
return false;
}
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
index db257bf..ca10603 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
@@ -19,6 +19,7 @@ ADD_KW: L_PAREN 'add' SEP+;
AND_KW: L_PAREN ('and'|'/\\') SEP+;
ASSERT_KW: L_PAREN 'assert' SEP+;
AT_KW: L_PAREN 'at' SEP+;
+BREAK_KW: L_PAREN 'break)';
CAST_KW: L_PAREN 'cast' SEP+;
CLEAR_KW: L_PAREN 'clear' SEP+;
COND_KW: L_PAREN 'cond' SEP+;
@@ -44,6 +45,7 @@ EXTENSION_FIRST_LEVEL_KW: L_PAREN '@';
EXTENSION_INSTRUCTION_KW: L_PAREN '#';
EXTENSION_VALUE_KW: L_PAREN '$';
FALSE_KW: L_PAREN 'false)';
+IGNORE_ERROR_KW: L_PAREN 'ignore'US('error'|'warning') SEP+;
FATE_VERSION_KW: L_PAREN 'fate'US'version' SEP+;
FIELD_KW: L_PAREN 'field' SEP+;
FOR_EACH_KW: L_PAREN ('for'US'each') SEP+;
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
index a86ca91..f5868fb 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
@@ -45,6 +45,7 @@ options
World WORLD;
TypedEntryList PARAMETERS;
List<Cons<String, Type>> ODD_VARS;
+ int BREAKABLE_LEVELS;
}
/******************************************************************************/
@@ -57,6 +58,7 @@ fate_file [Context context, World world]
WORLD = world;
PARAMETERS = null;
ODD_VARS = new ArrayList<Cons<String, Type>>();
+ BREAKABLE_LEVELS = 0;
}
:
WS* FATE_VERSION_KW WORD WS* R_PAREN WS*
@@ -164,6 +166,11 @@ first_level_fate_instr:
WORLD.variables().add(new_variable);
}
+ | IGNORE_ERROR_KW WORD WS+ first_level_fate_instr WS* R_PAREN
+ {
+ /* TODO: temporarily disable an compiler error category */
+ }
+
| DECLARE_VARIABLE_KW
scope=WORD
WS+
@@ -590,6 +597,12 @@ returns [Instruction result]
);
}
+ | IGNORE_ERROR_KW WORD WS+ general_fate_instr WS* R_PAREN
+ {
+ /* TODO: temporarily disable an compiler error category */
+ $result = ($general_fate_instr.result);
+ }
+
| REMOVE_ONE_KW value WS+ value_reference WS* R_PAREN
{
$result =
@@ -666,7 +679,6 @@ returns [Instruction result]
| FREE_KW value_reference WS* R_PAREN
{
- /* TODO */
$result =
new Free
(
@@ -718,7 +730,10 @@ returns [Instruction result]
$result = new InstructionList(origin, operations);
}
- | WHILE_KW value WS* general_fate_sequence WS* R_PAREN
+ | WHILE_KW value WS*
+ {BREAKABLE_LEVELS++;} general_fate_sequence {BREAKABLE_LEVELS--;}
+ WS*
+ R_PAREN
{
$result =
While.build
@@ -733,7 +748,10 @@ returns [Instruction result]
);
}
- | DO_WHILE_KW value WS* general_fate_sequence WS* R_PAREN
+ | DO_WHILE_KW value WS*
+ {BREAKABLE_LEVELS++;} general_fate_sequence {BREAKABLE_LEVELS--;}
+ WS*
+ R_PAREN
{
$result =
DoWhile.build
@@ -748,7 +766,22 @@ returns [Instruction result]
);
}
- | FOR_KW pre=general_fate_instr WS * value WS* post=general_fate_instr WS* general_fate_sequence WS* R_PAREN
+ | {BREAKABLE_LEVELS > 0}? BREAK_KW
+ {
+ $result =
+ new Break
+ (
+ CONTEXT.get_origin_at
+ (
+ ($BREAK_KW.getLine()),
+ ($BREAK_KW.getCharPositionInLine())
+ )
+ );
+ }
+
+ | FOR_KW pre=general_fate_instr WS * value WS* post=general_fate_instr WS*
+ {BREAKABLE_LEVELS++;} general_fate_sequence {BREAKABLE_LEVELS--;}
+ WS* R_PAREN
{
$result =
For.build
@@ -812,7 +845,9 @@ returns [Instruction result]
($new_reference_name.result)
);
}
- WS+ general_fate_sequence WS*
+ WS+
+ {BREAKABLE_LEVELS++;} general_fate_sequence {BREAKABLE_LEVELS--;}
+ WS*
R_PAREN
{
PARAMETERS.remove(($new_reference_name.result));
@@ -1981,6 +2016,12 @@ returns [Computation result]
);
}
+ | IGNORE_ERROR_KW WORD WS+ value WS* R_PAREN
+ {
+ $result = ($value.result);
+ /* TODO: temporarily disable an compiler error category */
+ }
+
| L_PAREN WS+ paragraph WS* R_PAREN
{
$result = ($paragraph.result);
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 dd3e707..121eda7 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
@@ -976,7 +976,8 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
)
throws Throwable
{
- /* TODO */
+ result_as_computation =
+ new New(TypeCompiler.compile(compiler, n.get_target_type()));
}
@Override
@@ -986,7 +987,31 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
)
throws Throwable
{
- /* TODO */
+ final ComputationCompiler i_cc, n_cc;
+
+ n_cc = new ComputationCompiler(compiler);
+ i_cc = new ComputationCompiler(compiler);
+
+ n.get_parent().get_visited_by(n_cc);
+ n.get_index().get_visited_by(i_cc);
+
+ assimilate(n_cc);
+ assimilate(i_cc);
+
+ result_as_ref =
+ new RelativeRef
+ (
+ n_cc.get_ref(),
+ new Cast(i_cc.get_computation(), Type.STRING),
+ TypeCompiler.compile
+ (
+ compiler,
+ (
+ (tonkadur.fate.v1.lang.type.CollectionType)
+ n.get_parent().get_type()
+ ).get_content_type()
+ )
+ );
}
@Override
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 ddb5350..6eaf4b8 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
@@ -1,7 +1,5 @@
package tonkadur.wyrd.v1.compiler.fate.v1;
-/* TODO: clean this up, way too many `new ...` could be reused. */
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -59,16 +57,6 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
result = new ArrayList<Instruction>();
}
- public InstructionCompiler
- (
- final Compiler compiler,
- final List<Instruction> result
- )
- {
- this.compiler = compiler;
- this.result = result;
- }
-
protected Instruction get_result ()
{
return compiler.assembler().merge(result);
@@ -254,7 +242,14 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
!(collection_type instanceof tonkadur.fate.v1.lang.type.CollectionType)
)
{
- /* TODO: error */
+ System.err.println
+ (
+ "[P] (add_element item collection), but this is not a collection: "
+ + ae.get_collection()
+ + ". It's a "
+ + collection_type.get_name()
+ + "."
+ );
}
collection_true_type =
@@ -335,55 +330,439 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
@Override
public void visit_switch_instruction
(
- final tonkadur.fate.v1.lang.instruction.SwitchInstruction ci
+ final tonkadur.fate.v1.lang.instruction.SwitchInstruction n
)
throws Throwable
{
- /* TODO */
+ /*
+ * Fate:
+ * (switch target
+ * (c0 i0)
+ * (... ...)
+ * (cn in)
+ * default
+ * )
+ *
+ * Wyrd:
+ * (declare_variable <target.type> .anon)
+ *
+ * (set .anon target) ;; in case target requires computation.
+ *
+ * <ifelse (= c0 .anon)
+ * i0
+ * <ifelse ...
+ * ...
+ * <ifelse (= cn .anon)
+ * in
+ * default
+ * >
+ * >
+ * >
+ */
+ Ref anon;
+ final List
+ <
+ Cons
+ <
+ tonkadur.fate.v1.lang.meta.Computation,
+ tonkadur.fate.v1.lang.meta.Instruction
+ >
+ > branches;
+ InstructionCompiler ic;
+ ComputationCompiler target_cc, cc;
+ Computation value_of_anon;
+ List<Instruction> current_branch, previous_else_branch;
+
+ branches = new ArrayList(n.get_branches()); // shallow copy.
+
+ previous_else_branch = new ArrayList<Instruction>();
+
+ ic = new InstructionCompiler(compiler);
+ n.get_default_instruction().get_visited_by(ic);
+
+ previous_else_branch.add(ic.get_result());
+
+ target_cc = new ComputationCompiler(compiler);
+
+ n.get_target().get_visited_by(target_cc);
+
+ target_cc.generate_ref();
+
+ if (target_cc.has_init())
+ {
+ result.add(target_cc.get_init());
+ }
+
+ anon = target_cc.get_ref();
+ value_of_anon = new ValueOf(anon);
+
+ for
+ (
+ final
+ Cons
+ <
+ tonkadur.fate.v1.lang.meta.Computation,
+ tonkadur.fate.v1.lang.meta.Instruction
+ >
+ branch:
+ branches
+ )
+ {
+ current_branch = new ArrayList<Instruction>();
+
+ ic = new InstructionCompiler(compiler);
+ cc = new ComputationCompiler(compiler);
+
+ branch.get_car().get_visited_by(cc);
+
+ if (cc.has_init())
+ {
+ current_branch.add(cc.get_init());
+ }
+
+ current_branch.add
+ (
+ IfElse.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler(),
+ Operation.equals(value_of_anon, cc.get_computation()),
+ ic.get_result(),
+ compiler.assembler().merge(previous_else_branch)
+ )
+ );
+
+ previous_else_branch = current_branch;
+
+ cc.release_variables();
+ }
+
+ result.add(compiler.assembler().merge(previous_else_branch));
+ }
+
+ @Override
+ public void visit_display (final tonkadur.fate.v1.lang.instruction.Display n)
+ throws Throwable
+ {
+ /*
+ * Fate: (display Computation)
+ *
+ * Wyrd: (display Computation)
+ */
+ final ComputationCompiler cc;
+
+ cc = new ComputationCompiler(compiler);
+
+ n.get_content().get_visited_by(cc);
+
+ if (cc.has_init())
+ {
+ result.add(cc.get_init());
+ }
+
+ result.add(new Display(cc.get_computation()));
+
+ cc.release_variables();
}
@Override
public void visit_free (final tonkadur.fate.v1.lang.instruction.Free n)
throws Throwable
{
- /* TODO */
+ final ComputationCompiler cc;
+ final Ref target;
+
+ cc = new ComputationCompiler(compiler);
+
+ n.get_reference().get_visited_by(cc);
+
+ if (cc.has_init())
+ {
+ result.add(cc.get_init());
+ }
+
+ target = cc.get_ref();
+
+ if (target == null)
+ {
+ System.err.println
+ (
+ "[P] Argument in (free "
+ + n.get_reference()
+ + ") did not compile to a reference."
+ );
+ }
+
+ result.add(new Remove(target));
+
+ cc.release_variables();
}
@Override
public void visit_while (final tonkadur.fate.v1.lang.instruction.While n)
throws Throwable
{
- /* TODO */
+ final ComputationCompiler cc;
+ final List<Instruction> body;
+ final String end_of_loop_label;
+ InstructionCompiler ic;
+
+ end_of_loop_label =
+ compiler.assembler().generate_label("<AfterWhile>");
+
+ compiler.assembler().push_context_label("breakable", end_of_loop_label);
+
+ cc = new ComputationCompiler(compiler);
+ body = new ArrayList<Instruction>();
+
+ n.get_condition().get_visited_by(cc);
+
+ for (final tonkadur.fate.v1.lang.meta.Instruction i: n.get_body())
+ {
+ ic = new InstructionCompiler(compiler);
+ i.get_visited_by(ic);
+
+ body.add(ic.get_result());
+ }
+
+
+ if (cc.has_init())
+ {
+ result.add
+ (
+ compiler.assembler().mark_after
+ (
+ While.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler(),
+ cc.get_init(),
+ cc.get_computation(),
+ compiler.assembler().merge(body)
+ ),
+ end_of_loop_label
+ )
+ );
+ }
+ else
+ {
+ result.add
+ (
+ compiler.assembler().mark_after
+ (
+ While.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler(),
+ cc.get_computation(),
+ compiler.assembler().merge(body)
+ ),
+ end_of_loop_label
+ )
+ );
+ }
+
+ compiler.assembler().pop_context_label("breakable");
+ cc.release_variables();
}
@Override
public void visit_do_while (final tonkadur.fate.v1.lang.instruction.DoWhile n)
throws Throwable
{
- /* TODO */
+ final List<Instruction> pre_cond_instructions;
+ final ComputationCompiler cc;
+ final String end_of_loop_label;
+ InstructionCompiler ic;
+
+ end_of_loop_label =
+ compiler.assembler().generate_label("<AfterDoWhile>");
+
+ compiler.assembler().push_context_label("breakable", end_of_loop_label);
+
+ pre_cond_instructions = new ArrayList<Instruction>();
+
+ cc = new ComputationCompiler(compiler);
+ n.get_condition().get_visited_by(cc);
+
+ for (final tonkadur.fate.v1.lang.meta.Instruction i: n.get_body())
+ {
+ ic = new InstructionCompiler(compiler);
+ i.get_visited_by(ic);
+
+ pre_cond_instructions.add(ic.get_result());
+ }
+
+ if (cc.has_init())
+ {
+ pre_cond_instructions.add(cc.get_init());
+ }
+
+ result.add
+ (
+ compiler.assembler().mark_after
+ (
+ While.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler(),
+ compiler.assembler().merge(pre_cond_instructions),
+ cc.get_computation(),
+ NOP.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler()
+ )
+ ),
+ end_of_loop_label
+ )
+ );
+
+ compiler.assembler().pop_context_label("breakable");
+ cc.release_variables();
}
@Override
public void visit_for (final tonkadur.fate.v1.lang.instruction.For n)
throws Throwable
{
- /* TODO */
+ final ComputationCompiler cc;
+ final List<Instruction> body;
+ final String end_of_loop_label;
+ InstructionCompiler ic;
+
+ end_of_loop_label =
+ compiler.assembler().generate_label("<AfterFor>");
+
+ compiler.assembler().push_context_label("breakable", end_of_loop_label);
+
+ body = new ArrayList<Instruction>();
+
+ ic = new InstructionCompiler(compiler);
+ n.get_pre().get_visited_by(ic);
+
+ result.add(ic.get_result());
+
+ for (final tonkadur.fate.v1.lang.meta.Instruction i: n.get_body())
+ {
+ ic = new InstructionCompiler(compiler);
+ i.get_visited_by(ic);
+
+ body.add(ic.get_result());
+ }
+
+ ic = new InstructionCompiler(compiler);
+ n.get_post().get_visited_by(ic);
+
+ body.add(ic.get_result());
+
+ cc = new ComputationCompiler(compiler);
+ n.get_condition().get_visited_by(cc);
+
+ if (cc.has_init())
+ {
+ result.add
+ (
+ While.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler(),
+ cc.get_init(),
+ cc.get_computation(),
+ compiler.assembler().merge(body)
+ )
+ );
+ }
+ else
+ {
+ result.add
+ (
+ While.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler(),
+ cc.get_computation(),
+ compiler.assembler().merge(body)
+ )
+ );
+ }
+
+ compiler.assembler().pop_context_label("breakable");
+ cc.release_variables();
}
@Override
- public void visit_remove_element_at (final tonkadur.fate.v1.lang.instruction.RemoveElementAt n)
+ public void visit_for_each (final tonkadur.fate.v1.lang.instruction.ForEach n)
throws Throwable
{
+ final String end_of_loop_label;
+
+ end_of_loop_label =
+ compiler.assembler().generate_label("<AfterFor>");
+
+ compiler.assembler().push_context_label("breakable", end_of_loop_label);
+
/* TODO */
+
+ compiler.assembler().pop_context_label("breakable");
}
@Override
- public void visit_for_each (final tonkadur.fate.v1.lang.instruction.ForEach n)
+ public void visit_remove_element_at
+ (
+ final tonkadur.fate.v1.lang.instruction.RemoveElementAt n
+ )
throws Throwable
{
- /* TODO */
+ final ComputationCompiler index_cc, collection_cc;
+ final Ref collection, collection_size;
+ final Computation value_of_collection_size;
+
+ index_cc = new ComputationCompiler(compiler);
+ collection_cc = new ComputationCompiler(compiler);
+
+ collection_size = compiler.anonymous_variables().reserve(Type.INT);
+
+ n.get_index().get_visited_by(index_cc);
+ n.get_collection().get_visited_by(collection_cc);
+
+ index_cc.generate_ref();
+
+ if (index_cc.has_init())
+ {
+ result.add(index_cc.get_init());
+ }
+
+ if (collection_cc.has_init())
+ {
+ result.add(collection_cc.get_init());
+ }
+
+ collection = collection_cc.get_ref();
+
+ value_of_collection_size = new ValueOf(collection_size);
+
+ result.add(new SetValue(collection_size, new Size(collection)));
+
+ result.add
+ (
+ RemoveAt.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler(),
+ index_cc.get_ref(),
+ value_of_collection_size,
+ collection
+ )
+ );
+
+ compiler.anonymous_variables().release(collection_size);
+
+ index_cc.release_variables();
+ collection_cc.release_variables();
}
+
@Override
public void visit_cond_instruction
(
@@ -411,12 +790,32 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
* >
* >
*/
+ final List
+ <
+ Cons
+ <
+ tonkadur.fate.v1.lang.meta.Computation,
+ tonkadur.fate.v1.lang.meta.Instruction
+ >
+ > branches;
InstructionCompiler ic;
ComputationCompiler cc;
List<Instruction> previous_else_branch;
- List<Instruction> current_else_branch;
+ List<Instruction> current_branch;
+
+ branches = new ArrayList(ci.get_branches()); // shallow copy
+ previous_else_branch = new ArrayList<Instruction>();
- previous_else_branch = result;
+ Collections.reverse(branches);
+
+ previous_else_branch.add
+ (
+ NOP.generate
+ (
+ compiler.anonymous_variables(),
+ compiler.assembler()
+ )
+ );
for
(
@@ -427,22 +826,23 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
tonkadur.fate.v1.lang.meta.Instruction
>
branch:
- ci.get_branches()
+ branches
)
{
- current_else_branch = new ArrayList<Instruction>();
+ current_branch = new ArrayList<Instruction>();
ic = new InstructionCompiler(compiler);
cc = new ComputationCompiler(compiler);
branch.get_car().get_visited_by(cc);
+ branch.get_cdr().get_visited_by(ic);
if (cc.has_init())
{
- previous_else_branch.add(cc.get_init());
+ current_branch.add(cc.get_init());
}
- previous_else_branch.add
+ current_branch.add
(
IfElse.generate
(
@@ -450,49 +850,18 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
compiler.assembler(),
cc.get_computation(),
ic.get_result(),
- compiler.assembler().merge(current_else_branch)
+ compiler.assembler().merge(previous_else_branch)
)
);
- previous_else_branch = current_else_branch;
+ previous_else_branch = current_branch;
cc.release_variables();
}
- previous_else_branch.add
- (
- NOP.generate
- (
- compiler.anonymous_variables(),
- compiler.assembler()
- )
- );
+ result.add(compiler.assembler().merge(previous_else_branch));
}
- @Override
- public void visit_display (final tonkadur.fate.v1.lang.instruction.Display n)
- throws Throwable
- {
- /*
- * Fate: (display Computation)
- *
- * Wyrd: (display Computation)
- */
- final ComputationCompiler cc;
-
- cc = new ComputationCompiler(compiler);
-
- n.get_content().get_visited_by(cc);
-
- if (cc.has_init())
- {
- result.add(cc.get_init());
- }
-
- result.add(new Display(cc.get_computation()));
-
- cc.release_variables();
- }
@Override
public void visit_event_call
@@ -705,6 +1074,22 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
}
@Override
+ public void visit_break
+ (
+ final tonkadur.fate.v1.lang.instruction.Break n
+ )
+ throws Throwable
+ {
+ result.add
+ (
+ new SetPC
+ (
+ compiler.assembler().get_context_label_constant("breakable")
+ )
+ );
+ }
+
+ @Override
public void visit_player_choice
(
final tonkadur.fate.v1.lang.instruction.PlayerChoice n
@@ -718,10 +1103,14 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
*/
final ComputationCompiler cc;
final InstructionCompiler ic;
+ final String start_of_effect, end_of_effect;
cc = new ComputationCompiler(compiler);
ic = new InstructionCompiler(compiler);
+ start_of_effect = compiler.assembler().generate_label("<choice#start>");
+ end_of_effect = compiler.assembler().generate_label("<choice#end>");
+
n.get_text().get_visited_by(cc);
if (cc.has_init())
@@ -729,6 +1118,26 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
result.add(cc.get_init());
}
+ result.add
+ (
+ new AddChoice
+ (
+ cc.get_computation(),
+ compiler.assembler().get_label_constant(start_of_effect)
+ )
+ );
+ result.add
+ (
+ compiler.assembler().mark_after
+ (
+ new SetPC
+ (
+ compiler.assembler().get_label_constant(end_of_effect)
+ ),
+ start_of_effect
+ )
+ );
+
for
(
final tonkadur.fate.v1.lang.meta.Instruction fate_instruction:
@@ -738,7 +1147,17 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
fate_instruction.get_visited_by(ic);
}
- result.add(new AddChoice(cc.get_computation(), ic.get_result()));
+ result.add
+ (
+ compiler.assembler().mark_after
+ (
+ new SetPC
+ (
+ compiler.assembler().get_context_label_constant("choices")
+ ),
+ end_of_effect
+ )
+ );
cc.release_variables();
}
@@ -750,6 +1169,13 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
)
throws Throwable
{
+ final String end_of_choices_label;
+
+ end_of_choices_label =
+ compiler.assembler().generate_label("<ChoicesResolved>");
+
+ compiler.assembler().push_context_label("choices", end_of_choices_label);
+
/*
* Fate: (player_choice_list i0 ... in)
*
@@ -768,7 +1194,16 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
fate_instruction.get_visited_by(this);
}
- result.add(new ResolveChoices());
+ compiler.assembler().pop_context_label("choices");
+
+ result.add
+ (
+ compiler.assembler().mark_after
+ (
+ new ResolveChoices(),
+ end_of_choices_label
+ )
+ );
}
@Override
@@ -1126,15 +1561,4 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
value_cc.release_variables();
ref_cc.release_variables();
}
-
- /*
- * TODO: Be careful about compiling Fate's loop operators:
- * You can't do:
- * condition.get_visited_by(ComputationCompiler);
- * result.add(ComputationCompiler.get_init();
- * result.add(While.generate(...));
- *
- * The whatever is added in result.add(ComputationCompiler.get_init();
- * needs to be re-evaluated at every iteration.
- */
}
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 216b578..61bcd14 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
@@ -44,7 +44,18 @@ public class TypeCompiler
if (fate_type instanceof tonkadur.fate.v1.lang.type.RefType)
{
- return Type.POINTER;
+ return
+ new PointerType
+ (
+ compile
+ (
+ compiler,
+ (
+ (tonkadur.fate.v1.lang.type.RefType)
+ fate_type
+ ).get_referenced_type()
+ )
+ );
}
fate_type = fate_type.get_base_type();
@@ -74,7 +85,8 @@ public class TypeCompiler
return Type.STRING;
}
- /* TODO: throw error. */
+ System.err.println("[P] Unknown basic fate type '" + fate_type + "'.");
+
return null;
}
@@ -149,7 +161,36 @@ public class TypeCompiler
return MapType.MAP_TO_STRING;
}
- /* TODO: error */
+ if (fate_content_type.equals(tonkadur.fate.v1.lang.type.Type.RICH_TEXT))
+ {
+ return MapType.MAP_TO_RICH_TEXT;
+ }
+
+ if (fate_content_type instanceof tonkadur.fate.v1.lang.type.RefType)
+ {
+ return
+ new MapType
+ (
+ new PointerType
+ (
+ compile
+ (
+ compiler,
+ (
+ (tonkadur.fate.v1.lang.type.RefType)
+ fate_content_type
+ ).get_referenced_type()
+ )
+ )
+ );
+ }
+
+ System.err.println
+ (
+ "[P] Unknown collection member fate type '"
+ + fate_content_type
+ + "'."
+ );
return null;
}
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java
index 4a8ee82..df0da53 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/AnonymousVariableManager.java
@@ -87,7 +87,6 @@ public class AnonymousVariableManager
+ r.toString()
+ "' is not at constant address."
);
- /* TODO: error */
return;
}
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/InstructionManager.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/InstructionManager.java
index bac8d8a..b06b8cb 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/util/InstructionManager.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/InstructionManager.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Stack;
import tonkadur.wyrd.v1.lang.World;
@@ -17,6 +18,7 @@ public class InstructionManager
{
protected Map<String, Integer> label_locations;
protected Map<String, List<Label>> unresolved_labels;
+ protected Map<String, Stack<String>> context_labels;
protected int generated_labels;
public InstructionManager ()
@@ -24,6 +26,7 @@ public class InstructionManager
label_locations = new HashMap<String, Integer>();
unresolved_labels = new HashMap<String, List<Label>>();
generated_labels = 0;
+ context_labels = new HashMap<String, Stack<String>>();
}
public void add_fixed_name_label (final String name)
@@ -34,6 +37,32 @@ public class InstructionManager
}
}
+ public void push_context_label (final String context, final String name)
+ {
+ Stack<String> stack;
+
+ stack = context_labels.get(context);
+
+ if (stack == null)
+ {
+ stack = new Stack<String>();
+
+ context_labels.put(context, stack);
+ }
+
+ stack.push(name);
+ }
+
+ public void pop_context_label (final String context)
+ {
+ context_labels.get(context).pop();
+ }
+
+ public Constant get_context_label_constant (final String context)
+ {
+ return get_label_constant(context_labels.get(context).peek());
+ }
+
public String generate_label ()
{
final String result;
diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/New.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/New.java
index 552362f..01af634 100644
--- a/src/core/src/tonkadur/wyrd/v1/lang/computation/New.java
+++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/New.java
@@ -3,6 +3,7 @@ package tonkadur.wyrd.v1.lang.computation;
import java.util.List;
import tonkadur.wyrd.v1.lang.type.Type;
+import tonkadur.wyrd.v1.lang.type.PointerType;
import tonkadur.wyrd.v1.lang.meta.Computation;
@@ -19,7 +20,7 @@ public class New extends Computation
/**** Constructors *********************************************************/
public New (final Type target_type)
{
- super(Type.POINTER);
+ super(new PointerType(target_type));
this.target_type = target_type;
}
diff --git a/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java b/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java
index c303288..5fe62d3 100644
--- a/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java
+++ b/src/core/src/tonkadur/wyrd/v1/lang/computation/Ref.java
@@ -1,6 +1,7 @@
package tonkadur.wyrd.v1.lang.computation;
import tonkadur.wyrd.v1.lang.type.Type;
+import tonkadur.wyrd.v1.lang.type.PointerType;
import tonkadur.wyrd.v1.lang.meta.Computation;
@@ -18,7 +19,7 @@ public class Ref extends Computation
/**** Constructors *********************************************************/
public Ref (final Computation address, final Type target_type)
{
- super(Type.POINTER);
+ super(new PointerType(target_type));
this.address = address;
this.target_type = target_type;
diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/AddChoice.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/AddChoice.java
index 4f33f8c..f16586a 100644
--- a/src/core/src/tonkadur/wyrd/v1/lang/instruction/AddChoice.java
+++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/AddChoice.java
@@ -9,16 +9,16 @@ public class AddChoice extends Instruction
/**** MEMBERS **************************************************************/
/***************************************************************************/
protected final Computation label;
- protected final Instruction effect;
+ protected final Computation address;
/***************************************************************************/
/**** PUBLIC ***************************************************************/
/***************************************************************************/
/**** Constructors *********************************************************/
- public AddChoice (final Computation label, final Instruction effect)
+ public AddChoice (final Computation label, final Computation address)
{
this.label = label;
- this.effect = effect;
+ this.address = address;
}
/**** Accessors ************************************************************/
@@ -27,9 +27,9 @@ public class AddChoice extends Instruction
return label;
}
- public Instruction get_effect ()
+ public Computation get_address ()
{
- return effect;
+ return address;
}
/**** Misc. ****************************************************************/
@@ -43,7 +43,7 @@ public class AddChoice extends Instruction
sb.append("(AddChoice ");
sb.append(label.toString());
sb.append(" ");
- sb.append(effect.toString());
+ sb.append(address.toString());
sb.append(")");
return sb.toString();
diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/End.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/End.java
new file mode 100644
index 0000000..4bfa97d
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/End.java
@@ -0,0 +1,25 @@
+package tonkadur.wyrd.v1.lang.instruction;
+
+import tonkadur.wyrd.v1.lang.meta.Instruction;
+
+public class End extends Instruction
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
+ public End ()
+ {
+ }
+
+ /**** Misc. ****************************************************************/
+ @Override
+ public String toString ()
+ {
+ return "(End)";
+ }
+}
diff --git a/src/core/src/tonkadur/wyrd/v1/lang/type/MapType.java b/src/core/src/tonkadur/wyrd/v1/lang/type/MapType.java
index a8d79b4..d8316da 100644
--- a/src/core/src/tonkadur/wyrd/v1/lang/type/MapType.java
+++ b/src/core/src/tonkadur/wyrd/v1/lang/type/MapType.java
@@ -6,12 +6,14 @@ public class MapType extends Type
public static final MapType MAP_TO_FLOAT;
public static final MapType MAP_TO_INT;
public static final MapType MAP_TO_STRING;
+ public static final MapType MAP_TO_RICH_TEXT;
static
{
MAP_TO_BOOLEAN = new MapType(Type.BOOLEAN);
MAP_TO_FLOAT = new MapType(Type.FLOAT);
MAP_TO_INT = new MapType(Type.INT);
+ MAP_TO_RICH_TEXT = new MapType(Type.RICH_TEXT);
MAP_TO_STRING = new MapType(Type.STRING);
}
@@ -20,7 +22,7 @@ public class MapType extends Type
/***************************************************************************/
protected final Type member_type;
- protected MapType (final Type member_type)
+ public MapType (final Type member_type)
{
super("(Map String->" + member_type.name + ")");
this.member_type = member_type;
diff --git a/src/core/src/tonkadur/wyrd/v1/lang/type/PointerType.java b/src/core/src/tonkadur/wyrd/v1/lang/type/PointerType.java
new file mode 100644
index 0000000..ee34c0d
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/lang/type/PointerType.java
@@ -0,0 +1,26 @@
+package tonkadur.wyrd.v1.lang.type;
+
+public class PointerType extends Type
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final Type target_type;
+
+ public PointerType (final Type target_type)
+ {
+ super("(PointerTo " + target_type.name + ")");
+ this.target_type = target_type;
+ }
+
+ public Type get_target_type ()
+ {
+ return target_type;
+ }
+
+ @Override
+ public String toString ()
+ {
+ return name;
+ }
+}
diff --git a/src/core/src/tonkadur/wyrd/v1/lang/type/Type.java b/src/core/src/tonkadur/wyrd/v1/lang/type/Type.java
index ed377cc..d2f5684 100644
--- a/src/core/src/tonkadur/wyrd/v1/lang/type/Type.java
+++ b/src/core/src/tonkadur/wyrd/v1/lang/type/Type.java
@@ -5,7 +5,6 @@ public class Type
public static final Type BOOLEAN;
public static final Type FLOAT;
public static final Type INT;
- public static final Type POINTER;
public static final Type RICH_TEXT;
public static final Type STRING;
@@ -14,7 +13,6 @@ public class Type
BOOLEAN = new Type("boolean");
FLOAT = new Type("float");
INT = new Type("int");
- POINTER = new Type("pointer");
RICH_TEXT = new Type("rich_text");
STRING = new Type("string");
}