summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-x.bin/jrp.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/.bin/jrp.c b/.bin/jrp.c
index 1847bbe8..a7f71180 100755
--- a/.bin/jrp.c
+++ b/.bin/jrp.c
@@ -4,6 +4,7 @@ exec cc -Wall -Wextra $@ $0 -ledit -o $(dirname $0)/jrp
 
 #include <err.h>
 #include <histedit.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/mman.h>
@@ -100,14 +101,14 @@ static void jit_fop(op fop) {
     *code.ptr++ = fop;
 }
 
-static void jit_print(void) {
+static void jit_push(value imm) {
+    jit_fop(FOP_PUSH);
+    jit_fop((op)imm);
+}
+
+static void jit_call(void (*fn)(value)) {
     jit_fop(FOP_CRT);
-    switch (radix) {
-        case 2:  jit_fop((op)rt_print_bin); break;
-        case 8:  jit_fop((op)rt_print_oct); break;
-        case 10: jit_fop((op)rt_print_dec); break;
-        case 16: jit_fop((op)rt_print_hex); break;
-    }
+    jit_fop((op)fn);
     jit_fop(FOP_CALL);
 }
 
@@ -117,13 +118,20 @@ static void jit(const char *src) {
     code.ptr = code.base;
     jit_fop(FOP_PROL);
 
+    bool quote = false;
     while (*src) {
+        if (quote) {
+            jit_push(*src++);
+            quote = false;
+            continue;
+        }
         switch (*src) {
             case ' ': break;
-            case 'b': radix = 2;  break;
-            case 'o': radix = 8;  break;
-            case 'd': radix = 10; break;
-            case 'x': radix = 16; break;
+            case 39:  quote = true; break;
+            case 'b': radix = 2;    break;
+            case 'o': radix = 8;    break;
+            case 'd': radix = 10;   break;
+            case 'x': radix = 16;   break;
             case ';': jit_hop(HOP_DROP); break;
             case ':': jit_hop(HOP_DUP);  break;
             case 92:  jit_hop(HOP_SWAP); break;
@@ -139,15 +147,19 @@ static void jit(const char *src) {
             case '^': jit_hop(HOP_XOR);  break;
             case '<': jit_fop(FOP_SHL);  break;
             case '>': jit_fop(FOP_SHR);  break;
-            case ',': jit_fop(FOP_CRT); jit_fop((op)rt_print_ascii); jit_fop(FOP_CALL); break;
-            case '.': jit_print(); break;
+            case ',': jit_call(rt_print_ascii); break;
+            case '.': switch (radix) {
+                case 2:  jit_call(rt_print_bin); break;
+                case 8:  jit_call(rt_print_oct); break;
+                case 10: jit_call(rt_print_dec); break;
+                case 16: jit_call(rt_print_hex); break;
+            } break;
             default: {
                 char *rest;
                 value val = strtoll(src, &rest, radix);
                 if (rest != src) {
                     src = rest;
-                    jit_fop(FOP_PUSH);
-                    jit_fop((op)val);
+                    jit_push(val);
                     continue;
                 }
             }
nize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe It's actually in a good state now, I think. 2019-02-21Replace "view" with "window"June McEnroe I think originally I didn't want to use the same word as curses WINDOW but it's really much clearer for the user if they're just called windows. UI code probably needs yet another rewrite though. Still feels messy. 2019-02-21Remove ROT13June McEnroe It's just not convenient when it can only do the whole line... 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe Otherwise the "Traveling" message isn't visible while connecting. 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe