Пример #1
0
        private void Get(CodeTerm codeTerm, WamInstructionRegister sourceRegister)
        {
            if (codeTerm.IsCodeList)
            {
                codeTerm = ConvertCodeList(codeTerm.AsCodeList);
            }

            if (codeTerm.IsCodeVariable)
            {
                Get(codeTerm.AsCodeVariable, sourceRegister);
                return;
            }

            if (codeTerm.IsCodeCompoundTerm)
            {
                Get(codeTerm.AsCodeCompoundTerm, sourceRegister);
                return;
            }

            if (codeTerm.IsCodeValue)
            {
                Get(codeTerm.AsCodeValue, sourceRegister);
                return;
            }

            throw new InvalidOperationException("Unsupported codeTerm type.");
        }
Пример #2
0
        private void Put(CodeTerm codeTerm, WamInstructionRegister targetRegister, LibraryList libraries)
        {
            if (codeTerm.IsCodeList)
            {
                codeTerm = ConvertCodeList(codeTerm.AsCodeList);
            }

            if (codeTerm.IsCodeVariable)
            {
                Put(codeTerm.AsCodeVariable, targetRegister);
                return;
            }

            if (codeTerm.IsCodeCompoundTerm)
            {
                Put(codeTerm.AsCodeCompoundTerm, targetRegister, libraries);
                return;
            }

            if (codeTerm.IsCodeValue)
            {
                Put(codeTerm.AsCodeValue, targetRegister);
                return;
            }

            throw new InvalidOperationException("Unsupported codeTerm type.");
        }
Пример #3
0
        readonly WamReferenceTarget    _referenceTarget; // 4 bytes

        public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister sourceRegister, Functor functor, int index, WamInstructionRegister targetRegister)
        {
            if (sourceRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "sourceRegister");
            }
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (index < 0)
            {
                throw new ArgumentException("Invalid index.", "index");
            }
            if (targetRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "targetRegister");
            }
            _opCode          = opCode;
            _sourceRegister  = sourceRegister;
            _functor         = functor;
            _index           = index;
            _targetRegister  = targetRegister;
            _referenceTarget = null;
        }
Пример #4
0
        private WamReferenceTarget m_referenceTarget; // 4 bytes

        #endregion

        #region Constructors

        public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister sourceRegister, Functor functor, int index, WamInstructionRegister targetRegister)
        {
            if (sourceRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "sourceRegister");
            }
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (index < 0)
            {
                throw new ArgumentException("Invalid index.", "index");
            }
            if (targetRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "targetRegister");
            }

            m_opCode = opCode;
            m_sourceRegister = sourceRegister;
            m_functor = functor;
            m_index = index;
            m_targetRegister = targetRegister;
            m_referenceTarget = null;
        }
Пример #5
0
        private void Get(CodeCompoundTerm codeCompoundTerm, WamInstructionRegister sourceRegister)
        {
            WamInstructionRegister[] childrenRegisters = new WamInstructionRegister[codeCompoundTerm.Children.Count];

            InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetStructure, sourceRegister, Functor.Create(codeCompoundTerm.Functor)));
            for (int idx = 0; idx < codeCompoundTerm.Children.Count; ++idx)
            {
                CodeTerm child = codeCompoundTerm.Children[idx];

                if (child.IsCodeList)
                {
                    child = ConvertCodeList(child.AsCodeList);
                }

                if (child.IsCodeVariable)
                {
                    string variableName = child.AsCodeVariable.Name;
                    WamInstructionRegister variableRegister = GetRegisterAssignment(variableName);
                    if (variableRegister.IsUnused)
                    {
                        variableRegister = GetNextPermanentRegister(variableName);
                        InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.UnifyUnboundVariable, variableRegister));
                    }
                    else
                    {
                        InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.UnifyBoundVariable, variableRegister));
                    }
                }
                else if (child.IsCodeCompoundTerm)
                {
                    childrenRegisters[idx] = GetNextTemporaryRegister();
                    InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.UnifyUnboundVariable, childrenRegisters[idx]));
                }
                else if (child.IsCodeValue)
                {
                    InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.UnifyValue, WamValue.Create(child.AsCodeValue)));
                }
                else
                {
                    throw new InvalidOperationException("Unsupported codeTerm type.");
                }
            }

            // Build substructures.
            //
            for (int idx = 0; idx < codeCompoundTerm.Children.Count; ++idx)
            {
                CodeTerm child = codeCompoundTerm.Children[idx];

                if (child.IsCodeList)
                {
                    child = ConvertCodeList(child.AsCodeList);
                }

                if (child.IsCodeCompoundTerm)
                {
                    Get(child, childrenRegisters[idx]);
                }
            }
        }
