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


Groups > comp.lang.forth > #19407

Re: Offline compilation of Forth

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.straub-nv.de!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!postnews2.euro.net!news.wanadoo.nl!not-for-mail
From mhx@iae.nl (Marcel Hendrix)
Subject Re: Offline compilation of Forth
Newsgroups comp.lang.forth
Message-ID <08181400018434@frunobulax.edu> (permalink)
Date Sun, 3 Feb 2013 21:17:27 +0200
References <58879100018434@frunobulax.edu>
X-Newsreader iForth 2.0 console (October 21, 2006)
Lines 87
Organization Wanadoo
NNTP-Posting-Date 03 Feb 2013 20:17:24 GMT
NNTP-Posting-Host s529d937f.adsl.online.nl
X-Trace 1359922644 dr2.euro.net 237 82.157.147.127:49498
X-Complaints-To abuse@wanadoo.nl
Xref csiph.com comp.lang.forth:19407

Show key headers only | View raw


mhx@iae.nl (Marcel Hendrix) writes Re: Matrices

> m.a.m.hendrix@tue.nl wrote Re: Matrices
>
>> On Monday, January 28, 2013 10:11:32 AM UTC+1, Andrew Haley wrote:
>>>> Is it possible to have 'delayed compilation?' 
>>>
>>> Whyever not? If you keep threaded code around you can recompile
>>> it to machine code whenever you want. 

>> I should have stated more clearly that I am looking for a syntax 
>> that hides the mechanics as much as possible. Of course the task 
>> as such is possible -- everything is possible in Forth.

> I thank everybody for their thoughtful replies.

> I postponed the solution of this challenge and first looked at the 
> main problem: inefficient array/matrix accesses.

[..]

A first cut at delayed compilation.

Of course, this idea should not be used when compiling takes longer
than the delay caused by suboptimal optimization.

-marcel

-- -------
ANEW -idea

DOC
(*
-- LET ( "cccc<:>" -- ) 
   *at compile time*

	1) accepts a string 
	2) allocates mem, copies string there ( c-addr u -- addr2 )
	3) compiles a vectored call through memory, with stack-effect ( 'vector addr2 -- ) 
	   Vector is setup for do-LET-FIRST.

   *at FIRST runtime* does do-LET-FIRST ( 'vector taddr -- )

	1) compiles a :NONAME. 
	   The first instruction is 2DROP
	   The rest comes from the text at taddr ( taddr -- xt ). 
	2) sets the vector to the :NONAME's xt.
	3) deallocates the string at taddr

   *at OTHER runtimes* (automatically) does
   
   	1) a call to the :NONAME ( xt addr -- )

   BUGS
   ----
   The :NONAME is called with two parameters. They are useful for do-LET-FIRST,
   but on next calls they are useless and should be dropped.

   NON ANS words
   -------------
   MULTI-LINE    WORD COUNT
   ?ALLOCATE     THROW
   @+		 DUP CELL+ SWAP @
   ]] [[	 string of POSTPONE .. 's
   PACK DROP     PLACE
*)
ENDDOC

-- For discussion only, is tokenized source in the real thing
: (LET) ( c-addr u -- ) EVALUATE ;

: do-LET-FIRST ( 'xt taddr -- )
	>R :NONAME ] ]] 2DROP [[  R@ @+ (LET) ]] ; [[  ( 'xt xt ) DUP ROT !
	R> FREE ?ALLOCATE  ( xt) 0. ROT EXECUTE ;

: LET ( "ccc<:>" -- )
	':' MULTI-LINE ( -- c-addr u )
	DUP 1+ ALLOCATE ?ALLOCATE LOCAL addr 
	addr PACK DROP
	POSTPONE AHEAD  ['] do-LET-FIRST , HERE CELL- >R  POSTPONE THEN
	R>   POSTPONE LITERAL ( 'xt)
	addr POSTPONE LITERAL ( string)
	POSTPONE OVER POSTPONE @EXECUTE ; IMMEDIATE

: test  LET cr ." Hello, world! ":  33 . ;

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


Thread

Matrices mhx@iae.nl (Marcel Hendrix) - 2013-01-27 22:17 +0200
  Re: Matrices Ron Aaron <rambamist@gmail.com> - 2013-01-28 08:50 +0200
  Re: Matrices Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-01-28 03:11 -0600
    Re: Matrices m.a.m.hendrix@tue.nl - 2013-01-28 01:46 -0800
      Re: Matrices mhx@iae.nl (Marcel Hendrix) - 2013-02-03 12:48 +0200
        Re: Matrices "A. K." <akk@nospam.org> - 2013-02-03 13:27 +0100
        Re: Offline compilation of Forth mhx@iae.nl (Marcel Hendrix) - 2013-02-03 21:17 +0200
  Re: Matrices stephenXXX@mpeforth.com (Stephen Pelc) - 2013-01-28 10:39 +0000
    Re: Matrices m.a.m.hendrix@tue.nl - 2013-01-28 03:33 -0800
  Re: Matrices albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-01-28 14:31 +0000
  Re: Matrices Alex McDonald <blog@rivadpm.com> - 2013-01-28 07:48 -0800
  Re: Matrices Hugh Aguilar <hughaguilar96@yahoo.com> - 2013-01-28 18:06 -0800
  Re: Matrices anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-01-29 09:49 +0000
    Re: Matrices Mark Wills <forthfreak@gmail.com> - 2013-01-29 04:08 -0800
      Re: Matrices m.a.m.hendrix@tue.nl - 2013-01-29 08:22 -0800

csiph-web