summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2016-10-08 00:26:29 -0400
committerJune McEnroe <programble@gmail.com>2016-10-08 00:26:29 -0400
commit22d5ee3a223a73891a703a4b1c3901abc52dd3f7 (patch)
treed87a0609e6e606b74bfc6ac15924da5088a9f583
parentImplement jit_hop and jit_hop for jrp (diff)
downloadsrc-22d5ee3a223a73891a703a4b1c3901abc52dd3f7.tar.gz
src-22d5ee3a223a73891a703a4b1c3901abc52dd3f7.zip
Implement jrp JIT
-rwxr-xr-x.bin/jrp.c77
1 files changed, 49 insertions, 28 deletions
diff --git a/.bin/jrp.c b/.bin/jrp.c
index 8c436163..4dc6f16f 100755
--- a/.bin/jrp.c
+++ b/.bin/jrp.c
@@ -91,39 +91,60 @@ static void jit_fop(op fop) {
     *code.ptr++ = fop;
 }
 
+static void jit_print(void) {
+    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(FOP_CALL);
+}
+
 static void jit(char *src) {
     int error;
 
     code.ptr = code.base;
     jit_fop(FOP_PROL);
 
-    jit_fop(FOP_PUSH);
-    jit_fop(7);
-    jit_fop(FOP_PUSH);
-    jit_fop(10);
-    jit_fop(FOP_PUSH);
-    jit_fop(9);
-    jit_fop(FOP_MUL);
-    jit_hop(HOP_ADD);
-    jit_hop(HOP_DUP);
-    jit_hop(HOP_DUP);
-    jit_hop(HOP_DUP);
-    jit_hop(HOP_DUP);
-    jit_fop(FOP_CRT);
-    jit_fop((op)rt_print_ascii);
-    jit_fop(FOP_CALL);
-    jit_fop(FOP_CRT);
-    jit_fop((op)rt_print_bin);
-    jit_fop(FOP_CALL);
-    jit_fop(FOP_CRT);
-    jit_fop((op)rt_print_oct);
-    jit_fop(FOP_CALL);
-    jit_fop(FOP_CRT);
-    jit_fop((op)rt_print_dec);
-    jit_fop(FOP_CALL);
-    jit_fop(FOP_CRT);
-    jit_fop((op)rt_print_hex);
-    jit_fop(FOP_CALL);
+    while (*src) {
+        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 ';': jit_hop(HOP_DROP); break;
+            case ':': jit_hop(HOP_DUP);  break;
+            case 92:  jit_hop(HOP_SWAP); break;
+            case '_': jit_hop(HOP_NEG);  break;
+            case '+': jit_hop(HOP_ADD);  break;
+            case '-': jit_fop(FOP_SUB);  break;
+            case '*': jit_fop(FOP_MUL);  break;
+            case '/': jit_fop(FOP_DIV); jit_hop(HOP_QUO); break;
+            case '%': jit_fop(FOP_DIV); jit_hop(HOP_REM); break;
+            case '~': jit_hop(HOP_NOT);  break;
+            case '&': jit_hop(HOP_AND);  break;
+            case '|': jit_hop(HOP_OR);   break;
+            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;
+            default: {
+                char *rest;
+                value val = strtoll(src, &rest, radix);
+                if (rest != src) {
+                    src = rest;
+                    jit_fop(FOP_PUSH);
+                    jit_fop((op)val);
+                    continue;
+                }
+            }
+        }
+        src++;
+    }
 
     jit_fop(FOP_EPIL);
     jit_fop(FOP_RET);
@@ -147,7 +168,7 @@ int main() {
     if (stack == MAP_FAILED) err(EX_OSERR, "mmap");
     stack += page / sizeof(value) - 1;
 
-    jit("7 10 9 * + :::: , b. o. d. h.");
+    jit("7 10 9 * + :::: , b. o. d. x.");
 
     return EX_OK;
 }
er-highlight'> 2021-06-09Add seprintfJune McEnroe Based on seprint(2) from Plan 9. I'm not sure if my return value exactly matches Plan 9's in the case of truncation. seprint(2) is described only as returning a pointer to the terminating '\0', but if it does so even in the case of truncation, it is awkward for the caller to detect. This implementation returns end in the truncation case, so that (ptr == end) indicates truncation. 2021-05-27Add pounce-notify to README 2.4June McEnroe 2021-05-27Fix ENVIRONMENT formatting in pounce-notify(1)June McEnroe 2021-05-27Add note about Libera.Chat SASL-only rangesJune McEnroe 2021-05-25Add QUIRKS fileJune McEnroe 2021-05-19Replace freenode with tilde.chatJune McEnroe 2021-05-04notify: Reword pounce-notify manualJune McEnroe 2021-05-02Clean up Makefiles, configure scriptsJune McEnroe Default MANDIR to ${PREFIX}/man since it turns out man-db includes /usr/local/man by default. Add support for BINDIR. Separate libs out into LDADD variables. 2021-04-30palaver: Exit on getopt failureJune McEnroe Oops. 2021-04-30notify: Implement pounce-notifyJune McEnroe