Skip to content

krypciak-zz/IGB-Compiler-L1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IGB Compiler L1 compiles IGB L1 code into IGB Binary.
You may call it an assembly language.

The IGB CL2 compiles high-level code into this low-level code.

The instruction set file can be seen here.

Commant set symbol explanation:

  • *string*|*number* If the current argument equals string, number is returned.
  • i The input value is returned as it is.
  • d The input value gets multiplied by 1000 (learn why here)
  • @ accepts two arguments:
    • n that returns 0
    • c that returns 1
      If it's next argument is 'd' and the current argument equals 'c', the next argument isn't multiplied by 1000.
  • P If the argument is a string, returns the cell of a pointer. If the argument is an integer, returns it.

Example:

Hint: |12| means cell 12

input: Math % 10 c 11 12
syntax match: Math|7 %|3 i @ d i
output: 7 1 10 1 11 12

That instruction can be translated into |12| = |10| % |12|

If you swap the 'c' for a 'n', the second last argument will be 1000 times bigger.

input: Math % 10 n 11 12
syntax match: Math|7 %|3 i @ d i
output: 7 1 10 0 11000 12

That instruction can be translated into |12| = |10| % 12

Memory cells

There are cells allocated for the IGB VM. You are safe to use cells 70 or above. Here are some more important cells:
  0 - Function return
  1 - Screen width
  2 - Screen height
  3 - Screen type (0=16c, 1=rgb)
  4 - Keyboard input char
  56 - charLib char code
  57 - charLib char x
  58 - charLib char y

The full list can be seen here.

Instruction explanation:

0. If

  Syntax: If *operation* i @ d P
  If cell arg2 operation arg4 / |arg4| is false then jump to arg5 (pointer or integer)

  Example: If > 70 n 5 :myfunction
  Which means: If cell 70 is NOT higher than the number 5000 jump to :mypointer

1. Init

  Syntax: Init d i
  Writes arg1 to cell arg2

  Example: Init 5.3 70
  Which means: Write 5300 to cell 70

2. Copy

  Syntax: Copy i i
  Copies cell arg1 to cell arg2

  Example: Copy 70 71
  Which means: Read cell 70 and write it to cell 71

3. Add

  Syntax: Add i @ d i
  Adds cell arg1 to arg3 / |arg3| and store the result in cell arg4
  Why a seperate instruction for adding numbers? It's faster that way.

  Example: Add 70 c 71 72
  Which means: Add cell 70 and cell 71 and store the result in cell 72

4. Cell

  Jump Syntax: Cell Jump P
  Sets the current cell to arg2

  Call Syntax: Cell Call P
  Stores the current cell on a stack and sets the current cell to arg2

  Return Syntax: Cell Return
  Pops the stack and sets the current cell to it

5. Pixel

  The screen type (cell 3) determinates which syntax will do what at runtime.
  I recommend that you read about more about pixel cache here.

  • Pixel @ i @ i
      Sets the pixel at x=arg2 / |arg2|, y=arg4 / |arg4| with the color stored in the pixel cache.

  • Pixel Cache Raw i
      Sets the pixel cache to arg3


  RGB exclusive synax:
  • Pixel Cache @ i @ i @ i
      Calculated at runtime the pixel cache from the arguments. (arg3 is r, arg5 is g, arg7 is b)
      If all arguments are d, the cache is computed at compile-time and the instruction is swapped with Pixel Cache Raw.

  • Pixel @ i @ i i
      Gets the rgb color from pixel at x=arg2 / |arg2|, y=arg4 / |arg4| and

    • r is writen to cell arg5
    • g is written to cell arg5+1
    • b is written to cell arg5+2

  16c exclusive synax:
  • Pixel Cache i
      Sets pixel cache to cell arg2

  • Pixel @ i @ i i
      Gets the 16c color from pixel at x=arg2 / |arg2|, y=arg4 / |arg4| and writes it to arg5

6. Device

  • Device CoreWait i
      Waits arg2 ticks (a tick is 1/20 of a second)

  • Device ScreenUpdate
      Resizes the screen based on the cells in memory and filles it with #FFFFFF

  • Device Log @ d
      Prints arg3 / |arg3| to the terminal/chat.

7. Math

  • Syntax for - * / % operations: Math *operation* i @ d i
      It does what you think.

  • Syntax for random: Math R i i i
      Writes a random number from arg2 to arg3 to cell arg4


  • Syntax for CC: Math CC i i
      It reads the value from cell arg2, then reads the value at cell it just read, then writes in to cell arg3
      If you assume ram is an array, then that's how it works:
    ram[ arg3 ] = ram[ ram[ arg2 ] ]
      Used for reading from arrays.

  • Syntax for CW: Math CW i i
      Writes value from cell arg2 to cell read from cell arg3
      If you assume ram is an array, then that's how it works:
    ram[ ram[ arg3 ] ] = ram[ arg2 ]
      Used for writing to arrays.

  • Synax for sqrt: Math sqrt i i
    Writes the square root of cell arg2 to cell arg3




Dependencies:

License

Licensed under GNU GPLv3 or later

About

Compiles IGB L1 to IGB binary

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages