Implementing a function in a macro?

Hi all,

Is it possible to define a macro that implements another function? I’m trying to write a macro that lets you define a “main” function that takes argc and argv as expected, but also takes views for things like “you have a readable file descriptor at int 0” and “errno is unset” to represent “global” process state that can be changed and tracked linearly. Currently, I have this, which is failing to compile:

(* Set a given function to be the POSIX entry point

  • This is equivalent to implementing main as the passed in function,
  • except that in addition to argc and argv views corresponding to initial
  • global program state in the POSIX environment are passed.
  • Currently, an errno_v ( free ) proof is passed. In the future, proofs
  • corresponding to open file descriptors for stdin, stdout, and stderr will
  • be passed as well
    *)
    macdef set_posix_entrypoint ( func ) =
    implement main ( argc, argv ) = let
    extern praxi { v: view } __assert_view (): v
    prval ev = __assert_view < errno_v ( free ) > ()
    val res = ,(func) ( ev | argc, argv )
    extern praxi { v: view } __unassert_view ( x: v ): ()
    prval () = __unassert_view ( ev )
    in res end

I get many errors, but the first one is:

481(line=12, offs=3) – 490(line=12, offs=12): error(parsing): the syntactic entity [d0exp] is needed.

(the line and offsets refer to the word “implement” above). It’s unclear to me how to continue, sorry for my ignorance!

Thanks,
Shea

Ah ha, I see, thank you.> On Mar 12, 2015, at 12:17 PM, gmhwxi gmh...@gmail.com wrote:

macdef expects a dynamic expression on the right-hand side of ‘=’;
‘implement’ introduces a declaration. So there is a mismatch here.

Anyways, I feel that ‘macdef’ is not really meant for this kind of heavy lifting.
Maybe you could implement set_posix_entrypoint in PHP.

On Thursday, March 12, 2015 at 11:03:25 AM UTC-4, Shea Levy wrote:
Hi all,

Is it possible to define a macro that implements another function? I’m trying to write a macro that lets you define a “main” function that takes argc and argv as expected, but also takes views for things like “you have a readable file descriptor at int 0” and “errno is unset” to represent “global” process state that can be changed and tracked linearly. Currently, I have this, which is failing to compile:

(* Set a given function to be the POSIX entry point
*

  • This is equivalent to implementing main as the passed in function,
  • except that in addition to argc and argv views corresponding to initial
  • global program state in the POSIX environment are passed.
  • Currently, an errno_v ( free ) proof is passed. In the future, proofs
  • corresponding to open file descriptors for stdin, stdout, and stderr will
  • be passed as well
    *)
    macdef set_posix_entrypoint ( func ) =
    implement main ( argc, argv ) = let
    extern praxi { v: view } __assert_view (): v
    prval ev = __assert_view < errno_v ( free ) > ()
    val res = ,(func) ( ev | argc, argv )
    extern praxi { v: view } __unassert_view ( x: v ): ()
    prval () = __unassert_view ( ev )
    in res end

I get many errors, but the first one is:

481(line=12, offs=3) – 490(line=12, offs=12): error(parsing): the syntactic entity [d0exp] is needed.

(the line and offsets refer to the word “implement” above). It’s unclear to me how to continue, sorry for my ignorance!

Thanks,
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 mailto:ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com mailto:ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users 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/64f5bf90-3407-4c11-88fa-6d91dc9c8757%40googlegroups.com https://groups.google.com/d/msgid/ats-lang-users/64f5bf90-3407-4c11-88fa-6d91dc9c8757%40googlegroups.com?utm_medium=email&utm_source=footer.

macdef expects a dynamic expression on the right-hand side of ‘=’;
‘implement’ introduces a declaration. So there is a mismatch here.

Anyways, I feel that ‘macdef’ is not really meant for this kind of heavy
lifting.
Maybe you could implement set_posix_entrypoint in PHP.On Thursday, March 12, 2015 at 11:03:25 AM UTC-4, Shea Levy wrote:

Hi all,

Is it possible to define a macro that implements another function? I’m
trying to write a macro that lets you define a “main” function that takes
argc and argv as expected, but also takes views for things like “you have a
readable file descriptor at int 0” and “errno is unset” to represent
“global” process state that can be changed and tracked linearly. Currently,
I have this, which is failing to compile:

(* Set a given function to be the POSIX entry point
*

  • This is equivalent to implementing main as the passed in function,
  • except that in addition to argc and argv views corresponding to initial
  • global program state in the POSIX environment are passed.
  • Currently, an errno_v ( free ) proof is passed. In the future, proofs
  • corresponding to open file descriptors for stdin, stdout, and stderr
    will
  • be passed as well
    *)
    macdef set_posix_entrypoint ( func ) =
    implement main ( argc, argv ) = let
    extern praxi { v: view } __assert_view (): v
    prval ev = __assert_view < errno_v ( free ) > ()
    val res = ,(func) ( ev | argc, argv )
    extern praxi { v: view } __unassert_view ( x: v ): ()
    prval () = __unassert_view ( ev )
    in res end

I get many errors, but the first one is:

481(line=12, offs=3) – 490(line=12, offs=12): error(parsing): the
syntactic entity [d0exp] is needed.

(the line and offsets refer to the word “implement” above). It’s unclear
to me how to continue, sorry for my ignorance!

Thanks,
Shea