[Mono-list] Embedding mono

A Rafael D Teixeira rafael.teixeirabr@terra.com.br
Tue, 22 Jun 2004 11:10:45 -0300


Inline
On Fri, 2004-06-18 at 23:34, Jonathan Pryor wrote:
> On Fri, 2004-06-18 at 16:08, Joe Ante wrote:
> > > It should be possible to load assemblies on demand.
> > Ok so how exactly does this work?
> > 
> > Say I have two .cs files. One calls a function in the other .cs file.
> > Obviously just compiling the two .cs files seperately in two different
> > .dll's gives me a compile error for the .cs file that tries to use the other
> > .cs file.
> 
> Circular dependencies are notoriously complicated in a statically typed
> environment.  The simple answer would be to put both .cs files into the
> same assembly, but this isn't apparently what you want to do.
> 
> Paolo could answer this better, but I would imagine that assemblies are
> demand-paged from disk -- only the parts of the assembly that you
> actually use are loaded, so I don't see any reason to not put everything
> into the same assembly.

Yes, as calling the compiler has always a measurable initializing cost,
I would go further and suggest to compile all the scripts as single
source, every time. The question here is how big will your scripts be?
See below

> > So is there some kind of import/include mechanism?
> 
> I'm not sure what you mean by import/include, but I imagine it's related
> to your questions below, so hopefully my answers below will help.

Yes, it's called a reference to an external assembly, but you can mess
with it, it is internal to the compiler mechanism.

> > The problem I am trying to solve is:
> > 
> > We have a game creation tool which includes a text editor to change scripts
> > (At the moment using python). Python has a import function, which is
> > necessary if you want to use a class that is defined in another script file.
> > We intercepted the import function and returned it the correct python script
> > and built a dependency tree. When the user saves a pythonscript we recompile
> > all pythonscripts that import the script the user has changed.
> > It is very important for us that saving/recompiling is immediate (less than
> > half a second).

If your scripts total some thousands of lines it is possible to
recompile them fast (but particularly the startup time for any compiler
may be more than half a second even on fast machines.

The important thing is: recompiling things means no instances can be
kept running around, everything will have to be restarted afterwards. Is
that true for your engine? Jon seems to believe it is not, from what you
can read below, but that is not a safe thing to do.

> > So whats the best way to do that?
> 
> It sounds like you want a highly dynamic environment, in which existing
> code can be changed at runtime, with older code silently invoking newer
> code.
> 
> I don't believe it's possible, or at least easily possible, to do this
> in C#.  This sounds more like something System.Reflection.Emit and a
> custom compiler would be useful for.  That way, you could ensure fast
> compile time, and you could come up with a custom way for pre-existing
> code to invoke newer code without requiring recompilation (interfaces
> might be good for this).

> I would suggest looking into IronPython, which is a Python
> implementation for .NET.  This may be an easier migration path for you,
> assuming you can actually get your hands on it (it's currently a
> "unreleased research prototype", but the author might be willing to
> help; I have no idea...).

As Rodrigo has pointed out in another email, now there is his new
language: Boo a statically-typed Python-lookalike. It's a very
interesting language and the compiler is a configurable pipeline, where
you can plug your own pieces to augment or personalize it. More:
probably it could be kept loaded as a library instead of as an
executable to help you with the initialization time. That is also
possible but not easily done with mcs/mbas code.

Hope it helps,

-- 
Rafael "Monoman" Teixeira 
Mono Hacker since 16 Jul 2001 - http://www.go-mono.org/
Mono Brasil Founding Member - http://monobrasil.redesolbrasil.org/
English Blog: http://monoblog.blogspot.com/
Brazilian Portuguese Blog: http://monoblog.weblogger.terra.com.br/