This document reflects current state of implementation. See To do section in main README.md
.
Syntax is heavily inspired by Go, but not the same. Differences so far:
- No support for short variable declaration
a := x
, dovar a = x
instead. - No
int
type, use explicitint32
orint64
. return
statement is either standalonereturn
or with call argumentsreturn (...)
.- No built-in
string
type, use[]char8
,[]char16
,[]char32
instead. - No
+
operator for string concatenation. - No
&^
(bit-clear, AND NOT) operator. - Bitwise complement
^x
is implemented as~x
.
Differences from C so far:
- Strings are slices, not pointers.
- No string zero-termination guarantee.
- No comma operator.
- No
while
statement, usefor
. - No
do-while
statement, usefor
.
Integer types:
int8
uint8
int16
uint16
int32
uint32
int64
uint64
Character types:
char8
(aliasint8
)char16
(aliasint16
)char32
(aliasint32
)
Float types:
float32
float64
const a = 1;
-- untyped integer constanta
.const a int32 = 1;
--int32
(typed) constanta
.
1
-- untyped integer constant (defaults toint64
)1.0
-- untyped float constant (defaults tofloat32
)"abc"
-- typed[]char8
constanttrue
-- typedbool
constantfalse
-- typedbool
constantnil
-- pointer constant
Untyped constant type inference is implemented for integer and real constants.
var b int32 = 1;
// Constant '1' will be interpreted as 'int32', because of 'b'.
var a int32 = 1 + b;
// Constant '1' will be interpreted as 'int32', because of 'a'.
var a int32 = 1;
// Variable 'a' is assigned type 'int64', 1 is interpreted to 'int64' because of default constant's type (see above).
var a = 1;
// Constants are treated by their default types 'int64'.
var a bool = 1 < 1;
Semicolons are currently required with rules similar to C. Will be re-evaluated to see whether they can be removed.
function <name> (arg, arg,...) (arg, arg, ...) {...}
<name> <type>
var <name> <type>
var <name> = <expr>
If var
declaration omits type, then the declaration must be followed with =
assignment, and the type is inferred from the right-hand side expression:
var b int32;
// Variable 'a' will be declared as 'int32' because of 'b'.
var a = b;
var a = b + 1;
// Variable 'a' will be declared as 'int64' because '1' will be interpreted by default type of untyped integer constant.
var a = 1;
- Variable declaration
- Expression
- Assignment
return ...;
To be changed to:
return (...)
return
if <pre-st>; <condition> { ... }
if <condition> { ... }
if ... { ... } else { ... }
if ... { ... } else if ...
Where:
pre-st
is simple statementcondition
is expression
for <pre-st>; <condition>; <post-st> { ... }
for <pre-st>; ; <post-st> { ... }
for <pre-st>; ; { ... }
for ; ; <post-st> { ... }
for ; <condition>; { ... }
for ; ; { ... }
for <condition> { ... }
Where:
pre-st
is simple statementpost-st
is simple statementcondition
is expression
for condition {
work();
}
for var ok = true; ok; ok = condition {
work();
}
for var ok = true; ok; ok = !condition {
work();
}
a = b
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
<name>(...)
a + b
a - b
a * b
a / b
a % b
~n
a & b
a | b
a ^ b
a << b
a >> b
a == b
a != b
a < b
a <= b
a > b
a >= b
!a
a && b
a || b