Created
October 8, 2018 15:00
-
-
Save masterex1000/468a662b5d70f134c68991390e2ed3a7 to your computer and use it in GitHub Desktop.
Ethos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<textarea type="textarea" placeholder="Ethos Code" v-model="code"></textarea> - {{ length }} | |
<p> | |
<textarea rows="10" cols="50">{{ output }}</textarea> | |
</p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = new Vue({ | |
el: '#app', | |
data: { | |
message: 'Hello Vue!', | |
code: "" | |
}, | |
computed: { | |
output () { | |
return execute(this.code); | |
}, | |
length () { | |
return this.code.length + " bytes"; | |
} | |
} | |
}) | |
//ETHOS stack based code golf thing. UNDER ACTIVE DEVELOPMENT. BREAKING CHANGES WILL HAPPEN!!!! | |
/** | |
*---------------ETHOS--------------- | |
* -- Stack based code golf language | |
* | |
* In-Code Docs: | |
* | |
* 1..9 : any number will be pushed to the stack | |
* | |
* o : puts the entire contents of the stack in cmem | |
* | |
* r : same as 'o' but it does it in reverse | |
* | |
* f : flushes the data in cmem to the cmd | |
* | |
* p : pops the last element off the stack | |
* | |
* c : clears cmem | |
* | |
* <, > : acts as a loop | |
* | |
* @ : pops last element then runs the latest | |
* loop that many times | |
* # : The same as running "9@" but it saves 1 byte | |
* | |
* _ : Pops the last two elements and turns them into | |
* a 2 digit number, then centers all text that | |
* many spaces in | |
* | |
*/ | |
function execute(ccode) { | |
var code = ccode; | |
var mem = {}; | |
var stack = []; | |
var nestOps = []; //stores the nested operations | |
var nesting = false; //says if we are nesting rignt now | |
var omem = ""; | |
var plength = 0; //sets the max width the output will be | |
var output = ""; | |
function exec(code, iVal) { | |
for(var i = 0; i < code.length; i++) { //iterate over the string | |
var c = code.charAt(i); | |
//console.log("" + i + " | " + c + " | " + nesting); | |
//console.log(stack); | |
if(nesting && c != ">") | |
nestOps[nestOps.length - 1] += c; | |
else if(nesting && c == ">") { | |
nesting = false; | |
} else if("0123456789".indexOf(c) != -1) { | |
stack.push(c); | |
} else if(c == "i") { //acts like a variable for looping | |
stack.push(iVal); | |
} else { | |
//console.log(c); | |
switch(c) { | |
case "o": //add contents of stack to output | |
for(var z = 0; z < stack.length; z++) { | |
omem += stack[z]; | |
} | |
break; | |
case "r": //add contents of the stack to output in reverse | |
for(var z = stack.length - 1; z >= 0; z--) { | |
omem += stack[z]; | |
} | |
break; | |
case "f": //flush output to the screen | |
var spaces = Math.max(Math.ceil(plength/2) - (omem.length / 2), 0); | |
for(var z = 0; z < spaces; z++) | |
omem = " " + omem; | |
//console.log(omem); | |
output += omem + "\n"; | |
omem = ""; | |
//math.ceil((x / 2) - (text:len() / 2)) | |
break; | |
case "p": //pop the last element from the stack | |
stack.pop(); | |
break; | |
case "c": //clear the output memory (same as flush but it dosen't print) | |
omem = ""; | |
break; | |
case "<": | |
//console.log("asdf"); | |
nesting = true; | |
nestOps[nestOps.length] = ""; | |
break; | |
case "@": | |
//console.log("asdf"); | |
var times = stack.pop(); | |
//console.log(times); | |
for(var z = 0; z < times; z++) { | |
exec(nestOps[nestOps.length - 1], z + 1); | |
} | |
nestOps.pop(); | |
break; | |
case "#": | |
exec("9@", iVal); | |
break; | |
case "_": | |
var len = parseInt((stack.pop() + stack.pop()).split('').reverse().join(''), 10); | |
plength = len; | |
break; | |
} | |
} | |
//console.log(c); | |
} | |
} | |
exec(code, 0); | |
return output; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment