Skip to content
This repository was archived by the owner on Jul 31, 2020. It is now read-only.

Commit 6ecc08e

Browse files
authored
Add files via upload
layout with initial sidebar, and possible future library
1 parent 1ca958b commit 6ecc08e

34 files changed

+15552
-37
lines changed

library_function/code_runner.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react"
2+
3+
'use strict';
4+
5+
6+
function () {
7+
return (
8+
<div>
9+
10+
</div>
11+
)
12+
}
13+
14+
export default
15+

library_function/module_loader.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
const ModuleLoader = (function() {
4+
function stringFromFile(path) { // private
5+
let request = new XMLHttpRequest();
6+
request.open('GET', path, false);
7+
request.send(null);
8+
return request.responseText;
9+
}
10+
11+
function getModuleDirList() {
12+
let data = stringFromFile('modules/modules.json');
13+
let obj = JSON.parse(data);
14+
if (obj['module_dirs'] === undefined) {
15+
throw 'Invalid modules.json: key "module_dirs" is missing';
16+
}
17+
return obj['module_dirs'];
18+
}
19+
20+
function loadModule(moduleDirList, moduleName, usedSymbols = []) {
21+
let dirname = moduleDirList[moduleName];
22+
if (dirname === undefined) {
23+
throw 'Unknown module: ' + moduleName;
24+
}
25+
let modulePath = 'modules/' + dirname;
26+
let moduleObj = JSON.parse(stringFromFile(modulePath + '/module_config.json'));
27+
let sourceFileNames = moduleObj['module_source_files'];
28+
let allSymbols = moduleObj['module_symbols'];
29+
for (let url of sourceFileNames) {
30+
dynamicallyLoadScript(modulePath + '/' + url);
31+
blockUnusedSymbols(allSymbols, usedSymbols);
32+
}
33+
}
34+
35+
function dynamicallyLoadScript(url) { // private
36+
let script = document.createElement('script');
37+
script.src = url;
38+
script.async = false;
39+
script.defer = true;
40+
document.body.appendChild(script);
41+
}
42+
43+
function blockUnusedSymbols(allSymbols, usedSymbols) {
44+
let unusedSymbols = allSymbols.filter(x => !usedSymbols.includes(x));
45+
let scriptText = '';
46+
for (let symbol of unusedSymbols) {
47+
scriptText += `${symbol} = undefined;\n`
48+
}
49+
let script = document.createElement('script');
50+
script.text = script;
51+
script.async = false;
52+
document.body.appendChild(script);
53+
}
54+
55+
return {
56+
loadModule: loadModule,
57+
getModuleDirList: getModuleDirList
58+
};
59+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
RUNES is a library for realising the picture language of
2+
<a href="https://sicp.comp.nus.edu.sg/chapters/33">section
3+
2.2.4 Example: A Picture Language</a>
4+
of the textbook
5+
<a href="https://sicp.comp.nus.edu.sg">Structure and Interpretation
6+
of Computer Programs, JavaScript Adaptation</a> (SICP JS).
7+
It provides primitive values, called runes, such
8+
as `heart` and `circle`, operations such as `beside`
9+
to construct more complex runes from simpler ones, and ways
10+
to display runes, in two-dimensional and three-dimensional
11+
space.
12+
13+
On the right, you see all predeclared names of the RUNES library,
14+
in alphabetical
15+
order. Click on a name to see how it is defined and used.
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"module_name": "BASE",
3+
"module_prefix": "",
4+
"module_source_files": [
5+
"src/list.js",
6+
"src/tree.js",
7+
"src/core.js"
8+
],
9+
"module_symbols": [
10+
"pair",
11+
"is_pair",
12+
"head",
13+
"tail",
14+
"is_null",
15+
"is_list",
16+
"list",
17+
"length",
18+
"map",
19+
"reverse",
20+
"append",
21+
"member",
22+
"remove",
23+
"equal",
24+
"filter",
25+
"enum_list",
26+
"list_ref",
27+
"accumulate",
28+
"set_head",
29+
"set_tail",
30+
"make_empty_tree",
31+
"is_tree",
32+
"make_tree",
33+
"is_empty_tree",
34+
"entry",
35+
"left_branch",
36+
"right_branch",
37+
"display",
38+
"math_abs"
39+
],
40+
"module_undocumented_symbols": [
41+
"array_test",
42+
"list_to_vector",
43+
"vector_to_list",
44+
"build_list",
45+
"build",
46+
"for_each",
47+
"remove_all",
48+
"assoc"
49+
]
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
function display(text) {
4+
let outputDiv = document.getElementById('output-div');
5+
let element = document.createElement('p');
6+
element.appendChild(document.createTextNode(text));
7+
outputDiv.appendChild(element);
8+
}
9+
10+
function math_abs(x) {
11+
return Math.abs(x);
12+
}

0 commit comments

Comments
 (0)