http://regedit.gamedev.pl/ Graphics programming, game programming, C++, PC games, Windows, Internet and more... |
| Main Page | Blog | Productions | Gallery | Download | Links | About me |
22:17
Sun
03
Jan 2010
RegScript - Bidirectional Type Inference
Coding my RegScript programming language is no longer easy as code grows bigger, but it's still much fun. In the last days I've added support for numeric types of different size. Here is the full list: float, double, uint8, uint16, uint32 (uint), uint64, int8, int16, int32 (int), int64.
I try to keep the syntax as close to C/C++ as possible, but at the same time I introduce some interesting details like:
object[x,y,z]
void Func(float x = sin(globalVar)) { ... }
- Multiple values in switch case label:
switch (val) { case 1, 2, 3: ...
- Arbitrary expressions in switch case label:
switch (val) { case someVar+1: ...
- Possibility to define variables in switch case labels.
I've also implemented function overloading and many compiler errors and warnings similar to these from C++ compiler. But most interesting feature so far is what I call "Bidirectional Type Inference" :) I first introduced auto keyword to allow skipping type name and next I've made literal constants like 123 typeless so their type is deduced from the context (because I hate typing this f, u or ll postfixes everywhere in C++ code). For example:
// Left to right - these numbers are int16 int16 myShort = -32000 + 10; // Right to left - newVar is int16 auto newVar = myShort;
Comments (2) | Tags: regscript compilers c++
| Kos 2010-01-04 00:12:51 | Is it "these numbers are int16" or "this whole expression is int16"? Would something like this work? int8 aByte = 1000000 - 999999; |
| Reg 2010-01-04 17:19:19 | It's real, "these numbers are int16". Your code doesn't compile. Error message says "Cannot parse decimal integer number" because 1000000 cannot be parsed as int8. |
| [Stat] [Admin] [STAT NO AD] [pub] [Mirror] | Copyright © 2004-2010 Adam Sawicki | 0.11 s |