Changeset 37f527b in mainline for uspace/dist
- Timestamp:
- 2010-03-26T21:55:23Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4204ad9
- Parents:
- b535aeb
- Location:
- uspace/dist/sysel
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/dist/sysel/except.sy
rb535aeb r37f527b 28 28 29 29 class ExceptionDemo is 30 fun foo() : intis30 fun foo() is 31 31 Builtin.WriteLine("Entered foo()."); 32 32 raise new BaseException(); -
uspace/dist/sysel/hexec.sy
rb535aeb r37f527b 29 29 class HelenOSExecDemo is 30 30 fun Main() is 31 Builtin.Exec("/app/tester");32 Builtin.Exec("/app/tester", "print1");31 Task.Exec("/app/tester"); 32 Task.Exec("/app/tester", "print1"); 33 33 end 34 34 end -
uspace/dist/sysel/inherit.sy
rb535aeb r37f527b 45 45 fun Main() is 46 46 var a : A; 47 var c : C; 47 48 49 -- Construct and assign object. 48 50 a = new A(); 49 51 a.Foo(); 50 52 53 -- Implicit conversion to base type. 51 54 a = new B(); 52 55 a.Foo(); … … 54 57 a = new C(); 55 58 a.Foo(); 59 60 -- Test 'as' operator for conversion to derived type. 61 c = a as C; 62 63 -- Test grandfather class. 64 var d : Object; 65 d = a; 66 d = new B(); 67 d = c; 56 68 end 57 69 end -
uspace/dist/sysel/list.sy
rb535aeb r37f527b 27 27 -- 28 28 29 -- Doubly-linked list implementation. 29 30 class List is 30 31 var head : ListNode; 31 32 33 -- Initialize list. 32 34 fun Init() is 33 35 head = new ListNode(); … … 36 38 end 37 39 40 -- Append new entry at the end of the list. 38 41 fun Append(data : int) is 39 42 var n : ListNode; … … 53 56 end 54 57 55 fun GetFirst() : ListNode is 56 return head.next; 58 -- Return first node in the list or @c nil if there is none. 59 prop First : ListNode is 60 get is 61 return get_first(); 62 end 63 end 64 65 -- Return first node in the list or @c nil if there is none. 66 fun get_first() : ListNode is 67 if head.next == head then 68 return nil; 69 else 70 return head.next; 71 end 57 72 end 58 73 end … … 65 80 var head : ListNode; 66 81 67 fun GetNext() : ListNode is 82 -- Value stored in this node. 83 prop Value : int is 84 get is 85 return value; 86 end 87 end 88 89 -- Previous node in list. 90 prop Prev : ListNode is 91 get is 92 return get_prev(); 93 end 94 end 95 96 -- Next node in list. 97 prop Next : ListNode is 98 get is 99 return get_next(); 100 end 101 end 102 103 -- Get next node. 104 fun get_next() : ListNode is 68 105 if next != head then 69 106 return next; … … 73 110 end 74 111 75 fun GetPrev() : ListNode is 112 -- Get previous node. 113 fun get_prev() : ListNode is 76 114 if prev != head then 77 115 return next; … … 81 119 end 82 120 83 fun GetValue() : int is84 return value;85 end86 121 end 87 122 … … 100 135 var n : ListNode; 101 136 102 n = list. GetFirst();137 n = list.First; 103 138 while n != nil do 104 139 Builtin.WriteLine(n.value); 105 n = n. GetNext();140 n = n.Next; 106 141 end 107 142 end -
uspace/dist/sysel/property.sy
rb535aeb r37f527b 27 27 -- 28 28 29 class Ais29 class Foo is 30 30 var x : int; 31 31 … … 68 68 end 69 69 end 70 71 -- 72 -- Class-type property. This is used for demonstrating property 73 -- field access. This case is still quite easy. It does not require 74 -- read-modify-write. Since class is a reference type, access 75 -- operator will read the value and dereference it, thereby 76 -- getting somewhere else (so the value will not be modified and 77 -- need not be written back). 78 -- 79 80 var bprop : Bar; 81 82 prop B : Bar is 83 get is 84 Builtin.WriteLine("Getting B"); 85 return bprop; 86 end 87 set value is 88 Builtin.WriteLine("Setting B"); 89 bprop = value; 90 end 91 end 92 93 end 94 95 class Bar is 96 var i : int; 70 97 end 71 98 72 99 class PropertyDemo is 73 100 fun Main() is 74 var a : A;101 var a : Foo; 75 102 var i : int; 76 103 77 a = new A();104 a = new Foo(); 78 105 79 106 -- Get value of named property. … … 96 123 Builtin.WriteLine("Main(): Got "); 97 124 Builtin.WriteLine(i); 125 126 -- Property field access 127 var b : Bar; 128 129 b = new Bar(); 130 131 b.i = 42; 132 a.bprop = b; 133 134 Builtin.WriteLine(a.bprop.i); 135 a.bprop.i = 2; 136 Builtin.WriteLine(a.bprop.i); 98 137 end 99 138 end -
uspace/dist/sysel/string.sy
rb535aeb r37f527b 31 31 -- Concatenate some strings. 32 32 Builtin.WriteLine("One-" + "two-" + "three!"); 33 34 -- Extract characters from a string. 35 var i : int; 36 i = 0; 37 while i < 5 do 38 Builtin.WriteLine("ABCDE"[i]); 39 i = i + 1; 40 end 33 41 end 34 42 end
Note:
See TracChangeset
for help on using the changeset viewer.
