Beispiel #1
0
 public FunctionTypeBuilder(ByteCodeChunk chunk)
 {
     this.chunk = chunk;
     this.startParameterIndex = (ushort)chunk.functionParamTypes.count;
     this.parameterCount      = 0;
     this.returnType          = new ValueType(TypeKind.Unit);
 }
Beispiel #2
0
        public void Reset(Mode mode, ByteCodeChunk chunk)
        {
            this.mode             = mode;
            this.chunk            = chunk;
            errors.count          = 0;
            stateFrameStack.count = 0;

            functionsStartIndex   = 0;
            structTypesStartIndex = 0;
        }
Beispiel #3
0
    public void StructSizeTests(string source, int expectedSize)
    {
        var c      = new Compiler();
        var chunk  = new ByteCodeChunk();
        var errors = c.CompileSource(chunk, null, TestHelper.CompilerMode, new Source(new Uri("source"), source));

        Assert.Empty(errors.ToArray());

        var type     = new ValueType(TypeKind.Struct, chunk.structTypes.count - 1);
        var typeSize = type.GetSize(chunk);

        Assert.Equal(expectedSize, typeSize);
    }
Beispiel #4
0
        public ValueType GetType(ByteCodeChunk chunk)
        {
            var classType = typeof(T);
            var builder   = chunk.BeginClassType();
            var result    = builder.Build(classType.Name, classType, out var typeIndex);

            if (result == ClassTypeBuilder.Result.Success)
            {
                global::cflat.Marshal.SizeOf <Class <T> > .size = 1;
                return(new ValueType(TypeKind.NativeClass, typeIndex));
            }

            throw new Marshal.InvalidReflectionException();
        }
Beispiel #5
0
    public void TupleDeclarationTest()
    {
        var chunk = new ByteCodeChunk();

        var builder = chunk.BeginTupleType();

        Assert.Equal(0, chunk.tupleTypes.count);
        Assert.Equal(0, chunk.tupleElementTypes.count);

        builder.WithElement(new ValueType(TypeKind.Int));
        builder.WithElement(new ValueType(TypeKind.Int));
        Assert.Equal(2, chunk.tupleElementTypes.count);

        var result = builder.Build(out var typeIndex);

        Assert.Equal(TupleTypeBuilder.Result.Success, result);
        var type = chunk.tupleTypes.buffer[typeIndex];

        Assert.Equal(1, chunk.tupleTypes.count);
        Assert.Equal(2, chunk.tupleElementTypes.count);

        Assert.Equal(2, type.size);
        Assert.Equal(0, type.elements.index);
        Assert.Equal(2, type.elements.length);

        builder = chunk.BeginTupleType();
        Assert.Equal(1, chunk.tupleTypes.count);
        Assert.Equal(2, chunk.tupleElementTypes.count);

        builder.WithElement(new ValueType(TypeKind.Int));
        builder.WithElement(new ValueType(TypeKind.Int));
        Assert.Equal(4, chunk.tupleElementTypes.count);

        result = builder.Build(out typeIndex);
        Assert.Equal(TupleTypeBuilder.Result.Success, result);
        type = chunk.tupleTypes.buffer[typeIndex];
        Assert.Equal(1, chunk.tupleTypes.count);
        Assert.Equal(2, chunk.tupleElementTypes.count);

        Assert.Equal(2, type.size);
        Assert.Equal(0, type.elements.index);
        Assert.Equal(2, type.elements.length);
    }
Beispiel #6
0
        internal void Load(ByteCodeChunk chunk)
        {
            this.chunk = chunk;
            error      = Option.None;

            callFrameStack.count = 0;
            memory.Reset();

            nativeObjects = new Buffer <object>
            {
                buffer = new object[chunk.stringLiterals.buffer.Length],
                count  = chunk.stringLiterals.count
            };
            for (var i = 0; i < nativeObjects.count; i++)
            {
                nativeObjects.buffer[i] = chunk.stringLiterals.buffer[i];
            }

            debugData.Clear();
        }
Beispiel #7
0
 public ValueType GetType(ByteCodeChunk chunk)
 {
     return(new ValueType());
 }
Beispiel #8
0
 public static ClassTypeBuilder BeginClassType(this ByteCodeChunk self)
 {
     return(new ClassTypeBuilder(self));
 }
Beispiel #9
0
 public static StructTypeBuilder BeginStructType(this ByteCodeChunk self)
 {
     return(new StructTypeBuilder(self));
 }
Beispiel #10
0
 public FunctionDefinitionMarshaler(ByteCodeChunk chunk)
 {
     this.chunk              = chunk;
     this.builder            = chunk.BeginFunctionType();
     this.builder.returnType = global::cflat.Marshal.TypeOf <R>(chunk);
 }
Beispiel #11
0
 public ValueType GetType(ByteCodeChunk chunk)
 {
     global::cflat.Marshal.SizeOf <Int> .size = 1;
     return(new ValueType(TypeKind.Int));
 }
Beispiel #12
0
 public ValueType GetType(ByteCodeChunk chunk)
 {
     global::cflat.Marshal.SizeOf <MutRef <T> > .size = 1;
     return(global::cflat.Marshal.TypeOf <T>(chunk).ToReferenceType(true));
 }
Beispiel #13
0
 public StructDefinitionMarshaler(ByteCodeChunk chunk)
 {
     this.chunk   = chunk;
     this.builder = chunk.BeginStructType();
 }
Beispiel #14
0
 public static void AddInstruction(this ByteCodeChunk chunk, Instruction instruction)
 {
     chunk.Add((byte)instruction);
 }
Beispiel #15
0
 public static FunctionTypeBuilder BeginFunctionType(this ByteCodeChunk self)
 {
     return(new FunctionTypeBuilder(self));
 }
Beispiel #16
0
 public ValueType GetType(ByteCodeChunk chunk)
 {
     return(new StructDefinitionMarshaler <T>(chunk).GetDefinedType());
 }
Beispiel #17
0
 public void Reset()
 {
     chunk = new ByteCodeChunk();
     compileErrors.count = 0;
 }
Beispiel #18
0
 public static ValueType TypeOf <T>(ByteCodeChunk chunk) where T : struct, IMarshalable
 {
     return(default(T).GetType(chunk));
 }
Beispiel #19
0
 public static TupleTypeBuilder BeginTupleType(this ByteCodeChunk self)
 {
     return(new TupleTypeBuilder(self));
 }
Beispiel #20
0
 public ValueType GetType(ByteCodeChunk chunk)
 {
     global::cflat.Marshal.SizeOf <Array <T> > .size = 1;
     return(global::cflat.Marshal.TypeOf <T>(chunk).ToArrayType());
 }
Beispiel #21
0
 public static void AddInstruction(this ByteCodeChunk chunk, Instruction instruction,
                                   ulong value)
 {
     chunk.Add((byte)instruction);
     chunk.AddRange(BitConverter.GetBytes(value));
 }
Beispiel #22
0
 public TupleDefinitionMarshaler(ByteCodeChunk chunk)
 {
     this.chunk   = chunk;
     this.builder = chunk.BeginTupleType();
 }