view editor.js @ 251:2557ce4e671f

Fix a couple of compiler bugs. topenv was getting initialized in multiple places. This resulted in multiple copies of modules getting created which caused problems for macro expansion. Additionally, arguments were not being marked as declared during code generation so assigning to an argument that was not closed over generated invalid C code.
author Michael Pavone <pavone@retrodev.com>
date Fri, 11 Apr 2014 22:29:32 -0700
parents 15aac5334b64
children
line wrap: on
line source



object.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	var el = newEl('div', {
		className: 'object',
		onclick: function(event) {
			main_module.objectClick(this, astNode, event);
		}
	});
	this.domNode = el;
	node.appendChild(el);
	for (var i in this.messages) {
		this.messages[i].toHTML(el, this);
	}
};

object.prototype.getNext = function(curNode) {
	for (var i = 0; i < this.messages.length-1; i++) {
		if (this.messages[i] == curNode) {
			return this.messages[i+1];
		}
	}
	return this.up.getNext(this);
};

object.prototype.getPrev = function(curNode) {
	for (var i = 1; i < this.messages.length; i++) {
		if (this.messages[i] == curNode) {
			return this.messages[i - 1];
		}
	}
	return this.up.getPrev(this);
};

lambda.prototype.toHTML = function(node, up) {
	this.up = up
	var astNode = this;
	var el = newEl('div', {
		className: 'lambda',
		onclick: function(event) {
			main_module.lambdaClick(this, astNode, event);
		}
	});
	this.domNode = el;
	var args = newEl('div', {
		className: 'args'
	});
	for (var i in this.args) {
		this.args[i].toHTML(args, this);
	}
	var body = newEl('div', {
		className: 'lambdabody'
	});
	for (var i in this.expressions) {
		this.expressions[i].toHTML(body, this);
	}
	el.appendChild(args);
	el.appendChild(body);
	node.appendChild(el);
};

lambda.prototype.getNext = function(curNode) {
	for (var i = 0; i < this.args.length; i++) {
		if (this.args[i] == curNode) {
			if ((i + 1) < this.args.length) {
				return this.args[i+1];
			} else if(this.expressions.length) {
				return this.expressions[0];
			} else {
				break;
			}
		}
	}
	for (var i = 0; i < this.expressions.length-1; i++) {
		if (this.expressions[i] == curNode) {
			return this.expressions[i+1];
		}
	}
	return this.up.getNext(this);
};

lambda.prototype.getPrev = function(curNode) {
	for (var i = 0; i < this.args.length; i++) {
		if (this.args[i] == curNode) {
			if (i > 0) {
				return this.args[i-1];
			} else {
				return this.up.getPrev(this);
			}
		}
	}
	for (var i = 0; i < this.expressions.length; i++) {
		if (this.expressions[i] == curNode) {
			if (i > 0) {
				return this.expressions[i-1];
			} else if(this.args.length) {
				return this.args[this.args.length-1];
			} else {
				break;
			}
		}
	}
	return this.up.getPrev(this);
};

assignment.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	var base = newEl('div', {
		className: 'assignment',
		onclick: function(event) {
			main_module.assignClick(this, astNode, event);
		}
	});
	var varName = newEl('span', {
		textContent: this.symbol.name,
		className: 'varname'
	});
	this.domNode = base;
	base.appendChild(varName);
	node.appendChild(base);
	this.expression.toHTML(base, this);
};

assignment.prototype.getNext = function(curNode) {
	return this.up.getNext(this);
};

assignment.prototype.getPrev = function(curNode) {
	return this;
};

op.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	var base = newEl('span', {
		className: 'op',
		onclick: function(event) {
			main_module.opClick(this, astNode, event);
		}
	});
	this.domNode = base;
	this.left.toHTML(base, this);
	base.appendChild(newEl('span', {
		textContent: this.op,
		className: 'opname'
	}));
	if (this.op == '&&' || this.op == '||') {
		this.right.expressions[0].toHTML(base, this);
	} else {
		this.right.toHTML(base, this);
	}
	node.appendChild(base);
};

op.prototype.getNext = function(curNode) {
	if (this.left == curNode) {
		return this.right;
	}
	return this.up.getNext(this);
};

