Changeset 38aaacc2 in mainline for uspace/dist/src
- Timestamp:
- 2010-04-23T21:41:10Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f4f866c
- Parents:
- 074444f
- Location:
- uspace/dist/src/sysel
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/dist/src/sysel/demos/arith.sy
r074444f r38aaacc2 30 30 fun Main() is 31 31 -- Test addition, multiplication and precedence. 32 Builtin.Write Line("2*2 + 2*2 =");33 Builtin.Write Line(2*2 + 2*2);34 Builtin.WriteLine(" (expected: 8)");32 Builtin.Write("2*2 + 2*2 = "); 33 Builtin.Write(2*2 + 2*2); 34 Builtin.WriteLine(" (expected: 8)"); 35 35 36 36 -- Test subtraction, multiplication and precedence. 37 Builtin.Write Line("1111 - 1 - 10 - 10*10 - 10*10*10 =");38 Builtin.Write Line(1111 - 1 - 10 - 10*10 - 10*10*10);39 Builtin.WriteLine(" (expected: 0)");37 Builtin.Write("1111 - 1 - 10 - 10*10 - 10*10*10 = "); 38 Builtin.Write(1111 - 1 - 10 - 10*10 - 10*10*10); 39 Builtin.WriteLine(" (expected: 0)"); 40 40 41 41 -- Test parenthesized sub-expressions. 42 Builtin.Write Line("10 * (1 - 1) =");43 Builtin.Write Line(10 * (1 - 1));44 Builtin.WriteLine(" (expected: 0)");42 Builtin.Write("10 * (1 - 1) = "); 43 Builtin.Write(10 * (1 - 1)); 44 Builtin.WriteLine(" (expected: 0)"); 45 45 46 46 -- Test unary plus and minus. 47 Builtin.Write Line("(+1) - (-1) - (+(+1)) + (+(-1)) = ");48 Builtin.Write Line((+1) - (-1) - (+(+1)) + (+(-1)));49 Builtin.WriteLine(" (expected: 0)");47 Builtin.Write("(+1) - (-1) - (+(+1)) + (+(-1)) = "); 48 Builtin.Write((+1) - (-1) - (+(+1)) + (+(-1))); 49 Builtin.WriteLine(" (expected: 0)"); 50 50 51 51 -- Test signed multiplication. 52 Builtin.WriteLine("+1 * +1 = "); 53 Builtin.WriteLine(+1 * +1); 54 Builtin.WriteLine("(expected: 1)"); 55 Builtin.WriteLine("-1 * -1 = "); 56 Builtin.WriteLine(-1 * -1); 57 Builtin.WriteLine("(expected: 1)"); 58 Builtin.WriteLine("+1 * -1 = "); 59 Builtin.WriteLine(+1 * -1); 60 Builtin.WriteLine("(expected: -1)"); 61 Builtin.WriteLine("-1 * +1 = "); 62 Builtin.WriteLine(-1 * +1); 63 Builtin.WriteLine("(expected: -1)"); 52 Builtin.Write("+1 * +1 = "); 53 Builtin.Write(+1 * +1); 54 Builtin.WriteLine(" (expected: 1)"); 55 56 Builtin.Write("-1 * -1 = "); 57 Builtin.Write(-1 * -1); 58 Builtin.WriteLine(" (expected: 1)"); 59 60 Builtin.Write("+1 * -1 = "); 61 Builtin.Write(+1 * -1); 62 Builtin.WriteLine(" (expected: -1)"); 63 64 Builtin.Write("-1 * +1 = "); 65 Builtin.Write(-1 * +1); 66 Builtin.WriteLine(" (expected: -1)"); 64 67 65 68 -- Test multiplication with large result. 66 Builtin.Write Line("1000000 * 1000000 * 1000000 * 1000000 =");67 Builtin.Write Line(1000000 * 1000000 * 1000000 * 1000000);68 Builtin.WriteLine(" (expected: 1000000000000000000000000)");69 Builtin.Write("1000000 * 1000000 * 1000000 * 1000000 = "); 70 Builtin.Write(1000000 * 1000000 * 1000000 * 1000000); 71 Builtin.WriteLine(" (expected: 1000000000000000000000000)"); 69 72 70 73 -- Test large literals. 71 Builtin.Write Line("1000000000000000000000000 =");72 Builtin.Write Line(1000000000000000000000000);73 Builtin.WriteLine(" (expected: 1000000000000000000000000)");74 Builtin.Write("1000000000000000000000000 = "); 75 Builtin.Write(1000000000000000000000000); 76 Builtin.WriteLine(" (expected: 1000000000000000000000000)"); 74 77 75 78 -- Test large factorials. -
uspace/dist/src/sysel/demos/list.sy
r074444f r38aaacc2 30 30 class ListDemo is 31 31 fun Main() is 32 var list : List; 33 var i : Int; 32 var list : List/int; 34 33 35 list = new List ();34 list = new List/int(); 36 35 list.Init(); 37 36 38 -- We need autoboxing or generics to get rid of this mess. 39 i = new Int(); i.Value = 5; list.Append(i); 40 i = new Int(); i.Value = 6; list.Append(i); 41 i = new Int(); i.Value = 7; list.Append(i); 42 i = new Int(); i.Value = 8; list.Append(i); 37 list.Append(5); 38 list.Append(6); 39 list.Append(7); 40 list.Append(8); 43 41 44 var n : ListNode ;42 var n : ListNode/int; 45 43 46 44 n = list.First; 47 45 while n != nil do 48 Builtin.WriteLine( (n.value as Int).Value);46 Builtin.WriteLine(n.Value); 49 47 n = n.Next; 50 48 end -
uspace/dist/src/sysel/demos/property.sy
r074444f r38aaacc2 33 33 prop X : int is 34 34 get is 35 Builtin.Write Line("Getting value of X which is");35 Builtin.Write("Getting value of X which is "); 36 36 Builtin.WriteLine(x); 37 37 return x; … … 39 39 40 40 set value is 41 Builtin.Write Line("Setting value of X to");41 Builtin.Write("Setting value of X to "); 42 42 Builtin.WriteLine(value); 43 43 x = value; … … 51 51 prop self[index : int] : int is 52 52 get is 53 Builtin.Write Line("Getting property with index ");54 Builtin.Write Line(index);55 Builtin.Write Line("which is");53 Builtin.Write("Getting property with index "); 54 Builtin.Write(index); 55 Builtin.Write(" which is "); 56 56 Builtin.WriteLine(iprops[index]); 57 57 … … 60 60 61 61 set value is 62 Builtin.Write Line("Setting property with index ");63 Builtin.Write Line(index);64 Builtin.Write Line("to");62 Builtin.Write("Setting property with index "); 63 Builtin.Write(index); 64 Builtin.Write(" to "); 65 65 Builtin.WriteLine(value); 66 66 … … 110 110 i = a.X; 111 111 112 Builtin.Write Line("Main(): Got ");112 Builtin.Write("Main(): Got "); 113 113 Builtin.WriteLine(i); 114 114 … … 121 121 i = a[1]; 122 122 123 Builtin.Write Line("Main(): Got ");123 Builtin.Write("Main(): Got "); 124 124 Builtin.WriteLine(i); 125 125 -
uspace/dist/src/sysel/lib/boxed.sy
r074444f r38aaacc2 28 28 29 29 -- 30 -- Declarations for boxed variants of primitive types. 30 -- Declarations for boxed variants of primitive types. The interpreter 31 -- binds to these types internally. They must be declared. 31 32 -- 32 33 -
uspace/dist/src/sysel/lib/list.sy
r074444f r38aaacc2 27 27 -- 28 28 29 -- Doubly-linked non-genericlist.30 class List is31 var head : ListNode ;29 -- Doubly-linked list. 30 class List/t is 31 var head : ListNode/t; 32 32 33 33 -- Initialize list. 34 34 fun Init() is 35 head = new ListNode ();35 head = new ListNode/t(); 36 36 head.prev = head; 37 37 head.next = head; … … 39 39 40 40 -- Append new entry at the end of the list. 41 fun Append(data : Object) is42 var n : ListNode ;43 var ntl : ListNode ;41 fun Append(data : t) is 42 var n : ListNode/t; 43 var ntl : ListNode/t; 44 44 45 45 ntl = head.prev; 46 46 47 n = new ListNode ();47 n = new ListNode/t(); 48 48 n.value = data; 49 49 … … 57 57 58 58 -- Return first node in the list or @c nil if there is none. 59 prop First : ListNode is59 prop First : ListNode/t is 60 60 get is 61 61 return get_first(); … … 64 64 65 65 -- Return first node in the list or @c nil if there is none. 66 fun get_first() : ListNode is66 fun get_first() : ListNode/t is 67 67 if head.next == head then 68 68 return nil; … … 73 73 end 74 74 75 class ListNode is76 var value : Object;75 class ListNode/t is 76 var value : t; 77 77 78 var prev : ListNode ;79 var next : ListNode ;80 var head : ListNode ;78 var prev : ListNode/t; 79 var next : ListNode/t; 80 var head : ListNode/t; 81 81 82 82 -- Value stored in this node. 83 prop Value : Object is83 prop Value : t is 84 84 get is 85 85 return value; … … 88 88 89 89 -- Previous node in list. 90 prop Prev : ListNode is90 prop Prev : ListNode/t is 91 91 get is 92 92 return get_prev(); … … 95 95 96 96 -- Next node in list. 97 prop Next : ListNode is97 prop Next : ListNode/t is 98 98 get is 99 99 return get_next(); … … 102 102 103 103 -- Get next node. 104 fun get_next() : ListNode is104 fun get_next() : ListNode/t is 105 105 if next != head then 106 106 return next; … … 111 111 112 112 -- Get previous node. 113 fun get_prev() : ListNode is113 fun get_prev() : ListNode/t is 114 114 if prev != head then 115 115 return next;
Note:
See TracChangeset
for help on using the changeset viewer.