Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all dynamic record features from Crochet #52

Merged
merged 6 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions examples/language/pocket-lisp/grammar/pocket-lisp.lingua.crochet

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"crochet.text.parsing.lingua",
"crochet.debug",
"crochet.wrapper.node.io",
"crochet.wrapper.node.file-system",
"crochet.language.cli-arguments"
"crochet.wrapper.node.file-system"
],
"capabilities": {
"requires": [],
Expand Down
2 changes: 0 additions & 2 deletions repl/basic-repl.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
"crochet.codec.basic",
"crochet.core",
"crochet.debug",
"crochet.language.cli-arguments",
"crochet.language.csv",
"crochet.language.json",
"crochet.mathematics",
"crochet.parsing.combinators",
"crochet.random",
"crochet.text.parsing.lingua",
"crochet.time",
Expand Down
2 changes: 0 additions & 2 deletions repl/node-repl.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
"crochet.codec.basic",
"crochet.core",
"crochet.debug",
"crochet.language.cli-arguments",
"crochet.language.csv",
"crochet.language.json",
"crochet.mathematics",
"crochet.parsing.combinators",
"crochet.random",
"crochet.text.parsing.lingua",
"crochet.time",
Expand Down
10 changes: 0 additions & 10 deletions source/binary-encode/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,6 @@ class CrochetIREncoder extends BinaryWriter {
break;
}

case IR.OpTag.RECORD_AT_PUT: {
this.encode_meta_id(x.meta);
break;
}

case IR.OpTag.PROJECT: {
this.encode_meta_id(x.meta);
break;
}

case IR.OpTag.PROJECT_STATIC: {
this.encode_meta_id(x.meta);
this.string(x.key);
Expand Down
2 changes: 1 addition & 1 deletion source/binary/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const MAGIC = "CROC";
export const VERSION = 34;
export const VERSION = 35;

export enum Section {
DECLARATION = 1,
Expand Down
6 changes: 0 additions & 6 deletions source/binary/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,6 @@ class CrochetIRDecoder extends BinaryReader {
this.array((_) => this.string())
);

case t.RECORD_AT_PUT:
return new IR.RecordAtPut(this.decode_meta_id());

case t.PROJECT:
return new IR.Project(this.decode_meta_id());

case t.PROJECT_STATIC:
return new IR.ProjectStatic(this.decode_meta_id(), this.string());

Expand Down
68 changes: 10 additions & 58 deletions source/compiler/lower-to-ir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,51 +684,23 @@ export class LowerToIR {
}

record_field(x: Ast.RecordField) {
return x.match<
{ static: true; name: string } | { static: false; expr: IR.Op[] }
>({
FName: (n) => ({
static: true,
name: n.name,
}),

FText: (n) => ({
static: true,
name: parseString(n),
}),

FComputed: (x) => ({
static: false,
expr: this.expression(x),
}),
return x.match<string>({
FName: (n) => n.name,

FText: (n) => parseString(n),
});
}

record_pairs(xs0: Ast.Pair<Ast.RecordField, Ast.Expression>[]) {
const xs1 = xs0.map((x) => {
const pairs = xs0.map((x) => {
return {
pos: x.pos,
key: this.record_field(x.key),
value: this.expression(x.value),
};
});

const xs_static = xs1
.filter((x) => x.key.static)
.map((x) => ({
key: (x.key as { static: true; name: string }).name,
value: x.value,
}));

const xs_dynamic = xs1
.filter((x) => !x.key.static)
.map((x) => ({
pos: this.context.register(x.pos),
expr: (x.key as { static: false; expr: IR.Op[] }).expr,
value: x.value,
}));

return { pairs: xs_static, dynamic_pairs: xs_dynamic };
return pairs;
}

comprehension(x: Ast.ForExpression): IR.Op[] {
Expand Down Expand Up @@ -917,10 +889,7 @@ export class LowerToIR {
const id = this.context.register(pos);
const type_id = this.context.register(type0.pos);
const type = new IR.LocalType(type_id, type0.name);
const { pairs, dynamic_pairs } = this.record_pairs(fields0);
if (dynamic_pairs.length !== 0) {
throw new Error(`internal: invalid AST.`);
}
const pairs = this.record_pairs(fields0);
return [
...pairs.flatMap((x) => x.value),
new IR.PushNewNamed(
Expand All @@ -935,10 +904,7 @@ export class LowerToIR {
const id = this.context.register(pos);
const type_id = this.context.register(type0.pos);
const type = new IR.LocalType(type_id, type0.name);
const { pairs, dynamic_pairs } = this.record_pairs(fields0);
if (dynamic_pairs.length !== 0) {
throw new Error(`internal: invalid AST.`);
}
const pairs = this.record_pairs(fields0);
return [
...pairs.flatMap((x) => x.value),
...this.expression(base),
Expand All @@ -958,36 +924,22 @@ export class LowerToIR {

Record: (pos, pairs0) => {
const id = this.context.register(pos);
const { pairs, dynamic_pairs } = this.record_pairs(pairs0);
const pairs = this.record_pairs(pairs0);

return [
...pairs.map((x) => x.value).flat(1),
new IR.PushRecord(
id,
pairs.map((x) => x.key)
),
...dynamic_pairs.flatMap((x) => {
return [...x.expr, ...x.value, new IR.RecordAtPut(x.pos)];
}),
];
},

Project: (pos, object0, field0) => {
const id = this.context.register(pos);
const field = this.record_field(field0);

if (field.static) {
return [
...this.expression(object0),
new IR.ProjectStatic(id, field.name),
];
} else {
return [
...field.expr,
...this.expression(object0),
new IR.Project(id),
];
}
return [...this.expression(object0), new IR.ProjectStatic(id, field)];
},

Interpolate: (_, value) => {
Expand Down
36 changes: 2 additions & 34 deletions source/generated/crochet-grammar.ts

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions source/grammar/crochet.lingua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ type ConditionCase(pos: Meta, guard: Expression, body: Statement[])
type RecordField =
| FName(value: Name)
| FText(value: String)
| FComputed(value: Expression)

type Projection(pos: Meta, name: RecordField, alias: RecordField)

Expand Down Expand Up @@ -863,7 +862,6 @@ grammar Crochet : Program {
recordField =
| n:(name | atom) -> RecordField.FName(n)
| t:string -> RecordField.FText(t)
| s<"["> e:expression s<"]"> -> RecordField.FComputed(e)

literalExpression =
| l:literal -> Expression.Lit(l)
Expand Down
20 changes: 0 additions & 20 deletions source/ir/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export enum OpTag {
PUSH_STATIC_TYPE, // meta name

PUSH_RECORD, // meta key... (value...)
RECORD_AT_PUT, // meta (key value)
PROJECT, // meta (object key)
PROJECT_STATIC, // meta key (object)
EXTEND_INSTANCE, // meta type fields... (base) (value...)

Expand Down Expand Up @@ -84,9 +82,7 @@ export type Op =
| PushNewNamed
| PushStaticType
| PushRecord
| RecordAtPut
| ExtendInstance
| Project
| ProjectStatic
| PushLazy
| Force
Expand Down Expand Up @@ -235,22 +231,6 @@ export class PushRecord extends BaseOp {
}
}

export class RecordAtPut extends BaseOp {
readonly tag = OpTag.RECORD_AT_PUT;

constructor(readonly meta: Metadata) {
super();
}
}

export class Project extends BaseOp {
readonly tag = OpTag.PROJECT;

constructor(readonly meta: Metadata) {
super();
}
}

export class ProjectStatic extends BaseOp {
readonly tag = OpTag.PROJECT_STATIC;

Expand Down
2 changes: 0 additions & 2 deletions source/targets/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ export class CrochetForBrowser {
"crochet.core",
"crochet.debug",
"crochet.debug.tracing",
"crochet.language.cli-arguments",
"crochet.language.csv",
"crochet.language.json",
"crochet.mathematics",
"crochet.novella",
"crochet.parsing.combinators",
"crochet.random",
"crochet.text.parsing.lingua",
"crochet.text.regex",
Expand Down
2 changes: 0 additions & 2 deletions source/targets/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ export class CrochetForNode {
"crochet.core",
"crochet.debug",
"crochet.debug.tracing",
"crochet.language.cli-arguments",
"crochet.language.csv",
"crochet.language.json",
"crochet.mathematics",
"crochet.novella",
"crochet.parsing.combinators",
"crochet.random",
"crochet.text.parsing.lingua",
"crochet.text.regex",
Expand Down
25 changes: 0 additions & 25 deletions source/vm/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,31 +870,6 @@ export class Thread {
return _continue;
}

case t.RECORD_AT_PUT: {
const [record0, key0, value] = this.pop_many(activation, 3);
const key = Values.text_to_string(key0);
const record = Values.record_at_put(this.universe, record0, key, value);
this.push(activation, record);
activation.next();
return _continue;
}

case t.PROJECT: {
const [key0, value0] = this.pop_many(activation, 2);
const key = Values.text_to_string(key0);
const result = Values.project(value0, key, (value) =>
Capability.assert_projection_capability(
this.universe,
this.module,
value,
key
)
);
this.push(activation, result);
activation.next();
return _continue;
}

case t.PROJECT_STATIC: {
const value = this.pop(activation);
const result = Values.project(value, op.key, (value) =>
Expand Down
1 change: 0 additions & 1 deletion stdlib/crochet.core/crochet.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"source/collection/indexed.crochet",
"source/collection/list.crochet",
"source/collection/map.crochet",
"source/collection/record.crochet",
"source/collection/set.crochet",
"source/collection/set-algebra.crochet",
"source/collection/stream.crochet",
Expand Down
Loading