Пример #1
0
        public void ShouldAssignVariable()
        {
            var value = _engine.Execute("a = 1").GetValue("a");

            Assert.NotNull(value);
            Assert.Equal(1, value.AsType <NumberInstance>().Value);
        }
Пример #2
0
 private void Execute(string code)
 {
     try {
         engine.Execute(code);
     }
     catch (SkryptException e) {
         Debug.LogError(e);
     }
 }
Пример #3
0
        public StructTests(ITestOutputHelper output)
        {
            _output = output;
            _engine = new SkryptEngine();

            _engine
            .SetValue("assert", new Action <bool>(Assert.True))
            .SetValue("equal", new Action <object, object>(Assert.Equal))
            ;

            _engine.Execute(@"
struct BasicStruct {
    public A = 0
    public B = """"

    public fn init (a,b) {
        self.A = a
        self.B = b
    }

    public fn toString () {
        return ""{"" + self.A + "","" + self.B + ""}""
    }
}
            ");
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Any())
            {
                _file = Path.Combine(Directory.GetCurrentDirectory(), args[0]);
            }

            if (!string.IsNullOrEmpty(_file))
            {
                RunFile(_file);
            }

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(">");

                string line = Console.ReadLine();

                if (line == "exit")
                {
                    return;
                }

                if (line.StartsWith("run "))
                {
                    _file = Path.Combine(
                        Directory.GetCurrentDirectory(),
                        line.Substring(4)
                        );

                    if (!string.IsNullOrEmpty(_file))
                    {
                        RunFile(_file);
                    }

                    continue;
                }

                try {
                    _engine.Execute(line);

                    Console.ForegroundColor = ConsoleColor.Magenta;

                    Console.WriteLine(_engine.CompletionValue?.ToString() ?? "null");
                }
                catch (SkryptException e) {
                    Console.ForegroundColor = ConsoleColor.Red;
                    _engine.ErrorHandler.ReportError(e);
                }
                catch (Exception e) {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(e);
                }
            }
        }
Пример #5
0
        public EngineBenchmarks()
        {
            _engine = new SkryptEngine();

            // Pre-set value to make sure it exists in the GetValue benchmark
            _engine.SetValue("A", 1);

            _engine.Execute(@"
fn fibonacci(num) {
    if (num <= 1) return 1

    return fibonacci(num - 1) + fibonacci(num - 2)
}
            ");
        }
Пример #6
0
 private void RunTest(string source)
 {
     _engine.Execute(source, new Compiling.ParserOptions {
         Tolerant = false
     });
 }
Пример #7
0
 public SkryptEngine ExecuteNumericalExpression()
 {
     return(_engine.Execute(@"result = ((A - 2) * 4) / 2"));
 }
Пример #8
0
        public void ShouldParseNull()
        {
            var nullValue = _engine.Execute("null").CompletionValue;

            Assert.Null(nullValue);
        }