- utf16 string boxing\r
- slot compile problem\r
- nulls at the end of utf16 strings\r
+- x86 register decl\r
\r
+ compiler/ffi:\r
\r
string-type >header emit
dup str-length emit
dup hashcode emit-fixnum
- pack-string
+ "\0" cat2 pack-string
align-here ;
M: string ' ( string -- pointer )
/* raw pointer to callstack top */
DLLEXPORT CELL cs;
+/* TAGGED currently executing quotation */
+CELL callframe;
+
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
sigjmp_buf toplevel;
#endif
-/* TAGGED currently executing quotation */
-CELL callframe;
-
/* TAGGED pointer to currently executing word */
CELL executing;
F_STRING* allot_string(CELL capacity)
{
F_STRING* string = allot_object(STRING_TYPE,
- sizeof(F_STRING) + capacity * CHARS);
+ sizeof(F_STRING) + (capacity + 1) * CHARS);
+ /* strings are null-terminated in memory, even though they also
+ have a length field. The null termination allows us to add
+ the sizeof(F_STRING) to a Factor string to get a C-style
+ UTF16 string for C library calls. */
+ cput(SREF(string,capacity),(uint16_t)'\0');
string->capacity = capacity;
return string;
}
+
+
typedef struct {
CELL header;
- /* untagged */
+ /* untagged num of chars */
CELL capacity;
/* tagged */
CELL hashcode;
} F_STRING;
+#define SREF(string,index) ((CELL)string + sizeof(F_STRING) + index * CHARS)
+
+#define SSIZE(pointer) align8(sizeof(F_STRING) + \
+ (((F_STRING*)pointer)->capacity + 1) * CHARS)
+
INLINE F_STRING* untag_string(CELL tagged)
{
type_check(STRING_TYPE,tagged);
DLLEXPORT BYTE* unbox_c_string(void);
DLLEXPORT uint16_t* unbox_utf16_string(void);
-#define SREF(string,index) ((CELL)string + sizeof(F_STRING) + index * CHARS)
-
-#define SSIZE(pointer) align8(sizeof(F_STRING) + \
- ((F_STRING*)pointer)->capacity * CHARS)
-
/* untagged & unchecked */
INLINE CELL string_nth(F_STRING* string, CELL index)
{