So, for showing off and/or soliciting critique, here's the first draft of the new Lisp/PostScript-ish objects in C. I'm still debating whether to add arrays or just keep using lists for everything.
#define PC10OBJECT_H
I've been playing with parser combinators off and on for a few years now,
and I have a new prototype in PostScript that seems to be working well.
So it's time to translate it all to C, the first step of which is the fun part of
designing an object system that's suitably Lisp-ish or PostScript-ish to represent the parsers and lists of arbitrary stuff.
I've been criticized in previous versions for using a typedef'd pointer as
my basic 'object' type that gets used everywhere. This time I don't do that. Instead the pointers are going to be in the middle and the basic object
with be a "double wrapped" pointer or integer.
So, for showing off and/or soliciting critique, here's the first draft of the new Lisp/PostScript-ish objects in C. I'm still debating whether to add arrays or just keep using lists for everything.
#define PC10OBJECT_H
typedef union object object;
typedef object list;
typedef object suspension;
typedef object parser;
typedef object boolean;
typedef object operator;
typedef operator predicate;
typedef object fSuspension( object );
typedef object fParser( object, list );
typedef object fOperator( object, object );
typedef boolean fPredicate( object, object );
typedef object fBinaryOperator( object, object );
typedef enum { INVALID, INT, LIST, SUSPENSION, PARSER, OPERATOR, SYMBOL, STRING, VOID } tag;
union object { tag t;
struct { tag t; int i; } Int;
struct { tag t; struct list *ref; } List;
struct { tag t; struct suspension *ref; } Suspension;
struct { tag t; struct parser *ref; } Parser;
struct { tag t; struct operator *ref; } Operator;
struct { tag t; struct symbol *ref; } Symbol;
struct { tag t; struct string *ref; } String;
struct { tag t; void *ptr; } Void;
};
struct list {
object a, b;
};
struct suspension {
object env;
fSuspension *f;
};
On Wednesday, April 27, 2022 at 10:47:55 PM UTC-5, luserdroog wrote:
I've been playing with parser combinators off and on for a few years now, and I have a new prototype in PostScript that seems to be working well.
So it's time to translate it all to C, the first step of which is the fun part of
designing an object system that's suitably Lisp-ish or PostScript-ish to represent the parsers and lists of arbitrary stuff.
I've been criticized in previous versions for using a typedef'd pointer as my basic 'object' type that gets used everywhere. This time I don't do that.
Instead the pointers are going to be in the middle and the basic object with be a "double wrapped" pointer or integer.
Such a pretty design, sigh. I guess it's back to pointers.
I'm not sure how I can implement lazy evaluation
without mutating the memory representation behind
the scenes.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (2 / 14) |
Uptime: | 63:39:58 |
Calls: | 6,488 |
Calls today: | 1 |
Files: | 12,096 |
Messages: | 5,274,684 |