1: include "std"; 2: open Long; 3: 4: header """#include <stdio.h>"""; 5: 6: header """ 7: struct Y { 8: int c; 9: int x; 10: long y; 11: Y() : c(-1) {} 12: Y(int _x) : c(-50), x(_x) {} 13: int h()const { return x + y + c; } 14: int f(int z)const { return z + x + y; } 15: int g(int z,int a)const { return z + x + y+a; } 16: 17: void setx(int _x){ x= _x;} 18: void setxy(int _x, long _y) {x = _x; y= _y;} 19: void print() { printf("Y=%d,%ld\\n",x,y); } 20: }; 21: """; 22: 23: cclass Y { 24: val c : int; 25: var x : int; 26: var y : long; 27: fun h: unit -> int; 28: fun f: int -> int; 29: fun g: int * int -> int; 30: proc setx: int; 31: proc setxy: int * long; 32: proc print: unit; 33: proc setc: int = "$1->c = $2;"; 34: ctor : unit; 35: ctor : int; 36: }; 37: 38: var b = Y(99); 39: b.x = 2; 40: b.y = 3L; 41: print b.c; endl; 42: print b.x; endl; 43: print b.y; endl; 44: 45: print$ b.f 100; endl; 46: print$ b.g$ 100,1000; endl; 47: b.print (); 48: 49: b.setx 20; 50: print b.x; endl; 51: print b.y; endl; 52: 53: b.setxy$ 20,42L; 54: b.setc 10000; 55: print b.x; endl; 56: print b.y; endl; 57: 58: print$ b.h (); endl; 59: print$ b.f 100; endl; 60: print$ b.g$ 100,1000; endl; 61: 62: anEff := b.f; 63: print$ anEff 100; endl; 64: 65: header """ 66: template <class T> 67: struct V 68: { 69: T x; 70: T get()const { return x; } 71: void sset(T _x) { x = _x; } 72: }; 73: """; 74: 75: cclass V[t] { 76: fun get: unit -> t; 77: proc sset: t; 78: ctor : unit; 79: }; 80: 81: v := V[int](); 82: 83: v.sset 1; 84: print (v.get ()); endl; 85: 86: header """ 87: template<class T> struct X { T x; }; 88: """; 89: 90: cstruct X[t] { x : t; } 91: xx := X(1); 92: print$ xx.x; endl; 93: 94: