2016年2月27日土曜日

開発環境

  • OS X El Capitan - Apple (OS)
  • Emacs(Text Editor)
  • Java (実行環境)

コンピュータシステムの理論と実装 (Noam Nisan (著)、Shimon Schocken (著)、斎藤 康毅(翻訳)、オライリージャパン)の12章(オペレーティングシステム)、12.5(プロジェクト)を取り組んでみる。

12.5(プロジェクト)

コード(Emacs)

Keyboard.jack

class Keyboard {
  function void init() {
    return;
  } 
  function char keyPressed() {
    return Memory.peek(24576);    
  }
  function char readChar() {
    var char c1, c2;
    var boolean b1, b2;

    let b1 = true;
    while (b1) {
      let c1 = Memory.peek(24576);
      if (~(c1 = 0)) {
        let b1 = false;
        let b2 = true;
        while (b2) {
          let c2 = Memory.peek(24576);
          if (c2 = 0) {
            let b2 = false;
          }
        }
      }
    }
    do Output.printChar(c1);
    
    return c1;
  }
  function String readLine(String message) {
    var String s;
    var char c;
    var boolean b;
    var char backspace;
    var char newline;

    do Output.printString(message);
    
    let s = String.new(64);
    let b= true;
    let newline = String.newLine();
    let backspace = String.backSpace();
    while (b) {
      let c = Keyboard.readChar();
      if (c = newline) {
        let b = false;
      } else {
        if (c = backspace) {
          do s.eraseLastChar();
        } else {
          do s.appendChar(c);
        }
      }
    }
    return s;
  }
  function int readInt(String message) {
    var String s;

    let s = Keyboard.readLine(message);
    
    return s.intValue();
  }
}

0 コメント:

コメントを投稿