mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Converted substring
This commit is contained in:
parent
11d15842ba
commit
09515b2141
4 changed files with 14 additions and 12 deletions
|
@ -131,7 +131,7 @@ 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_va_list(int argc, object str1, va_list ap);
|
||||
integer_type Cyc_string_length(object str);
|
||||
string_type Cyc_substring(object str, object start, object end);
|
||||
object Cyc_substring(object cont, object str, object start, object end);
|
||||
object Cyc_string_ref(object str, object k);
|
||||
object Cyc_string_set(object str, object k, object chr);
|
||||
string_type Cyc_installation_dir();
|
||||
|
|
|
@ -193,11 +193,11 @@ typedef struct {gc_header_type hdr; tag_type tag; int len; char *str;} string_ty
|
|||
{ int len = strlen(s); cs.tag = string_tag; cs.len = len; \
|
||||
cs.str = alloca(sizeof(char) * (len + 1)); \
|
||||
strcpy(cs.str, s);}
|
||||
#define make_string_with_len(cs, length, s) string_type cs; \
|
||||
#define make_string_with_len(cs, s, length) string_type cs; \
|
||||
{ cs.tag = string_tag; cs.len = length; \
|
||||
cs.str = alloca(sizeof(char) * (len + 1)); \
|
||||
strcpy(cs.str, s);}
|
||||
#define make_string_noalloc(cs, length, s) string_type cs; \
|
||||
#define make_string_noalloc(cs, s, length) string_type cs; \
|
||||
{ cs.tag = string_tag; cs.len = length; \
|
||||
cs.str = s; }
|
||||
// TODO: all of the dhalloc below needs to go away...
|
||||
|
|
13
runtime.c
13
runtime.c
|
@ -856,7 +856,7 @@ object Cyc_number2string(object cont, object n) {
|
|||
} else {
|
||||
Cyc_rt_raise2("number->string - Unexpected object", n);
|
||||
}
|
||||
make_string_noalloc(str, strlen(buffer), buffer);
|
||||
make_string_noalloc(str, buffer, strlen(buffer));
|
||||
return_closcall1(cont, &str);
|
||||
}
|
||||
|
||||
|
@ -891,7 +891,7 @@ object Cyc_list2string(object cont, object lst){
|
|||
}
|
||||
buf[i] = '\0';
|
||||
|
||||
{ make_string_noalloc(str, i - 1, buf);
|
||||
{ make_string_noalloc(str, buf, i - 1);
|
||||
return_closcall1(cont, &str);}
|
||||
}
|
||||
|
||||
|
@ -1029,7 +1029,7 @@ object Cyc_string_ref(object str, object k) {
|
|||
return obj_char2obj(raw[idx]);
|
||||
}
|
||||
|
||||
string_type Cyc_substring(object str, object start, object end) {
|
||||
object Cyc_substring(object cont, object str, object start, object end) {
|
||||
const char *raw;
|
||||
int s, e, len;
|
||||
|
||||
|
@ -1053,8 +1053,8 @@ string_type Cyc_substring(object str, object start, object end) {
|
|||
}
|
||||
|
||||
{
|
||||
make_stringn(sub, raw + s, e - s);
|
||||
return sub;
|
||||
make_string_with_len(sub, raw + s, e - s);
|
||||
return_closcall1(cont, sub);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1716,8 +1716,7 @@ void _string_91length(object cont, object args) {
|
|||
return_closcall1(cont, &i);}}
|
||||
void _cyc_substring(object cont, object args) {
|
||||
Cyc_check_num_args("substring", 3, args);
|
||||
{ string_type s = Cyc_substring(car(args), cadr(args), caddr(args));
|
||||
return_closcall1(cont, &s);}}
|
||||
Cyc_substring(cont, car(args), cadr(args), caddr(args));}
|
||||
void _cyc_string_91set_67(object cont, object args) {
|
||||
Cyc_check_num_args("string-set!", 3, args);
|
||||
{ object s = Cyc_string_set(car(args), cadr(args), caddr(args));
|
||||
|
|
|
@ -586,6 +586,7 @@
|
|||
((eq? p 'command-line-arguments) "object")
|
||||
((eq? p 'number->string) "object")
|
||||
((eq? p 'symbol->string) "object")
|
||||
((eq? p 'substring) "object")
|
||||
((eq? p 'make-vector) "object")
|
||||
((eq? p 'list->string) "object")
|
||||
((eq? p 'list->vector) "object")
|
||||
|
@ -617,13 +618,15 @@
|
|||
(define (prim:cont? exp)
|
||||
(and (prim? exp)
|
||||
(member exp '(Cyc-read-line apply command-line-arguments number->string
|
||||
symbol->string list->string make-vector list->vector))))
|
||||
symbol->string list->string substring
|
||||
make-vector list->vector))))
|
||||
;; TODO: this is a hack, right answer is to include information about
|
||||
;; how many args each primitive is supposed to take
|
||||
(define (prim:cont-has-args? exp)
|
||||
(and (prim? exp)
|
||||
(member exp '(Cyc-read-line apply number->string symbol->string
|
||||
list->string make-vector list->vector))))
|
||||
list->string substring
|
||||
make-vector list->vector))))
|
||||
|
||||
;; Pass an integer arg count as the function's first parameter?
|
||||
(define (prim:arg-count? exp)
|
||||
|
|
Loading…
Add table
Reference in a new issue