This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

change in static modules


I'm considering a change in the implementation of static modules,
and specically in when "module level actions" are performed.  These
are currently done automatically during class initialization.
The change would be to require code that uses a module to call a special
method to execute the top-level actions.  The Kawa compiler
would automatically insert a call to this method for a require,
but it would be change if you depend on module actions being done
when the class is first "accessed" (in the Java sense).

Plan:  a static module would be much more like a non-static module,
except:
* Top-level definitions are translated to static fields, rather than
(mostly) instance fields.
* Scheme functions are implemented using static methods, rather than
(mostly) instance methods.
* There would be a singleton instance accessed in a static field
named something like $instance.  (Having an instance is convenient
because it allows us to use override methods of ModuleBody and Runnable.)
* The class initializer creates an instance of the module, and
assigns it to $instance.
* The top-level actions are executed by (essentially) $instance.run().
* The main method when compiling with --main essentually calls $instance.run(),
as does the code emitted for a require.  We do need a mechanism to ensure
that run is only executed once; this could be a static boolean.

This solves a couple of problems with the current set-up:
* Command-line arguments aren't available in the class initializer.
* Multi-threaded programs may hang if one tread accesses a member
of a class that hasn't finished initializing yet.
* Currently requiring static module doesn't generate any code, which
makes it hard to control "load" order of modules.
* Complications because of differences between static and non-static
modules.

I'm also considering changing the default from the current
(module-static #t) to (module-static #f).  It's probably closer
to what people expect.  For example define-simple-class doesn't
really work except for static modules.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]