Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions ts/fixtures/lang/expected/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export function copy$Option_Mutex_u8_u8(v: [rt.Mutex<rt.u8>, rt.u8] | undefined)
return v === undefined ? v : copy$Mutex_u8_u8(v);
}

export function copy$Option_Shape(v: Shape.Shape | undefined): Shape.Shape | undefined {
return v === undefined ? v : copy$Shape(v);
}

export function copy$Option_Wrap_i16(v: Wrap.Wrap<rt.i16> | undefined): Wrap.Wrap<rt.i16> | undefined {
return v === undefined ? v : copy$Wrap_i16(v);
}
Expand Down
49 changes: 49 additions & 0 deletions ts/fixtures/lang/expected/shapes.Filled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$Point } from "./lib.ts";
import * as Point from "./shapes.Point.ts";
import type * as Shape from "./shapes.Shape.ts";

/** An `Option` a method matches, filling it between its matches. */
export interface Filled {
shape: Shape.Shape | undefined;
}

export function fill(self: Filled): void {
let _2!: Shape.Shape | undefined;
if (self.shape === undefined) {
_2 = { tag: "Line", _0: copy$Point(Point.new(5, 6)), _1: copy$Point(Point.new(7, 8)) } as Shape.Shape;
} else if (self.shape.tag === "Dot") {
_2 = { tag: "Line", _0: copy$Point(Point.new(1, 2)), _1: copy$Point(Point.new(3, 4)) } as Shape.Shape;
} else {
_2 = undefined;
}
self.shape = _2;
}

export function run(self: Filled): rt.u8 {
if (self.shape === undefined) {
fill(self);
if ((self.shape as Shape.Shape | undefined) === undefined) {
return 41;
}
if (((self.shape as Shape.Shape | undefined) as Shape.Shape).tag === "Line") {
return copy$Point((((self.shape as Shape.Shape | undefined) as Shape.Shape) as { tag: "Line"; _0: Point.Point; _1: Point.Point })._1).y & 0xff;
}
return 40;
}
if (self.shape.tag === "Dot") {
fill(self);
if ((self.shape as Shape.Shape | undefined) !== undefined) {
if ((self.shape as Shape.Shape).tag === "Line") {
return copy$Point(((self.shape as Shape.Shape) as { tag: "Line"; _0: Point.Point; _1: Point.Point })._0).x & 0xff;
}
}
return 42;
}
fill(self);
return 43;
}

