Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version
Go to top

Conscript: An embeddable, compiled scripting language for .NET

, 5 Sep 2008
An API for enhancing any .NET application with a scripting language
conscript_api_and_demo_source.zip
Conscript_API_&_Demo_Source
Conscript
ConscriptDemo
Conscript.ico
Properties
Settings.settings
vssver2.scc
Resources
Conscript.ico
vssver2.scc
vssver2.scc
Collections
vssver2.scc
Compiler
vssver2.scc
Conscript.doxyfile
Properties
vssver2.scc
Resources
Conscript.ico
vssver2.scc
Runtime
vssver2.scc
vssver2.scc
SampleScripts
BubbleSort.cns
Dungeon.cns
Factorial.cns
HelloWorld.cns
vssver2.scc
using System;
using System.Collections.Generic;
using System.Text;

namespace Conscript.Runtime
{
    /// <summary>
    /// Represents a single script instruction consisting of an operator code
    /// and optionally one or more operands.
    /// </summary>
    public class ScriptInstruction
    {
        #region Private Variables

        private uint m_uiAddress;
        private Opcode m_opcode;
        private Operand m_operand0;
        private Operand m_operand1;

        #endregion

        #region Public Methods

        /// <summary>
        /// Constructs a double-operand instruction with the given opcode and
        /// two operands.
        /// </summary>
        /// <param name="opcode">Instruction opcode.</param>
        /// <param name="operand0">First instruction operand.</param>
        /// <param name="operand1">Second instruction operand.</param>
        public ScriptInstruction(Opcode opcode, Operand operand0, Operand operand1)
        {
            m_uiAddress = 0;
            m_opcode = opcode;
            m_operand0 = operand0;
            m_operand1 = operand1;
        }

        /// <summary>
        /// Constructs a single-operand instruction with the given opcode and
        /// operand.
        /// </summary>
        /// <param name="opcode">Instruction opcode.</param>
        /// <param name="operand0">Instruction operand.</param>
        public ScriptInstruction(Opcode opcode, Operand operand0)
            : this(opcode, operand0, null)
        {
        }

        /// <summary>
        /// Constructs a zero-operand instruction with the given opcode.
        /// </summary>
        /// <param name="opcode">Instruction opcode.</param>
        public ScriptInstruction(Opcode opcode)
            : this(opcode, null, null)
        {
        }

        /// <summary>
        /// Returns a string representation of the instruction.
        /// </summary>
        /// <returns>A string representation of the instruction.</returns>
        public override string ToString()
        {
            if (m_opcode == Opcode.DBG)
            {
                int iLine = (int)m_operand0.Value;
                return "Ln: " + iLine.ToString("000000") + " " + m_operand1.Value;
            }

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(m_uiAddress.ToString("[00000000]"));
            stringBuilder.Append("    ");

            stringBuilder.Append(m_opcode.ToString());
            int iOpcodeLength = m_opcode.ToString().Length;
            if (iOpcodeLength == 2)
                stringBuilder.Append("  ");
            if (iOpcodeLength == 3)
                stringBuilder.Append(" ");

            if (m_operand0 != null)
            {
                stringBuilder.Append(" ");
                stringBuilder.Append(m_operand0.ToString());
            }

            if (m_operand1 != null)
            {
                stringBuilder.Append(", ");
                stringBuilder.Append(m_operand1.ToString());
            }

            return stringBuilder.ToString();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Numeric address of the script instruction.
        /// </summary>
        public uint Address
        {
            get { return m_uiAddress; }
            set { m_uiAddress = value; }
        }

        /// <summary>
        /// Instruction opcode.
        /// </summary>
        public Opcode Opcode
        {
            get { return m_opcode; }
            set { m_opcode = value; }
        }

        /// <summary>
        /// Optional first operand.
        /// </summary>
        public Operand Operand0
        {
            get { return m_operand0; }
            set { m_operand0 = value; }
        }

        /// <summary>
        /// Optional second operand.
        /// </summary>
        public Operand Operand1
        {
            get { return m_operand1; }
            set { m_operand1 = value; }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Colin Vella
Software Developer (Senior)
Malta Malta
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 5 Sep 2008
Article Copyright 2007 by Colin Vella
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid