From bb9b440337cb730488b3d9e33e52fc3259de5318 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Thu, 31 Dec 2020 06:25:40 +0900 Subject: [PATCH] Add "{" and "}" --- core.fs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/core.fs b/core.fs index c407f8c..a3995e1 100644 --- a/core.fs +++ b/core.fs @@ -145,6 +145,37 @@ l! \ '_' ( a -- ) DROP c_ i, 'd, 'C, '+, 'D, 'e, l! -\ Test -kA kB _ t \ -> A +\ '#' ( a -- a a ) DUP +c# i, 'd, '@, 'e, l! + + + +\ Implementations of TOR and FROMR are a bit tricky. +\ Since return-address will be placed at the top of return stack, +\ the code in the body of these function have to manipulate +\ 2nd element of the stack. + +\ '{' ( a -- R:a ) TOR +\ Move value from data stack to return stack. +c{ i, + 'r, 'r, '@, \ ( a rsp ret ) + 'r, 'C, '-, '#, \ ( a rsp ret rsp-CELL rsp-CELL ) + 'R, \ ( a rsp+CELL ret rsp ) extend return stack + '!, \ ( a rsp+CELL ) store return address to the top + '!, \ store a to the 2nd + 'e, +l! + +\ '}' ( R:a -- a ) FROMR +\ Move value from return stack to data stack. +c} i, + 'r, 'C, '+, '@, \ ( a ) load 2nd value + 'r, '@, \ ( a ret ) load return addr + 'r, 'C, '+, '#, \ ( a ret rsp+CELL rsp+CELL ) + 'R, \ ( a ret rsp ) reduce return stack + '!, \ ( a , R:ret ) store return addr to top of return stack + 'e, +l! + +kA kB { t } t Q