コード例 #1
0
        protected internal virtual void VisitSpan(HelperHeaderSpan span)
        {
            Debug.Assert(InHelper);

            CurrentBlock.WriteLinePragma = DesignTimeMode;
            if (!DesignTimeMode)
            {
                CurrentBlock.Writer.WriteHiddenLinePragma();
            }

            // Write the prefix
            CurrentBlock.Writer.WriteHelperHeaderPrefix(Host.GeneratedClassContext.TemplateTypeName, isStatic: Host.StaticHelpers);
            CurrentBlock.MarkStartGeneratedCode();
            CurrentBlock.Writer.WriteSnippet(span.Content);
            CurrentBlock.MarkEndGeneratedCode();
            if (span.Complete)
            {
                CurrentBlock.Writer.WriteHelperHeaderSuffix(Host.GeneratedClassContext.TemplateTypeName);
            }
            CurrentBlock.Writer.InnerWriter.WriteLine();
            if (span.Complete)
            {
                CurrentBlock.Writer.WriteReturn();
                CurrentBlock.Writer.WriteStartConstructor(Host.GeneratedClassContext.TemplateTypeName);
                CurrentBlock.Writer.WriteStartLambdaDelegate(HelperWriterName);
                CurrentHelper.WroteHelperPrefix = true;
            }

            WriteBlockToHelperContent(CurrentBlock);

            CurrentBlock.ResetBuffer();
        }
コード例 #2
0
        protected virtual void CreateBlockRegions(PDFLayoutBlock containerBlock, PDFPositionOptions position, PDFColumnOptions columnOptions)
        {
            PDFRect unused  = containerBlock.CurrentRegion.UnusedBounds;
            PDFUnit yoffset = containerBlock.CurrentRegion.Height;

            PDFRect total = new PDFRect(PDFUnit.Zero, yoffset, unused.Width, unused.Height);

            if (position.Width.HasValue)
            {
                total.Width = position.Width.Value;
            }
            //ADDED for min/max sizes. Include the margins as we are making this the available width.
            else if (position.MaximumWidth.HasValue)
            {
                total.Width = position.MaximumWidth.Value + position.Margins.Left + position.Margins.Right;
            }


            if (position.Height.HasValue)
            {
                total.Height = position.Height.Value;
            }
            //ADDED for min/max sizes. Include the margins as we are making this the available height.
            else if (position.MaximumHeight.HasValue)
            {
                total.Height = position.MaximumHeight.Value + position.Margins.Top + position.Margins.Bottom;
            }

            CurrentBlock.InitRegions(total, position, columnOptions, this.Context);
        }
コード例 #3
0
ファイル: Tetris.cs プロジェクト: LeafChage/algorithm
    //入力をとって動作まで
    private void inputButton(ref CurrentBlock tmp)
    {
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            Debug.Log("right");
            tmp       = current.MoveRight();
            button_on = true;
        }
        else if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            Debug.Log("left");
            tmp       = current.MoveLeft();
            button_on = true;
        }
        else if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("rotate");
            tmp       = current.Rotate();
            button_on = true;

            transform.Rotate(new Vector3(0f, 0f, 90f));
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("under");
            moveUnder(ref tmp);
            button_on = true;
        }
    }
コード例 #4
0
 /// <summary>
 /// Event handler from the input class that get's triggered when input is available
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void OnKeyPressed(object sender, KeyEventArgs args)
 {
     if (args.Key == KeyEventArgs.Keys.RotateL)
     {
         CurrentBlock.SafeRotate(gameBoard);
     }
     if (args.Key == KeyEventArgs.Keys.Left)
     {
         CurrentBlock.SafeMoveLeft(gameBoard);
     }
     if (args.Key == KeyEventArgs.Keys.Right)
     {
         CurrentBlock.SafeMoveRight(gameBoard);
     }
     if (args.Key == KeyEventArgs.Keys.Down)
     {
         CurrentBlock.SafeFall(gameBoard);
     }
     if (args.Key == KeyEventArgs.Keys.Exit)
     {
         GameOver();
     }
     // Draw again after a key is pressed
     Draw();
 }
コード例 #5
0
        /// <summary>
        /// Realizes an indirect load instruction.
        /// </summary>
        /// <param name="type">The target type.</param>
        private void MakeLoadObject(Type type)
        {
            var address = CurrentBlock.Pop();

            address = CreateConversion(address, type.MakePointerType());
            CurrentBlock.Push(type, BuildLoad(Builder, address.LLVMValue, string.Empty));
        }
コード例 #6
0
        /// <summary>
        /// Realizes an arithmetic mul operation.
        /// </summary>
        /// <param name="overflow">True, if an overflow has to be checked.</param>
        private void MakeArithmeticMul(bool overflow)
        {
            if (overflow)
            {
                throw new NotSupportedException();
            }
            Type type           = CurrentBlock.PopArithmeticArgs(out LLVMValueRef left, out LLVMValueRef right);
            var  name           = string.Empty;
            var  basicValueType = type.GetBasicValueType();

            if (basicValueType.IsFloat())
            {
                if (Unit.HasFlags(CompileUnitFlags.UseGPUMath))
                {
                    MakeIntrinsicMathOperation(
                        type,
                        basicValueType == BasicValueType.Single ? MathMulF32 : MathMulF64,
                        left,
                        right);
                }
                else
                {
                    CurrentBlock.Push(type, BuildFMul(Builder, left, right, name));
                }
            }
            else
            {
                CurrentBlock.Push(type, BuildMul(Builder, left, right, name));
            }
        }
コード例 #7
0
        /// <summary>
        /// Realizes a new-array instruction.
        /// </summary>
        /// <param name="elementType">The element type of the array.</param>
        private void MakeNewArray(Type elementType)
        {
            var stackValue  = CurrentBlock.Pop();
            var arrayLength = stackValue.LLVMValue;

            if (!IsConstant(arrayLength))
            {
                throw CompilationContext.GetNotSupportedException(ErrorMessages.NotSupportedArrayCreation);
            }

            // Allocate the element data first in a local alloca
            var llvmElementType  = Unit.GetType(elementType);
            var arrayLengthValue = (int)ConstIntGetZExtValue(arrayLength);

            var llvmAllocaArrayType = ArrayType(llvmElementType, arrayLengthValue);
            var arrayData           = CreateTempAlloca(llvmAllocaArrayType);

            BuildStore(Builder, ConstNull(llvmAllocaArrayType), arrayData);

            // Array<T> = (T*, int32)
            var arrayType         = elementType.MakeArrayType();
            var llvmArrayType     = Unit.GetType(arrayType);
            var initialArrayValue = GetUndef(llvmArrayType);
            // Setup T*: (T*, undef)
            var basePtr          = BuildPointerCast(Builder, arrayData, PointerType(llvmElementType), string.Empty);
            var arrayWithPointer = BuildInsertValue(Builder, initialArrayValue, basePtr, 0, string.Empty);
            // Setup length: (T*, int32)
            var array = BuildInsertValue(Builder, arrayWithPointer, arrayLength, 1, string.Empty);

            // Push the final array value
            CurrentBlock.Push(arrayType, array);
        }
コード例 #8
0
        public override bool VisitStmtReturnValue([NotNull] GamaParser.StmtReturnValueContext context)
        {
            if (Self.ReturnType == InstanceTypes.Void)
            {
                NamespaceContext.Context.AddError(new ErrorVoidReturnsValue(context));
                return(false);
            }

            var val = VisitExpression(Self.ReturnType, context.expr());

            if (val == null)
            {
                return(false);
            }

            if (Self.ReturnType != val.Type)
            {
                NamespaceContext.Context.AddError(new ErrorTypeMismatch(context.expr()));
                return(false);
            }

            /* LLVM */
            CurrentBlock.PositionBuilderAtEnd(Builder);
            Builder.BuildRet(val.Value);

            return(true);
        }
