glcc: minilisp - w-i-p

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
petersieg
Posts: 111
Joined: 28 Jun 2023, 09:06

glcc: minilisp - w-i-p

Post by petersieg »

Original source on github: https://github.com/Robert-van-Engelen/t ... /tree/main
More infos:
https://raw.githubusercontent.com/Rober ... nylisp.pdf
https://www.hpmuseum.org/forum/thread-18559.html

This zip contains minilisp (mlisp850). It compiles with glcc, but does not run as it should?
(Under Mac OS, it runs fine and on input (+ 1 2) it answers correct with 3..)

make output:
../../build/glcc -o lisp850.gt1 lisp850.c -map=64k -rom=v5a
lisp850.c:73: warning: expression with no effect elided
lisp850.c:74: warning: expression with no effect elided
lisp850.c:105: warning: missing return value

So this is currently NOT running as it should.
Maybe some c expert want to give it a try ;-) :D

best, Peter
Attachments
lisp850.zip
(22.47 KiB) Downloaded 109 times
lb3361
Posts: 367
Joined: 17 Feb 2021, 23:07

Re: glcc: minilisp - w-i-p

Post by lb3361 »

That's because the Gigatron double format is not IEEE754 but period correct Microsoft floating point (5 bytes). There are no NaNs, so NaN boxing won't work...
petersieg
Posts: 111
Joined: 28 Jun 2023, 09:06

Re: glcc: minilisp - w-i-p

Post by petersieg »

lb3361
Posts: 367
Joined: 17 Feb 2021, 23:07

Re: glcc: minilisp - w-i-p

Post by lb3361 »

Minilisp is not hopeless but one has to change it from NaN boxing to some variant of tagged format.

Code: Select all

typedef struct { double d; char t; } cell_t;

#define I     unsigned long
#define L     cell_t
#define D(x)  ((x).d) /* This macro is new and needs to be added in the right places everywhere */
#define T(x)  ((x).t)
...
The result is very slow because it relies on passing structures by copy and on floating point emulation. This is a bit more acceptable with dev7.rom because the new opcodes help a lot for those operations. Yet this is far from a speed competitive lisp.
Attachments
lisp850-tagged.zip
(19.87 KiB) Downloaded 113 times
Last edited by lb3361 on 11 Aug 2023, 18:34, edited 1 time in total.
petersieg
Posts: 111
Joined: 28 Jun 2023, 09:06

Re: glcc: minilisp - w-i-p

Post by petersieg »

You are a C genious!
I have to admit, that I have no clue, what you have done.
Have to study the diff (attached) a bit ;-)

Anyway - many thanks.
We know have an ancient and slow micro lisp interpreter on Gigatron.

best, Peter
Attachments
lisp850.diff.txt
(2.68 KiB) Downloaded 122 times
lb3361
Posts: 367
Joined: 17 Feb 2021, 23:07

Re: glcc: minilisp - w-i-p

Post by lb3361 »

And here is another one which represents the cells with longs. The tag is in the high four bits of the long. No floating point here. Yet it is closer to the original than the tagged version. This is a bit faster because it only uses long emulation and avoids structure copies. Still much better under dev7.rom though.

Code: Select all

#define I      unsigned
#define L      long
#define T(x)   (I)(x>>24)
#define B(t,x) ((L)(x)&0xffffffL|(((L)(t))<<24)).   /* This is a boxing macro to be used instead of T(n) = ... */
....
L box(I t,I i) { return B(t,i); }
I ord(L x) { return (I)x; }
L num(L n) { return ((n&0xfffffffL)^0x8000000L)-0x8000000L; }
...
L atomic() {
  char *endptr; L n = strtol(buf, &endptr, 0);
  return isdigit(buf[*buf == '-']) && !*endptr ? n : atom(buf);
}
...
I believe it is still worth looking at https://github.com/rui314/minilisp, if you care...
Attachments
lisp850-long.zip
(60.96 KiB) Downloaded 138 times
petersieg
Posts: 111
Joined: 28 Jun 2023, 09:06

Re: glcc: minilisp - w-i-p

Post by petersieg »

