Hi,
I'm working on a JIT compiled scriptingish language thing, and it's got to the stage where need to think about what sort of language it's actually going to be. I'm not sure if it's technically a scripting language, but it's meant to be embedded so it might count...
Anyway, I wanted to get some feedback on a few language features. Please bear with me, I havn't had a formal education in this sort of thing yet, so I don't know the terminology and some of my ideas might be naive. I'll endeavor to explain exactly how I plan on doing things, partly because I'm not sure how to describe the features any other way, and partly because I want feedback on the syntax etc. too.
Firstly, lets say it's a bit like C or java. Just saying that so you know it's not like some of the more (and even some of the less) obscure languages out there.
1. Any number of named returns
I'm thinking of something like this:
(int return1, int return2)Foo(int param1, int param2)
Rather than using eax for return values, which only works for things 32bit or less anyway, I thought I could pass them by reference. And I might as well pass the parameters by const reference while I'm about it, and throw pass by value out the window. So, that would make the above equivelant to the c++ snippet:
void Foo(int& return1, int& return2, const int& param1, const int& param2)
2. All variables must be initialised
I can't think of a time where saying a variable = 0 when you create it isn't possible, and uninitialised variables can cause bugs. And honestly, I think leaving a variable uninitialised is a pretty pointless micro optimisation. Especially when my language is already overkill, and is only going to get more so because I can compile it to the system, using things like sse if available. But I'm getting off topic. The real point is it makes feature 3 easier.
3. Type inference/template replacement
Basicly, a var type that can be anything. This could cause alot of pain, and for all I know it's impossible, but it would just be so handy. It goes like this:
(var result)Square(var num)
{
result = num * num;
}
Basicly, the compiler generates a new function each time it encounters a call using a different type. Pretty much like a template function, only not inlined. Pretty much like this template function in fact:
template<class T, class U>
void Square(T& result, const U& num)
{
result = num * num;
}
Of course you could end up generating huge amounts of code without even noticing, but that's really the point in it anyway... One thing that you can't normally do is:
var someVar = templateFunc(someOtherVar);
Forcing variable initialisation means you can't give a var different types based on some run time condition, which would make my head explode. If you can think of any flaws with all this I'd be very grateful.
4. Custom operators
The language should be flexible enough that the program it's embedded into can create new operators etc. But what I'm not sure about is if you should be able to in code... Probably not, given the purpose of the language. Anyway, it would look like this:
operator (vector result)X(vector lhs, vector rhs) : + // Same precedence as addition.
{
// You all know how to perform a cross product right?
}
vector C = A X B;
For ease of parsing I'd require a space between operators and operands. I was thinking precedence would be set in relation to other operators, rather than a flat value. Like the above operator would have the same precedence as addition. It might also be useful to say an operator has precedence 1 lower than some existing operator. And perhaps if you don't provide any sort of comparison it has the highest precedence.
That must be about enough for one day. If this goes well I might be back later with some more unusual ideas, but this post is getting long. So please, any and all feedback. Even if it's just to say that none of this is new (probably true) or it's badly thought out (wouldn't be surprised) or impossible to implement (why please) or X language is better in every way.