I’m having some trouble compiling code that makes heavy use of templates. I
am using a library that parses JSON into an array of tokens. Each token
refers to a value which can be retrieved from the original JSON string. I
have a template function that returns this string. Before any information
is taken from the tokens, the user must implement this function with the
correct string. This avoids having to set up a global variable or add
parameters to functions. When I try to compile the corresponding C code, I
find many instances of the following error, but only for some template
functions.
parsing_dats.c:86143:186: error: use of undeclared identifier 'data'
ATSINSmove(tmpret762__4, parse_s2rt__131__4(ATSPMVenv(data), arg0)) ;
The highest level code looks like the following
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this small
example on github.
This is a VERY tricky issue because this kind of use was not
part of the design. On the other hand, it seems natural to use templates
this way. So …On Thursday, January 8, 2015 12:59:43 AM UTC-5, gmhwxi wrote:
I have managed to produce this kind of bug using the following simple code:
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier 'data'
ATSINSmove(tmpret762__4, parse_s2rt__131__4(ATSPMVenv(data), arg0)) ;
The highest level code looks like the following
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this
small example on github.
Basically, the idea is to allow the programmer to indicate to the compiler
that a particular
dynamic variable should be included in the environment of a template
instance. For instance,
implement
main0 (argc, argv) = let
//
val () = $closurenv(argc) // [argc] is put into the environment of the
following instance of [foo]
//
in
… foo<> (…) …
end // end of [main0]
For a running example, please see:
You need ATS2-github to test this example.On Thursday, January 8, 2015 at 2:39:39 AM UTC-5, gmhwxi wrote:
This is a VERY tricky issue because this kind of use was not
part of the design. On the other hand, it seems natural to use templates
this way. So …
On Thursday, January 8, 2015 12:59:43 AM UTC-5, gmhwxi wrote:
I have managed to produce this kind of bug using the following simple
code:
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier 'data'
ATSINSmove(tmpret762__4, parse_s2rt__131__4(ATSPMVenv(data), arg0))
;
The highest level code looks like the following
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this
small example on github.
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of templates.
I am using a library that parses JSON into an array of tokens. Each token
refers to a value which can be retrieved from the original JSON string. I
have a template function that returns this string. Before any information
is taken from the tokens, the user must implement this function with the
correct string. This avoids having to set up a global variable or add
parameters to functions. When I try to compile the corresponding C code, I
find many instances of the following error, but only for some template
functions.
parsing_dats.c:86143:186: error: use of undeclared identifier 'data'
ATSINSmove(tmpret762__4, parse_s2rt__131__4(ATSPMVenv(data), arg0)) ;
The highest level code looks like the following
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this small
example on github.
Are mutually recursive templates only an issue when instantiating one of
the templates requires bringing in variables from the environment? If so, I
could just replace the jsonval_src template with a global variable for now.
What would you have to do to support using templates in this way?Am Donnerstag, 8. Januar 2015 02:39:39 UTC-5 schrieb gmhwxi:
This is a VERY tricky issue because this kind of use was not
part of the design. On the other hand, it seems natural to use templates
this way. So …
On Thursday, January 8, 2015 12:59:43 AM UTC-5, gmhwxi wrote:
I have managed to produce this kind of bug using the following simple
code:
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier 'data'
ATSINSmove(tmpret762__4, parse_s2rt__131__4(ATSPMVenv(data), arg0))
;
The highest level code looks like the following
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this
small example on github.
It seems that it isn’t finding the implementation of print_t0ype
given inside print_itmlstlst. Does it look like I am using templates
incorrectly here?
Thanks,
Will
Am Samstag, 10. Januar 2015 13:50:36 UTC-5 schrieb gmhwxi:
I changed the keyword $closurenv to $tempenver as this is only
related to compiling template instances.
On Saturday, January 10, 2015 at 2:59:02 AM UTC-5, gmhwxi wrote:
I came up with a fix for this issue.
Basically, the idea is to allow the programmer to indicate to the
compiler that a particular
dynamic variable should be included in the environment of a template
instance. For instance,
implement
main0 (argc, argv) = let
//
val () = $closurenv(argc) // [argc] is put into the environment of the
following instance of [foo]
//
in
… foo<> (…) …
end // end of [main0]
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C
code produced by patsopt compiles without any errors. You can find
this small example on github.
Thanks! That worked well. I’ve run into this issue before, and it’s good to
know what the cause of it is.Am Donnerstag, 15. Januar 2015 12:33:55 UTC-5 schrieb gmhwxi:
It seems that it isn’t finding the implementation of print_t0ype
given inside print_itmlstlst. Does it look like I am using templates
incorrectly here?
Thanks,
Will
Am Samstag, 10. Januar 2015 13:50:36 UTC-5 schrieb gmhwxi:
I changed the keyword $closurenv to $tempenver as this is only
related to compiling template instances.
On Saturday, January 10, 2015 at 2:59:02 AM UTC-5, gmhwxi wrote:
I came up with a fix for this issue.
Basically, the idea is to allow the programmer to indicate to the
compiler that a particular
dynamic variable should be included in the environment of a template
instance. For instance,
implement
main0 (argc, argv) = let
//
val () = $closurenv(argc) // [argc] is put into the environment of
the following instance of [foo]
//
in
… foo<> (…) …
end // end of [main0]
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires
some thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C
code produced by patsopt compiles without any errors. You can
find this small example on github.
I plan to add Part V to my book on Intro to ATS. It will be about
template-based programming.On Thursday, January 15, 2015 at 3:40:47 PM UTC-5, William Blair wrote:
It seems that it isn’t finding the implementation of
print_t0ype given inside print_itmlstlst. Does it look like I am
using templates incorrectly here?
Thanks,
Will
Am Samstag, 10. Januar 2015 13:50:36 UTC-5 schrieb gmhwxi:
I changed the keyword $closurenv to $tempenver as this is only
related to compiling template instances.
On Saturday, January 10, 2015 at 2:59:02 AM UTC-5, gmhwxi wrote:
I came up with a fix for this issue.
Basically, the idea is to allow the programmer to indicate to the
compiler that a particular
dynamic variable should be included in the environment of a template
instance. For instance,
implement
main0 (argc, argv) = let
//
val () = $closurenv(argc) // [argc] is put into the environment of
the following instance of [foo]
//
in
… foo<> (…) …
end // end of [main0]
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires
some thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C
code produced by patsopt compiles without any errors. You can
find this small example on github.
It seems that it isn’t finding the implementation of print_t0ype
given inside print_itmlstlst. Does it look like I am using templates
incorrectly here?
Thanks,
WillAm Samstag, 10. Januar 2015 13:50:36 UTC-5 schrieb gmhwxi:
I changed the keyword $closurenv to $tempenver as this is only
related to compiling template instances.
On Saturday, January 10, 2015 at 2:59:02 AM UTC-5, gmhwxi wrote:
I came up with a fix for this issue.
Basically, the idea is to allow the programmer to indicate to the
compiler that a particular
dynamic variable should be included in the environment of a template
instance. For instance,
implement
main0 (argc, argv) = let
//
val () = $closurenv(argc) // [argc] is put into the environment of the
following instance of [foo]
//
in
… foo<> (…) …
end // end of [main0]
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this
small example on github.
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of templates.
I am using a library that parses JSON into an array of tokens. Each token
refers to a value which can be retrieved from the original JSON string. I
have a template function that returns this string. Before any information
is taken from the tokens, the user must implement this function with the
correct string. This avoids having to set up a global variable or add
parameters to functions. When I try to compile the corresponding C code, I
find many instances of the following error, but only for some template
functions.
parsing_dats.c:86143:186: error: use of undeclared identifier 'data'
ATSINSmove(tmpret762__4, parse_s2rt__131__4(ATSPMVenv(data), arg0)) ;
The highest level code looks like the following
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this small
example on github.
It seems that it isn’t finding the implementation of print_t0ype
given inside print_itmlstlst. Does it look like I am using templates
incorrectly here?
Thanks,
Will
Am Samstag, 10. Januar 2015 13:50:36 UTC-5 schrieb gmhwxi:
I changed the keyword $closurenv to $tempenver as this is only
related to compiling template instances.
On Saturday, January 10, 2015 at 2:59:02 AM UTC-5, gmhwxi wrote:
I came up with a fix for this issue.
Basically, the idea is to allow the programmer to indicate to the
compiler that a particular
dynamic variable should be included in the environment of a template
instance. For instance,
implement
main0 (argc, argv) = let
//
val () = $closurenv(argc) // [argc] is put into the environment of
the following instance of [foo]
//
in
… foo<> (…) …
end // end of [main0]
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires
some thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C
code produced by patsopt compiles without any errors. You can
find this small example on github.
Ah I see, that should be easy to implement. Thanks!Am Donnerstag, 8. Januar 2015 15:20:22 UTC-5 schrieb gmhwxi:
Are mutually recursive templates only an issue when instantiating one of
the templates requires bringing in variables from the environment? If so, I
could just replace the jsonval_src template with a global variable for now.
That should work.
I think that a better way for now is to break the mutual dependency:
implement
{}(tmp)
parse_s2rt (…) = let
fun aux_S2RTfun (…) = (code for parse_S2RTfun)…
in
…
end
implement
{}(tmp)
parse_S2RTfun (…) = … // if you still need it.
On Thu, Jan 8, 2015 at 3:12 PM, William Blair <william...@gmail.com <javascript:>> wrote:
Are mutually recursive templates only an issue when instantiating one of
the templates requires bringing in variables from the environment? If so, I
could just replace the jsonval_src template with a global variable for now.
What would you have to do to support using templates in this way?
Am Donnerstag, 8. Januar 2015 02:39:39 UTC-5 schrieb gmhwxi:
This is a VERY tricky issue because this kind of use was not
part of the design. On the other hand, it seems natural to use templates
this way. So …
On Thursday, January 8, 2015 12:59:43 AM UTC-5, gmhwxi wrote:
I have managed to produce this kind of bug using the following simple
code:
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this
small example on github.
It seems that it isn’t finding the implementation of print_t0ype
given inside print_itmlstlst. Does it look like I am using templates
incorrectly here?
Thanks,
Will
Am Samstag, 10. Januar 2015 13:50:36 UTC-5 schrieb gmhwxi:
I changed the keyword $closurenv to $tempenver as this is only
related to compiling template instances.
On Saturday, January 10, 2015 at 2:59:02 AM UTC-5, gmhwxi wrote:
I came up with a fix for this issue.
Basically, the idea is to allow the programmer to indicate to the
compiler that a particular
dynamic variable should be included in the environment of a template
instance. For instance,
implement
main0 (argc, argv) = let
//
val () = $closurenv(argc) // [argc] is put into the environment of the
following instance of [foo]
//
in
… foo<> (…) …
end // end of [main0]
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires
some thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C
code produced by patsopt compiles without any errors. You can find
this small example on github.
What would you have to do to support using templates in this way?
Not really sure yet.
This kind of thing is inevitable as it is impossible to plan/design
everything
ahead.On Thursday, January 8, 2015 at 3:12:07 PM UTC-5, William Blair wrote:
Are mutually recursive templates only an issue when instantiating one of
the templates requires bringing in variables from the environment? If so, I
could just replace the jsonval_src template with a global variable for now.
What would you have to do to support using templates in this way?
Am Donnerstag, 8. Januar 2015 02:39:39 UTC-5 schrieb gmhwxi:
This is a VERY tricky issue because this kind of use was not
part of the design. On the other hand, it seems natural to use templates
this way. So …
On Thursday, January 8, 2015 12:59:43 AM UTC-5, gmhwxi wrote:
I have managed to produce this kind of bug using the following simple
code:
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this
small example on github.
I changed the keyword $closurenv to $tempenver as this is only
related to compiling template instances.On Saturday, January 10, 2015 at 2:59:02 AM UTC-5, gmhwxi wrote:
I came up with a fix for this issue.
Basically, the idea is to allow the programmer to indicate to the compiler
that a particular
dynamic variable should be included in the environment of a template
instance. For instance,
implement
main0 (argc, argv) = let
//
val () = $closurenv(argc) // [argc] is put into the environment of the
following instance of [foo]
//
in
… foo<> (…) …
end // end of [main0]
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this
small example on github.
Are mutually recursive templates only an issue when instantiating one of
the templates requires bringing in variables from the environment? If so, I
could just replace the jsonval_src template with a global variable for now.
That should work.
I think that a better way for now is to break the mutual dependency:
implement
{}(tmp)
parse_s2rt (…) = let
fun aux_S2RTfun (…) = (code for parse_S2RTfun)…
in
…
end
implement
{}(tmp)
parse_S2RTfun (…) = … // if you still need it.On Thu, Jan 8, 2015 at 3:12 PM, William Blair < william.dou...@gmail.com> wrote:
Are mutually recursive templates only an issue when instantiating one of
the templates requires bringing in variables from the environment? If so, I
could just replace the jsonval_src template with a global variable for now.
What would you have to do to support using templates in this way?
Am Donnerstag, 8. Januar 2015 02:39:39 UTC-5 schrieb gmhwxi:
This is a VERY tricky issue because this kind of use was not
part of the design. On the other hand, it seems natural to use templates
this way. So …
On Thursday, January 8, 2015 12:59:43 AM UTC-5, gmhwxi wrote:
I have managed to produce this kind of bug using the following simple
code:
On Wednesday, January 7, 2015 10:08:49 PM UTC-5, gmhwxi wrote:
I think I know the cause of this problem, but fixing it requires some
thoughts.
Basically, you used some templates that are defined mutually
recursively:
implement{} f () = g<> ()
implement{} g () = f<> ()
Let me first investigate the issue a bit further.
On Wednesday, January 7, 2015 6:38:38 PM UTC-5, William Blair wrote:
I’m having some trouble compiling code that makes heavy use of
templates. I am using a library that parses JSON into an array of tokens.
Each token refers to a value which can be retrieved from the original JSON
string. I have a template function that returns this string. Before any
information is taken from the tokens, the user must implement this function
with the correct string. This avoids having to set up a global variable or
add parameters to functions. When I try to compile the corresponding C
code, I find many instances of the following error, but only for some
template functions.
parsing_dats.c:86143:186: error: use of undeclared identifier
let val (data, jsv) = jsonval_parse_from_stdin ()
implement
jsonval_src<> () = data
val c3nstrs = jsv["c3nstrbody"]
in
parse_c3nstr (c3nstrs)
end
I made a simpler version that uses the same technique, but the C code
produced by patsopt compiles without any errors. You can find this
small example on github.