mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-06 12:46:35 +02:00
Added more make string macros and fixed related bugs
This commit is contained in:
parent
72917f4fbb
commit
11d15842ba
2 changed files with 14 additions and 11 deletions
|
@ -189,13 +189,16 @@ typedef struct {gc_header_type hdr; tag_type tag; int len; char *str;} string_ty
|
||||||
//// TODO: new way to allocate strings, but this requires changes to
|
//// TODO: new way to allocate strings, but this requires changes to
|
||||||
//// all functions that allocate strings, the GC, cgen, and maybe more.
|
//// all functions that allocate strings, the GC, cgen, and maybe more.
|
||||||
//// Because these strings are (at least for now) allocaed on the stack.
|
//// Because these strings are (at least for now) allocaed on the stack.
|
||||||
#define make_string(cs, len, s) string_type cs; \
|
#define make_string(cs, s) string_type cs; \
|
||||||
{ cs.tag = string_tag; cs.len = len; \
|
{ int len = strlen(s); cs.tag = string_tag; cs.len = len; \
|
||||||
cs.str = alloca(sizeof(char) * (len + 1)); \
|
cs.str = alloca(sizeof(char) * (len + 1)); \
|
||||||
strcpy(cs.str, s);}
|
strcpy(cs.str, s);}
|
||||||
TODO: make_string_with_len, remove len from above args
|
#define make_string_with_len(cs, length, s) string_type cs; \
|
||||||
#define make_string_noalloc(cs, len, s) string_type cs \
|
{ cs.tag = string_tag; cs.len = length; \
|
||||||
{ cs.tag = string_tag; cs.len = len; \
|
cs.str = alloca(sizeof(char) * (len + 1)); \
|
||||||
|
strcpy(cs.str, s);}
|
||||||
|
#define make_string_noalloc(cs, length, s) string_type cs; \
|
||||||
|
{ cs.tag = string_tag; cs.len = length; \
|
||||||
cs.str = s; }
|
cs.str = s; }
|
||||||
// TODO: all of the dhalloc below needs to go away...
|
// TODO: all of the dhalloc below needs to go away...
|
||||||
//#define make_string(cv,s) string_type cv; cv.tag = string_tag; \
|
//#define make_string(cv,s) string_type cv; cv.tag = string_tag; \
|
||||||
|
|
12
runtime.c
12
runtime.c
|
@ -286,7 +286,7 @@ void Cyc_rt_raise(object err) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
void Cyc_rt_raise2(const char *msg, object err) {
|
void Cyc_rt_raise2(const char *msg, object err) {
|
||||||
make_string(s, strlen(msg), msg);
|
make_string(s, msg);
|
||||||
make_cons(c3, err, nil);
|
make_cons(c3, err, nil);
|
||||||
make_cons(c2, &s, &c3);
|
make_cons(c2, &s, &c3);
|
||||||
make_cons(c1, boolean_f, &c2);
|
make_cons(c1, boolean_f, &c2);
|
||||||
|
@ -297,7 +297,7 @@ void Cyc_rt_raise2(const char *msg, object err) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
void Cyc_rt_raise_msg(const char *err) {
|
void Cyc_rt_raise_msg(const char *err) {
|
||||||
make_string(s, strlen(err), err);
|
make_string(s, err);
|
||||||
Cyc_rt_raise(&s);
|
Cyc_rt_raise(&s);
|
||||||
}
|
}
|
||||||
/* END exception handler */
|
/* END exception handler */
|
||||||
|
@ -857,14 +857,14 @@ object Cyc_number2string(object cont, object n) {
|
||||||
Cyc_rt_raise2("number->string - Unexpected object", n);
|
Cyc_rt_raise2("number->string - Unexpected object", n);
|
||||||
}
|
}
|
||||||
make_string_noalloc(str, strlen(buffer), buffer);
|
make_string_noalloc(str, strlen(buffer), buffer);
|
||||||
return_closcall1(cont, str);
|
return_closcall1(cont, &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
object Cyc_symbol2string(object cont, object sym) {
|
object Cyc_symbol2string(object cont, object sym) {
|
||||||
Cyc_check_sym(sym);
|
Cyc_check_sym(sym);
|
||||||
{ char *pname = symbol_pname(sym);
|
{ const char *pname = symbol_pname(sym);
|
||||||
make_string(str, strlen(pname), pname);
|
make_string(str, pname);
|
||||||
return_closcall1(cont, str); }}
|
return_closcall1(cont, &str); }}
|
||||||
|
|
||||||
object Cyc_string2symbol(object str) {
|
object Cyc_string2symbol(object str) {
|
||||||
object sym;
|
object sym;
|
||||||
|
|
Loading…
Add table
Reference in a new issue