コード例 #9
0
        public int Finish()
        {
            // Assuming current block is last block
            CurrentBlock.PositionBuilderAtEnd(Builder);
            if (!CurrentBlock.HasTerminator())
            {
                if (Self.ReturnType != InstanceTypes.Void)
                {
                    // TODO: fix your sh*tty error system (and error generator too)
                    // ALSO: possibly add (and improve) super konsole lib
                    NamespaceContext.Context.AddError(new GamaError("Function did not return a value, did you meant to use void return type? Expected {0} got nothing.", Self.ReturnType.Name));
                    return(-1);
                }
                // If self is void, no need to worry, just BuildRetVoid()
                Builder.BuildRetVoid();
            }

            Builder.Dispose();

            // Run optimizations of self
            // new Optimizers.AllocToEntry().Visit(this);
            // new Optimizers.ControlFlowEliminator().Visit(this);
            // new Optimizers.DeadBlockEliminator().Visit(this);

            return(0);
        }
コード例 #10
0
        public override bool VisitStmtVarDefBase([NotNull] GamaParser.StmtVarDefBaseContext context)
        {
            var name = context.Symbol().GetText();
            var val  = Top.FindValue(name);

            // Duplicate variable definition (parent frames can have same variable, it will be overriden in current frame)
            if (val != null)
            {
                NamespaceContext.Context.AddError(new ErrorDuplicateVariable(context));
                return(false);
            }
            val = VisitExpression(context.expr());
            if (val == null)
            {
                return(false);
            }

            /* LLVM */
            CurrentBlock.PositionBuilderAtEnd(Builder);
            var alloc = Builder.BuildAlloca(val.Type.UnderlyingType, name);

            Builder.BuildStore(val.Value, alloc);

            Top.AddValue(name, new GamaValueRef(val.Type, alloc, true));

            return(true);
        }
コード例 #11
0
        /// <summary>
        /// Realizes a new-object operation that creates a new instance of a specified type.
        /// </summary>
        /// <param name="method">The target method.</param>
        private void MakeNewObject(MethodBase method)
        {
            var constructor = method as ConstructorInfo;

            if (constructor == null)
            {
                throw CompilationContext.GetInvalidILCodeException();
            }
            var type     = constructor.DeclaringType;
            var llvmType = Unit.GetType(type);

            // Use a temporary alloca to realize object creation
            // and initialize object with zero
            var tempAlloca = CreateTempAlloca(llvmType);

            BuildStore(Builder, ConstNull(llvmType), tempAlloca);

            // Invoke constructor for type
            Value[] values = new Value[constructor.GetParameters().Length + 1];
            values[0] = new Value(type.MakePointerType(), tempAlloca);
            CurrentBlock.PopMethodArgs(constructor, values, 1);
            CreateCall(constructor, values);

            // Push created instance on the stack
            if (type.IsValueType)
            {
                CurrentBlock.Push(type, BuildLoad(Builder, values[0].LLVMValue, string.Empty));
            }
            else
            {
                CurrentBlock.Push(values[0]);
            }
        }
コード例 #12
0
        /// <summary>
        /// Loads the length of an array.
        /// </summary>
        private void LoadArrayLength()
        {
            var array = CurrentBlock.Pop();

            Debug.Assert(array.ValueType.IsArray);
            CurrentBlock.Push(typeof(int), BuildExtractValue(Builder, array.LLVMValue, 1, "ldlen"));
        }
