ada/demo/demo_std.adb · 1744 字节 · 下载原文
-- demo_std.adb —— Ada 第一层:**标准输入输出**(std)
-- demo_std.adb -- Ada layer 1: **standard input/output** (std)
--
-- 这一层只用 `Put_Line` / `Integer'Image` 与 `for` 循环,不碰 Crt / Graph / 宿主 `ui_*` ——
-- This layer only uses Put_Line / Integer'Image and a for loop; it touches no Crt / Graph / host ui_* --
-- 所以任何后端上行为一致,也是本组例程里唯一有"逐字节确定性输出"的一份。
-- so it behaves identically on every backend and is the only demo in this group with byte-exact output.
--
-- 跑法(桌面 vmlcli):
-- How to run (desktop vmlcli):
-- dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/ada/demo/demo_std.adb
--
-- 本前端的两个事实(都来自 Lib/ada 的既有约定):
-- Two facts about this frontend (both from the existing Lib/ada conventions):
-- ① `with Ada.Text_IO; use Ada.Text_IO;` 只做语法接受,I/O 绑到共享库的
-- ① `with Ada.Text_IO; use Ada.Text_IO;` is only syntactic; I/O is bound to the shared library's
-- print_str / print_int / newline。
-- ② 整转串只认 `Integer'Image(X)`(本子集没有别的写法)。
-- ② the only int-to-string form is Integer'Image(X) (this subset has no other way).
with Ada.Text_IO; use Ada.Text_IO;
procedure Demo_Std is
Sum : Integer := 0;
begin
Put_Line("=== Ada 标准输出 demo ===");
Put_Line("=== Ada standard output demo ===");
Put_Line("你好,世界 / hello, world");
Put_Line("整数: " & Integer'Image(42));
Put_Line("计算: 7 * 6 = " & Integer'Image(7 * 6));
for I in 1 .. 10 loop
Sum := Sum + I;
end loop;
Put_Line("循环求和: 1..10 = " & Integer'Image(Sum));
end Demo_Std;