Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function module(sockets, receiverid, func){
- this.receiverid = receiverid
- this.sockets = sockets.split(':');
- this.data = {};
- this.functions = {
- add: function(mdl){
- var res = mdl.data['l1'].shift()+mdl.data['l3'].shift();
- mdl.output('r2',res);
- },
- mul: function(mdl){
- var res = mdl.data['l1'].shift()*mdl.data['l3'].shift();
- mdl.output('r2',res);
- },
- sub: function(mdl){
- var res = mdl.data['l1'].shift()-mdl.data['l3'].shift();
- mdl.output('r2',res);
- },
- copy: function(mdl){
- var res = mdl.data['l2'].shift();
- mdl.output('r1',res);
- mdl.output('r3',res);
- },
- comp: function(mdl){
- var a = mdl.data['l1'].shift();
- var b = mdl.data['l3'].shift();
- mdl.output('r1',Math.max(a,b));
- mdl.output('r3',Math.min(a,b));
- },
- uni: function(mdl){
- if (typeof mdl.data['l1'] != 'undefined')
- if( typeof mdl.data['l1'][0] != 'undefined')
- mdl.output('r2',mdl.data['l1'].shift());
- if (typeof mdl.data['l3'] != 'undefined')
- if (typeof mdl.data['l3'][0] != 'undefined')
- mdl.output('r2',mdl.data['l3'].shift());
- },
- eq: function(mdl){
- var a = mdl.data['l1'].shift();
- var b = mdl.data['l3'].shift();
- if (a == b){
- mdl.output('r2',a);
- }
- else{
- mdl.output('t2',a);
- mdl.output('b2',b);
- }
- },
- grt: function(mdl){
- var a = mdl.data['l1'].shift();
- var b = mdl.data['l3'].shift();
- if (a >= b){
- mdl.output('t2',a);
- mdl.output('b2',b);
- }
- else{
- mdl.output('r1',a);
- mdl.output('r3',b);
- }
- },
- div: function(mdl){
- var a = mdl.data['l1'].shift();
- var b = mdl.data['l3'].shift();
- mdl.output('r1',(a-a%b)/b);
- mdl.output('r3',a%b);
- },
- zero: function(mdl){
- var a = mdl.data['l1'].shift();
- var b = mdl.data['l3'].shift();
- if (a == 0){
- mdl.output('r2',b);
- }
- else if (b == 0){
- mdl.output('r2',a);
- }
- else{
- mdl.output('t2',a);
- mdl.output('b2',b);
- }
- },
- gcd: function(mdl){
- var res = gcd(mdl.data['l1'].shift(),mdl.data['l3'].shift());
- mdl.output('r2',res);
- }
- }
- this.input = function(socket,data){
- if (typeof this.data[socket] == 'undefined')
- this.data[socket] = [];
- this.data[socket].push(data);
- while(this.dataCheck())
- this.proceed();
- }
- this.dataClear = function(){
- this.data = {};
- }
- this.dataCheck = function(){
- var ok = true;
- if (typeof this.data != 'undefined') {
- this.sockets.forEach(function(item){
- if (item[2] == 'i' && item[3] == 'r'){
- if (typeof this.data[item[0]+item[1]] == 'undefined' ){
- ok = false;
- }
- else if(typeof this.data[item[0]+item[1]][0] == 'undefined'){
- ok = false;
- }
- }
- },this);
- var empty = true;
- this.sockets.forEach(function(item){
- if (item[2] == 'i'){
- if (typeof this.data[item[0]+item[1]] != 'undefined' ){
- if(typeof this.data[item[0]+item[1]][0] != 'undefined' ){
- empty = false;
- }
- }
- }
- },this);
- if (empty)
- ok = false;
- } else ok = false;
- return ok;
- }
- this.proceed = function(){
- this.functions[func](this);
- };
- this.output = function(socket,data){
- var sides = {
- t:"top",
- r:"right",
- b:"bottom",
- l:"left"
- };
- var connectorId = $('.receiver[data-receiverid='+this.receiverid+']').find('.'+sides[socket[0]]).find('.pos'+socket[1]).attr('data-connectorid');
- sendData(data,connectorId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement