-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestingTC.js
128 lines (121 loc) · 3.8 KB
/
testingTC.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
// test.js
import antlr4 from "antlr4";
import fs from "fs";
import ScillaLexer from "./scillaLexer.js";
import ScillaParser from "./scillaParser.js";
import {
getError,
isError,
resetErrorSettings,
startingTEnv,
} from "./general.js";
import _ from "lodash";
import * as TC from "./typechecker.js";
import {expressionsTC, contracts, stdlib } from "./constants.js";
import SyntaxVisitor from "./syntaxVisitor.js";
import ScillaTypeChecker from "./typechecker.js";
import TranslateVisitor from "./translate.js";
var runTCexp = true;
var runSingleExp = false;
var runTCcmod = true;
var runSingleCmod = false;
/***************************************
*
* Typechecking expressions
*
***************************************/
if (runTCexp) {
const tenvSTC = startingTEnv();
resetErrorSettings();
const tenv = tenvSTC[0];
const STC = tenvSTC[1];
for (let i = 0; i < expressionsTC.length; i++) {
const input = fs
.readFileSync("scilexp/".concat(expressionsTC[i]))
.toString();
console.log("Input: " + "scilexp/".concat(expressionsTC[i]));
const chars = new antlr4.InputStream(input);
const lexer = new ScillaLexer(chars);
const tokens = new antlr4.CommonTokenStream(lexer);
const parser = new ScillaParser(tokens);
const tree = parser.simple_exp();
const exprAst = tree.accept(new SyntaxVisitor());
const tenv_ = _.cloneDeep(tenv);
const typed = STC.typeExpr(exprAst, tenv_);
if (!typed) {
if (getError().s && getError().s.search("We do not handle builtin") !== -1) {
//We allow errors that have to do with builtins
resetErrorSettings();
continue;
}
console.log(getError());
break;
}
}
}
if (runSingleExp) {
const tenvSTC = startingTEnv();
if (isError()) {
console.log(getError());
}
const tenv = tenvSTC[0];
const STC = tenvSTC[1];
try {
const input = fs.readFileSync("scilexp/church_nat2.scilexp").toString();
const chars = new antlr4.InputStream(input);
const lexer = new ScillaLexer(chars);
const tokens = new antlr4.CommonTokenStream(lexer);
const parser = new ScillaParser(tokens);
const tree = parser.simple_exp();
const exprAst = tree.accept(new SyntaxVisitor());
const tenv_ = _.cloneDeep(tenv);
const typed = STC.typeExpr(exprAst, tenv_);
if (isError()) {
console.log(getError());
}
} catch (e) {
console.log("Parsing Error");
}
}
/**
*
* Typechecking cmods
*
*/
if (runTCcmod) {
for (let i = 0; i < contracts.length; i++) {
resetErrorSettings();
const input = fs.readFileSync("contracts/".concat(contracts[i])).toString();
console.log("Input: " + "contracts/".concat(contracts[i]));
const chars = new antlr4.InputStream(input);
const lexer = new ScillaLexer(chars);
const tokens = new antlr4.CommonTokenStream(lexer);
const parser = new ScillaParser(tokens);
const tree = parser.cmodule();
const cmod = tree.accept(new TranslateVisitor());
const STC = new ScillaTypeChecker();
TC.typeCMod(cmod, {}, STC);
if (isError()) {
const error_msg = getError();
console.log(error_msg);
if (!(error_msg.s.search("We do not handle builtin") !== -1)) {
console.log(getError());
}
resetErrorSettings();
}
}
}
if (runSingleCmod) {
const input = fs.readFileSync('contracts/'.concat("mappair.scilla")).toString();
const chars = new antlr4.InputStream(input);
const lexer = new ScillaLexer(chars);
const tokens = new antlr4.CommonTokenStream(lexer);
const parser = new ScillaParser(tokens);
const tree = parser.cmodule();
const cmod = tree.accept(new TranslateVisitor());
const STC = new ScillaTypeChecker();
const typed = TC.typeCMod(cmod, {}, STC);
if (isError() && !(getError().s.search("We do not handle builtin") !== -1)) {
console.log(getError());
}
}