File: values.adb

package info (click to toggle)
gnat-gps 18-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,716 kB
  • sloc: ada: 362,679; python: 31,031; xml: 9,597; makefile: 1,030; ansic: 917; sh: 264; java: 17
file content (57 lines) | stat: -rw-r--r-- 1,455 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
with Except;
with Input;  use Input;
with Stack;

package body Values is

   -------------
   -- Process --
   -------------

   procedure Process (V : Value) is
   begin
      Stack.Push (V);
   end Process;

   ----------
   -- Read --
   ----------

   function Read (Word : String) return Value is
      Int_Val  : Integer;
      Real_Val : Float;
      Kind     : Input.Number_Kind;

   begin
      Input.Read_Number (Word, Int_Val, Real_Val, Kind);

      if Kind /= Int_Number then
         raise Except.User_Error;
      end if;

      return new Value_Info'(Kind => Int, E => Int_Val);
      --  Allocate a new Value_Info (which is a record with one field)
      --  on the heap and initialize its only field "E" to be "Int_Val".
      --  NOTE: the ' in Value_Info'(...) must be there.
   end Read;

   ---------------
   -- To_String --
   ---------------

   function To_String (V : Value) return String is
   begin
      case V.Kind is
         when Int =>
            return Integer'Image (V.E);
            --  V is a pointer to a Value_Info record. V.all is the
            --  actual Value_Info record pointed by V. Thus, strictly speaking,
            --  we shoudl have written V.all.E above. However, Ada allows to
            --  remove the ".all" because the meaning of expression "V.E" is
            --  clear from its context.
         when Matrix =>
            return Print (V.M);
      end case;
   end To_String;

end Values;