Skip to content

Commit 6b92414

Browse files
mattccemattcce
andauthored
enable and apply prettier to ec-evaluator (#73)
Co-authored-by: mattcce <[email protected]>
1 parent 9616897 commit 6b92414

File tree

11 files changed

+990
-1015
lines changed

11 files changed

+990
-1015
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ node_modules
22
dist
33

44
src/ast
5-
src/ec-evaluator

src/ec-evaluator/components.ts

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { UnannType } from "../ast/types/classes";
2-
import { DECLARED_BUT_NOT_YET_ASSIGNED, GLOBAL_FRAME, OBJECT_CLASS } from "./constants";
3-
import * as errors from "./errors";
4-
import * as struct from "./structCreator";
1+
import { UnannType } from '../ast/types/classes'
2+
import { DECLARED_BUT_NOT_YET_ASSIGNED, GLOBAL_FRAME, OBJECT_CLASS } from './constants'
3+
import * as errors from './errors'
4+
import * as struct from './structCreator'
55
import {
66
Class,
77
Closure,
@@ -11,181 +11,181 @@ import {
1111
StashItem,
1212
Value,
1313
VarValue,
14-
Variable,
15-
} from "./types";
16-
import { Stack } from "./utils";
14+
Variable
15+
} from './types'
16+
import { Stack } from './utils'
1717

1818
/**
1919
* Components of CSE Machine.
2020
*/
21-
export class Control extends Stack<ControlItem> {};
22-
export class Stash extends Stack<StashItem> {};
21+
export class Control extends Stack<ControlItem> {}
22+
export class Stash extends Stack<StashItem> {}
2323

2424
export class Environment {
25-
private _global: EnvNode;
26-
private _current: EnvNode;
27-
private _objects: Object[] = [];
25+
private _global: EnvNode
26+
private _current: EnvNode
27+
private _objects: Object[] = []
2828

2929
constructor() {
30-
const node = new EnvNode(GLOBAL_FRAME);
31-
this._global = node;
32-
this._current = node;
30+
const node = new EnvNode(GLOBAL_FRAME)
31+
this._global = node
32+
this._current = node
3333
}
3434

3535
get global() {
36-
return this._global;
36+
return this._global
3737
}
3838

3939
get current() {
40-
return this._current;
40+
return this._current
4141
}
4242

4343
get objects() {
44-
return this._objects;
44+
return this._objects
4545
}
4646

4747
set current(node: EnvNode) {
48-
this._current = node;
48+
this._current = node
4949
}
5050

5151
extendEnv(fromEnv: EnvNode, name: string) {
5252
// Create new environemnt.
53-
const node = new EnvNode(name);
54-
node.parent = fromEnv;
55-
fromEnv.addChild(node);
53+
const node = new EnvNode(name)
54+
node.parent = fromEnv
55+
fromEnv.addChild(node)
5656

5757
// Set current environment.
58-
this._current = node;
58+
this._current = node
5959
}
6060

6161
createObj(c: Class): Object {
6262
// Create new environment.
63-
const node = new EnvNode(OBJECT_CLASS);
63+
const node = new EnvNode(OBJECT_CLASS)
6464

6565
// Create new object.
66-
const obj = struct.objStruct(node, c);
66+
const obj = struct.objStruct(node, c)
6767

6868
// Add to objects arr.
69-
this._objects.push(obj);
69+
this._objects.push(obj)
7070

7171
// Set current environment.
72-
this._current = node;
72+
this._current = node
7373

74-
return obj;
74+
return obj
7575
}
7676

7777
restoreEnv(toEnv: EnvNode) {
78-
this._current = toEnv;
78+
this._current = toEnv
7979
}
8080

8181
declareVariable(name: Name, type: UnannType) {
82-
const variable = struct.varStruct(type, name, DECLARED_BUT_NOT_YET_ASSIGNED);
83-
this._current.setVariable(name, variable);
82+
const variable = struct.varStruct(type, name, DECLARED_BUT_NOT_YET_ASSIGNED)
83+
this._current.setVariable(name, variable)
8484
}
8585

8686
defineVariable(name: Name, type: UnannType, value: VarValue) {
87-
const variable = struct.varStruct(type, name, value);
88-
this._current.setVariable(name, variable);
87+
const variable = struct.varStruct(type, name, value)
88+
this._current.setVariable(name, variable)
8989
}
9090

9191
getName(name: Name): Variable | Class {
92-
return this._current.getName(name);
92+
return this._current.getName(name)
9393
}
9494

9595
getVariable(name: Name): Variable {
96-
return this._current.getVariable(name);
96+
return this._current.getVariable(name)
9797
}
9898

9999
defineMtdOrCon(name: Name, method: Closure) {
100-
this._current.setMtdOrCon(name, method);
100+
this._current.setMtdOrCon(name, method)
101101
}
102102

103103
defineClass(name: Name, c: Class) {
104-
this._global.setClass(name, c);
104+
this._global.setClass(name, c)
105105
}
106106

107107
getClass(name: Name): Class {
108-
return this._global.getClass(name);
108+
return this._global.getClass(name)
109109
}
110-
};
110+
}
111111

