mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-21 06:39:16 +02:00
Move string->list to scheme code
This commit is contained in:
parent
4c0ce77892
commit
6c277a724b
6 changed files with 5 additions and 42 deletions
|
@ -125,7 +125,6 @@ string_type Cyc_number2string(object n) ;
|
||||||
string_type Cyc_symbol2string(object sym) ;
|
string_type Cyc_symbol2string(object sym) ;
|
||||||
object Cyc_string2symbol(object str);
|
object Cyc_string2symbol(object str);
|
||||||
string_type Cyc_list2string(object lst);
|
string_type Cyc_list2string(object lst);
|
||||||
void __string2list(const char *str, cons_type *buf, int buflen);
|
|
||||||
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, ...);
|
||||||
|
@ -209,20 +208,6 @@ void dispatch_va(int argc, function_type_va func, object clo, object cont, objec
|
||||||
void do_dispatch(int argc, function_type func, object clo, object *buffer);
|
void do_dispatch(int argc, function_type func, object clo, object *buffer);
|
||||||
|
|
||||||
// Note: below is OK since alloca memory is not freed until function exits
|
// Note: below is OK since alloca memory is not freed until function exits
|
||||||
#define string2list(c,s) object c = nil; { \
|
|
||||||
char *str; \
|
|
||||||
int len; \
|
|
||||||
Cyc_check_str(s); \
|
|
||||||
str = ((string_type *)s)->str; \
|
|
||||||
len = strlen(str); \
|
|
||||||
cons_type *buf; \
|
|
||||||
if (len > 0) { \
|
|
||||||
buf = alloca(sizeof(cons_type) * len); \
|
|
||||||
__string2list(str, buf, len); \
|
|
||||||
c = (object)&(buf[0]); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define list2vector(v, l) object v = nil; { \
|
#define list2vector(v, l) object v = nil; { \
|
||||||
integer_type len; \
|
integer_type len; \
|
||||||
Cyc_check_cons_or_nil(l); \
|
Cyc_check_cons_or_nil(l); \
|
||||||
|
@ -339,7 +324,6 @@ extern const object primitive_integer_91_125char;
|
||||||
extern const object primitive_string_91_125number;
|
extern const object primitive_string_91_125number;
|
||||||
extern const object primitive_string_91cmp;
|
extern const object primitive_string_91cmp;
|
||||||
extern const object primitive_string_91append;
|
extern const object primitive_string_91append;
|
||||||
extern const object primitive_string_91_125list;
|
|
||||||
extern const object primitive_list_91_125string;
|
extern const object primitive_list_91_125string;
|
||||||
extern const object primitive_string_91_125symbol;
|
extern const object primitive_string_91_125symbol;
|
||||||
extern const object primitive_symbol_91_125string;
|
extern const object primitive_symbol_91_125string;
|
||||||
|
|
16
runtime.c
16
runtime.c
|
@ -872,16 +872,6 @@ string_type Cyc_list2string(object lst){
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __string2list(const char *str, cons_type *buf, int buflen){
|
|
||||||
int i = 0;
|
|
||||||
while (str[i]){
|
|
||||||
buf[i].tag = cons_tag;
|
|
||||||
buf[i].cons_car = obj_char2obj(str[i]);
|
|
||||||
buf[i].cons_cdr = (i == buflen - 1) ? nil : buf + (i + 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
common_type Cyc_string2number(object str){
|
common_type Cyc_string2number(object str){
|
||||||
common_type result;
|
common_type result;
|
||||||
double n;
|
double n;
|
||||||
|
@ -1689,10 +1679,6 @@ void _string_91cmp(object cont, object args) {
|
||||||
void _string_91append(object cont, object args) {
|
void _string_91append(object cont, object args) {
|
||||||
integer_type argc = Cyc_length(args);
|
integer_type argc = Cyc_length(args);
|
||||||
dispatch(argc.value, (function_type)dispatch_string_91append, cont, cont, args); }
|
dispatch(argc.value, (function_type)dispatch_string_91append, cont, cont, args); }
|
||||||
void _string_91_125list(object cont, object args) {
|
|
||||||
Cyc_check_num_args("string->list", 1, args);
|
|
||||||
{ string2list(lst, car(args));
|
|
||||||
return_funcall1(cont, lst);}}
|
|
||||||
void _make_91vector(object cont, object args) {
|
void _make_91vector(object cont, object args) {
|
||||||
Cyc_check_num_args("make-vector", 1, args);
|
Cyc_check_num_args("make-vector", 1, args);
|
||||||
{ integer_type argc = Cyc_length(args);
|
{ integer_type argc = Cyc_length(args);
|
||||||
|
@ -2365,7 +2351,6 @@ static primitive_type command_91line_91arguments_primitive = {primitive_tag, "co
|
||||||
static primitive_type system_primitive = {primitive_tag, "system", &_cyc_system};
|
static primitive_type system_primitive = {primitive_tag, "system", &_cyc_system};
|
||||||
static primitive_type string_91cmp_primitive = {primitive_tag, "string-cmp", &_string_91cmp};
|
static primitive_type string_91cmp_primitive = {primitive_tag, "string-cmp", &_string_91cmp};
|
||||||
static primitive_type string_91append_primitive = {primitive_tag, "string-append", &_string_91append};
|
static primitive_type string_91append_primitive = {primitive_tag, "string-append", &_string_91append};
|
||||||
static primitive_type string_91_125list_primitive = {primitive_tag, "string->list", &_string_91_125list};
|
|
||||||
static primitive_type list_91_125string_primitive = {primitive_tag, "list->string", &_list_91_125string};
|
static primitive_type list_91_125string_primitive = {primitive_tag, "list->string", &_list_91_125string};
|
||||||
static primitive_type string_91_125symbol_primitive = {primitive_tag, "string->symbol", &_string_91_125symbol};
|
static primitive_type string_91_125symbol_primitive = {primitive_tag, "string->symbol", &_string_91_125symbol};
|
||||||
static primitive_type symbol_91_125string_primitive = {primitive_tag, "symbol->string", &_symbol_91_125string};
|
static primitive_type symbol_91_125string_primitive = {primitive_tag, "symbol->string", &_symbol_91_125string};
|
||||||
|
@ -2482,7 +2467,6 @@ const object primitive_command_91line_91arguments = &command_91line_91arguments_
|
||||||
const object primitive_system = &system_primitive;
|
const object primitive_system = &system_primitive;
|
||||||
const object primitive_string_91cmp = &string_91cmp_primitive;
|
const object primitive_string_91cmp = &string_91cmp_primitive;
|
||||||
const object primitive_string_91append = &string_91append_primitive;
|
const object primitive_string_91append = &string_91append_primitive;
|
||||||
const object primitive_string_91_125list = &string_91_125list_primitive;
|
|
||||||
const object primitive_list_91_125string = &list_91_125string_primitive;
|
const object primitive_list_91_125string = &list_91_125string_primitive;
|
||||||
const object primitive_string_91_125symbol = &string_91_125symbol_primitive;
|
const object primitive_string_91_125symbol = &string_91_125symbol_primitive;
|
||||||
const object primitive_symbol_91_125string = &symbol_91_125string_primitive;
|
const object primitive_symbol_91_125string = &symbol_91_125string_primitive;
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
string-copy
|
string-copy
|
||||||
string-copy!
|
string-copy!
|
||||||
string-fill!
|
string-fill!
|
||||||
my-string->list
|
string->list
|
||||||
string->vector
|
string->vector
|
||||||
; TODO:
|
; TODO:
|
||||||
;string-upcase
|
;string-upcase
|
||||||
|
@ -225,7 +225,7 @@
|
||||||
(let ((lst (apply vector->list (cons vec opts))))
|
(let ((lst (apply vector->list (cons vec opts))))
|
||||||
(list->string lst)))
|
(list->string lst)))
|
||||||
;; TODO: change to string->list
|
;; TODO: change to string->list
|
||||||
(define (my-string->list str . opts)
|
(define (string->list str . opts)
|
||||||
(letrec ((len (string-length str))
|
(letrec ((len (string-length str))
|
||||||
(start (if (> (length opts) 0) (car opts) 0))
|
(start (if (> (length opts) 0) (car opts) 0))
|
||||||
(end (if (> (length opts) 1) (cadr opts) len))
|
(end (if (> (length opts) 1) (cadr opts) len))
|
||||||
|
|
|
@ -481,7 +481,6 @@
|
||||||
((eq? p 'integer->char) "Cyc_integer2char")
|
((eq? p 'integer->char) "Cyc_integer2char")
|
||||||
((eq? p 'string->number)"Cyc_string2number")
|
((eq? p 'string->number)"Cyc_string2number")
|
||||||
((eq? p 'list->string) "Cyc_list2string")
|
((eq? p 'list->string) "Cyc_list2string")
|
||||||
((eq? p 'string->list) "string2list")
|
|
||||||
((eq? p 'make-vector) "Cyc_make_vector")
|
((eq? p 'make-vector) "Cyc_make_vector")
|
||||||
((eq? p 'list->vector) "list2vector")
|
((eq? p 'list->vector) "list2vector")
|
||||||
((eq? p 'vector-length) "Cyc_vector_length")
|
((eq? p 'vector-length) "Cyc_vector_length")
|
||||||
|
@ -552,7 +551,6 @@
|
||||||
((eq? p '/) "common_type")
|
((eq? p '/) "common_type")
|
||||||
((eq? p 'string->number) "common_type")
|
((eq? p 'string->number) "common_type")
|
||||||
((eq? p 'list->string) "string_type")
|
((eq? p 'list->string) "string_type")
|
||||||
; ((eq? p 'string->list) "object")
|
|
||||||
((eq? p 'string-cmp) "integer_type")
|
((eq? p 'string-cmp) "integer_type")
|
||||||
((eq? p 'string-append) "string_type")
|
((eq? p 'string-append) "string_type")
|
||||||
((eq? p 'symbol->string) "string_type")
|
((eq? p 'symbol->string) "string_type")
|
||||||
|
@ -577,7 +575,7 @@
|
||||||
system
|
system
|
||||||
Cyc-installation-dir
|
Cyc-installation-dir
|
||||||
string->number
|
string->number
|
||||||
string-append string-cmp list->string string->list
|
string-append string-cmp list->string
|
||||||
make-vector list->vector
|
make-vector list->vector
|
||||||
symbol->string number->string
|
symbol->string number->string
|
||||||
string-length substring
|
string-length substring
|
||||||
|
@ -605,7 +603,7 @@
|
||||||
;; is obsolete and should be replaced by prim:cont? functions over time.
|
;; is obsolete and should be replaced by prim:cont? functions over time.
|
||||||
(define (prim:allocates-object? exp)
|
(define (prim:allocates-object? exp)
|
||||||
(and (prim? exp)
|
(and (prim? exp)
|
||||||
(member exp '(string->list list->vector))))
|
(member exp '(list->vector))))
|
||||||
|
|
||||||
;; c-compile-prim : prim-exp -> string -> string
|
;; c-compile-prim : prim-exp -> string -> string
|
||||||
(define (c-compile-prim p cont)
|
(define (c-compile-prim p cont)
|
||||||
|
@ -657,7 +655,7 @@
|
||||||
((prim/cvar? p)
|
((prim/cvar? p)
|
||||||
;;
|
;;
|
||||||
;; TODO: look at functions that would actually fall into this
|
;; TODO: look at functions that would actually fall into this
|
||||||
;; branch, I think they are just the macro's like string->list ??
|
;; branch, I think they are just the macro's like list->vector???
|
||||||
;; may be able to remove this using prim:cont? and simplify
|
;; may be able to remove this using prim:cont? and simplify
|
||||||
;; the logic
|
;; the logic
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -570,7 +570,6 @@
|
||||||
string->number
|
string->number
|
||||||
string-append
|
string-append
|
||||||
string-cmp
|
string-cmp
|
||||||
string->list
|
|
||||||
list->string
|
list->string
|
||||||
string->symbol
|
string->symbol
|
||||||
symbol->string
|
symbol->string
|
||||||
|
@ -639,7 +638,6 @@
|
||||||
set-cdr!
|
set-cdr!
|
||||||
string-set!
|
string-set!
|
||||||
string->symbol ;; Could be mistaken for an identifier
|
string->symbol ;; Could be mistaken for an identifier
|
||||||
string->list ;; Mistaken for function call (maybe OK if it was quoted, though). same for above?
|
|
||||||
make-vector
|
make-vector
|
||||||
;; I/O must be done at runtime for side effects:
|
;; I/O must be done at runtime for side effects:
|
||||||
Cyc-stdout
|
Cyc-stdout
|
||||||
|
|
|
@ -257,7 +257,6 @@
|
||||||
(list 'string->number string->number)
|
(list 'string->number string->number)
|
||||||
(list 'string-cmp string-cmp)
|
(list 'string-cmp string-cmp)
|
||||||
(list 'string-append string-append)
|
(list 'string-append string-append)
|
||||||
(list 'string->list string->list)
|
|
||||||
(list 'list->string list->string)
|
(list 'list->string list->string)
|
||||||
(list 'string->symbol string->symbol)
|
(list 'string->symbol string->symbol)
|
||||||
(list 'symbol->string symbol->string)
|
(list 'symbol->string symbol->string)
|
||||||
|
|
Loading…
Add table
Reference in a new issue