convert pascal code to purebasic

Just starting out? Need help? Post your questions and find answers here.
patrick88
User
User
Posts: 18
Joined: Sat May 03, 2003 10:30 am

convert pascal code to purebasic

Post by patrick88 »

how to convert this pascal code to purebasic ???

Code: Select all

      type  opcode = (add, neg, mul, divd, remd, div2, rem2, eqli, neqi, lssi,
                leqi, gtri, geqi, dupl, swap, andb, orb,
                load, stor, hhalt, wri, wrc, wrl, rdi, rdc, rdl, eol,
                ldc, ldla, ldl, ldg, stl, stg, move, copy, addc, mulc,
                jump, jumpz, call, adjs, sets, exit);
      instr  = record Case op: opcode of
                 add, neg, mul, divd, remd, div2, rem2, eqli, neqi, lssi,
                 leqi, gtri, geqi, dupl, swap, andb, orb,
                 load, stor, hhalt, wri, wrc, wrl, rdi, rdc, rdl, eol:
                        ();
                 ldc, ldla, ldl, ldg, stl, stg, move, copy, addc, mulc,
                 jump, jumpz, call, adjs, sets, exit:
                        (a: integer)
               End;

var code: array [0..cxmax] of instr;
      m   : array [0..amax] of integer;

Procedure gen(I: instr)
Procedure gen0(op: opcode)
a+

pat
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Pat,

Purebasic does not have Pascals elaborate typing system, so a direct translation is not possible.

What the code appears to be doing is creating an enumerated type representing assembly opcodes.

Probably the best approach is to create the commands as a set of constants. These constants would then be represented in your codes as long values. This means the variables are declared as default type or with .l.

You will then have to code the features offered by Pascal's typing. For example create an IsInstr() command.

If you really need to use Pascal's typing then why not try FreePascal.

Both Purebasic and FreePascal support DLLs so you can easily mix the two, perhaps using Purebasic for the GUI and FreePascal for the backend.
patrick88
User
User
Posts: 18
Joined: Sat May 03, 2003 10:30 am

Post by patrick88 »

thanks for your answer,
GedB wrote: If you really need to use Pascal's typing then why not try FreePascal.
it's not my goal, i bought turbo pascal and delphi 2, a long time ago...
if I does that, it is that I desire to know how it goes an compiler/interpreter....
a+

pat
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

In that case, Patrick, what exactly does the code do?

As I say, a direct translation is out of the question. However, you should be able achieve the same results in Purebasic.
patrick88
User
User
Posts: 18
Joined: Sat May 03, 2003 10:30 am

Post by patrick88 »

a+

pat
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

I'm no Pascal whiz, so the 1995-Snepscheut implementations leave me baffled. Very clever programming, I'm sure.

It looks like you'll have a lot more success with the 1975-Wirth implementation of Pascal-S. These use much more generic code which should prove easier to convert.

Purebasic is a much closer relation to C. Perhaps it would be a good idea to begin by converting one of the C implementations of PL/0 before tackling Pascal-S.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

@patrick88:

Code: Select all

Enumeration
  #add : #neg : #mul : #divd : #remd : #div2 : #rem2 : #eqli : #neqi : #lssi
  #leqi: #gtri: #geqi: #dupl : #swap : #andb : #orb  : #load : #stor : #hhalt
  #wri : #wrc : #wrl : #rdi  : #rdc  : #rdl  : #eol  : #ldc  : #ldla : #ldl
  #ldg : #stl : #stg : #move : #copy : #addc : #mulc : #jump : #jumpz: #call
  #adjs: #sets: #exit

  #lastopcode
EndEnumeration

DataSection
  instructions:
    Data$ "add" ,"neg" , "mul","divd","remd","div2", "rem2","eqli", "neqi","lssi"
    Data$ "leqi","gtri","geqi","dupl","swap","andb", "orb" ,"load", "stor","hhalt"
    Data$ "wri" ,"wrc" , "wrl", "rdi", "rdc","rdl" , "eol" , "ldc", "ldla","ldl"
    Data$ "ldg" ,"stl" , "stg","move","copy","addc", "mulc","jump","jumpz","call"
    Data$ "adjs","sets","exit"
EndDataSection

Procedure Init()
  Dim instr.s(#lastopcode-1)
  Restore instructions
  For a = 0 To #lastopcode-1
    Read A$
    instr(a)=A$
  Next a
EndProcedure


Init()

Debug instr(#mul)
Debug instr(#copy)
Debug instr(#exit)
Is this what you wanted ??
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
Post Reply