Exemple #1
0
 public void Should_call_target_within_target()
 {
     var targetsBuilt = new List<string>();
     var project = new CallTarget();
     project.RunHandler += target => targetsBuilt.Add(target.Name);
     project.Run("calling");
     Assert.That(targetsBuilt, Is.EqualTo(new[] { "Calling", "Called", "BeforeCalled" }));
 }
Exemple #2
0
 /// <summary>
 /// Provides the implementation for operations that get member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as getting a value for a property.
 /// </summary>
 /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
 /// <param name="result">The result of the get operation. For example, if the method is called for a property, you can assign the property value to <paramref name="result" />.</param>
 /// <returns>
 /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.)
 /// </returns>
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     if (!base.TryGetMember(binder, out result))
     {
         var tInterface = CallTarget.GetType().GetInterfaces().Single(it => it.Name == _extendedType.Name);
         result = new Invoker(binder.Name,
                              tInterface.IsGenericType ? tInterface.GetGenericArguments() : new Type[] {}, null, this);
     }
     return(true);
 }
 public MethodCallContext(FuncActionDispatcher beforeSimulation,
                          FuncActionDispatcher afterSimulation, FuncActionDispatcher mainThread, ICallable directCall,
                          CallTarget callTarget)
 {
     BeforeSimulation  = beforeSimulation;
     AfterSimulation   = afterSimulation;
     MainThread        = mainThread;
     DirectCall        = directCall;
     DefaultCallTarget = callTarget;
 }
Exemple #4
0
        public void NullFirstArgumentOnStaticMethod()
        {
            CallTarget call = (CallTarget)Delegate.CreateDelegate(
                typeof(CallTarget),
                null,
                GetType().GetMethod("Target", BindingFlags.NonPublic | BindingFlags.Static));

            Assert.IsNotNull(call);
            Assert.IsNull(call.Target);
            Assert.IsNull(call());
        }
Exemple #5
0
 public override void AcceptChildren(WSqlFragmentVisitor visitor)
 {
     if (Parameters != null)
     {
         var index = 0;
         for (var count = Parameters.Count; index < count; ++index)
         {
             Parameters[index].Accept(visitor);
         }
     }
     if (CallTarget != null)
     {
         CallTarget.Accept(visitor);
     }
     base.AcceptChildren(visitor);
 }
Exemple #6
0
        public override bool Execute()
        {
            var allSucceeded = true;

            Targets.AsParallel().Where(target => !string.IsNullOrWhiteSpace(target)).ForAll(target =>
            {
                var callTarget = new CallTarget
                {
                    Targets                 = new [] { target },
                    BuildEngine             = BuildEngine,
                    HostObject              = HostObject,
                    RunEachTargetSeparately = true,
                    UseResultsCache         = false
                };
                var success  = callTarget.Execute();
                allSucceeded = allSucceeded && success;
            });
            return(allSucceeded);
        }
        public ICallable GetCallable(CallTarget callTarget)
        {
            switch (callTarget)
            {
            case CallTarget.CurrentThread:
                return(DirectCall);

            case CallTarget.BeforeSimulation:
                return(BeforeSimulation);

            case CallTarget.AfterSimulation:
                return(AfterSimulation);

            case CallTarget.MainThread:
                return(MainThread);

            default:
                throw new ArgumentOutOfRangeException(nameof(callTarget), callTarget, null);
            }
        }
        public override void ExitFunctionDeclarationHeader(CodeElementsParser.FunctionDeclarationHeaderContext context)
        {
            // Register call parameters (shared storage areas) information at the CodeElement level
            var function = (FunctionDeclarationHeader)CodeElement;
            var target   = new CallTarget()
            {
                Name = function.FunctionName
            };
            int parametersCount = function.Profile.InputParameters.Count
                                  + function.Profile.InoutParameters.Count
                                  + function.Profile.OutputParameters.Count
                                  + (function.Profile.ReturningParameter != null ? 1 : 0);

            target.Parameters = new CallTargetParameter[parametersCount];
            int i = 0;

            foreach (var param in function.Profile.InputParameters)
            {
                target.Parameters[i++] = CreateCallTargetParameter(param);
            }
            foreach (var param in function.Profile.OutputParameters)
            {
                target.Parameters[i++] = CreateCallTargetParameter(param);
            }
            foreach (var param in function.Profile.InoutParameters)
            {
                target.Parameters[i++] = CreateCallTargetParameter(param);
            }
            if (function.Profile.ReturningParameter != null)
            {
                target.Parameters[i++] = CreateCallTargetParameter(function.Profile.ReturningParameter);
            }
            function.CallTarget = target;

            Context     = context;
            CodeElement = function;
            FunctionDeclarationTypeChecker.OnCodeElement(function, context);
        }
        public static void CheckMemoryDump(string filename)
        {
            string objFilepath = String.Format("Assembly/Samples/{0}.obj", filename);
            Stream objStream   = PlatformSpecific.GetStreamForProjectFile(objFilepath);

            string asmFilepath = String.Format("Assembly/DisassemblerResults/{0}.disasm", filename);
            Stream asmStream   = PlatformSpecific.GetStreamForProjectFile(asmFilepath);

            string referenceAsmText = null;

            using (StreamReader sr = new StreamReader(asmStream))
            {
                referenceAsmText = sr.ReadToEnd();
            }

            MemoryMap  memoryMap  = new MemoryMap(65536);
            CallTarget entryPoint = new CallTarget(new CallSource(CallSourceType.Boot, 0, null), 0);
            Program    program    = Disassembler.GenerateProgram(objFilepath, objStream, 0, new CallTarget[] { entryPoint }, memoryMap);

            if (program.ToString() != referenceAsmText)
            {
                throw new Exception(String.Format("Disassembly of program {0} does not match reference text", filename));
            }
        }
