26

Squeak を REPL (GUI なし) として起動して、Smalltalk 式を入力および評価できますか? デフォルトの画像ではこれが許可されていないことはわかっています。コマンドライン シェルからアクセスできる最小限のイメージを作成する方法に関するドキュメントはありますか?

4

4 に答える 4

15

これが(ハックな)解決策です:まず、OSProcessが必要なので、ワークスペースでこれを実行します:

Gofer new squeaksource:'OSProcess'; package:'OSProcess';load.

次に、これをファイル repl.st に入れます。

OSProcess thisOSProcess stdOut 
  nextPutAll: 'Welcome to the simple Smalltalk REPL'; 
  nextPut: Character lf; nextPut: $>; flush.
[ |input|
  [ input := OSProcess readFromStdIn.
    input size > 0 ifTrue: [
      OSProcess thisOSProcess stdOut 
        nextPutAll: ((Compiler evaluate: input) asString; 
        nextPut: Character lf; nextPut: $>; flush 
    ]
  ] repeat.
]forkAt: (Processor userBackgroundPriority)

最後に、次のコマンドを実行します。

squeak -headless path/to/squeak.image /absolute/path/to/repl.st

Smalltalk REPL を楽しむことができるようになりました。次のコマンドを忘れずに入力してください。

Smalltalk snapshot:true andQuit:true

変更を保存したい場合。

さて、このソリューションの説明に移りましょう: OSProcess は、他のプロセスを実行し、stdin から読み取り、stdout と stderr に書き込むことができるパッケージです。OSProcess thisOSProcess(現在のプロセス、別名squeak)でstdout AttachableFileStreamにアクセスできます。

次に、userBackgroundPriority で無限ループを実行します (他のプロセスを実行させるため)。この無限ループでは、 を使用Compiler evaluate:して入力を実行します。

これを、ヘッドレス イメージを含むスクリプトで実行します。

于 2011-05-24T09:00:21.840 に答える
8

Pharo 2.0 (および以下で説明する修正を加えた 1.3/1.4) では、ハッキングは必要ありません。次のスニペットは、バニラの Pharo イメージを REPL サーバーに変換します...

https://gist.github.com/2604215から:

"Works out of the box in Pharo 2.0. For prior versions (definitely works in 1.3 and 1.4), first file in https://gist.github.com/2602113"

| command |
[
    command := FileStream stdin nextLine.
    command ~= 'exit' ] whileTrue: [ | result |
        result := Compiler evaluate: command.
        FileStream stdout nextPutAll: result asString; lf ].

Smalltalk snapshot: false andQuit: true.

イメージを常に REPL にしたい場合は、コードを #startup: メソッドに入れます。それ以外の場合は、次のように、REPL モードが必要なときにコマンド ラインでスクリプトを渡します。

"/path/to/vm" -headless "/path/to/Pharo-2.0.image" "/path/to/gistfile1.st"
于 2012-05-23T14:27:19.273 に答える
0

プロジェクトhttp://www.squeaksource.com/SecureSqueak.htmlには、探しているものの多くを提供する可能性のあるREPLパッケージが含まれています。

于 2011-05-19T14:37:33.557 に答える