From 503e73bcb1dee0065719c01e9cf4e6eaca61155e Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 22 May 2018 00:46:51 -0700 Subject: [PATCH] Move knowledge of unicode strings into sdata.h and object.h. --- src/microcode/object.h | 20 ++++++++++++++++++++ src/microcode/sdata.h | 6 +++++- src/microcode/string.c | 7 +------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/microcode/object.h b/src/microcode/object.h index ccaa59f02..5dc0c51df 100644 --- a/src/microcode/object.h +++ b/src/microcode/object.h @@ -275,6 +275,26 @@ extern bool string_p (SCHEME_OBJECT); #define BYTEVECTOR_REF(s, i) (* (BYTEVECTOR_LOC ((s), (i)))) #define BYTEVECTOR_SET(s, i, c) ((* (BYTEVECTOR_LOC ((s), (i)))) = (c)) +/* Unicode string operations */ + +#define UNICODE_STRING_CP_LENGTH(u) \ + (OBJECT_DATUM (MEMORY_REF ((u), UNICODE_STRING_LENGTH_INDEX))) + +#define UNICODE_STRING_FLAGS(u) \ + (OBJECT_TYPE (MEMORY_REF ((u), UNICODE_STRING_LENGTH_INDEX))) + +/* This must be kept in sync with "runtime/string.scm". */ +#define UNICODE_STRING_BYTES_PER_CP(u) \ + ((((UNICODE_STRING_FLAGS (u)) & 0x3) == 0) \ + ? 3 \ + : ((UNICODE_STRING_FLAGS (u)) & 0x3)) + +#define UNICODE_STRING_BYTE_LENGTH(u) \ + ((UNICODE_STRING_CP_LENGTH (u)) * (UNICODE_STRING_BYTES_PER_CP (u))) + +#define UNICODE_STRING_POINTER(u) \ + ((uint8_t *) (MEMORY_LOC ((u), UNICODE_STRING_DATA))) + /* Legacy string operations */ /* Legacy strings are laid out exactly the same way as bytevectors, diff --git a/src/microcode/sdata.h b/src/microcode/sdata.h index 6caf5070d..6396a03bc 100644 --- a/src/microcode/sdata.h +++ b/src/microcode/sdata.h @@ -56,7 +56,7 @@ USA. * An object that points to one other object (extra indirection). * Used by the compiler to share objects. */ -#define CELL_CONTENTS 0 +#define CELL_CONTENTS 0 /* BYTEVECTOR * Format consists of the normal non-marked vector header @@ -67,6 +67,10 @@ USA. #define BYTEVECTOR_LENGTH_INDEX 1 #define BYTEVECTOR_LENGTH_SIZE 1 #define BYTEVECTOR_DATA 2 + +#define UNICODE_STRING_HEADER 0 +#define UNICODE_STRING_LENGTH_INDEX 1 +#define UNICODE_STRING_DATA 2 /* COMPILED_PROCEDURE */ #define COMP_PROCEDURE_ADDRESS 0 diff --git a/src/microcode/string.c b/src/microcode/string.c index 0f249f4a5..cfef1b36d 100644 --- a/src/microcode/string.c +++ b/src/microcode/string.c @@ -36,12 +36,7 @@ string_p (SCHEME_OBJECT object) return ((LEGACY_STRING_P (object)) || (BYTEVECTOR_P (object)) || ((UNICODE_STRING_P (object)) - // This tests that the ustring-cp-size is == 1, meaning - // one byte per code point. This must be kept in sync - // with "runtime/ustring.scm". - && (((OBJECT_TYPE (MEMORY_REF (object, BYTEVECTOR_LENGTH_INDEX))) - & 0x03) - == 0x01))); + && ((UNICODE_STRING_BYTES_PER_CP (object)) == 1))); } SCHEME_OBJECT -- 2.25.1