Пример #6
0
        void Put(CodeCompoundTerm codeCompoundTerm, WamInstructionRegister targetRegister, LibraryList libraries)
        {
            var childrenRegisters = new WamInstructionRegister[codeCompoundTerm.Children.Count];

            // Build substructures.
            //
            for (var idx = 0; idx < codeCompoundTerm.Children.Count; ++idx)
            {
                var child = codeCompoundTerm.Children[idx];
                if (child.IsCodeList)
                {
                    child = ConvertCodeList(child.AsCodeList);
                }
                if (child.IsCodeCompoundTerm)
                {
                    childrenRegisters[idx] = GetNextTemporaryRegister();
                    Put(child, childrenRegisters[idx], libraries);
                }
            }

            var functor = Functor.Create(codeCompoundTerm.Functor);

            InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.PutStructure, functor, targetRegister));
            for (var idx = 0; idx < codeCompoundTerm.Children.Count; ++idx)
            {
                var child = codeCompoundTerm.Children[idx];

                if (child.IsCodeList)
                {
                    child = ConvertCodeList(child.AsCodeList);
                }
                if (child.IsCodeVariable)
                {
                    var variableName     = child.AsCodeVariable.Name;
                    var variableRegister = GetRegisterAssignment(variableName);
                    if (variableRegister.IsUnused)
                    {
                        variableRegister = GetNextPermanentRegister(variableName);
                        InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.SetUnboundVariable, variableRegister));
                    }
                    else
                    {
                        InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.SetBoundVariable, variableRegister));
                    }
                }
                else if (child.IsCodeCompoundTerm)
                {
                    InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.SetBoundVariable, childrenRegisters[idx]));
                }
                else if (child.IsCodeValue)
                {
                    InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.SetValue, WamValue.Create(child.AsCodeValue)));
                }
                else
                {
                    throw new InvalidOperationException("Unsupported codeTerm type.");
                }
            }
        }
Пример #7
0
 public WamInstruction(WamInstructionOpCodes opCode)
 {
     _opCode          = opCode;
     _sourceRegister  = WamInstructionRegister.Unused;
     _functor         = null;
     _index           = -1;
     _targetRegister  = WamInstructionRegister.Unused;
     _referenceTarget = null;
 }
Пример #8
0
 public WamInstruction(WamInstructionOpCodes opCode)
 {
     m_opCode = opCode;
     m_sourceRegister = WamInstructionRegister.Unused;
     m_functor = null;
     m_index = -1;
     m_targetRegister = WamInstructionRegister.Unused;
     m_referenceTarget = null;
 }
Пример #9
0
 public WamInstruction(WamInstructionOpCodes opCode, WamReferenceTarget referenceTarget)
 {
     if (referenceTarget == null)
     {
         throw new ArgumentNullException("referenceTarget");
     }
     _opCode          = opCode;
     _sourceRegister  = WamInstructionRegister.Unused;
     _functor         = null;
     _index           = -1;
     _targetRegister  = WamInstructionRegister.Unused;
     _referenceTarget = referenceTarget;
 }
Пример #10
0
 public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister targetRegister)
 {
     if (targetRegister.IsUnused)
     {
         throw new ArgumentException("Invalid value.", "targetRegister");
     }
     _opCode          = opCode;
     _sourceRegister  = WamInstructionRegister.Unused;
     _functor         = null;
     _index           = -1;
     _targetRegister  = targetRegister;
     _referenceTarget = null;
 }
Пример #11
0
 public WamInstruction(WamInstructionOpCodes opCode, Functor functor)
 {
     if (functor == null)
     {
         throw new ArgumentNullException("functor");
     }
     _opCode          = opCode;
     _sourceRegister  = WamInstructionRegister.Unused;
     _functor         = functor;
     _index           = -1;
     _targetRegister  = WamInstructionRegister.Unused;
     _referenceTarget = null;
 }
 public WamInstructionStreamVariableAttribute(int index, string name, WamInstructionRegister register)
     : base(index)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("name");
     }
     if (register.IsUnused)
     {
         throw new ArgumentException("Register is unused.", "register");
     }
     Name = name;
     Register = register;
 }
Пример #13
0
        private void Get(CodeVariable codeVariable, WamInstructionRegister sourceRegister)
        {
            WamInstructionRegister targetRegister = GetRegisterAssignment(codeVariable.Name);

            if (targetRegister.IsUnused)
            {
                targetRegister = GetNextPermanentRegister(codeVariable.Name);
                InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetUnboundVariable, sourceRegister, targetRegister));
            }
            else
            {
                InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetBoundVariable, sourceRegister, targetRegister));
            }
        }
Пример #14
0
        void SetRegister(WamInstructionRegister register, WamReferenceTarget value)
        {
            switch (register.Type)
            {
            case WamInstructionRegisterTypes.Argument: ArgumentRegisters[register.Id] = value; break;

            case WamInstructionRegisterTypes.Permanent: Environment.PermanentRegisters[register.Id] = value; break;

            case WamInstructionRegisterTypes.Temporary: TemporaryRegisters[register.Id] = value; break;

            default:
                throw new InvalidOperationException(string.Format("Unknown register type {0}.", register.Type));
            }
        }
 public WamInstructionStreamVariableAttribute(int index, string name, WamInstructionRegister register)
     : base(index)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("name");
     }
     if (register.IsUnused)
     {
         throw new ArgumentException("Register is unused.", "register");
     }
     Name     = name;
     Register = register;
 }
Пример #16
0
        WamReferenceTarget GetRegister(WamInstructionRegister register)
        {
            switch (register.Type)
            {
            case WamInstructionRegisterTypes.Argument: return(ArgumentRegisters[register.Id]);

            case WamInstructionRegisterTypes.Permanent: return(Environment.PermanentRegisters[register.Id]);

            case WamInstructionRegisterTypes.Temporary: return(TemporaryRegisters[register.Id]);

            default:
                throw new InvalidOperationException(string.Format("Unknown register type {0}.", register.Type));
            }
        }
Пример #17
0
        WamInstructionRegister GetNextPermanentRegister(string name)
        {
            var instructionRegister = new WamInstructionRegister(WamInstructionRegisterTypes.Permanent, _nextPermanentRegisterId++);

            _variableAssignments.Add(name, instructionRegister);

            var variableAttribute = new WamInstructionStreamVariableAttribute(
                InstructionStreamBuilder.NextIndex,
                name,
                instructionRegister);

            InstructionStreamBuilder.AddAttribute(variableAttribute);
            return(instructionRegister);
        }
Пример #18
0
 public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister sourceRegister, WamReferenceTarget referenceTarget)
 {
     if (referenceTarget == null)
     {
         throw new ArgumentNullException("referenceTarget");
     }
     if (sourceRegister.IsUnused)
     {
         throw new ArgumentException("Invalid value.", "sourceRegister");
     }
     _opCode = opCode;
     _sourceRegister = sourceRegister;
     _functor = null;
     _index = -1;
     _targetRegister = WamInstructionRegister.Unused;
     _referenceTarget = referenceTarget;
 }
