cor-lang
Version:
The Language of the Web
43 lines (32 loc) • 1.04 kB
JavaScript
(function(){
cor = (typeof cor === 'undefined' ? {} : cor);
var
isBrowser = typeof window !== 'undefined' &&
typeof window.document !== 'undefined',
isNode = ! isBrowser &&
typeof global !== 'undefined' &&
typeof process !== 'undefined';
if (isBrowser) {
global = window;
}
cor.isBrowser = isBrowser;
cor.isNode = isNode;
cor.compile = function(src, filename) {
var
comp = new cor.Compiler(src, filename),
ast = comp.parse(),
js = comp.compile(ast);
return js;
};
cor.run = function(src, require, module, exports) {
exports = exports || {};
require = require || function(){};
module = module || {exports: exports};
var
PROG,
js = this.compile(src);
eval('var PROG=function(require,module,exports){var PROG;' + js + '};');
PROG(require, module, exports);
return module.exports;
};
})();