summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2021-08-30 23:50:54 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2021-08-30 23:50:54 +0200
commit535eabb82e49f94f51189823f6ee78b9103ed226 (patch)
tree8d9af3be7957fcc9fbcd9760eee5eddb09eceabe /src
parent746329272fcab689d0fa2f0594f7914c8cc497b0 (diff)
Adds the missing Wyrd Generic Instruction compilers & fixes a few issues.
Diffstat (limited to 'src')
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java4
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java2
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java6
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/instruction/generic/SetValue.java43
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateLexer.g443
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g489
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java647
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SequenceVariableCallCompiler.java102
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SequenceVariableJumpCompiler.java95
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SetValueCompiler.java66
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/ShuffleCompiler.java59
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SortCompiler.java126
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SubListCompiler.java98
13 files changed, 665 insertions, 715 deletions
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java b/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java
index 8bf5e8d..d2a5ef0 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/GenericComputation.java
@@ -94,7 +94,9 @@ public abstract class GenericComputation extends Computation
(
"[E] Unknown Generic Fate Computation '"
+ name
- + "'."
+ + "' at "
+ + origin
+ + "."
);
}
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java b/src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java
index c0392c9..5bfe6bd 100644
--- a/src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/Paragraph.java
@@ -32,7 +32,7 @@ public class Paragraph extends Computation
)
throws Throwable
{
- for (int i = content.size(); i > 0; i--)
+ for (int i = content.size() - 1; i >= 0; i--)
{
final Computation c;
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java b/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java
index 850dc73..29a0bd0 100644
--- a/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/GenericInstruction.java
@@ -95,10 +95,14 @@ public abstract class GenericInstruction extends Instruction
(
"[E] Unknown Generic Fate Instruction '"
+ name
- + "'."
+ + "' at "
+ + origin
+ + "."
);
}
+ System.out.println("Resolving GenericInstruction " + name + "...");
+
return
(Instruction) computation_class.getDeclaredMethod
(
diff --git a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/SetValue.java b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/SetValue.java
index 2102743..d712715 100644
--- a/src/core/src/tonkadur/fate/v1/lang/instruction/generic/SetValue.java
+++ b/src/core/src/tonkadur/fate/v1/lang/instruction/generic/SetValue.java
@@ -36,14 +36,34 @@ public class SetValue extends GenericInstruction
public static Instruction build
(
final Origin origin,
+ final Computation reference,
+ final Computation value
+ )
+ throws Throwable
+ {
+ reference.expect_non_string();
+
+ RecurrentChecks.handle_expected_type_propagation
+ (
+ value,
+ reference.get_type()
+ );
+
+ RecurrentChecks.assert_can_be_used_as(value, reference);
+
+ reference.use_as_reference();
+
+ return new SetValue(origin, value, reference);
+ }
+
+ public static Instruction build
+ (
+ final Origin origin,
final String _alias,
final List<Computation> call_parameters
)
throws Throwable
{
- final Computation reference;
- final Computation value;
-
if (call_parameters.size() != 2)
{
// TODO: Error.
@@ -56,22 +76,7 @@ public class SetValue extends GenericInstruction
return null;
}
- reference = call_parameters.get(0);
- value = call_parameters.get(1);
-
- reference.expect_non_string();
-
- RecurrentChecks.handle_expected_type_propagation
- (
- value,
- reference.get_type()
- );
-
- RecurrentChecks.assert_can_be_used_as(value, reference);
-
- reference.use_as_reference();
-
- return new SetValue(origin, value, reference);
+ return build(origin, call_parameters.get(0), call_parameters.get(1));
}
/***************************************************************************/
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
index 3934170..0cbe9f5 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
@@ -19,8 +19,6 @@ IMP_MARKER: IMP;
FATE_VERSION_KW: L_PAREN 'fate'US'version' SEP+;
-
-
DECLARE_ALIAS_TYPE_KW:
L_PAREN
((('declare'|('def''ine'?))US(('sub'|'alias')US)?'type')|'typedef')
@@ -58,34 +56,24 @@ DECLARE_LOCAL_VARIABLE_KW: L_PAREN 'local' SEP+;
-
-DICT_KW: L_PAREN 'dict'('ionary'?) SEP+;
-LIST_KW: L_PAREN 'list' SEP+;
-
+VARIABLE_KW: L_PAREN ('variable'|'var') SEP+;
ENABLE_TEXT_EFFECT_KW: L_PAREN 'text'US'effect' SEP+;
-NEWLINE_KW: L_PAREN 'newline' SEP* R_PAREN;
TEXT_KW: L_PAREN 'text' SEP+;
-
-CONS_KW: L_PAREN 'cons' SEP+;
-
COND_KW: L_PAREN 'cond' SEP+;
DO_WHILE_KW: L_PAREN 'do'US'while' SEP+;
FOR_KW: L_PAREN 'for' SEP+;
FOR_EACH_KW: L_PAREN 'for'US'each' SEP+;
WHILE_KW: L_PAREN 'while' SEP+;
SWITCH_KW: L_PAREN 'switch' SEP+;
-IMP_BREAK_KW: L_PAREN 'break'('!'?) SEP* R_PAREN;
-IMP_CONTINUE_KW: L_PAREN 'continue'('!'?) SEP* R_PAREN;
-
+// FIXME: this hides generic if_else and if.
IF_ELSE_KW: L_PAREN 'if'US'else' SEP+;
IF_KW: L_PAREN 'if' SEP+;
-
STRING_KW: L_PAREN 'string' SEP+;
@@ -100,10 +88,9 @@ IGNORE_ERROR_KW: L_PAREN 'ignore'US('error'|'warning') SEP+;
-EXTENSION_FIRST_LEVEL_KW: L_PAREN '@';
-EXTRA_INSTRUCTION_KW: L_PAREN '#';
-EXTRA_COMPUTATION_KW: L_PAREN '$';
-
+//EXTENSION_FIRST_LEVEL_KW: L_PAREN '@';
+//EXTRA_INSTRUCTION_KW: L_PAREN '#';
+//EXTRA_COMPUTATION_KW: L_PAREN '$';
FIELD_ACCESS_KW: L_PAREN 'struct:get'(US'field')? SEP+;
@@ -123,30 +110,10 @@ PROMPT_INTEGER_KW: L_PAREN 'prompt'US'int''eger'?'!' SEP+;
LET_KW: L_PAREN 'let' SEP+;
-REF_KW:
- L_PAREN
- (
- ((('ref''erence'?)|'ptr'|'pointer')(US'to')?)
- |('addr''ess'?(US'of')?)
- )
- SEP+;
-
-VARIABLE_KW: L_PAREN 'var''iable'? SEP+;
-
LAMBDA_KW: L_PAREN 'lambda' SEP+;
SEQUENCE_KW: L_PAREN 'seq''uence'? SEP+;
-DONE_KW: L_PAREN 'done''!'? SEP* R_PAREN;
-VISIT_KW:
- L_PAREN ('call'|'visit')(US(('seq''uence'?)|('proc''edure'?)))?'!' SEP+;
-CONTINUE_AS_KW:
- L_PAREN
- (('continue'US('as'|'to'|'with'))|('jump'(US'to')?)|('go'US'to')|'exec')
- (US(('seq''uence'?)|('proc''edure'?)))?
- '!'
- SEP+;
-END_KW: L_PAREN 'end'('!'?) SEP* R_PAREN;
fragment IDENTIFIER_FRAG: ~([ \t\r\n()]|'!');
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
index 1f70545..7a1f546 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
@@ -42,6 +42,8 @@ options
import tonkadur.fate.v1.lang.meta.*;
import tonkadur.fate.v1.lang.type.*;
import tonkadur.fate.v1.lang.computation.*;
+
+ import tonkadur.fate.v1.lang.instruction.generic.SetValue;
}
@members
@@ -931,7 +933,7 @@ returns [Instruction result]
($L_PAREN.getLine()),
($L_PAREN.getCharPositionInLine())
),
- ($WORD.text),
+ ($WORD.text).substring(0, (($WORD.text).length() - 1)),
($maybe_computation_list.result)
);
}
@@ -1480,15 +1482,15 @@ returns [Computation result]
{
}
:
- computation_list
+ computation_list_with_explicit_spaces
{
// convert all computations to text.
// return text node.
$result =
Paragraph.build
(
- $computation_list.result.get(0).get_origin(),
- $computation_list.result
+ $computation_list_with_explicit_spaces.result.get(0).get_origin(),
+ $computation_list_with_explicit_spaces.result
);
}
;
@@ -1744,13 +1746,13 @@ returns [List<Instruction> result]
SetValue.build
(
origin,
- ($computation.result),
VariableFromWord.generate
(
PARSER,
origin,
var_name
- )
+ ),
+ ($computation.result)
)
);
@@ -1835,8 +1837,8 @@ returns [List<Instruction> result]
SetValue.build
(
origin,
- ($computation.result),
- VariableFromWord.generate(PARSER, origin, var_name)
+ VariableFromWord.generate(PARSER, origin, var_name),
+ ($computation.result)
)
);
@@ -2262,6 +2264,36 @@ returns [Computation result]
($maybe_computation_list.result)
);
}
+
+ | IF_KW maybe_computation_list WS* R_PAREN
+ {
+ $result =
+ GenericComputation.build
+ (
+ PARSER.get_origin_at
+ (
+ ($IF_KW.getLine()),
+ ($IF_KW.getCharPositionInLine())
+ ),
+ ($IF_KW.text).substring(1),
+ ($maybe_computation_list.result)
+ );
+ }
+
+ | IF_ELSE_KW maybe_computation_list WS* R_PAREN
+ {
+ $result =
+ GenericComputation.build
+ (
+ PARSER.get_origin_at
+ (
+ ($IF_ELSE_KW.getLine()),
+ ($IF_ELSE_KW.getCharPositionInLine())
+ ),
+ ($IF_ELSE_KW.text).substring(1),
+ ($maybe_computation_list.result)
+ );
+ }
;
catch [final Throwable e]
{
@@ -2387,6 +2419,47 @@ catch [final Throwable e]
PARSER.handle_error(e);
}
+computation_list_with_explicit_spaces
+returns [List<Computation> result]
+@init
+{
+ $result = new ArrayList<Computation>();
+}
+:
+ computation
+ {
+ ($result).add(($computation.result));
+ }
+ (
+ (WS+
+ {
+ ($result).add
+ (
+ Constant.build_string
+ (
+ PARSER.get_origin_at
+ (
+ ($WS.getLine()),
+ ($WS.getCharPositionInLine())
+ ),
+ " "
+ )
+ );
+ }
+ )*
+ computation
+ {
+ ($result).add(($computation.result));
+ }
+ )*
+ {
+ }
+;
+catch [final Throwable e]
+{
+ PARSER.handle_error(e);
+}
+
word returns [String result, Origin origin]:
WORD
{
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 049e343..cc30524 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
@@ -146,76 +146,6 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
msg_cc.release_registers(result);
}
-/*
- public void visit_reverse_list
- (
- final tonkadur.fate.v1.lang.instruction.ReverseList n
- )
- throws Throwable
- {
- final ComputationCompiler address_compiler;
- final Address collection_address;
-
- address_compiler = new ComputationCompiler(compiler);
-
- n.get_collection().get_visited_by(address_compiler);
-
- if (address_compiler.has_init())
- {
- result.add(address_compiler.get_init());
- }
-
- collection_address = address_compiler.get_address();
-
- result.add
- (
- ReverseList.generate
- (
- compiler.registers(),
- compiler.assembler(),
- new Size(collection_address),
- collection_address
- )
- );
-
- address_compiler.release_registers(result);
- }
-*/
-/*
- @Override
- public void visit_shuffle
- (
- final tonkadur.fate.v1.lang.instruction.Shuffle n
- )
- throws Throwable
- {
- final ComputationCompiler address_compiler;
- final Address collection_address;
-
- address_compiler = new ComputationCompiler(compiler);
-
- n.get_collection().get_visited_by(address_compiler);
-
- if (address_compiler.has_init())
- {
- result.add(address_compiler.get_init());
- }
-
- collection_address = address_compiler.get_address();
-
- result.add
- (
- Shuffle.generate
- (
- compiler.registers(),
- compiler.assembler(),
- collection_address
- )
- );
-
- address_compiler.release_registers(result);
- }
-*/
@Override
public void visit_set_fields
(
@@ -273,174 +203,6 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
target_cc.release_registers(result);
}
-/*
- @Override
- public void visit_sort
- (
- final tonkadur.fate.v1.lang.instruction.Sort n
- )
- throws Throwable
- {
- final ComputationCompiler lambda_cc;
- final List<Computation> params;
- final List<ComputationCompiler> param_cc_list;
- final ComputationCompiler collection_cc;
- final Register sorted_result;
-
- params = new ArrayList<Computation>();
- param_cc_list = new ArrayList<ComputationCompiler>();
-
- lambda_cc = new ComputationCompiler(compiler);
-
- n.get_lambda_function().get_visited_by(lambda_cc);
-
- if (lambda_cc.has_init())
- {
- result.add(lambda_cc.get_init());
- }
-
- collection_cc = new ComputationCompiler(compiler);
-
- n.get_collection().get_visited_by(collection_cc);
-
- if (collection_cc.has_init())
- {
- result.add(collection_cc.get_init());
- }
-
- for
- (
- final tonkadur.fate.v1.lang.meta.Computation p:
- n.get_extra_parameters()
- )
- {
- final ComputationCompiler param_cc;
-
- param_cc = new ComputationCompiler(compiler);
-
- p.get_visited_by(param_cc);
-
- // Let's not re-compute the parameters on every iteration.
- param_cc.generate_address();
-
- if (param_cc.has_init())
- {
- result.add(param_cc.get_init());
- }
-
- param_cc_list.add(param_cc);
-
- params.add(param_cc.get_computation());
- }
-
- sorted_result =
- compiler.registers().reserve
- (
- collection_cc.get_computation().get_type(),
- result
- );
-
- result.add
- (
- Sort.generate
- (
- compiler.registers(),
- compiler.assembler(),
- lambda_cc.get_computation(),
- collection_cc.get_address(),
- sorted_result.get_address(),
- params
- )
- );
-
- result.add
- (
- new SetValue(collection_cc.get_address(), sorted_result.get_value())
- );
-
- compiler.registers().release(sorted_result, result);
-
- collection_cc.release_registers(result);
-
- for (final ComputationCompiler cc: param_cc_list)
- {
- cc.release_registers(result);
- }
- }
-*/
-/*
- @Override
- public void visit_sublist
- (
- final tonkadur.fate.v1.lang.instruction.SubList n
- )
- throws Throwable
- {
- final ComputationCompiler address_compiler, start_compiler, end_compiler;
- final Register result_holder;
-
- address_compiler = new ComputationCompiler(compiler);
- start_compiler = new ComputationCompiler(compiler);
- end_compiler = new ComputationCompiler(compiler);
-
- n.get_collection().get_visited_by(address_compiler);
-
- if (address_compiler.has_init())
- {
- result.add(address_compiler.get_init());
- }
-
- n.get_start_index().get_visited_by(start_compiler);
-
- if (start_compiler.has_init())
- {
- result.add(start_compiler.get_init());
- }
-
- n.get_end_index().get_visited_by(end_compiler);
-
- if (end_compiler.has_init())
- {
- result.add(end_compiler.get_init());
- }
-
- result_holder =
- compiler.registers().reserve
- (
- address_compiler.get_computation().get_type(),
- result
- );
-
- result.add
- (
- SubList.generate
- (
- compiler.registers(),
- compiler.assembler(),
- start_compiler.get_computation(),
- end_compiler.get_computation(),
- address_compiler.get_address(),
- result_holder.get_address()
- )
- );
-
- result.add
- (
- new SetValue
- (
- address_compiler.get_address(),
- result_holder.get_value()
- )
- );
-
- compiler.registers().release(result_holder, result);
-
- address_compiler.release_registers(result);
- start_compiler.release_registers(result);
- end_compiler.release_registers(result);
- }
-*/
-
@Override
public void visit_switch_instruction
(
@@ -1606,234 +1368,6 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
);
}
-// @Override
-// public void visit_remove_all_of_element
-// (
-// final tonkadur.fate.v1.lang.instruction.RemoveAllOfElement n
-// )
-// throws Throwable
-// {
-// /*
-// * Fate:
-// * (remove_all_of element collection)
-// *
-// * Wyrd:
-// * (declare_variable <element_type> .elem)
-// * (declare_variable int .collection_size)
-// *
-// * (set .elem element)
-// * (set .collection_size (size collection))
-// *
-// * <if collection is a list:
-// * <remove_all (var .elem) (var .collection_size) collection>
-// * >
-// * <if collection is a set:
-// * (declare_variable bool .found)
-// * (declare_variable int .index)
-// *
-// * <binary_search
-// * (var .elem)
-// * (var .collection_size)
-// * collection
-// * .found
-// * .index
-// * >
-// * (ifelse (var .found)
-// * <remove_at (var .index) (var .collection_size) collection>
-// * (nop)
-// * )
-// * >
-// */
-// final ComputationCompiler elem_cc, collection_cc;
-// final Register collection_size;
-// final Address elem, collection;
-//
-// elem_cc = new ComputationCompiler(compiler);
-// collection_cc = new ComputationCompiler(compiler);
-//
-// collection_size = compiler.registers().reserve(Type.INT, result);
-//
-// n.get_element().get_visited_by(elem_cc);
-// n.get_collection().get_visited_by(collection_cc);
-//
-// elem_cc.generate_address();
-//
-// if (elem_cc.has_init())
-// {
-// result.add(elem_cc.get_init());
-// }
-//
-// if (collection_cc.has_init())
-// {
-// result.add(collection_cc.get_init());
-// }
-//
-// collection = collection_cc.get_address();
-// elem = elem_cc.get_address();
-//
-// result.add
-// (
-// new SetValue(collection_size.get_address(), new Size(collection))
-// );
-//
-// if
-// (
-// (
-// (tonkadur.fate.v1.lang.type.CollectionType)
-// n.get_collection().get_type()
-// ).is_set()
-// )
-// {
-// final Computation value_of_elem;
-// final Register index, found;
-//
-// index = compiler.registers().reserve(Type.INT, result);
-// found = compiler.registers().reserve(Type.BOOL, result);
-//
-// value_of_elem = new ValueOf(elem);
-//
-// result.add
-// (
-// BinarySearch.generate
-// (
-// compiler.registers(),
-// compiler.assembler(),
-// new ValueOf(elem),
-// collection_size.get_value(),
-// collection,
-// found.get_address(),
-// index.get_address()
-// )
-// );
-//
-// elem_cc.release_registers(result);
-//
-// result.add
-// (
-// If.generate
-// (
-// compiler.registers(),
-// compiler.assembler(),
-// found.get_value(),
-// RemoveAt.generate
-// (
-// compiler.registers(),
-// compiler.assembler(),
-// index.get_address(),
-// collection_size.get_value(),
-// collection
-// )
-// )
-// );
-//
-// compiler.registers().release(index, result);
-// compiler.registers().release(found, result);
-// }
-// else
-// {
-// result.add
-// (
-// RemoveAllOf.generate
-// (
-// compiler.registers(),
-// compiler.assembler(),
-// new ValueOf(elem),
-// collection_size.get_value(),
-// collection
-// )
-// );
-//
-// elem_cc.release_registers(result);
-// }
-//
-// collection_cc.release_registers(result);
-//
-// compiler.registers().release(collection_size, result);
-// }
-
-// @Override
-// public void visit_remove_element
-// (
-// final tonkadur.fate.v1.lang.instruction.RemoveElement n
-// )
-// throws Throwable
-// {
-// /*
-// * Fate:
-// * (remove_element element collection)
-// *
-// * Wyrd:
-// * (declare_variable <element_type> .elem)
-// * (declare_variable int .collection_size)
-// * (declare_variable boolean .found)
-// * (declare_variable int .index)
-// *
-// * (set .elem element)
-// * (set .collection_size (size collection))
-// *
-// * <if collection is a set:
-// * <BinarySearch
-// * (var .elem)
-// * (var .collection_size)
-// * collection
-// * .found
-// * .index
-// * >
-// * >
-// * <if collection is a list:
-// * <IterativeSearch
-// * (var .elem)
-// * (var .collection_size)
-// * collection
-// * .found
-// * .index
-// * >
-// * >
-// *
-// * (if (var .found)
-// * <remove_at (var index) (var .collection_size) collection>
-// * (nop)
-// * )
-// */
-// final ComputationCompiler elem_cc, collection_cc;
-//
-// elem_cc = new ComputationCompiler(compiler);
-// collection_cc = new ComputationCompiler(compiler);
-//
-// n.get_element().get_visited_by(elem_cc);
-// n.get_collection().get_visited_by(collection_cc);
-//
-// elem_cc.generate_address();
-//
-// if (elem_cc.has_init())
-// {
-// result.add(elem_cc.get_init());
-// }
-//
-// if (collection_cc.has_init())
-// {
-// result.add(collection_cc.get_init());
-// }
-//
-// result.add
-// (
-// RemoveOneOf.generate
-// (
-// compiler.registers(),
-// compiler.assembler(),
-// elem_cc.get_computation(),
-// collection_cc.get_address(),
-// (
-// (tonkadur.fate.v1.lang.type.CollectionType)
-// n.get_collection().get_type()
-// ).is_set()
-// )
-// );
-//
-// elem_cc.release_registers(result);
-// collection_cc.release_registers(result);
-// }
-//
@Override
public void visit_sequence_call
(
@@ -1901,80 +1435,6 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
}
}
-/*
- @Override
- public void visit_sequence_variable_call
- (
- final tonkadur.fate.v1.lang.instruction.SequenceVariableCall n
- )
- throws Throwable
- {
- final ComputationCompiler sequence_cc;
- final List<ComputationCompiler> parameter_ccs;
- final List<Computation> parameters;
-
- final String return_to_label;
-
- return_to_label =
- compiler.assembler().generate_label("<seq_call#return_to>");
-
- sequence_cc = new ComputationCompiler(compiler);
- parameter_ccs = new ArrayList<ComputationCompiler>();
- parameters = new ArrayList<Computation>();
-
- n.get_sequence().get_visited_by(sequence_cc);
-
- if (sequence_cc.has_init())
- {
- result.add(sequence_cc.get_init());
- }
-
- for
- (
- final tonkadur.fate.v1.lang.meta.Computation param: n.get_parameters()
- )
- {
- final ComputationCompiler cc;
-
- cc = new ComputationCompiler(compiler);
-
- param.get_visited_by(cc);
-
- if (cc.has_init())
- {
- result.add(cc.get_init());
- }
-
- parameters.add(cc.get_computation());
- parameter_ccs.add(cc);
- }
-
- result.addAll(compiler.registers().store_parameters(parameters));
-
- result.add
- (
- compiler.assembler().mark_after
- (
- compiler.assembler().merge
- (
- compiler.registers().get_visit_context_instructions
- (
- sequence_cc.get_computation(),
- compiler.assembler().get_label_constant(return_to_label)
- )
- ),
- return_to_label
- )
- );
-
- sequence_cc.release_registers(result);
-
- for (final ComputationCompiler cc: parameter_ccs)
- {
- cc.release_registers(result);
- }
- }
-*/
@Override
public void visit_sequence_jump
(
@@ -2034,113 +1494,6 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
)
);
}
-/*
- @Override
- public void visit_sequence_variable_jump
- (
- final tonkadur.fate.v1.lang.instruction.SequenceVariableJump n
- )
- throws Throwable
- {
- final ComputationCompiler sequence_cc;
- final List<ComputationCompiler> parameter_ccs;
- final List<Computation> parameters;
-
- sequence_cc = new ComputationCompiler(compiler);
- parameter_ccs = new ArrayList<ComputationCompiler>();
- parameters = new ArrayList<Computation>();
-
- n.get_sequence().get_visited_by(sequence_cc);
-
- if (sequence_cc.has_init())
- {
- result.add(sequence_cc.get_init());
- }
-
- for
- (
- final tonkadur.fate.v1.lang.meta.Computation param: n.get_parameters()
- )
- {
- final ComputationCompiler cc;
-
- cc = new ComputationCompiler(compiler);
-
- param.get_visited_by(cc);
-
- if (cc.has_init())
- {
- result.add(cc.get_init());
- }
-
- parameters.add(cc.get_computation());
- parameter_ccs.add(cc);
- }
-
- result.addAll(compiler.registers().store_parameters(parameters));
-
- for (final ComputationCompiler cc: parameter_ccs)
- {
- cc.release_registers(result);
- }
-
- // Terminate current context
- result.addAll
- (
- compiler.registers().get_finalize_context_instructions()
- );
-
- result.addAll
- (
- compiler.registers().get_jump_to_context_instructions
- (
- sequence_cc.get_computation()
- )
- );
-
- sequence_cc.release_registers(result);
- }
-*/
-/*
- @Override
- public void visit_set_value
- (
- final tonkadur.fate.v1.lang.instruction.SetValue n
- )
- throws Throwable
- {
- /*
- * Fate: (set_value address value)
- * Wyrd: (set_value address value)
- *//*
- final ComputationCompiler value_cc, address_cc;
-
- value_cc = new ComputationCompiler(compiler);
- address_cc = new ComputationCompiler(compiler);
-
- n.get_value().get_visited_by(value_cc);
-
- if (value_cc.has_init())
- {
- result.add(value_cc.get_init());
- }
-
- n.get_reference().get_visited_by(address_cc);
-
- if (address_cc.has_init())
- {
- result.add(address_cc.get_init());
- }
-
- result.add
- (
- new SetValue(address_cc.get_address(), value_cc.get_computation())
- );
-
- value_cc.release_registers(result);
- address_cc.release_registers(result);
- }
-*/
@Override
public void visit_prompt_integer
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SequenceVariableCallCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SequenceVariableCallCompiler.java
new file mode 100644
index 0000000..673bf71
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SequenceVariableCallCompiler.java
@@ -0,0 +1,102 @@
+package tonkadur.wyrd.v1.compiler.fate.v1.instruction.generic;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import tonkadur.fate.v1.lang.instruction.generic.SequenceVariableCall;
+
+import tonkadur.wyrd.v1.lang.meta.Computation;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.Compiler;
+import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.instruction.GenericInstructionCompiler;
+
+public class SequenceVariableCallCompiler extends GenericInstructionCompiler
+{
+ public static Class get_target_class ()
+ {
+ return SequenceVariableCall.class;
+ }
+
+ public SequenceVariableCallCompiler (final Compiler compiler)
+ {
+ super(compiler);
+ }
+
+ public void compile
+ (
+ final tonkadur.fate.v1.lang.instruction.GenericInstruction instruction
+ )
+ throws Throwable
+ {
+ final SequenceVariableCall source;
+ final ComputationCompiler sequence_cc;
+ final List<ComputationCompiler> parameter_ccs;
+ final List<Computation> parameters;
+
+ final String return_to_label;
+
+ source = (SequenceVariableCall) instruction;
+
+ return_to_label =
+ compiler.assembler().generate_label("<seq_call#return_to>");
+
+ sequence_cc = new ComputationCompiler(compiler);
+ parameter_ccs = new ArrayList<ComputationCompiler>();
+ parameters = new ArrayList<Computation>();
+
+ source.get_sequence().get_visited_by(sequence_cc);
+
+ if (sequence_cc.has_init())
+ {
+ result.add(sequence_cc.get_init());
+ }
+
+ for
+ (
+ final tonkadur.fate.v1.lang.meta.Computation param:
+ source.get_parameters()
+ )
+ {
+ final ComputationCompiler cc;
+
+ cc = new ComputationCompiler(compiler);
+
+ param.get_visited_by(cc);
+
+ if (cc.has_init())
+ {
+ result.add(cc.get_init());
+ }
+
+ parameters.add(cc.get_computation());
+ parameter_ccs.add(cc);
+ }
+
+ result.addAll(compiler.registers().store_parameters(parameters));
+
+ result.add
+ (
+ compiler.assembler().mark_after
+ (
+ compiler.assembler().merge
+ (
+ compiler.registers().get_visit_context_instructions
+ (
+ sequence_cc.get_computation(),
+ compiler.assembler().get_label_constant(return_to_label)
+ )
+ ),
+ return_to_label
+ )
+ );
+
+ sequence_cc.release_registers(result);
+
+ for (final ComputationCompiler cc: parameter_ccs)
+ {
+ cc.release_registers(result);
+ }
+ }
+}
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SequenceVariableJumpCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SequenceVariableJumpCompiler.java
new file mode 100644
index 0000000..2ba4c44
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SequenceVariableJumpCompiler.java
@@ -0,0 +1,95 @@
+package tonkadur.wyrd.v1.compiler.fate.v1.instruction.generic;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import tonkadur.fate.v1.lang.instruction.generic.SequenceVariableJump;
+
+import tonkadur.wyrd.v1.lang.meta.Computation;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.Compiler;
+import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.instruction.GenericInstructionCompiler;
+
+public class SequenceVariableJumpCompiler extends GenericInstructionCompiler
+{
+ public static Class get_target_class ()
+ {
+ return SequenceVariableJump.class;
+ }
+
+ public SequenceVariableJumpCompiler (final Compiler compiler)
+ {
+ super(compiler);
+ }
+
+ public void compile
+ (
+ final tonkadur.fate.v1.lang.instruction.GenericInstruction instruction
+ )
+ throws Throwable
+ {
+ final SequenceVariableJump source;
+ final ComputationCompiler sequence_cc;
+ final List<ComputationCompiler> parameter_ccs;
+ final List<Computation> parameters;
+
+ source = (SequenceVariableJump) instruction;
+
+ sequence_cc = new ComputationCompiler(compiler);
+ parameter_ccs = new ArrayList<ComputationCompiler>();
+ parameters = new ArrayList<Computation>();
+
+ source.get_sequence().get_visited_by(sequence_cc);
+
+ if (sequence_cc.has_init())
+ {
+ result.add(sequence_cc.get_init());
+ }
+
+ for
+ (
+ final tonkadur.fate.v1.lang.meta.Computation param:
+ source.get_parameters()
+ )
+ {
+ final ComputationCompiler cc;
+
+ cc = new ComputationCompiler(compiler);
+
+ param.get_visited_by(cc);
+
+ if (cc.has_init())
+ {
+ result.add(cc.get_init());
+ }
+
+ parameters.add(cc.get_computation());
+ parameter_ccs.add(cc);
+ }
+
+ result.addAll(compiler.registers().store_parameters(parameters));
+
+ for (final ComputationCompiler cc: parameter_ccs)
+ {
+ cc.release_registers(result);
+ }
+
+ // Terminate current context
+ result.addAll
+ (
+ compiler.registers().get_finalize_context_instructions()
+ );
+
+ result.addAll
+ (
+ compiler.registers().get_jump_to_context_instructions
+ (
+ sequence_cc.get_computation()
+ )
+ );
+
+ sequence_cc.release_registers(result);
+ }
+}
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SetValueCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SetValueCompiler.java
new file mode 100644
index 0000000..122b9b7
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SetValueCompiler.java
@@ -0,0 +1,66 @@
+package tonkadur.wyrd.v1.compiler.fate.v1.instruction.generic;
+
+import tonkadur.fate.v1.lang.instruction.generic.SetValue;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.Compiler;
+import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.instruction.GenericInstructionCompiler;
+
+public class SetValueCompiler extends GenericInstructionCompiler
+{
+ public static Class get_target_class ()
+ {
+ return SetValue.class;
+ }
+
+ public SetValueCompiler (final Compiler compiler)
+ {
+ super(compiler);
+ }
+
+ /*
+ * Fate: (set_value address value)
+ * Wyrd: (set_value address value)
+ */
+ public void compile
+ (
+ final tonkadur.fate.v1.lang.instruction.GenericInstruction instruction
+ )
+ throws Throwable
+ {
+ final SetValue source;
+ final ComputationCompiler value_cc, address_cc;
+
+ source = (SetValue) instruction;
+
+ value_cc = new ComputationCompiler(compiler);
+ address_cc = new ComputationCompiler(compiler);
+
+ source.get_value().get_visited_by(value_cc);
+
+ if (value_cc.has_init())
+ {
+ result.add(value_cc.get_init());
+ }
+
+ source.get_reference().get_visited_by(address_cc);
+
+ if (address_cc.has_init())
+ {
+ result.add(address_cc.get_init());
+ }
+
+ result.add
+ (
+ new tonkadur.wyrd.v1.lang.instruction.SetValue
+ (
+ address_cc.get_address(),
+ value_cc.get_computation()
+ )
+ );
+
+ value_cc.release_registers(result);
+ address_cc.release_registers(result);
+ }
+}
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/ShuffleCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/ShuffleCompiler.java
new file mode 100644
index 0000000..d886233
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/ShuffleCompiler.java
@@ -0,0 +1,59 @@
+package tonkadur.wyrd.v1.compiler.fate.v1.instruction.generic;
+
+import tonkadur.fate.v1.lang.instruction.generic.Shuffle;
+
+import tonkadur.wyrd.v1.lang.computation.Address;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.Compiler;
+import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.instruction.GenericInstructionCompiler;
+
+public class ShuffleCompiler extends GenericInstructionCompiler
+{
+ public static Class get_target_class ()
+ {
+ return Shuffle.class;
+ }
+
+ public ShuffleCompiler (final Compiler compiler)
+ {
+ super(compiler);
+ }
+
+ public void compile
+ (
+ final tonkadur.fate.v1.lang.instruction.GenericInstruction instruction
+ )
+ throws Throwable
+ {
+ final Shuffle source;
+ final ComputationCompiler address_compiler;
+ final Address collection_address;
+
+ source = (Shuffle) instruction;
+
+ address_compiler = new ComputationCompiler(compiler);
+
+ source.get_collection().get_visited_by(address_compiler);
+
+ if (address_compiler.has_init())
+ {
+ result.add(address_compiler.get_init());
+ }
+
+ collection_address = address_compiler.get_address();
+
+ result.add
+ (
+ tonkadur.wyrd.v1.compiler.util.Shuffle.generate
+ (
+ compiler.registers(),
+ compiler.assembler(),
+ collection_address
+ )
+ );
+
+ address_compiler.release_registers(result);
+ }
+}
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SortCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SortCompiler.java
new file mode 100644
index 0000000..f31f58e
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SortCompiler.java
@@ -0,0 +1,126 @@
+package tonkadur.wyrd.v1.compiler.fate.v1.instruction.generic;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import tonkadur.fate.v1.lang.instruction.generic.Sort;
+
+import tonkadur.wyrd.v1.lang.Register;
+
+import tonkadur.wyrd.v1.lang.meta.Computation;
+
+import tonkadur.wyrd.v1.lang.instruction.SetValue;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.Compiler;
+import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.instruction.GenericInstructionCompiler;
+
+public class SortCompiler extends GenericInstructionCompiler
+{
+ public static Class get_target_class ()
+ {
+ return Sort.class;
+ }
+
+ public SortCompiler (final Compiler compiler)
+ {
+ super(compiler);
+ }
+
+ public void compile
+ (
+ final tonkadur.fate.v1.lang.instruction.GenericInstruction instruction
+ )
+ throws Throwable
+ {
+ final Sort source;
+ final ComputationCompiler lambda_cc;
+ final List<Computation> params;
+ final List<ComputationCompiler> param_cc_list;
+ final ComputationCompiler collection_cc;
+ final Register sorted_result;
+
+ source = (Sort) instruction;
+
+ params = new ArrayList<Computation>();
+ param_cc_list = new ArrayList<ComputationCompiler>();
+
+ lambda_cc = new ComputationCompiler(compiler);
+
+ source.get_lambda_function().get_visited_by(lambda_cc);
+
+ if (lambda_cc.has_init())
+ {
+ result.add(lambda_cc.get_init());
+ }
+
+ collection_cc = new ComputationCompiler(compiler);
+
+ source.get_collection().get_visited_by(collection_cc);
+
+ if (collection_cc.has_init())
+ {
+ result.add(collection_cc.get_init());
+ }
+
+ for
+ (
+ final tonkadur.fate.v1.lang.meta.Computation p:
+ source.get_extra_parameters()
+ )
+ {
+ final ComputationCompiler param_cc;
+
+ param_cc = new ComputationCompiler(compiler);
+
+ p.get_visited_by(param_cc);
+
+ // Let's not re-compute the parameters on every iteration.
+ param_cc.generate_address();
+
+ if (param_cc.has_init())
+ {
+ result.add(param_cc.get_init());
+ }
+
+ param_cc_list.add(param_cc);
+
+ params.add(param_cc.get_computation());
+ }
+
+ sorted_result =
+ compiler.registers().reserve
+ (
+ collection_cc.get_computation().get_type(),
+ result
+ );
+
+ result.add
+ (
+ tonkadur.wyrd.v1.compiler.util.Sort.generate
+ (
+ compiler.registers(),
+ compiler.assembler(),
+ lambda_cc.get_computation(),
+ collection_cc.get_address(),
+ sorted_result.get_address(),
+ params
+ )
+ );
+
+ result.add
+ (
+ new SetValue(collection_cc.get_address(), sorted_result.get_value())
+ );
+
+ compiler.registers().release(sorted_result, result);
+
+ collection_cc.release_registers(result);
+
+ for (final ComputationCompiler cc: param_cc_list)
+ {
+ cc.release_registers(result);
+ }
+ }
+}
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SubListCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SubListCompiler.java
new file mode 100644
index 0000000..af20802
--- /dev/null
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/instruction/generic/SubListCompiler.java
@@ -0,0 +1,98 @@
+package tonkadur.wyrd.v1.compiler.fate.v1.instruction.generic;
+
+import tonkadur.fate.v1.lang.instruction.generic.SubList;
+
+import tonkadur.wyrd.v1.lang.Register;
+
+import tonkadur.wyrd.v1.lang.instruction.SetValue;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.Compiler;
+import tonkadur.wyrd.v1.compiler.fate.v1.ComputationCompiler;
+
+import tonkadur.wyrd.v1.compiler.fate.v1.instruction.GenericInstructionCompiler;
+
+public class SubListCompiler extends GenericInstructionCompiler
+{
+ public static Class get_target_class ()
+ {
+ return SubList.class;
+ }
+
+ public SubListCompiler (final Compiler compiler)
+ {
+ super(compiler);
+ }
+
+ public void compile
+ (
+ final tonkadur.fate.v1.lang.instruction.GenericInstruction instruction
+ )
+ throws Throwable
+ {
+ final SubList source;
+ final ComputationCompiler address_compiler, start_compiler, end_compiler;
+ final Register result_holder;
+
+ source = (SubList) instruction;
+
+ address_compiler = new ComputationCompiler(compiler);
+ start_compiler = new ComputationCompiler(compiler);
+ end_compiler = new ComputationCompiler(compiler);
+
+ source.get_collection().get_visited_by(address_compiler);
+
+ if (address_compiler.has_init())
+ {
+ result.add(address_compiler.get_init());
+ }
+
+ source.get_start_index().get_visited_by(start_compiler);
+
+ if (start_compiler.has_init())
+ {
+ result.add(start_compiler.get_init());
+ }
+
+ source.get_end_index().get_visited_by(end_compiler);
+
+ if (end_compiler.has_init())
+ {
+ result.add(end_compiler.get_init());
+ }
+
+ result_holder =
+ compiler.registers().reserve
+ (
+ address_compiler.get_computation().get_type(),
+ result
+ );
+
+ result.add
+ (
+ tonkadur.wyrd.v1.compiler.util.SubList.generate
+ (
+ compiler.registers(),
+ compiler.assembler(),
+ start_compiler.get_computation(),
+ end_compiler.get_computation(),
+ address_compiler.get_address(),
+ result_holder.get_address()
+ )
+ );
+
+ result.add
+ (
+ new SetValue
+ (
+ address_compiler.get_address(),
+ result_holder.get_value()
+ )
+ );
+
+ compiler.registers().release(result_holder, result);
+
+ address_compiler.release_registers(result);
+ start_compiler.release_registers(result);
+ end_compiler.release_registers(result);
+ }
+}