Пример #19
0
        public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister sourceRegister, WamReferenceTarget referenceTarget)
        {
            if (referenceTarget == null)
            {
                throw new ArgumentNullException("referenceTarget");
            }
            if (sourceRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "sourceRegister");
            }

            m_opCode          = opCode;
            m_sourceRegister  = sourceRegister;
            m_functor         = null;
            m_index           = -1;
            m_targetRegister  = WamInstructionRegister.Unused;
            m_referenceTarget = referenceTarget;
        }
Пример #20
0
        public WamInstruction(WamInstructionOpCodes opCode, Functor functor, int index)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (index < 0)
            {
                throw new ArgumentException("Invalid index.", "index");
            }

            m_opCode          = opCode;
            m_sourceRegister  = WamInstructionRegister.Unused;
            m_functor         = functor;
            m_index           = index;
            m_targetRegister  = WamInstructionRegister.Unused;
            m_referenceTarget = null;
        }
Пример #21
0
        public WamInstruction(WamInstructionOpCodes opCode, Functor functor, WamInstructionRegister targetRegister)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (targetRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "targetRegister");
            }

            m_opCode          = opCode;
            m_sourceRegister  = WamInstructionRegister.Unused;
            m_functor         = functor;
            m_index           = -1;
            m_targetRegister  = targetRegister;
            m_referenceTarget = null;
        }
Пример #22
0
 private void Get(CodeVariable codeVariable, WamInstructionRegister sourceRegister)
 {
     WamInstructionRegister targetRegister = GetRegisterAssignment(codeVariable.Name);
     if (targetRegister.IsUnused)
     {
         targetRegister = GetNextPermanentRegister(codeVariable.Name);
         InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetUnboundVariable, sourceRegister, targetRegister));
     }
     else
     {
         InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetBoundVariable, sourceRegister, targetRegister));
     }
 }
Пример #23
0
 private void Get(CodeValue codeValue, WamInstructionRegister sourceRegister)
 {
     InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetValue, sourceRegister, WamValue.Create(codeValue)));
 }
Пример #24
0
        private void Get(CodeTerm codeTerm, WamInstructionRegister sourceRegister)
        {
            if (codeTerm.IsCodeList)
            {
                codeTerm = ConvertCodeList(codeTerm.AsCodeList);
            }

            if (codeTerm.IsCodeVariable)
            {
                Get(codeTerm.AsCodeVariable, sourceRegister);
                return;
            }

            if (codeTerm.IsCodeCompoundTerm)
            {
                Get(codeTerm.AsCodeCompoundTerm, sourceRegister);
                return;
            }

            if (codeTerm.IsCodeValue)
            {
                Get(codeTerm.AsCodeValue, sourceRegister);
                return;
            }

            throw new InvalidOperationException("Unsupported codeTerm type.");
        }
Пример #25
0
 private void Put(CodeValue codeValue, WamInstructionRegister targetRegister)
 {
     InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.PutValue, WamValue.Create(codeValue), targetRegister));
 }
Пример #26
0
 public WamInstruction(WamInstructionOpCodes opCode, Functor functor, int index)
 {
     if (functor == null)
     {
         throw new ArgumentNullException("functor");
     }
     if (index < 0)
     {
         throw new ArgumentException("Invalid index.", "index");
     }
     _opCode = opCode;
     _sourceRegister = WamInstructionRegister.Unused;
     _functor = functor;
     _index = index;
     _targetRegister = WamInstructionRegister.Unused;
     _referenceTarget = null;
 }
Пример #27
0
        public WamInstruction(WamInstructionOpCodes opCode, WamReferenceTarget referenceTarget)
        {
            if (referenceTarget == null)
            {
                throw new ArgumentNullException("referenceTarget");
            }

            m_opCode = opCode;
            m_sourceRegister = WamInstructionRegister.Unused;
            m_functor = null;
            m_index = -1;
            m_targetRegister = WamInstructionRegister.Unused;
            m_referenceTarget = referenceTarget;
        }
