summary refs log tree commit diff
diff options
context:
space:
mode:
-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;
 }
n title='2009-07-25 12:55:15 +0200'>2009-07-25Add support for mime type registration and lookupLars Hjemli 2009-07-25cgit.h: keep config flags sortedLars Hjemli 2009-07-25cgitrc.5.txt: document 'embedded' and 'noheader'Lars Hjemli 2009-07-25Add support for 'noheader' optionLars Hjemli 2009-07-25cgitrc.5.txt: document 'head-include'Lars Hjemli 2009-07-25ui-blob: return 'application/octet-stream' for binary blobsLars Hjemli 2009-07-25ui-plain: Return 'application/octet-stream' for binary files.Remko Tronçon 2009-06-11use cgit_httpscheme() for atom feedDiego Ongaro 2009-06-11add cgit_httpscheme() -> http:// or https://Diego Ongaro 2009-06-07Return http statuscode 404 on unknown branchLars Hjemli 2009-06-07Add head-include configuration option.Mark Lodato 2009-03-15CGIT 0.8.2.1Lars Hjemli 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli 2009-03-15fix segfault when displaying empty blobsEric Wong 2009-02-19Add support for HEAD requestsLars Hjemli 2009-02-19Add support for ETag in 'plain' viewLars Hjemli 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli 2009-02-12Makefile: add doc-related targetsLars Hjemli