Skip to content

Commit

Permalink
Merge pull request #70 from qteatime/patch/aliases3
Browse files Browse the repository at this point in the history
Namespaces and qualified enums
  • Loading branch information
robotlolita authored Feb 20, 2022
2 parents f5601b9 + 51ea5ad commit d204855
Show file tree
Hide file tree
Showing 61 changed files with 1,721 additions and 642 deletions.
2 changes: 1 addition & 1 deletion examples/agata/todo-list/source/ui/lists-panel.crochet
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ command todo-ui render-new-list-widget do
let Name = #observable-cell with-value: "";
let Key-events = #event-stream empty;
Key-events
| keep-if: { X in X key =:= key-code-enter }
| keep-if: { X in X key is key-code--enter }
| listener
| subscribe: { _ in
let List = #todo-list-concrete with-name: Name value;
Expand Down
2 changes: 1 addition & 1 deletion examples/agata/todo-list/source/ui/todo-list.crochet
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ command todo-ui render-list: (List is todo-list) do
let New-item = #observable-cell with-value: "";
let Key-events = #event-stream empty;
Key-events
| keep-if: { X in X key =:= key-code-enter }
| keep-if: { X in X key is key-code--enter }
| listener
| subscribe: { _ in
let Title = New-item value;
Expand Down
10 changes: 5 additions & 5 deletions examples/agata/widget-gallery/source/controls/button.crochet
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ command controls-button page do

self row: [
#widget icon-button: "cat"
| size: icon-size-small,
| size: #icon-size small,
#widget icon-button: "cat"
| size: icon-size-medium,
| size: #icon-size medium,
#widget icon-button: "cat"
| size: icon-size-large,
| size: #icon-size large,
#widget icon-button: "cat"
| size: icon-size-extra-large,
| size: #icon-size extra-large,
#widget icon-button: "cat"
| disabled: true
| size: icon-size-extra-large,
| size: #icon-size extra-large,
]
| align-items: "flex-end",
],
Expand Down
2 changes: 1 addition & 1 deletion examples/web-apis/ws-chat/source/main.crochet
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ command screen-chat as widget do
|> #observable-cell collect-stream: _;
let Key-events = #event-stream empty;
Key-events
| keep-if: { X in X key =:= key-code-enter }
| keep-if: { X in X key is key-code--enter }
| listener
| subscribe: { _ in
let To-send = new message-send(Message value);
Expand Down
63 changes: 60 additions & 3 deletions source/binary-encode/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,61 @@ class CrochetIREncoder extends BinaryWriter {
break;
}

case IR.DeclarationTag.ALIAS: {
this.encode_meta_id(x.meta);
this.encode_entity(x.entity);
this.string(x.name);
break;
}

case IR.DeclarationTag.NAMESPACE: {
this.encode_meta_id(x.meta);
this.string(x.documentation);
this.string(x.name);
this.array(x.aliases, (a) => this.encode_declaration(a));
break;
}

default:
throw unreachable(x, `Declaration`);
}
}

encode_entity(x: IR.Entity) {
this.encode_enum_tag(x.tag);
const t = IR.EntityTag;
switch (x.tag) {
case t.GLOBAL_TRAIT: {
this.encode_meta_id(x.meta);
this.string(x.namespace);
this.string(x.name);
break;
}

case t.GLOBAL_TYPE: {
this.encode_meta_id(x.meta);
this.string(x.namespace);
this.string(x.name);
break;
}

case t.LOCAL_TRAIT: {
this.encode_meta_id(x.meta);
this.string(x.name);
break;
}

case t.LOCAL_TYPE: {
this.encode_meta_id(x.meta);
this.string(x.name);
break;
}

default:
throw unreachable(x, "Entity");
}
}

