try
{
- preview.setText(FactorPlugin.evalInWire(
- FactorPlugin.factorWord(word) + " see").trim());
+ String text = FactorPlugin.evalInWire(
+ FactorPlugin.factorWord(word) + " see").trim();
+ preview.setText(text);
+ preview.setCaretPosition(text.length());
}
catch(Exception e)
{
throws Exception
{
FactorWord w = reader.nextWord(true);
+ if(w == null)
+ return;
+
w.def = new FactorTraitsDefinition(w);
reader.intern("<" + w.name + ">",true);
reader.intern(w.name + "?",true);
[ "alien" | "set-alien-1" ]
[ "kernel" | "heap-stats" ]
[ "errors" | "throw" ]
+ [ "kernel-internals" | "string>memory" ]
+ [ "kernel-internals" | "memory>string" ]
] [
unswons create swap succ [ f define ] keep
] each drop
USE: files
USE: io-internals
USE: kernel
+USE: kernel-internals
USE: lists
USE: math
USE: math-internals
[ set-alien-1 " n alien off -- " [ 3 | 0 ] ]
[ heap-stats " -- instances bytes " [ 0 | 2 ] ]
[ throw " error -- " [ 1 | 0 ] ]
+ [ string>memory " str address -- " [ 2 | 0 ] ]
+ [ memory>string " address length -- str " [ 2 | 1 ] ]
] [
uncons dupd uncons car ( word word stack-effect infer-effect )
>r "stack-effect" set-word-property r>
: negative-array-size-error ( obj -- )
"Cannot allocate array with negative size " write . ;
-: bad-primitive-error ( obj -- )
- "Bad primitive number: " write . ;
-
: c-string-error ( obj -- )
"Cannot convert to C string: " write . ;
float-format-error
signal-error
negative-array-size-error
- bad-primitive-error
c-string-error
ffi-disabled-error
ffi-error
#define ERROR_FLOAT_FORMAT (8<<3)
#define ERROR_SIGNAL (9<<3)
#define ERROR_NEGATIVE_ARRAY_SIZE (10<<3)
-#define ERROR_BAD_PRIMITIVE (11<<3)
-#define ERROR_C_STRING (12<<3)
-#define ERROR_FFI_DISABLED (13<<3)
-#define ERROR_FFI (14<<3)
-#define ERROR_CLOSED (15<<3)
+#define ERROR_C_STRING (11<<3)
+#define ERROR_FFI_DISABLED (12<<3)
+#define ERROR_FFI (13<<3)
+#define ERROR_CLOSED (14<<3)
/* When throw_error throws an error, it sets this global and
longjmps back to the top-level. */
primitive_alien_1,
primitive_set_alien_1,
primitive_heap_stats,
- primitive_throw
+ primitive_throw,
+ primitive_string_to_memory,
+ primitive_memory_to_string
};
CELL primitive_to_xt(CELL primitive)
{
if(primitive < 0 || primitive >= PRIMITIVE_COUNT)
- general_error(ERROR_BAD_PRIMITIVE,tag_fixnum(primitive));
-
- return (CELL)primitives[primitive];
+ return (CELL)undefined;
+ else
+ return (CELL)primitives[primitive];
}
extern XT primitives[];
-#define PRIMITIVE_COUNT 189
+#define PRIMITIVE_COUNT 191
CELL primitive_to_xt(CELL primitive);
return new_string;
}
-/* untagged */
-F_STRING* from_c_string(const BYTE* c_string)
+INLINE F_STRING* memory_to_string(const BYTE* string, CELL length)
{
- CELL length = strlen(c_string);
F_STRING* s = allot_string(length);
CELL i;
for(i = 0; i < length; i++)
{
- cput(SREF(s,i),*c_string);
- c_string++;
+ cput(SREF(s,i),*string);
+ string++;
}
rehash_string(s);
return s;
}
+void primitive_memory_to_string(void)
+{
+ CELL length = unbox_cell();
+ BYTE* string = (BYTE*)unbox_cell();
+ dpush(tag_object(memory_to_string(string,length)));
+}
+
+/* untagged */
+F_STRING* from_c_string(const BYTE* c_string)
+{
+ return memory_to_string(c_string,strlen(c_string));
+}
+
/* FFI calls this */
void box_c_string(const BYTE* c_string)
{
return to_c_string_unchecked(s);
}
+INLINE void string_to_memory(F_STRING* s, BYTE* string)
+{
+ CELL i;
+ for(i = 0; i < s->capacity; i++)
+ string[i] = string_nth(s,i);
+}
+
+void primitive_string_to_memory(void)
+{
+ F_STRING* str = untag_string(dpop());
+ BYTE* address = (BYTE*)unbox_cell();
+ string_to_memory(str,address);
+}
+
/* untagged */
BYTE* to_c_string_unchecked(F_STRING* s)
{
F_STRING* _c_str = allot_string(s->capacity / CHARS + 1);
- CELL i;
-
BYTE* c_str = (BYTE*)(_c_str + 1);
-
- for(i = 0; i < s->capacity; i++)
- c_str[i] = string_nth(s,i);
-
+ string_to_memory(s,c_str);
c_str[s->capacity] = '\0';
-
return c_str;
}
F_STRING* grow_string(F_STRING* string, F_FIXNUM capacity, uint16_t fill);
BYTE* to_c_string(F_STRING* s);
BYTE* to_c_string_unchecked(F_STRING* s);
+void primitive_string_to_memory(void);
DLLEXPORT void box_c_string(const BYTE* c_string);
F_STRING* from_c_string(const BYTE* c_string);
+void primitive_memory_to_string(void);
DLLEXPORT BYTE* unbox_c_string(void);
#define SREF(string,index) ((CELL)string + sizeof(F_STRING) + index * CHARS)