-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add range opcodes * add text_to_list opcodes * transform some loop plugins * fix getType * add Literal type, use defaults in mapOps & gen'ed docs * update emitters * update parsing, polygolf emit * remove some leftovers * update loop plugins * avoid circular dependency * update docs * fix couple tests * add for lang tests * rename concat alias to + * remove ForEachKey, ForEachPair * add lang names above fences * add forEachToForRange plugin * support ascii forEach overload * use default values when parsing * make .. backwards compatible * fix 1 py test * fix more tests * add Cast node * fix more tests * add atTextToListToAtText plugin * add py emit of naked text_to_list[codepoint] * fix some tests * fix gs range_diff_excl emit * add test for range alias in py * fix js loop over chars * implement naked range in py * fix last tests * fix cover script * fix naked range in nim * fix argv in js * update tests to use new for loops
- Loading branch information
1 parent
3909bba
commit 5d3b63c
Showing
62 changed files
with
1,642 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,94 @@ | ||
import { type BaseNode, type Node, type KeyValue } from "./IR"; | ||
import { | ||
type BaseNode, | ||
type Node, | ||
type KeyValue, | ||
type Integer, | ||
type Text, | ||
isOfKind, | ||
} from "./IR"; | ||
|
||
export interface Array extends BaseNode { | ||
export interface Array<T extends Node = Node> extends BaseNode { | ||
readonly kind: "Array"; | ||
readonly exprs: readonly Node[]; | ||
readonly value: readonly T[]; | ||
} | ||
|
||
export interface List extends BaseNode { | ||
export interface List<T extends Node = Node> extends BaseNode { | ||
readonly kind: "List"; | ||
readonly exprs: readonly Node[]; | ||
readonly value: readonly T[]; | ||
} | ||
|
||
export interface Set extends BaseNode { | ||
export interface Set<T extends Node = Node> extends BaseNode { | ||
readonly kind: "Set"; | ||
readonly exprs: readonly Node[]; | ||
readonly value: readonly T[]; | ||
} | ||
|
||
export interface Table extends BaseNode { | ||
export interface Table<Key extends Node = Node, Value extends Node = Node> | ||
extends BaseNode { | ||
readonly kind: "Table"; | ||
readonly kvPairs: readonly KeyValue[]; | ||
readonly value: readonly KeyValue<Key, Value>[]; | ||
} | ||
|
||
export function array(exprs: readonly Node[]): Array { | ||
export type Literal = | ||
| Integer | ||
| Text | ||
| Array<Literal> | ||
| List<Literal> | ||
| Set<Literal> | ||
| KeyValue<Literal, Literal> | ||
| Table<Literal, Literal>; | ||
|
||
export function isLiteral(x: Node): x is Literal { | ||
return ( | ||
isOfKind("Integer", "Text")(x) || | ||
(isOfKind("List", "Array", "Set", "Table")(x) && | ||
x.value.every(isLiteral)) || | ||
(x.kind === "KeyValue" && isLiteral(x.key) && isLiteral(x.value)) | ||
); | ||
} | ||
|
||
export function isEqualToLiteral(x: Node, literal: Literal): boolean { | ||
if (isOfKind("Integer", "Text")(literal)) { | ||
return isOfKind(literal.kind)(x) && x.value === literal.value; | ||
} else if (isOfKind("Array", "List", "Set", "Table")(literal)) { | ||
return ( | ||
isOfKind(literal.kind)(x) && | ||
x.value.every((x, i) => isEqualToLiteral(x, literal.value[i])) | ||
); | ||
} | ||
if (isOfKind("KeyValue")(literal)) { | ||
return ( | ||
isOfKind(literal.kind)(x) && | ||
isEqualToLiteral(x.key, literal.key) && | ||
isEqualToLiteral(x.value, literal.value) | ||
); | ||
} | ||
throw new Error("Unknown literal kind."); | ||
} | ||
|
||
export function array(value: readonly Node[]): Array { | ||
return { | ||
kind: "Array", | ||
exprs, | ||
value, | ||
}; | ||
} | ||
|
||
export function list(exprs: readonly Node[]): List { | ||
export function list(value: readonly Node[]): List { | ||
return { | ||
kind: "List", | ||
exprs, | ||
value, | ||
}; | ||
} | ||
|
||
export function set(exprs: readonly Node[]): Set { | ||
export function set(value: readonly Node[]): Set { | ||
return { | ||
kind: "Set", | ||
exprs, | ||
value, | ||
}; | ||
} | ||
|
||
export function table(kvPairs: readonly KeyValue[]): Table { | ||
export function table(value: readonly KeyValue[]): Table { | ||
return { | ||
kind: "Table", | ||
kvPairs, | ||
value, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.