From 5d758cc15f9d472801630968fcc088e7da0a7a4c Mon Sep 17 00:00:00 2001 From: Koichi Nakamura Date: Sun, 17 Jan 2021 12:38:10 +0900 Subject: [PATCH] Implement private and export --- bootstrap.fs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/bootstrap.fs b/bootstrap.fs index 254c723..985f1c1 100644 --- a/bootstrap.fs +++ b/bootstrap.fs @@ -2511,6 +2511,38 @@ need-defined (read) @ &latest ! ; +( === Private and Export === ) + +\ Words defined between private{ ... }private +\ are invisible outside of this scope. +\ You can export words using 'export'. +\ : name .... ; export + +: private{ + align + latest , + here cell- &latest ! + s" private-marker" dup strlen + c, strcpy, align +; + +: }private + s" private-marker" find! name>link @ &latest ! +; + +: export + \ Move latest to the boottm of the dictionary. + latest + begin dup name>link while + name>link + repeat + latest + ( last latest ) + dup name>link &latest ! + 0 over ! + swap ! +; + ( === Primitive Instructions === ) : insn:docol docol ; @@ -2553,7 +2585,7 @@ need-defined (read) include included source >in next-arg shift-args arg argv argc version runtime copyright - [if] [unless] [else] [then] defined? + [if] [unless] [else] [then] defined? private{ }private export open-file close-file write-file flush-file read-file key-file read-line R/W W/O R/O EOF