From a41845693ff9bee3037e767890a65ff63d55b5a8 Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Wed, 8 Dec 2021 06:11:20 +0900 Subject: [PATCH] Add "enum" --- lib/core.fs | 14 ++++++++++++++ test/core.fs | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/lib/core.fs b/lib/core.fs index 956c5ee..297ee6d 100644 --- a/lib/core.fs +++ b/lib/core.fs @@ -40,4 +40,18 @@ end-struct cons-cell% : car first @ ; export : cdr second @ ; export +( === Enum === ) + +\ 0 +\ enum A +\ enum B +\ drop + +\ 0 constant A +\ 1 constant B + +: enum ( n "name" -- n ) + dup constant 1+ +; export + }private diff --git a/test/core.fs b/test/core.fs index c900cd6..8c442bc 100644 --- a/test/core.fs +++ b/test/core.fs @@ -1013,4 +1013,10 @@ T{ cons0 cdr -> 1 }T cons0 free +\ ------------------------------------------------------------------------ +testing enum +T{ 0 enum e0 enum e1 enum e2 drop -> }T +T{ e0 -> 0 }T +T{ e1 -> 1 }T +T{ e2 -> 2 }T