Пример #28
0
        public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister sourceRegister, WamInstructionRegister targetRegister)
        {
            if (sourceRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "sourceRegister");
            }
            if (targetRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "targetRegister");
            }

            m_opCode = opCode;
            m_sourceRegister = sourceRegister;
            m_functor = null;
            m_index = -1;
            m_targetRegister = targetRegister;
            m_referenceTarget = null;
        }
Пример #29
0
        private void Get(CodeCompoundTerm codeCompoundTerm, WamInstructionRegister sourceRegister)
        {
            WamInstructionRegister[] childrenRegisters = new WamInstructionRegister[codeCompoundTerm.Children.Count];

            InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetStructure, sourceRegister, Functor.Create(codeCompoundTerm.Functor)));
            for (int idx = 0; idx < codeCompoundTerm.Children.Count; ++idx)
            {
                CodeTerm child = codeCompoundTerm.Children[idx];

                if (child.IsCodeList)
                {
                    child = ConvertCodeList(child.AsCodeList);
                }

                if (child.IsCodeVariable)
                {
                    string variableName = child.AsCodeVariable.Name;
                    WamInstructionRegister variableRegister = GetRegisterAssignment(variableName);
                    if (variableRegister.IsUnused)
                    {
                        variableRegister = GetNextPermanentRegister(variableName);
                        InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.UnifyUnboundVariable, variableRegister));
                    }
                    else
                    {
                        InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.UnifyBoundVariable, variableRegister));
                    }
                }
                else if (child.IsCodeCompoundTerm)
                {
                    childrenRegisters[idx] = GetNextTemporaryRegister();
                    InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.UnifyUnboundVariable, childrenRegisters[idx]));
                }
                else if (child.IsCodeValue)
                {
                    InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.UnifyValue, WamValue.Create(child.AsCodeValue)));
                }
                else
                {
                    throw new InvalidOperationException("Unsupported codeTerm type.");
                }
            }

            // Build substructures.
            //
            for (int idx = 0; idx < codeCompoundTerm.Children.Count; ++idx)
            {
                CodeTerm child = codeCompoundTerm.Children[idx];

                if (child.IsCodeList)
                {
                    child = ConvertCodeList(child.AsCodeList);
                }

                if (child.IsCodeCompoundTerm)
                {
                    Get(child, childrenRegisters[idx]);
                }
            }
        }
Пример #30
0
 private void Put(CodeValue codeValue, WamInstructionRegister targetRegister)
 {
     InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.PutValue, WamValue.Create(codeValue), targetRegister));
 }
Пример #31
0
        private WamInstructionRegister GetNextPermanentRegister(string name)
        {
            WamInstructionRegister instructionRegister = new WamInstructionRegister(WamInstructionRegisterTypes.Permanent, m_nextPermanentRegisterId++);

            m_variableAssignments.Add(name, instructionRegister);

            WamInstructionStreamVariableAttribute variableAttribute = new WamInstructionStreamVariableAttribute(
                InstructionStreamBuilder.NextIndex,
                name,
                instructionRegister);
            InstructionStreamBuilder.AddAttribute(variableAttribute);

            return instructionRegister;
        }