op.prototype.getPrev = function(curNode) {
	if (this.right == curNode) {
		return this.left;
	}
	return this.up.getPrev(this);
};

intlit.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	this.domNode = newEl('span', {
		className: 'integer',
		textContent: this.val,
		onclick: function(event) {
			main_module.scalarClick(this, astNode, event);
		}
	});
	node.appendChild(this.domNode);
};

floatlit.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	this.domNode = newEl('span', {
		className: 'float',
		textContent: this.val,
		onclick: function(event) {
			main_module.scalarClick(this, astNode, event);
		}
	});
	node.appendChild(this.domNode);
};

strlit.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	this.domNode = newEl('span', {
		className: 'string',
		contentEditable: 'true',
		textContent: this.val,
		onclick: function(event) {
			main_module.scalarClick(this, astNode, event);
		}
	});
	node.appendChild(this.domNode);
};

listlit.prototype.toHTML = function(node, up) {
	this.up = up;
	this.domNode = newEl('span', {
		className: 'listlit',
	});
	for (var i = 0; i < this.val.length; i++) {
		this.val[i].toHTML(this.domNode, this);
	}
	node.appendChild(this.domNode);
};

listlit.prototype.getNext = arraylit.prototype.getNext = function(curNode) {
	for (var i = 0; i < this.val.length; i++) {
		if (this.val[i] == curNode) {
			if ((i + 1) < this.val.length) {
				return this.val[i+1];
			} else {
				break;
			}
		}
	}
	return this.up.getNext(this);
};

listlit.prototype.getPrev = arraylit.prototype.getPrev = function(curNode) {
	for (var i = 0; i < this.val.length; i++) {
		if (this.val[i] == curNode) {
			if (i > 0) {
				return this.val[i-1];
			} else {
				break;
			}
		}
	}
	return this.up.getPrev(this);
};

arraylit.prototype.toHTML = function(node, up) {
	this.up = up;
	this.domNode = newEl('span', {
		className: 'arraylit',
	});
	for (var i = 0; i < this.val.length; i++) {
		this.val[i].toHTML(this.domNode, this);
	}
	node.appendChild(this.domNode);
};

funcall.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	var base = newEl('div', {
		className: 'funcall',
		onclick: function(event) {
			main_module.funClick(this, astNode, event);
		}
	});
	this.domNode = base;
	if (this.receiver) {
		this.receiver.toHTML(base, this);
	}
	var parts = this.name.split(':');
	for (var i in parts ) {
		if(parts[i]) {
			base.appendChild(newEl('span', {
				textContent: parts[i] + (this.receiver && parts.length == 1 ? '' : ':'),
				className: 'funpart'
				}));
			if (this.args[i]) {
				this.args[i].toHTML(base, this);
			}
		}
	}
	for (; i < this.args.length; i++) {
		this.args[i].toHTML(base, this);
	}
	node.appendChild(base);
};

funcall.prototype.getNext = function(curNode) {
	if (this.receiver == curNode && this.args.length) {
		return this.args[0];
	}
	for (var i = 0; i < this.args.length-1; i++) {
		if (this.args[i] == curNode) {
			return this.args[i+1];
		}
	}
	return this.up.getNext(this);
};

funcall.prototype.getPrev = function(curNode) {
	for (var i = 0; i < this.args.length; i++) {
		if (this.args[i] == curNode) {
			if (i > 0) {
				return this.args[i-1];
			} else if (this.receiver) {
				return this.receiver;
			} else {
				break;
			}
		}
	}
	return this.up.getPrev(this);
};

symbol.prototype.toHTML = function(node, up) {
	this.up = up;
	var astNode = this;
	this.domNode = newEl('span', {
		className: 'symbol',
		textContent: this.name,
		onclick: function(event) {
			main_module.symbolClick(this, astNode, event);
		}
	})
	node.appendChild(this.domNode);
}

function getEl(from, idx)
{
	return from[idx];
}

function setEl(to, idx, val)
{
	to[idx] = val;
	return to;
}

function goFullScreen()
{
	var el = q('body');
	if (el.requestFullscreen) {
		el.requestFullscreen();
	} else if (el.mozRequestFullScreen) {
		el.mozRequestFullScreen();
	} else {
		el.webkitRequestFullscreen();
	}
}

function create_symbol(name)
{
	return new symbol(name);
}