[Omake] allowing for lazy extends?

Erick Tryzelaar erickt at dslextreme.com
Fri Jan 26 03:09:10 PST 2007


This is vaguely related to the following bugs 582 and 583, but for 
0.9.8. Do you think it would be possible to allow lazy extensions of 
objects? I'm not sure how objects are currently implemented, but if it 
is the classic "if a field doesn't exist in the current object, check 
the parent", it may be comparatively easy to implement because instead 
of storing a pointer to the parent object, you just store the name and 
then look up the object dynamically. This would then allow for a 
structure like this:

X. =
    x = 1
Y. =
    extends $`X
X. +=
    y = 2

echo $(Y.y) # prints out 2, not "unbound method"

Normal extension, like this:

X. =
    x = 1
Y. =
    extends $X
X. +=
    y = 2

echo $(Y.y) # errors out with "unbound method"

Finally, with sections:

X. =
    x = 1
Y. =
    extends $`X
section
    X. +=
        y = 2
    echo $(Y.y) # prints out 2

echo $(Y.y) # errors out with "unbound method"
   

I believe this would fit in pretty orthogonally with the rest of the 
object system. It also shouldn't violate the purity of the object 
system, as it's just doing dynamic lookup. This would be a big win for 
building module build systems. The system I want to do is to have a base 
file describing common functions, and then have another set of files 
depending on the compiler. So, something like this:


file1.om:
EXECUTABLE. =
    exe =
    comflags(target, sources) =
    com(target, sources) = ...
    make-rule(target, sources) =
       $(target): $(sources)
          $(com $(target), $(sources))
      
C. =
    extends $`(EXECUTABLE)
    make-rule(target, sources) =
       $(target): $(sources) :scanner: scan-c-$(sources)
          $(com $(target), $(sources))

CXX. =
    extends $`(C)
    make-rule(target, sources) =
       $(target): $(sources) :scanner: scan-cxx-$(sources)
          $(com $(target), $(sources))


posix.om:
C. +=
    exe = gcc
    ...

CXX. +=
    exe = g++
    ...


msvc.om:
C. +=
    exe = cl.exe
    ...


Without it, I run into all sorts of issues because "extends" forces 
evaluation, even if it's a lazy variable. So I have to do all sorts of 
hacks in order to avoid extending things until the last possible moment.

-e


More information about the Omake mailing list