-
Notifications
You must be signed in to change notification settings - Fork 1
/
classes.js
85 lines (85 loc) · 2.32 KB
/
classes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var ep
const classdata = {
//Trans-Scope var. Just some data, stored as an object with references instead of clones.
TSVar:class{
constructor(n, v, t){
t = (typeof t !== "undefined" ? t : ep.types.any)
this.name = n
this.val = v
this.type = t
}
/**
*
* @param {TSVar} otherVar The variable to compare.
* @returns Whether the values were equivalent.
*/
eq(otherVar){
return this.val == otherVar.val
}
},
// A scope to contain variables, stored as TSVars.
Env:class{
constructor(){
this.contents = []
this.parents = []
this.children = []
}
/**
*
* @param {Env} env The environment to add as a parent.
*/
addParent(env){
env.children.push(this)
this.parents.push(env)
env.contents.forEach((vData)=>{
this.contents.push(vData)
})
}
add(name, data, type){
this.contents.push(new classdata.TSVar(name, data, type))
}
get(name){
var foundResult = null
this.contents.forEach((val)=>{
if(val.name == name){
foundResult = val
}
})
if(foundResult)return foundResult.val
return null
}
has(name){
var foundResult = false
this.contents.forEach((val)=>{
if(val.name == name){
foundResult = true
}
})
return foundResult
}
add(name, value, type){
this.contents.push(new classdata.TSVar(name.trim(), value, type))
}
set(name, value, type){
var foundResult = null
this.contents.forEach((val)=>{
if(val.name == name){
foundResult = val
}
})
val.val = value
val.type = (type ? type : val.type)
}
list(){
var output = []
this.contents.forEach((val)=>{
output.push(val.val)
})
return output
}
}
}
module.exports = (lep)=>{
ep = lep
return classdata
}