-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathejit.js
113 lines (96 loc) · 2.21 KB
/
ejit.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
var WrongNumberOfArguments = function(msg) {
this.message = msg;
this.name = "WrongNumberOfArguments";
};
// The two emacs-lisp namespaces
exports.vars = {};
exports.functions = {};
exports.JSREQUIRE = function (symbol) {
// Loads symbol (a string) into the current scope.
var path = process.cwd() + "/" + symbol;
try {
var loadthing = require (path);
for (var key in loadthing) {
exports[key] = loadthing[key];
}
}
catch (e) {
throw new Exception("failed to require with " + path);
}
};
exports.require = function (symbol) {
// We need the ejit namespace to have been established.
child_process.spawn(
ejit.emacs_process,
["-batch", ""]
);
};
exports.cons = function (car, cdr) {
return {
car: car,
cdr: cdr
};
};
exports.car = function (cons) {
return cons.car;
};
exports.cdr = function (cons) {
return cons.cdr;
};
exports.cadr = function (cons) {
return cons.cdr.car;
}
exports.caddr = function (cons) {
return cons.cdr.cdr.car;
}
exports.cadddr = function (cons) {
return cons.cdr.cdr.cdr.car;
}
exports.PLUS = function () {
var a=0;
for (var i=0; i < arguments.length; i++) {
a = a + arguments[i];
}
return a;
};
exports.MULT = function () {
var a=1;
for (var i=0; i < arguments.length; i++) {
a = a * arguments[i];
}
return a;
};
exports.MINUS = function () {
if (arguments.length == 1) {
return 0 - arguments[0];
}
else {
var a = arguments[0];
for (var i=1; i < arguments.length; i++) {
a = a - arguments[i];
}
return a;
}
};
exports.DIVIDE = function () {
if (arguments.length < 2) {
throw new WrongNumberOfArguments("wrong number of arguments");
}
else {
var a = arguments[0];
for (var i=1; i < arguments.length; i++) {
a = a - arguments[i];
}
return a;
}
};
// And the std library
var utils = require("util");
exports.functions.message = function () {
if (arguments.length < 2) {
console.log(arguments);
}
else {
console.log(utils.format(arguments));
}
};