FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

May 27 -- Import/module loading changes, namespace syntaxes

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Sun May 27, 2007 3:15 pm    Post subject: May 27 -- Import/module loading changes, namespace syntaxes Reply with quote

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.

  1. The name is looked up in the list of already-loaded modules. If it's already been loaded, the process stops here.
  2. It checks for circular imports. These are no longer legal.
  3. 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.
  4. 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.
  5. 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
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Tue Jun 05, 2007 9:31 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Wed Jun 06, 2007 7:15 am    Post subject: Reply with quote

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;

Smile
Back to top
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Wed Jun 06, 2007 7:10 pm    Post subject: Reply with quote

Yeah Smile

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
View user's profile Send private message Send e-mail
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Mon Jun 11, 2007 7:19 pm    Post subject: Reply with quote

.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
View user's profile Send private message Send e-mail
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Mon Jun 11, 2007 9:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Mon Jun 11, 2007 10:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Tue Jun 12, 2007 6:05 am    Post subject: Reply with quote

I just tried that now (revision 175, DMD 1.014) and I don't get an access violation. Confused

Try upgrading DMD to 1.015, or try re-checking out MiniD. Maybe something just got messed up.
Back to top
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Tue Jun 12, 2007 7:06 am    Post subject: Reply with quote

ah,it's OK! Smile Smile

Thanks!

I lose -version=MDNoDynLibs ! Embarassed
________
Triumph Speedmaster
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group