Handling noreturn functions

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

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.On Friday, September 12, 2014 1:40:08 PM UTC-4, Shea Levy wrote:

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?

~Shea

On Fri, Sep 12, 2014 at 10:22:57AM -0700, gmhwxi wrote:

It works if you write:

fn foo{b:bool}(b: bool b): int =
if b then 1 else (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 then 1 else (perror “bad value”; exit(1){int})

On Friday, September 12, 2014 1:12:51 PM UTC-4, Shea Levy wrote:

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


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/633a0d8e-6d2a-476a-9727-ad3190a74372%40googlegroups.com.

Perfect!On Fri, Sep 12, 2014 at 12:11:16PM -0700, gmhwxi wrote:

How about

ptr0_get(the_null_ptr)

On Friday, September 12, 2014 3:07:15 PM UTC-4, Shea Levy wrote:

Ah, right. I wonder if something like:

#define FAKE_VAL(ty) *((ty *) NULL)

could be done in ATS?

~Shea

On Fri, Sep 12, 2014 at 10:53:04AM -0700, gmhwxi wrote:

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.

On Friday, September 12, 2014 1:40:08 PM UTC-4, Shea Levy wrote:

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?

~Shea

On Fri, Sep 12, 2014 at 10:22:57AM -0700, gmhwxi wrote:

It works if you write:

fn foo{b:bool}(b: bool b): int =
if b then 1 else (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 then 1 else (perror “bad value”; exit(1){int})

On Friday, September 12, 2014 1:12:51 PM UTC-4, Shea Levy wrote:

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


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit

https://groups.google.com/d/msgid/ats-lang-users/633a0d8e-6d2a-476a-9727-ad3190a74372%40googlegroups.com.


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/0041ef17-fbf3-4fa1-9be7-cf3dd4d59fd8%40googlegroups.com.


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 post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/0fb3ee84-6d02-4a4f-b835-0de39a8db74d%40googlegroups.com.

Ah, right. I wonder if something like:

#define FAKE_VAL(ty) *((ty *) NULL)

could be done in ATS?

~SheaOn Fri, Sep 12, 2014 at 10:53:04AM -0700, gmhwxi wrote:

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.

On Friday, September 12, 2014 1:40:08 PM UTC-4, Shea Levy wrote:

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?

~Shea

On Fri, Sep 12, 2014 at 10:22:57AM -0700, gmhwxi wrote:

It works if you write:

fn foo{b:bool}(b: bool b): int =
if b then 1 else (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 then 1 else (perror “bad value”; exit(1){int})

On Friday, September 12, 2014 1:12:51 PM UTC-4, Shea Levy wrote:

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


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/633a0d8e-6d2a-476a-9727-ad3190a74372%40googlegroups.com.


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 post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/0041ef17-fbf3-4fa1-9be7-cf3dd4d59fd8%40googlegroups.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?

~SheaOn Fri, Sep 12, 2014 at 10:22:57AM -0700, gmhwxi wrote:

It works if you write:

fn foo{b:bool}(b: bool b): int =
if b then 1 else (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 then 1 else (perror “bad value”; exit(1){int})

On Friday, September 12, 2014 1:12:51 PM UTC-4, Shea Levy wrote:

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


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 post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/633a0d8e-6d2a-476a-9727-ad3190a74372%40googlegroups.com.

It works if you write:

fn foo{b:bool}(b: bool b): int =
if b then 1 else (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 then 1 else (perror “bad value”; exit(1){int})On Friday, September 12, 2014 1:12:51 PM UTC-4, Shea Levy wrote:

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

How about

ptr0_get(the_null_ptr)On Friday, September 12, 2014 3:07:15 PM UTC-4, Shea Levy wrote:

Ah, right. I wonder if something like:

#define FAKE_VAL(ty) *((ty *) NULL)

could be done in ATS?

~Shea

On Fri, Sep 12, 2014 at 10:53:04AM -0700, gmhwxi wrote:

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.

On Friday, September 12, 2014 1:40:08 PM UTC-4, Shea Levy wrote:

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?

~Shea

On Fri, Sep 12, 2014 at 10:22:57AM -0700, gmhwxi wrote:

It works if you write:

fn foo{b:bool}(b: bool b): int =
if b then 1 else (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 then 1 else (perror “bad value”; exit(1){int})

On Friday, September 12, 2014 1:12:51 PM UTC-4, Shea Levy wrote:

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


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit

https://groups.google.com/d/msgid/ats-lang-users/633a0d8e-6d2a-476a-9727-ad3190a74372%40googlegroups.com.


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/0041ef17-fbf3-4fa1-9be7-cf3dd4d59fd8%40googlegroups.com.