//# sourceMappingURL=shapes.Filled.ts.map
6 changes: 3 additions & 3 deletions ts/fixtures/lang/expected/shapes.Machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export function log(self: Machine, v: rt.u8): rt.u8 {
export function run(self: Machine, n: rt.u8): rt.u8 {
if (self.state.tag === "Dot") {
step(self);
if (self.state.tag === "Dot") {
return 27;
if ((self.state as Shape.Shape).tag === "Line") {
return (copy$Point(((self.state as Shape.Shape) as { tag: "Line"; _0: Point.Point; _1: Point.Point })._1).x & 0xff) ^ self.steps ^ n;
}
return self.steps ^ n;
return 27;
}
if (self.state.tag === "Line") {
const seen: rt.u8 = peek(self);
Expand Down
129 changes: 98 additions & 31 deletions ts/fixtures/lang/expected/shapes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$ControlFlow_Arc_u8_u8s, copy$ControlFlow_unit_u8s, copy$Gauge, copy$Held, copy$Lens, copy$Level, copy$Mutex_u8_u8, copy$Mutex_u8s, copy$Option_Mutex_u8_u8, copy$Point, copy$Point_u8, copy$Points, copy$Poll_u8s, copy$Result_Mutex_u8_u8_u8, copy$Shape, copy$u8_u8, copy$u8s } from "./lib.ts";
import { copy$ControlFlow_Arc_u8_u8s, copy$ControlFlow_unit_u8s, copy$Gauge, copy$Held, copy$Lens, copy$Level, copy$Mutex_u8_u8, copy$Mutex_u8s, copy$Option_Mutex_u8_u8, copy$Option_Shape, copy$Point, copy$Point_u8, copy$Points, copy$Poll_u8s, copy$Result_Mutex_u8_u8_u8, copy$Shape, copy$u8_u8, copy$u8s } from "./lib.ts";
import * as Pair from "./fmt.Pair.ts";
import { advance, reset$Gauge } from "./generics.ts";
import type * as Dir from "./shapes.Dir.ts";
import * as Filled from "./shapes.Filled.ts";
import type * as Gauge from "./shapes.Gauge.ts";
import type * as Held from "./shapes.Held.ts";
import type * as Lens from "./shapes.Lens.ts";
Expand Down Expand Up @@ -1615,11 +1616,16 @@ export function rematched(data: rt.ByteSlice, out: rt.ByteVec): void {
let _19!: rt.u8;
let _29!: rt.u8;
let _43!: rt.u8;
let _48!: rt.u8;
let _59!: rt.u8;
let _68!: rt.u8;
let _72!: Shape.Shape;
let _114!: rt.u8;
let _50!: rt.u8;
let r!: rt.Result<rt.u8, rt.u8>;
let _58!: rt.u8;
let _76!: rt.u8;
let _97!: rt.u8;
let _107!: rt.u8;
let _118!: rt.u8;
let _127!: rt.u8;
let _131!: Shape.Shape;
let _189!: rt.u8;
const s: Shape.Shape = shape(data);
if (s.tag === "Dot") {
_5 = 2;
Expand Down Expand Up @@ -1652,55 +1658,108 @@ export function rematched(data: rt.ByteSlice, out: rt.ByteVec): void {
_29 = { North: 1, East: 2, South: 4, West: 8 }[d] & 0xff;
}
rt.byteVecPush(out, _29);
if (rt.cmp(data.length & 0xff, 2) === -1) {
const order_: rt.Ordering = rt.cmp(data.length & 0xff, 2);
if (order_ === -1) {
_43 = 17;
} else {
_43 = 0;
}
rt.byteVecPush(out, _43);
if (order_ === -1) {
if ((order_ as rt.Ordering) === 0) {
_50 = 31;
} else {
_50 = 32;
}
rt.byteVecPush(out, _50);
}
if (!(data.length > 1)) {
r = rt.Err(2);
} else {
r = rt.Ok(1);
}
if (r.ok) {
if ((r as rt.Result<rt.u8, rt.u8>).ok) {
_58 = ((r as rt.Result<rt.u8, rt.u8>) as { ok: true; value: rt.u8 }).value;
} else {
_58 = ((r as rt.Result<rt.u8, rt.u8>) as { ok: false; error: rt.u8 }).error;
}
rt.byteVecPush(out, _58);
}
let assigned = -1 as rt.Ordering;
if (data.length > 3) {
assigned = 1;
}
if (assigned === 0) {
rt.byteVecPush(out, 34);
}
const flow: rt.Result<rt.u16, rt.u8 | undefined> = step(0, data.length & 0xff);
if (!flow.ok) {
if ((flow as rt.Result<rt.u16, rt.u8 | undefined>).ok) {
_76 = ((flow as rt.Result<rt.u16, rt.u8 | undefined>) as { ok: true; value: rt.u16 }).value & 0xff;
} else {
_76 = rt.optionUnwrapOr(((flow as rt.Result<rt.u16, rt.u8 | undefined>) as { ok: false; error: rt.u8 | undefined }).error, 33);
}
rt.byteVecPush(out, _76);
}
const counts: rt.HashMap<rt.u8, rt.u8> = rt.hashNew() as rt.HashMap<rt.u8, rt.u8>;
if (rt.usizeRem(data.length, 2) === 0) {
rt.hashInsert(counts, data.length & 0xff, 35);
}
const entry: rt.Entry<rt.u8, rt.u8> | undefined = rt.entry(counts, data.length & 0xff);
if (entry !== undefined) {
if ((entry as rt.Entry<rt.u8, rt.u8> | undefined) === undefined) {
_97 = 37;
} else if (rt.entryOccupied(((entry as rt.Entry<rt.u8, rt.u8> | undefined) as rt.Entry<rt.u8, rt.u8>) as rt.Entry<rt.u8, rt.u8>)) {
_97 = rt.entryGet((entry as rt.Entry<rt.u8, rt.u8> | undefined) as rt.Entry<rt.u8, rt.u8>);
} else {
_97 = rt.entryOrInsertMut((entry as rt.Entry<rt.u8, rt.u8> | undefined) as rt.Entry<rt.u8, rt.u8>, 36).v;
}
rt.byteVecPush(out, _97);
}
let m: Shape.Shape = s;
if (m.tag === "Dot") {
m = shape(rt.byteSliceRange(data, rt.min(data.length, 1)));
if (m.tag === "Line") {
_48 = 18;
_107 = 18;
} else {
_48 = 19;
_107 = 19;
}
} else {
_48 = 20;
_107 = 20;
}
rt.byteVecPush(out, _48);
rt.byteVecPush(out, _107);
let held = copy$Shape(m) as Shape.Shape | undefined;
if (held === undefined) {
_59 = 22;
_118 = 22;
} else {
const taken2 = held;
held = undefined;
const taken: Shape.Shape | undefined = taken2;
if (held === undefined) {
_59 = rt.optionMapOr(taken, 22, (t: Shape.Shape): rt.u8 => {
if ((held as Shape.Shape | undefined) === undefined) {
_118 = rt.optionMapOr(taken, 22, (t: Shape.Shape): rt.u8 => {
return rt.u64Low(Shape.area$Area(t)) & 0xff;
});
} else {
_59 = 21;
_118 = 21;
}
}
rt.byteVecPush(out, _59);
rt.byteVecPush(out, _118);
let cur: Shape.Shape = s;
let iterStart: rt.u8 = 0;
const iterEnd: rt.u8 = 3;
while ((_68 = iterStart++) < iterEnd) {
const i: rt.u8 = _68;
while ((_127 = iterStart++) < iterEnd) {
const i: rt.u8 = _127;
if (cur.tag === "Dot") {
_72 = { tag: "Line", _0: Point.new(i as rt.i32, 0), _1: Point.new(0, 0) } as Shape.Shape;
_131 = { tag: "Line", _0: Point.new(i as rt.i32, 0), _1: Point.new(0, 0) } as Shape.Shape;
} else if (cur.tag === "Line") {
_72 = { tag: "Rect", corner: cur._0, width: rt.u16Add(cur._1.x & 0xffff, 1), height: 2 } as Shape.Shape;
_131 = { tag: "Rect", corner: cur._0, width: rt.u16Add(cur._1.x & 0xffff, 1), height: 2 } as Shape.Shape;
} else if (!(cur.width > 1)) {
_72 = cur;
_131 = cur;
} else {
_72 = { tag: "Dot" } as Shape.Shape;
_131 = { tag: "Dot" } as Shape.Shape;
}
cur = _72;
cur = _131;
rt.byteVecPush(out, rt.u64Low(Shape.area$Area(cur)) & 0xff);
}
const machine: Machine.Machine = { state: copy$Shape(s), steps: 0 };
Expand All @@ -1709,16 +1768,24 @@ export function rematched(data: rt.ByteSlice, out: rt.ByteVec): void {
while (iterStart2++ < iterEnd2) {
rt.byteVecPush(out, Machine.run(machine, data.length & 0xff));
}
const filled: Filled.Filled = { shape: copy$Option_Shape(rt.optionMap(dir(data.length & 0xff), (_2: Dir.Dir): Shape.Shape => {
return copy$Shape(s);
})) };
let iterStart3: rt.i32 = 0;
const iterEnd3: rt.i32 = 3;
while (iterStart3++ < iterEnd3) {
rt.byteVecPush(out, Filled.run(filled));
}
let original: Shape.Shape = shape(data);
if (original.tag === "Dot") {
original = shape(rt.byteSliceFrom(Uint8Array.of(1)));
rt.byteVecPush(out, 24);
if (original.tag === "Line") {
_114 = 25;
_189 = 25;
} else {
_114 = 26;
_189 = 26;
}
rt.byteVecPush(out, _114);
rt.byteVecPush(out, _189);
}
reseated(data, out);
}
Expand All @@ -1739,7 +1806,7 @@ export function reseated(data: rt.ByteSlice, out: rt.ByteVec): void {
let r: Shape.Shape = a;
if (r.tag === "Dot") {
r = b;
if (r.tag === "Line") {
if ((r as Shape.Shape).tag === "Line") {
_12 = 27;
} else {
_12 = 28;
Expand All @@ -1751,7 +1818,7 @@ export function reseated(data: rt.ByteSlice, out: rt.ByteVec): void {
let r2: Shape.Shape = a;
if (r2.tag === "Dot") {
r2 = b;
if (r2.tag === "Line") {
if ((r2 as Shape.Shape).tag === "Line") {
_19 = 30;
} else {
_19 = 31;
Expand All @@ -1765,7 +1832,7 @@ export function reseated(data: rt.ByteSlice, out: rt.ByteVec): void {
((): void => {
r3 = b;
})();
if (r3.tag === "Line") {
if ((r3 as Shape.Shape).tag === "Line") {
_26 = 36;
} else {
_26 = 37;
Expand All @@ -1780,7 +1847,7 @@ export function reseated(data: rt.ByteSlice, out: rt.ByteVec): void {
const swapped = r4;
r4 = other;
other = swapped;
if (r4.tag === "Line") {
if ((r4 as Shape.Shape).tag === "Line") {
_37 = 39;
} else {
_37 = 40;
Expand All @@ -1795,7 +1862,7 @@ export function reseated(data: rt.ByteSlice, out: rt.ByteVec): void {
while (iterStart++ < iterEnd) {
if (r5.tag === "Dot") {
r5 = b;
if (r5.tag === "Line") {
if ((r5 as Shape.Shape).tag === "Line") {
_51 = 42;
} else {
_51 = 43;
Expand Down
Loading