sho.co interpreter

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Mr.L
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Oct 09, 2011 7:39 am

sho.co interpreter

Post by Mr.L »

Here is a little program of mine that I wrote for my entertainment...
It's an interpreter for my own programming language called "sho.co"!
Before running the code, it is first compiled into an assembly-like code which is then interpreted.
It comes with a small IDE, an assembly viewer, a few examples, and a brief help file. I even wrote an entire Centipede Clone in sho.co :lol: (you can find it inside the "_examples" folder).
The IDE is based on Scintilla and supports syntax highlighting, AutoComplete, highlighting of matching braces and more.

The syntax is a bit like Basic and C and it looks like this:

Code: Select all

maxiter = 200

n = 0 Loop(
    x = n * 4
    y = x + 128
    i = n
    
    $RGB y x 0 i
    i = n + 64
    $RGB 64 255 x i
    i = n + 128
	y = 255 - x
    $RGB 64 y 255 i
    i = n + 192
    $RGB 64 0 y i
	n + 1 > 60 (Break)
)

width = 400
height = 300

Screen width height

y = 0 Loop(
	Float ci = y / height * 2.5 - 1.25
	
    x = 0 Loop(
		Float x0 = 0 Float y0 = 0
		Float cr = x / width * 2.5 - 2

		i = 0 Loop(
			Float v1 = x0 * x0
			Float v2 = y0 * y0
			(v1 + v2) > 4 (Break)
			y0 = y0 * 2 * x0 + ci
			x0 = v1 - v2 + cr
			i + 1 > maxiter (Break)
        )
        i < maxiter (ColorF i Plot x y)
		x + 1 > width (Break)
    )
    (y % 5) == 0 (Draw)
	y + 1 > height (Break)
)

Loop(
	Input Is 1 (End)
	Delay 250
)

End 

Define $RGB r g b i(
    i + #COLOR + 1
	!i = (b << 16) + (g << 8) + r
)
here is the assembly of the above code

