#640 Less redudant code should be generated by compiler

Open
opened 3 years ago by nero · 0 comments

Originally at 2013-08-29T12:46:17Z by Herbert Vojčík

fn: function (anObject){
var self=this;
return smalltalk.withContext(function($ctx1) { 
var $1,$2,$4,$5,$3;
$1=anObject;
if(($receiver = $1) == nil || $receiver == undefined){
$2=self._for_(self._defaultType());
return $2;
} else {
$1;
};
$4=self._for_(_st(anObject)._type());
_st($4)._setupFromJson_(anObject);
$5=_st($4)._yourself();
$3=$5;
return $3;
}

should be (ignoring semicolons after if, I will put it in another issue)

fn: function (anObject){
var self=this;
return smalltalk.withContext(function($ctx1) { 
var $1,$2;
$1=anObject;
if(($receiver = $1) == nil || $receiver == undefined){
return self._for_(self._defaultType());
};
$2=self._for_(_st(anObject)._type());
_st($2)._setupFromJson_(anObject);
return _st($2)._yourself();
}

That it is possible is proven by by the former design of new compiler (thrown in favour of multilayered OPAL one which we have today). The concept of aliasing used there was much stronger (probably because it was lazier) and produced denser output.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Originally at 2013-08-29T12:46:17Z by Herbert Vojčík ```js fn: function (anObject){ var self=this; return smalltalk.withContext(function($ctx1) { var $1,$2,$4,$5,$3; $1=anObject; if(($receiver = $1) == nil || $receiver == undefined){ $2=self._for_(self._defaultType()); return $2; } else { $1; }; $4=self._for_(_st(anObject)._type()); _st($4)._setupFromJson_(anObject); $5=_st($4)._yourself(); $3=$5; return $3; } ``` should be (ignoring semicolons after if, I will put it in another issue) ```js fn: function (anObject){ var self=this; return smalltalk.withContext(function($ctx1) { var $1,$2; $1=anObject; if(($receiver = $1) == nil || $receiver == undefined){ return self._for_(self._defaultType()); }; $2=self._for_(_st(anObject)._type()); _st($2)._setupFromJson_(anObject); return _st($2)._yourself(); } ``` That it is possible is proven by by the former design of new compiler (thrown in favour of multilayered OPAL one which we have today). The concept of aliasing used there was much stronger (probably because it was lazier) and produced denser output. <bountysource-plugin> --- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/7400889-less-redudant-code-should-be-generated-by-compiler?utm_campaign=plugin&utm_content=tracker%2F79201&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F79201&utm_medium=issues&utm_source=github). </bountysource-plugin>
Sign in to join this conversation.
No Label
No Milestone
No assignee
1 Participants
Loading...
Cancel
Save
There is no content yet.