• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

#1Lioirc  Members

Posted 08 September 2004 - 10:43 AM

Hi I was implementing the constructor arguments feature this morning, but i dont see a good way of declaring the arguments for the constructor on the script, as simply doing this "CObject obj(REG_TYPE) will not work, to support this way requires a lot of changes in the parser as the functions will be recognized as globalvars because of the open paranthesis, so it will need to store the var type and compare to a registered type for declaring it as a global var, anyway, alot So the question is how you want (or how its a good way to do it in a script language, im a little c++ biased) the arguments to be declared in the script? a keyword? probably an assigment with the arguments enclosed in paranthesis ? a _(agrs) probably ? or CObject obj { type_reg } or a CObject obj TYPE reg_type or what ? Hope WitchLord can take a look at the jit compiler source that i posted in another thread soon WhitchLord, are interested in tutorials for your library? Well, i have continue testing these scripting libraries with my framework best regards Lioric

#2Deyja  Members

Posted 08 September 2004 - 10:57 AM

Perhaps a better route should be to mimic the string-factory mechanism?

You could register a global function as a 'typefactory'. In C++, this function looks like "type CreateType(type*,...)". Within the angelscript compiler, parse statements such as "type identifier(...)" into a call to CreateType, passing the proper pointer of course.

If this mechanism is also used for implicit type conversion, it can replace the StringFactory mechanism completely. If a function expects a string, and you pass a const char*(string literal) the compiler can look and see if there is a registered factory for string that takes a const char*. This is exactly what the StringFactory does, except it's looking at the destination type and not the source type.

#3Deyja  Members

Posted 08 September 2004 - 11:10 AM

Re-reading your post, I've noticed that you said the AngelScript compiler can't tell the difference between a function declaration and a constructor-call. Obviously C++ compilers can, so there must be a way to tell!

If it apears within a function, it can't be a function.
If the return-type is a built-in primitive, it can't be a variable.
If any argument lacks a type specifier, it should be treated as a variable - it will cause errors if it's a function, especially when someone tries to call it.

There is one extreme case.

Type var(Type arg1, Type arg2);

Is that a function declaration or a variable constructed from two default constructed arguments?
If any arg has it's own constructor arguments, it must be a variable.
If AngelScript doesn't need forward function declaration (I haven't checked... but if not, it shouldn't support it at all) then it must be a variable.
If it's followed by {} instead of a semi-colon, it must be a function.

Perfectly understandable if you don't want to dive in and implement all that. I'm already just doing Type obj = Factory(...) myself. A simple prefix to the argument list, though ugly, is good enough for now. A syntax like Type obj = (argument list) or Type obj : (argument list) is good. The colon is used in C++ for initializer lists, so it almost makes sense like that in AngelScript. :D!

#4Lioirc  Members

Posted 08 September 2004 - 11:32 AM

Deyja wrote :
///////////////////////////////////////
If it apears within a function, it can't be a function.
///////////////////////////////////////
void func(void) {
CObject obj(1);
CObject getObject(1);
}

obj is a Object constructor and getObjec is a function, so if it appears within a function, it can be a function, can you tell the difference just parsing the text?, we need to make extra token compares to find which is what, and that is what i dont want to do it (i dont have time)

Deyja wrote :
///////////////////////////////////////
If any argument lacks a type specifier, it should be treated as a variable - it will cause errors if it's a function, especially when someone tries to
///////////////////////////////////////

the same, see above.

I like the CObject obj : (args) syntax, what others think about it?

Lioric

#5Deyja  Members

Posted 08 September 2004 - 12:31 PM

Quote:
 obj is a Object constructor and getObjec is a function, so if it appears within a function, it can be a function, can you tell the difference just parsing the text?, we need to make extra token compares to find which is what, and that is what i dont want to do it (i dont have time)

I wasn't aware AngelScript supported function declarations inside functions. C++ does not. Of course, the compiler would detect the lack of a type specifier on 1, and assume it's an object. I'm going to assume this is what you meant by 'extra token compares'. A recursive-descent parser actually handles this pretty well! Any state-machine driven compiler should be able to handle it, though it'd probably get rather complicated fast.

Also, use [ quote ][ /quote ].

#6Andreas Jonsson  Moderators

