| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-09-14 22:55:18 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-09-14 22:55:18 +0200 | 
| commit | a7976e05d481ade628b3a31855dd34398646b33b (patch) | |
| tree | 3c3b6a1c1c21c66ddb119e20916ec22c4f94668c /src | |
| parent | ccd6e9c7548b8097e5503a2087d41366bbf18846 (diff) | |
Fully implements cons, car, and cdr.
Diffstat (limited to 'src')
4 files changed, 139 insertions, 2 deletions
| 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 c86ddda..f7893be 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 @@ -15,6 +15,7 @@ import tonkadur.wyrd.v1.lang.meta.Instruction;  import tonkadur.wyrd.v1.lang.type.Type;  import tonkadur.wyrd.v1.lang.type.PointerType; +import tonkadur.wyrd.v1.lang.type.DictType;  import tonkadur.wyrd.v1.lang.instruction.SetValue;  import tonkadur.wyrd.v1.lang.instruction.SetPC; @@ -23,6 +24,7 @@ import tonkadur.wyrd.v1.compiler.util.BinarySearch;  import tonkadur.wyrd.v1.compiler.util.IfElse;  import tonkadur.wyrd.v1.compiler.util.If;  import tonkadur.wyrd.v1.compiler.util.RemoveAt; +import tonkadur.wyrd.v1.compiler.util.CreateCons;  import tonkadur.wyrd.v1.compiler.util.IterativeSearch;  import tonkadur.wyrd.v1.compiler.util.CountOccurrences; @@ -1880,7 +1882,25 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor     )     throws Throwable     { -      /* TODO */ +      final ComputationCompiler address_cc; + +      address_cc = new ComputationCompiler(compiler); + +      n.get_parent().get_visited_by(address_cc); + +      assimilate(address_cc); + +      result_as_address = +         new RelativeAddress +         ( +            address_cc.get_address(), +            new Constant +            ( +               Type.STRING, +               (n.is_car()? "0" : "1") +            ), +            TypeCompiler.compile(compiler, n.get_type()) +         );     }     @Override @@ -1890,7 +1910,46 @@ implements tonkadur.fate.v1.lang.meta.ComputationVisitor     )     throws Throwable     { -      /* TODO */ +      final Address car_addr, cdr_addr; +      final ComputationCompiler car_compiler, cdr_compiler; +      final Register result; + +      result = reserve(DictType.WILD); +      result_as_address = result.get_address(); +      result_as_computation = result.get_value(); + +      car_compiler = new ComputationCompiler(compiler); + +      n.get_car().get_visited_by(car_compiler); + +      if (car_compiler.has_init()) +      { +         init_instructions.add(car_compiler.get_init()); +      } + +      cdr_compiler = new ComputationCompiler(compiler); + +      n.get_cdr().get_visited_by(cdr_compiler); + +      if (cdr_compiler.has_init()) +      { +         init_instructions.add(cdr_compiler.get_init()); +      } + +      init_instructions.add +      ( +         CreateCons.generate +         ( +            compiler.registers(), +            compiler.assembler(), +            result_as_address, +            car_compiler.get_computation(), +            cdr_compiler.get_computation() +         ) +      ); + +      car_compiler.release_registers(init_instructions); +      cdr_compiler.release_registers(init_instructions);     }     @Override 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 3792080..f820d7b 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 @@ -32,6 +32,11 @@ public class TypeCompiler              );        } +      if (fate_type instanceof tonkadur.fate.v1.lang.type.ConsType) +      { +         return DictType.WILD; +      } +        if (fate_type instanceof tonkadur.fate.v1.lang.type.CollectionType)        {           return diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/util/CreateCons.java b/src/core/src/tonkadur/wyrd/v1/compiler/util/CreateCons.java new file mode 100644 index 0000000..a13feec --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/compiler/util/CreateCons.java @@ -0,0 +1,67 @@ +package tonkadur.wyrd.v1.compiler.util; + +import java.util.List; +import java.util.ArrayList; + +import tonkadur.wyrd.v1.lang.Register; + +import tonkadur.wyrd.v1.lang.type.Type; + +import tonkadur.wyrd.v1.lang.meta.Instruction; +import tonkadur.wyrd.v1.lang.meta.Computation; + +import tonkadur.wyrd.v1.lang.computation.Constant; +import tonkadur.wyrd.v1.lang.computation.Address; +import tonkadur.wyrd.v1.lang.computation.RelativeAddress; + +import tonkadur.wyrd.v1.lang.instruction.SetValue; +import tonkadur.wyrd.v1.lang.instruction.Initialize; + +import tonkadur.wyrd.v1.compiler.util.registers.RegisterManager; + +public class CreateCons +{ +   /* Utility Class */ +   private CreateCons () {} + +   /* +    */ +   public static Instruction generate +   ( +      final RegisterManager registers, +      final InstructionManager assembler, +      final Address target, +      final Computation car_value, +      final Computation cdr_value +   ) +   { +      final Address car_address, cdr_address; +      final List<Instruction> result; + +      result = new ArrayList<Instruction>(); + +      car_address = +         new RelativeAddress +         ( +            target, +            new Constant(Type.STRING, "0"), +            car_value.get_type() +         ); + +      cdr_address = +         new RelativeAddress +         ( +            target, +            new Constant(Type.STRING, "1"), +            car_value.get_type() +         ); + +      result.add(new Initialize(car_address)); +      result.add(new Initialize(cdr_address)); + +      result.add(new SetValue(car_address, car_value)); +      result.add(new SetValue(cdr_address, cdr_value)); + +      return assembler.merge(result); +   } +} diff --git a/src/core/src/tonkadur/wyrd/v1/lang/instruction/Initialize.java b/src/core/src/tonkadur/wyrd/v1/lang/instruction/Initialize.java index 04a039e..88f3b87 100644 --- a/src/core/src/tonkadur/wyrd/v1/lang/instruction/Initialize.java +++ b/src/core/src/tonkadur/wyrd/v1/lang/instruction/Initialize.java @@ -24,6 +24,12 @@ public class Initialize extends Instruction        this.type = type;     } +   public Initialize (final Address address) +   { +      this.address = address; +      this.type = address.get_target_type(); +   } +     /**** Accessors ************************************************************/     public Address get_address ()     { | 


