Changes by: Jason Hickey (jyh at cs.caltech.edu)
Date: 2005-07-05 20:02:55 -0700 (Tue, 05 Jul 2005)
Revision: 1189
Log message:
Continuing with experimenting with scoping. This compiles and surely
doesn't work.
Here is the current model.
- Kinds of variables:
private : local to an object/file, statically scoped.
protected : object fields, dynamically scoped.
public : class fields, dynamically scoped.
By default, variable definitions are protected.
- Directives:
include <file> : include the file as if it were inlined in
the current environment; you get public and protected
variables, but not private.
open <file> : include at-most-once, in the Pervasives
environment, you get only the public variables,
the variables are *not* part of the current object.
extends <file-or-object> : the usual inheritance directive,
like open, but protected variables become part of the
current object.
import <file-or-object> : just get the file object.
The <file> and <file-or-objects> do not have to be a constant.
Linking is performed right afterwards.
If the <file> is a constant, it defines an object
of that name. For example,
open build/C
will open the <OMAKEPATH>/build/C file, and it will also define the
"C" variable. If the filename is not a constant, this doesn't
happen.
Implementation:
- There is a link step following an include/open/extends.
Variables are references(!) that are set during the link step.
It is only the variable names; the language remains functional.
- Public variables are class variables. This has little impact
since the language is functional, but it does mean that some
aliasing happens.
X. =
public.foo = 1
open $(X)
Y = $(X)
foo = 2 # This is the X.foo field
println($(Y.foo)) # Prints "2"
This would not be true for protected variables, but "open"
has no effect on protected variables.
X. =
protected.foo = 1
open $(X)
Y = $(X)
foo = 2 # This is not the X.foo field
println($(X.foo)) # Prints "1"
println($(Y.foo)) # Prints "1"
- Every object gets a public section for all its public vars.