Releases: jac3km4/redscript
v1.0.0-preview1
This is a preview compiler release. DO NOT USE IT UNLESS YOU'RE A DEVELOPER. For standard releases go here.
REDscript 1 is a rewrite of REDscript that introduces a lot of improvements and new very powerful features.
Major highlights
Generics
User-defined generics with constraints and variance annotations are now supported. The compiler verifies and enforces correctness of their variance and constraints.
func TakeObject<A extends GameObject>(obj: A) -> A ...
// makes A contravariant
abstract class Predicate<-A> {
func Test(obj: A) -> Bool
}
Lambdas
First-class anonymous functions that close over their environment are now supported.
func Demo(arg: Int32) {
let array = [1, 2, 3, 4, 5];
let result = FilterArray(array, (x) -> x % arg == 0);
}
func FilterArray<A>(arr: [A], filter: (A) -> Bool) -> [A] ...
Hindley-Milner-based type inference
REDscript now uses a powerful type inference algorithm that enables type safety with few to no type annotations.
class Animal {}
class Pet extends Animal {}
class Human extends Animal {}
func Demo1() -> array<Animal> {
let array; // no type annotation needed
ArrayPush(array, new Pet()); // compiler infers that elements of `array` are at least Pet
ArrayPush(array, new Human()); // compiler adjusts array to the least upper type, Animal
return array;
}
func Demo2() {
let swap = (f, a, b) -> f(b, a);
swap((a, b) -> RandRange(0, 1) == 0 ? a : b, 1, 2);
}
Implicit ref
The compiler now inserts the ref
type automatically when needed.
class Class {}
// parameter and return type are `ref<Class>`
func Func(inst: Class) -> Class {...}
New diagnostics
The compiler now supports some additional diagnostics.
abstract class Abstract<A> {
func Unimplemented() -> A;
}
class Concrete extends Abstract<Int32> {
}
[ERROR] scripts\Test.reds:50:7
class Concrete extends Abstract<Int32> {
^^^^^^^^^^
this class is missing some required method implementation(s):
func Unimplemented() -> Int32 {}
Improved parser with error recovery
The parser was rewritten with better diagnostics and error recovery in mind. The compiler now reports static analysis errors even when the syntax in the file is broken.
[ERROR] At scripts\Test.reds:50:3
let str: Int32 = "";
^
expected ';' after expression in statement
[ERROR] At scripts\Test.reds:50:20
let str: Int32 = "";
^^
type mismatch: found String when expected Int32
Improved I/O performance
The compiler reads and writes large binary files whenever it runs, which was one of the main bottlenecks in the past. The I/O code has been rewritten to avoid copying data and a typical full compiler run is now 2-5 times faster.
Caveats
This is a pre-release and it's therefore incomplete and unstable. While it can already compile and run a lot of existing code, there are currently some limitations:
case
is now a keyword and can't be used as an identifier- no
@replaceGlobal
annotation* - no static receivers (the ability to call static methods with a receiver)*
- no line numbers in generated code (debugger won't work)*
- no C API for red4ext*
- for now, you need to manually remove
engine/tools/scc_lib.dll
when moving from previous version of redscript
- for now, you need to manually remove
- no error popup in scc.exe or support for user hints config*
- no conditional compilation*
- the
ref
type as specified by users is currently completely ignored and instead inserted by the compiler where needed* - no
NameOf
* - no decompiler*
- some diagnostics like unused variable check are missing*
Features marked with an asterisk are planned to be included in the final release.
Planned features
Some additional and not yet implemented features include:
@specialize
annotation for providing specialized implementations of generic data types- enforcement of visibility for user code specifically
- some shortcut for creating instance of classes (most likely generating a static
Create
method) - basic pattern matching based on Swift
v0.5.27
v0.5.26
[0.5.26] - 2024-08-18
Bug Fixes
- Fix an edge case around
wrapMethod
that would not emit a proper error message (bd37a9f) - Correct the handling for assignment to fields and array elements of values behind a
script_ref
(f60cf70)
Features
- Do not upgrade
wref
s before dynamic casts (d34f65b) - Implement
ArraySort
intrinsic (3bac4c2) - Implement a sealed struct allow-list (2019eaf)
- this is a list of native structs that have all their members exposed to scripts in a way that permits safe construction, native structs that are not in the list now emit an appropriate warning when constructed
- native structs that are not in the sealed struct list can now be used with
addField
annotation
- Emit compressed 0 and 1 constants (5fb167d)
- Cross-platform builds (0c27ac2)
- Warn on invalid usages of
AsRef
andVariant
operations (6b79caf) - Emit an error for annotations on native items (2e612c9)
Contributors
- jekky
v0.5.25
[0.5.25] - 2024-06-16
Bug Fixes
- Fixes required for redscript-dap (ac5606b, 1bde744)
Contributors
- jekky
v0.5.24
v0.5.23
[0.5.23] - 2024-05-28
Bug Fixes
- Minor fix in Deref bytecode (f12f7ab)
- Correct the types of ArrayFindFirst and ArrayFindLast (cbed943)
- Correct invisible import handling (4a7f995)
Features
- Add a NameOf intrinsic for type names (9a886d1)
- Syntax sugar for calling static methods with a receiver (edf2689)
Contributors
- jekky
v0.5.21
[0.5.21] - 2024-05-16
Bug Fixes
- Recover from invalid type errors in define_function (4ac2862)
- Fix excessive stack usage in else-if (8990d58)
Features
- Reject duplicate fields within a type (d7a59ff)
- Add function names to bytecode output in the decompiler (336d448)
- More precise diagnostics for re-defined types (951a4d8)
- Reject non-class types inside of ref/wref (92a2f59)
- Reject class types without ref/wref (2d11150)
Contributors
- jekky
v0.5.19
v0.5.18
[0.5.18] - 2024-03-09
Bug Fixes
- Evaluate
@if
annotation for class members (4902d10) - Only resolve direct class members in annotations (19c42a2)
- This will now reject code that annotates a method with the wrong class (a class that happens to be a subtype of something that has the right method), leading to this error:
no method with this name exists on the target type
. This kind of annotation used to be allowed but it leads to surprising behavior, so it is now rejected and scripts should be updated to refer to the correct class (the class where the method is actually declared).
- This will now reject code that annotates a method with the wrong class (a class that happens to be a subtype of something that has the right method), leading to this error:
- Fix detection of
super
vsthis
in the decompiler (eea9a2a)
Features
- Add diagnostics for incorrect usage of temporaries and switch fallthrough (f031843)
- Add a warning for problematic usage of
addMethod
(984541f) - Support writing to a separate cache file (d635455)
Contributors
- jekky
v0.5.17
[0.5.17] - 2023-12-17
Bug Fixes
- Fix handling of an unknown function field (a1dde39)
- Add fallback for script path retrieval in the error report (39e48b4)
Features
- Extract a shared scc library to be used in red4ext to detect scripts that prevent the game from starting (aadbeda)
- Improve error reporting for corrupted cache (72ec7c4)
Contributors
- jekky