Add basic types
This commit is contained in:
parent
810777b0de
commit
f4447c70f7
68
AoC/2015/day_7/day_7.adb
Normal file
68
AoC/2015/day_7/day_7.adb
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Strings.Unbounded;
|
||||
with Ada.Containers.Vectors;
|
||||
|
||||
procedure Day_7 is
|
||||
|
||||
package Ustr renames Ada.Strings.Unbounded;
|
||||
|
||||
type Instruction_Operator is (
|
||||
OP_INVALID,
|
||||
OP_STORE,
|
||||
OP_AND,
|
||||
OP_OR,
|
||||
OP_NOT,
|
||||
OP_LEFTSHIFT,
|
||||
OP_RIGHTSHIFT
|
||||
);
|
||||
|
||||
type Instruction( Op : Instruction_Operator := OP_STORE) is
|
||||
record
|
||||
Dest : Ustr.Unbounded_String;
|
||||
case Op is
|
||||
when OP_STORE =>
|
||||
Data : Natural;
|
||||
when OP_AND | OP_OR =>
|
||||
Left_Op, Right_Op : Ustr.Unbounded_String;
|
||||
when OP_NOT =>
|
||||
Uni_Op : Ustr.Unbounded_String;
|
||||
when OP_LEFTSHIFT | OP_RIGHTSHIFT =>
|
||||
Shift_Op : Ustr.Unbounded_String;
|
||||
Shift : Natural;
|
||||
when others =>
|
||||
null;
|
||||
end case;
|
||||
end record;
|
||||
|
||||
type Instructions is array (Natural range <>) of Instruction;
|
||||
|
||||
function Read_File( File_Name : String ) return Instructions is
|
||||
package vec is new Ada.Containers.Vectors(
|
||||
Natural, Instruction);
|
||||
|
||||
DVec : vec.Vector;
|
||||
|
||||
File : File_Type;
|
||||
begin
|
||||
open(File, In_File, File_Name);
|
||||
|
||||
while not End_Of_File(File) loop
|
||||
Put_Line(Get_Line(File));
|
||||
end loop;
|
||||
|
||||
close(File);
|
||||
|
||||
return Instrs : Instructions( 0 .. Natural(DVec.Length) - 1) do
|
||||
for I in Instrs'range loop
|
||||
Instrs(I) := DVec(I);
|
||||
end loop;
|
||||
end return;
|
||||
end Read_File;
|
||||
|
||||
File_Name : String := "input_day_7.txt";
|
||||
|
||||
begin
|
||||
|
||||
Put_Line(Read_File(File_Name)'Image);
|
||||
|
||||
end Day_7;
|
||||
Loading…
Reference in New Issue
Block a user