From c6fdc53d2176f5844ee198d03b97cca63dd9197f Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Sat, 9 Jan 2021 23:39:29 +0900 Subject: [PATCH] Add "V" --- others/planck.c | 3 +++ others/planck.py | 7 +++++++ planck.xxd | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/others/planck.c b/others/planck.c index eae7e59..e8a0f5c 100644 --- a/others/planck.c +++ b/others/planck.c @@ -13,6 +13,8 @@ #include #include +#define VERSION "C implementation" + typedef uintptr_t cell; typedef void (**cfa)(); @@ -141,6 +143,7 @@ defcode("t", type) { putchar(pop()); next(); } defcode("x", exec) { (*(ip = (cfa) pop()))(); } defcode("f", find_) { push((cell) find(pop())); next(); } defcode("v", argv_) { push((cell) saved_argv); push(saved_argc); next(); } +defcode("V", version) { push((cell) VERSION); next(); } #define defbinary(name, label, op, ty) \ defcode(name, label) { \ ty b = (ty) pop(); \ diff --git a/others/planck.py b/others/planck.py index 9951be2..4dbf74f 100644 --- a/others/planck.py +++ b/others/planck.py @@ -7,6 +7,7 @@ import os import sys import operator +VERSION = "Python 3.x implementation" MEMORY_SIZE = 0x20000 STACK_SIZE = 0x400 RSTACK_SIZE = 0x400 @@ -156,6 +157,11 @@ ARGV_ADDR = read(HERE_CELL) for addr in argv_addrs: comma(addr) +# Version String +VERSION_ADDR = read(HERE_CELL) +comma_string(VERSION) +align() + def docol(ip, np): rpush(np) return next(ip + 4) @@ -217,6 +223,7 @@ def argv(): push(ARGV_ADDR) push(len(sys.argv)) add_simple_operator('v', argv) +add_simple_operator('V', lambda: push(VERSION_ADDR)) SUCCESS = 0 ALLOCATE_ERROR = -59 diff --git a/planck.xxd b/planck.xxd index 7071788..a798566 100644 --- a/planck.xxd +++ b/planck.xxd @@ -6,10 +6,10 @@ 00000028: 3400 2000 0100 0000 e_ehsize,e_phentsize,e_phnum,e_shentsize 00000030: 0000 0000 0100 0000 e_shnum,e_shstrndx,p_type=PT_LOAD 00000038: 0000 0000 0080 0408 p_offset,p_vaddr=0x08048000 -00000040: 0000 0000 9403 0000 p_paddr,p_filesz +00000040: 0000 0000 d003 0000 p_paddr,p_filesz 00000048: 0000 2000 0700 0000 p_memsz(128KB),p_flags=PF_X|PF_W|PF_R -00000050: 0010 0000 9483 0408 p_align, -00000058: 7483 0408 0000 0000 , +00000050: 0010 0000 d083 0408 p_align, +00000058: 9483 0408 0000 0000 , 00000060: e480 0408 5c81 0408 key, find 00000068: 8881 0408 3081 0408 execute, jump 00000070: f0ff ffff be60 8004 -16, movl $interpreter, %esi @@ -156,3 +156,12 @@ 0000037c: 8083 0408 8b05 5c80 movl sp0,%eax; 00000384: 0408 89c3 83c3 0453 movl %eax,%ebx; addl $4,%ebx; pushl %ebx 0000038c: ff30 adff 2000 0000 pushl (%eax); next; + +00000394: 7483 0408 0156 0000 V: version +0000039c: 8083 0408 68a8 8304 pushl $version +000003a4: 08ad ff20 6861 6e64 next; hand +000003ac: 2d77 7269 7474 656e -written +000003b4: 2069 3338 362d 6c69 i386-li +000003bc: 6e75 7820 696d 706c nux impl +000003c4: 656d 656e 7461 7469 ementati +000003cc: 6f6e 0000 on