Shop OBEX P1 Docs P2 Docs Learn Events
Propforth v5.5 is available for download - Page 12 — Parallax Forums

Propforth v5.5 is available for download

191012141526

Comments

  • caskazcaskaz Posts: 957
    edited 2013-10-26 17:01
    Hi prof_braino.

    I know there is forth-source list in 2013FEB23mygo V5.5 RC1.zip.
    But this cannot use in PropForth5.5.
    I want to know how IPKernel execute telnet.
    So I want source-code list.
    That is very good sample code.

    There is no word about ip_server, etc in PropForth.htm.

    It is difficult for me to go back to PropForth5 to understand about ip_server.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-10-26 19:48
    caskaz wrote: »
    I know there is forth-source list in 2013FEB23mygo V5.5 RC1.zip.
    But this cannot use in PropForth5.5.
    I want to know how IPKernel execute telnet.
    So I want source-code list.
    That is very good sample code.

    There is no word about ip_server, etc in PropForth.htm.

    It is difficult for me to go back to PropForth5 to understand about ip_server.

    To restate: 2013FEB23mygo V5.5 RC1.zip is propforth 5.5. The scripts in 2013FEB23mygo V5.5 RC1.zip are the scipts used to build and test v5.5.

    The source code for the IP kernel, and the tests, are in there. The way to use it is to set up and run the Go language build and test automation.

    If you don't have the Go language support for the build and test automation, it will be very difficult to get the scripts to run.

    The IP supporrt is not included in Propforth.HTM becuase it is requires additional hardware (the spinerette) beyond the prop chip itself. Additional hardware was to be covered in web pages, but there were few requests. This is why we decided to use RPi instead of spinerette.

    I realize my response is not much help at this point. I'll talk with Sal tomorrow, maybe he will offer something more useful.
  • caskazcaskaz Posts: 957
    edited 2013-10-26 20:25
    Hi prof_braino.

    Is such a makefile used for making spin-file(DevKernel,EEpromkernel,EEpromIPKernel,IPKernel,SDKernel)?
    I don't understand go.
    Forth-source-list don't exist because go generate word-list(hex)?
    I don't want to use RPi only when connecting to net.
    I want to write code by using W5100. If it's heavy, I select RPi.
    I want sample code to use W5100chip.
    Currently I think PropForth5.5 is like a blackbox.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-10-27 07:10
    caskaz wrote: »
    Hi prof_braino.

    Is such a makefile used for making spin-file(DevKernel,EEpromkernel,EEpromIPKernel,IPKernel,SDKernel)?
    yes, the makefile makes all of propforth, from source. If someone werre to change the kerrnel, this would erbuild the enitre everything using theat kernel. But don't do that unless the kernel has no errors.
    I don't understand go.

    We don't NEED to undestand GO, just install the support (follow the Go instal insttructions, its pretty staight forward). All the propforth go stuff is set up. By ALL I mean you have to type three commands the first time through, but ask me afterr the get the go support installed.
    Forth-source-list don't exist because go generate word-list(hex)?
    no
    I don't want to use RPi only when connecting to net.
    I want to write code by using W5100. If it's heavy, I select RPi.
    I want sample code to use W5100chip.

    Your choice
    Currently I think PropForth5.5 is like a blackbox.

    Maybe, but its not a black box to people like Sal, and Nick, and a few others. Just as prop GCC is black box to most folks except jazzed and a few other, tachyon is a black box to most folks except Peter and a few otherr.

    We CAN learn everythig about it, because the source is thee and complete, and we can ask the author; but that is not necessary for most of us, as its a lot of trouble and we can just USE it, most of tthe time.

    You, in particular, are the main audience for the "deeper" and more details explanations. We put your question at the top of the list. But we need very specific questions to answer.

    ...
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-10-27 08:00
    caskaz,

    When I get a new release, I dig down into the mygo directory and copy all of the .f files that can be found to a new directory, such as pf55-source where it is someplace easy to find. Usually I put it with my other Forth sources. Then I use this list, the decompiler that is out on the wiki pages and a lot of paper to start digging in to what is in the kernels I am using. It's a great way to learn what is in the kernels. I haven't yet played with the Go build system to build new kernels.

    I find my word list and having the source all in one place to be very useful to learning about PropForth's internals and also some really good coding examples from Sal.

    I've been idle with PropForth (and everything else) for quite a while but hope to be back into it some day.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-10-27 08:43
    Todays Call:

    Spinerete Revisted:

    v5.0
    * v5.0 was telenet. please use that, to start, to demonstrate the hardware and internet porton are configured correctly. If you can cet telnet to work in v5.0 you are good to go, or ready move on to v5.5

    V5.5
    * 2013FEB23mygo V5.5 RC1.zip/mygo/V5.5/kernels/MAKE/results/outputFiles
    is the source the automation generates to do everything, it is all there.
    These are your references:
    - ip.f
    - ipconfig.f

    * v5.5 kernels - these exist in the standard package, and run on the spinerete
    - PropForthEEpromIP
    - PropforthIP

    Follow the scripts:
    - InitSnetEEpromIP.txt
    - LoadSnetEEpromKernel.txt
    - LoadSnetEEpromIPKernel.txt
    or
    - InitSnetEEpromHTTP.txt
    - LoadSnetEEpromHTTPKernel.txt
    or
    - InitSnetFsrdSDHTTP.txt (and the ones that call this)

    to see how these are set up and run

    And of course ask questions, it might be a little involved in some places


    Dealing with bureaucracy:
    ADVICE - Your problem is the most excitement they get.
    When in conflict, understand, bureaucracy has stamina the far surpases an individual.
    Unless we see a path that is beneficial to both of us, it will be a war of attrition.


    Dangerous Experiements:

    * Google: "Black Blood of the Earth"
    * Nitrogen Laser + Peachy Printer


    Status:

    - Propforth core has been stable for four years.

    - The Multitasking stuff to be introduced in Propforth 6 is still running and appears stable. Recall that PF6 will treat threads as "execution opportunities". These execution opportunities will be assigned to one or more "pools". Pools can be configured as "must execute deterministicially" (which just means allocate enough threads so it can) and "execute as availible" (which means tasks can be non deterministic, and share threads, such as terminal I/O, status LED's etc). PropForth 6 will have eight threads on the Prop 1, and thirty-two threads on the Prop 2.
  • caskazcaskaz Posts: 957
    edited 2013-11-09 05:41
    I wrote code for i2c-devices.
    Yet only 3 devices.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-11-09 10:58
    caskaz, have you looked at the cheap 10DOF IMU?

    http://www.ebay.com/itm/10DOF-IMU-BMP085-HMC5883L-ADXL345-L3G4200D-Sensor-Module-For-Arduino-MWC-A091-/271037801548?pt=LH_DefaultDomain_0&hash=item3f1b1ca44c

    You seem to have completed all the parts needed to make a driver for this unit! Actually there's four parts on this one, so theres at least one more layer. I have one of these from when they were $30 and still haven't gotten around to playing with it.
  • caskazcaskaz Posts: 957
    edited 2013-11-11 04:09
    Hi.
    I got i2c-touch-sensor.
    I use QuickStartBoard.
    It seems to communicate between prop and device by word"test".
    But I cannot get sense-data . Always '0'.
    And by "reboot", PropForth hang up.


    It also is same phenomenon on DRV8830.
    In case of DRV8830, adding resistor(1kohm) on scl/sda-line had gone trouble.
    [combined resistance is 909ohm)

    Now, I added resistor(220ohm). [combined resistance is 198ohm]
    But trouble don't has gone.

    How does it fix?
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-11-11 05:04
    I couldn't find an english manual for rh6010 (only have a couple minutes)

    But, if there is an disagreement from the address, and you are getting 0, then I would start looking at the address again.

    Also, if it hangs on reboot, I would guess (1) there is a code error and/or (2) the prop is waiting for the device, and the device is not answering.

    Your questions get harder and harder!
  • fridafrida Posts: 155
    edited 2013-11-11 09:44
    @caskaz
    In the dokument at 9.1 there are a centence:
    RH6010 I C地址是0x78H,当主机向从机写数据时,寻址地址为0xF0;当主机向从机读数据时,寻址地址为0xF1。

    I think write is F0, and read is F1, Try it and see what happen.

    Frida
  • caskazcaskaz Posts: 957
    edited 2013-11-11 15:50
    HI.

    Reboot-problem was caused by poor contact of my bread-board.

    It seems register-address'1' don't exist.
    Prop0 Cog6 ok
    0 0 RH6010 i2c_wr err?
    ST: 0000_0000 0000_0000 0000_0000  <-- wr for slave-addr is ok
    ST: 0000_0000 0000_0000  <-- wr for register-addr is ok
    ST: 0000_0000
    Prop0 Cog6 ok
    
    0 1 RH6010 i2c_wr err?
    ST: 0000_0000 0000_0001 0000_0000  <-- wr for slave-addr is ok
    ST: 0000_0000 FFFF_FFFF  <-- wr for register-addr is ng
    ST: FFFF_FFFF
    I2C error
    Prop0 Cog6 ok
    

    When read process, 3rd _eewrite cause fault.
    i2c_rd use on DS3231,DS1337,DRV8830,HM5883L.
    It's ok.
    It seems RH6010's rd-process is a little different.
    Or i2c_rd might be wrong a little.
    0 RH6010 i2c_rd err?  sc
    ST: 0000_00F0 0000_0000 0000_0000  <-- wr for slave-addr is ok
    ST: 0000_00F0 0000_0000  <-- wr for register-addr is ok
    ST: 0000_0000 0000_00F0
    ST: 0000_0000 0000_00F1
    ST: 0000_0000 FFFF_FFFF  <-- wr for slave-addr is ng
    ST: FFFF_FFFF
    ST: 0000_00FF FFFF_FFFF
    I2C error
    
    Prop0 Cog6 ok
    2 RH6010 i2c_rd err?  sc
    ST: 0000_00F0 0000_0002 0000_0000  <-- wr for slave-addr is ok
    ST: 0000_00F0 0000_0000  <-- wr for register-addr is ok
    ST: 0000_0000 0000_00F0
    ST: 0000_0000 0000_00F1
    ST: 0000_0000 FFFF_FFFF  <-- wr for slave-addr is ng
    ST: FFFF_FFFF
    ST: 0000_00FF FFFF_FFFF
    I2C error
    
    Prop0 Cog6 ok
    
  • caskazcaskaz Posts: 957
    edited 2013-11-12 03:05
    Hi prof_braino.

    I'm looking for _eewrite's source code.
    Where is it?
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-11-12 18:20
    caskaz wrote: »
    Hi prof_braino.

    I'm looking for _eewrite's source code.
    Where is it?

    I think _eewrite is assembler only, the assembler code is the source code.

    /PropForth5.5/2013FEB23mygo V5.5 RC1/mygo/V5.5/kernels/MAKE/src / forthEepromUtils.f

    and

    FsrdKernel.spin

    etc
  • Martin_HMartin_H Posts: 4,051
    edited 2013-11-13 19:27
    Hi Prof, I'm also trying to port my IK code from gforth to PropForth and I want to make sure I'm on the right track.Here's the first bit:
    \ Values for common angles in brad13
    $0016 constant DEGREE_ANGLE
    $0400 constant EIGHTH_ANGLE
    $0800 constant RIGHT_ANGLE
    $1000 constant STRAIGHT_ANGLE
    $1400 constant FIVEEIGHTH_ANGLE
    
    
    \ arctangent table from Beau Schwabe's cordic
    create table_atan , $20000000 , \ atan(1)   = 45    degrees   iteration  0
                        $12E4051E , \ atan(1/2) = 26.56 degrees   iteration  1
                        $09FB385B , \ atan(1/4)                   iteration  2
                        $051111D4 , \ atan(1/8)                   iteration  3
                        $028B0D43 , \ atan(1/16)                  iteration  4
                        $0145D7E1 , \ atan(1/32)                  iteration  5
                        $00A2F61E , \ atan(1/64)                  iteration  6
                        $00517C55 , \ atan(1/128)                 iteration  7
                        $0028BE53 , \ atan(1/256)                 iteration  8
                        $00145F2F , \ atan(1/512)                 iteration  9
                        $000A2F98 , \ atan(1/1024)                iteration 10
                        $000517CC , \ atan(1/2048)                iteration 11
                        $00028BE6 , \ atan(1/4096)                iteration 12
    Does> swap cells  + ;
    

    Based upon some code samples I've seen this becomes:
    \ Values for common angles in brad13
    hex
    0016 wconstant DEGREE_ANGLE
    0400 wconstant EIGHTH_ANGLE
    0800 wconstant RIGHT_ANGLE
    1000 wconstant STRAIGHT_ANGLE
    1400 wconstant FIVEEIGHTH_ANGLE
    
    \ arctangent table from Beau Schwabe's cordic
    lockdict create table_atan forthentry
                        20000000 l, \ atan(1)   = 45    degrees   iteration  0
                        12E4051E l, \ atan(1/2) = 26.56 degrees   iteration  1
                        09FB385B l, \ atan(1/4)                   iteration  2
                        051111D4 l, \ atan(1/8)                   iteration  3
                        028B0D43 l, \ atan(1/16)                  iteration  4
                        0145D7E1 l, \ atan(1/32)                  iteration  5
                        00A2F61E l, \ atan(1/64)                  iteration  6
                        00517C55 l, \ atan(1/128)                 iteration  7
                        0028BE53 l, \ atan(1/256)                 iteration  8
                        00145F2F l, \ atan(1/512)                 iteration  9
                        000A2F98 l, \ atan(1/1024)                iteration 10
                        000517CC l, \ atan(1/2048)                iteration 11
                        00028BE6 l, \ atan(1/4096)                iteration 12
    Does> swap cells  + ;
    freedict
    

    which seems to be OK, except the Does> construct which I seem to recall you don't support. Besides putting the array indexing code inline do you have a prefered replacement?
  • Martin_HMartin_H Posts: 4,051
    edited 2013-11-14 19:37
    So I officially declare myself clueless on how to create a longword array in PropForth. I've tried several different syntaxes, but none of them produce the expected result. Are there any examples?

    UPDATE: This sort of works
    \ arctangent table from Beau Schwabe's cordic
    variable table_atan h20000000 l, \ atan(1)   = 45    degrees   iteration  0
                        h12E4051E l, \ atan(1/2) = 26.56 degrees   iteration  1
                        h09FB385B l, \ atan(1/4)                   iteration  2
                        h051111D4 l, \ atan(1/8)                   iteration  3
                        h028B0D43 l, \ atan(1/16)                  iteration  4
                        h0145D7E1 l, \ atan(1/32)                  iteration  5
                        h00A2F61E l, \ atan(1/64)                  iteration  6
                        h00517C55 l, \ atan(1/128)                 iteration  7
                        h0028BE53 l, \ atan(1/256)                 iteration  8
                        h00145F2F l, \ atan(1/512)                 iteration  9
                        h000A2F98 l, \ atan(1/1024)                iteration 10
                        h000517CC l, \ atan(1/2048)                iteration 11
                        h00028BE6 l, \ atan(1/4096)                iteration 12
    
    : table_atan() 4 * table_atan + L@ ;
    

    The problem is the 1 table_atan() indexes to h20000000. I would have expected 0 to do that.
  • caskazcaskaz Posts: 957
    edited 2013-11-15 05:53
    Hi prof_braino.

    I read _eewrite inside forthEepromUtils.f.

    This is 333.3kHz, not 400kHz clock.
    Because it can operate any i2c-devices?

    And I think timing getting acknowledge bit is when clock is high.
    Why does sda is received before clock high?
    \ _eewrite ( c1 -- t/f ) write c1 to the eeprom, true if there was an error
    \
    \
    :asm
    		jmp	# __x0C
    __x02sda
    		h20000000
    __x03scl
    		h10000000
    __x04delay/2
    		hD
    \ this delay makes for a 400kHZ clock on an 80 Mhz prop
    \
    __x0Edelay/2
    		mov	$C_treg6 , __x04delay/2
    __x0D
    		djnz	$C_treg6 , # __x0D
    __x0Fdelayret
    		ret
    \
    __x0C
    		mov	$C_treg3 , # h8
    \		
    __x0B
    		test	$C_stTOS , # h80	wz
    		muxnz	outa , __x02sda
    \
    		jmpret	__x0Fdelayret , # __x0Edelay/2
    \
    		or	outa , __x03scl
    \
    		jmpret	__x0Fdelayret , # __x0Edelay/2
    		jmpret	__x0Fdelayret , # __x0Edelay/2
    \
    		andn	outa , __x03scl
    		shl	$C_stTOS , # 1
    \
    		jmpret	__x0Fdelayret , # __x0Edelay/2
    \
    		djnz	$C_treg3 , # __x0B
    \
    		andn	dira , __x02sda
    		test	__x02sda , ina	wz
    		muxnz	$C_stTOS , $C_fLongMask
    \
    		jmpret	__x0Fdelayret , # __x0Edelay/2
    \
    		or	outa , __x03scl
    \
    		jmpret	__x0Fdelayret , # __x0Edelay/2
    		jmpret	__x0Fdelayret , # __x0Edelay/2
    \
    		andn	outa , __x03scl
    \
    		jmpret	__x0Fdelayret , # __x0Edelay/2
    		andn	outa , __x02sda
    		or	dira , __x02sda
    \
    \
    		jexit
    \
    ;asm _eewrite
    
  • Martin_HMartin_H Posts: 4,051
    edited 2013-11-16 08:49
    I've finally figured out a create does> workaround and I'm creating array as follows:
    \ compatibility words
    : cells 4 * ;
    
    \ Create a set of arrays using a workaround for the missing create does>
    variable table_atan 13 cells allot
    : atan() cells table_atan + ;
    
    \ load array with arctangent table iteration from Beau Schwabe's cordic
    h20000000  0 atan() L! \ atan(1)   = 45    degrees
    h12E4051E  1 atan() L! \ atan(1/2) = 26.56 degrees
    h09FB385B  2 atan() L! \ atan(1/4)
    h051111D4  3 atan() L! \ atan(1/8)
    h028B0D43  4 atan() L! \ atan(1/16)
    h0145D7E1  5 atan() L! \ atan(1/32)
    h00A2F61E  6 atan() L! \ atan(1/64)
    h00517C55  7 atan() L! \ atan(1/128)
    h0028BE53  8 atan() L! \ atan(1/256)
    h00145F2F  9 atan() L! \ atan(1/512)
    h000A2F98 10 atan() L! \ atan(1/1024)
    h000517CC 11 atan() L! \ atan(1/2048)
    h00028BE6 12 atan() L! \ atan(1/4096)
    
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-11-16 09:40
    Martin_H wrote: »
    which seems to be OK, except the Does> construct which I seem to recall you don't support. ...
    Martin_H wrote: »
    So I officially declare myself clueless on how to create a longword array in PropForth. .... The problem is the 1 table_atan() indexes to h20000000. I would have expected 0 to do that.
    Martin_H wrote: »
    I've finally figured out a create does> workaround and I'm creating array as follows:

    The way you are doing is what I would do also.

    The deal with Does> is we define one word for the compile time behavior, and a separate word for the the run time behavior. While this adds a couple bytes to your appliction, it save more bytes in the kernel. Also, folks tend to have trouble with Does>; if one is expert enough to use Does> correctly, then one should also be able to handle to separate definiitions. This was just the design decision at the time, of course we are free to add our own Does> if desired (Sal doesn't).

    Th3e deal with arrays is the VARIABLE definition is the 0th offset. So we would do
    h200000 table_atan L!
    
    to load the value in the 0th location.

    from ..\doc\Propforth.htm
    9.1.244                 l,
    \ l, ( x -- ) allocate 1 long, 4 bytes in the dictionary and copy x to that location
    

    This is what I use for loading the 1 thru n elements of the array.

    After the array is built, I use a word like your
    : atan() cells table_atan + ;
    
    to acces the values
  • caskazcaskaz Posts: 957
    edited 2013-11-16 17:36
    Hi Martin.

    This is NG?
    variable table_atan -4 allot
    h20000000 l, \ atan(1)   = 45    degrees   iteration  0
    h12E4051E l, \ atan(1/2) = 26.56 degrees   iteration  1
    h09FB385B l, \ atan(1/4)                   iteration  2
    h051111D4 l, \ atan(1/8)                   iteration  3
    h028B0D43 l, \ atan(1/16)                  iteration  4
    h0145D7E1 l, \ atan(1/32)                  iteration  5
    h00A2F61E l, \ atan(1/64)                  iteration  6
    h00517C55 l, \ atan(1/128)                 iteration  7
    h0028BE53 l, \ atan(1/256)                 iteration  8
    h00145F2F l, \ atan(1/512)                 iteration  9
    h000A2F98 l, \ atan(1/1024)                iteration 10
    h000517CC l, \ atan(1/2048)                iteration 11
    h00028BE6 l, \ atan(1/4096)                iteration 12
    
    \ Get atan value
    \ ( n1 -- n2 )  n1:index[0,1,2,n] n2:Long value
    : get_atan 4 u* table_atan + L@  ;
    
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-11-17 08:54
    Today's call:

    * Question: Defining Table using "variable" instead of "create"

    Answer: caskaz's suggestion
    variable -4 allot n l, n l, n l,
    is good. Be sure to start with lock dict and end with unlock dict

    * Question - eewrite timing: 333.3khz, not 400khz, I2C?

    Answer: Sal uses these "ee" routines on everything (I2C). Concerning clock: The ee (I2C) is tuned to 400khz for 6Mhz processor. Most I2C are 400 MAX. This is so it will still work with an overclocked prop. (Recall our rule is that propforth must work on ANY standard prop rig. I guess we now include 6Mhz as "regular") It will still work slower. On a 5Mhz system, it will run fine at 333.3.

    * Question: 400hz I2C on 5Mhz prop?

    Answer: To run ee (I2C) at 400khz on 5Mhz crystal:
    Assuming Proforth 5.5: ../ kernels / make / src / optimized
    [source utils is just copy of the stock routines from kernel, so all are same]

    _eewrite - delay/2 is set to 13, hD, change this to get 400 from 5mhz crystal
    (I didn't figure out the proper value)

    * caskaz question: And I think timing getting acknowledge bit is when clock is high. Why does sda is received before clock high?

    Answer: Acknowledge bit Last bit is being reread while clock is still high.
    Caskaz is correct - The last bit, the acknowldege bit, is being read while the clock is still high.
    Should probably be switch around, but is probably irrelevant since its only 50 ns.
    Sal checked the spec.... spec says data hold after clock drops low is TDH = 50ns min hold time, so its just fine and within spec. its fine for minimum of 50 ms AFTER clock goes low.

    The way it really works has to do with capacitace, hold time is very long. Unless the application has many devices (more than 10 devices) it should be fine.
    Its not wrong, but it should be made to line up with the spec sheet.

    Braino to OPEN am issue report - EEWRITE acknowledge bit is read AFTER clock goes low, should be before? Should data is read BEFORE clock goes low.

    opened Issue 209 http://code.google.com/p/propforth/issues/detail?id=209

    * Logger 2 : The Logger 2 demo might be ready for next neek.
    After midnight, the logger will auto create a new SD log file if one does not exist.
    The log file size will be based on the buffer size (256 bytes) and log interval (once per second default).
    The default log file allocation will be about 28 meg, about 43000 blocks.
    One record per second should fit about 1 month per Gig.

    The log file name will be LOGyyyymmdd so they sort in order.

    If the user does not set the time, it will log to a file with the default date 2001-01-01. If we don't set the time, this default file could end up getting overwritten.
  • Martin_HMartin_H Posts: 4,051
    edited 2013-11-18 06:18
    @caskaz, thanks. If I understand that the -4 backs up the current allocation location so that the l, allocations that follow will start at zero rather than one? If so what does the adujstment to the curret allocation location? Does this mean PropForth's allot keyword takes two arguments ( amount adujstment -- )?
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-11-18 06:55
    Martin, in standard Forth a table is created using create followed by the variable name and the data. However, PropForth's create doesn't work like the standard create word, so the work-around is to use "variable name -4 allot" instead. PropForth's allot word works like the standard word where it advances the data pointer by the number of bytes specified on the stack.
  • Martin_HMartin_H Posts: 4,051
    edited 2013-11-18 07:48
    Thanks for the explanation Dave.

    BTW I circled back to my original IK program and found that using the approach in reply #349 works under gforth and PropForth. I also changed all the wconstants to constant, so now my program compiles under gforth (it should also compile under pfth). I'm going to try and keep the IK program portable because that strikes me as the reason to use Forth over Spin.
  • caskazcaskaz Posts: 957
    edited 2013-11-19 04:38
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-11-19 05:12
    Martin_H wrote: »
    @caskaz, thanks. If I understand that the -4 backs up the current allocation location so that the l, allocations that follow will start at zero rather than one? If so what does the adujstment to the curret allocation location? Does this mean PropForth's allot keyword takes two arguments ( amount adujstment -- )?

    from Propforth.htm:
    9.1.147 allot
    \ allot ( n1 -- ) add n1 to here, allocates space on the data dictionary or release it

    Allot has very simple function. It acts on the "here", the pointer to the end of the dictionary. Allot simply more the dictionary pointer by N bytes. Since the definition for variable already reserves space for storage, -4 allot moves the pointer back a long size, allowing the l, word to be used in the regular manner.
  • Martin_HMartin_H Posts: 4,051
    edited 2013-11-19 07:28
    from Propforth.htm:
    9.1.147 allot
    \ allot ( n1 -- ) add n1 to here, allocates space on the data dictionary or release it

    Allot has very simple function. It acts on the "here", the pointer to the end of the dictionary. Allot simply more the dictionary pointer by N bytes. Since the definition for variable already reserves space for storage, -4 allot moves the pointer back a long size, allowing the l, word to be used in the regular manner.

    Thanks prof_braino, up until that array example I hadn't seen a negative number used as a parameter to allot. It seems useful to be able to free space, but what are the limits?
    Gforth 0.7.0, Copyright (C) 1995-2008 Free Software Foundation, Inc.
    Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
    Type `bye' to exit
    here . 2126267312  ok
    
    \ lets alloc and free a variable
    variable foo here . 1 cells negate allot here . 2126267340 2126267336  ok
    
    \ That's what I expected.
    
    \ Let's try another allot and see where here starts off.
    variable bar here . 2126267364  ok
    
    \ Now that's weird, bar is pretty far away from foo.
    
    \ Let's go crazy and feed a big negative number into allot!
    variable foo1 here . 10 cells negate allot here . 2126267388 2126267348  ok
    
    \ Call me paranoid, but have here back all the away up to '348 seems like it would cause problems.
    
    \ Now let's allot again and see where here is.
    variable bar1 here . 2126267372  ok
    
    \ OK I'm confused.
    

    It's clear I need to learn more about FORTH's data dictionary.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-11-19 10:30
    Martin, when you create a variable the interpreter uses 1 cell for the variable plus space needed for the dictionary entry. Your variables require 24 bytes under GForth, where only 4 bytes are used for the variable's value. If you do the same thing under pfth you will see that it uses 16 bytes for each variable. However, the name is stored as part of the dictionary entry, so it will be bigger for longer names. A variable named "foobar" will use 20 bytes instead of 16.

    If you do a "-4 allot" the data pointer will back up to just after the variables dictionary entry. If you define another variable after this without advancing the data pointer, writes to the first variable will clobber the dictionary entry for the next variable.
  • Martin_HMartin_H Posts: 4,051
    edited 2013-11-19 13:15
    Thanks Dave, that helps me understand why here advanced more than I expected. It also explains the terseness you often see in FORTH programs. Basically it sounds like the data pointer is yet another stack. Each allocation advances the here pointer, but if you back it up over the previous entry you'll soon regret it.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-11-19 13:29
    Martin_H wrote: »
    Thanks Dave, that helps me understand why here advanced more than I expected. It also explains the terseness you often see in FORTH programs. Basically it sounds like the data pointer is yet another stack. Each allocation advances the here pointer, but if you back it up over the previous entry you'll soon regret it.

    here is the back end of the dictionary, the next free memory location.

    memory COULD be seen as one big line of memory locations. those would a lot slower than the regular stack in cog memory.

    remember when you do experiments like variable followed by aribtrary negative allot, things will get whacked and you recover by hitting reset. once things go nuts, we rarely can unwind the errors.
Sign In or Register to comment.