string.c fix
parent
a8c34f50a8
commit
5de9e55e26
|
@ -33,6 +33,7 @@
|
||||||
- utf16 string boxing
|
- utf16 string boxing
|
||||||
- slot compile problem
|
- slot compile problem
|
||||||
- nulls at the end of utf16 strings
|
- nulls at the end of utf16 strings
|
||||||
|
- x86 register decl
|
||||||
|
|
||||||
+ compiler/ffi:
|
+ compiler/ffi:
|
||||||
|
|
||||||
|
|
|
@ -253,7 +253,7 @@ M: cons ' ( c -- tagged )
|
||||||
string-type >header emit
|
string-type >header emit
|
||||||
dup str-length emit
|
dup str-length emit
|
||||||
dup hashcode emit-fixnum
|
dup hashcode emit-fixnum
|
||||||
pack-string
|
"\0" cat2 pack-string
|
||||||
align-here ;
|
align-here ;
|
||||||
|
|
||||||
M: string ' ( string -- pointer )
|
M: string ' ( string -- pointer )
|
||||||
|
|
|
@ -27,6 +27,9 @@ CELL cs_bot;
|
||||||
/* raw pointer to callstack top */
|
/* raw pointer to callstack top */
|
||||||
DLLEXPORT CELL cs;
|
DLLEXPORT CELL cs;
|
||||||
|
|
||||||
|
/* TAGGED currently executing quotation */
|
||||||
|
CELL callframe;
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
|
@ -26,9 +26,6 @@ jmp_buf toplevel;
|
||||||
sigjmp_buf toplevel;
|
sigjmp_buf toplevel;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TAGGED currently executing quotation */
|
|
||||||
CELL callframe;
|
|
||||||
|
|
||||||
/* TAGGED pointer to currently executing word */
|
/* TAGGED pointer to currently executing word */
|
||||||
CELL executing;
|
CELL executing;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,12 @@
|
||||||
F_STRING* allot_string(CELL capacity)
|
F_STRING* allot_string(CELL capacity)
|
||||||
{
|
{
|
||||||
F_STRING* string = allot_object(STRING_TYPE,
|
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;
|
string->capacity = capacity;
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
CELL header;
|
CELL header;
|
||||||
/* untagged */
|
/* untagged num of chars */
|
||||||
CELL capacity;
|
CELL capacity;
|
||||||
/* tagged */
|
/* tagged */
|
||||||
CELL hashcode;
|
CELL hashcode;
|
||||||
} F_STRING;
|
} 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)
|
INLINE F_STRING* untag_string(CELL tagged)
|
||||||
{
|
{
|
||||||
type_check(STRING_TYPE,tagged);
|
type_check(STRING_TYPE,tagged);
|
||||||
|
@ -26,11 +33,6 @@ void primitive_memory_to_string(void);
|
||||||
DLLEXPORT BYTE* unbox_c_string(void);
|
DLLEXPORT BYTE* unbox_c_string(void);
|
||||||
DLLEXPORT uint16_t* unbox_utf16_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 */
|
/* untagged & unchecked */
|
||||||
INLINE CELL string_nth(F_STRING* string, CELL index)
|
INLINE CELL string_nth(F_STRING* string, CELL index)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue