Advertisement
Guest User

Untitled

a guest
May 29th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function module(sockets, receiverid, func){
  2.     this.receiverid = receiverid
  3.     this.sockets = sockets.split(':');
  4.     this.data = {};
  5.     this.functions = {
  6.         add: function(mdl){
  7.             var res = mdl.data['l1'].shift()+mdl.data['l3'].shift();
  8.             mdl.output('r2',res);
  9.         },
  10.         mul: function(mdl){
  11.             var res = mdl.data['l1'].shift()*mdl.data['l3'].shift();
  12.             mdl.output('r2',res);
  13.         },
  14.         sub: function(mdl){
  15.             var res = mdl.data['l1'].shift()-mdl.data['l3'].shift();
  16.             mdl.output('r2',res);
  17.         },
  18.         copy: function(mdl){
  19.             var res = mdl.data['l2'].shift();
  20.             mdl.output('r1',res);
  21.             mdl.output('r3',res);
  22.         },
  23.         comp: function(mdl){
  24.             var a = mdl.data['l1'].shift();
  25.             var b = mdl.data['l3'].shift();
  26.             mdl.output('r1',Math.max(a,b));
  27.             mdl.output('r3',Math.min(a,b));
  28.         },
  29.         uni: function(mdl){
  30.             if (typeof mdl.data['l1'] != 'undefined')
  31.                 if( typeof mdl.data['l1'][0] != 'undefined')
  32.                     mdl.output('r2',mdl.data['l1'].shift());
  33.             if (typeof mdl.data['l3'] != 'undefined')
  34.                 if (typeof mdl.data['l3'][0] != 'undefined')
  35.                     mdl.output('r2',mdl.data['l3'].shift());
  36.         },
  37.         eq: function(mdl){
  38.             var a = mdl.data['l1'].shift();
  39.             var b = mdl.data['l3'].shift();
  40.             if (a == b){
  41.                 mdl.output('r2',a);
  42.             }
  43.             else{
  44.                 mdl.output('t2',a);
  45.                 mdl.output('b2',b);
  46.             }
  47.         },
  48.         grt: function(mdl){
  49.             var a = mdl.data['l1'].shift();
  50.             var b = mdl.data['l3'].shift();
  51.             if (a >= b){
  52.                 mdl.output('t2',a);
  53.                 mdl.output('b2',b);
  54.             }
  55.             else{
  56.                 mdl.output('r1',a);
  57.                 mdl.output('r3',b);
  58.             }
  59.         },
  60.         div: function(mdl){
  61.             var a = mdl.data['l1'].shift();
  62.             var b = mdl.data['l3'].shift();
  63.             mdl.output('r1',(a-a%b)/b);
  64.             mdl.output('r3',a%b);
  65.         },
  66.         zero: function(mdl){
  67.             var a = mdl.data['l1'].shift();
  68.             var b = mdl.data['l3'].shift();
  69.             if (a == 0){
  70.                 mdl.output('r2',b);
  71.             }
  72.             else if (b == 0){
  73.                 mdl.output('r2',a);
  74.             }
  75.             else{
  76.                 mdl.output('t2',a);
  77.                 mdl.output('b2',b);
  78.             }
  79.         },
  80.         gcd: function(mdl){
  81.             var res = gcd(mdl.data['l1'].shift(),mdl.data['l3'].shift());
  82.             mdl.output('r2',res);
  83.         }
  84.        
  85.     }
  86.  
  87.     this.input = function(socket,data){
  88.         if (typeof this.data[socket] == 'undefined')
  89.             this.data[socket] = [];
  90.         this.data[socket].push(data);
  91.         while(this.dataCheck())
  92.             this.proceed();
  93.     }
  94.  
  95.     this.dataClear = function(){
  96.         this.data = {};
  97.     }
  98.  
  99.     this.dataCheck = function(){
  100.         var ok = true;
  101.         if (typeof this.data != 'undefined') {
  102.             this.sockets.forEach(function(item){
  103.                 if (item[2] == 'i' && item[3] == 'r'){
  104.                     if (typeof this.data[item[0]+item[1]] == 'undefined' ){
  105.                         ok = false;
  106.                     }
  107.                     else if(typeof this.data[item[0]+item[1]][0] == 'undefined'){
  108.                         ok = false;
  109.                     }
  110.                 }
  111.             },this);
  112.             var empty = true;
  113.             this.sockets.forEach(function(item){
  114.                 if (item[2] == 'i'){
  115.                     if (typeof this.data[item[0]+item[1]] != 'undefined' ){
  116.                         if(typeof this.data[item[0]+item[1]][0] != 'undefined' ){
  117.                             empty = false;
  118.                         }
  119.                     }
  120.                 }
  121.             },this);
  122.             if (empty)
  123.                 ok = false;
  124.         } else ok = false;
  125.         return ok;
  126.     }
  127.  
  128.     this.proceed = function(){
  129.         this.functions[func](this);
  130.     };
  131.  
  132.     this.output = function(socket,data){
  133.         var sides = {
  134.             t:"top",
  135.             r:"right",
  136.             b:"bottom",
  137.             l:"left"
  138.         };
  139.  
  140.         var connectorId = $('.receiver[data-receiverid='+this.receiverid+']').find('.'+sides[socket[0]]).find('.pos'+socket[1]).attr('data-connectorid');
  141.         sendData(data,connectorId);
  142.     }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement