예제 #1
0
        public StringPrototype(MelonEngine engine, MelonType type) : base(engine, type)
        {
            var properties = new PropertyDictionary {
                ["Length"] = new Property(new NativeFunctionInstance("Length", type, engine, Length))
            };

            SetProperties(properties);
        }
        public LexicalEnvironment(MelonEngine engine, bool isRoot)
        {
            IsRoot = isRoot;

            _engine = engine;

            Children = new List <LexicalEnvironment>();
        }
        public LexicalEnvironment(LexicalEnvironment parent, bool isRoot)
        {
            IsRoot = isRoot;
            Parent = parent;

            Parent.AddChild(this);
            _engine = Parent._engine;

            Variables = new Dictionary <string, Variable>();
            Children  = new List <LexicalEnvironment>();
        }
예제 #4
0
        public NativeFunctionInstance(string name, MelonObject self, MelonEngine engine, NativeFunctionDelegate del) : base(name, engine)
        {
            Self = self;

            ReturnTypeAttribute returnTypeAttribute = del.Method.GetCustomAttribute <ReturnTypeAttribute>();

            if (returnTypeAttribute != null)
            {
                ReturnType = new TypeReference(engine, engine.GetType(returnTypeAttribute.Type));
            }

            ParameterAttribute[] parameterAttributes = del.Method.GetCustomAttributes <ParameterAttribute>().ToArray();

            if (parameterAttributes?.Length > 0)
            {
                ParameterTypes = new FunctionParameter[parameterAttributes.Length];

                bool hasVarargs = false;

                for (int i = 0; i < parameterAttributes.Length; i++)
                {
                    if (parameterAttributes[i].IsGeneric)
                    {
                        ParameterTypes[i] = new FunctionParameter(parameterAttributes[i].Name, parameterAttributes[i].GenericIndex);
                    }
                    else
                    {
                        ParameterTypes[i] = new FunctionParameter(parameterAttributes[i].Name, new TypeReference(engine, engine.GetType(parameterAttributes[i].Type)));
                    }

                    if (parameterAttributes[i].IsVarargs)
                    {
                        if (hasVarargs || i < parameterAttributes.Length - 1)
                        {
                            throw new MelonException("Varargs parameter can only appear once and has to be the last parameter");
                        }

                        ParameterTypes[i].IsVarargs = true;

                        hasVarargs = true;
                    }
                }
            }
            else
            {
                ParameterTypes = new[] { new FunctionParameter("", new TypeReference(engine, engine.anyType))
                                         {
                                             IsVarargs = true
                                         } };
            }

            Delegate = del;
        }
예제 #5
0
        public static bool TryCreateFunction(MelonEngine engine, MethodInfo method, out NativeFunctionInstance function)
        {
            if (CheckSignature(method))
            {
                var del = (NativeFunctionDelegate)method.CreateDelegate(typeof(NativeFunctionDelegate));

                function = new NativeFunctionInstance(del.Method.Name, null, engine, del);

                return(true);
            }

            function = null;

            return(false);
        }
예제 #6
0
 public BooleanType(MelonEngine engine) : base(engine)
 {
 }
예제 #7
0
 public FunctionInstance(string name, MelonEngine engine) : base(engine)
 {
     Type = engine.functionType;
     Name = name;
 }
예제 #8
0
 public FunctionType(MelonEngine engine) : base(engine)
 {
     Prototype = new FunctionPrototype(engine, this);
 }
예제 #9
0
 public AnyType(MelonEngine engine) : base(engine)
 {
 }
예제 #10
0
 public ParseContext(MelonEngine engine, LexicalEnvironment environment)
 {
     LexicalEnvironment = new LexicalEnvironment(environment, !environment.IsRoot);
 }
예제 #11
0
 public MelonType(MelonEngine engine) : base(engine)
 {
 }
예제 #12
0
 public MelonPrototype(MelonEngine engine, MelonType type) : base(engine)
 {
     Type = type;
 }
예제 #13
0
 public MelonGenericType(MelonEngine engine) : base(engine)
 {
 }
예제 #14
0
 public ByteCodePrinter(MelonEngine engine)
 {
     _engine = engine;
 }
예제 #15
0
 public MelonInstance(MelonEngine engine) : base(engine)
 {
 }
예제 #16
0
 public MelonVisitor(MelonEngine engine, ScriptFunctionInstance scriptFunction) : this(engine) {
     _scriptFunction = scriptFunction;
 }
예제 #17
0
 public BooleanPrototype(MelonEngine engine, MelonType type) : base(engine, type)
 {
 }
 public FunctionPrototype(MelonEngine engine, MelonType type) : base(engine, type)
 {
 }
예제 #19
0
        public BooleanInstance(MelonEngine engine, bool val) : base(engine)
        {
            Type = engine.booleanType;

            value = val;
        }
예제 #20
0
 public ExpressionSolver(MelonEngine engine)
 {
     _engine = engine;
 }
예제 #21
0
 public FloatPrototype(MelonEngine engine, MelonType type) : base(engine, type)
 {
 }
예제 #22
0
        public IntegerInstance(MelonEngine engine, int val) : base(engine)
        {
            Type = engine.integerType;

            value = val;
        }
예제 #23
0
 public FloatType(MelonEngine engine) : base(engine)
 {
 }
예제 #24
0
 public IntegerPrototype(MelonEngine engine, MelonType type) : base(engine, type)
 {
 }
예제 #25
0
        public MelonInterpreter(MelonEngine engine)
        {
            _engine = engine;

            _expressionSolver = new ExpressionSolver(engine);
        }
예제 #26
0
        public FloatInstance(MelonEngine engine, double val) : base(engine)
        {
            Type = engine.floatType;

            value = val;
        }
예제 #27
0
        public ArrayInstance(MelonEngine engine, MelonObject[] vals) : base(engine)
        {
            Type = engine.arrayType;

            values = new List <MelonObject>(vals);
        }
예제 #28
0
 public IntegerType(MelonEngine engine) : base(engine)
 {
 }
예제 #29
0
 public MelonErrorObject(MelonEngine engine, string msg) : base(engine)
 {
     message = msg;
 }
예제 #30
0
 public MelonVisitor(MelonEngine engine)
 {
     _engine           = engine;
     _expressionSolver = new ExpressionSolver(engine);
 }