adamdunkels/ubasic — pull request #1 by dbohdan (2013-12-22 15:28:28+00:00)
Title: Assignment bug fix, tests, loop speed improvement, REM and a couple other things.

I got to play with uBASIC this weekend. Nice old-school little language! This patch is the direct result of my playing with it and contains the following additions:

* Bugfix: it was impossible to assign a value to or get the value of the variable `a`. This was due to the comparison `if(varnum > 0 && varnum <= MAX_VARNUM)` in `ubasic_get_variable` and `ubasic_set_variable` where a zero would mean `a`.

* The ability to add comments to the code with REM. The tokenizer now discards `rem anything\n` at runtime.

* Line indexing. As a uBASIC program is run its lines are added to an "index" that maps the line number to the actual pointers to where in the source code those lines are (implemented as a linked list of structs). This makes jumping back in the program significantly faster.

On my machine line indexing improves the run time of the code

10 for i = 0 to 126
20 for j = 0 to 126
30 for k = 0 to 1
40 next k
50 next j
60 next i
70 end

from 0.650 s to 0.150 s.

* Tests for the correctness of assignment to `a`, looping and goto in the file `tests.c`. They can be compiled with `make tests`.

* The identifier `VARIABLE_TYPE` in `vartype.h` as a more clean way to change the type of uBASIC's variables and its tokenizer's expressions (e.g., in case you want them to be `int`s rather than `char`s).

* The file `LICENSE`. There was a license for uBASIC [on your website] (http://dunkels.com/adam/ubasic/license.html) but not in the repository.

* Tabs replaced with spaces where they were mixed together.