diff --git a/srcgen2/xats2js/srcgen1/xshared/runtime/xats2js_prelude.js b/srcgen2/xats2js/srcgen1/xshared/runtime/xats2js_prelude.js index 3bd709dcc..9405798d5 100644 --- a/srcgen2/xats2js/srcgen1/xshared/runtime/xats2js_prelude.js +++ b/srcgen2/xats2js/srcgen1/xshared/runtime/xats2js_prelude.js @@ -1,4 +1,4 @@ -// Thu 05 Sep 2024 09:36:56 PM EDT +// Sun 08 Sep 2024 07:37:07 PM EDT //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /* @@ -685,6 +685,19 @@ XATS2JS_a1sz_lset$at } // ////////////////////////////////////////////////////////////////////////. +/* +HX-2024-09-06: +Fri 06 Sep 2024 04:18:38 PM EDT +*/ +// +function +XATS2JS_a1sz_make_none + ( n ) +{ + var A = new Array(n) + return A // HX: A = [?, ?, ..., ?] +} +////////////////////////////////////////////////////////////////////////. // /* HX-2024-08-15: @@ -696,7 +709,7 @@ XATS2JS_a1sz_make_ncpy (n, x) { var i = 0 - var A = new Array(n); + var A = new Array(n) while (i < n) { A[i] = (x); i += 1 } @@ -708,7 +721,7 @@ XATS2JS_a1sz_make_nfun (n, f) { var i = 0 - var A = new Array(n); + var A = new Array(n) while (i < n) { A[i] = f(i); i += 1 } diff --git a/srcgen2/xats2js/srcgen1/xshared/runtime/xats2js_xatslib.js b/srcgen2/xats2js/srcgen1/xshared/runtime/xats2js_xatslib.js index bd8eb6f42..0f7489c6b 100644 --- a/srcgen2/xats2js/srcgen1/xshared/runtime/xats2js_xatslib.js +++ b/srcgen2/xats2js/srcgen1/xshared/runtime/xats2js_xatslib.js @@ -1,4 +1,4 @@ -// Thu 05 Sep 2024 09:36:56 PM EDT +// Sun 08 Sep 2024 07:37:07 PM EDT //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /* @@ -296,6 +296,15 @@ XATS2JS_jshsmap_make_nil // ///////////////////////////////////////////////////////////////////////// // +function +XATS2JS_jshsmap_search$tst + (map, key) +{ + return map.has(key) // HX: bool +} +// +///////////////////////////////////////////////////////////////////////// +// /* fun<> UN_jshsmap_get$at$raw diff --git a/xatslib/DATS/CATS/JS/Hsmap00.cats b/xatslib/DATS/CATS/JS/Hsmap00.cats index f19925be1..0a2d64b34 100644 --- a/xatslib/DATS/CATS/JS/Hsmap00.cats +++ b/xatslib/DATS/CATS/JS/Hsmap00.cats @@ -53,6 +53,15 @@ XATS2JS_jshsmap_make_nil // ///////////////////////////////////////////////////////////////////////// // +function +XATS2JS_jshsmap_search$tst + (map, key) +{ + return map.has(key) // HX: bool +} +// +///////////////////////////////////////////////////////////////////////// +// /* fun<> UN_jshsmap_get$at$raw diff --git a/xatslib/DATS/CATS/JS/Hsmap00.dats b/xatslib/DATS/CATS/JS/Hsmap00.dats index 8fbf0eea7..45e62614b 100644 --- a/xatslib/DATS/CATS/JS/Hsmap00.dats +++ b/xatslib/DATS/CATS/JS/Hsmap00.dats @@ -228,17 +228,15 @@ jshsmap_forall_f2un (* ****** ****** *) // #extern -fun - - +fun<> jshsmap_search$tst + {k:t0}{x:vt} (map: jsm0(k,x), key: k): bool // #extern -fun - - +fun<> jshsmap_search$cpy + {k:t0}{x:vt} (map: jsm0(k,x), key: k): optn_vt(x) // (* ****** ****** *) @@ -506,6 +504,24 @@ jshsmap_rlistize // #impltmp <(*tmp*)> +jshsmap_search$tst + (map, key) = +( +XATS2JS_jshsmap_search$tst + (map, key)) where +{ +#extern +fun +XATS2JS_jshsmap_search$tst + {k:t0}{x:vt} +(map: jsm0(k,x), key: k): bool = $extnam() +} +// +(* ****** ****** *) +(* ****** ****** *) +// +#impltmp +<(*tmp*)> UN_jshsmap_get$at$raw (map, key) = ( @@ -575,9 +591,25 @@ jshsmap_getout$opt<>(map, key) } jshsmap_insert$new (map, k, x) = let -val- -~optn_vt_nil() = -jshsmap_insert$opt<>(map, k, x) end +val-false = +jshsmap_search$tst<>(map, k) +in//let +UN_jshsmap_insert$raw<>(map, k, x) +end//let +// +(* ****** ****** *) +// +#impltmp +<(*tmp*)> +jshsmap_insert$opt + (map, k, x) = +( + opt ) where +{ +val opt = +jshsmap_getout$opt<>(map, k) +val ( ) = +UN_jshsmap_insert$raw<>(map, k, x) } // (* ****** ****** *) (* ****** ****** *) diff --git a/xatslib/githwxi/DATS/CATS/JS/myobj00.dats b/xatslib/githwxi/DATS/CATS/JS/myobj00.dats index d409df4ff..3f1f6a2f3 100644 --- a/xatslib/githwxi/DATS/CATS/JS/myobj00.dats +++ b/xatslib/githwxi/DATS/CATS/JS/myobj00.dats @@ -24,6 +24,14 @@ hmap_tbox(a:t0) = jshsmap(strn, a) // #impltmp < a: t0 > +hmap_strmize + (map) = jshsmap_strmize(map) +// +(* ****** ****** *) +(* ****** ****** *) +// +#impltmp +< a: t0 > hmap_make_nil ((*void*)) = jshsmap_make_nil<>() // @@ -32,6 +40,13 @@ hmap_make_nil // #impltmp < a: t0 > +hmap_insert$obj + (map, k0, x0) = +( + jshsmap_insert$opt<>(map, k0, x0)) +// +#impltmp +< a: t0 > hmap_insert$new (map, k0, x0) = ( diff --git a/xatslib/githwxi/DATS/myobj00.dats b/xatslib/githwxi/DATS/myobj00.dats index 7a082b715..651ae30de 100644 --- a/xatslib/githwxi/DATS/myobj00.dats +++ b/xatslib/githwxi/DATS/myobj00.dats @@ -15,12 +15,25 @@ Sat 07 Sep 2024 08:37:22 PM EDT (* ****** ****** *) (* ****** ****** *) // -#abstype +#abstbox hmap_tbox(a:t0) #typedef hmap(a:t0) = hmap_tbox(a) // (* ****** ****** *) +(* ****** ****** *) +// +#extern +fun + +hmap_strmize +( map +: hmap(a)): strm_vt@(strn,a) +// +#symload +strmize with hmap_strmize of 1000 +// +(* ****** ****** *) // #extern fun @@ -32,10 +45,59 @@ hmap_make_nil((*0*)): hmap(a) #extern fun +hmap_insert$opt +( map +: hmap(a) +, k0: strn, x0: a): optn_vt(a) +// +(* ****** ****** *) +// +#extern +fun + hmap_insert$new ( map : hmap(a), k0: strn, x0: a): void // +#impltmp +< a: t0 > +hmap_insert$new + (map, k0, x0) = +( +case+ opt of +| ~optn_vt_nil() => () +) where +{ +val opt = +( + hmap_insert$opt(map, k0, x0)) +} +// +(* ****** ****** *) +// +#impltmp +{ a: t0 } +g_ptype +() = +( +strn_print"hmap("; +g_ptype();strn_print")") +// +#impltmp +{ a: t0 } +g_print +(map) = +( +gseq_print0 + +(hmap_strmize(map))) +where +{ +#typedef kx = (strn, a) +#vwtpdef kxs = strm_vt(kx) +#impltmp +gseq_beg() = "hmap(" } +// (* ****** ****** *) (* ****** ****** *) // @@ -63,7 +125,7 @@ datatype dtval = // (* ****** ****** *) (* ****** ****** *) - +// #extern fun<> dtval_un_sint @@ -108,6 +170,59 @@ dtval_un_fxun (dtv: dtval): (a1sz(dtval))->dtval // (* ****** ****** *) +(* ****** ****** *) +// +#impltmp +g_ptype +< dtval > +( (*0*) ) = strn_print<>("dtval") +// +(* ****** ****** *) +// +#impltmp +g_print +< dtval > +( dtv ) = +( +praux(dtv)) where +{ +// +fun +praux +(dtv: dtval): void = +let +// +#impltmp +g_print = praux +// +in//let +case+ dtv of +// +|DTVunit(ut) => +( + prints("DTVunit(", ")")) +// +|DTVsint(i0) => +( + prints("DTVsint(", i0, ")")) +|DTVbool(b0) => +( + prints("DTVbool(", b0, ")")) +|DTVchar(c0) => +( + prints("DTVchar(", c0, ")")) +|DTVdflt(f0) => +( + prints("DTVdflt(", f0, ")")) +|DTVstrn(s0) => +( + prints("DTVstrn(", s0, ")")) +// +end//let//end-of-[praux(dtv)] +// +} +// +(* ****** ****** *) // #impltmp <(*tmp*)> @@ -191,6 +306,17 @@ let val-DTVfxun(fx) = dtv in fx end // #extern fun<> +myobj_make_nil(): myobj +// +#impltmp +<(*tmp*)> +myobj_make_nil + ( (*void*) ) = hmap_make_nil<>() +// +(* ****** ****** *) +// +#extern +fun<> myobj_fmake_fwork ( fwork : ((strn, dtval)->void)->void): myobj @@ -200,7 +326,8 @@ myobj_fmake_fwork myobj_fmake_fwork (fwork) = let -val obj = hmap_make_nil() +val obj = +myobj_make_nil<>((*0*)) in//let fwork( lam(k0, x0) => diff --git a/xatslib/githwxi/HATS/githwxi_dats.hats b/xatslib/githwxi/HATS/githwxi_dats.hats index 5e167baf5..58053655f 100644 --- a/xatslib/githwxi/HATS/githwxi_dats.hats +++ b/xatslib/githwxi/HATS/githwxi_dats.hats @@ -20,8 +20,11 @@ ATS3_XANADU/xatslib/githwxi/DATS (* ****** ****** *) (* ****** ****** *) #staload "./../DATS/myfil00.dats" +(* ****** ****** *) #staload "./../DATS/mycsv00.dats" (* ****** ****** *) +#staload "./../DATS/myobj00.dats" +(* ****** ****** *) (* ****** ****** *) (* HX: for linearly typed interfaces diff --git a/xatslib/githwxi/TEST/CATS/JS/Makefile_jsemit b/xatslib/githwxi/TEST/CATS/JS/Makefile_jsemit index c862b8d17..f4c9f636d 100644 --- a/xatslib/githwxi/TEST/CATS/JS/Makefile_jsemit +++ b/xatslib/githwxi/TEST/CATS/JS/Makefile_jsemit @@ -156,6 +156,25 @@ npx google-closure-compiler -W QUIET \ --compilation_level SIMPLE --js=$@_out.js --js_output_file=$@_out1.js ######################################################################## ######################################################################## +test07:: ; \ +echo "//" `date` > $@_out.js +############ +test07:: ; \ +$(CAT) $(SRCGEN2_XSHARED)/xats2js_js1emit.js >> $@_out.js +test07:: ; \ +$(CAT) $(SRCGEN2_XSHARED)/xats2js_prelude.js >> $@_out.js +test07:: ; \ +$(CAT) $(SRCGEN2_XSHARED)/xats2js_xatslib.js >> $@_out.js +############ +test07:: \ +test07_myobj00.dats; \ +$(NODE) --stack-size=4096 $(SRCGEN2_XATS2JS) $< >> $@_out.js +############ +test07:: ; \ +npx google-closure-compiler -W QUIET \ + --compilation_level SIMPLE --js=$@_out.js --js_output_file=$@_out1.js +######################################################################## +######################################################################## test99:: ; \ echo "//" `date` > $@_out.js ############ diff --git a/xatslib/githwxi/TEST/CATS/JS/test07_myobj00.dats b/xatslib/githwxi/TEST/CATS/JS/test07_myobj00.dats new file mode 100644 index 000000000..1cfd9ef86 --- /dev/null +++ b/xatslib/githwxi/TEST/CATS/JS/test07_myobj00.dats @@ -0,0 +1,80 @@ +(* ****** ****** *) +(* ****** ****** *) +(* +HX-2024-09-07: +Sat 07 Sep 2024 02:40:27 PM EDT +*) +(* ****** ****** *) +(* ****** ****** *) +#staload UN = +"prelude/SATS/unsfx00.sats" +(* ****** ****** *) +(* ****** ****** *) +#staload _ = +"prelude/DATS/gdbg000.dats" +(* ****** ****** *) +(* ****** ****** *) +// +#include +"srcgen2\ +/prelude/HATS/prelude_dats.hats" +#include +"xatslib\ +/githwxi/HATS/githwxi_dats.hats" +// +(* ****** ****** *) +(* ****** ****** *) +#include +"srcgen2\ +/prelude/HATS/prelude_JS_dats.hats" +#include +"xatslib/HATS/xatslib_JS_dats.hats" +#include +"xatslib\ +/githwxi/HATS/githwxi_JS_dats.hats" +// +(* ****** ****** *) +(* ****** ****** *) +// +(* +#include +"srcgen2\ +/prelude/HATS/prelude_NODE_dats.hats" +#include +"xatslib\ +/githwxi/HATS/githwxi_NODE_dats.hats" +*) +// +(* ****** ****** *) +(* ****** ****** *) +// +val () = +prints +("Hello from [test07_myobj00]!", "\n") +// +(* ****** ****** *) +(* ****** ****** *) + +val +obj0 = myobj_make_nil() +val () = prints("obj0 = ", obj0, "\n") +// +val () = +hmap_insert$new(obj0, "a", DTVsint(0)) +val () = +hmap_insert$new(obj0, "b", DTVsint(1)) +val () = prints("obj0 = ", obj0, "\n") +// +// +(* ****** ****** *) +(* ****** ****** *) +// +val () = console_log(the_print_store_flush()) +// +(* ****** ****** *) +(* ****** ****** *) +// +(* ****** ****** *)(* ****** ****** *)(* ****** ****** *) +(* ****** ****** *)(* ****** ****** *)(* ****** ****** *) + +(* end of [ATS3/XANADU_xatslib_JS_githwxi_TEST_test07_myobj00.dats] *)