From bda310f7c93c99d58c3e210a290f2c0f80e494cc Mon Sep 17 00:00:00 2001 From: flrl Date: Mon, 29 Jun 2009 12:44:35 +0000 Subject: [PATCH] Added NDROP to builtin.c Added COUNT to base.fs --- TODO | 2 +- base.fs | 1 + builtin.c | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 553c62b..eea0fc7 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,7 @@ then just no-op (and maybe print a warning) <- sorta done, but needs more thought * debug primitives -- SEE, DUMP, etc * proper test suite built around ASSERT -* don't like my NDUP or ASSERT implementations -- rewrite (use user memory?) + diff --git a/base.fs b/base.fs index c3c2612..4900374 100644 --- a/base.fs +++ b/base.fs @@ -70,3 +70,4 @@ : CONSTANT CREATE DFA>CFA DOCON SWAP ! , ; : EXIT IMMEDIATE NOINTERPRET 0 , ; DEC 32 CONSTANT BL +: COUNT DUP 1+ SWAP C@ ; diff --git a/builtin.c b/builtin.c index f2343c6..8036554 100644 --- a/builtin.c +++ b/builtin.c @@ -417,8 +417,19 @@ PRIMITIVE ("2DROP", 0, _2DROP, _negROT) { } +// ( n*a n -- ) +PRIMITIVE ("NDROP", 0, _NDROP, _2DROP) { + REG(n); + + DPOP(n); + n = data_stack.index - n; + n = (n >= -1 ? n : -1); + data_stack.index = n; +} + + // ( b a -- b a b a ) -PRIMITIVE ("2DUP", 0, _2DUP, _2DROP) { +PRIMITIVE ("2DUP", 0, _2DUP, _NDROP) { REG(a); REG(b); @@ -1327,7 +1338,7 @@ PRIMITIVE ("LITSTRING", 0, _LITSTRING, _0BRANCH) { } -// ( -- ) +// ( addr len -- ) PRIMITIVE ("TELL", 0, _TELL, _LITSTRING) { REG(a); REG(b);