小编mat*_*141的帖子

在编译器中实现闭包

我试图设计一个基本编译器到伪汇编代码.但是,我无法弄清楚如何实现闭包.看来我需要将特定的寄存器值与每个"子程序"相关联.我已经考虑过使用堆栈了,但是再一次看起来不够.似乎没有任何关联数组可以工作,但是如何在汇编中完成它或类似的东西呢?

我选择尝试表示的示例如下,以CoffeeScript形式传达以简洁.

((x) -> (y) -> x(y))((x) -> x)(2)
Run Code Online (Sandbox Code Playgroud)

这是我一直在尝试的一般结构.这是我正在编译的伪程序集的示例.

'((label lam1)   ;; (x) -> x
  (cp resp arg)
  (ret)

  (label lam2)   ;; (y) -> x(y)
  (jmp x)

  (label lam3)   ;; (x) -> [(y) -> ...]
  (cp x arg)     ;; this is the assignment intended for a closure
  (cp resp lam2) ;; this is a returned lambda, needing the closure
  (ret)

  (label main)
  (cp arg lam1)
  (call lam3)
  (set arg 2)
  (call resp))) 
Run Code Online (Sandbox Code Playgroud)

这有效; 但是,只需在名称下设置值x,然后返回一个lambda,在x执行lambda之前,该值很容易被污染.

计算机程序的结构和解释中的实现描述如下,在组装中似乎不可行.我不知道他们可以使用什么其他策略. …

lisp compiler-construction assembly closures

8
推荐指数
1
解决办法
2755
查看次数

JSON.parse如何管理'undefined'?

我改变了这个:

function MangaElt(obj) {
  "use strict";
  this.mirror = obj.mirror;
  this.name = obj.name;
  this.url = obj.url;
  if (obj.lastChapterReadURL !== undefined) {
    this.lastChapterReadURL = obj.lastChapterReadURL;
    this.lastChapterReadName = obj.lastChapterReadName;
  } else {
    this.lastChapterReadURL = null;
    this.lastChapterReadName = null;
  }
  this.listChaps = [];
  if (obj.listChaps !== undefined && obj.listChaps !== null && obj.listChaps !== "null") {
    if (!isArray(obj.listChaps)) {
      this.listChaps = JSON.parse(obj.listChaps);
    }
  }
  this.read = 0;
  if (obj.read !== undefined && obj.read !== null && obj.read !== "null") {
    this.read = obj.read;
  } …
Run Code Online (Sandbox Code Playgroud)

javascript json

4
推荐指数
2
解决办法
2万
查看次数

Haskell递归类型

我试图在Haskell中创建一个函数,Resp在BNF和Haskell类型之间的奇怪混合中返回下面说明的类型.

elem ::= String | (String, String, Resp)
Resp ::= [elem]
Run Code Online (Sandbox Code Playgroud)

我的问题是(a)如何在Haskell中定义这种类型,以及(b)如果有一种方法这样做而不必强制使用自定义构造函数,例如Node,而是仅使用元组和数组.

recursion haskell types

3
推荐指数
2
解决办法
3162
查看次数