Example #1
0
        public EnkelFunction Bind(EnkelInstance instance)
        {
            var env = new EnkelEnvironment(_closure);

            env.Define(new DummyToken(TokenType.This, "this", null, 0), instance);
            return(new EnkelFunction(_declaration, env, _isConstructor));
        }
Example #2
0
 static EnkelEnvironment()
 {
     GlobalEnvironment = new EnkelEnvironment(new Dictionary <string, object>
     {
         { "IsOdd", new IsOdd() },
         { "IsEven", new IsEven() },
         { "Print", new Print() },
         { "Input", new Input() },
         { "TypeOf", new TypeOf() }
     });
 }
Example #3
0
        public object Call(IInterpreter interpreter, IList <object> args)
        {
            var environment = new EnkelEnvironment(_closure);

            for (var i = 0; i < _declaration.Params.Count; i++)
            {
                environment.Define(_declaration.Params[i], args[i]);
            }

            try
            {
                interpreter.ExecuteBlock(_declaration.Body, environment);
            }
            catch (Return @return)
            {
                return(@return.Value);
            }

            return(_isConstructor ? _closure.GetAt(0, new DummyToken(TokenType.This, "this", null, 0)) : null);
        }