First star on the right, then straight on 'till Morning.

A project log for Computer Motivator

If you don't know what a computer motivator is by now, then you have been reading too many textbooks and not watching enough TV.

glgormanglgorman 10/07/2021 at 03:560 Comments

O.K., UCSD p-system Pascal is now compiling under Visual Studio to the point that I can load a Pascal file in a Microsoft MFC CEditView derived class, and then attempt to compile it, even though I only have about 2500 or so lines converted so far, i.e., mostly by using find and replace in a word processor and then manually fixing the VAR statements and the WITH statements.  Had to write my own versions of BLOCKREAD, IDSEARCH, and TREESEARCH, among other things; as these were nowhere to be found in the UCSD distribution.  TREESEARCH I already had, in my bTreeType class, but my earlier version uses recursion, so I redid that one.  IDSEARCH is the one that is going to be more interesting since the whole concept of checking to see whether a token is on a list of keywords and then calling an appropriate function is also something that I am doing with Rubidium.  Thus the Pascal version looks like this:

#include "stdafx.h"
#include "afxmt.h"
#include <iostream>
#include "../Frame Lisp/defines.h"
#include "../Frame Lisp/symbol_table.h"
#include "../Frame Lisp/btreetype.h"
#include "../Frame Lisp/node_list.h"
#include "../Frame Lisp/text_object.h"
#include "../Frame Lisp/scripts.h"
#include "../Frame Lisp/frames.h"
#include "../Frame Lisp/frames1.h"
#include "../Frame Lisp/extras.h"
#include "compiler.h"

namespace SEARCH
    char *keywords[] = 
    frame m_pFrame;
    symbol_table *m_keywords;
    void RESET_SYMBOLS();
    void IDSEARCH(int &pos, char *&str);

    frame &f = SEARCH::m_pFrame;
    symbol_table *t=NULL;
    t = f.cons(keywords)->sort();
     m_keywords = t;

void SEARCH::IDSEARCH(int &pos, char *&str)
    char buf[32];
    symbol_table &T = *SEARCH::m_keywords;
    size_t i, len, sz;
    sz = T.size();
    token *t;
    pos = -1;
    for (i=0;i<sz;i++)
        t = &T[(int)i];
        len = strlen(t->ascii);
        if (strcmp(buf,t->ascii)==0)
//            PASCALCOMPILER::SY;
//            PASCALCOMPILER::OP;
//            PASCALCOMPILER::ID;

Now as it turns out, on the Apple II, we are told that this function was actually implemented in 6502 assembly; which is why it is not in the UCSD distribution.  What it does of course, is check to see whether the symbols that are extracted by INSYMBOL are in the list of Pascal keywords, and then modify a bunch of ordinal values, enumerated types, or whatever in the global variable space; which is exactly what I need to do, but don't want to do in Rubidium; with respect to not wanting to use global variables, that is.  That would be TOO simple.  Even if this should turn out to be a refactoring job from hell, the payoff, in the end, will be well worth it - once I have clean C code that can be compiled, or transmogrified, or whatever to also run on the Propeller, or the Pi, or an Arduino, etc., such as by trans-compiling C to Forth, or C to SPIN, or C to Propeller assembly (PASM) or perhaps a mixture of all three.  Oh, and let's not forget about LISP.