2kays / YOLOLISP

S-expression syntax for Starbase's YOLOL programming language
MIT License
2 stars 0 forks source link

Massive error log #1

Open MrMunchkin21 opened 5 months ago

MrMunchkin21 commented 5 months ago

I am trying to get YOLOLISP to work, though it is not going well.

When I run the .sh, I get a long error message with "Eager macro-expansion failure: (error "Misplaced t or 'otherwise' clause")" being the only thing I can see that leads me in any sort of direction of troubleshooting.

image_2024-04-12_152340646

2kays commented 5 months ago

Hi! As fate would have it, I actually saw your reddit thread before running in to this GH issue. I am intrigued by your intrigue in my incredibly obscure project!

I haven't touched anything Starbase or YOLOL in the years since the initial SB release, so my knowledge of YOLOL might be rusty and out of date. Nonetheless I'll try to get this running.

You appear to be running this through emacs in Git Bash. Which version of emacs are you using? emacs --version should tell us.

MrMunchkin21 commented 5 months ago

Version 29.1

YOLOL has not changed anything major since launch. I have been playing Starbase since CA though only recently got interested by Emacs. It has been a bit of a meme in my friend group of "There's a package for that", so out of curiosity, I searched for ELisp to YOLOL and was ecstatic to find this.

2kays commented 5 months ago

Well, now we know there are other Emacs-Starbase enthusiasts.

I got it running fairly quickly on Emacs 29.3 just now. I hope 29.1 fares the same.

I have just pushed some bugfixes, as well as the README's example as a file called inputfile.yololisp.

My cl-ecase usage was indeed wrong as that helpful user on the reddit thread pointed out (though I swear it wasn't an error when I wrote it! 😄).


inputfile.yololisp

;; Declarations are optional, but useful for hinting the optimizer.
;; In this case, the if-statement later can be made branchless.
(declare (type integer :c e))

;; Assignment
(set a  10
     :b (inc a))

;; Simple WHEN conditional
(when (== :b 11)
  (set :c 1))

;; IF conditional (optimisable into a branchless form)
(if :c
    (assign d 1)
  (assign d 2))

;; Arithmetic expressions
(set e (* d (+ :c :b)))
(set f (* a (* a (+ a a))))

; Looping!
(while (< :wout 5)
  (set :wout (+ :wout 2)))

(for ((x 0) (<= x 3) (inc x))
  (set :fout (* x x)))

;; Literal output for when YOLOLISP isn't enough
(literal "\nz = e + f")

;; Lisp comment vs. output YOLOL comment
(// "Made in YOLOLISP!")

I am able to run the following on this file and get an output:

~/code/yololisp $ ./yololisp.sh inputfile.yololisp > myfile.yolol
~/code/yololisp $ cat myfile.yolol 
a=10 :b=a++ if :b==11 then :c=1 end d=2*0^:c+1*:c e=d*(:c+:b)
f=a*a*(a+a)
if not :wout<5 then goto 4 end :wout+=2 goto 3
x=0
if not x<=3 then goto 6 end :fout=x*x x++ goto 5

z = e + f //Made in YOLOLISP!

Try that, and if not, I'll get 29.1 running locally to find out why not.


I also found some unpushed features I wrote for jump tables, if those are interesting to you, I can push 'em:

(set a -1)
(jmptab
  ((> a 0) (set :out "above"))
  ((<= a 0) (set :out "below")))
(set :done 1)
MrMunchkin21 commented 5 months ago

It almost works! The bash is showing the correct YOLOL, though it is not being sent to the myfile.yolol.

The jump tables do look quite interesting as well.

2kays commented 5 months ago

I've tried ./yololisp.sh inputfile.yololisp > myfile.yolol on eshell and bash and it works on both. Granted, my script probably sucks.

Does the following do anything good?

emacs -Q --batch -l yololisp-compiler.el --eval "(yl $(cat inputfile.yololisp) )" > myfile.yolol
MrMunchkin21 commented 5 months ago

IT WORKS!

I put the command in the .sh and it took the example Yololisp and converted it to YOLOL and put said YOLOL in the file. Hopefully in the future when I know a lot more, I can try to see what all I can expand to this as well since I love the concept.

Thank you very much indeed. I will also take a look into the jump tables as well if you are to push them. Hopefully this whole thing can push me into thoroughly learning ELisp as well.

I do question how the d=2*0^:c+1*:c works in Starbase though, since it seems a bit odd with the 0^ in it.

2kays commented 5 months ago

Great, glad it's working. I'll take a look at the jump table impl and push if it looks usable.

The d=2*0^:c+1*:c is a branchless rendition of the conditional trick listed in https://wiki.starbasegame.com/index.php?title=YOLOL_Tricks#Number_tricks. I think I had tested this and it worked, but I can't remember the hows and whys. It's 100% worth rechecking.

FWIW the relevant piece of code is here (though that Output comment looks a bit wrong...):

https://github.com/2kays/YOLOLISP/blob/b130aabb5feb52f40427263b61191692105b6b28/yololisp-compiler.el#L518-L537

MrMunchkin21 commented 5 months ago

Ohhhhhh, that is pretty bloody cool. I shall remember that. This is now on my increasing list of desired projects.

If you want to see the state of the game today as well, then I am often streaming it if you choose to take a look.

2kays commented 4 months ago

So I was finally able to get around to looking at the jump tables. It's close enough to be usable with a couple of manual fixes, but it's not quite "production ready" yet.

(set a -1)
(jmptab
 ((> a 0) (set :out "above"))
 ((== a 0) (set :out "equal"))
 ((< a 0) (set :out "below")))

;   _______________________________________________________________________
; 1 | a=-1
; 2 |
; 3 | goto 2+1*(a>0!=0)+2*(a==0!=0)*(a>0==0)+3*(a<0!=0)*(a==0==0)*(a>0==0)
; 4 | :out="above" goto 7
; 5 | :out="equal" goto 7
; 6 | :out="below" goto 7
; 7 |

There are two issues here:

  1. Incorrect offsets: the goto thinks it's starting on line 2 because of label elision gone wrong.
    The good news is that it works when one manually bumps the offsets, at least according to the emulator I used...
  2. The optimizer isn't smart enough to get a 3-branch jump table comfortably within the 70 char line limit. The lowest hanging fruit fix here is this a==0==0 bit of the computed goto, but there are probably a few other cheap wins. I think it'd be a huge struggle to get a 4-branch working in 70 characters though.

I'll have a crack at fixing the offset issue at some point.


I'm interested in a stream - feel free to plug it! It's been a long time since I've played, and I heard FB might be picking up development again?

MrMunchkin21 commented 4 months ago

Hmm.... I know that you don't need the space in-between the goto and number; goto1 or goto[variable] works when I do it in starbase for instance. That's one character saved....

I'm not an expert at YOLOL, though I will give a think throughout the day on a good way to organize it for more branches if it is possible.


Yes, FB is developing the game again. Some time this month we will have a major announcement on what they are up to and a rough roadmap. Later months will have a PTU update, then Live update after that. Quoting Lauri, the main things being worked on are:

  1. Cost of loss, ie. losing a ship shouldn't have such huge impact
  2. Down time, ie. long travel times where nothing happens
  3. Interactions between players and things to do, eg. Siege

So some interesting stuffs.

I will likely be live here in a second in Starbase as well, I am mining ore for a few ships at Elysium. https://www.twitch.tv/mrmunchkin21