env-ref semantics

32 views
Skip to first unread message

Lucas Paul

unread,
Apr 24, 2013, 6:26:03 PM4/24/13
to utah-compiler...@googlegroups.com
I'm not sure I understand env-ref fully. In the spec, its grammar is listed as

(env-ref <name> <aexp> <field-name>)

and pycc on Caprica produces calls like this:

(env-ref $env_t19 $env k18)

Aren't the first two arguments here referring to the same thing? $env is an argument to the lambda part of the closure, and $env_t19 is the name we're giving that environment in the make-env part of the closure. Why does the env-ref need both?

Petey A

unread,
Apr 24, 2013, 8:07:40 PM4/24/13
to Lucas Paul, utah-compilers-spring-2013
From an email during the semester I took the class (with minor edits):

<blockquote>
For (define-env name (field ...)), you're defining a C struct with fields "field ..."

For (env-ref name exp field), you're accessing the field "field" in a C struct with type "name".

For (make-env name (fieldname fieldval) ...), you're creating a struct of type "name" and initializing each field accordingly.
</blockquote>

Please let me know if that doesn't clear it up.


- Petey


--
You received this message because you are subscribed to the Google Groups "Utah Compilers, Spring 2013" group.
To unsubscribe from this group and stop receiving emails from it, send an email to utah-compilers-spri...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Petey A

unread,
Apr 24, 2013, 8:08:01 PM4/24/13
to Lucas Paul, utah-compilers-spring-2013
Sorry - I was hoping that gmail would format my blockquote. Oh, well.


- Petey

cam

unread,
Apr 24, 2013, 10:22:02 PM4/24/13
to utah-compiler...@googlegroups.com
Here's an example to go along with Petey's explanation to show that the reason for two $env vars in env-ref is for casting the pointer to the environment.
Each lambda takes a void pointer to an env that needs to be cast.
$env_95 is the type of the environment (for casting in c code from void *).
$env is the parameter to the lambda that needs to be cast from a void * to a $env_95 *.

CLOSURE CONVERTED:
(env-ref $env95 $env someField)

C:
...
struct __$env_95 {
val_t __someField ;
};
...
void __$lambda43(void* __$env, val_t __c, val_t __k18) {
...
/*cast the env param to the right type of environment in order to access the appropriate field*/
(((__$env_95* )__$env)->__someField
...
}

Lucas Paul

unread,
Apr 24, 2013, 10:45:05 PM4/24/13
to utah-compiler...@googlegroups.com, thatskinn...@gmail.com
What about app*? What does that do?

Petey A

unread,
Apr 24, 2013, 11:32:28 PM4/24/13
to Lucas Paul, utah-compilers-spring-2013
I think, but am not sure, that app* applies the first expression to the rest of them.


- Petey


On Wed, Apr 24, 2013 at 8:45 PM, Lucas Paul <reili...@gmail.com> wrote:
What about app*? What does that do?

Petey A

unread,
Apr 24, 2013, 11:41:50 PM4/24/13
to Lucas Paul, utah-compilers-spring-2013
To follow up, all of my computers except my work laptop have killed themselves this semester (it's been a little rough) and I've been waiting until it ended to replace them. I have backups of my files, but they're buried deep and I'd rather not take the time.

That said, if you need an answer, I'll find it. Just let me know.


- Petey

Lucas Paul

unread,
Apr 24, 2013, 11:57:28 PM4/24/13
to utah-compiler...@googlegroups.com, Lucas Paul, thatskinn...@gmail.com
I'm just trying to understand why app* is there. It's getting used in the reference pycc, but I'm not understanding what it does or why. I get env-ref now, btw. Thanks.

Petey A

unread,
Apr 25, 2013, 12:11:23 AM4/25/13
to Lucas Paul, utah-compilers-spring-2013
It's in the closure conversion step, so it probably is applying arguments to a closure (a function paired with an environment). In the past, lambdas were applied directly to their arguments without the environment being explicitly paired. But after closure conversion, lexical scoping is made explicit in the closures. That way, lambda lifting is no more than moving closures to the top level and replacing them with references.


- Petey


Reply all
Reply to author
Forward
0 new messages