Пример #1
0
 public override void Print(TextWriter writer, string indent)
 {
     writer.WriteLine($"{InstructionWriter.GetTypeID(values[0], true)}[{values.Count}]");
     for (int i = 0; i < values.Count; i++)
     {
         Symbol.Print(writer, i == values.Count - 1, false, indent, values[i]);
     }
 }
Пример #2
0
 public void BasicCodegen(TextWriter writer, bool simple)
 {
     InstructionWriter.WriteHeader(writer, simple);
     InstructionWriter.WriteInstructionOp(writer, Opcodes.INIT, simple);
     writer.WriteLine($"{maxValues} {maxObjects}");
     foreach (BaseNode child in children)
     {
         child.BasicCodegen(writer, simple);
     }
     writer.WriteLine("}");
 }
Пример #3
0
 public override void BasicCodegen(TextWriter writer, bool simple)
 {
     foreach (Instruction node in nodes)
     {
         InstructionWriter.WriteInstructionOp(writer, (Opcodes)node.OpCode, simple);
         foreach (object obj in node.Parameters)
         {
             writer.Write($" {obj}");
         }
         writer.WriteLine();
     }
 }
Пример #4
0
        public override void BasicCodegen(TextWriter writer, bool simple)
        {
            InstructionWriter.WriteInstructionOp(writer, Opcodes.PUSH_MAP, simple);
            KeyValuePair <BaseNode, BaseNode> firstkvp = map.First();

            // Optimisation if they all are value nodes
            if (firstkvp.Key is ValueNode firstKey && firstkvp.Value is ValueNode firstValue)
            {
                string keyTypeID   = InstructionWriter.GetTypeID(firstKey.obj, simple);
                string valueTypeID = InstructionWriter.GetTypeID(firstValue.obj, simple);

                writer.WriteLine($"{keyTypeID} {valueTypeID}");
                InstructionWriter.WriteInstructionOp(writer, Opcodes.QUICK_SET_MAP, simple);
                writer.Write($"{keyTypeID} {valueTypeID}");
                foreach (KeyValuePair <BaseNode, BaseNode> kvp in map)
                {
                    ValueNode key   = (ValueNode)kvp.Key;
                    ValueNode value = (ValueNode)kvp.Value;
                    writer.Write($" {key.obj} {value.obj}");
                }
                writer.WriteLine();
            }
Пример #5
0
 public override void BasicCodegen(TextWriter writer, bool simple)
 {
     InstructionWriter.WriteInstructionOp(writer, Opcodes.PUSH_ARRAY, simple);
     // Check for onedimensional
     if (values[0] is ValueNode)
     {
         string typeID = InstructionWriter.GetTypeID(((ValueNode)values[0]).obj, simple);
         writer.WriteLine($"{typeID} {values.Count}");
         InstructionWriter.WriteInstructionOp(writer, Opcodes.ARRAY_CPY, simple);
         writer.Write($"{typeID} {values.Count}");
         foreach (BaseNode node in values)
         {
             writer.Write($" {(node as ValueNode).obj}");
         }
         writer.WriteLine();
     }
     else
     {
         // @TODO: Implement non one dimensional arrays
         throw new NotImplementedException();
     }
 }
Пример #6
0
        public override IEnumerable <Instruction> GetInstructions()
        {
            int typeID = InstructionWriter.GetTypeID(values[0]);

            yield return(new Instruction(Opcodes.PUSH_ARRAY, new object[] { typeID, values.Count }));

            if (values[0] is ValueNode)
            {
                // Simpler for 1D
                object[] parameters = new object[values.Count + 100];
                parameters[0] = typeID;
                parameters[1] = values.Count;

                for (int i = 0; i < values.Count; i++)
                {
                    parameters[2 + i] = ((ValueNode)values[i]).obj;
                }
                yield return(new Instruction(Opcodes.ARRAY_CPY, parameters));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Пример #7
0
 public override void BasicCodegen(TextWriter writer, bool simple)
 {
     InstructionWriter.WriteInstructionOp(writer, Opcodes.DE_INIT, simple);
     writer.WriteLine();
 }