@@ -55,19 +55,35 @@ const Janet *janet_tuple_n(const Janet *values, int32_t n) {
5555
5656/* C Functions */
5757
58- static Janet cfun_tuple_brackets (int32_t argc , Janet * argv ) {
58+ JANET_CORE_FN (cfun_tuple_brackets ,
59+ "(tuple/brackets & xs)" ,
60+ "Creates a new bracketed tuple containing the elements xs." ) {
5961 const Janet * tup = janet_tuple_n (argv , argc );
6062 janet_tuple_flag (tup ) |= JANET_TUPLE_FLAG_BRACKETCTOR ;
6163 return janet_wrap_tuple (tup );
6264}
6365
64- static Janet cfun_tuple_slice (int32_t argc , Janet * argv ) {
66+ JANET_CORE_FN (cfun_tuple_slice ,
67+ "(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])" ,
68+ "Take a sub sequence of an array or tuple from index start "
69+ "inclusive to index end exclusive. If start or end are not provided, "
70+ "they default to 0 and the length of arrtup respectively. "
71+ "'start' and 'end' can also be negative to indicate indexing "
72+ "from the end of the input. Note that index -1 is synonymous with "
73+ "index '(length arrtup)' to allow a full negative slice range. "
74+ "Returns the new tuple." ) {
6575 JanetView view = janet_getindexed (argv , 0 );
6676 JanetRange range = janet_getslice (argc , argv );
6777 return janet_wrap_tuple (janet_tuple_n (view .items + range .start , range .end - range .start ));
6878}
6979
70- static Janet cfun_tuple_type (int32_t argc , Janet * argv ) {
80+ JANET_CORE_FN (cfun_tuple_type ,
81+ "(tuple/type tup)" ,
82+ "Checks how the tuple was constructed. Will return the keyword "
83+ ":brackets if the tuple was parsed with brackets, and :parens "
84+ "otherwise. The two types of tuples will behave the same most of "
85+ "the time, but will print differently and be treated differently by "
86+ "the compiler." ) {
7187 janet_fixarity (argc , 1 );
7288 const Janet * tup = janet_gettuple (argv , 0 );
7389 if (janet_tuple_flag (tup ) & JANET_TUPLE_FLAG_BRACKETCTOR ) {
@@ -77,7 +93,10 @@ static Janet cfun_tuple_type(int32_t argc, Janet *argv) {
7793 }
7894}
7995
80- static Janet cfun_tuple_sourcemap (int32_t argc , Janet * argv ) {
96+ JANET_CORE_FN (cfun_tuple_sourcemap ,
97+ "(tuple/sourcemap tup)" ,
98+ "Returns the sourcemap metadata attached to a tuple, "
99+ " which is another tuple (line, column)." ) {
81100 janet_fixarity (argc , 1 );
82101 const Janet * tup = janet_gettuple (argv , 0 );
83102 Janet contents [2 ];
@@ -86,56 +105,26 @@ static Janet cfun_tuple_sourcemap(int32_t argc, Janet *argv) {
86105 return janet_wrap_tuple (janet_tuple_n (contents , 2 ));
87106}
88107
89- static Janet cfun_tuple_setmap (int32_t argc , Janet * argv ) {
108+ JANET_CORE_FN (cfun_tuple_setmap ,
109+ "(tuple/setmap tup line column)" ,
110+ "Set the sourcemap metadata on a tuple. line and column indicate "
111+ "should be integers." ) {
90112 janet_fixarity (argc , 3 );
91113 const Janet * tup = janet_gettuple (argv , 0 );
92114 janet_tuple_head (tup )-> sm_line = janet_getinteger (argv , 1 );
93115 janet_tuple_head (tup )-> sm_column = janet_getinteger (argv , 2 );
94116 return argv [0 ];
95117}
96118
97- static const JanetReg tuple_cfuns [] = {
98- {
99- "tuple/brackets" , cfun_tuple_brackets ,
100- JDOC ("(tuple/brackets & xs)\n\n"
101- "Creates a new bracketed tuple containing the elements xs." )
102- },
103- {
104- "tuple/slice" , cfun_tuple_slice ,
105- JDOC ("(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])\n\n"
106- "Take a sub sequence of an array or tuple from index start "
107- "inclusive to index end exclusive. If start or end are not provided, "
108- "they default to 0 and the length of arrtup respectively. "
109- "'start' and 'end' can also be negative to indicate indexing "
110- "from the end of the input. Note that index -1 is synonymous with "
111- "index '(length arrtup)' to allow a full negative slice range. "
112- "Returns the new tuple." )
113- },
114- {
115- "tuple/type" , cfun_tuple_type ,
116- JDOC ("(tuple/type tup)\n\n"
117- "Checks how the tuple was constructed. Will return the keyword "
118- ":brackets if the tuple was parsed with brackets, and :parens "
119- "otherwise. The two types of tuples will behave the same most of "
120- "the time, but will print differently and be treated differently by "
121- "the compiler." )
122- },
123- {
124- "tuple/sourcemap" , cfun_tuple_sourcemap ,
125- JDOC ("(tuple/sourcemap tup)\n\n"
126- "Returns the sourcemap metadata attached to a tuple, "
127- " which is another tuple (line, column)." )
128- },
129- {
130- "tuple/setmap" , cfun_tuple_setmap ,
131- JDOC ("(tuple/setmap tup line column)\n\n"
132- "Set the sourcemap metadata on a tuple. line and column indicate "
133- "should be integers." )
134- },
135- {NULL , NULL , NULL }
136- };
137-
138119/* Load the tuple module */
139120void janet_lib_tuple (JanetTable * env ) {
140- janet_core_cfuns (env , NULL , tuple_cfuns );
121+ JanetRegExt tuple_cfuns [] = {
122+ JANET_CORE_REG ("tuple/brackets" , cfun_tuple_brackets ),
123+ JANET_CORE_REG ("tuple/slice" , cfun_tuple_slice ),
124+ JANET_CORE_REG ("tuple/type" , cfun_tuple_type ),
125+ JANET_CORE_REG ("tuple/sourcemap" , cfun_tuple_sourcemap ),
126+ JANET_CORE_REG ("tuple/setmap" , cfun_tuple_setmap ),
127+ JANET_REG_END
128+ };
129+ janet_core_cfuns_ext (env , NULL , tuple_cfuns );
141130}
0 commit comments