Exemple #1
0
    public void TupleIoTest(string source, int n, bool b)
    {
        var cflat = new CFlat();

        cflat.AddFunction <Tuple <Int, Bool>, Tuple <Int, Bool> >(nameof(TupleTestFunction), TupleTestFunction);
        var t = TestHelper.RunExpression <Tuple <Int, Bool> >(cflat, source, out var a);

        a.AssertSuccessCall();
        Assert.Equal(n, t.e0.value);
        Assert.Equal(b, t.e1.value);
    }
Exemple #2
0
    public void StructIoTest(string source, int x, int y, int z)
    {
        var cflat = new CFlat();

        cflat.AddFunction <Struct <MyStruct>, Struct <MyStruct> >(nameof(StructTestFunction), StructTestFunction);
        var s = TestHelper.RunExpression <Struct <MyStruct> >(cflat, source, out var a).value;

        a.AssertSuccessCall();
        Assert.Equal(x, s.x);
        Assert.Equal(y, s.y);
        Assert.Equal(z, s.z);
    }
Exemple #3
0
    public static void RunSource(string sourcePath, string sourceContent, bool printDisassembled)
    {
        var filename = Path.GetFileNameWithoutExtension(sourcePath);
        var source   = new Source(new Uri(filename), sourceContent);

        /*
         * var debugger = new EmbeddedDebugger((s, v) =>
         * {
         *      EmbeddedDebugger.Break();
         * });
         * /*/
        var debugger = new DebugServer(DebugServer.DefaultPort);

        debugger.StartPaused();
        //*/

        var cflat = new CFlat();

        //cflat.SetDebugger(debugger);

        cflat.AddFunction <Class <Stopwatch> >(nameof(StartStopwatch), StartStopwatch);
        cflat.AddFunction <Class <Stopwatch>, Float>(nameof(StopStopwatch), StopStopwatch);

        var compileErrors = cflat.CompileSource(source, Mode.Debug, Option.None);

        if (compileErrors.count > 0)
        {
            var errorMessage = cflat.GetFormattedCompileErrors();
            ConsoleHelper.Error("COMPILER ERROR\n");
            ConsoleHelper.Error(errorMessage);
            ConsoleHelper.LineBreak();

            System.Environment.ExitCode = 65;
            return;
        }

        if (printDisassembled)
        {
            ConsoleHelper.Write(cflat.Disassemble());
            ConsoleHelper.LineBreak();
        }

        var main = cflat.GetFunction <Empty, Unit>("main");

        if (main.isSome)
        {
            System.Console.WriteLine("RESULT: {0}", main.value.Call(cflat, new Empty()));
        }
        else
        {
            System.Console.WriteLine("NOT FOUNDED");
        }

        var runtimeError = cflat.GetRuntimeError();

        if (runtimeError.isSome)
        {
            var errorMessage = cflat.GetFormattedRuntimeError();
            ConsoleHelper.Error("RUNTIME ERROR\n");
            ConsoleHelper.Error(errorMessage);
            ConsoleHelper.LineBreak();
            ConsoleHelper.Error(cflat.TraceCallStack());

            System.Environment.ExitCode = 70;
        }
        else
        {
            System.Environment.ExitCode = 0;
        }

        ConsoleHelper.LineBreak();
    }