Merge pull request #4 from nineties/add_private

Add private
This commit is contained in:
Koichi NAKAMURA 2021-01-17 13:07:03 +09:00 committed by GitHub
commit 20b5a8a123
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 1 deletions

View file

@ -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

View file

@ -13,5 +13,7 @@ include test/utilities.fs
include test/errorreport.fs
include test/coreexttest.fs
include test/export.fs
report-errors
report-and-exit

31
test/export.fs Normal file
View file

@ -0,0 +1,31 @@
\ planckforth -
\ Copyright (C) 2021 nineties
testing private and export
: f1 ;
private{
: f2 ;
T{ defined? f1 -> true }T
T{ defined? f2 -> true }T
private{
: f3 ;
T{ defined? f2 -> true }T
T{ defined? f3 -> true }T
}private
T{ defined? f1 -> true }T
T{ defined? f2 -> true }T
T{ defined? f3 -> false }T
}private
T{ defined? f1 -> true }T
T{ defined? f2 -> false }T
T{ defined? f3 -> false }T