# HG changeset patch # User Mike Pavone # Date 1365921474 25200 # Node ID d715fb3c39abab22fbee2fbf1bd2e06ba75a2630 # Parent a647cdad620b3afe6a9fe90397f8457bfbba7fce Implemented clicking on symbols inside inscope box to replace function name in funcall. diff -r a647cdad620b -r d715fb3c39ab compiler.js --- 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) { diff -r a647cdad620b -r d715fb3c39ab editor.css --- 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; diff -r a647cdad620b -r d715fb3c39ab editor.js --- 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; +} diff -r a647cdad620b -r d715fb3c39ab jsbackend.js --- 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' + diff -r a647cdad620b -r d715fb3c39ab mquery.js --- 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) { diff -r a647cdad620b -r d715fb3c39ab src/editor.tp --- 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) }