コード例 #13
0
        /// <summary>
        /// Realizes an arithmetic rem operation.
        /// </summary>
        /// <param name="forceUnsigned">True, if the comparison should be forced to be unsigned.</param>
        private void MakeArithmeticRem(bool forceUnsigned = false)
        {
            Type type           = CurrentBlock.PopArithmeticArgs(out LLVMValueRef left, out LLVMValueRef right);
            var  name           = string.Empty;
            var  basicValueType = type.GetBasicValueType();

            if (basicValueType.IsFloat())
            {
                if (Unit.HasFlags(CompileUnitFlags.UseGPUMath))
                {
                    MakeIntrinsicMathOperation(
                        type,
                        basicValueType == BasicValueType.Single ? MathRemF32 : MathRemF64,
                        left,
                        right);
                }
                else
                {
                    CurrentBlock.Push(type, BuildFRem(Builder, left, right, name));
                }
            }
            else if (forceUnsigned || basicValueType.IsUnsignedInt())
            {
                CurrentBlock.Push(type, BuildURem(Builder, left, right, name));
            }
            else
            {
                CurrentBlock.Push(type, BuildSRem(Builder, left, right, name));
            }
        }
コード例 #14
0
ファイル: Calls.cs プロジェクト: awesomedotnetcore/ILGPU
        /// <summary>
        /// Creates a call instruction to the given method with the given arguments.
        /// </summary>
        /// <param name="target">The target method to invoke.</param>
        /// <param name="args">The call arguments</param>
        private void CreateCall(MethodBase target, Value[] args)
        {
            var intrinsicContext = new InvocationContext(Builder, Method, target, args, this);
            // Check for remapping first
            var remappedContext = Unit.RemapIntrinsic(intrinsicContext);

            if (remappedContext != null)
            {
                intrinsicContext = remappedContext.Value;
            }

            // Early rejection for runtime-dependent methods
            VerifyNotRuntimeMethod(CompilationContext, intrinsicContext.Method);

            // Handle device functions
            if (!Unit.HandleIntrinsic(intrinsicContext, out Value? methodInvocationResult))
            {
                var method   = Unit.GetMethod(intrinsicContext.Method);
                var llvmArgs = new LLVMValueRef[args.Length];
                for (int i = 0, e = args.Length; i < e; ++i)
                {
                    llvmArgs[i] = args[i].LLVMValue;
                }
                var call = BuildCall(Builder, method.LLVMFunction, llvmArgs);
                if (!method.IsVoid)
                {
                    methodInvocationResult = new Value(method.ReturnType, call);
                }
            }
            if (methodInvocationResult.HasValue)
            {
                CurrentBlock.Push(methodInvocationResult.Value);
            }
        }
コード例 #15
0
ファイル: Way.cs プロジェクト: AskMeAgain/TangleChain-System
        public void Print()
        {
            CurrentBlock.Print();
            Console.WriteLine("==============================================================");

            Before?.Print();
        }
コード例 #16
0
        public LiveBuildHelperVM(IDominoProvider pFParameters, int pBlockSize, Core.Orientation orientation, bool MirrorX, bool MirrorY)
        {
            BlockSize            = pBlockSize;
            fParameters          = pFParameters;
            intField             = fParameters.GetBaseField(orientation, MirrorX, MirrorY);
            NextN                = 500;
            CountRow             = intField.GetLength(1);
            stonesPerLine        = intField.GetLength(0);
            CountBlock           = Convert.ToInt32(Math.Ceiling(((double)stonesPerLine / BlockSize)));
            SizeChanged          = new RelayCommand(o => { RefreshCanvas(); });
            MouseDown            = new RelayCommand(o => { CurrentBlock.Focus(); });
            PositionSnapshots    = new ObservableCollection <PositionSnapshot>();
            MakePositionSnapshot = new RelayCommand(o => {
                PositionSnapshots.RemoveAll(x => x.Column == SelectedBlock && x.Row == SelectedRow);
                if ((bool)o == true)
                {
                    PositionSnapshots.Insert(0, new PositionSnapshot()
                    {
                        Column = SelectedBlock, Row = SelectedRow
                    });
                }
                RaisePropertyChanged(nameof(PositionSnapshots));
            });
            GoToPositionSnapshot = new RelayCommand(o => { if (o is PositionSnapshot ps)
                                                           {
                                                               SelectedBlock = ps.Column; SelectedRow = ps.Row;
                                                           }
                                                    });
            ColumnConfig = new AvaloniaList <Column>
            {
                new Column()
                {
                    DataField = "DominoColor.mediaColor", Header = "", Class = "Color"
                },
                new Column()
                {
                    DataField = "DominoColor.name", Header = _("Name")
                },
                new Column()
                {
                    DataField = "ProjectCount[0]", Header = GetParticularString("Number of stones available", "Total")
                },
                new Column()
                {
                    DataField = "ProjectCount[1]", Header = GetParticularString("Remaining number of stones", "Remaining"), Class = "Count"
                },
                new Column()
                {
                    DataField = "ProjectCount[2]", Header = string.Format(GetParticularString("Dominoes of the given color within the next {0}", "Next {0}"), NextN)
                }
            };

            OpenPopup = new RelayCommand(x => { FillColorList(); PopupOpen = true; });

            CurrentStones = new ObservableCollection <SolidColorBrush>();
            HistStones    = new ObservableCollection <SolidColorBrush>();
            ColorNames    = new ObservableCollection <ColorAmount>();

            RefreshCanvas();
        }
