vibe了一个stream io函数库

感觉还可以呀~ 除了 symbol table 保存的居然是 symbol name 而非 symbol 本身,都是很正统、很普遍的写法。cons 前保护引用,cons 后解除什么的,也都很常见。总之目前没什么问题。

建议的话,比如 GC 可以改成

void **root = NULL;
size_t total_allocated = 0;
void *gc_alloc(size_t s) {
  void **res = (void **)malloc(s + sizeof(void *) * 2);
  assert(("allocation fail", res != NULL));
  total_allocated += s + 2;
  res[0] = (voie *)root; root = res;
  res[1] = s;
  // rmaybe res[2] is type?
  return res + 2;
}

void gc() {
  void **p = root;
  while (p != NULL) {
    void **next = (void **)p[0];
    if (!scanned(p)) free(p);
    p = next;
  }
}

又比如,现在的代码命名又有点不清晰?以及为了精确回收,可以使用一些宏?类似

/* I believe this function could be inlined */
INLINE void __protect(int n, ref *xs) {
  int i;
  for (i = 0; i < n; i++) push(xs[i]);
}
#define protect(...) (__protect(sizeof((ref[]){__VA_ARGS__})/sizeof(ref), (ref[]){__VA_ARGS__});
// see the following link for the technology 
// https://github.com/emacs-mirror/emacs/blob/9a431e431ad92f94f4290c3f0bf043b0f97a7b56/src/lisp.h#L4492

然后就可以用 protect(a, b) 来保护 a、b 两个变量了。

谢谢。现在我头痛的地方主要是写了太多递归函数,包括gc,read,print,这些函数仍然依赖C堆栈,要一口气清理掉才行。当前的版本我觉得做的很烂,要改却总是改不紧凑。不想仿照C栈做,在尝试构思lisp和c可以共享的call protocol。

如果你还有好的想法,就写信给我吧!

可以查一下 trampoline 技术,不过这个写起来很痛苦

重新声明:本人从未在互联网上诋毁过深度求索,并没有称梁文锋为梁子或牢梁。本人实际上是深度求索一年老粉,经过长时间的思考,我发现Deepseek才是中国AI的希望,有时候做出决定很难,经过许多个日夜的思考,我决定加入Deepseek粉丝团。至于Kimi,GLM和Minimax,祝他们的开源模型一切顺利。

怎么才一年老粉,从 R1 开始算得多久了

2 个赞

其实才3个月(逃; dsv4出来前一直在用claude

1 个赞