Implementing a function in a macro?

27 views
Skip to first unread message

Shea Levy

unread,
Mar 12, 2015, 11:03:25 AM3/12/15
to ats-lan...@googlegroups.com
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

gmhwxi

unread,
Mar 12, 2015, 12:17:02 PM3/12/15
to ats-lan...@googlegroups.com

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.

Shea Levy

unread,
Mar 12, 2015, 5:00:19 PM3/12/15
to ats-lan...@googlegroups.com
Ah ha, I see, thank you.

--
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/64f5bf90-3407-4c11-88fa-6d91dc9c8757%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages