-
Notifications
You must be signed in to change notification settings - Fork 2
Reference
BlueScript is a scripting language that borrows heavily from TypeScript syntax. However, not all TypeScript syntax is currently supported in BlueScript. Notable features that are not yet supported include exceptions, certain built-in objects, and async/await functionality.
BlueScript also diverges from TypeScript in some key semantics, particularly in its type system. Unlike TypeScript, BlueScript separates integer
and float
types, treating them as distinct.
BlueScript provides six primitive types as well as object types:
-
integer
(32bit integer) -
number
(an alias ofinteger
) -
float
(32bit floating-point number) string
boolean
-
null
andundefined
(they are the same) any
Any kind of value can be implicitly converted into any
type, and vice versa.
- When an
integer
value is converted, the resulting value is represented as a 30bit integer. - When a
float
value is converted, the resulting value is represented as a 30bit floating-point number, where only 6 bits are allocated for an exponent instead of 8 bits. - When a
boolean
value is converted intoany
type, the resulting value ofany
type is either 0 (false
) or 1 (true
). Thus, it can be later converted into aninteger
value. Similarly, anany
-type value holding 0, 0.0,null
, orundefined
can be converted into aboolean
valuefalse
. The otherany
-type values can be converted intotrue
.
-
null
andundefined
(they are the same) true
false
- Numbers such as
7
and0.3
- Character strings such as
"text"
and'text'
- Arrays
Array literals are defined using square brackets, with elements separated by commas.
let arr = [1, "Foo", 42];
BlueScript supports both Type[]
and Array<Type>
syntax for type annotations.
let iarr: integer[] = [1, 2, 3];
let iarr2: Array<integer> = [1, 2, 4];
Only numeric indices are supported for accessing array elements.
let arr = [1, 3, 4];
print(arr[0]); // 1
Accessing an index out of bounds will result in a runtime error.
let arr = [1, 2, 3];
arr[5]; // ** error: array index out of range: 5
Currently, array methods such as push
, pop
, map
, filter
, etc., are not supported in BlueScript.
The increment and decrement operators work with numerical values and literals.
-
Postfix Increment/Decrement Operators
The value is incremented or decremented by 1, and the original value is returned.let x = 1; print(x++); // 1 print(x); // 2 let y = 1.0; print(y--); // 1.0 print(y); // 0.0
-
Prefix Increment/Decrement Operators
The value is incremented or decremented by 1, and the updated value is returned.let x = 1; print(++x); // 2 print(x); // 2
BlueScript supports the following unary operators:
-
+
(Unary plus, returns the value of its operand) -
-
(Unary negation, returns the negation of its operand) -
~
(Bitwise NOT) -
!
(Logical NOT)
print(-3) // -3
These operators take numerical operands and return a single numerical result.
-
**
(Exponentiation) -
*
(Multiplication) -
/
(Division) -
%
(Modulus) -
+
(Addition) -
-
(Subtraction)
Relational operators take numerical operands and return a boolean value.
-
<
(Less than) -
>
(Greater than) -
<=
(Less than or equal to) -
>=
(Greater than or equal to)
-
==
and===
are used as equality operators. In BlueScript, they are identical in behavior, checking both value and type. -
!=
and!==
are used as inequality operators, also identical in behavior, checking both value and type.
Bitwise shift operators take integer operands and return a integer value.
-
<<
(Left shift) -
>>
(Right shift) -
>>>
(Unsigned right shift)
Binary bitwise operators take integer operands and return a integer value.
-
&
(AND) -
|
(OR) -
^
(XOR)
-
&&
(Logical AND) -
||
(Logical OR)
The ternary operator is used for conditional expressions:
let result = condition ? trueValue : falseValue;
BlueScript supports the following assignment operators:
=
-
+=
,-=
,*=
,/=
(Compound assignment operators)
Variables in BlueScript are declared using let
and const
.
let x = 10;
let y: float = 5.5;
const t:boolean = true
-
while loop
let i = 0; while (i < 10) { print(i); i++; }
-
for loop
for (let i = 0; i < 10; i++) { print(i); }
-
break and continue
for (let i = 0; i < 10; i++) { if (i == 5) { continue; } if (i == 8) { break; } print(i); }
-
if … else …
let a = 10; if (a > 5) { print("Greater than 5"); } else { print("Less than or equal to 5"); }
Functions are declared with function
keyword.
function add(a:integer, b:integer):integer {
return a + b;
}
The function definition can be overwritten only if the function’s argument types and return type are the same.
let add = (a: integer, b: integer): integer => a + b;
Currently, closures are not supported in BlueScript.
Classes in BlueScript are declared by using class
keyword.
class Rectangle {
height:float;
width: float;
constructor(height: float, width:float) {
this.height = height;
this.width = width;
}
getArea() {
return this.height * this.width;
}
}
Currently, Access modifiers are not supported in BlueScript.
extends
keyword is used to create child classes.
class Square extends Rectangle {
constructor(sideLength:float) {
super(sideLenght, sideLength);
}
}
new
keyword is used to create class instance.
let rect = new Rectangle(13, 15);
Properties and methods are accessed with dot notation.
print(rect.height) // 13
print(rect.getArea()); // 195
In the methods' definitions, the properties and methods are accessed with this
keyword.
class Rectangle {
height:float;
width: float;
constructor(height: float, width:float) {
this.height = height;
this.width = width;
}
getArea() {
return this.height * this.width;
}
}