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