Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Trap full -- please empty.


devel / comp.lang.misc / Re: Designing an object system for a compiler's data

SubjectAuthor
* Designing an object system for a compiler's dataluserdroog
+- Re: Designing an object system for a compiler's dataluserdroog
`* Re: Designing an object system for a compiler's dataluserdroog
 `- Re: Designing an object system for a compiler's dataluserdroog

1
Designing an object system for a compiler's data

<aa7091fb-5e11-4d25-b373-48b270a8e0e2n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1810&group=comp.lang.misc#1810

  copy link   Newsgroups: comp.lang.misc
X-Received: by 2002:ac8:5754:0:b0:2e1:eee8:be0b with SMTP id 20-20020ac85754000000b002e1eee8be0bmr21487593qtx.349.1651117675219;
Wed, 27 Apr 2022 20:47:55 -0700 (PDT)
X-Received: by 2002:a37:6c46:0:b0:60d:d526:7e48 with SMTP id
h67-20020a376c46000000b0060dd5267e48mr18554780qkc.451.1651117675033; Wed, 27
Apr 2022 20:47:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.misc
Date: Wed, 27 Apr 2022 20:47:54 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=24.207.213.87; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.207.213.87
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <aa7091fb-5e11-4d25-b373-48b270a8e0e2n@googlegroups.com>
Subject: Designing an object system for a compiler's data
From: mijoryx@yahoo.com (luserdroog)
Injection-Date: Thu, 28 Apr 2022 03:47:55 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 74
 by: luserdroog - Thu, 28 Apr 2022 03:47 UTC

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;
};

struct parser {
object env;
fParser *f;
};

struct operator {
object env;
fOperator *f;
};

struct symbol {
int code;
char *printname;
object data;
};

struct string {
char *ptr;
int disposable;
};

extern boolean T_, NIL_;

Re: Designing an object system for a compiler's data

<b27319cb-0aab-42fa-83b0-0e00845ae1a5n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1811&group=comp.lang.misc#1811

  copy link   Newsgroups: comp.lang.misc
X-Received: by 2002:a05:6214:d47:b0:456:4672:d6e5 with SMTP id 7-20020a0562140d4700b004564672d6e5mr7849578qvr.22.1651118395446;
Wed, 27 Apr 2022 20:59:55 -0700 (PDT)
X-Received: by 2002:ad4:5dee:0:b0:455:b847:2960 with SMTP id
jn14-20020ad45dee000000b00455b8472960mr19186078qvb.27.1651118395309; Wed, 27
Apr 2022 20:59:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.misc
Date: Wed, 27 Apr 2022 20:59:55 -0700 (PDT)
In-Reply-To: <aa7091fb-5e11-4d25-b373-48b270a8e0e2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=24.207.213.87; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.207.213.87
References: <aa7091fb-5e11-4d25-b373-48b270a8e0e2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b27319cb-0aab-42fa-83b0-0e00845ae1a5n@googlegroups.com>
Subject: Re: Designing an object system for a compiler's data
From: mijoryx@yahoo.com (luserdroog)
Injection-Date: Thu, 28 Apr 2022 03:59:55 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 11
 by: luserdroog - Thu, 28 Apr 2022 03:59 UTC

On Wednesday, April 27, 2022 at 10:47:55 PM UTC-5, luserdroog wrote:
>
> 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
>

By the way, this is the "McIllroy convention" so the guards go on the outside,
deciding whether or not to even look at this file.

Re: Designing an object system for a compiler's data

<457ef04c-0e56-499d-9dfa-7df0f57a97cbn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1816&group=comp.lang.misc#1816

  copy link   Newsgroups: comp.lang.misc
X-Received: by 2002:ac8:5905:0:b0:2f3:9fdd:22f1 with SMTP id 5-20020ac85905000000b002f39fdd22f1mr22372018qty.191.1651775825634;
Thu, 05 May 2022 11:37:05 -0700 (PDT)
X-Received: by 2002:a37:a149:0:b0:69f:bb3c:9f09 with SMTP id
k70-20020a37a149000000b0069fbb3c9f09mr21162756qke.21.1651775825452; Thu, 05
May 2022 11:37:05 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.misc
Date: Thu, 5 May 2022 11:37:05 -0700 (PDT)
In-Reply-To: <aa7091fb-5e11-4d25-b373-48b270a8e0e2n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=24.207.219.108; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.207.219.108
References: <aa7091fb-5e11-4d25-b373-48b270a8e0e2n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <457ef04c-0e56-499d-9dfa-7df0f57a97cbn@googlegroups.com>
Subject: Re: Designing an object system for a compiler's data
From: mijoryx@yahoo.com (luserdroog)
Injection-Date: Thu, 05 May 2022 18:37:05 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 75
 by: luserdroog - Thu, 5 May 2022 18:37 UTC

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.
>
> 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;
> };

Darnitall. It's pretty. But I think it's not going to work.
I can't mutate suspensions into other types behind
the scene because the type is coupled into the handle.

If the handle is just a pointer to a tagged union, then
I can swap the unions in memory to change the
suspension object into some other object and this
works no matter how many times the suspension
is referenced.

With the tag pulled out to the front, then the tag may
exist in multiple places in memory, one coupled to
every reference. But I don't have an easy list of those
to patch. Some may be in automatic memory in the
call stack. Some could have already been virtualized
and disappeared.

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.

Re: Designing an object system for a compiler's data

<07ec2e30-b20a-4ec9-84c4-b7fac9b2c268n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1821&group=comp.lang.misc#1821

  copy link   Newsgroups: comp.lang.misc
X-Received: by 2002:a5d:6d8a:0:b0:21b:a2a3:55f8 with SMTP id l10-20020a5d6d8a000000b0021ba2a355f8mr2825268wrs.283.1655918548558;
Wed, 22 Jun 2022 10:22:28 -0700 (PDT)
X-Received: by 2002:a05:6214:20e9:b0:46e:27b5:fe16 with SMTP id
9-20020a05621420e900b0046e27b5fe16mr28721751qvk.42.1655918547910; Wed, 22 Jun
2022 10:22:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.128.87.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.misc
Date: Wed, 22 Jun 2022 10:22:27 -0700 (PDT)
In-Reply-To: <457ef04c-0e56-499d-9dfa-7df0f57a97cbn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=24.207.219.108; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 24.207.219.108
References: <aa7091fb-5e11-4d25-b373-48b270a8e0e2n@googlegroups.com> <457ef04c-0e56-499d-9dfa-7df0f57a97cbn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <07ec2e30-b20a-4ec9-84c4-b7fac9b2c268n@googlegroups.com>
Subject: Re: Designing an object system for a compiler's data
From: mijoryx@yahoo.com (luserdroog)
Injection-Date: Wed, 22 Jun 2022 17:22:28 +0000
Content-Type: text/plain; charset="UTF-8"
 by: luserdroog - Wed, 22 Jun 2022 17:22 UTC

On Thursday, May 5, 2022 at 1:37:06 PM UTC-5, luserdroog wrote:
> 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.
> >
[snip]
>
> 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.

Back to pointers version available for review:

https://codereview.stackexchange.com/questions/277525/5912/parser-combinators-in-c-redux

or

https://github.com/luser-dr00g/pcomb/archive/af8c3354f0a615087de79d3ccb409f32ef47d480.zip

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor