Files
spl/stage1/test15.spl

41 lines
853 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* test_syntax.spl — 测试新语法expr.*, var/const :=, 内联 type */
fn main() i32 {
/* test 1: var name := expr */
var x := 42;
if x != 42 { ret 1; }
/* test 2: const name := const_expr */
const y := 100;
if y != 100 { ret 2; }
/* test 3: var name: Type = expr 仍可用 */
var z: i32 = 77;
if z != 77 { ret 3; }
/* test 4: expr.* 后缀解引用 */
var a: i32 = 99;
var p: *i32 = &a;
var v := p.*;
if v != 99 { ret 4; }
/* test 5: 指针修改后 .* 读到新值 */
a = 55;
var v2 := p.*;
if v2 != 55 { ret 5; }
/* test 6: 内联 type 定义 */
type Point = struct {
x: i32,
y: i32,
};
var pt: Point;
pt.x = 10;
pt.y = 20;
var ppt: *Point = &pt;
if ppt.x != 10 { ret 6; }
if ppt.y != 20 { ret 7; }
ret 0;
}