mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
Clean formatting and remove unneeded comments
This commit is contained in:
parent
0e01716827
commit
a843591136
1 changed files with 27 additions and 33 deletions
|
@ -323,7 +323,7 @@ sexp sexp_parse_json (sexp ctx, sexp self, sexp_sint_t n, sexp str) {
|
||||||
sexp unparse_json (sexp ctx, sexp self, sexp obj);
|
sexp unparse_json (sexp ctx, sexp self, sexp obj);
|
||||||
|
|
||||||
|
|
||||||
sexp unparse_json_fixnum(sexp ctx, sexp self, const sexp obj){
|
sexp unparse_json_fixnum(sexp ctx, sexp self, const sexp obj) {
|
||||||
sexp_gc_var2(res, tmp);
|
sexp_gc_var2(res, tmp);
|
||||||
sexp_gc_preserve2(ctx, res, tmp);
|
sexp_gc_preserve2(ctx, res, tmp);
|
||||||
res = SEXP_NULL;
|
res = SEXP_NULL;
|
||||||
|
@ -336,7 +336,7 @@ sexp unparse_json_fixnum(sexp ctx, sexp self, const sexp obj){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sexp unparse_json_string(sexp ctx, sexp self, const sexp obj){
|
sexp unparse_json_string(sexp ctx, sexp self, const sexp obj) {
|
||||||
sexp_gc_var2(res, tmp);
|
sexp_gc_var2(res, tmp);
|
||||||
sexp_gc_preserve2(ctx, res, tmp);
|
sexp_gc_preserve2(ctx, res, tmp);
|
||||||
res = SEXP_NULL;
|
res = SEXP_NULL;
|
||||||
|
@ -348,10 +348,10 @@ sexp unparse_json_string(sexp ctx, sexp self, const sexp obj){
|
||||||
unsigned long ch, chh, chl;
|
unsigned long ch, chh, chl;
|
||||||
|
|
||||||
sexp_uint_t len = sexp_string_length(obj);
|
sexp_uint_t len = sexp_string_length(obj);
|
||||||
for(sexp_uint_t i=0; i!= len; i++){
|
for(sexp_uint_t i=0; i!= len; i++) {
|
||||||
ch = sexp_unbox_character(sexp_string_ref(ctx, obj, sexp_make_fixnum(i)));
|
ch = sexp_unbox_character(sexp_string_ref(ctx, obj, sexp_make_fixnum(i)));
|
||||||
if(ch < 0x7F){
|
if(ch < 0x7F) {
|
||||||
switch(ch){
|
switch(ch) {
|
||||||
case '\\':
|
case '\\':
|
||||||
sprintf(cout, "\\\\");
|
sprintf(cout, "\\\\");
|
||||||
break;
|
break;
|
||||||
|
@ -377,13 +377,13 @@ sexp unparse_json_string(sexp ctx, sexp self, const sexp obj){
|
||||||
sprintf(cout, "%c", ch);
|
sprintf(cout, "%c", ch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if(ch <= 0xFFFF){
|
} else if(ch <= 0xFFFF) {
|
||||||
sprintf(cout,"\\u%04lX", ch);
|
sprintf(cout,"\\u%04lX", ch);
|
||||||
} else {
|
} else {
|
||||||
// Surrogate pair
|
// Surrogate pair
|
||||||
chh = (0xD800 - (0x10000 >> 10) + ((ch) >> 10));
|
chh = (0xD800 - (0x10000 >> 10) + ((ch) >> 10));
|
||||||
chl = (0xDC00 + ((ch) & 0x3FF));
|
chl = (0xDC00 + ((ch) & 0x3FF));
|
||||||
if (chh > 0xFFFF || chl > 0xFFFF){
|
if (chh > 0xFFFF || chl > 0xFFFF) {
|
||||||
res = sexp_json_unparse_exception(ctx, self, "unable to encode string", obj);
|
res = sexp_json_unparse_exception(ctx, self, "unable to encode string", obj);
|
||||||
sexp_gc_release2(ctx);
|
sexp_gc_release2(ctx);
|
||||||
return res;
|
return res;
|
||||||
|
@ -404,7 +404,7 @@ sexp unparse_json_string(sexp ctx, sexp self, const sexp obj){
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
sexp unparse_json_array(sexp ctx, sexp self, const sexp obj){
|
sexp unparse_json_array(sexp ctx, sexp self, const sexp obj) {
|
||||||
sexp_gc_var2(res, tmp);
|
sexp_gc_var2(res, tmp);
|
||||||
sexp_gc_preserve2(ctx, res, tmp);
|
sexp_gc_preserve2(ctx, res, tmp);
|
||||||
res = SEXP_NULL;
|
res = SEXP_NULL;
|
||||||
|
@ -413,15 +413,15 @@ sexp unparse_json_array(sexp ctx, sexp self, const sexp obj){
|
||||||
res = sexp_cons(ctx, tmp, res);
|
res = sexp_cons(ctx, tmp, res);
|
||||||
|
|
||||||
int len = sexp_vector_length(obj);
|
int len = sexp_vector_length(obj);
|
||||||
for (int i=0; i!=len; i++){
|
for (int i=0; i!=len; i++) {
|
||||||
tmp = unparse_json(ctx, self, sexp_vector_ref(obj, sexp_make_fixnum(i)));
|
tmp = unparse_json(ctx, self, sexp_vector_ref(obj, sexp_make_fixnum(i)));
|
||||||
if (sexp_exceptionp(tmp)){
|
if (sexp_exceptionp(tmp)) {
|
||||||
sexp_gc_release2(ctx);
|
sexp_gc_release2(ctx);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
res = sexp_cons(ctx, tmp, res);
|
res = sexp_cons(ctx, tmp, res);
|
||||||
|
|
||||||
if (i != len-1){
|
if (i != len-1) {
|
||||||
tmp = sexp_c_string(ctx, ",", -1);
|
tmp = sexp_c_string(ctx, ",", -1);
|
||||||
res = sexp_cons(ctx, tmp, res);
|
res = sexp_cons(ctx, tmp, res);
|
||||||
}
|
}
|
||||||
|
@ -438,7 +438,7 @@ sexp unparse_json_array(sexp ctx, sexp self, const sexp obj){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sexp unparse_json_object(sexp ctx, sexp self, const sexp obj){
|
sexp unparse_json_object(sexp ctx, sexp self, const sexp obj) {
|
||||||
sexp_gc_var6(res, tmp, it, cur, key, val);
|
sexp_gc_var6(res, tmp, it, cur, key, val);
|
||||||
sexp_gc_preserve6(ctx, res, tmp, it, cur, key, val);
|
sexp_gc_preserve6(ctx, res, tmp, it, cur, key, val);
|
||||||
res = SEXP_NULL;
|
res = SEXP_NULL;
|
||||||
|
@ -448,21 +448,21 @@ sexp unparse_json_object(sexp ctx, sexp self, const sexp obj){
|
||||||
|
|
||||||
int len = sexp_unbox_fixnum(sexp_length(ctx, obj));
|
int len = sexp_unbox_fixnum(sexp_length(ctx, obj));
|
||||||
it = obj;
|
it = obj;
|
||||||
for (int i=0; i!=len; i++){
|
for (int i=0; i!=len; i++) {
|
||||||
cur = sexp_car(it);
|
cur = sexp_car(it);
|
||||||
if (!sexp_pairp(cur)){
|
if (!sexp_pairp(cur)) {
|
||||||
res = sexp_json_unparse_exception(ctx, self, "unable to encode key-value pair: not a pair", obj);
|
res = sexp_json_unparse_exception(ctx, self, "unable to encode key-value pair: not a pair", obj);
|
||||||
goto except;
|
goto except;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key
|
// Key
|
||||||
key = sexp_car(cur);
|
key = sexp_car(cur);
|
||||||
if (!(sexp_symbolp(key) /*|| sexp_stringp(key)*/)){
|
if (!(sexp_symbolp(key) /*|| sexp_stringp(key)*/)) {
|
||||||
res = sexp_json_unparse_exception(ctx, self, "unable to encode key: not a symbol", key);
|
res = sexp_json_unparse_exception(ctx, self, "unable to encode key: not a symbol", key);
|
||||||
goto except;
|
goto except;
|
||||||
}
|
}
|
||||||
tmp = unparse_json(ctx, self, key);
|
tmp = unparse_json(ctx, self, key);
|
||||||
if (sexp_exceptionp(tmp)){
|
if (sexp_exceptionp(tmp)) {
|
||||||
res = tmp;
|
res = tmp;
|
||||||
goto except;
|
goto except;
|
||||||
}
|
}
|
||||||
|
@ -477,7 +477,7 @@ sexp unparse_json_object(sexp ctx, sexp self, const sexp obj){
|
||||||
tmp = unparse_json(ctx, self, val);
|
tmp = unparse_json(ctx, self, val);
|
||||||
res = sexp_cons(ctx, tmp, res);
|
res = sexp_cons(ctx, tmp, res);
|
||||||
|
|
||||||
if (i != len-1){
|
if (i != len-1) {
|
||||||
tmp = sexp_c_string(ctx, ",", -1);
|
tmp = sexp_c_string(ctx, ",", -1);
|
||||||
res = sexp_cons(ctx, tmp, res);
|
res = sexp_cons(ctx, tmp, res);
|
||||||
}
|
}
|
||||||
|
@ -494,33 +494,27 @@ except:
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
sexp unparse_json (sexp ctx, sexp self, sexp obj){
|
sexp unparse_json (sexp ctx, sexp self, sexp obj) {
|
||||||
sexp_gc_var1(res);
|
sexp_gc_var1(res);
|
||||||
sexp_gc_preserve1(ctx, res);
|
sexp_gc_preserve1(ctx, res);
|
||||||
res = SEXP_NULL;
|
res = SEXP_NULL;
|
||||||
|
|
||||||
if( sexp_symbolp(obj) ){
|
if( sexp_symbolp(obj) ) {
|
||||||
// SYMBOL
|
obj = sexp_symbol_to_string(ctx, obj);
|
||||||
obj = sexp_symbol_to_string(ctx, obj);
|
|
||||||
res = unparse_json_string(ctx, self, obj);
|
res = unparse_json_string(ctx, self, obj);
|
||||||
} else if (sexp_stringp(obj)){
|
} else if (sexp_stringp(obj)) {
|
||||||
// STRING
|
|
||||||
res = unparse_json_string(ctx, self, obj);
|
res = unparse_json_string(ctx, self, obj);
|
||||||
} else if (sexp_listp(ctx, obj) == SEXP_TRUE){
|
} else if (sexp_listp(ctx, obj) == SEXP_TRUE) {
|
||||||
// OBJECT
|
|
||||||
res = unparse_json_object(ctx, self, obj);
|
res = unparse_json_object(ctx, self, obj);
|
||||||
} else if (sexp_vectorp(obj)){
|
} else if (sexp_vectorp(obj)) {
|
||||||
// ARRAY
|
|
||||||
res = unparse_json_array(ctx, self, obj);
|
res = unparse_json_array(ctx, self, obj);
|
||||||
} else if(sexp_fixnump(obj)){
|
} else if(sexp_fixnump(obj)) {
|
||||||
res = unparse_json_fixnum(ctx, self, obj);
|
res = unparse_json_fixnum(ctx, self, obj);
|
||||||
} else if (sexp_numberp(obj)){
|
} else if (obj == SEXP_FALSE) {
|
||||||
// FLONUM or RATIONAL
|
|
||||||
} else if (obj == SEXP_FALSE){
|
|
||||||
res = sexp_c_string(ctx, "false", -1);
|
res = sexp_c_string(ctx, "false", -1);
|
||||||
} else if (obj == SEXP_TRUE){
|
} else if (obj == SEXP_TRUE) {
|
||||||
res = sexp_c_string(ctx, "true", -1);
|
res = sexp_c_string(ctx, "true", -1);
|
||||||
} else if (obj == SEXP_NULL){
|
} else if (obj == SEXP_NULL) {
|
||||||
res = sexp_c_string(ctx, "null", -1);
|
res = sexp_c_string(ctx, "null", -1);
|
||||||
} else {
|
} else {
|
||||||
res = sexp_json_unparse_exception(ctx, self, "unable to encode element", obj);
|
res = sexp_json_unparse_exception(ctx, self, "unable to encode element", obj);
|
||||||
|
|
Loading…
Add table
Reference in a new issue