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

March 6th -- Has it been more than 2 weeks?

 
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: Tue Mar 06, 2007 12:55 pm    Post subject: March 6th -- Has it been more than 2 weeks? Reply with quote

Sure doesn't feel like it.

This changes the instruction and module format. You will have to recompile any compiled modules. For that matter, maybe you'd better hold off on compiling your modules until MiniD reaches a stable version.

Added/Removed
  • Put some unit tests in minid.utils. Found some bugs. Cool.
  • Removed the tablelib .remove() function. This is no longer needed, because you just assign a member to null to remove it from the table.
  • Removed the tablelib .contains() function. Since tables can no longer hold null, this check can be done much more efficiently by indexing the table and seeing if the value is null.
  • Added toInt(), toFloat(), and toChar() to the baselib.
  • Added constant folding to the compiler. This also includes some simple code culling for control statements, i.e. if you write "if(false) {} else {}", only the else clause is compiled. The first part is entirely skipped and doesn't have to pass semantic analysis, and so this works a bit like conditional compilation. This applies to most control statements (most notably not switch statements (yet)).
  • Added a way to call functions and methods with a specific context. Simply specify the context as the first parameter and precede it with the 'with' keyword:

    Code:
    f(with a, 1, 2, 3);
    obj.m(with b);

  • Added fieldsOf() and methodsOf() to the baselib. These allow you to iterate through the fields and methods of classes and class instances with a foreach loop.
  • Added an opApply for namespace types.
  • Added toUpperD and toLowerD to minid.utils, which are for dchar[]s.


Changed
  • MiniD is now licensed under a zlib/libpng-style license.
  • Serialize() and Deserialize() now check to see if structs contain anonymous unions, but only if it has to automatically write them out. Structs with anonymous unions can still be serialized, as long as either (1) they declare SerializeAsChunk or (2) they have custom serialization/deserialization functions.
  • Serialize() and Deserialize() now expect that either you have both custom serialization and deserialization functions or neither.
  • It's now possible to write expressions for case values rather than single constants. Of course, these expressions still have to evaluate to a constant.
  • I took out the makefile since I hate makefiles, and replaced it with four Build response files. They're based on build 3.04.
  • I changed the dsss.conf file to be more up-to-date. I hope I did it right Gregor!
  • Some little optimizations in the interpreter here and there.


Fixed
  • Fixed what has probably been a long-standing and rather insidious bug involving upvalues in the compiler. I was comparing against the wrong indices; local variable definition indices vs. register indices. I changed the way locals were added probably five months ago and never changed the upvalue code along with it.
  • Fixed a bug in MDCL where the first command-line argument was being put into the 'this' for the module-level function instead of the vararg parameter.
  • Fixed a bug with string comparison. Basically the minid.utils.dcmp routine was only comparing a quarter of the strings; I forgot to take the size of dchars into account!
  • Fixed a bug in the compiler that caused an error if a case or default statement came right before the end of the switch statement with no code inside it.


So the big things this time are the new license, constant folding, and calling functions with an arbitrary context. Fun.
Back to top
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Thu Mar 08, 2007 2:34 am    Post subject: Reply with quote

Thanks for your hard work!

since release94, How call a global var in D from miniD script? and function?

at source trunk 93, allow use

Code:

MDValue* sl = state.getGlobal("varName");
writefln (sl.asString());


like we talk about inhttp://dsource.org/forums/viewtopic.php?t=2041
Quote:
OK, yes, that's right. Anything that you want to be accessible from both D code and MiniD code has to be a MiniD global, since locals in MiniD code will disappear.

Now, to access MiniD functions and classes from D, it's just an extension of that.

Say you have the MiniD code:

Code:
function Foo(x, y)
{
writefln("Foo got: ", x, ", ", y);
}


Then, in D, you can access this:

Code:
MDClosure cl = new MDClosure(state, compileFile(`simple.md`));

// This is required so that the function gets set as a global.
state.easyCall(cl, 0u);

MDClosure func = state.getGlobal("Foo").asFunction();
state.easyCall(func, 0u, 3, 4);


This will output:

Code:
Foo got: 3, 4


Notice that you have to execute the loaded file in order for the function "Foo" to be set as a global. Then you can just get the global and call it with state.easyCall().

As for MiniD classes in D.. I plan on really changing how classes and instances are created very soon, so if I documented how to use them, it might be outdated in a couple weeks.

Lastly, I plan on working on a binding library which should make it much easier to use MiniD code from D and to expose D functions and classes to MiniD. So a lot of this might become obsolete as well

________
Honda Phantom


Last edited by ideage on Wed Feb 02, 2011 5:06 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: Fri Mar 09, 2007 9:01 am    Post subject: Reply with quote

Globals have been moved from MDState to MDGlobalState. So to access a global from D code, you use:

Code:
MDValue* sl = MDGlobalState().getGlobal("varName");
writefln (sl.asString());


However, keep in mind that when you declare a global in MiniD, it's put into the module's namespace. So:

Code:
module test;

global varName = "hi";


Means that varName is actually test.varName. So to access this from D code, you write:

Code:
MDValue* sl = MDGlobalState().getGlobal("test").asNamespace()["varName"];


If you want to make a REAL global in MiniD, you can use the _G variable to declare it:

Code:
_G.varName = "hi";


Then you can access that with:

Code:
MDValue* sl = MDGlobalState().getGlobal("varName");


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



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Sat Mar 10, 2007 10:29 pm    Post subject: Reply with quote

Oh,I see.Thank you! Smile

I write a method, use dot split string. it easy understand,easy use.

char[] val = Value("test.varName");

Code:
char[] Value(char[] name)
   {
      //name = test.tv
      char[][] parts = string.split(name, ".");
      if(parts.length==1)
      {
         dchar[] ev = std.utf.toUTF32(name);   
         MDValue* sl = MDGlobalState().getGlobal(ev);
         return sl.asString().asUTF8();
      }
      if(parts.length==2)
      {
         dchar[] fn = std.utf.toUTF32(parts[0]);   
         dchar[] ev = std.utf.toUTF32(parts[1]);
         MDValue* sl = MDGlobalState().getGlobal(fn).asNamespace()[ev];
         return sl.asString().asUTF8();
      }      
      return "";
   }


can getGlobal direct to do it?
________
digital vaporizer


Last edited by ideage on Wed Feb 02, 2011 5:07 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: Sun Mar 11, 2007 8:08 am    Post subject: Reply with quote

That's a good idea Smile I plan on really cleaning up the API and adding a lot more useful stuff to it for the next update. This should be one of them!
Back to top
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Sun Mar 11, 2007 8:51 pm    Post subject: Reply with quote

Very Happy ,Thank you hard work!!! some idea to MiniD !!! The code will help Host easy to Access MiniD and Extend MiniD.


Code:
//reg Global function
   void regDFunciton(char[] funName,int delegate(MDState s) dg)
   {
      dchar[] ev = std.utf.toUTF32(funName);
      MDGlobalState().setGlobal(ev, MDGlobalState().newClosure(dg,ev));
   }
   
   //run a Minid Method
   void Run(T...)(char[] methodname,T params)
   {
      char[][] parts = string.split(methodname, ".");
      dchar[] fn = std.utf.toUTF32(parts[0]);   
      dchar[] ev = std.utf.toUTF32(parts[1]);
      MDValue* sl = MDGlobalState().getGlobal(fn).asNamespace()[ev];
         MDClosure  mf = sl.asFunction();
      assert(mf);
         state.easyCall( mf, 0,MDValue(MDGlobalState().globals),params);
      
   }

________
Daihatsu Leeza
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