ID:181878
 
I was wondering what programming language was used to make BYOND? It works somewhat too good to be VB
C++
The general purpose programming language widely used around the world, C++. (And I think, the most-used programming language in the technology industry.)
In response to Nadrew
If it's C++, how you handle vars in BYOND? In DM we can set var to any value, and we don't care if it's int, float, double or string. However in C++ var type has to be defined, and can't be changed. Do you have multiple Arrays?
In response to Ripiz
BYOND handles all that good stuff for you. But I believe most of it all comes down to floats in the end.
In response to Ripiz
All values are just numbers, when it comes down to it. I believe they have a scheme where variables store type and value information, and the type determines what the value means - they basically just store five bytes per variable or something. If the first byte says "Number", the remaining four bytes are a numeric type (float, I think). If the first byte says "object reference", the remaining four bytes are a pointer. And so on.

Note that this is mostly speculation.
In response to Nadrew
Maybe my question was little confusing. In C++ if you define array, you have to define type too, ex. (string myarray[10];). How you define lists in C++ code? I assume you use array for normal vars too?
In response to Ripiz
C++ is not beholden to its type system, unlike languages like Java. All values are just binary, whether they're an integer, a floating point number, a character array, a pointer, a struct, a class. With the right incantation, it's possible to tell the compiler "No, it's okay, I know what I'm doing. Let me play with the binary".

That said, that level of magic isn't really required for BYOND's variable system. Variables are just tagged - the value owns the type, rather than the variable. All you need to do in C++ is move around the type+value combinations - as a struct, probably - and interpret the value different ways depending on what the type value is. Braindead example:

struct Variable {
  Type_t VariableType,
  int VariableValue
};

void PrintVariable(Variable* variable) {
  switch(variable->VariableType) {
    case TYPE_INT:
      printf("%i", variable->VariableValue);
      break;

    case TYPE_FLOAT:
      //Cast to prevent compiler warning
      printf("%f", (float) (variable->VariableValue));
      break;

    case TYPE_STRING:
      //Notice VariableValue is treated as a pointer here
      printf("%s", (char*) (variable->VariableValue));
      break;

    default:
      printf("can't happen");
  }
}
In response to Jp
Sounds interesting.

But if lets say I do mob/var/HP=1, in C++ it should be int HP=1;. However in DM I can do it HP="A" at any time, while HP="A"; won't work in C++, as it's not int.

But I think I've got idea how it was made
In response to Ripiz
A lot of langauges (not sure about BYOND) use the concept of a symbol table, which have the names (symbols) of variables and pointers to whatever they represent. So, in your example with HP being changed from an interger to a string, you'd just update the symbol table to reflect the change, freeing the old integer value and switching the pointer over to your new string value.

It might be interesting for you to design your own programming language using documentation from books and the Internet -- you'll learn a lot about the cool things you can do.
In response to Ripiz
Garthor mentioned the stl::vector class at [link]; it looks nice, though I haven't tried using it yet.
In response to Naokohiro
C++ is typically superceded by Java or C#.NET as a general purpose application language. C++ finds use in embedded or real-time systems, typically for military systems as they prefer it's well discussed real-time behaviour and company specific proprietory libraries they've developed about 10 years ago. You have to bear in mind that C++ is younger than Java.
In response to Stephen001
Stephen001 wrote:
You have to bear in mind that C++ is younger than Java.

Hold on there, cowboy. C++ is twelve years older than Java.
In response to Ryan P
I guess I was going on the ISO standard for C++, and when it stopped using the cfront pre-processor on Linux. I do stand corrected, 1983 vs 1995.
In response to Ryan P
So when lets say in BYOND I do var/X=1, in C++ is appears as int* X=(int)X; int X=1; string X; int Xarray[]; string Xarray[]; ?
In response to Ripiz
Most probably not, as it's a VM< it's not just translating to C++ and compiling that.
In response to Stephen001
Stephen: I think he means that it's equivalant to that in a binary sense. So behind the scenes when it's handling the binary bits and bobs.
In response to Haywire
Well, it's not, not least due to the memory overhead.
In response to Ripiz
In BYOND's code, there is a special struct called Value that holds info on the type of the value (null, obj, num, client, etc.) and then either an exact value (in the case of a floating point number) or a reference. For instance, a particular obj might be #13, so the Value associated with this has a reference of 13 and type 2. If you use the \ref macro on this you'll see [0x200000D].

Almost anything that DM identifies by a reference, it stores somewhere else and does reference counting on it. So for instance if you assign this value to a var, the reference count goes up; if you assign something else to that var, the reference count goes down. If the obj no longer has any references and isn't on the may anywhere, it gets deleted.

When DM goes to use that object, it actually calls code to look up object #13, which retrieves an even bigger struct with more info about the object itself.

As you noted, in C++ when you define an array you have to give it a type. Internally in BYOND, a regular user-defined list is an array of Value structs.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Almost anything that DM identifies by a reference, it stores somewhere else and does reference counting on it.

If DM handles garbage collection with reference counting, how does it handle reference islands - where two objects hold a reference to each other but all other refs have been cut? From the user's standpoint they may expect GC to take care of those, but the ref counter doesn't actually reach zero. Most interpreters will run into this problem (AFAIK) unless they add some mark & sweep in there.
Page: 1 2