Here are the files, with some of the functions that are never used in the example removed. The code was compiled with: *patscc -c -DATS_MEMALLOC_LIBC dict.dats* | | | (* ### dict.sats ###
*) #include "share/atspre_staload.hats" (* buckets (aka linked lists) *) absvtype bucket (a:vt@ype) = ptr fn{a:vt@ype} bucket_new ( string, a ) : bucket(a) fn{a:vt@ype} bucket_map ( !bucket(a) ) : void fn{a:vt@ype} bucket_filter_map ( b: !bucket(a) ) : void fn{a:vt@ype} bucket_item$delete ( x: a ): void fn{a:vt@ype} bucket_item$map ( x: &a ): void fn{a:vt@ype} bucket_item$filter ( x: !a ): bool fn{a:vt@ype} bucket_item$to_string ( x: !a ): string fun{a:vt@ype} bucket_delete_recursive ( b: bucket(a) ) : void fn{a:vt@ype} bucket_print ( b: !bucket(a) ) : void (* dictionaries *) sortdef dsz = {s:int | s > 0} absvt@ype dict (a:vt@ype, n:int) = @{size=int,buckets=ptr} 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 fn{a:vt@ype} dict_delete_fun {s:dsz} ( d: dict(a, s), (a) -> void ) : void | | | (* ### dict.dats ### *) #include "share/atspre_staload.hats" staload "./dict.sats" fn hash {n:int | n>0}{s:int | s>0} ( s: string(s), size: int(n) ) : [o:int | o >= 0; o < n] int o = let fun hash_num {i:nat | i <= s} ( i: int i, h: int, str_sz: int(s) ) : int = if i < str_sz then let val c_at_i = string_get_at_gint(s, i) in hash_num(i+1, h * 101 + g0int_of_char(c_at_i), str_sz) end else h in g1int_nmod(abs(g1ofg0(hash_num(0, 0, sz2i(strlen(s))))), size) end local datavtype BUCKET (a:vt@ype) = | bucket_empty of () | bucket_filled of (Strptr1, a, BUCKET(a)) assume bucket(a:vt@ype) = BUCKET(a) assume dict(a:vt@ype, n:int) = @{ size=int n, buckets=arrayptr(bucket(a), n) } extern fn{a:vt@ype} bucket_operate ( !bucket(a) ) : void 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 implmnt{a} dict_delete_fun ( d, dltr ) = let implmnt bucket_item$delete<a> ( x ) = dltr(x) in dict_delete_lin(d) end implmnt{a} bucket_new ( key, item ) = bucket_filled($UNSAFE.castvwtp0{Strptr1}(key), item, bucket_empty()) implmnt{a} bucket_map ( b ) = case+ b of | bucket_empty() => () | @bucket_filled(_, x, next_bucket) => { val () = bucket_item$map(x) val () = bucket_map(next_bucket) prval () = fold@(b) } implmnt{a} bucket_filter_map ( b ) = case+ b of | bucket_empty() => () | @bucket_filled(_, x, next_bucket) => if bucket_item$filter(x) then { val () = bucket_item$map(x) val () = bucket_filter_map(next_bucket) prval () = fold@(b) } else { val () = bucket_filter_map(next_bucket) prval () = fold@(b) } implmnt{a} bucket_print ( b ) = case+ b of | bucket_empty() => () | bucket_filled(str, x, next_bucket) => let val () = print("\(") val () = print(str) val () = print(" : ") val () = print( bucket_item$to_string(x) ) val () = print(")") in bucket_print(next_bucket) end end var d = dict_new<int>(7) val () = dict_delete<int>(d) | | | On Thursday, December 30, 2021 at 2:48:29 PM UTC-5 gmhwxi wrote: > Where can I find your source code so that I can produce the error you are > referring to? > > --Hongwei > > > On Thu, Dec 30, 2021 at 12:47 PM d4v3y_5c0n3s <tmj...@gmail.com> wrote: > >> Ok, so I've been able to get the "dict" type to be abstract, but I can't >> seem to get "bucket" to be abstract. I tried adding the "= ptr" part you >> suggested, but I'm not having any luck. Using your solution, the code will >> compile, unless I test the "dict" type by calling "dict_new" & >> "dict_delete." Looking at the error messages, the problem appears to be >> related to the "dict_delete" call, and I've provided the error below so you >> can see for yourself. I know that there are a lot of details missing, so >> let me know if you'd like me to provide any more details. >> >> Error message: >> In file included from dict_dats.c:15: >> dict_dats.c: In function ‘loop_95__95__1’: >> dict_dats.c:6190:28: error: ‘PMVtmpltcstmat’ undeclared (first use in >> this function) >> 6190 | ATSINSmove_void(tmp195__1, >> PMVtmpltcstmat[0](array_uninitize$clear<S2Eapp(S2Ecst(BUCKET); >> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2, >> ATSPMVrefarg1(arg0))) ; >> | ^~~~~~~~~~~~~~ >> /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 >> | ^~~~~~~ >> dict_dats.c:6190:28: note: each undeclared identifier is reported only >> once for each function it appears in >> 6190 | ATSINSmove_void(tmp195__1, >> PMVtmpltcstmat[0](array_uninitize$clear<S2Eapp(S2Ecst(BUCKET); >> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2, >> ATSPMVrefarg1(arg0))) ; >> | ^~~~~~~~~~~~~~ >> /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 >> | ^~~~~~~ >> dict_dats.c:6190:46: error: ‘array_uninitize$clear’ undeclared (first use >> in this function) >> 6190 | ATSINSmove_void(tmp195__1, >> PMVtmpltcstmat[0](array_uninitize$clear<S2Eapp(S2Ecst(BUCKET); >> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2, >> ATSPMVrefarg1(arg0))) ; >> | ^~~~~~~~~~~~~~~~~~~~~ >> /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 >> | ^~~~~~~ >> dict_dats.c:6190:68: warning: implicit declaration of function ‘S2Eapp’ >> [-Wimplicit-function-declaration] >> 6190 | ATSINSmove_void(tmp195__1, >> PMVtmpltcstmat[0](array_uninitize$clear<S2Eapp(S2Ecst(BUCKET); >> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2, >> ATSPMVrefarg1(arg0))) ; >> | >> ^~~~~~ >> /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 >> | ^~~~~~~ >> dict_dats.c:6190:75: warning: implicit declaration of function ‘S2Ecst’ >> [-Wimplicit-function-declaration] >> 6190 | ATSINSmove_void(tmp195__1, >> PMVtmpltcstmat[0](array_uninitize$clear<S2Eapp(S2Ecst(BUCKET); >> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2, >> ATSPMVrefarg1(arg0))) ; >> | >> ^~~~~~ >> /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 >> | ^~~~~~~ >> dict_dats.c:6190:82: error: ‘BUCKET’ undeclared (first use in this >> function) >> 6190 | ATSINSmove_void(tmp195__1, >> PMVtmpltcstmat[0](array_uninitize$clear<S2Eapp(S2Ecst(BUCKET); >> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2, >> ATSPMVrefarg1(arg0))) ; >> | >> ^~~~~~ >> /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 >> | ^~~~~~~ >> dict_dats.c:6190:89: error: expected ‘)’ before ‘;’ token >> 6190 | move_void(tmp195__1, >> PMVtmpltcstmat[0](array_uninitize$clear<S2Eapp(S2Ecst(BUCKET); >> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)))>)(arg2, >> ATSPMVrefarg1(arg0))) ; >> | >> ~ ^ >> >> /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 >> | ^~~~~~~ >> dict_dats.c:6190:145: error: expected expression before ‘)’ token >> 6190 | lear<S2Eapp(S2Ecst(BUCKET); S2Eapp(S2Ecst(g0int_t0ype); >> S2Eextkind(atstype_int)))>)(arg2, ATSPMVrefarg1(arg0))) ; >> | >> ^ >> >> /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, December 7, 2021 at 8:08:48 AM UTC-5 d4v3y_5c0n3s wrote: >> >>> Thanks, I tried something similar with the "dict" type, but completely >>> overlooked the "bucket" type. I'll test this to see if it resolves the >>> issue. >>> >>> On Wednesday, December 1, 2021 at 12:28:15 AM UTC-5 gmhwxi wrote: >>> >>>> After taking a quick look at dict.sats, I spotted the following line: >>>> >>>> absvtype bucket(a:vt@ype) >>>> >>>> which should be change to the following one: >>>> >>>> absvtype bucket(a:vt@ype) = ptr // ptr takes the compiler the size of >>>> bucket >>>> >>>> The simple reason is that the compiler needs to know the size of an >>>> abstract type in order to compile it to a type in C. >>>> >>>> >>>> On Wednesday, December 1, 2021 at 12:16:34 AM UTC-5 gmhwxi wrote: >>>> >>>>> I don't quite understand. >>>>> Templates in ATS2 are supposed to be working with abstract types. >>>>> >>>>> If I could try precisely what you did on your machine, then I may be >>>>> able to suggest something. >>>>> >>>>> >>>>> >>>>> On Tue, Nov 30, 2021 at 8:27 PM d4v3y_5c0n3s <tmj...@gmail.com> wrote: >>>>> >>>>>> Update 2: >>>>>> After investigating the prelude, I've determined that templates in >>>>>> ATS2 just conflict with abstract types in some instances. For this >>>>>> reason, >>>>>> it seems that in many parts of the prelude avoided the use of the >>>>>> "assume" >>>>>> keyword with template-heavy code. >>>>>> >>>>>> On Tuesday, November 30, 2021 at 7:08:48 PM UTC-5 d4v3y_5c0n3s wrote: >>>>>> >>>>>>> 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-user...@googlegroups.com. >>>>>> >>>>> To view this discussion on the web visit >>>>>> https://groups.google.com/d/msgid/ats-lang-users/8f8bd20f-8ec3-4008-ae28-e28b013d8069n%40googlegroups.com >>>>>> >>>>>> <https://groups.google.com/d/msgid/ats-lang-users/8f8bd20f-8ec3-4008-ae28-e28b013d8069n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> >>>>> -- >> > You received this message because you are subscribed to a topic in the >> Google Groups "ats-lang-users" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/ats-lang-users/sZgQapU08Bo/unsubscribe. >> To unsubscribe from this group and all its topics, 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/19270152-47db-4f7a-adf4-247b1adedd4dn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ats-lang-users/19270152-47db-4f7a-adf4-247b1adedd4dn%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/787ea3b9-d40c-45bb-89e3-8713a151c000n%40googlegroups.com.