compiler

Unnamed Compiled Systems Language Project
git clone http://frotz.net/git/compiler.git
Log | Files | Refs

1040-structs.src (715B)


      1 
      2 type Point struct {
      3 	x i32,
      4 	y i32,
      5 };
      6 
      7 type Line struct {
      8 	start Point,
      9 	end Point,
     10 };
     11 
     12 func add(a *Point, b *Point) {
     13 	a.x = a.x + b.x;
     14 	a.y = a.y + b.y;
     15 }
     16 
     17 type PointPtr *Point;
     18 
     19 func add2(a PointPtr, b PointPtr) {
     20 	a.x = a.x + b.x;
     21 	a.y = a.y + b.y;
     22 }
     23 
     24 func print(p *Point) {
     25 	_hexout_(p.x);
     26 	_hexout_(p.y);
     27 }
     28 
     29 var p0 Point = { x: 45, y: 17 };
     30 var p1 Point = { x: 5, y: 3 };
     31 
     32 var p2 struct { x i32, y i32, } = { x: 7, y: 6 };
     33 
     34 func start() i32 {
     35 	_hexout_(p0.x);
     36 	_hexout_(p0.y);
     37 	p0.x = 123;
     38 	p0.y = 456;
     39 	_hexout_(p0.x);
     40 	_hexout_(p0.y);
     41 	add(&p1, &p0);
     42 	print(&p1);
     43 	add2(&p1, &p0);
     44 	print(&p1);
     45 	var z Point;
     46 	z.x = 0x10203040;
     47 	z.y = 0x50607080;
     48 	print(&z);
     49 	_hexout_(p2.x);
     50 	_hexout_(p2.y);
     51 	return 0;
     52 }