Update: I was able to get the code I provided above running by staloading the dict.dats file from the dict_test.dats file using " staload _ = "./dict.dats" ". Now, my only problem is that if I make the "dict" & bucket types abstract, the templates stop working.
On Tuesday, November 30, 2021 at 1:39:39 PM UTC-5 d4v3y_5c0n3s wrote: > You are right, including " share/atspre_staload.hats" causes the code to > compile. However, I'm still having issues. You see, the code I provided I > had taken from a static (.sats) and dynamic (.dats) file in order to make > it more presentable when asking for help. Your fix only fixes the issue in > the single-file version, and when including the external static file it > doesn't work. Do you know what might be going wrong? I'll provide the > (simplified) contents of each of these files below. > > *dict.sats*: > #include "share/atspre_staload.hats" > > > datavtype BUCKET (a:vt@ype) = > | bucket_empty of () > | bucket_filled of (Strptr1, a, BUCKET(a)) > > vtypedef bucket(a:vt@ype) = BUCKET(a) > > fn{a:vt@ype} bucket_item$delete ( x: a ): void > > fun{a:vt@ype} bucket_delete_recursive ( b: bucket(a) ) : void > > sortdef dsz = {s:int | s > 0} > > vtypedef dict(a:vt@ype, n:int) = > @{ > size=int n, > buckets=arrayptr(bucket(a), n) > } > > fn{a:vt@ype} dict_new {s:dsz} ( int s ) : dict(a, s) > fn{a:t@ype} dict_delete {s:dsz} ( d: dict(a, s) ) : void > fn{a:vt@ype} dict_delete_lin {s:dsz} ( d: dict(a, s) ) : void > > > *dict.dats*: > #include "share/atspre_staload.hats" > > staload "./dict.sats" > > local > in > > > implement{a} dict_new {s} ( size ) = let > val size_st = size_of_int(size) > val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) > implmnt array_initize$init<bucket(a)> (i, x) = x := bucket_empty() > val () = arrayptr_initize<bucket(a)>(bucket_arr, size_st) > in > @{size=size, buckets=bucket_arr}:dict(a, s) > end > > implmnt{a} dict_delete ( d ) = let > implmnt(a2:t@ype) bucket_item$delete<a2> ( x ) = () > in > dict_delete_lin<a>(d) > end > > implmnt{a} bucket_delete_recursive ( b ) = > case+ b of > | ~bucket_empty() => () > | ~bucket_filled(str, x, next_bucket) => let > val () = strptr_free(str) > val () = bucket_item$delete<a>(x) > in > bucket_delete_recursive<a>(next_bucket) > end > > implmnt{a} dict_delete_lin ( d ) = let > implmnt array_uninitize$clear<bucket(a)> (i, x) = > bucket_delete_recursive<a>(x) > in > arrayptr_freelin(d.buckets, size_of_int(d.size)) > end > end > > *dict_test.dats*, where main is: > #include "share/atspre_staload.hats" > > staload "./dict.sats" > > > implmnt main0 () = let > var d = dict_new<int>(13) > in > dict_delete(d) > end > > *My output*: > $ patscc --gline -DATS_MEMALLOC_LIBC dict_test.dats > > In file included from dict_test_dats.c:15: > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats: In function > ‘mainats_0_void’: > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:21: error: > ‘PMVtmpltcstmat’ undeclared (first use in this function) > 58 | var d = dict_new<int>(13) > | ^~~~~~~ > > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: > > note: in definition of macro ‘ATSINSmove’ > 276 | #define ATSINSmove(tmp, val) (tmp = val) > | ^~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:21: note: each > undeclared identifier is reported only once for each function it appears in > 58 | var d = dict_new<int>(13) > | ^~~~~~~ > > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: > > note: in definition of macro ‘ATSINSmove’ > 276 | #define ATSINSmove(tmp, val) (tmp = val) > | ^~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:39: error: > ‘dict_new’ undeclared (first use in this function) > 58 | var d = dict_new<int>(13) > > | ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: > > note: in definition of macro ‘ATSINSmove’ > 276 | #define ATSINSmove(tmp, val) (tmp = val) > | ^~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:48: warning: > implicit declaration of function ‘S2Eapp’ [-Wimplicit-function-declaration] > 58 | var d = dict_new<int>(13) > > | ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: > > note: in definition of macro ‘ATSINSmove’ > 276 | #define ATSINSmove(tmp, val) (tmp = val) > | ^~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:55: warning: > implicit declaration of function ‘S2Ecst’ [-Wimplicit-function-declaration] > 58 | var d = dict_new<int>(13) > > | ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: > > note: in definition of macro ‘ATSINSmove’ > 276 | #define ATSINSmove(tmp, val) (tmp = val) > | ^~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:62: error: > ‘g0int_t0ype’ undeclared (first use in this function) > 58 | var d = dict_new<int>(13) > > | > ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: > > note: in definition of macro ‘ATSINSmove’ > 276 | #define ATSINSmove(tmp, val) (tmp = val) > | ^~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:74: error: > expected ‘)’ before ‘;’ token > 58 | var d = dict_new<int>(13) > > > | ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: > > note: in definition of macro ‘ATSINSmove’ > 276 | #define ATSINSmove(tmp, val) (tmp = val) > | ^~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:58:101: error: > expected expression before ‘)’ token > 58 | var d = dict_new<int>(13) > > > | > > ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: > > note: in definition of macro ‘ATSINSmove’ > 276 | #define ATSINSmove(tmp, val) (tmp = val) > | ^~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:60:44: error: > ‘dict_delete’ undeclared (first use in this function); did you mean > ‘timer_delete’? > 60 | dict_delete(d) > > | ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: > > note: in definition of macro ‘ATSINSmove_void’ > 284 | #define ATSINSmove_void(tmp, command) command > | ^~~~~~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:60:82: error: > expected ‘)’ before ‘;’ token > 60 | dict_delete(d) > > > | > > ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: > > note: in definition of macro ‘ATSINSmove_void’ > 284 | #define ATSINSmove_void(tmp, command) command > | ^~~~~~~ > /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:60:109: error: > expected expression before ‘)’ token > 60 | dict_delete(d) > > > | > > ^ > /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: > > note: in definition of macro ‘ATSINSmove_void’ > 284 | #define ATSINSmove_void(tmp, command) command > | ^~~~~~~ > On Tuesday, November 30, 2021 at 11:28:47 AM UTC-5 gmhwxi wrote: > >> I tried your code and it compiled without any issue. >> >> Did you have the following line at the top: >> >> #include "share/atspre_staload.hats" >> >> The error messages you showed indicate that many template implementations >> were not >> available to the compiler (patsopt). >> >> --Hongwei >> >> >> On Tue, Nov 30, 2021 at 10:52 AM d4v3y_5c0n3s <tmj...@gmail.com> wrote: >> >>> Okay, so I've been struggling with my use of templates for a while >>> now, and I'm making this post to get some more eyes on the issue. I've >>> been getting really frustrated, because nothing I've tried seems to work, >>> and I have no way to understand what is going wrong whatsoever besides >>> becoming familiar with compiler internals (which could take who knows how >>> long to learn.) >>> >>> Here's my code: >>> datavtype BUCKET (a:vt@ype) = >>> | bucket_empty of () >>> | bucket_filled of (Strptr1, a, BUCKET(a)) >>> >>> vtypedef bucket(a:vt@ype) = BUCKET(a) >>> >>> sortdef dsz = {s:int | s > 0} >>> >>> vtypedef dict(a:vt@ype, n:int) = >>> @{ >>> size=int n, >>> buckets=arrayptr(bucket(a), n) >>> } >>> >>> extern fn{a:vt@ype} dict_new {s:dsz} ( int s ) : dict(a, s) >>> extern fn{a:t@ype} dict_delete {s:dsz} ( d: dict(a, s) ) : void >>> extern fn{a:vt@ype} dict_delete_lin {s:dsz} ( d: dict(a, s) ) : void >>> >>> extern fun{a:vt@ype} bucket_delete_recursive ( b: bucket(a) ) : void >>> extern fn{a:vt@ype} bucket_item$delete ( x: a ): void >>> >>> implement{a} dict_new {s} ( size ) = let >>> val size_st = size_of_int(size) >>> val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> implmnt array_initize$init<bucket(a)> (i, x) = x := bucket_empty() >>> val () = arrayptr_initize<bucket(a)>(bucket_arr, size_st) >>> in >>> @{size=size, buckets=bucket_arr}:dict(a, s) >>> end >>> >>> implmnt{a} dict_delete ( d ) = let >>> implmnt(a2:t@ype) bucket_item$delete<a2> ( x ) = () >>> in >>> dict_delete_lin<a>(d) >>> end >>> >>> implmnt{a} bucket_delete_recursive ( b ) = >>> case+ b of >>> | ~bucket_empty() => () >>> | ~bucket_filled(str, x, next_bucket) => let >>> val () = strptr_free(str) >>> val () = bucket_item$delete<a>(x) >>> in >>> bucket_delete_recursive<a>(next_bucket) >>> end >>> >>> implmnt{a} dict_delete_lin ( d ) = let >>> implmnt array_uninitize$clear<bucket(a)> (i, x) = >>> bucket_delete_recursive<a>(x) >>> in >>> arrayptr_freelin(d.buckets, size_of_int(d.size)) >>> end >>> >>> implmnt main0 () = let >>> var d = dict_new<int>(13) >>> in >>> dict_delete(d) >>> end >>> >>> >>> Here's the output: >>> $ patscc --gline dict_test.dats >>> In file included from dict_test_dats.c:15: >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats: In function >>> ‘_057_home_057_tmj90_057_Goldelish_055_Engine_057_source_057_data_057_dict_test_056_dats__dict_new__0__1’: >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:21: error: >>> ‘PMVtmpltcstmat’ undeclared (first use in this function) >>> 24 | val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> | ^~~~~~~~~~~~~~ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: >>> >>> note: in definition of macro ‘ATSINSmove’ >>> 276 | #define ATSINSmove(tmp, val) (tmp = val) >>> | ^~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:21: note: >>> each undeclared identifier is reported only once for each function it >>> appears in >>> 24 | val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> | ^~~~~~~~~~~~~~ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: >>> >>> note: in definition of macro ‘ATSINSmove’ >>> 276 | #define ATSINSmove(tmp, val) (tmp = val) >>> | ^~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:39: error: >>> ‘arrayptr_make_uninitized’ undeclared (first use in this function) >>> 24 | val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> | ^~~~~~~~~~~~~~~~~~~~~~~~ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: >>> >>> note: in definition of macro ‘ATSINSmove’ >>> 276 | #define ATSINSmove(tmp, val) (tmp = val) >>> | ^~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:64: warning: >>> implicit declaration of function ‘S2Eapp’ [-Wimplicit-function-declaration] >>> 24 | val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> | >>> ^~ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: >>> >>> note: in definition of macro ‘ATSINSmove’ >>> 276 | #define ATSINSmove(tmp, val) (tmp = val) >>> | ^~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:71: warning: >>> implicit declaration of function ‘S2Ecst’ [-Wimplicit-function-declaration] >>> 24 | val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> >>> | >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: >>> >>> note: in definition of macro ‘ATSINSmove’ >>> 276 | #define ATSINSmove(tmp, val) (tmp = val) >>> | ^~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:78: error: >>> ‘BUCKET’ undeclared (first use in this function) >>> 24 | val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> >>> | >>> >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: >>> >>> note: in definition of macro ‘ATSINSmove’ >>> 276 | #define ATSINSmove(tmp, val) (tmp = val) >>> | ^~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:85: error: >>> expected ‘)’ before ‘;’ token >>> 24 | val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> >>> | >>> >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: >>> >>> note: in definition of macro ‘ATSINSmove’ >>> 276 | #define ATSINSmove(tmp, val) (tmp = val) >>> | ^~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:24:141: error: >>> expected expression before ‘)’ token >>> 24 | val bucket_arr = arrayptr_make_uninitized<bucket(a)>(size_st) >>> >>> | >>> >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:276:37: >>> >>> note: in definition of macro ‘ATSINSmove’ >>> 276 | #define ATSINSmove(tmp, val) (tmp = val) >>> | ^~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:26:44: error: >>> ‘arrayptr_initize’ undeclared (first use in this function) >>> 26 | val () = arrayptr_initize<bucket(a)>(bucket_arr, size_st) >>> | ^~~~~~~~~~~~~~~~ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: >>> >>> note: in definition of macro ‘ATSINSmove_void’ >>> 284 | #define ATSINSmove_void(tmp, command) command >>> | ^~~~~~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:26:82: error: >>> expected ‘)’ before ‘;’ token >>> 26 | val () = arrayptr_initize<bucket(a)>(bucket_arr, size_st) >>> >>> | >>> >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: >>> >>> note: in definition of macro ‘ATSINSmove_void’ >>> 284 | #define ATSINSmove_void(tmp, command) command >>> | ^~~~~~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:26:138: error: >>> expected expression before ‘)’ token >>> 26 | val () = arrayptr_initize<bucket(a)>(bucket_arr, size_st) >>> >>> | >>> >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: >>> >>> note: in definition of macro ‘ATSINSmove_void’ >>> 284 | #define ATSINSmove_void(tmp, command) command >>> | ^~~~~~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats: In function >>> ‘_057_home_057_tmj90_057_Goldelish_055_Engine_057_source_057_data_057_dict_test_056_dats__dict_delete_lin__5__1’: >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:50:30: error: >>> ‘PMVtmpltcstmat’ undeclared (first use in this function) >>> 50 | arrayptr_freelin(d.buckets, size_of_int(d.size)) >>> | ^~~~~~~~~~~~~~ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: >>> >>> note: in definition of macro ‘ATSINSmove_void’ >>> 284 | #define ATSINSmove_void(tmp, command) command >>> | ^~~~~~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:50:48: error: >>> ‘arrayptr_freelin’ undeclared (first use in this function) >>> 50 | arrayptr_freelin(d.buckets, size_of_int(d.size)) >>> | ^~~ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: >>> >>> note: in definition of macro ‘ATSINSmove_void’ >>> 284 | #define ATSINSmove_void(tmp, command) command >>> | ^~~~~~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:50:79: error: >>> ‘BUCKET’ undeclared (first use in this function) >>> 50 | arrayptr_freelin(d.buckets, size_of_int(d.size)) >>> >>> | >>> >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: >>> >>> note: in definition of macro ‘ATSINSmove_void’ >>> 284 | #define ATSINSmove_void(tmp, command) command >>> | ^~~~~~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:50:86: error: >>> expected ‘)’ before ‘;’ token >>> 50 | arrayptr_freelin(d.buckets, size_of_int(d.size)) >>> >>> | >>> >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: >>> >>> note: in definition of macro ‘ATSINSmove_void’ >>> 284 | #define ATSINSmove_void(tmp, command) command >>> | ^~~~~~~ >>> /home/tmj90/Goldelish-Engine/source/data/dict_test.dats:50:142: error: >>> expected expression before ‘)’ token >>> 50 | arrayptr_freelin(d.buckets, size_of_int(d.size)) >>> >>> | >>> >>> ^ >>> /usr/local/lib/ats2-postiats-0.4.2/ccomp/runtime/pats_ccomp_instrset.h:284:39: >>> >>> note: in definition of macro ‘ATSINSmove_void’ >>> 284 | #define ATSINSmove_void(tmp, command) command >>> | ^~~~~~~ >>> >>> Any help is greatly appreciated, and let me know if you have any >>> questions. Thank you. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "ats-lang-users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to ats-lang-user...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/ats-lang-users/d42e5377-0287-4311-9b39-716235b7a0c3n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/ats-lang-users/d42e5377-0287-4311-9b39-716235b7a0c3n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "ats-lang-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/d9ebcc56-7951-4cb4-90df-9af90b5cff30n%40googlegroups.com.