encode_handler(x: IR.HandlerCase) {
this.encode_enum_tag(x.tag);

Expand Down Expand Up @@ -717,13 +767,13 @@ class CrochetIREncoder extends BinaryWriter {
break;
}

case IR.TypeTag.LOCAL_STATIC: {
case IR.TypeTag.STATIC: {
this.encode_meta_id(x.meta);
this.string(x.name);
this.encode_type(x.type);
break;
}

case IR.TypeTag.GLOBAL_STATIC: {
case IR.TypeTag.LOCAL_NAMESPACED: {
this.encode_meta_id(x.meta);
this.string(x.namespace);
this.string(x.name);
Expand Down Expand Up @@ -768,6 +818,13 @@ class CrochetIREncoder extends BinaryWriter {
break;
}

case IR.TraitTag.NAMESPACED: {
this.encode_meta_id(x.meta);
this.string(x.namespace);
this.string(x.name);
break;
}

default:
throw unreachable(x, `Trait`);
}
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 = 41;
export const VERSION = 50;

export enum Section {
DECLARATION = 1,
Expand Down
84 changes: 74 additions & 10 deletions source/binary/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CrochetIRDecoder extends BinaryReader {
return this.array((_) => this.decode_declaration());
}

decode_declaration() {
decode_declaration(): IR.Declaration {
const t = IR.DeclarationTag;
const tag = this.decode_enum_tag(t, "declaration");
switch (tag) {
Expand Down Expand Up @@ -234,11 +234,67 @@ class CrochetIRDecoder extends BinaryReader {
return new IR.DDefaultHandler(this.decode_meta_id(), this.string());
}

case t.ALIAS: {
return new IR.DAlias(
this.decode_meta_id(),
this.decode_entity(),
this.string()
);
}

case t.NAMESPACE: {
return new IR.DNamespace(
this.decode_meta_id(),
this.string(),
this.string(),
this.array((_) => {
const x = this.decode_declaration();
if (!(x instanceof IR.DAlias)) {
throw new Error(`Non-alias content in namespace`);
}
return x;
})
);
}

default:
throw unreachable(tag, "Declaration");
}
}

decode_entity() {
const tag = this.decode_enum_tag(IR.EntityTag, "Entity");
const t = IR.EntityTag;
switch (tag) {
case t.GLOBAL_TRAIT: {
return new IR.EntityGlobalTrait(
this.decode_meta_id(),
this.string(),
this.string()
);
}

case t.GLOBAL_TYPE: {
return new IR.EntityGlobalType(
this.decode_meta_id(),
this.string(),
this.string()
);
}

case t.LOCAL_TRAIT: {
return new IR.EntityLocalTrait(this.decode_meta_id(), this.string());
}

case t.LOCAL_TYPE: {
return new IR.EntityLocalType(this.decode_meta_id(), this.string());
}

default:
throw unreachable(tag, "Entity");
}
}

decode_handler_case() {
const tag = this.decode_enum_tag(IR.HandlerCaseTag, "HandlerCase");
const t = IR.HandlerCaseTag;
Expand Down Expand Up @@ -290,12 +346,12 @@ class CrochetIRDecoder extends BinaryReader {
return new IR.LocalType(this.decode_meta_id(), this.string());
}

case IR.TypeTag.LOCAL_STATIC: {
return new IR.LocalStaticType(this.decode_meta_id(), this.string());
case IR.TypeTag.STATIC: {
return new IR.StaticType(this.decode_meta_id(), this.decode_type());
}

case IR.TypeTag.GLOBAL_STATIC: {
return new IR.GlobalStaticType(
case IR.TypeTag.LOCAL_NAMESPACED: {
return new IR.LocalNamespacedType(
this.decode_meta_id(),
this.string(),
this.string()
Expand Down Expand Up @@ -345,6 +401,14 @@ class CrochetIRDecoder extends BinaryReader {
);
}

case IR.TraitTag.NAMESPACED: {
return new IR.NamespacedTrait(
this.decode_meta_id(),
this.string(),
this.string()
);
}

default:
throw unreachable(tag, "Trait");
}
Expand Down Expand Up @@ -390,11 +454,11 @@ class CrochetIRDecoder extends BinaryReader {
this.uint32()
);

case t.PUSH_STATIC_TYPE:
return new IR.PushStaticType(
this.decode_meta_id(),
this.decode_type() as IR.LocalStaticType
);
case t.PUSH_STATIC_TYPE: {
const id = this.decode_meta_id();
const type = this.decode_type();
return new IR.PushStaticType(id, type);
}

case t.PUSH_RECORD:
return new IR.PushRecord(
Expand Down
Loading

0 comments on commit d204855

Please sign in to comment.