Ejemplo n.º 1
0
 public EFunctionOperation(EWord name, ETypeWord type, ETypeNameKey[] arguments, EOperation[] operations)
 {
     this.name      = name;
     this.type      = type;
     this.arguments = arguments;
     program        = new EProgram(operations);
 }
Ejemplo n.º 2
0
 public ECustomFunction(EWord name, ETypeWord type, EProgram program, ETypeNameKey[] arguments)
 {
     this.name      = name;
     this.type      = type;
     this.arguments = arguments;
     this.program   = program;
 }
Ejemplo n.º 3
0
        public EVariable Convert(ETypeWord to)
        {
            EVariable tryConvert = ConvertInternal(to);

            if (tryConvert != null)
            {
                return(tryConvert);
            }
            if (GetEType().Get() == to.Get())
            {
                return(this);
            }
            return(CannotConvert(to));
        }
Ejemplo n.º 4
0
        protected override EVariable ConvertInternal(ETypeWord to)
        {
            switch (to.Get())
            {
            case EType.Double:
                return(((EVDouble)New(to)).Set(value));

            case EType.Int:
                return(((EVInt)New(to)).Set(value));

            case EType.Boolean:
                return(((EVBoolean)New(to)).Set(value != 0));
            }
            return(null);
        }
Ejemplo n.º 5
0
        public override EVariable Exec(EScope scope, ESolvable[] args)
        {
            // TODO: output type casting
            if (args.Length != arguments.Length)
            {
                throw new ELangException("Wrong amount of args for function " + name);
            }

            EScope lowerScope = scope.GetChild();

            for (int i = 0; i < arguments.Length; i++)
            {
                string    argname = arguments[i].GetVariable().ToString();
                ETypeWord argtype = arguments[i].GetEType();

                EVariable solved = EVariable.New(argtype).Assign(args[i].Solve(lowerScope));
                lowerScope.Set(argname, solved);
            }

            return(Interpreter.Run(program, lowerScope));
        }
Ejemplo n.º 6
0
 protected EVariable CannotConvert(ETypeWord type)
 {
     throw new ELangException("Cannot convert " + type + " to " + GetEType());
 }
Ejemplo n.º 7
0
 protected virtual EVariable ConvertInternal(ETypeWord to)
 {
     return(null);
 }
Ejemplo n.º 8
0
 public static EVariable New(ETypeWord type)
 {
     return(New(type.Get()));
 }
Ejemplo n.º 9
0
 public ECustomFunction(EWord name, ETypeWord type, EProgram program) : this(name, type, program, new ETypeNameKey[] { })
 {
 }
Ejemplo n.º 10
0
 public ECreateOperation(EWord[] variables, ETypeWord type, ESolvable assign) : this(variables, type)
 {
     assignOperations = variables.Select(variable => new EAssignOperation(variable, assign)).ToArray();
 }
Ejemplo n.º 11
0
 public ECreateOperation(EWord[] variables, ETypeWord type)
 {
     this.variables = variables;
     this.type      = type;
 }
Ejemplo n.º 12
0
 public EGlobalFunction(EWord name, ETypeWord type, Func <EScope, ESolvable[], EVariable> func)
 {
     this.name = name;
     this.type = type;
     this.func = func;
 }
Ejemplo n.º 13
0
 public ETypeNameKey(EWord name, ETypeWord type)
 {
     variable  = name;
     this.type = type;
 }