Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #53155

Re: how to create standalone EXE from inside forth with actual working environment (in forth or c)

From Alex <alex@rivadpm.com>
Newsgroups comp.lang.forth
Subject Re: how to create standalone EXE from inside forth with actual working environment (in forth or c)
Date 2016-12-07 13:50 +0000
Organization A noiseless patient Spider
Message-ID <o2941d$pth$1@dont-email.me> (permalink)
References <332b84e4-3e3d-426c-9a27-42b25b9979a5@googlegroups.com> <c420c554-9bbc-4f33-903f-0b01cb2a8d9c@googlegroups.com>

Show all headers | View raw


On 12/7/2016 11:26, Julian Fondren wrote:
> On Wednesday, December 7, 2016 at 4:55:20 AM UTC-6, make....@gmail.com wrote:
>> Hi all,
>>
>> But inside forth i want to save the working environment with a new standalone execute file like as:
>>
>> on command prompt:
>>    xyz_forth.exe -f core.fth (minimal forth words in forth language)
>>    inside xyz_forth:
>>             : test 1 1 + . ;
>> (and now)   fsave new_forth.exe
>>             bye
>>
>> now on command prompt:
>>     new_forth.exe
>>     inside new_forth:
>>             test (--> output 2)
>>     bye
>>
>
> Hello,
>
> What you're describing is a normal feature of any Forth that does
> offer any kind of 'turnkey' feature. I don't even know how you
> could've saved the state without being able to do as you describe.
> So if you tell us what Forth you're working with, someone can
> probably tell you exactly what to do.
>
> -- Julian
>

It's not easy to do; and the only Windows Forth I know that can build a 
native EXE file from a running copy as you indicate is Win32Forth 
version 6. (Does MPE's VFX do this? It may, since IIRC it can build DLLs.)

I wrote the code for Win32Forth native EXEs. You might want to look at 
it; the source modules are imagehds.f (which descrbes the PE headers) 
and imageman.f (which builds the EXE file). It is over 1000 lines of 
Forth and comment, and has several notable restrictions that I hadn't 
got round to addressing:

1. It can't build relocatable files; they can only execute at fixed 
addresses (the default for EXE files is 0x0040000)
2. It doesn't build DLLs (although it could; issue 1 would need fixed 
first).
3. It doesn't handle resources, so a seperate resource editor has to be 
used.

If you require these features, the solutions will be messy, though not 
impossible. There is some non-Forth literature on the subject; search on 
object serialization for example.

There are other ways of writing FSAVE though, and I would suggest the 
method that a number of other Forth's use. Write an FSAVE that creates 
an image file of your design; and write an EXE that can load & execute 
it. IIRC that's the mechanism gforth uses. This also has the advantage 
of possibly making it easier to support both a 32bit and 64bit Forth 
with a single image (or very similar images).

Regardless of which method you choose, these are still considerations 
that make the task complex. Initialisation needs to be done to make the 
newly restored environment look like the FSAVEd environment.
. File handles do not persist
. Dynamically allocated memory (heaps for instance) does not persist, 
and repeating allocations doesn't guarantee the same memory addresses
. The stack and rstack may be difficult to copy & restore
. Error recovery may not work correctly on the saved EXE.

-- 
Alex

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

how to create standalone EXE from inside forth with actual working environment (in forth or c) make.kmatze@gmail.com - 2016-12-07 02:55 -0800
  Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) Julian Fondren <julian.fondren@gmail.com> - 2016-12-07 03:26 -0800
    Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) make.kmatze@gmail.com - 2016-12-07 05:31 -0800
      Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) Julian Fondren <julian.fondren@gmail.com> - 2016-12-07 05:50 -0800
    Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) Alex <alex@rivadpm.com> - 2016-12-07 13:50 +0000
      Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) stephen@mpeforth.com (Stephen Pelc) - 2016-12-07 20:24 +0000
        Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) Alex <alex@rivadpm.com> - 2016-12-07 22:05 +0000
          Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) stephen@mpeforth.com (Stephen Pelc) - 2016-12-08 09:13 +0000
        Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) "Elizabeth D. Rather" <erather@forth.com> - 2016-12-07 14:59 -1000
          Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) Ron Aaron <rambamist@gmail.com> - 2016-12-08 06:50 +0200
        Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) JUERGEN <epldfpga@aol.com> - 2017-04-29 04:58 -0700
      Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-12-08 15:58 +0000
        Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) Alex <alex@rivadpm.com> - 2016-12-08 23:04 +0000
          Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-29 13:09 +0200
            Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) Alex <alex@rivadpm.com> - 2017-04-29 18:46 +0100
              Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-30 12:09 +0200
                Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) "Elizabeth D. Rather" <erather@forth.com> - 2017-04-30 09:35 -1000
                Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) Alex <alex@rivadpm.com> - 2017-04-30 22:23 +0100
                Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) "Elizabeth D. Rather" <erather@forth.com> - 2017-04-30 13:50 -1000
      Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) stephen@mpeforth.com - 2017-01-02 03:59 -0800
        Re: how to create standalone EXE from inside forth with actual albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-01-02 15:10 +0100
        Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) "Elizabeth D. Rather" <erather@forth.com> - 2017-01-02 07:43 -1000
      Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) stephen@mpeforth.com - 2017-01-02 04:01 -0800
  Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-07 15:58 +0100
  Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) make.kmatze@gmail.com - 2016-12-08 01:32 -0800
  Re: how to create standalone EXE from inside forth with actual working environment (in forth or c) make.kmatze@gmail.com - 2017-01-02 03:39 -0800

csiph-web