コード例 #1
0
 internal RantProgram(string name, RantProgramOrigin type, RST rst)
 {
     Name       = name;
     Type       = type;
     Code       = null;
     SyntaxTree = rst;
 }
コード例 #2
0
        public void Test_RST(byte opcode)
        {
            ushort resetAddress = (ushort)(opcode & 0x38);

            ushort sp = 0x4242;
            ushort pc = 0x1122;

            var expectedState = new CpuState();

            expectedState.StackPointer   = (ushort)(sp - 2);
            expectedState.ProgramCounter = resetAddress;

            var actualState = new CpuState();

            actualState.StackPointer   = sp;
            actualState.ProgramCounter = pc;

            var memoryMock = new Mock <IRandomAccessMemory>();

            var instruction = new RST();

            instruction.Initialize(opcode);

            //act
            while (!instruction.IsFetchNecessary())
            {
                instruction.ExecuteCycle(actualState, memoryMock.Object);
            }

            TestHelper.AssertCpuState(expectedState, actualState);
            memoryMock.Verify(m => m.WriteByte((ushort)(sp - 1), (byte)(pc >> 8)), Times.Once);
            memoryMock.Verify(m => m.WriteByte((ushort)(sp - 2), (byte)(pc & 0x00FF)), Times.Once);
        }
コード例 #3
0
ファイル: RantRuntimeException.cs プロジェクト: thygrrr/rant3
 internal RantRuntimeException(Sandbox sb, RST rst, string errorMessageType = "err-generic-runtime",
                               params object[] errorArgs)
     : base(rst == null
         ? $"({sb.Pattern.Name}) {GetString(errorMessageType, errorArgs)}"
         : $"{GetString("src-line-col", sb.Pattern.Name, rst.Location.Line, rst.Location.Column)} {GetString(errorMessageType, errorArgs)}"
            )
 {
     Code           = sb.Pattern.Code;
     Line           = rst?.Location.Line ?? 0;
     Column         = rst?.Location.Column ?? 0;
     Index          = rst?.Location.Index ?? -1;
     RantStackTrace = sb.GetStackTrace();
 }
コード例 #4
0
 /// <summary>
 /// Saves the compiled program to the specified stream.
 /// </summary>
 /// <param name="stream">The stream to save the program to.</param>
 public void SaveToStream(Stream stream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException(nameof(stream));
     }
     using (var output = new EasyWriter(stream, Endian.Little, true))
     {
         output.WriteBytes(Encoding.ASCII.GetBytes(Magic));
         RST.SerializeRST(SyntaxTree, output);
     }
     stream.Flush();
 }
コード例 #5
0
        /// <summary>
        /// Creates a new RantObject instance from the specified object.
        /// </summary>
        /// <param name="obj">The value to assign to the object.</param>
        public RantObject(object obj)
        {
            if (obj == null)
            {
                return;
            }

            if (obj is string)
            {
                _string = obj.ToString();
                Type    = RantObjectType.String;
            }
            else if (obj is bool)
            {
                _boolean = (bool)obj;
                Type     = RantObjectType.Boolean;
            }
            else if (IsNumber(obj))
            {
                _number = (double)obj;
                Type    = RantObjectType.Number;
            }
            else if (obj is List <RantObject> )
            {
                _list = (List <RantObject>)obj;
                Type  = RantObjectType.List;
            }
            else if (obj.GetType().IsArray)
            {
                _list = ((object[])obj).Select(o => new RantObject(o)).ToList();
                Type  = RantObjectType.List;
            }
            else if (obj is RST)
            {
                _rst = (RST)obj;
                Type = RantObjectType.Action;
            }
        }
コード例 #6
0
        /// <summary>
        /// Loads a compiled Rant program from the specified stream.
        /// </summary>
        /// <param name="programName">The name to give to the program.</param>
        /// <param name="stream">The stream to load the program from.</param>
        /// <returns></returns>
        public static RantProgram LoadStream(string programName, Stream stream)
        {
            if (programName == null)
            {
                throw new ArgumentNullException(nameof(programName));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            using (var input = new EasyReader(stream))
            {
                if (Encoding.ASCII.GetString(input.ReadBytes(4)) != Magic)
                {
                    throw new InvalidDataException(GetString("err-pgmload-bad-magic"));
                }

                var rst = RST.DeserializeRST(input);

                // TODO: Use string table

                return(new RantProgram(programName, RantProgramOrigin.File, rst));
            }
        }
コード例 #7
0
 public Overload(SubroutineParameter[] parameters, RST body)
 {
     Params = parameters;
     Body   = body;
 }
コード例 #8
0
        public void DefineOverload(IEnumerable <SubroutineParameter> parameters, RST body)
        {
            var pArray = parameters.ToArray();

            _overloads[pArray.Length] = new Overload(pArray, body);
        }
コード例 #9
0
 internal override void SerializeData(EasyWriter writer)
 {
     writer.Write(Name);
     RST.SerializeRST(SyntaxTree, writer);
 }
コード例 #10
0
 internal override void DeserializeData(EasyReader reader)
 {
     Name       = reader.ReadString();
     SyntaxTree = RST.DeserializeRST(reader);
 }
コード例 #11
0
 public NMIHandler(Z80Cpu cpu)
 {
     _pcPush             = new PUSH(cpu, WideRegister.PC);
     _restartInstruction = new RST(cpu, 0x66);
 }
コード例 #12
0
 internal RantObject(RST rst)
 {
     Type = RantObjectType.Action;
     _rst = rst;
 }
コード例 #13
0
    public static void AddMesh(Transform transform, int vertexCount, int triangleCount, Vector3[] vertices, int[] triangles, uint mask)
    {
        RST rst = new RST(transform.rotation, transform.lossyScale, transform.position);

        AddMesh(rst, vertexCount, triangleCount, vertices, triangles, mask);
    }
コード例 #14
0
 public static extern void AddMesh([MarshalAs(UnmanagedType.LPStruct)] RST rst, int vertexCount, int indexCount, [MarshalAs(UnmanagedType.LPArray)] Vector3[] vertices, [MarshalAs(UnmanagedType.LPArray)] int[] triangles, uint mask);
コード例 #15
0
ファイル: DeserializeRequest.cs プロジェクト: thygrrr/rant3
 public void SetResult(RST rst) => Result = rst;