fez-lisp 1.6.24 → 1.6.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/lib/baked/std-T.js +1 -1
- package/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/check.js +14 -5
- package/src/macros.js +40 -8
- package/src/types.js +41 -1
package/package.json
CHANGED
package/src/check.js
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
VALUE,
|
17
17
|
WORD
|
18
18
|
} from './keywords.js'
|
19
|
-
import { isLeaf
|
19
|
+
import { isLeaf } from './parser.js'
|
20
20
|
import {
|
21
21
|
SPECIAL_FORM_TYPES,
|
22
22
|
toTypeNames,
|
@@ -91,6 +91,9 @@ export const identity = (name) => [
|
|
91
91
|
[1, 'x']
|
92
92
|
]
|
93
93
|
]
|
94
|
+
export const typeSetDefaultFunction = (Types, name, env, exp) =>
|
95
|
+
Types.set(withScope(name, env), () => formatType(name, env))
|
96
|
+
|
94
97
|
const returnType = (rest) => {
|
95
98
|
const body = rest.at(-1)
|
96
99
|
const rem = hasBlock(body) ? body.at(-1) : body
|
@@ -459,7 +462,7 @@ const getScopeNames = (scope) => {
|
|
459
462
|
}
|
460
463
|
return scopeNames.reverse()
|
461
464
|
}
|
462
|
-
const withScope = (name, scope) => {
|
465
|
+
export const withScope = (name, scope) => {
|
463
466
|
const chain = getScopeNames(scope)
|
464
467
|
return `${chain.join(' ')} ${name}`
|
465
468
|
}
|
@@ -990,7 +993,11 @@ const checkReturnType = ({ exp, stack, name, env, check }) => {
|
|
990
993
|
const stagger = (stack, method, data, fn) => {
|
991
994
|
stack[method]({ data, fn })
|
992
995
|
}
|
993
|
-
export const typeCheck = (
|
996
|
+
export const typeCheck = (
|
997
|
+
ast,
|
998
|
+
ctx = SPECIAL_FORM_TYPES,
|
999
|
+
typeSet = typeSetDefaultFunction
|
1000
|
+
) => {
|
994
1001
|
const Types = new Map()
|
995
1002
|
const stack = new Brr()
|
996
1003
|
const rootScopeIndex = 1
|
@@ -1204,7 +1211,8 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
|
|
1204
1211
|
)})`
|
1205
1212
|
)
|
1206
1213
|
if (name in env) {
|
1207
|
-
Types
|
1214
|
+
typeSet(Types, name, env, exp)
|
1215
|
+
// Types.set(withScope(name, env), () => formatType(name, env))
|
1208
1216
|
// If current scope is root then these are user defined types
|
1209
1217
|
if (env[SCOPE_NAME] === rootScopeIndex) break
|
1210
1218
|
}
|
@@ -1344,7 +1352,8 @@ export const typeCheck = (ast, ctx = SPECIAL_FORM_TYPES) => {
|
|
1344
1352
|
}
|
1345
1353
|
check(rightHand, env, scope)
|
1346
1354
|
}
|
1347
|
-
Types
|
1355
|
+
typeSet(Types, name, env, exp)
|
1356
|
+
// Types.set(withScope(name, env), () => formatType(name, env))
|
1348
1357
|
break
|
1349
1358
|
case KEYWORDS.ANONYMOUS_FUNCTION:
|
1350
1359
|
{
|
package/src/macros.js
CHANGED
@@ -39,7 +39,14 @@ export const SUGGAR = {
|
|
39
39
|
NEW_BIG_INTEGER: 'new:big-integer',
|
40
40
|
PROMISES: '*DATA*',
|
41
41
|
VARIABLE: 'variable',
|
42
|
-
SET_VARIABLE: 'set'
|
42
|
+
SET_VARIABLE: 'set',
|
43
|
+
INCREMENT: '++',
|
44
|
+
DECREMENT: '--',
|
45
|
+
INCREMENT_BY: '+=',
|
46
|
+
DECREMENT_BY: '-=',
|
47
|
+
BOOLEAN_VARIABLE: 'boolean',
|
48
|
+
BOOLEAN_VARIABLE_GET: 'boole',
|
49
|
+
BOOLEAN_VARIABLE_SET: 'boole-set'
|
43
50
|
}
|
44
51
|
export const deSuggarAst = (ast, scope) => {
|
45
52
|
if (scope === undefined) scope = ast
|
@@ -102,19 +109,44 @@ export const deSuggarAst = (ast, scope) => {
|
|
102
109
|
// break
|
103
110
|
case KEYWORDS.GET_ARRAY:
|
104
111
|
if (rest.length === 1) {
|
105
|
-
exp
|
112
|
+
exp[0][VALUE] = 'math:var-get'
|
113
|
+
// exp.push([ATOM, 0])
|
106
114
|
}
|
107
115
|
break
|
116
|
+
case SUGGAR.INCREMENT:
|
117
|
+
exp[0][VALUE] = 'math:var-increment!'
|
118
|
+
break
|
119
|
+
case SUGGAR.DECREMENT:
|
120
|
+
exp[0][VALUE] = 'math:var-decrement!'
|
121
|
+
break
|
122
|
+
case SUGGAR.INCREMENT_BY:
|
123
|
+
exp[0][VALUE] = 'math:var-add!'
|
124
|
+
deSuggarAst(exp.at(-1))
|
125
|
+
break
|
126
|
+
case SUGGAR.DECREMENT_BY:
|
127
|
+
exp[0][VALUE] = 'math:var-subtract!'
|
128
|
+
deSuggarAst(exp.at(-1))
|
129
|
+
break
|
108
130
|
case SUGGAR.VARIABLE:
|
109
|
-
|
110
|
-
|
111
|
-
const temp = exp.pop()
|
112
|
-
exp.push([[APPLY, 'var:def'], temp])
|
113
|
-
}
|
131
|
+
exp[0][VALUE] = 'let'
|
132
|
+
exp.push([[APPLY, 'math:var-def'], exp.pop()])
|
114
133
|
deSuggarAst(exp.at(-1))
|
115
134
|
break
|
116
135
|
case SUGGAR.SET_VARIABLE:
|
117
|
-
exp[0][VALUE] = 'var
|
136
|
+
exp[0][VALUE] = 'math:var-set!'
|
137
|
+
deSuggarAst(exp.at(-1))
|
138
|
+
break
|
139
|
+
case SUGGAR.BOOLEAN_VARIABLE:
|
140
|
+
exp[0][VALUE] = 'let'
|
141
|
+
exp.push([[APPLY, 'boole:def-strict'], exp.pop()])
|
142
|
+
deSuggarAst(exp.at(-1))
|
143
|
+
break
|
144
|
+
case SUGGAR.BOOLEAN_VARIABLE_SET:
|
145
|
+
exp[0][VALUE] = 'boole:set!'
|
146
|
+
deSuggarAst(exp.at(-1))
|
147
|
+
break
|
148
|
+
case SUGGAR.BOOLEAN_VARIABLE_GET:
|
149
|
+
exp[0][VALUE] = 'boole:get'
|
118
150
|
deSuggarAst(exp.at(-1))
|
119
151
|
break
|
120
152
|
case KEYWORDS.BLOCK:
|
package/src/types.js
CHANGED
@@ -1368,7 +1368,47 @@ export const formatType = (name, env) => {
|
|
1368
1368
|
: `(let ${name} ${formatSubType(getTypes(stats))})`
|
1369
1369
|
: name
|
1370
1370
|
}
|
1371
|
-
|
1371
|
+
export const formatInlineType = (name, env) => {
|
1372
|
+
const stats = env[name][STATS]
|
1373
|
+
return stats
|
1374
|
+
? getType(stats) === APPLY
|
1375
|
+
? `(lambda ${
|
1376
|
+
stats[ARG_COUNT] === VARIADIC
|
1377
|
+
? '... '
|
1378
|
+
: stats[ARGUMENTS]?.length
|
1379
|
+
? stats[ARGUMENTS].map(
|
1380
|
+
(x, i) =>
|
1381
|
+
`${
|
1382
|
+
getType(x[STATS]) === APPLY
|
1383
|
+
? `${formatType(i, stats[ARGUMENTS])}`
|
1384
|
+
: `${formatSubType(getTypes(x[STATS]))}`
|
1385
|
+
}`
|
1386
|
+
).join(' ') + ' '
|
1387
|
+
: ''
|
1388
|
+
// TODO format returned functions when type support is added
|
1389
|
+
}(${KEYWORDS.BLOCK} ${formatSubType(getReturns(stats))}))`
|
1390
|
+
: formatSubType(getTypes(stats))
|
1391
|
+
: name
|
1392
|
+
}
|
1393
|
+
export const formatAstTypes = (name, env) => {
|
1394
|
+
const stats = env[name][STATS]
|
1395
|
+
return stats
|
1396
|
+
? getType(stats) === APPLY
|
1397
|
+
? [
|
1398
|
+
stats[ARG_COUNT] === VARIADIC
|
1399
|
+
? '...'
|
1400
|
+
: stats[ARGUMENTS]?.length
|
1401
|
+
? stats[ARGUMENTS].map((x, i) =>
|
1402
|
+
getType(x[STATS]) === APPLY
|
1403
|
+
? formatType(i, stats[ARGUMENTS])
|
1404
|
+
: formatSubType(getTypes(x[STATS]))
|
1405
|
+
)
|
1406
|
+
: '',
|
1407
|
+
formatSubType(getReturns(stats))
|
1408
|
+
]
|
1409
|
+
: formatSubType(getTypes(stats))
|
1410
|
+
: name
|
1411
|
+
}
|
1372
1412
|
export const validateLambda = (exp, name) => {
|
1373
1413
|
if (exp.length === 1)
|
1374
1414
|
throw new TypeError(
|