这个星期天我正在做一些 Ada .. ;-)
我写了一个小的 Log 包:
log.ads:
package Log is
procedure log (text: String);
end Log;
Run Code Online (Sandbox Code Playgroud)
日志.adb:
with Ada.Text_IO;
package body Log is
procedure log (text: String) is
begin
Ada.Text_IO.Put (text);
end log;
end Log;
Run Code Online (Sandbox Code Playgroud)
我可以这样使用它:test.adb:
with Log;
procedure Test is
begin
Log.log ("bla bla");
end Test;
Run Code Online (Sandbox Code Playgroud)
现在,我想“改进”这个包。我希望日志程序将文本“推送”到任务中。这是执行“Ada.Text_IO.Put(文本)”的任务。任务可以是:
task Logger_Task is
entry log (text : String);
end Logger_Task;
task body Logger_Task is
begin
loop
accept log (text: String) do
Ada.Text_IO.Put (text);
end log;
end loop;
end Logger_Task;
Run Code Online (Sandbox Code Playgroud)
我希望 Log …
我正在Ada做一个Z80模拟器.我正在实现JR(Jump relative)系列,但我对我的代码不满意:
with Ada.Text_IO;
procedure main is
type UInt16 is mod 2 ** 16;
type UInt8 is mod 2 ** 8;
type Int8 is range -128 .. 127;
package UInt16_IO is new Ada.Text_IO.Modular_IO (UInt16);
function Two_Complement(N : UInt8) return Int8 is
begin
if N <= 127 then
return Int8 (N);
end if;
return Int8 (Integer (N) - 256);
end Two_Complement;
-- Relative jump
function Jr (Address : UInt16; D: UInt8) return UInt16 is
begin
return UInt16 (Integer (Address) + Integer …Run Code Online (Sandbox Code Playgroud)