Author Topic: The R$ Project & Download  (Read 9964 times)

0 Members and 1 Guest are viewing this topic.

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
The R$ Project & Download
« on: September 29, 2007, 05:30:57 PM »
R$ Download

Updates:

13:05 15 Oct 2007 new reword operator / first stage of metabasic project (md at console)
14:45 11 Oct 2007 add Patch-Tokeniser to improve speed/ Lose the go instruction/
22:00 08 Oct 2007 Tidy Directory Structure: All progs in ./prog/
11:45 08 Oct 2007 Console functions getrow getcol  / New console.prog with 'Doskey' line recall facility
00:15 07 Oct 2007 '). '.' duplication operator/ ? help command for console / METABASIC html reporting
09:30 06 Oct 2007 ').' fix / 'save' fix / new mb console command for METABASIC testing
15:30 05 Oct 2007 using prog files / using r$.data as source / further Assemberising.
16:00 03 Oct 2007 word bug fixed / preprocessor using r$.dat as source.
11:45 30 Sep 2007 More boundary protection for stacks.

ZIP available below.

Generating FreeBasic source code and instruction list from r$.data

1: Extract from the zip file
2: Activate r$
3: type 2 dots '..' at the R$ console and press ENTER.
    This will generate FreeBasic source code: 'rr$.bas'
    If you do this in a FreeBasic console then it will also compile to rr$.exe
5  info ENTER will generate the instruction list from the basic source code into file 'info.txt'
6: single dot '.' and ENTER to quit the console.

If you want to try this this in Linux, I can supply the r$ binary.


This page will be frequently updated as the R$ project progresses.

This uses a very simple console, itself written in R$, enabling single line expressions to be tested and recorded in 'log.txt' with their results.

INSTRUCTION LIST

This is automatically derived from the R$.bas source file, so will always be  'in sync' with the latest version.

