forked from kanaka/mal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
miniMAL: add classOf and fix printing.
- Loading branch information
Showing
4 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Node vs browser behavior | ||
var interop = {}; | ||
if (typeof module === 'undefined') { | ||
var exports = interop, | ||
GLOBAL = window; | ||
} | ||
|
||
function resolve_js(str) { | ||
if (str.match(/\./)) { | ||
var re = /^(.*)\.\([^\.]*)$/, | ||
match = re.exec(str); | ||
return [eval(match[0]), eval(str)]; | ||
} else { | ||
return [GLOBAL, eval(str)]; | ||
} | ||
} | ||
|
||
function js_to_mal(obj) { | ||
var cache = []; | ||
var str = JSON.stringify(obj, function(key, value) { | ||
if (typeof value === 'object' && value !== null) { | ||
if (cache.indexOf(value) !== -1) { | ||
// Circular reference found, discard key | ||
return; | ||
} | ||
// Store value in our collection | ||
cache.push(value); | ||
} | ||
return value; | ||
}); | ||
cache = null; // Enable garbage collection | ||
return JSON.parse(str); | ||
} | ||
|
||
exports.resolve_js = interop.resolve_js = resolve_js; | ||
exports.js_to_mal = interop.js_to_mal = js_to_mal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters