View previous topic :: View next topic |
Author |
Message |
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Sun May 27, 2007 3:15 pm Post subject: May 27 -- Import/module loading changes, namespace syntaxes |
|
|
Added/Removed
- MDCL now looks up module names specified on the command line a bit better.
- MDCL now has an -I flag to add module import paths. This also affects module lookup for any command-line module names.
- Added namespace declarations and literals. Been meaning to do that for a while.
- Functions now have an environment function that you can use to get and set the function's environment (where it starts looking up globals).
- New MDValue.canCastTo!(T) function.
- New baselib function setModuleLoader().
Changed
- Changed the grammar very slightly to allow underscores directly after the 0x, 0b, 0c, decimal point and exponent 'e' in numeric literals. Also 0X, 0B, and 0C are now legal.
- Imports are no longer restricted to top-level use. You may place them anywhere a normal statement may occur. This also means that you can use imports in MDCL.
- Imports now also accept any expression as the import name by writing "import(expr)". This replaces the baselib "require" function. It also allows a list of "selective" imports, like the regular import statement.
- The MDGlobalState().globals property is no longer just an MDNamespace. It's a struct that has opIndex and opIndexAssign overloaded, making it easier to set and get globals (i.e. MDGlobalState().globals["x"] = 5; ) You can still retrieve the global namespace by using "MDGlobalState().globals.ns". If you want to get a global, you can either use the indexing operator, or you can use .globals.get!(type)(name) to make sure it's a particular type.
- The import stuff has been moved out of minid.minid.MDFileLoader and into MDGlobalState. It was really only in MDFileLoader to avoid a circular dependency between minid.compiler and minid.types.
- Furthermore, the module loading system has been changed. The process is explained below.
- Circular imports are no longer allowed.
- The dynamic library loading is there, but not really functional for a few reasons (none of which can really be fixed). DLLs + D = bad. So all the .brf files define the version MDNoDynLibs, and I recommend you do the same for any projects which depend on MiniD.
- Got the lib.brf up-to-date.
- The baselib fieldsOf() and methodsOf() functions now return a namespace instead of an iterator. This doesn't change when you iterate over the fields or methods of a class or instance with foreach, but it now allows you to just get at the namespace.
- MDState.getParam now allows any type, and will call .to!() on the parameter if it doesn't match any of the known types.
- MDValue .as!() and .to!() no longer implicitly cast floats to ints.
- Concatenation and concatenation assignment for arrays optimized for when there's only one element to concatenate.
Fixed
- Fixed op= parsing; you can now have conditional (?: ) expressions on the RHS of op= expressions.
- A few assertions in minid.types did stuff like "assert(objReference)", which calls the object invariant rather than seeing that it's non-null.
- MDState.getParam was broken for namespace params.
The biggest thing this update is that the importing and module loading system has changed. Gone is the MDFileLoader class, as well as the old module loader system. Additionally the baselib require() function has been replaced by the new import() syntax.
The new module loading behavior is as follows, and happens whenever you use an import statement.
- The name is looked up in the list of already-loaded modules. If it's already been loaded, the process stops here.
- It checks for circular imports. These are no longer legal.
- It goes through the list of registered module loaders, searching for one that has been registered for this module name. If it finds one, it calls that function with the name of the module to load and a namespace to load the symbols into.
- If there is no registered loader, it attempts to load the module from a .md or .mdm file. This behavior hasn't really changed from before.
- Optional: it tries to load the module from a dynamic library. This does not work right now.
That last point is kind of disappointing (see the Dynamic Library Loading Status thread for why).
For an example on how to register and use a module loader (step 3), see samples/simple.md at the top.
This release is also likely to be the last all-phobos release. MiniD will be being migrated slowly over to Tango; through tangobos at first, and then probably more Tango from there. |
|
Back to top |
|
|
ideage
Joined: 12 Jul 2006 Posts: 63 Location: china
|
Posted: Tue Jun 05, 2007 9:31 pm Post subject: |
|
|
when access globals,display compile error:
Code: | MDValue.opAssign() - Invalid argument type '_Globals '
..\minid\types.d(873): Error: undefined identifier ARGUMENT_ERROR
..\minid\types.d(873): Error: function expected before (), not ARGUMENT_ERROR of
type int
..\minid\types.d(251): template instance minid.types.MDValue.opAssign!(_Globals
) error instantiating |
please help me? Thanks!
________
los angeles dispensary
Last edited by ideage on Wed Feb 02, 2011 5:08 pm; edited 1 time in total |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Wed Jun 06, 2007 7:15 am Post subject: |
|
|
You're probably doing something like:
MDValue val = MDGlobalState().globals;
But .globals is no longer an MDNamespace, it's a structure. So to get the global namespace, use:
MDValue val = MDGlobalState().globals.ns;
|
|
Back to top |
|
|
ideage
Joined: 12 Jul 2006 Posts: 63 Location: china
|
Posted: Wed Jun 06, 2007 7:10 pm Post subject: |
|
|
Yeah
Code: | state.easyCall( mf, 0,MDValue(MDGlobalState().globals),params); |
Thanks!
________
Toyota Curren
Last edited by ideage on Wed Feb 02, 2011 5:08 pm; edited 1 time in total |
|
Back to top |
|
|
ideage
Joined: 12 Jul 2006 Posts: 63 Location: china
|
Posted: Mon Jun 11, 2007 7:19 pm Post subject: |
|
|
.globals.get!(type)(name) ERROR!
Code: | module test;
import std.stdio;
import std.stream;
import std.string;
import std.traits;
import minid.minid;
void main()
{
try
{
MDState s = MDInitialize();
MDGlobalState().addImportPath(`samples`);
MDGlobalState().importModule("arrays");
MDNamespace mn = MDGlobalState().globals.get!(MDNamespace)("arrays"d);
}
catch(MDException e)
{
writefln("Error: ", e);
writefln(MDState.getTracebackString());
}
catch(Object e)
{
writefln("Bad error: ", e);
writefln(MDState.getTracebackString());
}
} |
________
vaporizer wholesaler
Last edited by ideage on Wed Feb 02, 2011 5:08 pm; edited 1 time in total |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Jun 11, 2007 9:47 pm Post subject: |
|
|
I don't get any error, but I'm using the newest version. I don't think I changed anything with that though. What error do you get? |
|
Back to top |
|
|
ideage
Joined: 12 Jul 2006 Posts: 63 Location: china
|
Posted: Mon Jun 11, 2007 10:51 pm Post subject: |
|
|
I use 175 version and phobos. dmd1.014,xp sp2.
it return:
Code: | D:\D\dmd\import\minid>test
oki doki
Bad error: Access Violation |
________
magic flight
Last edited by ideage on Wed Feb 02, 2011 5:08 pm; edited 1 time in total |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Tue Jun 12, 2007 6:05 am Post subject: |
|
|
I just tried that now (revision 175, DMD 1.014) and I don't get an access violation.
Try upgrading DMD to 1.015, or try re-checking out MiniD. Maybe something just got messed up. |
|
Back to top |
|
|
ideage
Joined: 12 Jul 2006 Posts: 63 Location: china
|
Posted: Tue Jun 12, 2007 7:06 am Post subject: |
|
|
ah,it's OK!
Thanks!
I lose -version=MDNoDynLibs !
________
Triumph Speedmaster |
|
Back to top |
|
|
|