Thx again!
The included gt1 doesnt run? New compiled = works fine in romv5a and 64k ;-)
---
To the minilisp from: https://github.com/rui314/minilisp
After first simple changes, glcc doesnt seem to like the declaration around line 71 `struct Obj':
../../build/glcc -o minilisp.gt1 minilisp.c -map=64k -rom=v5a

Code: Select all

minilisp.c:71: field name missing
minilisp.c:81: field name missing
minilisp.c:87: field name missing
minilisp.c:90: field name missing
minilisp.c:94: illegal expression
minilisp.c:94: cast from `int' to `struct Obj' is illegal
minilisp.c:94: lvalue required
minilisp.c:94: syntax error; found `TTRUE' expecting `;'
minilisp.c:94: redeclaration of `TTRUE' previously declared at minilisp.c:43
minilisp.c:94: syntax error; found `}' expecting `;'
minilisp.c:94: skipping `}'
minilisp.c:95: illegal expression
minilisp.c:95: cast from `int' to `struct Obj' is illegal
minilisp.c:95: lvalue required
minilisp.c:95: syntax error; found `TNIL' expecting `;'
minilisp.c:95: redeclaration of `TNIL' previously declared at minilisp.c:44
minilisp.c:95: syntax error; found `}' expecting `;'
minilisp.c:95: skipping `}'
minilisp.c:96: illegal expression
minilisp.c:96: cast from `int' to `struct Obj' is illegal
minilisp.c:96: too many errors
make: *** [minilisp.gt1] Error 1
best, Peter
Attachments
minilisp.c
(30.94 KiB) Downloaded 126 times
lb3361
Posts: 367
Joined: 17 Feb 2021, 23:07

Re: glcc: minilisp - w-i-p

Post by lb3361 »

petersieg wrote: 12 Aug 2023, 08:03 The included gt1 doesnt run? New compiled = works fine in romv5a and 64k ;-)
My mistake. These were the dev7 versions. The lisp850sim.gt1 one is intended to run in the glcc test simulator gtsim. This is convenient for debugging.

Code: Select all

./build/gtsim -rom gigatron/roms/dev7.rom ~/Downloads/lisp850/lisp850sim.gt1
petersieg wrote: 12 Aug 2023, 08:03 To the minilisp from: https://github.com/rui314/minilisp
After first simple changes, glcc doesnt seem to like the declaration around line 71 `struct Obj':

Code: Select all

../../build/glcc -o minilisp.gt1 minilisp.c -map=64k -rom=v5a
minilisp.c:71: field name missing
No luck. These is a convenient C11 feature called anonymous structure and unions (see https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html) but lcc only supports C89. It won't work without adding names and using these names in all places where they were elided. I looked briefly at the code and it seems that some macros also depend on mixing declarations and statements.
Last edited by lb3361 on 05 Sep 2023, 23:22, edited 1 time in total.
petersieg
Posts: 111
Joined: 28 Jun 2023, 09:06

Re: glcc: minilisp - w-i-p

Post by petersieg »

Yes. Some need and small code relies on brand new features ;-)
Maybe some other minilisp is better/easier to convert towards glcc and Gigatron?
Anyway, we have now lisp850 :-)

thx, Peter
Attachments
Bildschirmfoto 2023-08-12 um 18.33.55.png
Bildschirmfoto 2023-08-12 um 18.33.55.png (46.09 KiB) Viewed 1439 times
lb3361
Posts: 367
Joined: 17 Feb 2021, 23:07

Re: glcc: minilisp - w-i-p

Post by lb3361 »

lb3361 wrote: 13 Aug 2023, 07:04 No luck. These is a convenient C11 feature called anonymous structure and unions (see https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html) but lcc only supports C89. It won't work without adding names and using these names in all places where they were elided. I looked briefly at the code and it seems that some macros also depend on mixing declarations and statements.
I just implemented two useful features found in C99 or C11:
  • Mixed declarations and statements.
  • Anonymous structs and unions.
This might be a good time to give another try minilisp.c.

There might still be problems with this kind of initialization

Code: Select all

static Obj *True = &(Obj){ TTRUE };
but one can write instead

Code: Select all

static Obj objTrue = { TTRUE };
static Obj *True = &objTrue;
Post Reply