-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd_lib.js
216 lines (203 loc) · 6.54 KB
/
std_lib.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { cycle } from "./run.js"
export const std_lib = [
// @ external
// @ ????
{//loop
name: ".loop",
src: "std",
exec: (stack,vartac) => {// ${} num|str word
if (stack.length > 2) {
if (
stack[stack.length - 1].type == "word" &&
(
stack[stack.length - 2].type == "number" ||
stack[stack.length - 2].type == "word" ||
stack[stack.length - 2].type == "string"
) &&
stack[stack.length - 3].type == "block"
) {
const _block = stack[stack.length - 3].value
const varible = stack[stack.length - 1]
let nxb = 0
switch (stack[stack.length - 2].type) {
case "number":
nxb = stack[stack.length - 2].value
break;
case "word":
if (vartac[stack[stack.length - 2].value] &&
vartac[stack[stack.length - 2].value].stype == "const" &&
vartac[stack[stack.length - 2].value].type == "number") {
nxb = vartac[stack[stack.length - 2].value].value
} else {
//todo: error
}
break;
case "string":
nxb = parseFloat(stack[stack.length - 2].value)
break;
}
if (vartac[varible.value]) {
console.log("error: varible overwrite error\n name: '" + varible.value + "'")
}
for (let i = 0; i < nxb; i++) {
vartac[varible.value] = {
stype: "const",
type: "number",
value: i
}
cycle(_block, stack, vartac, false)
}
vartac[varible.value] = undefined
stack.pop()
stack.pop()
stack.pop()
return {
stack:stack,
vartac:vartac
}
}
}
// const temp = cycle(vartac[tks[i].value.slice(1)].call, stack, vartac, ddl)
// if (temp) {
// if (temp.vartac) vartac = temp.vartac
// if (temp.stack) stack = temp.stack
// if (temp.ddl != undefined) ddl = temp.ddl
// }
}
},
// @ debug
{//debug
name: ".debug",
src: "std",
exec: (_s, _v, _t, ddl) => {
return { ddl: !ddl }
}
},
// @ sai
{//print
name: ".print",
src: "std",
exec: (stack) => {
if (stack.length > 0) {
//todo: type handeling
console.log(stack[stack.length - 1].value)
stack.pop()
return {
stack:stack
}
}
}
},
// @ vartac
{//function
name: ".function",
src: "std",
exec: (stack, vartack) => {//${} name () .function
if (stack.length > 2) {
if (
stack[stack.length - 1].type == "parameter" &&
stack[stack.length - 2].type == "word" &&
stack[stack.length - 3].type == "block"
) {
if (vartack[stack[stack.length - 2].value]) {
console.log("error: varible overwrite error\n name: '" + stack[stack.length - 2].value + "'")
}
vartack[stack[stack.length - 2].value] = {
stype: "function",
typrg: stack[stack.length - 1].value,
call: stack[stack.length - 3].value
}
stack.pop()
stack.pop()
stack.pop()
} else {
console.log("error: stack pattern not recognized\n proper formulation: ${} name () .function")
}
}
return {
vartac: vartack,
stack: stack
}
}
},
{//const
name: ".const",
src: "std",
exec: (stack, vartack) => {//any
if (stack.length > 1) {
if (
stack[stack.length - 1].type == "word"
) {
if (vartack[stack[stack.length - 1].value]) {
console.log("error: varible overwrite error\n name: '" + stack[stack.length - 1].value + "'")
}
vartack[stack[stack.length - 1].value] = {
stype: "const",
type: stack[stack.length - 2].type,
value: stack[stack.length - 2].value
}
stack.pop()
stack.pop()
} else {
console.log("error: stack pattern not recognized\n proper formulation: any!(block|params) name .const\n given formation: " + stack[stack.length - 2].type + " " + stack[stack.length - 1].type + " .const")
}
}
return {
vartac: vartack,
stack: stack
}
}
}
// @ string
// @ array
]
/**
* .function ${} word ()
* .loop ${} num|str word
* .print any
* .const any!(block|params) word
*/
/*standard mk 2
@ external
import string
export word
@ ????
loop ${} num|str word
while
if
async usr_func
@ debug
debug
@ sai
print any
@ vartac
function ${} word ()
const any!(block|params) word
@ string
@ array
at
replace
push
pop
reverse
remove
slice
length
code
trim
uppercase
lowercase
array
array
*/
/**
(fs) .load_file string -> obj
(fs) .save_file string string -> none
(var) .get name -> any
(var) .set any name -> none
(var) .const type name -> none
(str) .split string string -> string
(arr|str) .at array|string number -> any
(arr|str) .length string|array -> number
(terminal) .console_prompt any -> string
*/