Skip to content

Commit

Permalink
Added Forth-2012 throwcode table, fixed substitute
Browse files Browse the repository at this point in the history
  • Loading branch information
forthy42 committed Apr 13, 2015
1 parent 4b5559d commit e5f53f8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
21 changes: 21 additions & 0 deletions errors.fs
Expand Up @@ -84,6 +84,27 @@ decimal
-56 s" QUIT" rot errstring
-57 s" Error in sending or receiving a character" rot errstring
-58 s" [IF], [ELSE], [THEN] error" rot errstring
-59 s" ALLOCATE" rot errstring
-60 s" FREE" rot errstring
-61 s" RESIZE" rot errstring
-62 s" CLOSE-FILE" rot errstring
-63 s" CREATE-FILE" rot errstring
-64 s" DELETE-FILE" rot errstring
-65 s" FILE-POSITION" rot errstring
-66 s" FILE-SIZE" rot errstring
-67 s" FILE-STATUS" rot errstring
-68 s" FLUSH-FILE" rot errstring
-69 s" OPEN-FILE" rot errstring
-70 s" READ-FILE" rot errstring
-71 s" READ-LINE" rot errstring
-72 s" RENAME-FILE" rot errstring
-73 s" REPOSITION-FILE" rot errstring
-74 s" RESIZE-FILE" rot errstring
-75 s" WRITE-FILE" rot errstring
-76 s" WRITE-LINE" rot errstring
-77 s" Malformed xchar" rot errstring
-78 s" SUBSTITUTE" rot errstring
-79 s" REPLACES" rot errstring

\ Gforth's errors:

Expand Down
17 changes: 13 additions & 4 deletions substitute.fs
Expand Up @@ -29,13 +29,22 @@ User macro$
'%' macro$ c$+! 1 /string
ELSE
'%' $split 2swap dup 0= IF
2drop s" %" macro$ $+! r> 1+ >r
2drop '%' macro$ c$+!
ELSE
macros-wordlist search-wordlist IF
-rot 2>r execute macro$ $+! 2r> r> 1+ >r
2over drop 1- c@ '%' = IF
2dup macros-wordlist search-wordlist IF
nip nip -rot
2>r execute macro$ $+! 2r> r> 1+ >r
ELSE
'%' macro$ c$+! macro$ $+! '%' macro$ c$+!
THEN
ELSE
'%' macro$ c$+! macro$ $+!
THEN
THEN
THEN
ELSE
over 1- c@ '%' = IF '%' macro$ c$+! THEN
THEN
REPEAT 2drop macro$ $@ r> ;

Expand All @@ -44,7 +53,7 @@ User macro$
\G result to @var{addr2 len2}. @var{n} is the number of
\G substitutions, @var{addr2 len3} the result. If
\G @var{len2}=@var{len3}, it is likely that the string did not fit.
2>r $substitute -rot
2>r $substitute over r@ u<= -78 swap select -rot
2r> rot umin 2dup 2>r move 2r> rot ;

: unescape ( addr1 u1 dest -- dest u2 )
Expand Down
2 changes: 1 addition & 1 deletion utf-8.fs
Expand Up @@ -19,7 +19,7 @@

\ short: u8 means utf-8 encoded address

s" malformed UTF-8 character" exception Constant UTF-8-err
-77 Constant UTF-8-err

$80 Value max-single-byte

Expand Down

0 comments on commit e5f53f8

Please sign in to comment.