Skip to content

Commit b3f442c

Browse files
authored
Merge pull request #125 from sugarlabs/develop
Release v1.0.1
2 parents 0efb959 + f55fbea commit b3f442c

28 files changed

+1600
-1981
lines changed

CHANGELOG.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Changelog
2+
3+
## 1.0.1 [2022-02-09]
4+
5+
- ([#122](https://github.com/sugarlabs/musicblocks-v4-lib/pull/122))
6+
Added provision to provide initialisation values in snapshot of data elements.
7+
- ([#119](https://github.com/sugarlabs/musicblocks-v4-lib/pull/119))
8+
Added function to **specification** snapshot.
9+
- ([#121](https://github.com/sugarlabs/musicblocks-v4-lib/pull/121))
10+
Removed custom type reliance for element name (`TElementName`).
11+
- ([#120](https://github.com/sugarlabs/musicblocks-v4-lib/pull/120))
12+
Updated package dependencies.
13+
- ([#118](https://github.com/sugarlabs/musicblocks-v4-lib/pull/118))
14+
Added validations in **specification** functions for registering and unregistering _syntax elements_.
15+
16+
## 1.0.0 [2022-01-26]
17+
18+
- Added 3 categories of components: **Syntax Representation**, **Execution Engine**, **Library**
19+
20+
- **Syntax Representation**
21+
22+
- Added **Element API**: represents **syntax elements** -- the atomic constructs for building
23+
programs. There are 2 kinds of **syntax elements**:
24+
- **Arguments** which return values. These are of 2 types:
25+
- **Data** which return a value inherently and without operating on other provided values
26+
- **Expression** which return a value after operating on other provided values
27+
- **Instructions** which perform a task. These are of 2 types:
28+
- **Statements** perform a single task
29+
- **Blocks** encapsulate _statements_ and generally set some states or control the flow to them
30+
31+
- Added **Specification** component: maintains a table of concrete **syntax elements** which can
32+
be used to build programs.
33+
- Added **Warehouse** component: maintains a table of instances of **syntax elements** registered
34+
in the **specification**. It can also generate statistics about the instances.
35+
- Added **Syntax Tree** component: represents the _abstract syntax tree_ or _AST_ by maintaining
36+
interconnections between **syntax elements**.
37+
38+
- **Execution Engine**
39+
40+
- Added **Symbol Table** component: maintains tables of dynamic global variables and states which
41+
the **syntax elements** can use during execution.
42+
- Added **Parser** component: parses the **syntax tree** in a postorder sequence, and maintains
43+
_call frame stacks_ and the _program counter_.
44+
- Added **Interpreter** component: fetches elements from the **parser** and executes them.
45+
46+
- There are 2 special constructs: **Process** and **Routine**. These are special _block_ elements.
47+
**Routines** encapsulate _instructions_ that can be executed by multiple **processes**. **Processes**
48+
encapsulate independent set of _instructions_, and multiple **processes** can run concurrently.
49+
- There is an additional terminology called **crumbs** which are sets of connected _syntax elements_
50+
not part of any _process_ or _routine_.
51+
52+
- **Library**
53+
54+
- Added basic **Concrete Syntax Elements**
55+
- **Values**
56+
- Represent stored values
57+
- Supports `boolean`, `number`, `string` data-types
58+
- **Boxes**
59+
- Represents variable values
60+
- Support `boolean`, `number`, `string`, `generic` data-types
61+
- **Box Identifiers**
62+
- Represents variable identifiers
63+
- Supports `boolean`, `number`, `string`, `generic` **boxes**
64+
- **Math Operators**
65+
- `plus`, `minus`, `times`, `divide`, `modulus` operators
66+
- **Conditionals**: `if`
67+
- **Loops**: generic `repeat`
68+
- **Program**: `process` and `routine`
69+
- **Miscellaneous**: `print`
70+
- Added a _specification_ of the above **syntax elements**

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sugarlabs/musicblocks-v4-lib",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "The core of the new Music Blocks (v4) application",
55
"repository": {
66
"type": "git",
@@ -17,21 +17,21 @@
1717
"main": "index.js",
1818
"types": ".",
1919
"devDependencies": {
20-
"@types/jest": "^26.0.19",
21-
"@types/uuid": "^8.3.1",
22-
"@typescript-eslint/eslint-plugin": "^4.11.1",
23-
"@typescript-eslint/parser": "^4.11.1",
24-
"eslint": "^7.17.0",
25-
"eslint-config-prettier": "^7.1.0",
20+
"@types/jest": "^27.4.0",
21+
"@types/uuid": "^8.3.4",
22+
"@typescript-eslint/eslint-plugin": "^5.10.2",
23+
"@typescript-eslint/parser": "^5.10.2",
24+
"eslint": "^8.8.0",
25+
"eslint-config-prettier": "^8.3.0",
2626
"eslint-plugin-json": "^3.1.0",
27-
"jest": "^26.6.3",
28-
"prettier": "^2.4.1",
27+
"jest": "^27.4.7",
28+
"prettier": "^2.5.1",
2929
"textlint": "^12.1.0",
3030
"textlint-rule-no-dead-link": "^4.8.0",
3131
"textlint-rule-no-empty-section": "^1.1.0",
3232
"textlint-rule-terminology": "^2.1.5",
33-
"ts-jest": "^26.4.4",
34-
"typescript": "4.1.3"
33+
"ts-jest": "^27.1.3",
34+
"typescript": "4.5.5"
3535
},
3636
"dependencies": {
3737
"uuid": "^8.3.2"

src/@types/elements.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { TData, TDataName } from './data';
2-
import { TElementName, TElementKind, TElementType } from './specification';
2+
import { TElementKind, TElementType } from './specification';
33

44
// -------------------------------------------------------------------------------------------------
55

66
/** Interface for the class that implements a syntax element. */
77
export interface IElementSyntax {
88
/** Name of the syntax element. */
9-
name: TElementName;
9+
name: string;
1010
/** Display name of the syntax element. */
1111
label: string;
1212
/** Kind (`Argument`, `Instruction`) of the syntax element. */

src/@types/specification.d.ts

Lines changed: 40 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TData } from './data';
1+
import { TData, TDataName } from './data';
22
import {
33
IElementData,
44
IElementExpression,
@@ -14,54 +14,17 @@ export type TElementKind = 'Argument' | 'Instruction';
1414
/** Type (`Data`, `Expression`, `Statement`, `Block`) of the syntax element. */
1515
export type TElementType = 'Data' | 'Expression' | 'Statement' | 'Block';
1616

17-
/** Names of factory list of data elements. */
18-
export type TElementNameData =
19-
// value elements
20-
| 'value-boolean'
21-
| 'value-number'
22-
| 'value-string'
23-
// box identifier elements
24-
| 'boxidentifier-generic'
25-
| 'boxidentifier-boolean'
26-
| 'boxidentifier-number'
27-
| 'boxidentifier-string';
28-
29-
/** Names of factory list of expression elements. */
30-
export type TElementNameExpression =
31-
// math operator elements
32-
| 'operator-math-plus'
33-
| 'operator-math-minus'
34-
| 'operator-math-times'
35-
| 'operator-math-divide'
36-
| 'operator-math-modulus';
37-
38-
/** Names of factory list of statement elements. */
39-
export type TElementNameStatement =
40-
// box elements
41-
| 'box-generic'
42-
| 'box-boolean'
43-
| 'box-number'
44-
| 'box-string'
45-
// print element
46-
| 'print';
47-
48-
/** Names of factory list of block elements. */
49-
export type TElementNameBlock = 'process' | 'routine' | 'repeat' | 'if';
50-
51-
/** Names of factory list of syntax elements. */
52-
export type TElementName =
53-
| 'dummy'
54-
| TElementNameData
55-
| TElementNameExpression
56-
| TElementNameStatement
57-
| TElementNameBlock;
58-
5917
/** Type for the specification object for data elements. */
6018
export interface IElementSpecificationData {
6119
label: string;
6220
type: 'Data';
6321
category: string;
64-
prototype: (name: TElementNameData, label: string) => IElementData<TData>;
22+
prototype: (name: string, label: string) => IElementData<TData>;
23+
values?:
24+
| string[]
25+
| {
26+
types: TDataName[];
27+
};
6528
}
6629

6730
/** Type for the specification entry object for data elements. */
@@ -77,7 +40,7 @@ export interface IElementSpecificationExpression {
7740
label: string;
7841
type: 'Expression';
7942
category: string;
80-
prototype: (name: TElementNameExpression, label: string) => IElementExpression<TData>;
43+
prototype: (name: string, label: string) => IElementExpression<TData>;
8144
}
8245

8346
/** Type for the specification object for expression elements. */
@@ -90,21 +53,21 @@ export interface IElementSpecificationEntryExpression extends IElementSpecificat
9053

9154
/** Type for the specification object for instruction elements. */
9255
interface IElementSpecificationInstruction {
93-
allowAbove?: TElementName[] | boolean;
94-
allowBelow?: TElementName[] | boolean;
95-
forbidAbove?: TElementName[];
96-
forbidBelow?: TElementName[];
56+
allowAbove?: string[] | boolean;
57+
allowBelow?: string[] | boolean;
58+
forbidAbove?: string[];
59+
forbidBelow?: string[];
9760
allowedNestLevel?: number[] | 'any';
98-
allowedNestInside?: TElementNameBlock[] | boolean;
99-
forbiddenNestInside?: TElementNameBlock[];
61+
allowedNestInside?: string[] | boolean;
62+
forbiddenNestInside?: string[];
10063
}
10164

10265
/** Type for the specification object for statement elements. */
10366
export type IElementSpecificationStatement = IElementSpecificationInstruction & {
10467
label: string;
10568
type: 'Statement';
10669
category: string;
107-
prototype: (name: TElementNameStatement, label: string) => IElementStatement;
70+
prototype: (name: string, label: string) => IElementStatement;
10871
};
10972

11073
/** Type for the specification object for statement elements. */
@@ -120,9 +83,9 @@ export type IElementSpecificationBlock = IElementSpecificationInstruction & {
12083
label: string;
12184
type: 'Block';
12285
category: string;
123-
prototype: (name: TElementNameBlock, label: string) => IElementBlock;
124-
allowNestInside?: (TElementNameStatement | TElementNameBlock)[] | boolean;
125-
forbidNestInside?: (TElementNameStatement | TElementNameBlock)[];
86+
prototype: (name: string, label: string) => IElementBlock;
87+
allowNestInside?: string[] | boolean;
88+
forbidNestInside?: string[];
12689
};
12790

12891
/** Type for the specification entry object for block elements. */
@@ -131,22 +94,33 @@ export type IElementSpecificationEntryBlock = IElementSpecificationInstruction &
13194
type: 'Block';
13295
category: string;
13396
prototype: typeof IElementBlock;
134-
allowNestInside?: (TElementNameStatement | TElementNameBlock)[] | boolean;
135-
forbidNestInside?: (TElementNameStatement | TElementNameBlock)[];
97+
allowNestInside?: string[] | boolean;
98+
forbidNestInside?: string[];
13699
};
137100

101+
/** Type for the specification object for an element. */
138102
export interface IElementSpecification {
139103
label: string;
140104
type: TElementType;
141105
category: string;
142-
prototype: new (name: TElementName, label: string) => IElementSyntax;
143-
allowAbove?: TElementName[] | boolean;
144-
allowBelow?: TElementName[] | boolean;
145-
forbidAbove?: TElementName[];
146-
forbidBelow?: TElementName[];
106+
prototype: new (name: string, label: string) => IElementSyntax;
107+
allowAbove?: string[] | boolean;
108+
allowBelow?: string[] | boolean;
109+
forbidAbove?: string[];
110+
forbidBelow?: string[];
147111
allowedNestLevel?: number[] | 'any';
148-
allowedNestInside?: TElementNameBlock[] | boolean;
149-
forbiddenNestInside?: TElementNameBlock[];
150-
allowNestInside?: (TElementNameStatement | TElementNameBlock)[] | boolean;
151-
forbidNestInside?: (TElementNameStatement | TElementNameBlock)[] | boolean;
112+
allowedNestInside?: string[] | boolean;
113+
forbiddenNestInside?: string[];
114+
allowNestInside?: string[] | boolean;
115+
forbidNestInside?: string[] | boolean;
116+
values?:
117+
| string[]
118+
| {
119+
types: TDataName[];
120+
};
121+
}
122+
123+
/** Type for the snapshot of an element's specification. */
124+
export interface IElementSpecificationSnapshot extends Omit<IElementSpecification, 'prototype'> {
125+
prototypeName: string;
152126
}

src/@types/syntaxTree.d.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import {
2-
TElementNameData,
3-
TElementNameExpression,
4-
TElementNameStatement,
5-
TElementNameBlock,
6-
TElementName,
7-
} from './specification';
8-
91
// -- snapshots ------------------------------------------------------------------------------------
102

113
/** Type definition for the snapshot input of a data element. */
124
export interface ITreeSnapshotDataInput {
135
/** Name of the data element. */
146
elementName: string;
7+
/** Value to initialize data element with. */
8+
value?: string;
159
}
1610

1711
/** Type definition for the snapshot of a data element. */
@@ -105,7 +99,7 @@ export interface ITreeSnapshot {
10599
/** Type definition for the class that implements a generic syntax tree node. */
106100
interface ITreeNode {
107101
/** Name of the syntax element. */
108-
elementName: TElementName;
102+
elementName: string;
109103
/** Node ID of the syntax tree node instance. */
110104
nodeID: string;
111105
/** Warehouse ID of the syntax element instance. */
@@ -121,15 +115,15 @@ export interface ITreeNodeArgument extends ITreeNode {
121115
/** Type definition for the class that implements a syntax tree data node. */
122116
export interface ITreeNodeData extends ITreeNodeArgument {
123117
/** Name of the data element. */
124-
elementName: TElementNameData;
118+
elementName: string;
125119
/** Returns a snapshot of the syntax tree data node. */
126120
snapshot: ITreeSnapshotData;
127121
}
128122

129123
/** Type definition for the class that implements a syntax tree expression node. */
130124
export interface ITreeNodeExpression extends ITreeNodeArgument {
131125
/** Name of the expression element. */
132-
elementName: TElementNameExpression;
126+
elementName: string;
133127
/** Returns a snapshot of the syntax tree expression node. */
134128
snapshot: ITreeSnapshotExpression;
135129
/** Object with key-value pairs of argument names and corresponding argument nodes. */
@@ -175,15 +169,15 @@ export interface ITreeNodeInstruction extends ITreeNode {
175169
/** Type definition for the class that implements a syntax tree statement node. */
176170
export interface ITreeNodeStatement extends ITreeNodeInstruction {
177171
/** Name of the statement element. */
178-
elementName: TElementNameStatement;
172+
elementName: string;
179173
/** Returns a snapshot of the syntax tree statement node. */
180174
snapshot: ITreeSnapshotStatement;
181175
}
182176

183177
/** Type definition for the class that implements a syntax tree block node. */
184178
export interface ITreeNodeBlock extends ITreeNodeInstruction {
185179
/** Name of the block element. */
186-
elementName: TElementNameBlock;
180+
elementName: string;
187181
/** Returns a snapshot of the syntax tree block node. */
188182
snapshot: ITreeSnapshotBlock;
189183
/** Syntax tree node reference of the first nested instruction element. */

0 commit comments

Comments
 (0)