コード例 #17
0
ファイル: Variables.cs プロジェクト: awesomedotnetcore/ILGPU
        /// <summary>
        /// Loads a value of the given type from an unsafe memory address.
        /// </summary>
        /// <param name="type">The type of the value to load.</param>
        private void LoadIndirect(Type type)
        {
            var address = CurrentBlock.Pop(type.MakePointerType());
            var load    = BuildLoad(Builder, address.LLVMValue, "ldind");

            CurrentBlock.Push(type, load);
        }
コード例 #18
0
ファイル: Variables.cs プロジェクト: awesomedotnetcore/ILGPU
        /// <summary>
        /// Stores a value to an unsafe address.
        /// </summary>
        /// <param name="type">The type of the value to store.</param>
        private void StoreIndirect(Type type)
        {
            var value   = CurrentBlock.Pop(type);
            var address = CurrentBlock.Pop(type.MakePointerType());

            BuildStore(Builder, value.LLVMValue, address.LLVMValue);
        }
コード例 #19
0
        public override bool VisitStmtAssign([NotNull] GamaParser.StmtAssignContext context)
        {
            ExpressionCompiler.PushLoad(false);
            var lhs = VisitExpression(context.expr(0));

            ExpressionCompiler.PopLoad();

            if (lhs == null)
            {
                return(false);
            }

            if (!lhs.IsModifiableLValue)
            {
                NamespaceContext.Context.AddError(new ErrorAssignToNonModLValue(context.expr(0)));
                return(false);
            }

            var value = VisitExpression(lhs.Type, context.expr(1));

            if (value == null)
            {
                NamespaceContext.Context.AddError(new ErrorTypeMismatch(context.expr(1)));
                return(false);
            }

            /* LLVM */
            CurrentBlock.PositionBuilderAtEnd(Builder);
            Builder.BuildStore(value.Value, lhs.Value);
            return(true);
        }
コード例 #20
0
ファイル: Variables.cs プロジェクト: awesomedotnetcore/ILGPU
        /// <summary>
        /// Loads a variable address. This can be an argument or a local reference.
        /// </summary>
        /// <param name="var">The variable reference.</param>
        private void LoadVariableAddress(VariableRef var)
        {
            Debug.Assert(var.RefType == VariableRefType.Argument || var.RefType == VariableRefType.Local);
            var value = variables[var];

            CurrentBlock.Push(value.ValueType.MakePointerType(), value.LLVMValue);
        }
コード例 #21
0
        /// <summary>
        /// Loads the value of a field specified by the given metadata token.
        /// </summary>
        /// <param name="field">The field.</param>
        private void LoadField(FieldInfo field)
        {
            var value = CurrentBlock.Pop();
            var name  = string.Empty;

            if (value.ValueType.IsTreatedAsPtr())
            {
                var address = LoadFieldAddress(field, value);
                CurrentBlock.Push(field.FieldType, BuildLoad(Builder, address, name));
            }
            else
            {
                // It is a value object
                do
                {
                    var mappedType = Unit.GetObjectType(value.ValueType);
                    if (mappedType.TryResolveOffset(field, out int offset))
                    {
                        value = new Value(field.FieldType, BuildExtractValue(Builder, value.LLVMValue, offset, name));
                        break;
                    }
                    var baseType = value.ValueType.BaseType;
                    if (baseType == null)
                    {
                        throw new InvalidOperationException();
                    }
                    value = new Value(baseType, BuildExtractValue(Builder, value.LLVMValue, 0, name));
                }while (value.ValueType.BaseType != null);
                CurrentBlock.Push(value);
            }
        }
