mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-14 16:27:35 +02:00
Converting make_string functions
This commit is contained in:
parent
d027b85a64
commit
72917f4fbb
4 changed files with 29 additions and 22 deletions
|
@ -122,10 +122,10 @@ object Cyc_vector_ref(object v, object k);
|
||||||
object Cyc_vector_set(object v, object k, object obj);
|
object Cyc_vector_set(object v, object k, object obj);
|
||||||
object Cyc_make_vector(object cont, object len, object fill);
|
object Cyc_make_vector(object cont, object len, object fill);
|
||||||
object Cyc_list2vector(object cont, object l);
|
object Cyc_list2vector(object cont, object l);
|
||||||
string_type Cyc_number2string(object n) ;
|
object Cyc_number2string(object cont, object n);
|
||||||
string_type Cyc_symbol2string(object sym) ;
|
object Cyc_symbol2string(object cont, object sym) ;
|
||||||
object Cyc_string2symbol(object str);
|
object Cyc_string2symbol(object str);
|
||||||
string_type Cyc_list2string(object lst);
|
object Cyc_list2string(object cont, object lst);
|
||||||
common_type Cyc_string2number(object str);
|
common_type Cyc_string2number(object str);
|
||||||
void dispatch_string_91append(int argc, object clo, object cont, object str1, ...);
|
void dispatch_string_91append(int argc, object clo, object cont, object str1, ...);
|
||||||
string_type Cyc_string_append(int argc, object str1, ...);
|
string_type Cyc_string_append(int argc, object str1, ...);
|
||||||
|
|
|
@ -193,6 +193,10 @@ typedef struct {gc_header_type hdr; tag_type tag; int len; char *str;} string_ty
|
||||||
{ cs.tag = string_tag; cs.len = len; \
|
{ 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_noalloc(cs, len, s) string_type cs \
|
||||||
|
{ cs.tag = string_tag; cs.len = len; \
|
||||||
|
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; \
|
||||||
//{ int len = strlen(s); cv.str = dhallocp; \
|
//{ int len = strlen(s); cv.str = dhallocp; \
|
||||||
|
|
32
runtime.c
32
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, msg);
|
make_string(s, strlen(msg), 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, err);
|
make_string(s, strlen(err), err);
|
||||||
Cyc_rt_raise(&s);
|
Cyc_rt_raise(&s);
|
||||||
}
|
}
|
||||||
/* END exception handler */
|
/* END exception handler */
|
||||||
|
@ -846,7 +846,7 @@ integer_type Cyc_length(object l){
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
string_type Cyc_number2string(object n) {
|
object Cyc_number2string(object cont, object n) {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
Cyc_check_num(n);
|
Cyc_check_num(n);
|
||||||
if (type_of(n) == integer_tag) {
|
if (type_of(n) == integer_tag) {
|
||||||
|
@ -856,14 +856,15 @@ string_type Cyc_number2string(object n) {
|
||||||
} else {
|
} else {
|
||||||
Cyc_rt_raise2("number->string - Unexpected object", n);
|
Cyc_rt_raise2("number->string - Unexpected object", n);
|
||||||
}
|
}
|
||||||
make_string(str, buffer);
|
make_string_noalloc(str, strlen(buffer), buffer);
|
||||||
return str;
|
return_closcall1(cont, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
string_type Cyc_symbol2string(object sym) {
|
object Cyc_symbol2string(object cont, object sym) {
|
||||||
Cyc_check_sym(sym);
|
Cyc_check_sym(sym);
|
||||||
{ make_string(str, symbol_pname(sym));
|
{ char *pname = symbol_pname(sym);
|
||||||
return str; }}
|
make_string(str, strlen(pname), pname);
|
||||||
|
return_closcall1(cont, str); }}
|
||||||
|
|
||||||
object Cyc_string2symbol(object str) {
|
object Cyc_string2symbol(object str) {
|
||||||
object sym;
|
object sym;
|
||||||
|
@ -875,7 +876,7 @@ object Cyc_string2symbol(object str) {
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
string_type Cyc_list2string(object lst){
|
object Cyc_list2string(object cont, object lst){
|
||||||
char *buf;
|
char *buf;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
integer_type len;
|
integer_type len;
|
||||||
|
@ -890,8 +891,8 @@ string_type Cyc_list2string(object lst){
|
||||||
}
|
}
|
||||||
buf[i] = '\0';
|
buf[i] = '\0';
|
||||||
|
|
||||||
make_string(str, buf);
|
{ make_string_noalloc(str, i - 1, buf);
|
||||||
return str;
|
return_closcall1(cont, &str);}
|
||||||
}
|
}
|
||||||
|
|
||||||
common_type Cyc_string2number(object str){
|
common_type Cyc_string2number(object str){
|
||||||
|
@ -1773,19 +1774,16 @@ void _list_91_125vector(object cont, object args) {
|
||||||
Cyc_list2vector(cont, car(args));}
|
Cyc_list2vector(cont, car(args));}
|
||||||
void _list_91_125string(object cont, object args) {
|
void _list_91_125string(object cont, object args) {
|
||||||
Cyc_check_num_args("list->string", 1, args);
|
Cyc_check_num_args("list->string", 1, args);
|
||||||
{ string_type s = Cyc_list2string(car(args));
|
Cyc_list2string(cont, car(args));}
|
||||||
return_closcall1(cont, &s);}}
|
|
||||||
void _string_91_125symbol(object cont, object args) {
|
void _string_91_125symbol(object cont, object args) {
|
||||||
Cyc_check_num_args("string->symbol", 1, args);
|
Cyc_check_num_args("string->symbol", 1, args);
|
||||||
return_closcall1(cont, Cyc_string2symbol(car(args)));}
|
return_closcall1(cont, Cyc_string2symbol(car(args)));}
|
||||||
void _symbol_91_125string(object cont, object args) {
|
void _symbol_91_125string(object cont, object args) {
|
||||||
Cyc_check_num_args("symbol->string", 1, args);
|
Cyc_check_num_args("symbol->string", 1, args);
|
||||||
{ string_type s = Cyc_symbol2string(car(args));
|
Cyc_symbol2string(cont, car(args));}
|
||||||
return_closcall1(cont, &s);}}
|
|
||||||
void _number_91_125string(object cont, object args) {
|
void _number_91_125string(object cont, object args) {
|
||||||
Cyc_check_num_args("number->string", 1, args);
|
Cyc_check_num_args("number->string", 1, args);
|
||||||
{ string_type s = Cyc_number2string(car(args));
|
Cyc_number2string(cont, car(args));}
|
||||||
return_closcall1(cont, &s);}}
|
|
||||||
void _open_91input_91file(object cont, object args) {
|
void _open_91input_91file(object cont, object args) {
|
||||||
Cyc_check_num_args("open-input-file", 1, args);
|
Cyc_check_num_args("open-input-file", 1, args);
|
||||||
{ port_type p = Cyc_io_open_input_file(car(args));
|
{ port_type p = Cyc_io_open_input_file(car(args));
|
||||||
|
|
|
@ -584,7 +584,10 @@
|
||||||
((eq? p 'apply) "object")
|
((eq? p 'apply) "object")
|
||||||
((eq? p 'Cyc-read-line) "object")
|
((eq? p 'Cyc-read-line) "object")
|
||||||
((eq? p 'command-line-arguments) "object")
|
((eq? p 'command-line-arguments) "object")
|
||||||
|
((eq? p 'number->string) "object")
|
||||||
|
((eq? p 'symbol->string) "object")
|
||||||
((eq? p 'make-vector) "object")
|
((eq? p 'make-vector) "object")
|
||||||
|
((eq? p 'list->string) "object")
|
||||||
((eq? p 'list->vector) "object")
|
((eq? p 'list->vector) "object")
|
||||||
(else #f)))
|
(else #f)))
|
||||||
|
|
||||||
|
@ -613,12 +616,14 @@
|
||||||
;; Pass continuation as the function's first parameter?
|
;; Pass continuation as the function's first parameter?
|
||||||
(define (prim:cont? exp)
|
(define (prim:cont? exp)
|
||||||
(and (prim? exp)
|
(and (prim? exp)
|
||||||
(member exp '(Cyc-read-line apply command-line-arguments make-vector list->vector))))
|
(member exp '(Cyc-read-line apply command-line-arguments number->string
|
||||||
|
symbol->string list->string make-vector list->vector))))
|
||||||
;; TODO: this is a hack, right answer is to include information about
|
;; TODO: this is a hack, right answer is to include information about
|
||||||
;; how many args each primitive is supposed to take
|
;; how many args each primitive is supposed to take
|
||||||
(define (prim:cont-has-args? exp)
|
(define (prim:cont-has-args? exp)
|
||||||
(and (prim? exp)
|
(and (prim? exp)
|
||||||
(member exp '(Cyc-read-line apply make-vector list->vector))))
|
(member exp '(Cyc-read-line apply number->string symbol->string
|
||||||
|
list->string make-vector list->vector))))
|
||||||
|
|
||||||
;; Pass an integer arg count as the function's first parameter?
|
;; Pass an integer arg count as the function's first parameter?
|
||||||
(define (prim:arg-count? exp)
|
(define (prim:arg-count? exp)
|
||||||
|
|
Loading…
Add table
Reference in a new issue