Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: drewlesueur/thumbs
base: bfe26e6bb4
...
head fork: drewlesueur/thumbs
compare: edb93ed3b4
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 50 additions and 42 deletions.
  1. +13 −0 index.html
  2. +12 −1 thumbs-test.thumbs
  3. +17 −37 thumbs.js
  4. +8 −4 thumbs2.js
View
13 index.html
@@ -158,6 +158,17 @@
</script>
<script type="text/thumbs" id="tests">
+
+sayHi * name
+ ' hello $name
+
+phrase sayHi. 'drew
+eq. phrase ' hello drew
+
+phrase SayHi $drew
+Eq phrase $ hello drew
+
+
Start
stuff #
@@ -168,6 +179,8 @@
+
+
people + $tom $dale $bert
peopleActions #
eachPerson * person
View
13 thumbs-test.thumbs
@@ -4,8 +4,19 @@
;assert x 1
;assert [this_is_line_index_2] 2
+;fn [sayHi] $sayHi
+;call sayHi
+
+;stop
+[sayHi]
+;say $hi_dude
+
+
+;set $x 0
+;fn [inc] $inc
+;return
+
-;debugger
;fn [incmaker] $incmaker
;call incmaker $inc
;stop
View
54 thumbs.js
@@ -349,7 +349,7 @@
var generateValue = function (second, rest, nestedArgs, currentScope) {
- if (second == "$") { //todo. do a faster way of converting to string //cache or something
+ if (isStringStart(second)) { //todo. do a faster way of converting to string //cache or something
value = setString(rest, nestedArgs, currentScope)
} else if (second == "+") {
value = setList(rest, nestedArgs, currentScope)
@@ -359,7 +359,7 @@
value = setOneLineFunction(rest, nestedArgs, currentScope)
} else if ((second - 0) == second) {
value = setNumber(second)
- } else if (second && second.match(/^[A-Z]/)) {
+ } else if (isFuncCall(second)) {
value = setFuncCall(second, rest, nestedArgs, currentScope);
} else if (!second && nestedArgs.length) {
value = setFunction(rest, nestedArgs, currentScope)
@@ -416,7 +416,7 @@
var callInRestIfNeeded = function (rest) {
if (!rest[0]) return;
- if (rest[0].match(/^[A-Z]/)) {
+ if (isFuncCall(rest[0])) {
}
}
@@ -603,10 +603,13 @@
}
var isStartSymbol = function (thing) {
- return thing && thing.match && thing.match(/(^[\*\#\$\+\>]$)/)
+ return thing && thing.match && thing.match(/(^[\*\#\$\'\+\>]$)/)
}
var isFuncCall = function (thing) {
- return thing && thing.match && thing.match(/^[A-Z]/)
+ return (thing && thing.match && thing.match(/^[A-Z]/)) || (thing && thing.charAt && thing.charAt(thing.length - 1) == ".")
+ }
+ var isStringStart = function (thing) {
+ return thing == "$" || thing == "'"
}
var callFunction = function (first, second, rest, nestedArgs, currentScope) {
var fn = get(first/*.toLowerCase()*/, currentScope)
@@ -649,6 +652,7 @@
opts = opts || {}
lookupScope = lookupScope || currentScope;
+
if (name == "0") {
var a = 1
}
@@ -657,13 +661,17 @@
return name
}
- if (name.charAt && name.charAt(0) == "$") {
+ if (name.charAt && isStringStart(name.charAt(0))) {
return name.substring(1)
} else if (name - 0 == name && !opts.inChain) { //wierd
return name - 0
}
var names = name.split(/\.|\:/)
+ if (names[names.length - 1] == "") { //remove the last dot for function calls
+ names.pop();
+ name = names[0]
+ }
if (names.length > 1) {
var symbols = name.match(/\.|\:/g)
symbols.unshift(".")
@@ -720,18 +728,18 @@
}
if (first == "stop") {
return stopSignal;
- } if (first == "$") { //todo handle all the rest where it starts with a symbol
+ } if (isStringStart(first)) { //todo handle all the rest where it starts with a symbol
var theRest = [second].concat(__slice.call(rest))
var value = generateValue(first, theRest, nestedArgs, currentScope);
return value;
+ } else if (isFuncCall(first)) { //first check funciton call
+ return callFunction(first, second, rest, nestedArgs, currentScope)
} else if (first.match(/^[a-z]/)) {
return setValue(first, second, rest, nestedArgs, currentScope, opts)
} else if (first.match(/^\d/)) {
return setValue(first, second, rest, nestedArgs, currentScope, opts)
//} else if (first.match(/^[a-z]/) && !second) {
// return get(first, currentScope)
- } else if (first.match(/^[A-Z]/)) {
- return callFunction(first, second, rest, nestedArgs, currentScope)
}
}
@@ -785,39 +793,11 @@
}
- var addUI = function () {
- var codeEl = document.createElement("div")
- for (var i = 0; i < originalLines.length; i++) {
- var lineEl = document.createElement('pre')
- lineEl.setAttribute("class", "line")
- lineEl.setAttribute('data-line', i)
- codeEl.appendChild(lineEl)
- var line = originalLines[i]
- line = line.replace(/^([\s]*)([a-z][\w]+)/, function (all, s, w) {
- return s + "<span class='set'>" + w + '</span>'
- })
- line = line.replace(/^([\s]*)([A-Z][\w]*)/, function (all, s, w) {
- return s + "<span class='call'>" + w + '</span>'
- })
- line = line.replace(/^([\s]*)([A-Z][\w]*)/, function (all, s, w) {
- return s + "<span class='call'>" + w + '</span>'
- })
- line = line.replace(/^([\s]*)([\$].*)/, function (all, s, w) {
- return s + "<span class='text'>" + w + '</span>'
- })
- line = line.replace(/[\$][^\s]+/, function (all, s, w) {
- return "<span class='text'>" + all + '</span>'
- })
- lineEl.innerHTML = line
-
- }
- }
var run = function (code) {
parsed = parse(code);
originalLines = code.split("\n")
parsed = parsed.slice(1)
- //addUI(originalLines)
runParsed(parsed);
}
View
12 thumbs2.js
@@ -48,7 +48,11 @@ var instructionSet = {
console.log(what)
},
call: function (func, outputVar, scope) {
- console.log(func)
+ var line = func[0];
+ var funcScope = func[0]
+ callStack.
+ pc = line;
+
},
"return": function () {
@@ -122,12 +126,12 @@ var getLineStr = function () {
return line;
}
+var pc = 0; //program counter
var interpretBytecode = function (bytecodes, scope) {
var line, fn, args, ret;
var scope = scope || globalScope
- var i = 0;
var bytecodesLength = bytecodes.length
- while (i < bytecodesLength) {
+ while (pc < bytecodesLength) {
line = bytecodes[i];
fn = line[0];
args = line.slice(1);
@@ -156,7 +160,7 @@ var interpretBytecode = function (bytecodes, scope) {
if (ret == killSignal) {
break;
}
- i += 1
+ pc += 1
}
return ret
}

No commit comments for this range

Something went wrong with that request. Please try again.