Initialize Aster project with basic structure, including Cargo configuration, lexer, parser, interpreter, and AST definitions. Add a sample script and README documentation. Implement basic error handling and environment management for variable storage.
This commit is contained in:
40
script.ast
Normal file
40
script.ast
Normal file
@@ -0,0 +1,40 @@
|
||||
// 压测:循环、递归、闭包
|
||||
|
||||
fn fib(n) {
|
||||
if (n <= 1) {
|
||||
return n
|
||||
}
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
}
|
||||
|
||||
fn make_adder(x) {
|
||||
return fn(y) { return x + y }
|
||||
}
|
||||
|
||||
let t0 = clock()
|
||||
|
||||
// 1. 循环压测:100万次算术
|
||||
let sum = 0
|
||||
let i = 0
|
||||
while (i < 1000000) {
|
||||
sum = sum + i
|
||||
i = i + 1
|
||||
}
|
||||
print("loop 1M:", sum)
|
||||
|
||||
// 2. 递归压测:fib(25)
|
||||
let f = fib(25)
|
||||
print("fib(25):", f)
|
||||
|
||||
// 3. 闭包压测:100万次调用
|
||||
let add10 = make_adder(10)
|
||||
let j = 0
|
||||
let total = 0
|
||||
while (j < 1000000) {
|
||||
total = add10(j)
|
||||
j = j + 1
|
||||
}
|
||||
print("closure 1M calls:", total)
|
||||
|
||||
let t1 = clock()
|
||||
print("total time (s):", t1 - t0)
|
||||
Reference in New Issue
Block a user