You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

第三栈(3rd Stack)问题:为何VFX Forth正常,其他Forth环境偶尔失效?

第三栈实现的跨Forth环境兼容性问题

这段模仿JForth实现的第三栈代码在VFX Forth中运行完全正常,但在Swift Forth、Win32Forth和GForth里仅能偶尔成功运行。异常点在于这三款Forth环境无法处理点引号字符串(dot-quote string)两侧调用栈操作的情况。

\ 模仿JForth实现的第三栈

CREATE us_ptr 0 C,
CREATE us 32 CELLS ALLOT
us 32 CELLS ERASE
: us? ( -- u ) us_ptr C@ ; \ 循环索引:0, 255, 254 ... 2, 1, 0
: >us ( n -- ) -1 us_ptr C+! us us? CELLS + ! ;
: us@ ( -- n ) us us? CELLS + @ ;
: us> ( -- n ) us@ 1 us_ptr C+! ;

: test.3rd.stack
  CR CR ." 测试用户栈."

  CR ." 将在循环中推入10个值."

  11 0 DO I >us LOOP
  CR ." 循环推入10次成功!"

  CR CR ." 现在获取并取出栈顶值."

  CR ." 若us@返回10则成功:" us@ .
  CR ." 若us>返回10则成功:" us> .

  CR CR ." 对新的栈顶值重复测试."
  CR ." 若us@返回9则成功:" us@ .
  CR ." 若us>返回9则成功:" us> .

  CR CR ." 换种方式测试下一个值."
  CR ." 在GForth和Swift Forth中测试会在此处终止."
  CR ." 若us@返回8则成功:" us@ . ." = 8"
  CR ." 若us>返回8则成功:" us> . ." = 8"

  CR CR ." Win32Forth会在此处抛出错误信息."

  CR CR ." 但VFX Forth能正常运行到结尾." CR
;

test.3rd.stack

内容的提问来源于stack exchange,提问作者Gan Uesli Starling

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 03:07:20