The numbers in the second column specify how many parameters are used by each function followed by the change to the the stack pointer.

  R$                   '
  An Object Oriented  postfix Language '
  Charles E V Pegge    '
  Start: 1 Sept 2007 - '
  updates 12:43   15 Oct 2007 '
  '
  '
  Preprocessed with R$ self coding manager '
  Compiled with Freebasic v0.18 '
  '
  '
  -----------------------------------'
  type0+1     create a type definition
  union0+1     created a union definition
  INTRINSIC TYPES USED IN type STATEMENT
  ---------------------------------------
  cdeclc C call
  stdcallk standard system vall
  int1b single unsigned byte
  int2i 1 byte signed integer
  int4l 4 byte signed integer
  int8q 8 byte signed integer
  real4s 4 byte single precision floating point
  real8d 8 byte double prevision floating point
  z n bytes fixed length string including null terminating byte
  ---------------------------------------
  gettype1+1     get variable type code
  settype2-1     set variable type code
  getname1+1     get name of variable (derefrenced)
  nderef0+0     suppress derefencing on next variable
  getid1+0     get the index if the quoted variable
  setname2-1     set the name of a variable
  machinex0+1     machine code sequence of opcodes, extended call
  machine0+1     machine code sequence of opcodes. simple call
  args1-1     number of args taken from stack  in a 'def' procedure
  incr0+0     increment a number variable
  decr0+0     decrement a number variable
  len1+1     get length of any variable
  then0+0     optional word with no effects
  if0+0     if (followed by condition word) .. endif
  -------------------------------------- '
  eqif equal
  ltif less than
  leif less than or equal
  gtif greater than
  geif greater that or equal
  neif not equal
  trueif equal
  falseif not equal
  isif non zero (or len string>0)
  nullif zero (or empty string)
  voidif zero (or empty string)
  -------------------------------------- '
  endif0+0     the end of an 'if' block
  cmp2-1     compare operands and set the sign flag but make no changes
  def0+1     define a procedure (and step over)
  exit0+0     exit from a bracket block
  exec2+0     call a string containing R$ script
  end0+0     end of def procedure
  returns1+0     number of params to leave on stack after leaving a def
  array1-1     specify array eg: 40 array myarray
  idx1-1     index to array eg: 40 idx myarray
  pop0-1     deallocat the last var by decrementing the stack pointer (this is a build upwards
  repeat0+0     block repeat The block is defined by () brackets
  ref0+0     put a reference to a variable on the stack eg: ref myvar
  to0+0     assign current stack content to a named variable eg: 42 to myvar
  swap2+0     swap last 2 members on the stack
  state0+0     store R$ state in locations  @1..@7 / a snapshot
  exist1+0     does something exist eg: "myvar" exist if false then 42 : myvar endif
  find1+0     find a variable and place it in current posotion eg: "myvar" find if true ? endif
  examine1+1     markup structure and content of a low level UDT and.  place result on stack.
  asc2+0     get ascii code from char in a string
  chr1+0     convert asci to character
  ltrim1+0     trim left spaces
  rtrim1+0     trim right spaces
  lower1+0     convert to lowercase
  upper1+0     convert to uppercase
  mid3-1     extract part of a string by position and length
  midl3-1     extract part of a string by position and boundary position
  insert4-3     insert / delete string into prior string at position and exclusion position
  patch3-2     patch string into prior string at specified position.
  pos3-1     search for string in prior string starting at position
  hex1+1     return hexadecimal string of a number
  oct1+1     return octal string of number
  bin1+1     return binary string of number
  str1+1     return string of number
  many2-1     return repeating string elements
  read1+0     set up a string to read its words (no effect on stack)
  word0+0     read the next word in a read string (see read)
  reword1+0     alter current word eg:  "a_" word, reword (inserts prefix a_)
  val1+1     return the value of any number, text or binary
  date0+1     return the date in US mm/dd/yyyy format
  time0+1     return the time in hh:mm:ss format
  getcol0+1     get the cursor column position
  getrow0+1     get the cursor row position
  getkey0+1     get the string generated by the last key press
  getline1+0     print the string promt and wait for line input from the console
  setcolor2-2     set the forground and background color of console output
  cls0+0     clear the console display
  beep0+0     console beep
  locate3-3     place the console cursor at the specified row, column and specify cursor visibili
  shell1-1     invoke a shell command eg: "dir *.txt>t.t" shell
  file1+1     open a file and return the file handle: eg "myfile.txt" file : myfile
  filein1+1     open a file to read individual lines of text (using in)
  fileout1+1      open an output file to print text strings (using out)
  fileappend1+1      append to an existing output file (using out)
  save2+0     save a string  to a file
  out2-1     print text to an output file eg "hello" myfile out    (see fileout)
  eof1+0     sets the sign flag if end of file is eached eg: myfile eof if true then ... endif
  loc1+0     return the position in a random access file (opened with file) eg: myfile loc
  lof1+0     return the length of a random access file (see file): eg myfile lof
  in1+0     return line of text from an input file (see filein) eg: myfile in
  load1+0      eg: "myfile.txt" load
  get2+0     get a string of bytes from a file (see file) of specified length eg: 50 myfile ge
  seek2-1     move position in a random access file (see file) eg: 4001 myfile seek
  lock3-3     lock region of a file to prevent shared access
  unlock3-3     unlock locked region of file
  put2-1     put a string of bytes into a random access file at the current location eg: "X" m
  close1-1     close an open file eg: myfile close   0 to myfile
  and2-1     bitwise and
  or2-1     bitwise or
  xor2-1     bitwise xor
  not1+0     not / bit inversion
  abs1+0     absolute value
  frac1+1     frac rturn the fraction of a number
  int1+1     return integer
  round2-1     round a number to n places eg: 1234.56789 3 round   (result 1234.568)
  sgn1+0     return sign of a number eg -0.23   result: -1
  neg1+0     negate / reverse sign
  mod2-1     modulus (supports floating point)  eg: 4.5 3 mod   Result: 1.5
  sqr1+0     square root
  log1+0     natural log
  exp2+0     exponent
  min2-1     minimum of 2 numbers
  max2-1     maximum of 2 numbers
  range3-3     within range? eg:  1 nyvalue 10 range if true then .. endif
  rnd1+0     random return a random number   eg: 1 rnd
  randomize0+0     seed randomiser (no effect on stack)
  degrees0+0     do trig functions in degrees
  radians0+0     do trig functions in radians
  cos1+0     cosine
  sin1+0     sine
  tan1+0     tangent
  atn1+0     arctangent
  libload1+0     get a dll handle: eg: "opengl32.dll" libload : opengl
  libfun2-1     get dll function address   eg: opengl "GLgetmatrix" libfun : GLgetmatrix
  libfree1-1     free dll  eg: opengl libfree
  replace1+0     replace a tagged structure in a string eg: "<xx>#1</>" replace myvec.x
  -------------------------------------- '
  dbl quote0+1     0x22 ".." quoted text '
  sgl quote0+1     0x27 '..' quoted text
  (0+0     0x28 ( left bracket block start (loop and block scoping) '
  )0-n     0x29 ) right bracket block end (restore stacks / diallocate vars) '
  ,1+0     0x2c , comma as concatenation operator eg: a b, appends b to a '
  .1+0     0x2e , dot as duplication operator eg: 3 . *  result: 9 '
  ),0+0     0x2c , concatenates last param inside block to last  param before the block '
  ).0+1     0x2e , pushes then last param inside the block onto the cleaned stack '
  +2-1     0x2b + add eg: 2 -3 4 + + '
  -2-1     0x2d - subtract eg: a b c - - '
  *2-1     0x2a * multiply eg: 32 q * '
  /2-1     0x2f / divide   eg: a b / '
  ^2-1     0x5e ^ power eg: 2 ^ .5 (square root of 2) '
  $0+1     0x24 quoted text eg $ ' "hello" ' ? $
  `0+n     0x60 inverted quotes eg $a`42 chr`b $ result: a*b '
  &0+0     0x26 absolute address prefix eg: &aa (absolute address of aa)  '
  :0+0     0x3a assign name to last variable on the stack eg: 42 : univ '
  @0+0     0x40 pointer prefix eg @1 (a system var) @a (a pointer var) '
  vert bar0+0     0x7c | comment till end of line '
  ?0+0     0x3f print data to console with crlf eg "hello"? '
  ??0+0     0x3f print to console without crlf '
  <0+0     0x3c markup left tag mark  '
  >0+0     0x3e markup  right tag mark '
  -------------------------------------- '
 
 
  Number of intrinsic commands/functions : 153
« Last Edit: July 19, 2013, 12:19:33 PM by Charles Pegge »

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
Re: R$ with Console
« Reply #1 on: October 08, 2007, 12:57:57 PM »
Here is the Console program included in the ZIP above. I am  placing it here with color highlighting, for illustrative purposes, since it contains a variety of useful components, including the line edit function and the memor history function.

Fortunately the keyboard control codes Under MS Windows and the Linux Bash terminal are the same, so no adaptations are required.

 This program will be periodically updated.


|
|   R$  POSTFIX LANGUAGE
|
|   Charles E V Pegge
|
|      8 Oct 2007



|=====================
| LINE EDITOR
|=====================
 def editline

  getcol 1 - : xa | anchor
  getrow : yp
  ref s len 1 + : xp
  getrow 1 xa + 1 locate s ? ? | Initial display
  (
   getkey : k
   if null repeat endif
   1 asc : a
   27 cmp if eq to kch exit endif
   10 cmp if eq to kch exit endif
   13 cmp if eq to kch exit endif
   255 cmp if eq
    k 2 asc
    72 cmp if eq to kch exit endif
    80 cmp if eq to kch exit endif
    73 cmp if eq to kch exit endif
    81 cmp if eq to kch exit endif
    75 cmp if eq decr xp endif
    77 cmp if eq incr xp endif
    71 cmp if eq 1 to xp endif
    79 cmp if eq ref s len 1 + to xp endif
    83 cmp if eq
     ref s "" xp xp 1 + insert
     yp 1 xa + 0 locate s " " , ? ? | blank end
    endif
   endif
   k len 1 cmp if eq
    a 8 cmp if eq
     xp 2 cmp if ge
      decr xp
      ref s "" xp xp 1 + insert
      yp ( ref s len 1 + xa + ) . 0 locate " " ? ? | blank end
     endif
    endif
    a 31 cmp if le
     "" : k
     a 9 cmp if eq
      9 chr : k
     endif
    endif
    ref s k xp xp insert
    k len xp + to xp
    yp 1 xa + 0 locate s ? ?
   endif
   1 xp max to xp
   s len 1 + xp min to xp
   getrow to yp
   yp xp xa + 1 locate
   repeat
  )
 end


|========================
| BLANK THE COMMAND LINE
|========================
 def clearline
  prompt len : lp
  getrow lp 1 + 1 locate
  ref s len : ls
  " " ls many ? ?
 end


|========================
| REMEMBER PREVIOUS LINES
|========================
 def memor
  0 chr : nch
  kch
  72 cmp if eq
   (
    hp 1 cmp if gt
     : e . : b
     "" to s
     (
      decr b
      if eq exit endif
      ref history b asc
      0 cmp
      if eq
       b to hp 1 + to b
       ref history b e midl to s 0 returns
       exit
      endif
      repeat
     )
    endif
   )
  endif
  80 cmp if eq
   (
    hp 1 + to b
    ref history nch b pos
    if eq clearline "" to s exit endif
    to hp
    ref history b hp midl to s 0 returns
   )
  endif
  13 cmp if eq
   ref s len
   if ne
    ref history s , nch ,
    len to hp
   endif
  endif
 end


|=====================
| (diagnostic)
|=====================
 def showhistory
  getrow : r
  getcol : c
  3 1 0 locate
  history ? ?
  r c 1 locate
 end



|=====================
| INITIAL
|=====================
 "" : s
 "" : mysession
 "" : result
 0 chr : history
 0 : hp
 0 : kch
 13 chr ( 10 chr ) , : crlf
 "<> " : prompt

 0 : a : b : c : d : e : f | these are user vars


 | cls
 | 10 1 1 locate
 "R$ Console" ?

|=====================
| MAIN LOOP
|=====================
(

 getrow 1 1 locate
 prompt ? ?
 editline

 kch 13 cmp if ne
  clearline
  memor
  kch 27 cmp if eq "" to s endif
  repeat
 endif

 memor | doskey facility
 "" ?

 | prompt getline : s | original method

 s

|=====================
| INTERPRETATION
|=====================

 "help" cmp if eq
  "?"
 endif

 "?" cmp if eq
  "
  CONSOLE COMMANDS
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   ? list of commands
   . end R $
   bye end R $
   # restart console
   info extract command list from r $ . data and generate table
   mark print a a file of a prog marked up in BB format
   rb build rr $ . bas from r $ . data
   mb metabasic prototype code generator ( being developed )
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  "
  ?
  "" to s
 endif
 |read word : w word : w1 word : w2
 |w

 "." cmp if eq
  exit
 endif

 "bye" cmp if eq
  exit
 endif

 "#" cmp if eq
  1 to restart
  0 returns
 endif

 "info" cmp if eq
  "./prog/intrinsics.prog" load exec "" to s
 endif

 "mark" cmp if eq
  "./prog/markup.prog" load exec "" to s
 endif

 "rb" cmp if eq
  "./prog/processr$.prog" load exec | preprocess
  "fbc ./rr$.bas" shell | compile
   "" to s
 endif

 "mb" cmp if eq
  "./prog/metabasic.prog" load exec "" to s
 endif

 if null
  repeat
 endif

 "0 " s , " str to result ? end " , exec
 mysession
 (
  " " 30 many "( " s , " )" , 1 patch
 ) ,
 " |:  " , |:  ",
 result ,
 crlf ,
 to mysession
 "" to s
 repeat
)
mysession "log.txt" save
end

« Last Edit: October 08, 2007, 02:23:36 PM by Charles Pegge »

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 284
    • Hellobasic.com
Re: R$ with Console
« Reply #2 on: October 08, 2007, 02:22:39 PM »
I might never use this language but i appreciate you thought about it's syntax.
Like everything in lowercase..
keep it so.

:)

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
Re: R$ with Console
« Reply #3 on: October 08, 2007, 03:07:10 PM »
Upper case is like shouting, and I assume most programmers have a sensitive disposition. But I can see why uppercase is useful in PB where there are hundreds of intrinsics that need to be distinguished from user/api functions and variables.

I am trying hard to keep the R$ word set to around 150 including symbols. If it was  just a high level language it would be less

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 284
    • Hellobasic.com
Re: R$ with Console
« Reply #4 on: October 08, 2007, 04:02:00 PM »
IF your language is case dependand it's *really* annoying, like javascript, each time i have to look it up.
like the idiotic setTimeout.. or was it SetTimeOut?? you see?

Offline Charles Pegge

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 704
    • Charles Pegge
Re: R$ with Console
« Reply #5 on: October 08, 2007, 04:41:07 PM »
It's currently case sensitive. If the names are long, I prefer using underscores, as they are easier to read. But the scoping behaviour, I hope will reduce the need for troublesome long variable and function names. Functions can be as transient as variables on the stack. Simple names can then be reused in different contexts. A function can contain subfunctions which are local to itself. An entire  program can be contained in a single string, and all its symbols and definitions will be invisible to the rest of the code.