(PC-G850) lisp in 99 lines of C
|
07-14-2022, 09:47 PM
Post: #1
|
|||
|
|||
(PC-G850) lisp in 99 lines of C
I wrote a Lisp interpreter for the Sharp PC-G850 in 99 lines of C with a writeup in an article to explain the inner workings in detail. The C program compiles and runs on the PC-G850(V)(S) itself:
I created a tinylisp GitHub project repo with the code, examples, and the article writeup. The idea is to exploit something similar to NaN boxing of IEEE floats, but with Sharp BCD floats instead, "BCD float boxing". A BCD float is stored in 8 bytes. The first 2 bytes store the exponent in BCD and the sign of the number. The next 5 bytes store the 10 digit BCD mantissa followed by a zero byte: \[ |\overbrace{b~\underbrace{b~b~b}_{\it tag}~|~b~b~b~b~|~b~b~b~b}^{\it 10's\,complement\,BCD\,exponent}|~\overbrace{s~d~u~u}^{\it control}~|~\overbrace{b~b~b~b~|~\cdots~|~b~b~b~b}^{\it 10\,digit\,BCD\,mantissa}~|~\overbrace{0~0~0~0~|~0~0~0~0}^{\it 2\,BCD\,guard\,digits}~| \] where
To copy lisp to the Sharp PC-G850(V)(S) use SIO or PocketTools to load via audio cassette interface (CE-124 or CE-126p): PC: bas2img --pc=G850VS --type=asm -l0x408 lisp850-opt.c PC: bin2wav --pc=G850VS lisp850-opt.img G850: BASIC (PRO MODE) G850: BLOAD PC: play lisp850-opt.wav G850: TEXT G850: Basic G850: Text<-Basic G850: BASIC (2x PRO MODE) G850: NEW G850: 2ndF TEXT (C) G840: G (go) The bas2img option -l0x400 adds line numbers to the C source automatically. I've included the wav files in the GitHub repo in case you don't have PocketTools. - Rob "I count on old friends to remain rational" |
|||
07-15-2022, 06:41 AM
Post: #2
|
|||
|
|||
RE: (PC-G850) lisp in 99 lines of C
Marvellous - thank you!
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)