SharpC: A C Interpreter In C# - 0010

Keywords: C#

type

Programs support the following types: void, char, short, int, float, pointer.
The operands associated with an expression are:

  • Operand: Operand base class.
  • Value: Value type.
  • ValueOfPointer: Pointer type.
  • ValueOfPointerIndiction: Pointer content type.
  • ValueOfVariableReference: Variable reference type.
  • ValueOfFunctionCalling: Function call type. Not surprisingly, function calls are boiled down to a type system to simplify operations.

type definition

public enum PrimitiveDataType
{
  VoidType = 0x0001,
  CharType = 0x0002,
  ShortType = 0x0004,
  IntType = 0x0008,
  FloatType = 0x0010,

  SignedType = 0x0100,
  UnsignedType = 0x0200,

  ConstType = 0x1000,
  PointerType = 0x2000,
  StructureType = 0x4000,

  BaseTypeMask = 0x00FF,
  PointerMask = 0xDFFF
};

Type information

public struct DataTypeInfo
{
  public PrimitiveDataType Type;
  public int PointerCount;

  public PrimitiveDataType BaseType

  public bool IsPointer

  public bool IsUnsigned

  ...

Variable information

public class Variable : Context
{
  public DataTypeInfo TypeInfo;
  public int Address;
  public int PointerAddress;
  public int ReferenceCount = 0;

        ...

Function information

public class FunctionDefine : Context
{
  private Stack<List<Expression.Operand.Value>> m_parameterStack;

  public DataTypeInfo ReturnType;
  public Expression.Operand.Operand ReturnValue;

  public bool IsVariableArgument;
  public int ReferenceCount;
  public int IteratorCount = 0;

  public List<Context> ArgumentDefinitions;
  public Block Body;

...

Expression information

public class ExpressionNode
{
  public Expression.ExpressionToken Token;
  public ExpressionNode LeftNode;
  public ExpressionNode RightNode;

  public override string ToString()
  {
      ...

  }

  public Operand.Operand Evaluate(Context ctx)
  {
      ...        

  }

  public DataTypeInfo ResultType(Context ctx)
  {
      // Derivation of Result Type of Expressions

      ...        

  } // func ResultType
}

Type system is rough, the next section from the operation process to understand SharpC in depth.

Posted by gurjit on Sun, 13 Oct 2019 08:24:23 -0700