Posted 08 September 2004 - 02:53 PM

If I may...

AngelScript is following the C++ syntax pretty closely so I want to continue that trend with the constructors as well. That means that local objects will be constructed with the following declaration:

CObject obj(param1, param2);

To have AngelScript support this form you will have to change the parser and the compiler. The parser is capable of looking ahead to determine how to interpret the syntax so don't worry about that. There is no need for new tokens.

The constructor should be registered with the following call:

engine->RegisterObjectBehaviour("CObject", asBEHAVE_CONSTRUCT, "void f(int, int)", asFUNCTION(ConstructCObjectWithParams), asCALL_CDECL_OBJLAST);

For this to work you'll also have to change the behaviour structure used to store the registered behaviour functions for the object, and change the RegisterObjectBehaviour() method to support constructors with different function signatures.

If you need help, in realizing these changes you're welcome to e-mail me.

As I said earlier, JIT compilation is still quite far away. I will concentrate on language features first.

Yes, I am very interested in tutorials for AngelScript. I'll post them on the site if you want, or if you prefer I'll link to your site with the tutorials.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#7Andreas Jonsson  Moderators

Posted 08 September 2004 - 03:06 PM

// Global variable declarationCObject obj(parm1, param2);// Function declarationCObject function(int, float){  ..}

These are the cases you'll have to worry about in the global scope. At first they may seem similar, but the variable declaration can be identified in that it doesn't declare parameters but instead uses arguments.

// Global variable with more complex argumentCObject obj(int(parm1));

This is another case that has to be identified. You'll have to write a function that looks ahead until the first parenthesis, and then from what it finds in the parenthesis determines if it is a declaration (will find an expression) or function (will find a parameter declaration).

// Global variable with no argumentsCObject obj();

This is also a possible situation, in which case AngelScript should give an error because the variable declaration don't need the parenthesis, and the function doesn't have a body.

There are no function prototypes in AngelScript, except for imported functions that are preceeded with the keyword 'import'.

I know it is a complicated sitation, but take a look at how I solved ParseScript(). It uses the method IsGlobalVar() to determine if the global statement is a global variable declaration or a function declaration. IsGlobalVar() looks ahead several tokens in order to determine this.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#8Lioirc  Members

Posted 09 September 2004 - 11:03 AM

I already have this feature implemented, i was not sure about the script syntax, as i said before, im c++ biased and the scripters no, but i will let it the way its implemented, like c++ object creation parameters

It took 20 minutes to do it, for now it supports , any number of parameters, enums parameters or constant integers (that is how enum are implemented) but changing it to support other data types its a matter of adding a few line in the compiler, but i dont know if i will do it because i still have not decided about what scripting library i will use in my framework ( the other lib that has jit compilation requires to have wrapper or proxy function for antive functions, and i like the angelscript way of supporting native functions directly)

WitchLord what about this script, these is where it will need extra comparations to find if its object declaration or a function call

int type1 = 1;
int type2 = 2;

void main() {
CObject obj(1, 2);
CObject getObjectByTypes(1, 2);
}

and getObjectByTypes is a global function that do whatever you want, and return a CObject, there is where the parser have problems. But now that i see it, probably checking if getObjectByType is a script or native function will do, yes, i will take a look at it later

I will send you the patch probably this weeekend or on monday

Come on, take a look at the jit source, my project will not be out of the beta stage for at least 2 or 3 months, so i hope that a quite far away its not more thatn a few months :)
And i will contribute a lot to your library, i will send you 2 tutorials with this patch

Lioric

#9Deyja  Members

Posted 09 September 2004 - 12:11 PM

Simply put, your example isn't valid code. You can't declare a function inside a function. So getObjectByTypes MUST be a variable.

#10Andreas Jonsson  Moderators

Posted 10 September 2004 - 04:27 AM

Deyja is correct.

void Func(){  CObject getObjectByTypes(1, 2);}

This code can only be treated as a variable declaration. Even if the function CObject getObjectByTypes(int, int) existed the compiler should still treat the statement above as a variable declaration, though it might give an error because the name is already taken. (I actually don't remember right now if I put in this restriction or not).

JIT is something that will be supported, though I won't take the time to implement it at this moment. If you should want to give it a try though, it would be another excellent contribution to the library.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.