summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/tests/extra_functionals.fate39
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/ComputationCompiler.java81
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/InstructionCompiler.java49
3 files changed, 167 insertions, 2 deletions
diff --git a/data/tests/extra_functionals.fate b/data/tests/extra_functionals.fate
new file mode 100644
index 0000000..53c4b33
--- /dev/null
+++ b/data/tests/extra_functionals.fate
@@ -0,0 +1,39 @@
+(fate_version 1)
+
+(declare_structure test_struct
+ (int i)
+ (float f)
+ (int j)
+ (string str)
+)
+
+(global test_struct st0)
+(global test_struct st1)
+
+(set_fields! st0
+ (i -1)
+ (f -5.0)
+ (j -2)
+ (str nothing)
+)
+
+(global (lambda test_struct (test_struct)) update_test_struct)
+
+(set_value update_test_struct
+ (lambda ( (test_struct s) )
+ (if_else (< (var s.i) 10)
+ (eval
+ update_test_struct
+ (set_fields s
+ (i (+ (var s.i) 1))
+ (j (+ (var s.j) 10))
+ )
+ )
+ (var s)
+ )
+ )
+)
+
+(set_value st1 (eval update_test_struct (var st0)))
+
+(end)
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 78047a3..c86ddda 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
@@ -1878,6 +1878,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.CarCdr n
)
+ throws Throwable
{
/* TODO */
}
@@ -1887,6 +1888,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.ConsComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1896,6 +1898,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.AddElementComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1905,6 +1908,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.AddElementAtComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1914,6 +1918,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.AddElementsOfComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1923,6 +1928,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.Fold n
)
+ throws Throwable
{
/* TODO */
}
@@ -1932,6 +1938,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.MapComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1941,6 +1948,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.Range n
)
+ throws Throwable
{
/* TODO */
}
@@ -1950,6 +1958,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.RemoveAllOfElementComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1959,6 +1968,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.RemoveElementAtComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1968,6 +1978,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.RemoveElementComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1977,6 +1988,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.ReverseListComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1986,6 +1998,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.ShuffleComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -1995,6 +2008,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.MergeComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -2004,6 +2018,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.SubListComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -2013,6 +2028,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.PartitionComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -2022,6 +2038,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.SortComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -2031,6 +2048,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.FilterComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -2040,6 +2058,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.IndexedMapComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -2049,6 +2068,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.PushElementComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -2058,6 +2078,7 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.PopElementComputation n
)
+ throws Throwable
{
/* TODO */
}
@@ -2067,7 +2088,65 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor
(
final tonkadur.fate.v1.lang.computation.SetFieldsComputation n
)
+ throws Throwable
{
- /* TODO */
+ final ComputationCompiler target_cc;
+ final Register result;
+
+ target_cc = new ComputationCompiler(compiler);
+
+ n.get_target().get_visited_by(target_cc);
+
+ target_cc.generate_address();
+
+ if (target_cc.has_init())
+ {
+ init_instructions.add(target_cc.get_init());
+ }
+
+ result = reserve(target_cc.get_address().get_target_type());
+ result_as_computation = result.get_value();
+ result_as_address = result.get_address();
+
+ init_instructions.add
+ (
+ new SetValue(result_as_address, target_cc.get_computation())
+ );
+
+ target_cc.release_registers(init_instructions);
+
+ for
+ (
+ final Cons<String, tonkadur.fate.v1.lang.meta.Computation> entry:
+ n.get_assignments()
+ )
+ {
+ final ComputationCompiler cc;
+
+ cc = new ComputationCompiler(compiler);
+
+ entry.get_cdr().get_visited_by(cc);
+
+ if (cc.has_init())
+ {
+ init_instructions.add(cc.get_init());
+ }
+
+ init_instructions.add
+ (
+ new SetValue
+ (
+ new RelativeAddress
+ (
+ result_as_address,
+ new Constant(Type.STRING, entry.get_car()),
+ cc.get_computation().get_type()
+ ),
+ cc.get_computation()
+ )
+ );
+
+ cc.release_registers(init_instructions);
+ }
}
}
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 7ca4652..c8488d8 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
@@ -596,7 +596,54 @@ implements tonkadur.fate.v1.lang.meta.InstructionVisitor
)
throws Throwable
{
- /* TODO */
+ final ComputationCompiler target_cc;
+ final Address target;
+
+ target_cc = new ComputationCompiler(compiler);
+
+ n.get_target().get_visited_by(target_cc);
+
+ target = target_cc.get_address();
+
+ if (target_cc.has_init())
+ {
+ result.add(target_cc.get_init());
+ }
+ for
+ (
+ final Cons<String, tonkadur.fate.v1.lang.meta.Computation> entry:
+ n.get_assignments()
+ )
+ {
+ final ComputationCompiler cc;
+
+ cc = new ComputationCompiler(compiler);
+
+ entry.get_cdr().get_visited_by(cc);
+
+ if (cc.has_init())
+ {
+ result.add(cc.get_init());
+ }
+
+ result.add
+ (
+ new SetValue
+ (
+ new RelativeAddress
+ (
+ target,
+ new Constant(Type.STRING, entry.get_car()),
+ cc.get_computation().get_type()
+ ),
+ cc.get_computation()
+ )
+ );
+
+ cc.release_registers(result);
+ }
+
+ target_cc.release_registers(result);
}