Skip to content

Commit

Permalink
Add to JS backend conversion between JavaScript objects and associati…
Browse files Browse the repository at this point in the history
…on lists.
  • Loading branch information
feeley committed Feb 19, 2014
1 parent 815cf3d commit 78831de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
23 changes: 22 additions & 1 deletion gsc/_t-univ.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2961,7 +2961,13 @@ function Gambit_js2scm(obj) {
if (obj instanceof Array) {
return obj.map(Gambit_js2scm);
} else {
throw "Gambit_js2scm error";
var alist = null;
for (var key in obj) {
alist = new Gambit_Pair(new Gambit_Pair(Gambit_js2scm(key),
Gambit_js2scm(obj[key])),
alist);
}
return alist;
}
} else {
throw "Gambit_js2scm error";
Expand All @@ -2986,6 +2992,20 @@ function Gambit_scm2js(obj) {
return obj.toString();
} else if (obj instanceof Gambit_Flonum) {
return obj.val;
} else if (obj instanceof Gambit_Pair) {
var jsobj = {};
var i = 0;
while (obj instanceof Gambit_Pair) {
var elem = obj.car;
if (elem instanceof Gambit_Pair) {
jsobj[Gambit_scm2js(elem.car)] = Gambit_scm2js(elem.cdr);
} else {
jsobj[i] = Gambit_scm2js(elem);
}
++i;
obj = obj.cdr;
}
return jsobj;
} else {
throw "Gambit_scm2js error";
}
Expand Down Expand Up @@ -3080,6 +3100,7 @@ EOF
(need-feature 'strtocodes)
(need-feature 'String)
(need-feature 'Flonum)
(need-feature 'Pair)
(need-feature 'ffi)

(for-each need-feature
Expand Down
4 changes: 2 additions & 2 deletions include/stamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* Time stamp of last source code repository commit.
*/

#define ___STAMP_YMD 20140218
#define ___STAMP_HMS 152752
#define ___STAMP_YMD 20140219
#define ___STAMP_HMS 43208

0 comments on commit 78831de

Please sign in to comment.