コード例 #22
0
        /// <summary>
        /// Realizes an indirect store instruction.
        /// </summary>
        /// <param name="type">The target type.</param>
        private void MakeStoreObject(Type type)
        {
            var value   = CurrentBlock.Pop(type);
            var address = CurrentBlock.Pop();

            address = CreateConversion(address, type.MakePointerType());
            BuildStore(Builder, value.LLVMValue, address.LLVMValue);
        }
コード例 #23
0
        /// <summary>
        /// Stores a value to a field.
        /// </summary>
        /// <param name="field">The field.</param>
        private void StoreField(FieldInfo field)
        {
            var value        = CurrentBlock.Pop(field.FieldType);
            var fieldValue   = CurrentBlock.Pop();
            var fieldAddress = LoadFieldAddress(field, fieldValue);

            BuildStore(Builder, value.LLVMValue, fieldAddress);
        }
コード例 #24
0
        /// <summary>
        /// Loads a static field specified by the given metadata token.
        /// </summary>
        /// <param name="field">The field.</param>
        private void LoadStaticField(FieldInfo field)
        {
            VerifyStaticFieldLoad(CompilationContext, Unit.Flags, field);

            var value = field.GetValue(null);

            CurrentBlock.Push(field.FieldType, Unit.GetValue(field.FieldType, value));
        }
コード例 #25
0
ファイル: Constants.cs プロジェクト: awesomedotnetcore/ILGPU
        /// <summary>
        /// Loads the constant null.
        /// </summary>
        private void LoadNull()
        {
            var t = typeof(object);

            CurrentBlock.Push(
                t.MakePointerType(),
                ConstNull(Unit.GetType(t)));
        }
コード例 #26
0
ファイル: Player.cs プロジェクト: fxMem/Plot
        internal void MoveToNextLine()
        {
            var nextLine = CurrentBlock.GetNextLine(CurrentLine);

            TraceVerbose($"Internal: moving to next line {nextLine.Id.ToStringDebug()}");

            _progress.CurrentLineId = nextLine.Id;
        }
コード例 #27
0
 private void EndBlock()
 {
     //Debug.Log("EndBlock: " + CurrentBlock.Config);
     CurrentBlock.Close();
     //LoadScene("debriefing");
     LoadScene(null);
     menue.enabled = true;
     ContinueButton.Deactivate();
 }
コード例 #28
0
ファイル: Program.cs プロジェクト: gitter-badger/Incs
        private static void MakeDataField(string FileAddress)
        {
            var Bytes = System.IO.File.ReadAllBytes(FileAddress);

            CurrentBlock.NewBlock(() =>
            {
                CurrentBlock += $"public static readonly string Url =\"data:image/gif;base64,{Convert.ToBase64String(Bytes)}\";";
            });
        }
コード例 #29
0
    public void EndTrial()
    {
        bool blockFinished = CurrentBlock.EndCurrentTrial();

        if (blockFinished)
        {
            EndBlock();
        }
    }
コード例 #30
0
        /// <summary>
        /// Loads the address of an array element.
        /// </summary>
        private void LoadArrayElementAddress()
        {
            var idx   = CurrentBlock.PopInt();
            var array = CurrentBlock.Pop();

            Debug.Assert(array.ValueType.IsArray);
            var addr = ComputeArrayAddress(array.LLVMValue, idx.LLVMValue);

            CurrentBlock.Push(array.ValueType.GetElementType().MakePointerType(), addr);
        }