Changeset 5499 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler
- Timestamp:
- 02/16/11 19:01:00 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Property svn:ignore
-
old new 2 2 obj 3 3 HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs 4 *.user
-
- Property svn:ignore
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/Instruction.cs
r5445 r5499 21 21 22 22 23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Compiler { 24 // total size of this struct should be small to improve cache access while executing the code 25 // should be aligned to 8/16/32 byte 26 // size = 4(8) + 1 + 1 + 2 = 8 (12) 23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 24 // total size of this class should be small to improve cache access while executing the code 27 25 public class Instruction { 28 26 // the tree node can hold additional data that is necessary for the execution of this instruction 29 public SymbolicExpressionTreeNode dynamicNode;27 public ISymbolicExpressionTreeNode dynamicNode; 30 28 // op code of the function that determines what operation should be executed 31 29 public byte opCode; -
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Compiler/SymbolicExpressionTreeCompiler.cs
r5445 r5499 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;26 25 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Compiler{26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 28 27 public class SymbolicExpressionTreeCompiler { 29 28 private Dictionary<string, ushort> entryPoint = new Dictionary<string, ushort>(); 30 29 private List<Func<Instruction, Instruction>> postInstructionCompiledHooks = new List<Func<Instruction, Instruction>>(); 31 30 32 public Instruction[] Compile(SymbolicExpressionTree tree, Func< SymbolicExpressionTreeNode, byte> opCodeMapper) {31 public Instruction[] Compile(SymbolicExpressionTree tree, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper) { 33 32 List<Instruction> code = new List<Instruction>(); 34 33 entryPoint.Clear(); 35 34 // compile main body branches 36 foreach (var branch in tree.Root. SubTrees[0].SubTrees) {35 foreach (var branch in tree.Root.GetSubTree(0).SubTrees) { 37 36 code.AddRange(Compile(branch, opCodeMapper)); 38 37 } … … 60 59 } 61 60 62 private IEnumerable<Instruction> Compile( SymbolicExpressionTreeNode branch, Func<SymbolicExpressionTreeNode, byte> opCodeMapper) {61 private IEnumerable<Instruction> Compile(ISymbolicExpressionTreeNode branch, Func<ISymbolicExpressionTreeNode, byte> opCodeMapper) { 63 62 foreach (var node in branch.IterateNodesPrefix()) { 64 63 Instruction instr = new Instruction(); 65 if (node.SubTrees.Count > 255) throw new ArgumentException("Number of subtrees is too big (>255)"); 66 instr.nArguments = (byte)node.SubTrees.Count; 64 int subTreesCount = node.SubTrees.Count(); 65 if (subTreesCount > 255) throw new ArgumentException("Number of subtrees is too big (>255)"); 66 instr.nArguments = (byte)subTreesCount; 67 67 instr.opCode = opCodeMapper(node); 68 68 if (node.Symbol is Argument) {
Note: See TracChangeset
for help on using the changeset viewer.