Code: Select all

        [000000]     259   64989            GET maxiter 
        [000002]       4     200            SET 200 
        [000004]     259   64988            GET n 
        [000006]       4       0            SET 0 
        [000008]     259   64987            GET x 
        [000010]     260   64988            SET n 
        [000012]      12       4            MUL 4 
        [000014]     259   64986            GET y 
        [000016]     260   64987            SET x 
        [000018]      10     128            ADD 128 
        [000020]     259   64985            GET i 
        [000022]     260   64988            SET n 
        [000024]      37      36            PSH 36 
        [000026]     293   64986            PSH y 
        [000028]     293   64987            PSH x 
        [000030]      37       0            PSH 0 
        [000032]     293   64985            PSH i 
        [000034]      26     272            JMP $RGB 
        [000036]     259   64985            GET i 
        [000038]     260   64988            SET n 
        [000040]      10      64            ADD 64 
        [000042]      37      54            PSH 54 
        [000044]      37      64            PSH 64 
        [000046]      37     255            PSH 255 
        [000048]     293   64987            PSH x 
        [000050]     293   64985            PSH i 
        [000052]      26     272            JMP $RGB 
        [000054]     259   64985            GET i 
        [000056]     260   64988            SET n 
        [000058]      10     128            ADD 128 
        [000060]     259   64986            GET y 
        [000062]       4     255            SET 255 
        [000064]     267   64987            SUB x 
        [000066]      37      78            PSH 78 
        [000068]      37      64            PSH 64 
        [000070]     293   64986            PSH y 
        [000072]      37     255            PSH 255 
        [000074]     293   64985            PSH i 
        [000076]      26     272            JMP $RGB 
        [000078]     259   64985            GET i 
        [000080]     260   64988            SET n 
        [000082]      10     192            ADD 192 
        [000084]      37      96            PSH 96 
        [000086]      37      64            PSH 64 
        [000088]      37       0            PSH 0 
        [000090]     293   64986            PSH y 
        [000092]     293   64985            PSH i 
        [000094]      26     272            JMP $RGB 
        [000096]     259   64988            GET n 
        [000098]      10       1            ADD 1 
        [000100]      30      60     105    IGR 60 105
        [000103]      26     107            JMP 107 
        [000105]      26       8            JMP 8 
        [000107]     259   64984            GET width 
        [000109]       4     400            SET 400 
        [000111]     259   64983            GET height 
        [000113]       4     300            SET 300 
        [000115]    4408   64984   64983    SCR width height 
        [000118]     259   64986            GET y 
        [000120]       4       0            SET 0 
        [000122]     259   64999            GET ci 
        [000124]     260   64986            SET y 
        [000126]     269   64983            DIV height 
        [000128]      12     2.5            MUL 2.5 
        [000130]      11    1.25            SUB 1.25 
        [000132]     259   64987            GET x 
        [000134]       4       0            SET 0 
        [000136]     259   64998            GET x0 
        [000138]       4       0            SET 0 
        [000140]     259   64997            GET y0 
        [000142]       4       0            SET 0 
        [000144]     259   64996            GET cr 
        [000146]     260   64987            SET x 
        [000148]     269   64984            DIV width 
        [000150]      12     2.5            MUL 2.5 
        [000152]      11       2            SUB 2 
        [000154]     259   64985            GET i 
        [000156]       4       0            SET 0 
        [000158]     259   64995            GET v1 
        [000160]     260   64998            SET x0 
        [000162]     268   64998            MUL x0 
        [000164]     259   64994            GET v2 
        [000166]     260   64997            SET y0 
        [000168]     268   64997            MUL y0 
        [000170]      43                    PUV 
        [000171]     259   65008            GET 65008 
        [000173]     260   64995            SET v1 
        [000175]     266   64994            ADD v2 
        [000177]      44                    POV 
        [000178]     259   65008            GET 65008 
        [000180]      30       4     185    IGR 4 185
        [000183]      26     214            JMP 214 
        [000185]     259   64997            GET y0 
        [000187]     260   64997            SET y0 
        [000189]      12       2            MUL 2 
        [000191]     268   64998            MUL x0 
        [000193]     266   64999            ADD ci 
        [000195]     259   64998            GET x0 
        [000197]     260   64995            SET v1 
        [000199]     267   64994            SUB v2 
        [000201]     266   64996            ADD cr 
        [000203]     259   64985            GET i 
        [000205]      10       1            ADD 1 
        [000207]     286   64989     212    IGR maxiter 212
        [000210]      26     214            JMP 214 
        [000212]      26     158            JMP 158 
        [000214]     259   64985            GET i 
        [000216]     285   64989     224    ILO maxiter 224
        [000219]     309   64985            CLF i 
        [000221]    4407   64987   64986    PLT x y 
        [000224]     259   64987            GET x 
        [000226]      10       1            ADD 1 
        [000228]     286   64984     233    IGR width 233
        [000231]      26     235            JMP 235 
        [000233]      26     136            JMP 136 
        [000235]      43                    PUV 
        [000236]     259   65008            GET 65008 
        [000238]     260   64986            SET y 
        [000240]      20       5            MOD 5 
        [000242]      44                    POV 
        [000243]     259   65008            GET 65008 
        [000245]      33       0     249    IEQ 0 249
        [000248]      57                    DRW 
        [000249]     259   64986            GET y 
        [000251]      10       1            ADD 1 
        [000253]     286   64983     258    IGR height 258
        [000256]      26     260            JMP 260 
        [000258]      26     122            JMP 122 
        [000260]      60                    INP 
        [000261]      28       1     265    IFL 1 265
        [000264]       0                    END 
        [000265]      64     250            DLY 250 
        [000267]      26     260            JMP 260 
        [000269]       0                    END 
        [000270]      26     313            JMP 313 
            $RGB                            
        [000272]     294   64990            POP i 
        [000274]     294   64991            POP b 
        [000276]     294   64992            POP g 
        [000278]     294   64993            POP r 
        [000280]     259   64990            GET i 
        [000282]      10   65280            ADD #COLOR 
        [000284]      10       1            ADD 1 
        [000286]     771   64990            GET [!i] 
        [000288]      43                    PUV 
        [000289]     259   65008            GET 65008 
        [000291]     260   64991            SET b 
        [000293]      16      16            SHL 16 
        [000295]      44                    POV 
        [000296]     260   65008            SET 65008 
        [000298]      43                    PUV 
        [000299]     259   65008            GET 65008 
        [000301]     260   64992            SET g 
        [000303]      16       8            SHL 8 
        [000305]      44                    POV 
        [000306]     266   65008            ADD 65008 
        [000308]     266   64993            ADD r 
        [000310]     258   65008            MOV 65008 
        [000312]      40                    POI 
Here is the github link to the source code.
https://github.com/MR-L-PB/sho.co
Axolotl
Enthusiast
Enthusiast
Posts: 448
Joined: Wed Dec 31, 2008 3:36 pm

Re: sho.co interpreter

Post by Axolotl »

Mr.L wrote: Sat Apr 06, 2024 7:37 pm Here is a little program of mine that I wrote for my entertainment...
// .....
Here is the github link to the source code.
https://github.com/MR-L-PB/sho.co
HI Mr.L
Thanks for sharing.
I am always curious when it comes to scintilla and here I just wanted to let you know that the link is not working.
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
Mr.L
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Oct 09, 2011 7:39 am

Re: sho.co interpreter

Post by Mr.L »

Thanks for the response, I accidently set the project to 'private'... :oops:
Please try again, the link should work now
GoodNPlenty
Enthusiast
Enthusiast
Posts: 108
Joined: Wed May 13, 2009 8:38 am
Location: Arizona, USA

Re: sho.co interpreter

Post by GoodNPlenty »

Very Impressive. Thank You for sharing. :D
Post Reply