在自我语言中,我们如何在其VM上运行代码?

时间:2012-10-03 09:29:15

标签: self selflanguage

如果使用http://selflanguage.org/上的文件在Ubuntu上安装了Self,那么我们可以使用

$ Self
Self Virtual Machine Version 4.1.13, Sat 20 Feb 10 22:39:48 Linux
Copyright 1989-2003: The Self Group (type _Credits for credits)

for I386:  LogVMMessages = true
for I386:  PrintScriptName  = true
for I386:  Inline = true
for I386:  SICDeferUncommonBranches = false (not implemented)
for I386:  SICReplaceOnStack = false (not implemented)
for I386:  SaveOutgoingArgumentsOfPatchedFrames = true

但是,无法运行一些简单的行:

VM# 'Hello, World!' print.
A lookup error happened while sending the message
    print
to
    'Hello, World!'.
Subsequently, the lookup error message
    undefinedSelector:Receiver:Type:Delegatee:MethodHolder:Arguments:
was sent to
    <0>,
and was also not understood, causing the process to be aborted by the Self VM.

#0 (<error>:1): print = ( | self* = 'Hello, World!'. delegatee = nil. selector = 'print'. | 
"undefined selector error;
this method was automatically generated by the VM."
 )


#1 (<stdin>:1): <top level expr> = ( | self* = lobby. | 'Hello, World!' print )

或另一个尝试插槽:

VM# _AddSlots: (| vehicle <- (|parent* = traits clonable|) |).
A lookup error happened while sending the message
    traits
to
    lobby.
Subsequently, the lookup error message
    undefinedSelector:Receiver:Type:Delegatee:MethodHolder:Arguments:
was sent to
    <0>,
and was also not understood, causing the process to be aborted by the Self VM.

#0 (<error>:1): traits = ( | self* = lobby. delegatee = nil. selector = 'traits'. | 
"undefined selector error;
this method was automatically generated by the VM."
 )


#1 (<stdin>:1): <top level expr> = ( | self* = lobby. | traits clonable )


                             ^
Self VM error: couldn't construct object literal on line 1, character 30
               ^
Self VM error: couldn't construct object literal on line 1, character 16
VM#

有人知道如何让它发挥作用吗?

1 个答案:

答案 0 :(得分:3)

你遇到的是那种最基本的自我形式。

VM本身只知道很少的消息。它们包括所有原语 以及一些消息,例如bootstrap

如果您尝试使用_Quit'some/path/to/self/script' _RunScript之类的内容 将起作用,因为这些是始终可用的基元。

如果你想要一个工作环境,你必须

  • 通过使用-s选项启动VM来加载快照:

    Self -s mySnapshot.snap
    

    您可以在自己的主页上找到快照。

  • 运行世界建筑脚本。为此,您需要objects目录 自带的。如果找不到,请使用github page中的一个。然后,将工作目录更改为objects目录并运行世界构建器脚本。

    cd $PATH_TO_OBJECTS/objects
    Self -f worldBuilder.self
    

    或者,将SELF_WORKING_DIR环境变量指向包含 objects目录的目录并运行sctipt。

    SELF_WORKING_DIR=$PATH_TO_OBJECTS Self -f s$PATH_TO_OBJECTS/worldBuilder.self
    

这引导了一个自我世界,应该理解每个已知的信息。

PS:当然,您还可以在正在运行的VM中运行单词构建器脚本:'/path/to/dir/with/objects/worldBuilder.self' _RunScript'。但请确保已设置SELF_WORKING_DIR。