# HG changeset patch # User Mike Pavone # Date 1334888421 25200 # Node ID 608eb70fe261ce3d85d9ca8bb9123341cce269da # Parent 18cec540238aa50c7102aa832174cf68969dadd0 Fix some compiler bugs and do initial work on module import diff -r 18cec540238a -r 608eb70fe261 compiler.js --- a/compiler.js Thu Apr 05 21:06:43 2012 -0700 +++ b/compiler.js Thu Apr 19 19:20:21 2012 -0700 @@ -3,11 +3,27 @@ return str.split('\n').join('\n\t'); } +function topsymbols() +{ + this.names = null; +} +topsymbols.prototype.find = function(name) { + if (!this.names) { + + } + if (name in this.names) { + return { + type: 'toplevel', + def: null + }; + } + return null; +} + function osymbols(parent) { this.parent = parent; this.names = {}; - this.lastname = null; } osymbols.prototype.find = function(name) { if (name in this.names) { @@ -36,7 +52,6 @@ return null; }; osymbols.prototype.defineMsg = function(name, def) { - this.lastname = name; this.names[name] = def; } osymbols.prototype.parentObject = function() { @@ -67,7 +82,6 @@ { this.parent = parent; this.names = {}; - this.lastname = null; this.needsSelfVar = false; } lsymbols.prototype.find = function(name) { @@ -92,7 +106,6 @@ return null; }; lsymbols.prototype.defineVar = function(name, def) { - this.lastname = name; this.names[name] = def; }; lsymbols.prototype.selfVar = function() { @@ -210,8 +223,10 @@ this.symbols = symbols; }; assignment.prototype.populateSymbolsObject = function(symbols) { - symbols.defineMsg(this.symbol.name, this.expression); - if (!(this.expression instanceof lambda) && !(this.expression instanceof funcall && this.expression.name == 'foreign:')) { + if (this.expression instanceof lambda || (this.expression instanceof funcall & this.expression.name == 'foreign:')) { + symbols.defineMsg(this.symbol.name, this.expression); + } else { + symbols.defineMsg(this.symbol.name, new getter(null)); symbols.defineMsg(this.symbol.name + '!', new setter(null)); } this.symbol.populateSymbols(symbols); @@ -223,9 +238,9 @@ { this.fun = fun; } - +setter.prototype.args = [new symbol('self'), new symbol('newval')]; function getter(fun) { this.fun = fun; } - +getter.prototype.args = [new symbol('self')]; diff -r 18cec540238a -r 608eb70fe261 editor.tp --- a/editor.tp Thu Apr 05 21:06:43 2012 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -#{ -//mquery functions -q <- foreign: :query {} -qall <- foreign: :query {} -each <- foreign: :iterable fun {} -addClass <- foreign: :node className {} -removeClass <- foreign: :node className {} -get <- foreign: :url onSuccess onFail onOther {} -newEl <- foreign: :tagname props {} - -//TP Parser -parser <- foreign: #{ - parse <- foreign: :str {} -} -isLambda <- foreign: :astnode {} - -//js builtins -console <- foreign: #{ - log <- foreign: :val {} -} -window <- foreign: #{} -Object <- foreign: #{ - keys <- foreign: :object {} -} - -//kernel definitions -true <- #{ - if:else <- :self trueblock :elseblock { - trueblock: - } -} - -false <- #{ - if:else <- :self trueblock :elseblock { - elseblock: - } -} - -filter <- :arr pred { - output <- arr slice: 0 0 - each: arr :idx el { - if: (pred: el) { - output push: el - } else: {} - } - output -} - -//editor code -editFile <- :path { - get: path :request { - addClass: (q: "body") "editorMode" - src <- request responseText - console log: src - ast <- parser parse: src - console log: ast - ast populateSymbols: (foreign: null) - ast toHTML: (q: "#src") - } -} - -selectNode <- :node { - each: (qall: ".selected") :idx el { - removeClass: el "selected" - } - addClass: node "selected" -} - -selectQuery <- :selector { - selectQuery: selector in: (foreign: undefined) -} - -selectQuery:in <- :selector :context { - each: (qall: ".selected") :idx el { - removeClass: el "selected" - } - each: (qall: selector context) :idx el { - addClass: el "selected" - } -} - -selectParent <- :node { - each: (qall: ".selectParent") :idx el { - removeClass: el "selected" - } - addClass: (node parentNode) "selectParent" -} - -popInscope:onClick <- :syms :handler { - inscope <- q: "#inscope" - inscope innerHTML!: "" - each: syms :idx key { - inscope appendChild: (newEl: "li" #{ - textContent <- key - onclick <- { handler: key } - }) - } -} - -symbolClick <- :domnode astnode event { - console log: astnode - selectNode: domnode - popInscope: ((astnode symbols) allSymbols) onClick: :key { - domnode textContent!: key - astnode name!: key - } - event stopPropagation -} - -funClick <- :domnode astnode event { - selectParent: domnode - selectQuery: ".selectParent > .funpart" in: (domnode parentNode) - symtable <- astnode symbols - syms <- filter: (symtable allSymbols) :sym { - isLambda: ((symtable find: sym) def) - } - popInscope: syms onClick: {} - event stopPropagation -} - -lambdaClick <- :domnode astnode event { - symbolClick: domnode astnode event -} - -main <- { - //bind handlers for file browser links - each: (qall: "a") :idx el { - el onclick!: :event { - link <- foreign: this - path <- link href - path <- path substr: (path indexOf: "/edit/") + 5 - console log: path - editFile: path - foreign: false - } - } - - //bind handlers for editor buttons - each: (qall: ".controls li") :idx el { - el onclick!: :event { - srcel <- (q: "#src") - srcel textContent!: (srcel textContent) + (el textContent) - } - } - (q: "#ops_button") onclick!: :event { - each: (qall: ".controls") :idx el { - addClass: el "showops" - } - } - - path <- (window location) pathname - if: (path indexOf: "/edit/") = 0 { - editFile: (path substr: 5) - } else: {} -} - -} diff -r 18cec540238a -r 608eb70fe261 index.html --- a/index.html Thu Apr 05 21:06:43 2012 -0700 +++ b/index.html Thu Apr 19 19:20:21 2012 -0700 @@ -10,14 +10,12 @@ - +
diff -r 18cec540238a -r 608eb70fe261 jsbackend.js --- a/jsbackend.js Thu Apr 05 21:06:43 2012 -0700 +++ b/jsbackend.js Thu Apr 19 19:20:21 2012 -0700 @@ -146,6 +146,12 @@ } else { var receiver = args[0]; args.splice(0, 1); + if (args.length == 0) { + var rJS = receiver.toJS(true); + var callee = rJS + '.' + escapeJSName(name); + + return '(' + callee + ' instanceof Function ? ' + callee + '() : ' + callee + ')'; + } } ret = receiver.toJS(true) + '.'; break; diff -r 18cec540238a -r 608eb70fe261 src/editor.tp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/editor.tp Thu Apr 19 19:20:21 2012 -0700 @@ -0,0 +1,167 @@ +#{ +//mquery functions +q <- foreign: :query {} +qall <- foreign: :query {} +each <- foreign: :iterable fun {} +addClass <- foreign: :node className {} +removeClass <- foreign: :node className {} +get <- foreign: :url onSuccess onFail onOther {} +newEl <- foreign: :tagname props {} + +//TP Parser +parser <- foreign: #{ + parse <- foreign: :str {} +} +isLambda <- foreign: :astnode {} + +//js builtins +console <- foreign: #{ + log <- foreign: :val {} +} +window <- foreign: #{} +Object <- foreign: #{ + keys <- foreign: :object {} +} + +//kernel definitions +true <- #{ + if:else <- :self trueblock :elseblock { + trueblock: + } +} + +false <- #{ + if:else <- :self trueblock :elseblock { + elseblock: + } +} + +filter <- :arr pred { + output <- arr slice: 0 0 + each: arr :idx el { + if: (pred: el) { + output push: el + } else: {} + } + output +} + +//editor code +editFile <- :path { + get: path :request { + addClass: (q: "body") "editorMode" + src <- request responseText + ast <- parser parse: src + ast populateSymbols: (foreign: null) + ast toHTML: (q: "#src") + } +} + +selectNode <- :node { + each: (qall: ".selected") :idx el { + removeClass: el "selected" + } + addClass: node "selected" +} + +selectQuery <- :selector { + selectQuery: selector in: (foreign: undefined) +} + +selectQuery:in <- :selector :context { + each: (qall: ".selected") :idx el { + removeClass: el "selected" + } + each: (qall: selector context) :idx el { + addClass: el "selected" + } +} + +selectParent <- :node { + each: (qall: ".selectParent") :idx el { + removeClass: el "selected" + } + addClass: (node parentNode) "selectParent" +} + +popInscope:onClick <- :syms :handler { + inscope <- q: "#inscope" + inscope innerHTML!: "" + each: syms :idx key { + inscope appendChild: (newEl: "li" #{ + textContent <- key + onclick <- { handler: key } + }) + } +} + +symbolClick <- :domnode astnode event { + console log: astnode + selectNode: domnode + popInscope: ((astnode symbols) allSymbols) onClick: :key { + domnode textContent!: key + astnode name!: key + } + event stopPropagation +} + +funClick <- :domnode astnode event { + selectParent: domnode + selectQuery: ".selectParent > .funpart" in: (domnode parentNode) + symtable <- astnode symbols + syms <- filter: (symtable allSymbols) :sym { + isLambda: ((symtable find: sym) def) + } + popInscope: syms onClick: {} + event stopPropagation +} + +lambdaClick <- :domnode astnode event { + symbolClick: domnode astnode event +} + +main <- { + get: "/src/" :data { + fakeEl <- newEl: "div" #{ + innerHTML <- data response + } + each: (qall: "a" fakeEl) :idx el { + if: ((el textContent) = "../") {} else: { + nel <- newEl: "a" #{ + href <- "/edit/src/" + (el textContent) + textContent <- el textContent + } + nel onclick!: :event { + link <- foreign: this + path <- link href + path <- path substr: (path indexOf: "/edit/") + 5 + editFile: path + foreign: false + } + li <- newEl: "li" + li appendChild: nel + (q: "#browser ul") appendChild: li + } + } + } + + //bind handlers for editor buttons + each: (qall: ".controls li") :idx el { + el onclick!: :event { + srcel <- (q: "#src") + srcel textContent!: (srcel textContent) + (el textContent) + } + } + (q: "#ops_button") onclick!: :event { + each: (qall: ".controls") :idx el { + addClass: el "showops" + } + } + + path <- (window location) pathname + if: (path indexOf: "/edit/") = 0 { + editFile: (path substr: 5) + } else: {} +} + +}