From 9e8f63f841d8cf68e3bfff0445a910b49ec2fb12 Mon Sep 17 00:00:00 2001 From: ketmar Date: Tue, 24 Oct 2023 11:13:17 +0000 Subject: [PATCH] UrForth: added "FORTH:(DATASKIP)" FossilOrigin-Name: 01ed506e048e2d723b2601739a9acaf50761832d835aa2088d7bb2d291860bc4 --- dox/urforth.txt | 6 ++++++ src/liburforth/urforth.c | 33 +++++++++++---------------------- src/liburforth/urforth.h | 20 ++++++++++++-------- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/dox/urforth.txt b/dox/urforth.txt index ecca025..5262aed 100644 --- a/dox/urforth.txt +++ b/dox/urforth.txt @@ -180,6 +180,12 @@ skip next 4 bytes if `num` is positive (but not 0), otherwise perform "(BRANCH)" ( num -- ) skip next 4 bytes if `num` is negative, otherwise perform "(BRANCH)". +(DATASKIP) +( -- ) +read next 4 bytes, advance IP. then increment IP by the read number. +this is used to tell the decompiler that it should skip some inline +data instead of trying to decompile it. + EXECUTE ( cfa ) pop word CFA address, and execute it. diff --git a/src/liburforth/urforth.c b/src/liburforth/urforth.c index 0381f18..362953d 100644 --- a/src/liburforth/urforth.c +++ b/src/liburforth/urforth.c @@ -257,10 +257,7 @@ UFO_FORCE_INLINE int digitInBase (char ch, int base) { ;; 5: cblock ;; 6: vocid ;; 7: byte-counted string with terminating zero (not counted) -;; 8: *UNUSED* unsigned byte -;; 9: *UNUSED* signed byte -;; 10: *UNUSED* unsigned word -;; 11: *UNUSED* signed word +;; 8: data skip: the arg is amout of bytes to skip (not including the counter itself) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -296,11 +293,6 @@ UFO_FORCE_INLINE int digitInBase (char ch, int base) { // ////////////////////////////////////////////////////////////////////////// // -//#define UFW_WARG_U8 (8u<<8) -//#define UFW_WARG_S8 (9u<<8) -//#define UFW_WARG_U16 (10u<<8) -//#define UFW_WARG_S16 (11u<<8) - #define UFW_VOCAB_OFS_LATEST (0u * 4u) #define UFW_VOCAB_OFS_VOCLINK (1u * 4u) #define UFW_VOCAB_OFS_PARENT (2u * 4u) @@ -2254,6 +2246,7 @@ __attribute__((unused)) static void ufoDumpWordHeader (const uint32_t lfa) { case UFW_WARG_CBLOCK: fprintf(stderr, "CBLOCK"); break; case UFW_WARG_VOCID: fprintf(stderr, "VOCID"); break; case UFW_WARG_C1STRZ: fprintf(stderr, "C1STRZ"); break; + case UFW_WARG_DATASKIP: fprintf(stderr, "DATA"); break; default: fprintf(stderr, "wtf?!"); break; } fputc('\n', stderr); @@ -2696,20 +2689,10 @@ static void ufoDecompilePart (uint32_t addr, uint32_t eaddr, int indent) { case UFW_WARG_C1STRZ: count = ufoImgGetU8(addr); addr += 1; goto print_str; - /* - case UFW_WARG_U8: - fprintf(fo, " ubyte:%u", ufoImgGetU8(addr)); addr += 1u; - break; - case UFW_WARG_S8: - fprintf(fo, " sbyte:%u", ufoImgGetU8(addr)); addr += 1u; - break; - case UFW_WARG_U16: - fprintf(fo, " uword:%u", ufoImgGetU16(addr)); addr += 2u; + case UFW_WARG_DATASKIP: + fprintf(fo, " DATA:%u", ufoImgGetU32(addr)); + addr += ufoImgGetU32(addr) + 4u; break; - case UFW_WARG_S16: - fprintf(fo, " sword:%u", ufoImgGetU16(addr)); addr += 2u; - break; - */ default: fprintf(fo, " -- WTF?!\n"); abort(); @@ -3451,6 +3434,11 @@ UFWORD(PAR_MBRANCH) { } } +// (DATASKIP) ( -- ) +UFWORD(PAR_DATASKIP) { + ufoIP += ufoImgGetU32(ufoIP) + 4u; +} + // ////////////////////////////////////////////////////////////////////////// // // execute words by CFA @@ -7507,6 +7495,7 @@ UFO_DISABLE_INLINE void ufoInitBasicWords (void) { UFWORDX("(+BRANCH)", PAR_PBRANCH); ufoSetLatestArgs(UFW_WARG_BRANCH); UFWORDX("(-0BRANCH)", PAR_M0BRANCH); ufoSetLatestArgs(UFW_WARG_BRANCH); UFWORDX("(-BRANCH)", PAR_MBRANCH); ufoSetLatestArgs(UFW_WARG_BRANCH); + UFWORDX("(DATASKIP)", PAR_DATASKIP); ufoSetLatestArgs(UFW_WARG_DATASKIP); ufoPublicWords(); } diff --git a/src/liburforth/urforth.h b/src/liburforth/urforth.h index b2f6745..5050738 100644 --- a/src/liburforth/urforth.h +++ b/src/liburforth/urforth.h @@ -78,14 +78,18 @@ uint32_t ufoGetForthVocId (void); #define UFW_WARG_MASK ((uint32_t)0xff00U) // possible word arg types -#define UFW_WARG_NONE (0u<<8) -#define UFW_WARG_BRANCH (1u<<8) -#define UFW_WARG_LIT (2u<<8) -#define UFW_WARG_C4STRZ (3u<<8) -#define UFW_WARG_CFA (4u<<8) -#define UFW_WARG_CBLOCK (5u<<8) -#define UFW_WARG_VOCID (6u<<8) -#define UFW_WARG_C1STRZ (7u<<8) +#define UFW_WARG_NONE (0u<<8) +#define UFW_WARG_BRANCH (1u<<8) +#define UFW_WARG_LIT (2u<<8) +#define UFW_WARG_C4STRZ (3u<<8) +#define UFW_WARG_CFA (4u<<8) +#define UFW_WARG_CBLOCK (5u<<8) +#define UFW_WARG_VOCID (6u<<8) +#define UFW_WARG_C1STRZ (7u<<8) +// the arg is amount of bytes to skip (not including the counter itself) +// the following inline data cannot (and shouldn't) be decompiled +#define UFW_WARG_DATASKIP (8u<<8) + typedef void (*ufoNativeCFA) (uint32_t pfa); -- 2.11.4.GIT