[Fix][Impl] 为了消除类构造带来的语法歧义,同时保持实现简洁和括号省略的语法,自此版本,引入了 `new` 操作符
造成歧义的原方法:
if a == A{}
条件是 a == A,还是 a == A{} ?
因此,现在使用 new a_struct{}来构造类
[Opti] 相较于 Fig v0.4.1-alpha版本,release O3同编译条件下
Fib普通递归法性能提升 ~50%
具体方式:
增加了小整数优化,-128~127的整数现在会直接从IntPool获取而不是新构造
...忘了
[Fix] 类构造 shorthand模式忘写了,现在补上了
[Feat][Impl] 类型声明现在接受一个表达式,原为Identifier。实现 var start: time.Time = time.now() 的效果
这是符合语法和语言特性的支持,类型为一等公民。类似Python的 <class 'type'>
[Impl] 修改了部分错误输出的细节
79 lines
1.6 KiB
Plaintext
79 lines
1.6 KiB
Plaintext
var any_var; // type is Any
|
|
var number = 10; // type is Int
|
|
number = "123"; // valid
|
|
|
|
var number2 := 10; // specific type is Int
|
|
var number3: Int = 10; // both is ok
|
|
/*
|
|
number2 = 3.14;
|
|
invalid!
|
|
*/
|
|
|
|
const Pi := 3.14; // recommended, auto detect type
|
|
// equal -> const Pi: Double = 3.14;
|
|
|
|
/*
|
|
In fig, we have 13 builtin-type
|
|
|
|
01 Any
|
|
02 Null
|
|
03 Int
|
|
04 String
|
|
05 Bool
|
|
06 Double
|
|
07 Function
|
|
08 StructType
|
|
09 StructInstance
|
|
10 List
|
|
11 Map
|
|
12 Module
|
|
13 InterfaceType
|
|
|
|
3, 4, 5, 6, 10, 11 are initable
|
|
|
|
value system:
|
|
object is immutable
|
|
(included basic types: Int, String...)
|
|
|
|
`variable` is a name, refers to an object
|
|
assignment is to bind name to value
|
|
|
|
Example: var a := 10;
|
|
|
|
[name] 'a' ---> variable slot (name, declared type, access modifier, [value) ---> ObjectPtr ---> raw Object class
|
|
bind bind (shared_ptr)
|
|
|
|
For example:
|
|
var a := 10;
|
|
var b := 10;
|
|
|
|
`a` and `b` reference to the same object in memory
|
|
|
|
a = 20;
|
|
|
|
now a refers to a new object (20, Int)
|
|
|
|
what about complex types?
|
|
they actually have same behaviors with basic types
|
|
|
|
var a := [1, 2, 3, 4];
|
|
var b := a;
|
|
|
|
> a
|
|
[1, 2, 3, 4]
|
|
> b
|
|
[1, 2, 3, 4]
|
|
|
|
set a[0] to 5
|
|
|
|
> a
|
|
[5, 2, 3, 4]
|
|
> b
|
|
[5, 2, 3, 4]
|
|
|
|
Why did such a result occur?
|
|
|
|
" `a` and `b` reference to the same object in memory "
|
|
|
|
If you wish to obtain a copy, use List {a} to deeply copy it
|
|
*/ |