Пример #32
0
        void Put(CodeCompoundTerm codeCompoundTerm, WamInstructionRegister targetRegister, LibraryList libraries)
        {
            var childrenRegisters = new WamInstructionRegister[codeCompoundTerm.Children.Count];

            // Build substructures.
            //
            for (var idx = 0; idx < codeCompoundTerm.Children.Count; ++idx)
            {
                var child = codeCompoundTerm.Children[idx];
                if (child.IsCodeList)
                {
                    child = ConvertCodeList(child.AsCodeList);
                }
                if (child.IsCodeCompoundTerm)
                {
                    childrenRegisters[idx] = GetNextTemporaryRegister();
                    Put(child, childrenRegisters[idx], libraries);
                }
            }

            var functor = Functor.Create(codeCompoundTerm.Functor);

            InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.PutStructure, functor, targetRegister));
            for (var idx = 0; idx < codeCompoundTerm.Children.Count; ++idx)
            {
                var child = codeCompoundTerm.Children[idx];

                if (child.IsCodeList)
                {
                    child = ConvertCodeList(child.AsCodeList);
                }
                if (child.IsCodeVariable)
                {
                    var variableName = child.AsCodeVariable.Name;
                    var variableRegister = GetRegisterAssignment(variableName);
                    if (variableRegister.IsUnused)
                    {
                        variableRegister = GetNextPermanentRegister(variableName);
                        InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.SetUnboundVariable, variableRegister));
                    }
                    else
                    {
                        InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.SetBoundVariable, variableRegister));
                    }
                }
                else if (child.IsCodeCompoundTerm)
                {
                    InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.SetBoundVariable, childrenRegisters[idx]));
                }
                else if (child.IsCodeValue)
                {
                    InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.SetValue, WamValue.Create(child.AsCodeValue)));
                }
                else
                {
                    throw new InvalidOperationException("Unsupported codeTerm type.");
                }
            }
        }
Пример #33
0
        public WamInstruction(WamInstructionOpCodes opCode, Functor functor)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }

            m_opCode = opCode;
            m_sourceRegister = WamInstructionRegister.Unused;
            m_functor = functor;
            m_index = -1;
            m_targetRegister = WamInstructionRegister.Unused;
            m_referenceTarget = null;
        }
Пример #34
0
 private void Get(CodeValue codeValue, WamInstructionRegister sourceRegister)
 {
     InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.GetValue, sourceRegister, WamValue.Create(codeValue)));
 }
Пример #35
0
        private WamReferenceTarget GetRegister(WamInstructionRegister register)
        {
            switch (register.Type)
            {
                case WamInstructionRegisterTypes.Argument: return ArgumentRegisters[register.Id];
                case WamInstructionRegisterTypes.Permanent: return Environment.PermanentRegisters[register.Id];
                case WamInstructionRegisterTypes.Temporary: return TemporaryRegisters[register.Id];

                default:
                    throw new InvalidOperationException(string.Format("Unknown register type {0}.", register.Type));
            }
        }
Пример #36
0
        private void Put(CodeTerm codeTerm, WamInstructionRegister targetRegister, LibraryList libraries)
        {
            if (codeTerm.IsCodeList)
            {
                codeTerm = ConvertCodeList(codeTerm.AsCodeList);
            }

            if (codeTerm.IsCodeVariable)
            {
                Put(codeTerm.AsCodeVariable, targetRegister);
                return;
            }

            if (codeTerm.IsCodeCompoundTerm)
            {
                Put(codeTerm.AsCodeCompoundTerm, targetRegister, libraries);
                return;
            }

            if (codeTerm.IsCodeValue)
            {
                Put(codeTerm.AsCodeValue, targetRegister);
                return;
            }

            throw new InvalidOperationException("Unsupported codeTerm type.");
        }
Пример #37
0
        private void SetRegister(WamInstructionRegister register, WamReferenceTarget value)
        {
            switch (register.Type)
            {
                case WamInstructionRegisterTypes.Argument: ArgumentRegisters[register.Id] = value; break;
                case WamInstructionRegisterTypes.Permanent: Environment.PermanentRegisters[register.Id] = value; break;
                case WamInstructionRegisterTypes.Temporary: TemporaryRegisters[register.Id] = value; break;

                default:
                    throw new InvalidOperationException(string.Format("Unknown register type {0}.", register.Type));
            }
        }
Пример #38
0
 public WamInstruction(WamInstructionOpCodes opCode, Functor functor, WamInstructionRegister targetRegister)
 {
     if (functor == null)
     {
         throw new ArgumentNullException("functor");
     }
     if (targetRegister.IsUnused)
     {
         throw new ArgumentException("Invalid value.", "targetRegister");
     }
     _opCode = opCode;
     _sourceRegister = WamInstructionRegister.Unused;
     _functor = functor;
     _index = -1;
     _targetRegister = targetRegister;
     _referenceTarget = null;
 }