You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ats-lan...@googlegroups.com
Hi all,
Some functions (like C's exit(3) or longjmp(3)) never return. Is there a
way to mark them as such in ATS so that a non-void function can call
them without having to construct a fake value to return after the call?
e.g. is there some way I can write:
> fn foo(bool b): int = if b then 1 else perror "bad value"; exit(1)
without sequencing the exit with some constructed value that I know will
never actually be returned?
~Shea
gmhwxi
unread,
Sep 12, 2014, 1:22:57 PM9/12/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ats-lan...@googlegroups.com
It works if you write:
fn foo{b:bool}(b:bool b):int= if b then1else(perror "bad value";exit(1))
For any type T, exit(1){T} is considered by the typechecker a value of the type T. So you can write:
fn foo{b:bool}(b:bool b):int= if b then1else(perror "bad value";exit(1){int})
Shea Levy
unread,
Sep 12, 2014, 1:40:08 PM9/12/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ats-lan...@googlegroups.com
Ah ha! I see that's implemented by making exit a template and
implementing it as a macro. My attempt to implement something similar
with an infinte loop failed:
> fun loop (): {a: t@ype}(a) = loop ()
> implement main () = loop ()
Gives:
> test_dats.c:119:1: error: ‘loop_0’ declared as function returning an array
during c compilation. Do I have to resort to a macro/function in C here?
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ats-lan...@googlegroups.com
Notice that the size of the type T = {a:t@ype}(a) is unknown, so the compiler cannot generate proper C code for 'loop' (it is no problem to generate JavaScript code, though). So you need a special way to implement such a function for use in C.
Shea Levy
unread,
Sep 12, 2014, 3:07:15 PM9/12/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message