Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Fully implement #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Soaku committed Jan 8, 2019
1 parent b8ffc4d commit 582d661
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
15 changes: 13 additions & 2 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,19 @@ List of commands available in Pepe.
- `EEee` - [Forward - Move WS pointer to next item](https://github.com/Soaku/Pepe/projects/2#card-7337906)
- `EeEE` - [Set position to random item](https://github.com/Soaku/Pepe/projects/2#card-7487437)
- `EeEe` - Empty (reserved for random function)
- `EeeE` - [Push pointer position (0-indexed)](https://github.com/Soaku/Pepe/issues/10)
- `Eeee` - [Push pointer position in reverse](https://github.com/Soaku/Pepe/issues/10)
- `EeeE` - [Push pointer position (0-indexed)][i10]
- `Eeee` - [Push pointer position in reverse][i10]
- `eEEE` - [Move input pointer to the first item][i10]
- `eEEe` - [Move input pointer to the last item][i10]
- `eEeE` - [Move input pointer to the previous item][i10]
- `eEee` - [Move input pointer to the next item][i10]
- `eeEE` - [Push input pointer position][i10]
- `eeEe` - [Push amount of input items left][i10]
- Warning: this will return a negative number if end of input was crossed.
- `eeeE` - [Lock input pointer – prevent automatic changes to it][i10]
- `eeee` - [Unlock input pointer – allow automatic changes to it][i10]

[i10]: https://github.com/Soaku/Pepe/issues/10

### [5 E/e (32) Active item](https://github.com/Soaku/Pepe/projects/2#column-2173896)

Expand Down
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,11 @@
$("#debug, #output").text("");

var inputs = $("#input").val();
if ($("#isinpsep").is(":checked")) inputs = inputs.split($("#inpsep").val());
else inputs = [inputs];
if ($("#isinpsep").is(":checked")) {
if (inputs.length) inputs = inputs.split($("#inpsep").val());
else inputs

} else inputs = [inputs];

if ($("[name=step]:checked").length) {
$("#run").text("Restart");
Expand Down
48 changes: 43 additions & 5 deletions js/pepe.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Before entering this file, be aware that this is my second worst code I've ever written.
// TODO: Rewrite this.

function nthroot(x, n) {
try {
var negate = n % 2 == 1 && x < 0;
Expand Down Expand Up @@ -147,6 +150,7 @@ function pepe(code, inp) {
var out = "";
var flags = {};
var ip = 0;
var iplock = false;
var returns = [];

function getinp() {
Expand Down Expand Up @@ -377,7 +381,7 @@ function pepe(code, inp) {
debug("input:",parse)
stack.push(parse);
}
ip++;
if (!iplock) ip++;
break;

case "EEe":
Expand All @@ -387,7 +391,7 @@ function pepe(code, inp) {
for (let j = 0; j < getinp().length; j++) {
stack.push(getinp().charCodeAt(j));
}
ip++;
if (!iplock) ip++;
break;

case "EeE":
Expand All @@ -400,7 +404,7 @@ function pepe(code, inp) {
expl += "Input (int): "+Math.round(getinp());
stack.push(Math.round(getinp()))
}
ip++;
if (!iplock) ip++;
break;

case "Eee":
Expand All @@ -413,7 +417,7 @@ function pepe(code, inp) {
expl += "Input (float): "+getinp();
stack.push(parseFloat(getinp()))
}
ip++;
if (!iplock) ip++;
break;

case "eEE":
Expand Down Expand Up @@ -475,7 +479,41 @@ function pepe(code, inp) {
cmdflag(patterns.pos);
expl += "Push reverse pointer position";
stack.push(stack.array.length - stack.pointer - 1)
break;
break;
case "eEEE":
ip = 0;
expl += "Move input pointer before the first item ("+ip+")";
break;
case "eEEe":
ip = inp.length -1;
expl += "Move input pointer before the last item ("+ip+")";
break;
case "eEeE":
ip = Math.max(ip-1, 0);
expl += "Move input pointer to previous item ("+ip+")";
break;
case "eEee":
ip++;
expl += "Move input pointer to next item ("+ip+")";
break;
case "eeEE":
stack.push(ip);
expl += "Push input pointer position ("+ip+")";
break;
case "eeEe":
var pos = inp.length - ip;
stack.push(pos);
expl += "Push amount of input items left ("+pos+")";
break;
case "eeeE":
expl += "Lock input pointer";
iplock = true;
break;
case "eeee":
expl += "Unlock input pointer";
iplock = false;
break;


// 5 E/e (active)
case "EEEEE": // ++
Expand Down

0 comments on commit 582d661

Please sign in to comment.