Guest User

Untitled

a guest
Jan 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. : make-string ( -- s )
  2. s" foo" ;
  3.  
  4. : append-print ( s s -- )
  5. append type cr ;
  6.  
  7. make-string s" bar" append-print
  8.  
  9. $ gforth prob1.fs -e bye
  10. gforth(41572,0x7fff79cc2310) malloc: *** error for object 0x103a551a0: pointer being realloc'd was not allocated
  11. *** set a breakpoint in malloc_error_break to debug
  12.  
  13. Abort trap: 6.
  14.  
  15. variable foo
  16. s" foo" foo !
  17.  
  18. foo s" bar " append type cr
  19.  
  20. $ gforth prob2.fs
  21. foo��^C
  22. in file included from *OS command line*:-1
  23. prob2.fs:4: User interrupt
  24. foo s" bar " append >>>type<<< cr
  25. Backtrace:
  26. $10C7C2E90 write-file
  27.  
  28. see append
  29. : append
  30. >l >l >l >l @local0 @local1 @local3 + dup >l resize throw >l @local4 @local0 @local3 + @local5
  31. move @local0 @local1 lp+!# 48 ; ok
  32.  
  33. : make-string ( -- s )
  34. s" foo" ;
  35.  
  36. : append-print
  37. s+ type cr ;
  38.  
  39. make-string s" bar" append-print
  40.  
  41. $ gforth b.fs -e bye
  42. foobar
  43.  
  44. : append { addr1 u1 addr2 u2 -- addr u }
  45. addr1 u1 u2 + dup { u } resize throw { addr }
  46. addr2 addr u1 + u2 move
  47. addr u ;
  48.  
  49. : s+ { addr1 u1 addr2 u2 -- addr u }
  50. u1 u2 + allocate throw { addr }
  51. addr1 addr u1 move
  52. addr2 addr u1 + u2 move
  53. addr u1 u2 +
  54. ;
  55.  
  56. : astring S" foo" ;
  57.  
  58. CREATE buffer 100 ALLOT space for 100 chars
  59.  
  60. Put the first string in `buffer and append the second string.
  61.  
  62. Also print the second string
  63.  
  64. : append-print ( s s -- )
  65.  
  66. type cr 2swap
  67.  
  68. buffer $!
  69.  
  70. buffer $+! ;
  71.  
  72. astring s" bar" append-print
  73.  
  74. bar OK answer
  75.  
  76. buffer $@ TYPE
  77.  
  78. foobar OK answer
Add Comment
Please, Sign In to add comment