Skip to content

Commit

Permalink
PicForth 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Feb 6, 2015
1 parent 9a72831 commit 33e8d25
Show file tree
Hide file tree
Showing 9 changed files with 2,299 additions and 1,495 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

To understand the scope of these changes, please refer to the documentation.

* New in version 1.3

** Various

+ Use gforth 0.7.3 instead of gforth 0.6.x.

+ Use GPL v3 to follow gforth move.

* New in version 1.2.5

** New features
Expand Down
913 changes: 624 additions & 289 deletions COPYING

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PROGS= booster.hex generator.hex silver.hex \
librshift.hex liblshift.hex libnibble.hex libcmove.hex \
libstrings.hex libextra.hex

GFORTH?= gforth-0.6.2
GFORTH?= gforth-0.7.3
PAGER?= less

DISASM= ${PROGS:.hex=.disasm}
Expand All @@ -30,12 +30,10 @@ interactive:
${GFORTH} picforth.fs

.fs.hex: ${COMPILER} ${LIBRARIES}
${GFORTH} picforth.fs -e 'include $< file-dump ${<:.fs=.hex} \
write-map ${<:.fs=.map} bye'
${GFORTH} picforth.fs -e 'include $< file-dump ${<:.fs=.hex} write-map ${<:.fs=.map} bye'

.fs.disasm: ${COMPILER} ${LIBRARIES}
${GFORTH} picforth.fs -e 'include $< file-dump ${<:.fs=.hex} \
write-map ${<:.fs=.map} write-dis ${<:.fs=.disasm} bye'
${GFORTH} picforth.fs -e 'include $< file-dump ${<:.fs=.hex} write-map ${<:.fs=.map} write-dis ${<:.fs=.disasm} bye'

.hex.asm:
gpdasm $< > $@
Expand All @@ -49,7 +47,7 @@ interactive:
${GFORTH} picforth.fs -e 'include $< include serial.fs serprog bye'
# ${GFORTH} picforth.fs -e 'include $< include serial.fs serprog firmware bye'

RELEASEVERSION = 1.2.5
RELEASEVERSION = 1.3
DEVELOPMENTBRANCH = picforth-1

release:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ picforth

Forth compiler for Microchip PIC16Fxxx microcontrollers.

This compiler is no longer maintained and only works with gforth 0.6.3. It will *not* work with gforth 0.7.
This compiler has only been tested with gforth 0.7.3.
2 changes: 1 addition & 1 deletion doc/picforth.texi
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ anything else).
@section License

The compiler is released at the moment under the GNU General Public
License version 2 (I intend to use the less restrictive BSD license in
License version 3 (I intend to use the less restrictive BSD license in
the future, but as it is based on gforth, I have to sort out those
issues with gforth copyright holders).

Expand Down
98 changes: 61 additions & 37 deletions input.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
\ Input handling (object oriented) 22oct00py

\ Copyright (C) 2000,2003 Free Software Foundation, Inc.
\ Copyright (C) 2000,2003,2004,2005,2006,2007 Free Software Foundation, Inc.

\ This file is part of Gforth.

\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation; either version 2
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.

\ This program is distributed in the hope that it will be useful,
Expand All @@ -15,8 +15,7 @@
\ GNU General Public License for more details.

\ You should have received a copy of the GNU General Public License
\ along with this program; if not, write to the Free Software
\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
\ along with this program. If not, see http://www.gnu.org/licenses/.

\ input handling structure:

Expand All @@ -26,7 +25,7 @@ DOES> ( ... -- ... ) @ current-input @ @ + perform ;
DOES> ( -- addr ) @ current-input @ + ;

0
input-method source ( -- addr u ) \ core-ext,file source
input-method source ( -- addr u ) \ core source
\G Return address @i{addr} and length @i{u} of the current input
\G buffer
input-method refill ( -- flag ) \ core-ext,block-ext,file-ext
Expand All @@ -53,52 +52,66 @@ input-method source-id ( -- 0 | -1 | fileid ) \ core-ext,file source-i-d
drop

cell \ the first cell points to the method table
cell input-var >in \ core to-in
cell input-var >in ( -- addr ) \ core to-in
\G @code{input-var} variable -- @i{a-addr} is the address of a
\G cell containing the char offset from the start of the input
\G buffer to the start of the parse area.
cell input-var #tib \ core-ext number-t-i-b
2 cells input-var input-lexeme ( -- a-addr ) \ gforth-internal
\G @code{input-var} variable -- @i{a-addr} is the address of two
\G cells containing the string (in c-addr u form) parsed with
\G @code{parse}, @code{parse-name} or @code{word}. If you do your
\G own parsing, you can set it with @code{input-lexeme!}.
cell input-var #tib ( -- addr ) \ core-ext-obsolescent number-t-i-b
\G @code{input-var} variable -- @i{a-addr} is the address of a
\G cell containing the number of characters in the terminal input
\G buffer. OBSOLESCENT: @code{source} superceeds the function of
\G this word.
cell input-var max#tib \ gforth max-number-t-i-b
cell input-var max#tib ( -- addr ) \ gforth max-number-t-i-b
\G @code{input-var} variable -- This cell contains the maximum
\G size of the current tib.
cell input-var old-input \ gforth
cell input-var old-input ( -- addr ) \ gforth
\G @code{input-var} variable -- This cell contains the pointer to
\G the previous input buffer
cell input-var loadline \ gforth
cell input-var loadline ( -- addr ) \ gforth
\G @code{input-var} variable -- This cell contains the line that's
\G currently loaded from
1 [IF]
cell input-var loadfile \ gforth
has? file [IF]
cell input-var loadfile ( -- addr ) \ gforth
\G @code{input-var} variable -- This cell contains the file the
\G input buffer is associated with (0 if none)
cell input-var blk \ block
cell input-var blk ( -- addr ) \ block b-l-k
\G @code{input-var} variable -- This cell contains the current
\G block number
cell input-var #fill-bytes \ gforth
cell input-var #fill-bytes ( -- addr ) \ gforth
\G @code{input-var} variable -- number of bytes read via
\G (read-line) by the last refill
2 cells input-var loadfilename \ gforth
2 cells input-var loadfilename ( -- addr ) \ gforth
\G @code{input-var} variable -- addr u describes name of currently
\G interpreted input (file name or somesuch)
[THEN]
0 input-var tib
0 input-var tib ( -- addr ) \ core-ext-obsolescent t-i-b

Constant tib+

\ helper words

: input-lexeme! ( c-addr u -- )
\ record that the current lexeme us c-addr u
input-lexeme 2! ;

: input-start-line ( -- )
>in off source drop 0 input-lexeme! ;

\ terminal input implementation

:noname ( in 1 -- ) 1 <> -12 and throw >in ! ;
\ restore-input
:noname ( -- in 1 ) >in @ 1 ; \ save-input
' false \ source-id
:noname ( -- flag ) [ 1 [IF] ]
:noname ( -- flag ) [ has? file [IF] ]
stdin file-eof? IF false EXIT THEN [ [THEN] ]
tib max#tib @ accept #tib !
>in off true 1 loadline +! ; \ refill
input-start-line true 1 loadline +! ; \ refill
:noname ( -- addr u ) tib #tib @ ; \ source

| Create terminal-input A, A, A, A, A,
Expand All @@ -112,8 +125,9 @@ Constant tib+

\ file input implementation

1 [IF]
: read-line ( c_addr u1 wfileid -- u2 flag wior ) (read-line) nip ;
has? file [IF]
: read-line ( c_addr u1 wfileid -- u2 flag wior ) \ file
(read-line) nip ;

:noname ( in line# udpos 4 -- ) 4 <> -12 and throw
loadfile @ reposition-file throw
Expand All @@ -124,7 +138,7 @@ Constant tib+
4 ; \ save-input
:noname ( -- file ) loadfile @ ; \ source-id
:noname ( -- flag )
#tib off #fill-bytes off >in off
#tib off #fill-bytes off input-start-line
BEGIN
tib max#tib @ #tib @ /string
loadfile @ (read-line) throw #fill-bytes +!
Expand All @@ -151,17 +165,15 @@ terminal-input @ \ source -> terminal-input::source
: expand-tib ( n -- )
dup tib+ + current-input @ swap resize throw current-input !
max#tib ! tib max#tib @ #tib @ /string 0 fill ;
1 [IF]
has? file [IF]
: push-file ( -- ) \ gforth
\G Create a new file input buffer
file-input def#tib new-tib ;
[THEN]
: pop-file ( throw-code -- throw-code ) \ gforth
\G pop and free the current top input buffer
dup IF
source >in @ sourceline#
[ 1 [IF] ] sourcefilename [ [THEN] ]
>error
input-error-data >error
THEN
current-input @ old-input @ current-input ! free throw ;

Expand Down Expand Up @@ -193,16 +205,23 @@ terminal-input @ \ source -> terminal-input::source
terminal-input def#tib new-tib ;
\ s" *the terminal*" loadfilename 2!

: execute-parsing ( ... addr u xt -- ... )
\G Make @i{addr u} the current input source, execute @i{xt @code{(
\G ... -- ... )}}, then restore the previous input source.
>r evaluate-input cell new-tib
[ 1 [IF] ]
s" *evaluated string*" loadfilename 2!
: execute-parsing-wrapper ( ... addr1 u1 xt addr2 u2 -- ... ) \ gforth-internal
\ addr1 u1 is the string to be processed, xt is the word for
\ processing it, addr2 u2 is the name of the input source
rot >r 2>r evaluate-input cell new-tib 2r>
[ has? file [IF] ]
loadfilename 2!
[ [ELSE] ]
2drop
[ [THEN] ]
-1 loadline ! #tib ! tib !
r> catch pop-file throw ;

: execute-parsing ( ... addr u xt -- ... ) \ gforth
\G Make @i{addr u} the current input source, execute @i{xt @code{(
\G ... -- ... )}}, then restore the previous input source.
s" *evaluated string*" execute-parsing-wrapper ;

: evaluate ( ... addr u -- ... ) \ core,block
\G Save the current input source specification. Store @code{-1} in
\G @code{source-id} and @code{0} in @code{blk}. Set @code{>IN} to
Expand All @@ -219,18 +238,23 @@ terminal-input @ \ source -> terminal-input::source
current-input @ 0= IF create-input THEN
BEGIN old-input @ WHILE 0 pop-file drop REPEAT ;

: query ( -- ) \ core-ext
: query ( -- ) \ core-ext-obsolescent
\G Make the user input device the input source. Receive input into
\G the Terminal Input Buffer. Set @code{>IN} to zero. OBSOLESCENT:
\G superceeded by @code{accept}.
clear-tibstack refill drop ;
clear-tibstack refill 0= -39 and throw ;

\ load a file

1 [IF]
has? file [IF]
defer line-end-hook ( -- ) \ gforth
\G called at every end-of-line when text-interpreting from a file
\ alternatively we could use a wrapper for REFILL
' noop is line-end-hook

: read-loop ( i*x -- j*x ) \ gforth
\G refill and interpret a file until EOF
BEGIN refill WHILE interpret REPEAT ;
BEGIN refill WHILE interpret line-end-hook REPEAT ;

: execute-parsing-named-file ( i*x wfileid filename-addr filename-u xt -- j*x )
>r push-file \ dup 2* cells included-files 2@ drop + 2@ type
Expand All @@ -239,12 +263,12 @@ terminal-input @ \ source -> terminal-input::source
loadfile @ close-file swap 2dup or
pop-file drop throw throw ;

: execute-parsing-file ( i*x fileid xt -- j*x )
: execute-parsing-file ( i*x fileid xt -- j*x ) \ gforth
\G Make @i{fileid} the current input source, execute @i{xt @code{( i*x
\G -- j*x )}}, then restore the previous input source.
s" *a file*" rot execute-parsing-named-file ;

: include-file ( i*x wfileid -- j*x )
: include-file ( i*x wfileid -- j*x ) \ file
\G Interpret (process using the text interpreter) the contents of
\G the file @var{wfileid}.
['] read-loop execute-parsing-file ;
Expand Down
6 changes: 4 additions & 2 deletions picforth.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
\
\ PicForth: Forth compiler for Microchip PIC 16F87x/16F88
\
\ Copyright (c) 2002-2004 Samuel Tardieu <sam@rfc1149.net>
\ Copyright (c) 2002-2015 Samuel Tardieu <sam@rfc1149.net>
\
\ This compiler is released under the GNU General Public License version 2,
\ This compiler is released under the GNU General Public License version 3,
\ see the COPYING file in the same directory, as well as the README.
\

Expand Down Expand Up @@ -2601,3 +2601,5 @@ target
\ 4 bytes at a time on 16F8xxA devices)

4 org

unsupported2 foo bar
Loading

0 comments on commit 33e8d25

Please sign in to comment.