Type handling
Displaying 1-1 of 1 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Overkill

Just some stuff I've jotted down in notepad, talking about how better type handling could be done, as well as possible function overloading.

One of the big hinderances that prevents verge from having good type enforcement is the lack of knowing what constitutes the type of a literal, variable, or function is.

As is, verge just checks all literals against the list of declared identifiers and if it doesn't find the literal declared (which it won't), it'll say it's an unknown identifier or unknown string variable. It doesn't actually check the literal's type which, if checked, would give much more useful error reporting, like say, "Expected an integer. However, the string literal "asparagus" was found" or "The integer literal, 42, is not a string!" or maybe "The function Log(string) isn't compatible with the arguments (int)."

When better type checking is added, things like function overloading or introduction of new primitive types would become much easier. Here are some outlined notes and ideas.


Obvious, int check not requiring variables:
Token must be one of:
A NUMERICAL LITERAL OF SOME SORT
-
~
!
(

Obvious, string check not requiring variables:
Token must be one of:
"
str
mid
left (
right (
Note: Brackets are important, so to not confuse left and right with the integer button variables of the same name.

Less obvious, the type-check involving a variable or function:
Search for variable with same name as token.
Retreive variable's type.

For function declarations:
Get return type: void, int or string
Get name.
Get arguments.
If signature of arguments and name are identical to existing function,
Error due to ambiguity.
If name is identical to existing function, but signatures differ,
Permit the creation of a new function.
Otherwise, permit the creation of a new function.

For function calls:
Ensure function of given name exists.
Resolve type of first piece of argument.
If string, the rest of the argument must be string.
If int, the rest of the argument must be int.
Whatever the variable type, add to temporary signature.
Repeat as necessary, commas separating each arg.
Compare temp signature against all functions of given name.
Error if function that matches signature doesn't exist.

Function overloading is dealt with at compile-time, thus it should have basically no impact on the runtime execution.

Posted on 2006-06-30 21:18:05 (last edited on 2006-07-01 20:00:12)


Displaying 1-1 of 1 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.