Exemplo n.º 1
0
 private static void Initialize(this FLFunction function, SerializableFLFunction serializableFunction,
                                FLProgram script,
                                FLInstructionSet instructionSet)
 {
     function.SetInstructions(serializableFunction.Instructions.Select(x => x.Initialize(script, instructionSet))
                              .ToList());
 }
Exemplo n.º 2
0
        public override object Process(object o)
        {
            SerializableFLProgram input = (SerializableFLProgram)o;
            bool removedOne             = true;

            while (removedOne)
            {
                removedOne = false;
                foreach (SerializableFLFunction f in input.Functions)
                {
                    for (int i = f.Instructions.Count - 1; i >= 0; i--)
                    {
                        SerializableFLInstruction t = f.Instructions[i];
                        if (t.InstructionKey == "jmp" &&
                            t.Arguments[0].ArgumentCategory == InstructionArgumentCategory.Function)
                        {
                            string fname = t.Arguments[0].Identifier;
                            SerializableFLFunction func = input.Functions.First(x => x.Name == fname);
                            f.Instructions.RemoveAt(i);
                            f.Instructions.AddRange(func.Instructions);
                            removedOne = true;
                        }
                    }
                }
            }
            return(input);
        }
        public override void Serialize(PrimitiveValueWrapper s, object obj)
        {
            SerializableFLFunction input = (SerializableFLFunction)obj;

            s.Write(ResolveName(input.Name));
            s.Write(input.Instructions.Count);

            for (int i = 0; i < input.Instructions.Count; i++)
            {
                instructionSerializer.Serialize(s, input.Instructions[i]);
            }
        }
        protected override void Validate(
            SerializableFLProgram prog, SerializableFLFunction func,
            SerializableFLInstruction inst, SerializableFLInstructionArgument arg)
        {
            FLExecutableElementModifiers calledFunc =
                prog.Functions.FirstOrDefault(x => x.Name == arg.Identifier)?.Modifiers ??
                prog.ExternalFunctions.First(x => x.Name == arg.Identifier).Modifiers;

            if (calledFunc.NoCall)
            {
                throw new FLInvalidFLElementModifierUseException(
                          func.Name,
                          FLKeywords.NoCallKeyword,
                          $"Can not use instruction {inst.InstructionKey} with a Defined Function that is marked with the nocall modifier."
                          );
            }
        }
Exemplo n.º 5
0
        protected override void Validate(
            SerializableFLProgram prog, SerializableFLFunction func,
            SerializableFLInstruction inst, SerializableFLInstructionArgument arg)
        {
            SerializableFLBuffer buf = prog.DefinedBuffers.First(x => x.Name == arg.Identifier);

            if (buf.Modifiers.IsReadOnly)
            {
                throw new FLInvalidFLElementModifierUseException(
                          func.Name,
                          FLKeywords.ReadOnlyBufferModifier,
                          $"Can not use instruction {inst.InstructionKey} with a static buffer."
                          );
            }

            if (buf.Modifiers.IsArray)
            {
                throw new FLInvalidFLElementModifierUseException(
                          func.Name,
                          FLKeywords.ArrayKey,
                          $"Can not use instruction {inst.InstructionKey} with an array buffer."
                          );
            }
        }
 protected abstract void Validate(
     SerializableFLProgram prog, SerializableFLFunction func,
     SerializableFLInstruction inst, SerializableFLInstructionArgument arg);
        public override object Process(object o)
        {
            SerializableFLProgram input = (SerializableFLProgram)o;
            Dictionary <string, SerializableFLFunction> staticFunctions =
                new Dictionary <string, SerializableFLFunction>();

            for (int i = input.Functions.Count - 1; i >= 0; i--)
            {
                SerializableFLFunction staticFunction = input.Functions[i];
                if (!staticFunction.Modifiers.IsStatic || staticFunction.Name == FLKeywords.EntryFunctionKey)
                {
                    continue;
                }

                string funcName = "_ext_" + staticFunction.Name;
                staticFunctions.Add(funcName, staticFunction);
                input.Functions.RemoveAt(i);

                List <string> source = staticFunction.Instructions.Select(x => x.ToString()).ToList();
                source.Insert(0, FLKeywords.EntryFunctionKey + ":");
                FLParserInput pi = new FLParserInput(
                    "Exported Function: " +
                    staticFunction
                    .Name,
                    source.ToArray(),
                    false
                    );
                pi.KernelData = new List <EmbeddedKernelData>(input.KernelData);
                SerializableFLProgram ext = (SerializableFLProgram)Target.Process(pi);


                List <string> mods = new List <string> {
                    FLKeywords.NoJumpKeyword
                };

                if (staticFunction.Modifiers.ComputeOnce)
                {
                    mods.Add(FLKeywords.ComputeOnceKeyword);
                }


                FLExecutableElementModifiers e = new FLExecutableElementModifiers(funcName, mods.ToArray());
                input.ExternalFunctions.Add(new SerializableExternalFLFunction(funcName, ext, e));
            }

            foreach (KeyValuePair <string, SerializableFLFunction> staticFunction in staticFunctions)
            {
                foreach (SerializableFLFunction serializableFlFunction in input.Functions)
                {
                    foreach (SerializableFLInstruction serializableFlInstruction in serializableFlFunction.Instructions)
                    {
                        for (int i = 0; i < serializableFlInstruction.Arguments.Count; i++)
                        {
                            SerializableFLInstructionArgument arg = serializableFlInstruction.Arguments[i];
                            if (arg.Identifier == staticFunction.Value.Name)
                            {
                                serializableFlInstruction.Arguments[i] =
                                    new SerializeExternalFunctionArgument(staticFunction.Key);
                            }
                        }
                    }
                }
            }

            return(input);
        }