Exemple #10
0
        private WCallTarget ParseCallTarget(CallTarget callTarget)
        {
            if (callTarget == null)
                return null;
            WCallTarget result;
            var tCallTarget = callTarget as MultiPartIdentifierCallTarget;
            if (tCallTarget != null)
            {
                result = new WMultiPartIdentifierCallTarget
                {
                    Identifiers = ParseMultiPartIdentifier(tCallTarget.MultiPartIdentifier)
                };
            }
            else
            {
                throw new NotImplementedException();
            }

            return result;
        }
 public override void ExplicitVisit(CallTarget fragment)
 {
     _fragments.Add(fragment);
 }
Exemple #12
0
 public CallEffect(CallTarget target, Ref <TReturnData> returnValue, params object[] args)
 {
     this.returnValue = returnValue;
     this.target      = target;
     this.args        = args;
 }
Exemple #13
0
 public override int GetHashCode()
 {
     return(CallTarget != null ? CallTarget.GetHashCode() : 0);
 }
Exemple #14
0
        /// <summary>
        /// Invokes the static method.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] args)
        {
            var staticType = InvokeContext.CreateStatic;
            var nameArgs   = InvokeMemberName.Create;

            var tList = new List <object> {
                CallTarget
            };

            tList.AddRange(args);

            object result        = null;
            var    sucess        = false;
            var    exceptionList = new List <Exception>();

            var tGenericPossibles = new List <Type[]>();

            if (name.GenericArgs != null && name.GenericArgs.Length > 0)
            {
                var tInterface    = CallTarget.GetType().GetInterfaces().Single(it => it.Name == _extendedType.Name);
                var tTypeGenerics = (tInterface.IsGenericType ? tInterface.GetGenericArguments()
                                            : new Type[] { }).Concat(name.GenericArgs).ToArray();

                tGenericPossibles.Add(tTypeGenerics);
                tGenericPossibles.Add(name.GenericArgs);
            }
            else
            {
                tGenericPossibles.Add(null);
            }



            foreach (var sType in _staticTypes)
            {
                foreach (var tGenericPossible in tGenericPossibles)
                {
                    try
                    {
                        result = Dynamic.InvokeMember(staticType(sType), nameArgs(name.Name, tGenericPossible), tList.ToArray());
                        sucess = true;
                        break;
                    }
                    catch (RuntimeBinderException ex)
                    {
                        exceptionList.Add(ex);
                    }
                }
            }

            if (!sucess)
            {
                throw exceptionList.First();
            }


            Type tOutType;

            if (TryTypeForName(name.Name, out tOutType))
            {
                if (tOutType.IsInterface)
                {
                    var tIsGeneric = tOutType.IsGenericType;
                    if (tOutType.IsGenericType)
                    {
                        tOutType = tOutType.GetGenericTypeDefinition();
                    }

                    if (InstanceHints.Select(it => tIsGeneric && it.IsGenericType ? it.GetGenericTypeDefinition() : it)
                        .Contains(tOutType))
                    {
                        result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
                    }
                }
            }
            else
            {
                if (IsExtendedType(result))
                {
                    result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
                }
            }

            return(result);
        }
Exemple #15
0
 public CallOn(CallTarget value)
 {
     Target = value;
 }
Exemple #16
0
	void AddConversion (CallTarget converter)
	{
	}
 public sealed override void ExplicitVisit(CallTarget node)
 {
     base.ExplicitVisit(node);
 }
 public sealed override void Visit(CallTarget node)
 {
     base.Visit(node);
 }
 public ThreadCallEffect(CallTarget target, Ref <TReturnData> returnValue, params object[] args)
     : base(target, returnValue, args)
 {
 }
Exemple #20
0
 public override void ExplicitVisit(CallTarget node) { this.action(node); }