예제 #1
0
        public static bool MatchObjects(object obj1, object obj2, Context context)
        {
            if (obj1 == null)
                if (obj2 == null)
                    return true;
                else
                    return false;

            if (obj1 is Variable)
                obj1 = (new VariableExpression((Variable)obj1)).Evaluate(context, true);

            if (obj2 is Variable)
                obj2 = (new VariableExpression((Variable)obj2)).Evaluate(context, true);

            if (obj1.Equals(obj2))
                return true;

            if (obj1 is Variable && !(obj2 is Variable))
            {
                Variable variable = (Variable)obj1;

                if (variable.Name != "_")
                    context.SetValue(variable.Name, obj2);

                return true;
            }

            if (obj2 is Variable && !(obj1 is Variable))
            {
                Variable variable = (Variable)obj2;
                context.SetValue(variable.Name, obj1);
                return true;
            }

            if (obj1 is Atom)
                if (obj2 is Atom)
                    return ((Atom)obj1).Match((Atom)obj2);
                else
                    return false;

            if (obj1 is List)
                if (obj2 is List)
                    return ((List)obj1).Match((List)obj2, context);
                else
                    return false;

            if (obj1 is Tuple)
                if (obj2 is Tuple)
                    return ((Tuple)obj1).Match((Tuple)obj2, context);
                else
                    return false;

            return false;
        }
예제 #2
0
파일: Machine.cs 프로젝트: ajlopez/ErlSharp
        public Machine()
        {
            this.rootcontext = new Context();
            this.rootcontext.SetValue("c/1", new CompileModuleFunction(this));
            this.rootcontext.SetValue("spawn/1", new SpawnFunction());
            this.rootcontext.SetValue("self/0", new SelfFunction());

            this.TextWriter = System.Console.Out;

            Module lists = new ListsModule(this.rootcontext);
            this.rootcontext.SetValue(lists.Name, lists);

            Module io = new IoModule(this);
            this.rootcontext.SetValue(io.Name, io);
        }
예제 #3
0
파일: Context.cs 프로젝트: ajlopez/ErlSharp
 public void SetParent(Context parent)
 {
     this.parent = parent;
 }
예제 #4
0
파일: Context.cs 프로젝트: ajlopez/ErlSharp
 public Context(Context parent = null, Module module = null)
 {
     this.parent = parent;
     this.module = module;
 }