Adding docs high level float words.
This commit is contained in:
@ -12,7 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
VERSION=7.0.6.4
|
VERSION=7.0.6.5
|
||||||
STABLE_VERSION=7.0.5.4
|
STABLE_VERSION=7.0.5.4
|
||||||
REVISION=$(shell git rev-parse HEAD)
|
REVISION=$(shell git rev-parse HEAD)
|
||||||
REVSHORT=$(shell echo $(REVISION) | head -c 7)
|
REVSHORT=$(shell echo $(REVISION) | head -c 7)
|
||||||
@ -248,8 +248,8 @@ $(POSIX):
|
|||||||
$(POSIX)/ueforth: \
|
$(POSIX)/ueforth: \
|
||||||
posix/posix_main.c \
|
posix/posix_main.c \
|
||||||
common/opcodes.h \
|
common/opcodes.h \
|
||||||
common/floats.h \
|
|
||||||
common/calls.h \
|
common/calls.h \
|
||||||
|
common/floats.h \
|
||||||
common/interp.h \
|
common/interp.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
$(GEN)/posix_boot.h | $(POSIX)
|
$(GEN)/posix_boot.h | $(POSIX)
|
||||||
@ -264,8 +264,8 @@ $(WINDOWS):
|
|||||||
$(WINDOWS)/uEf32.obj: \
|
$(WINDOWS)/uEf32.obj: \
|
||||||
windows/windows_main.c \
|
windows/windows_main.c \
|
||||||
common/opcodes.h \
|
common/opcodes.h \
|
||||||
common/floats.h \
|
|
||||||
common/calls.h \
|
common/calls.h \
|
||||||
|
common/floats.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
windows/windows_interp.h \
|
windows/windows_interp.h \
|
||||||
$(GEN)/windows_boot.h | $(WINDOWS)
|
$(GEN)/windows_boot.h | $(WINDOWS)
|
||||||
@ -279,8 +279,8 @@ $(WINDOWS)/uEf32.exe: \
|
|||||||
$(WINDOWS)/uEf64.obj: \
|
$(WINDOWS)/uEf64.obj: \
|
||||||
windows/windows_main.c \
|
windows/windows_main.c \
|
||||||
common/opcodes.h \
|
common/opcodes.h \
|
||||||
common/floats.h \
|
|
||||||
common/calls.h \
|
common/calls.h \
|
||||||
|
common/floats.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
windows/windows_interp.h \
|
windows/windows_interp.h \
|
||||||
$(GEN)/windows_boot.h | $(WINDOWS)
|
$(GEN)/windows_boot.h | $(WINDOWS)
|
||||||
@ -298,8 +298,8 @@ $(ESP32)/ESP32forth:
|
|||||||
|
|
||||||
ESP32_PARTS = esp32/template.ino \
|
ESP32_PARTS = esp32/template.ino \
|
||||||
common/opcodes.h \
|
common/opcodes.h \
|
||||||
common/floats.h \
|
|
||||||
common/calling.h \
|
common/calling.h \
|
||||||
|
common/floats.h \
|
||||||
common/core.h \
|
common/core.h \
|
||||||
common/interp.h \
|
common/interp.h \
|
||||||
$(GEN)/esp32_boot.h
|
$(GEN)/esp32_boot.h
|
||||||
|
|||||||
@ -62,3 +62,40 @@ e: test-throw
|
|||||||
foo cr
|
foo cr
|
||||||
out: 1 99.000000
|
out: 1 99.000000
|
||||||
;e
|
;e
|
||||||
|
|
||||||
|
e: test-fconstant
|
||||||
|
100e fconstant foo
|
||||||
|
foo f. cr
|
||||||
|
out: 100.000000
|
||||||
|
;e
|
||||||
|
|
||||||
|
e: test-fvariable
|
||||||
|
fvariable foo
|
||||||
|
100e foo sf!
|
||||||
|
foo sf@ fdup f* foo sf!
|
||||||
|
foo sf@ f. cr
|
||||||
|
out: 10000.000000
|
||||||
|
;e
|
||||||
|
|
||||||
|
e: test-fcompare
|
||||||
|
123e 245e f< assert
|
||||||
|
123e 66e f> assert
|
||||||
|
123e 123e f>= assert
|
||||||
|
124e 123e f>= assert
|
||||||
|
123e 123e f<= assert
|
||||||
|
123e 124e f<= assert
|
||||||
|
123e 124e f<> assert
|
||||||
|
123e 123e f= assert
|
||||||
|
;e
|
||||||
|
|
||||||
|
e: test-fliteral
|
||||||
|
: foo [ 123e ] fliteral f. cr ;
|
||||||
|
foo
|
||||||
|
out: 123.000000
|
||||||
|
;e
|
||||||
|
|
||||||
|
e: test-afliteral
|
||||||
|
: foo [ 123e afliteral ] f. cr ;
|
||||||
|
foo
|
||||||
|
out: 123.000000
|
||||||
|
;e
|
||||||
|
|||||||
@ -12,6 +12,26 @@
|
|||||||
\ See the License for the specific language governing permissions and
|
\ See the License for the specific language governing permissions and
|
||||||
\ limitations under the License.
|
\ limitations under the License.
|
||||||
|
|
||||||
|
: f= ( r r -- f ) f- f0= ;
|
||||||
|
: f< ( r r -- f ) f- f0< ;
|
||||||
|
: f> ( r r -- f ) fswap f< ;
|
||||||
|
: f<> ( r r -- f ) f= 0= ;
|
||||||
|
: f<= ( r r -- f ) f> 0= ;
|
||||||
|
: f>= ( r r -- f ) f< 0= ;
|
||||||
|
|
||||||
|
4 constant sfloat
|
||||||
|
: sfloats ( n -- n*4 ) sfloat * ;
|
||||||
|
: sfloat+ ( a -- a ) sfloat + ;
|
||||||
|
: sf, ( r -- ) here sf! sfloat allot ;
|
||||||
|
|
||||||
|
: afliteral ( r -- ) ['] DOFLIT , sf, align ;
|
||||||
|
: fliteral afliteral ; immediate
|
||||||
|
|
||||||
|
: fconstant ( r "name" ) create sf, align does> sf@ ;
|
||||||
|
: fvariable ( "name" ) create sfloat allot align ;
|
||||||
|
|
||||||
|
3.14159265359e fconstant pi
|
||||||
|
|
||||||
: fsqrt ( r -- r ) 1e 20 0 do fover fover f/ f+ 0.5e f* loop fnip ;
|
: fsqrt ( r -- r ) 1e 20 0 do fover fover f/ f+ 0.5e f* loop fnip ;
|
||||||
|
|
||||||
6 value precision
|
6 value precision
|
||||||
@ -21,17 +41,10 @@ internals definitions
|
|||||||
: #f+s ( r -- ) fdup precision 0 ?do 10e f* loop
|
: #f+s ( r -- ) fdup precision 0 ?do 10e f* loop
|
||||||
precision 0 ?do fdup f>s 10 mod [char] 0 + hold 0.1e f* loop
|
precision 0 ?do fdup f>s 10 mod [char] 0 + hold 0.1e f* loop
|
||||||
[char] . hold fdrop f>s #s ;
|
[char] . hold fdrop f>s #s ;
|
||||||
|
transfer doflit
|
||||||
forth definitions internals
|
forth definitions internals
|
||||||
|
|
||||||
: #fs ( r -- ) fdup f0< if fnegate #f+s [char] - hold else #f+s then ;
|
: #fs ( r -- ) fdup f0< if fnegate #f+s [char] - hold else #f+s then ;
|
||||||
: f. ( r -- ) <# #fs #> type space ;
|
: f. ( r -- ) <# #fs #> type space ;
|
||||||
|
|
||||||
(
|
|
||||||
internals definitions
|
|
||||||
$80000000 constant sign-mask
|
|
||||||
$7f800000 constant exp-mask
|
|
||||||
$3f000000 constant half-mask
|
|
||||||
$007fffff constant mantissa-mask
|
|
||||||
)
|
|
||||||
|
|
||||||
forth definitions
|
forth definitions
|
||||||
|
|||||||
@ -24,7 +24,8 @@
|
|||||||
X("FOVER", FOVER, fp[1] = fp[-1]; ++fp) \
|
X("FOVER", FOVER, fp[1] = fp[-1]; ++fp) \
|
||||||
X("FSWAP", FSWAP, float ft = fp[-1]; fp[-1] = *fp; *fp = ft) \
|
X("FSWAP", FSWAP, float ft = fp[-1]; fp[-1] = *fp; *fp = ft) \
|
||||||
X("FNEGATE", FNEGATE, *fp = -*fp) \
|
X("FNEGATE", FNEGATE, *fp = -*fp) \
|
||||||
X("F0<", FZLESS, DUP; tos = *fp-- < 0 ? -1 : 0) \
|
X("F0<", FZLESS, DUP; tos = *fp-- < 0.0f ? -1 : 0) \
|
||||||
|
X("F0=", FZEQUAL, DUP; tos = *fp-- == 0.0f ? -1 : 0) \
|
||||||
X("F+", FPLUS, fp[-1] += *fp; --fp) \
|
X("F+", FPLUS, fp[-1] += *fp; --fp) \
|
||||||
X("F-", FMINUS, fp[-1] -= *fp; --fp) \
|
X("F-", FMINUS, fp[-1] -= *fp; --fp) \
|
||||||
X("F*", FSTAR, fp[-1] *= *fp; --fp) \
|
X("F*", FSTAR, fp[-1] *= *fp; --fp) \
|
||||||
|
|||||||
@ -33,9 +33,9 @@ function DropCopyright(source) {
|
|||||||
var version = process.argv[2];
|
var version = process.argv[2];
|
||||||
var revision = process.argv[3];
|
var revision = process.argv[3];
|
||||||
var code = fs.readFileSync(process.argv[4]).toString();
|
var code = fs.readFileSync(process.argv[4]).toString();
|
||||||
var floats = DropCopyright(fs.readFileSync(process.argv[5]).toString());
|
var opcodes = DropCopyright(fs.readFileSync(process.argv[5]).toString());
|
||||||
var opcodes = DropCopyright(fs.readFileSync(process.argv[6]).toString());
|
var calling = DropCopyright(fs.readFileSync(process.argv[6]).toString());
|
||||||
var calling = DropCopyright(fs.readFileSync(process.argv[7]).toString());
|
var floats = DropCopyright(fs.readFileSync(process.argv[7]).toString());
|
||||||
var core = DropCopyright(fs.readFileSync(process.argv[8]).toString());
|
var core = DropCopyright(fs.readFileSync(process.argv[8]).toString());
|
||||||
var interp = DropCopyright(fs.readFileSync(process.argv[9]).toString());
|
var interp = DropCopyright(fs.readFileSync(process.argv[9]).toString());
|
||||||
var boot = DropCopyright(fs.readFileSync(process.argv[10]).toString());
|
var boot = DropCopyright(fs.readFileSync(process.argv[10]).toString());
|
||||||
|
|||||||
@ -124,6 +124,68 @@ SEE ( "name" -- ) Attempt to decompile a word
|
|||||||
ECHO ( -- a ) -- Address of flag that determines if commands are echoed
|
ECHO ( -- a ) -- Address of flag that determines if commands are echoed
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<h5>Floating-Point</h5>
|
||||||
|
<p><b>(Requires v7.0.6.5+)</b></p>
|
||||||
|
<p>
|
||||||
|
Single precision floating-point support is available as a work in progress.
|
||||||
|
While initially left out in the name of minimalism,
|
||||||
|
hardware support for floating-point argues some advantages to limited support.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Floating point is kept on a separate stack.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<b>NOTE: Tasks currently don't correctly support floating point.</b>
|
||||||
|
A single floating point stack is shared by all tasks.
|
||||||
|
</p>
|
||||||
|
<pre>
|
||||||
|
FLOAT OPCODES
|
||||||
|
-------------
|
||||||
|
DOFLIT ( --- ) Puts a float from the next cell onto float stack.
|
||||||
|
FP@ ( -- a )
|
||||||
|
FP! ( a -- )
|
||||||
|
SF@ ( a -- r ) Single precision load
|
||||||
|
SF! ( r a -- ) Single precision store
|
||||||
|
FDUP ( r -- r r )
|
||||||
|
FNIP ( ra rb -- rb )
|
||||||
|
FDROP ( r -- )
|
||||||
|
FOVER ( ra rb -- ra rb ra )
|
||||||
|
FSWAP ( ra rb -- rb ra )
|
||||||
|
F0< ( r -- f )
|
||||||
|
F0= ( r -- f )
|
||||||
|
F+ ( r r -- r )
|
||||||
|
F- ( r r -- r )
|
||||||
|
F* ( r r -- r )
|
||||||
|
F/ ( r r -- r )
|
||||||
|
1/F ( r -- r )
|
||||||
|
S>F ( n -- r )
|
||||||
|
F>S ( r -- n )
|
||||||
|
|
||||||
|
HIGH LEVEL
|
||||||
|
----------
|
||||||
|
F= ( r r -- f )
|
||||||
|
F< ( r r -- f )
|
||||||
|
F> ( r r -- f )
|
||||||
|
F<= ( r r -- f )
|
||||||
|
F>= ( r r -- f )
|
||||||
|
F<> ( r r -- f )
|
||||||
|
|
||||||
|
SFLOAT ( -- 4 )
|
||||||
|
SFLOATS ( n -- n*4 )
|
||||||
|
SFLOAT+ ( a -- a+4 )
|
||||||
|
SF, ( r -- )
|
||||||
|
|
||||||
|
AFLITERAL ( r -- )
|
||||||
|
FLITERAL ( r -- ) IMMEDIATE
|
||||||
|
|
||||||
|
FCONSTANT ( r "name" )
|
||||||
|
FVARAIABLE ( "name" )
|
||||||
|
|
||||||
|
PI ( -- r )
|
||||||
|
|
||||||
|
FSQRT ( r r -- r )
|
||||||
|
</pre>
|
||||||
|
|
||||||
<h5>Locals</h5>
|
<h5>Locals</h5>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
Reference in New Issue
Block a user