Refactor out pushParams method

Simplifies hash and param push logic
This commit is contained in:
kpdecker
2014-01-06 14:41:23 -06:00
parent daeecf825c
commit c73aceb3d3
+20 -35
View File
@@ -186,30 +186,14 @@ Compiler.prototype = {
},
hash: function(hash) {
var pairs = hash.pairs, pair, val;
var pairs = hash.pairs, pair;
this.opcode('pushHash');
for(var i=0, l=pairs.length; i<l; i++) {
pair = pairs[i];
val = pair[1];
if (this.stringParams) {
if(val.depth) {
this.addDepth(val.depth);
}
this.opcode('getContext', val.depth || 0);
this.opcode('pushStringParam', val.stringModeValue, val.type);
if (val.type === 'sexpr') {
// Subexpressions get evaluated and passed in
// in string params mode.
this.sexpr(val);
}
} else {
this.accept(val);
}
this.pushParam(pair[1]);
this.opcode('assignToHash', pair[0]);
}
this.opcode('popHash');
@@ -382,27 +366,28 @@ Compiler.prototype = {
},
pushParams: function(params) {
var i = params.length, param;
var i = params.length;
while(i--) {
param = params[i];
this.pushParam(params[i]);
}
},
if(this.stringParams) {
if(param.depth) {
this.addDepth(param.depth);
}
this.opcode('getContext', param.depth || 0);
this.opcode('pushStringParam', param.stringModeValue, param.type);
if (param.type === 'sexpr') {
// Subexpressions get evaluated and passed in
// in string params mode.
this.sexpr(param);
}
} else {
this[param.type](param);
pushParam: function(val) {
if (this.stringParams) {
if(val.depth) {
this.addDepth(val.depth);
}
this.opcode('getContext', val.depth || 0);
this.opcode('pushStringParam', val.stringModeValue, val.type);
if (val.type === 'sexpr') {
// Subexpressions get evaluated and passed in
// in string params mode.
this.sexpr(val);
}
} else {
this.accept(val);
}
},