[Wheat-developer] XML Media: build objects then mount, or mount then build?
Status: Pre-Alpha
Brought to you by:
mark_lentczner
From: Jim K. <ki...@pa...> - 2005-05-10 05:42:47
|
I'm working on trying to get relative pathnames to work in prototype declarations. It seems to work fine for wheatscript. However, XML Media operates differently. In util/testutil.cpp, Setup::Setup first builds up a bunch of objects, and only then calls NameSpace::mount (I'm thinking the non-test version operates similarly but don't remember for sure whether I looked at that case). What I need instead is to create an empty root object, call NameSpace::mount on it, and only then start building objects inside it. Are there problems with this approach? Is it considered desirable that an object tree in memory can be remounted without changing the objects therein? Index: root/library/compiler.ws =================================================================== RCS file: /cvsroot/wheat/r1/root/library/compiler.ws,v retrieving revision 1.1 diff -u -r1.1 compiler.ws --- root/library/compiler.ws 5 May 2005 17:42:25 -0000 1.1 +++ root/library/compiler.ws 10 May 2005 05:35:44 -0000 @@ -71,4 +71,22 @@ #assert-error("system/vm/exception/not-found(++)", error); } + point2d: { x: 5; y: 6 } +`` absolute: { :'/library/compiler/tests/point2d': } + relative: { :point2d: } + + test-prototype(): { + point2d := $point2d.absolute-path.as-string; +`` #assert-equals(point2d, $absolute.prototype().as-string); + #assert-equals(point2d, $relative.prototype().as-string); + copy := $relative; + #assert-equals(point2d, copy.prototype().as-string); + } + + test-inheritance(): { + #assert-equals(5, $relative.x); + copy := $relative; + #assert-equals(5, copy.x); + } + } Index: wheat/memobject.cpp =================================================================== RCS file: /cvsroot/wheat/r1/wheat/memobject.cpp,v retrieving revision 1.17 diff -u -r1.17 memobject.cpp --- wheat/memobject.cpp 18 Feb 2005 16:10:40 -0000 1.17 +++ wheat/memobject.cpp 10 May 2005 05:35:46 -0000 @@ -12,6 +12,8 @@ #include "media.hpp" +#include <iostream> // TEMPORARY, for debugging + using namespace Wheat; namespace { @@ -358,8 +360,21 @@ clearValue(v); MemoryObject* m = new MemoryObject; - m->prototype = - prototype.isEmpty() ? standardPrototype(TypeObject) : prototype; + + if (prototype.isEmpty()) { + m->prototype = standardPrototype(TypeObject); + } + else { + Path base = NameSpace::pathTo(p.container()); + Path absolute(base, prototype); + if (prototype.isRelative()) { + std::cout << "relative path " << prototype.debugName() << + " absolutified to \n" << + " " << absolute.debugName() << "\n"; + } + m->prototype = absolute; + } + m->capacity = 0; m->keySize = 0; m->arraySize = 0; |