File tree Expand file tree Collapse file tree 5 files changed +73
-19
lines changed
Expand file tree Collapse file tree 5 files changed +73
-19
lines changed Original file line number Diff line number Diff line change 1+ import UglifyJS from 'uglify-js' ;
2+
13import Parser from './parser/Parser.js' ;
24import InputStream from './tokenizer/InputStream.js' ;
35import TokenStream from './tokenizer/TokenStream.js' ;
46
57import evaluate from './runtime/Evaluator.js' ;
68import Executor from './runtime/Executor.js' ;
79
8- import makeEnv from './stdlib/StdEnvJS.js' ;
9- import stdEnv from './stdlib/StdEnvYAS.js' ;
10- import makeCompilerEnv from './stdlib/StdCompilerEnv.js' ;
10+ import makeEnv from './stdlib/interpreter/StdEnvJS.js' ;
11+ import stdEnv from './stdlib/interpreter/StdEnvYAS.js' ;
12+
13+ import makeCompilerEnv from './stdlib/compiler/StdCompilerEnv.js' ;
1114
1215import CompilerJS from './codegen/CompilerJS.js' ;
1316
@@ -27,9 +30,9 @@ export function compile(code) {
2730 const tokenStream = new TokenStream ( inputStream ) ;
2831 const parser = new Parser ( tokenStream ) ;
2932 const ast = parser . parse ( ) ;
30- makeCompilerEnv ( ) ;
3133 const compiler = new CompilerJS ( stdEnv ( ast ) ) ;
32- return compiler . compile ( ) ;
34+ const js = makeCompilerEnv ( ) + compiler . compile ( ) ;
35+ return UglifyJS . minify ( js ) . code ;
3336}
3437
3538export function runJS ( jsCode ) {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ export default function makeCompilerEnv ( ) {
2+ return `
3+ global.print = function(...txt) {
4+ txt.forEach(i => process.stdout.write(i.toString()));
5+ };
6+
7+ global.println = function(...txt) {
8+ txt.forEach(i => console.log(i));
9+ };
10+
11+ global.clear = console.clear;
12+
13+ global.time = (callback, func) => {
14+ console.log(callback, func);
15+ console.time('time');
16+ func((ret) => {
17+ console.timeEnd('time');
18+ callback(ret);
19+ });
20+ };
21+
22+ global.sleep = (callback, delay) => {
23+ setTimeout(() => {
24+ callback();
25+ }, delay);
26+ };
27+
28+ global.callcc = (callback, fn, ...args) => {
29+ fn(callback, (discard, ret) => {
30+ callback(ret);
31+ }, ...args);
32+ };
33+
34+ global.halt = (k) => {};
35+
36+ global.pstack = [];
37+
38+ global._goto = function(f) {
39+ f((r) => {
40+ const h = pstack.pop();
41+ h(r);
42+ });
43+ };
44+
45+ global.reset = function(KRESET, th) {
46+ pstack.push(KRESET);
47+ _goto(th);
48+ };
49+
50+ global.shift = function(KSHIFT, f) {
51+ _goto((KGOTO) => {
52+ f(KGOTO, (k1, v) => {
53+ pstack.push(k1);
54+ KSHIFT(v);
55+ });
56+ });
57+ };` ;
58+ }
Original file line number Diff line number Diff line change 1- import Environment from '../runtime/Environment.js' ;
2- import Executor from '../runtime/Executor.js' ;
1+ import Environment from '../../ runtime/Environment.js' ;
2+ import Executor from '../../ runtime/Executor.js' ;
33
44export default function makeEnv ( ) {
55 const globalEnv = new Environment ( ) ;
@@ -49,6 +49,7 @@ export default function makeEnv() {
4949 h ( r ) ;
5050 } ) ;
5151 }
52+ globalEnv . def ( '_goto' , _goto ) ;
5253
5354 function reset ( KRESET , th ) {
5455 pstack . push ( KRESET ) ;
@@ -64,6 +65,7 @@ export default function makeEnv() {
6465 } ) ;
6566 } ) ;
6667 }
68+ globalEnv . def ( 'shift' , shift ) ;
6769
6870 return globalEnv ;
6971}
Original file line number Diff line number Diff line change 1- import Parser from '../parser/Parser.js' ;
2- import InputStream from '../tokenizer/InputStream.js' ;
3- import TokenStream from '../tokenizer/TokenStream.js' ;
1+ import Parser from '../../ parser/Parser.js' ;
2+ import InputStream from '../../ tokenizer/InputStream.js' ;
3+ import TokenStream from '../../ tokenizer/TokenStream.js' ;
44
55export default function stdEnv ( ast ) {
66 const std = `def cons = fn(a, b) -> fn(f) -> f(a, b);
You can’t perform that action at this time.
0 commit comments