alliedmodders/sourcemod — pull request #55 by dvander (2014-06-25 07:00:19+00:00)
Title: New type system.

This patch introduces the start of an actual type system in Pawn. The top type of this system is "object", which is a new reserved keyword. "object" is conceptually the root of the inheritance chain for all classes. Coercion is forbidden from tags to types, and vice versa. This extends to the `any` tag, variadic argument lists, multi-tag selectors, and the dreaded "relabel" or tag-override operator. Any attempt to cross the type systems is an error.

The reason for this is not so much for semantics, but because internally, SourceMod can't tell the difference between two different kinds of values. If we don't lock down the set of natives that take objects, we won't know what places in SourceMod need changing for garbage collection support.

Most of this patch is changing callers of matchtag() to not report an error. matchtag() itself now handles all error reporting. It is likely error 213 (tag mismatch) will become a full-blown compile-time error soon.

This patch also introduces a "class" keyword, which acts exactly the same as methodmaps, except classes use the type system instead of the tag system. However, there is currently no way to construct a class object. The VM does not provide an API to do it, Core provides no natives to do it, and no user-level construct can be casted to the class type.

I'll address this in an upcoming PR. Ultimately, I would like everything to coerce to "object", with some kind of boxing scheme for primitives. Finding the best way to communicate this to the JIT will take time, but in the interim, it should be okay to develop the C++ API for natives.