changeset 110:d715fb3c39ab

Implemented clicking on symbols inside inscope box to replace function name in funcall.
author Mike Pavone <pavone@retrodev.com>
date Sat, 13 Apr 2013 23:37:54 -0700
parents a647cdad620b
children b2a3f202d485
files compiler.js editor.css editor.js jsbackend.js mquery.js src/editor.tp
diffstat 6 files changed, 84 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/compiler.js	Sat Apr 13 17:33:14 2013 -0700
+++ b/compiler.js	Sat Apr 13 23:37:54 2013 -0700
@@ -322,18 +322,7 @@
 
 function toobj(val)
 {
-	switch(typeof val)
-	{
-	case 'boolean':
-		if(val) {
-			return mainModule.strue;
-		} else {
-			return mainModule.sfalse;
-		}
-	case 'number':
-		return mainModule.snumber(val);
-	}
-	throw new Error("can't make val into object");
+	return (typeof val == "boolean") ? (val ? module_true : module_false) : val;
 }
 
 op.prototype.populateSymbols = function(symbols, isReceiver) {
--- a/editor.css	Sat Apr 13 17:33:14 2013 -0700
+++ b/editor.css	Sat Apr 13 23:37:54 2013 -0700
@@ -42,11 +42,16 @@
 	background-color: yellow;
 }
 
-#src .selected
+.selected
 {
 	background-color: #FFFFB0;
 }
 
+#src .selectParent
+{
+	background-color: #F5F5F5;
+}
+
 #editor
 {
 	display: none;
--- a/editor.js	Sat Apr 13 17:33:14 2013 -0700
+++ b/editor.js	Sat Apr 13 23:37:54 2013 -0700
@@ -120,3 +120,14 @@
 		}
 	}));
 }
+
+function getEl(from, idx)
+{
+	return from[idx];
+}
+
+function setEl(to, idx, val)
+{
+	to[idx] = val;
+	return to;
+}
--- a/jsbackend.js	Sat Apr 13 17:33:14 2013 -0700
+++ b/jsbackend.js	Sat Apr 13 23:37:54 2013 -0700
@@ -34,8 +34,14 @@
 }
 
 op.prototype.toJS = function(isReceiver) {
-	var opmap = {'=': '==', '.': '+'};
-	var ret = '(' + this.left.toJS() +' '+ (this.op in opmap ? opmap[this.op] : this.op) +' '+ this.right.toJS() + ')';
+	if (this.op == '&&') {
+		var ret = 'toobj(' + this.left.toJS() + ').sif(' + this.right.toJS() + ')';
+	} else if(this.op == '||') {
+		var ret = 'toobj(' + this.left.toJS() + ').ifnot(' + this.right.toJS() + ')';
+	} else {
+		var opmap = {'=': '==', '.': '+'};
+		var ret = '(' + this.left.toJS() +' '+ (this.op in opmap ? opmap[this.op] : this.op) +' '+ this.right.toJS() + ')';
+	}
 	return ret;
 };
 
@@ -315,8 +321,10 @@
 	'Number.prototype.__defineGetter__("string", function() { return "" + this; });\n' +
 	'String.prototype.__defineGetter__("string", function() { return this; });\n' +
 	'String.prototype.__defineGetter__("print", function() { write(this); });\n' +
-	'Array.prototype = function(action) { var ret = module_false; for (var i = 0; i < this.length; i++) { ret = action(i, this[i]) }; return ret; };\n' +
+	'Object.defineProperty(Array.prototype, "foreach", {value: function(action) { var ret = module_false; for (var i = 0; i < this.length; i++) { ret = action(i, this[i]) }; return ret; }});\n' +
 	'Function.prototype.whileCN_do = function(action) { var ret = module_false; while(toobj(this()) == module_true) { ret = action(); } return ret; };\n' +
+	'module_true.valueOf = function() { return true; }\n' +
+	'module_false.valueOf = function() { return false; }\n' +
 	'function toobj(val) {\n' + 
 	'	return (typeof val == "boolean") ? (val ? module_true : module_false) : val;\n' + 
 	'}\n' + 
--- a/mquery.js	Sat Apr 13 17:33:14 2013 -0700
+++ b/mquery.js	Sat Apr 13 23:37:54 2013 -0700
@@ -1,6 +1,6 @@
 function each(container, fun)
 {
-	if (container instanceof Array) {
+	if (container instanceof Array || container instanceof HTMLCollection || container instanceof NodeList) {
 		for (var i = 0; i < container.length; i++) {
 			fun(i, container[i]);
 		}
@@ -68,6 +68,11 @@
 	} 
 }
 
+function hasClass(el, classname)
+{
+	return el.className == classname || el.className.split(' ').indexOf(classname) > -1
+}
+
 function ajax(method, url, data, onSuccess, onFail, onOthers)
 {
 	var req;
@@ -110,6 +115,7 @@
 
 function newEl(tagname, props)
 {
+	console.log('tagname:', tagname, 'props:', props);
 	var el = document.createElement(tagname);
 	if (typeof props == 'object') {
 		each(props, function (key, val) {
--- a/src/editor.tp	Sat Apr 13 17:33:14 2013 -0700
+++ b/src/editor.tp	Sat Apr 13 23:37:54 2013 -0700
@@ -5,7 +5,10 @@
 each <- foreign: :iterable fun {}
 addClass <- foreign: :node className {}
 removeClass <- foreign: :node className {}
+hasClass <- foreign: :node className {}
 get <- foreign: :url onSuccess onFail onOther {}
+getEl <- foreign: :from idx {}
+setEl <- foreign: :to idx val {}
 newEl <- foreign: :tagname props {}
 
 //TP Parser
@@ -101,7 +104,51 @@
 	syms <- filter: (symtable allSymbols: (foreign: undefined)) :sym {
 		isLambda: ((symtable find: sym) def)
 	}
-	popInscope: syms onClick: {}
+	popInscope: syms onClick: :key {
+		astnode name!: key
+		parts <- key split: ":"
+		parent <- domnode parentNode
+		nodes <- []
+		each: (parent children) :idx val{
+			nodes push: val
+		}
+		partIdx <- 0
+		nodeIdx <- 0
+		lastWasNamePart <- true
+		while: { partIdx < (parts length) || nodeIdx < (nodes length) } do: {
+			if: nodeIdx < (nodes length) {
+				node <-getEl: nodes nodeIdx
+				nodeIdx <- nodeIdx + 1
+				if: (hasClass: node "funpart") {
+					if: partIdx < (parts length) {
+						postfix <- if: partIdx = 0 && nodeIdx = 2 && (parts length) = 1 && (nodes length) = 2 { "" } else: { ":" }
+						t <- (getEl: parts partIdx)
+						node textContent!: (getEl: parts partIdx) . postfix
+						partIdx <- partIdx + 1
+					} else: {
+						parent removeChild: node
+					}
+					lastWasNamePart <- true
+				} else: {
+					if: (not: lastWasNamePart) && partIdx < (parts length) && nodeIdx > 0 {
+						parent insertBefore: (newEl: "span" #{
+							className <- "funpart selected"
+							textContent <- (getEl: parts partIdx) . ":"
+						}) node
+						partIdx <- partIdx + 1
+					}
+					lastWasNamePart <- false
+				}
+			} else: {
+				console log: "part: " . (getEl: parts partIdx)
+				parent appendChild: (newEl: "span" #{
+					className <- "funpart selected"
+					textContent <- (getEl: parts partIdx) . ":"
+				})
+				partIdx <- partIdx + 1
+			}
+		}
+	}
 	event stopPropagation: (foreign: undefined)
 }