Beispiel #1
0
        public int Execute()
        {
            var environment = new ExecEnvironment(functions);

            foreach (var def in definitions)
            {
                def.Execute(environment);
            }
            Function main = environment.GetFunctionByName("main");

            if (main is null)
            {
                throw new RuntimeException("Cannot find main function");
            }
            main.Execute(environment, null);
            var returnedValue = (environment.GetReturnedValue() as Int_t);

            return(returnedValue is null ?
                   throw new RuntimeException("Wrong return type") :
                   returnedValue.Value);
        }
Beispiel #2
0
        public Value Evaluate(ExecEnvironment environment)
        {
            Function fun    = environment.GetFunctionByName(name);
            var      values = new List <Value>();

            foreach (var arg in arguments)
            {
                values.Add(arg.Evaluate(environment));
            }
            fun.Execute(environment, values);
            if (fun.Type == TypeValue.Void)
            {
                return(null);
            }
            var value = environment.GetReturnedValue();

            if (value.Type != fun.Type)
            {
                throw new RuntimeException("Wrong return type");
            }
            return(value);
        }