继续记录PC和寄存器状态吗?

发布于 2024-10-28 09:10:15 字数 883 浏览 1 评论 0原文

目前,当我在函数式语言中试验延续时,我的理解是延续记录了当前的程序计数器和寄存器文件,当延续返回时,PC和注册的文件将恢复为其记录的值。

因此,在以下来自 的愚蠢示例中可能的博文

; right-now : -> moment
(define (right-now)
  (call-with-current-continuation 
   (lambda (cc) 
     (cc cc))))

; go-when : moment -> ...
(define (go-when then)
  (then then))  


; An infinite loop:
(let ((the-beginning (right-now)))
  (display "Hello, world!")
  (newline)
  (go-when the-beginning))  ; here the-beginning continuation passed to go-when, which ultimately will have an continuation applied to an continuation, that returns a continuation, which will cause the the program point resumed to the PC and registers states recorded in it.

我不确定我的理解是否正确。如果您认为不对,请纠正我......

currently, when I am experimenting the continuation in functional languages, my understanding is that a continuation records the current program counter and register files, and when a continuation is returned, then the PC and the registered files will be restored to the values it has recorded.

So in the following dumb example from Might's blog post,

; right-now : -> moment
(define (right-now)
  (call-with-current-continuation 
   (lambda (cc) 
     (cc cc))))

; go-when : moment -> ...
(define (go-when then)
  (then then))  


; An infinite loop:
(let ((the-beginning (right-now)))
  (display "Hello, world!")
  (newline)
  (go-when the-beginning))  ; here the-beginning continuation passed to go-when, which ultimately will have an continuation applied to an continuation, that returns a continuation, which will cause the the program point resumed to the PC and registers states recorded in it.

I am not sure my understanding right.. Please correct me if you think it is not.....

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

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

发布评论

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

评论(1

執念 2024-11-04 09:10:15

程序计数器和寄存器文件不是延续记录的。

描述 call-with-current-continuation 含义的最好方式是它记录了程序上下文。例如,假设您正在评估程序

(+ 3 (f (call-with-current-continuation g)))

,在这种情况下,call-with-current-continuation 表达式的上下文将是

(+ 3 (f [hole]))

,即当前表达式周围的内容。

Call-with-current-continuation 捕获这些上下文之一。调用延续会导致当前上下文替换为延续中存储的上下文。

上下文的概念很像堆栈,只是上下文中的函数调用没有什么特别之处。

这是一个非常简短的治疗。我强烈建议您看一下 Shriram Krishnamurthi 的(免费在线)书PLAI,特别是第七部分,更详细、更仔细地了解这个主题。

Program counter and register files are not what the continuation records.

The best way to describe the meaning of call-with-current-continuation is that it records the program context. For instance, suppose you're evaluating the program

(+ 3 (f (call-with-current-continuation g)))

In this case, the context of the call-with-current-continuation expression would be

(+ 3 (f [hole]))

That is, the stuff surrounding the current expression.

Call-with-current-continuation captures one of these contexts. Invoking a continuation causes the replacement of the current context with the one stored in the continuation.

The idea of a context is a lot like that of a stack, except that there's nothing special about function calls in contexts.

This is a very brief treatment. I strongly urge you to take a look at Shriram Krishnamurthi's (free, online) book PLAI, in particular Part VII, for a more detailed and careful look at this topic.

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