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 <tmj9...@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-users+unsubscr...@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/CAPPSPLpyWugPLRRu-ivHp%2BRGMrxPgFyqPm%2BFvnbHW7-LtpKLiA%40mail.gmail.com.