112112
// Frame with metadata, e.g., parent/children, name.
113113
export class EnvNode {
114-
private _frame: Frame = new Frame();
115-
private _parent: EnvNode;
116-
private _children: EnvNode[] = [];
114+
private _frame: Frame = new Frame()
115+
private _parent: EnvNode
116+
private _children: EnvNode[] = []
117117

118118
constructor(readonly name: string) {}
119119

120120
get frame() {
121-
return this._frame;
121+
return this._frame
122122
}
123123

124124
get parent(): EnvNode {
125-
return this._parent;
125+
return this._parent
126126
}
127127

128128
set parent(parent: EnvNode) {
129-
this._parent = parent;
129+
this._parent = parent
130130
}
131131

132132
get children() {
133-
return this._children;
133+
return this._children
134134
}
135135

136136
addChild(child: EnvNode) {
137-
this._children.push(child);
137+
this._children.push(child)
138138
}
139139

140140
setVariable(name: Name, value: Variable) {
141141
if (this._frame.has(name)) {
142-
throw new errors.VariableRedeclarationError(name);
142+
throw new errors.VariableRedeclarationError(name)
143143
}
144-
this._frame.set(name, value);
144+
this._frame.set(name, value)
145145
}
146146

147147
getName(name: Name): Variable | Class {
148148
if (this._frame.has(name)) {
149-
return this._frame.get(name) as Variable | Class;
149+
return this._frame.get(name) as Variable | Class
150150
}
151151
if (this._parent) {
152-
return this._parent.getName(name);
152+
return this._parent.getName(name)
153153
}
154-
throw new errors.UndeclaredNameError(name);
154+
throw new errors.UndeclaredNameError(name)
155155
}
156156

157157
getVariable(name: Name): Variable {
158158
if (this._frame.has(name)) {
159-
return this._frame.get(name) as Variable;
159+
return this._frame.get(name) as Variable
160160
}
161161
if (this._parent) {
162-
return this._parent.getVariable(name);
162+
return this._parent.getVariable(name)
163163
}
164-
throw new errors.UndeclaredVariableError(name);
164+
throw new errors.UndeclaredVariableError(name)
165165
}
166166

167167
setMtdOrCon(name: Name, value: Closure) {
168168
if (this._frame.has(name)) {
169-
throw new errors.MtdOrConRedeclarationError(name);
169+
throw new errors.MtdOrConRedeclarationError(name)
170170
}
171-
this._frame.set(name, value);
171+
this._frame.set(name, value)
172172
}
173173

174174
setClass(name: Name, value: Class) {
175175
if (this._frame.has(name)) {
176-
throw new errors.ClassRedeclarationError(name);
176+
throw new errors.ClassRedeclarationError(name)
177177
}
178-
this._frame.set(name, value);
178+
this._frame.set(name, value)
179179
}
180180

181181
getClass(name: Name): Class {
182182
if (this._frame.has(name)) {
183-
return this._frame.get(name) as Class;
183+
return this._frame.get(name) as Class
184184
}
185185
if (this._parent) {
186-
return this._parent.getClass(name);
186+
return this._parent.getClass(name)
187187
}
188-
throw new errors.UndeclaredClassError(name);
188+
throw new errors.UndeclaredClassError(name)
189189
}
190190
}
191191

src/ec-evaluator/constants.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { symStruct } from "./structCreator";
1+
import { symStruct } from './structCreator'
22

3-
export const STEP_LIMIT = 100000;
4-
export const DECLARED_BUT_NOT_YET_ASSIGNED = symStruct("Used to implement block scope");
3+
export const STEP_LIMIT = 100000
4+
export const DECLARED_BUT_NOT_YET_ASSIGNED = symStruct('Used to implement block scope')
55

6-
export const THIS_KEYWORD = "this";
7-
export const SUPER_KEYWORD = "super";
6+
export const THIS_KEYWORD = 'this'
7+
export const SUPER_KEYWORD = 'super'
88

9-
export const OBJECT_CLASS = "Object";
9+
export const OBJECT_CLASS = 'Object'
1010

11-
export const GLOBAL_FRAME = "global";
12-
export const BLOCK_FRAME = "block";
11+
export const GLOBAL_FRAME = 'global'
12+
export const BLOCK_FRAME = 'block'

0 commit comments

Comments
 (0)