从 shell 中使用 Squeak

发布于 2024-09-06 06:49:31 字数 110 浏览 3 评论 0原文

我可以将 Squeak 作为 REPL(无 GUI)启动,以便在其中输入和计算 Smalltalk 表达式吗?我知道默认图像不允许这样做。是否有任何有关如何构建可从命令行 shell 访问的最小映像的文档?

Can I launch Squeak as a REPL (no GUI), where I can enter and evaluate Smalltalk expressions? I know the default image don't allow this. Is there any documentation on how to build a minimum image that can be accessed from a command-line shell?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一曲爱恨情仇 2024-09-13 06:49:31

这是一个(hackish)解决方案:
首先,您需要 OSProcess,因此在工作区中运行此命令:

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

接下来,将其放入文件 repl.st 中:

OSProcess thisOSProcess stdOut 
  nextPutAll: 'Welcome to the simple Smalltalk REPL'; 
  nextPut: Character lf; nextPut: 
gt;; flush.
[ |input|
  [ input := OSProcess readFromStdIn.
    input size > 0 ifTrue: [
      OSProcess thisOSProcess stdOut 
        nextPutAll: ((Compiler evaluate: input) asString; 
        nextPut: Character lf; nextPut: 
gt;; 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 处运行无限循环(以让其他进程运行)。在此无限循环中,您使用编译器评估:来执行输入。

然后您在带有无头图像的脚本中运行它。

Here is a (hackish) solution:
First, you need OSProcess, so run this in a Workspace:

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

Next, put this in the file repl.st:

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

And last, run this command:

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

You can now have fun with a Smalltalk REPL. Dont forget to type in the command:

Smalltalk snapshot:true andQuit:true

if you want to save your changes.

Now, onto the explanation of this solution:
OSProcess is a package that allows to run other processes, read from stdin, and write to stdout and stderr. You can access the stdout AttachableFileStream with OSProcess thisOSProcess (the current process, aka squeak).

Next, you run an infinite loop at userBackgroundPriority (to let other processes run). In this infinite loop, you use Compiler evaluate: to execute the input.

And you run this in a script with a headless image.

愁杀 2024-09-13 06:49:31

从 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"

As of Pharo 2.0 (and 1.3/1.4 with the fix described below), there are no more hacks necessary. The following snippet will turn your vanilla Pharo image into a REPL server...

From 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.

If you want the image to always be a REPL, put the code in a #startup: method; otherwise, pass the script at the command line when you want REPL mode, like:

"/path/to/vm" -headless "/path/to/Pharo-2.0.image" "/path/to/gistfile1.st"
吾性傲以野 2024-09-13 06:49:31

该项目 http://www.squeaksource.com/SecureSqueak.html 包含一个 REPL 包,可以提供您正在寻找的大部分内容。

The project http://www.squeaksource.com/SecureSqueak.html includes a REPL package that may provide much of what you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文