summaryrefslogtreecommitdiff
path: root/Compiler/CType.cs
blob: 61b51083ddb8b11a985870e5712f0b20468af6ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace Q1.Compiler.visitors;

public class CType
{
    public string Name;
    public int    Size;

    public CType(string name, int size)
    {
        this.Name = name;
        this.Size = size;

        if (size > 2)
            throw new CompilerException("Types that take up more than 2 bytes are not supported");
    }

    public override string ToString() => this.Name;

    public static readonly CType Int  = new("int", 2);
    public static readonly CType Char = new("char", 1);
}

public class CTypePtr : CType
{
    public CType Sub;

    public CTypePtr(CType sub) : base($"{sub.Name}*",2)
    {
        this.Sub = sub;
    }
}