mò
6¶¿Ec           @   sJ  d  Z  d Z d Z y e Wn d1 \ Z Z n Xy| d k Z d k Z d k Z d k Z d k	 Z	 e i
 i e i i e	 i e i ƒ  ƒ d d d g ƒ ƒ d	 k l Z l Z Wn1 y e i i d
 e ƒ Wn e GHn X‚  n Xe i d i e i ƒ d Z e i d ƒ d Z e i ƒ  d Z d „  Z d „  Z d „  Z d k l Z d k Z d Z  h  d d <d d <d d <d d <d d <d d <d d <d d <d  d! <d" d# <Z! d$ „  Z" d% „  Z# d& „  Z$ d' „  Z% d( „  Z& d) „  Z' d* „  Z( d+ „  Z) d, „  Z* d- f  d. „  ƒ  YZ+ d/ „  Z, e- d0 j o e, e i d ƒ n d S(2   sÐ   bootstrap compiler for postFORTH version 1

   purpose of this is to keep things extremely simple when bootstrapping;
   I was doing this with the RCS file but each time I change machines
   I lose that trails7  
    pfcompile -- bootstrap compiler for postFORTH version 1
    Copyright (C) 2005  John Comeau <jc.jcomeau.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    s5   Not all needed libraries found, upgrade or check pathi   i    Ni   t   libt   python(   s   gpls	   jclicenses   %s
iÿÿÿÿt   .c          G   s   t  S(   N(   t   False(   t   whatever(    (    t   ./pfcompile.pyt
   DebugPrint3   s    c          G   s0   x) t  |  d ƒ t i j o |  d }  q W|  S(   sA   reduces args to lists or scalars, helps with command-line testingi    N(   t   typet   argst   typest	   TupleType(   R   (    (    R   t   noTuples6   s
       c          G   s<   t  |  ƒ }  x) t |  d ƒ t i j o |  d }  q W|  S(   s8   reduces args to scalars, helps with command-line testingi    N(   R   R   R   R	   t   ListType(   R   (    (    R   t   scalars;   s       (   s	   countdicti @ s   /*t   multilineComments   2#t
   pushnumbers   10#s   16#t   ,t   commat   't   ticks   LIT,t   litcommat   CREATEt   createt   :t   colont   ;t	   semicolonc          G   s-   t  |  ƒ }  |  d } | i | i ƒ  ƒ d S(   s'   comma is the FORTH single-word compileri    N(   R   R   t   compilert   compilet   pop(   R   R   (    (    R   R   S   s     
c          G   s1   t  |  ƒ }  |  d } | i d ƒ t | ƒ d S(   s?   compile a FORTH LIT followed by the compiled TOS (top-of-stack)i    t   LITN(   R   R   R   R   R   (   R   R   (    (    R   R   Y   s
     
c          G   s‚   t  d ƒ t |  ƒ }  |  d } d } xH t o@ | i ƒ  } | d j p | i	 d ƒ o Pn | | d 7} q) Wt  d | ƒ d S(   s   skip past next */s   processing multiline commenti    t    s   */t    t   skippedN(
   R   R   R   R   R!   t   Truet   getnextt   tokent   Nonet   endswith(   R   R!   R$   R   (    (    R   R   `   s     

  c          G   s_   t  |  ƒ }  |  d } t d d | i ƒ  | i ƒ  f ƒ | i t | i ƒ  | i ƒ  ƒ ƒ d  S(   Ni    t   pushings   %s%s(	   R   R   R   R   t   getlastt
   getcurrentt   pusht   baseconvertR#   (   R   R   (    (    R   R   l   s    
#c          G   s:   t  |  ƒ }  |  \ } } t | i d ƒ ƒ } t | | ƒ S(   Nt   #(   R   R   t   baset   integert   intt   rstrip(   R   R.   R-   (    (    R   R+   r   s    c          G   s:   t  |  ƒ }  |  d } | i d ƒ t d | i ƒ  ƒ d  S(   Ni    s   tick: faked pushing address of(   R   R   R   R*   R   R#   (   R   R   (    (    R   R   x   s    
c          G   sn   t  |  ƒ }  |  d } | i ƒ  } | i ƒ  | i | <| i t i	 d t
 | ƒ t
 | ƒ | t
 | ƒ ƒ ƒ d  S(   Ni    s   B %ds B(   R   R   R   R#   t   wordt   heret   addrR   t   structt   packt   len(   R   R1   R   (    (    R   R   ~   s    
c          G   s1   t  |  ƒ t |  ƒ }  |  d } | i d ƒ d  S(   Ni    (   R   R   R   R   R   (   R   R   (    (    R   R   †   s    

c          G   s'   t  |  ƒ }  |  d } | i d ƒ d  S(   Ni    (   R   R   R   R   (   R   R   (    (    R   R   Œ   s    
R   c           B   sz   t  Z d Z g  Z g  Z g  Z e ƒ  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z RS(   Ni    c         G   sE   t  | ƒ } | d } t | ƒ i ƒ  i ƒ  |  _ t d |  i ƒ d  S(   Ni    t   list(	   R   R   t
   sourcefilet   opent   readt   splitt   selfR7   R   (   R<   R   R8   (    (    R   t   __init__˜   s    
c         C   s8   t  d |  i d |  i d |  i d |  i d |  i ƒ
 d  S(   Nt   pointerR7   t   stackt   compiledR3   (   R   R<   R>   R7   R?   R@   R3   (   R<   (    (    R   t   dumpž   s    c         C   sR   |  i t |  i ƒ j o t d ƒ d Sn$ |  i |  i } |  i d 7_ | Sd S(   s=   return next token or None if end of list, and advance pointers   getnext: end of tokensi   N(   R<   R>   R6   R7   R   R%   t   next(   R<   RB   (    (    R   R#   ¢   s     
c         C   s   |  i |  i d S(   s   last token processedi   N(   R<   R7   R>   (   R<   (    (    R   R(   ¬   s     c         C   s   |  i |  i S(   sC   next available token, will throw exception if called at end of listN(   R<   R7   R>   (   R<   (    (    R   R)   °   s     c         G   s&   t  | ƒ } |  i i t | ƒ ƒ d  S(   N(   R   R   R<   R?   t   extendR7   (   R<   R   (    (    R   R*   ´   s    c         C   s!   t  d |  i d ƒ |  i i ƒ  S(   Nt   poppingiÿÿÿÿ(   R   R<   R?   R   (   R<   (    (    R   R   ¸   s    c         G   s>   t  | ƒ } x+ | D]# } t d | ƒ |  i i | ƒ q Wd  S(   Nt	   compiling(   R   R   t   argR   R<   R@   t   append(   R<   R   RF   (    (    R   R   ¼   s
     c         C   s   t  t |  i ƒ S(   N(   t   baseAddressR6   R<   R@   (   R<   (    (    R   R2   Â   s    (   t   __name__t
   __module__R>   R7   R?   R@   t   dictR3   R=   RA   R#   R(   R)   R*   R   R   R2   (    (    (    R   R   ‘   s   				
					c          G   sò   t  d t t f |  ƒ t |  ƒ }  t t ƒ } t ƒ  } xœ |  D]” } t | ƒ } x t ow | i ƒ  } | d j o Pn | | c d 7<| | i ƒ  j o% t  d | ƒ t | | ƒ | ƒ qT t  d | ƒ qT Wq? W| i ƒ  t  d | ƒ d S(   sž   compile postFORTH tokens from program(s) passed in on command line

    using "inside knowledge" of postFORTH, find tokens and output as
    a linked binary
 s'   'pytest %s.%s' should show this; args: i   s   processing token:s   unrecognized tokent   tokensN(   R   R<   t   originalselfR   R   RK   t	   postfortht   tokenmapt	   countdictRL   R8   R   t
   pfcompilerR"   R#   R$   R%   t   keyst   evalRA   (   R   RL   R8   R$   RO   RQ   (    (    R   t	   pfcompileÅ   s(     	   t   __main__(   i   i    (.   t   __doc__t	   Copyrightt   errormessageR"   R   t   syst   osR	   t   ret   pwdt   pathRG   t   sept   joint   getpwuidt   geteuidt   com.jcomeaut   gplt	   jclicenset   stderrt   writet   argvR;   R<   t   commandRM   R   R   R   t   com.jcomeau.arcaneRP   R4   RH   RN   R   R   R   R   R+   R   R   R   R   R   RT   RI   (    R   RW   R   R   Rc   R4   R<   R[   R"   R   RM   R   RP   RY   R\   R+   RH   R   R   R	   R   R   R   RX   R   RT   Rd   Rh   RN   R   RZ   R   (    (    R   t   ?   sN   -8					`									4	