Skip to content

Commit 1acee0c

Browse files
committed
sync everything to github
1 parent 880f492 commit 1acee0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+20424
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
*.lai
1111
*.la
1212
*.a
13+
14+
*~
15+
*.ll
16+
*.s

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
LLVM_CXXFLAGS="`$LLVM_CONFIG --cxxflags` -fno-rtti"
2+
LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
3+
LLVM_LIBS=`$LLVM_CONFIG --libs core bitwriter jit x86codegen`
4+
LLVM_LIBS:="$LLVM_LDFLAGS $LLVM_LIBS -lstdc++"
5+
6+
make-shell:
7+
$(MAKE) -C shell
8+
9+
make-llvm:
10+
cd llvm && ./configure --disable-jit
11+
$(MAKE) -C llvm
12+
13+
14+
test: foo.js main.o libecho.a
15+
-./ejs -f foo.js 2> foo-tmp.ll
16+
llvm-as < foo-tmp.ll | opt -mem2reg -simplifycfg | llvm-dis > foo.ll
17+
llc -march=x86-64 -O0 foo.ll
18+
sed -e s/vmovsd/movsd/ < foo.s > foo.sed.s
19+
gcc -o test foo.sed.s main.o -lecho

STUFF

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
3+
* lexer
4+
5+
* parser
6+
7+
* desugar
8+
- get rid of immediately applied functions:
9+
10+
(function () { /* ... */ })();
11+
12+
can become nothing but:
13+
14+
{ /* ... */ }
15+
16+
if there are no 'vars' inside it. if there are, we hoist the
17+
vars to the toplevel of the function and convert them to
18+
lets, then replace it with the { }
19+
20+
* lambda lifting
21+
22+
* optimizations
23+
24+
* ffi
25+
26+
- we need some sort of DSL for external C-linkage functions. bonus points for a syntax that allows objc messages as well.
27+
maybe something like:
28+
29+
@extern void print_internal_i32 (@i32(theInt))
30+
@extern void print_internal_d64 (@d64(theDouble))
31+
@extern void print_internal_string (@string(theString))
32+
33+
function print(theObj) {
34+
if (theObj === null)
35+
print_internal_string ("null");
36+
else if (typeof(theObj) == "undefined")
37+
print_internal_string ("undefined");
38+
else if (typeof(theObj) == "object")
39+
print_internal_string (theObj.toString());
40+
}

ejs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/python
2+
#
3+
# Narcissus 'shell' for use with jstests.py
4+
# Expects to be in the same directory as ./js
5+
# Expects the Narcissus src files to be in ./narcissus/
6+
7+
import os, re, sys, signal
8+
from subprocess import *
9+
from optparse import OptionParser
10+
11+
THIS_DIR = os.path.dirname(__file__)
12+
SPIDERMONKEY_DIR = os.path.abspath(os.path.join(THIS_DIR, 'spidermonkey'))
13+
14+
if 'NJS_SHELL' in os.environ:
15+
js_cmd = os.path.abspath(os.environ['NJS_SHELL'])
16+
else:
17+
js_cmd = os.path.abspath(os.path.join(THIS_DIR, 'js'))
18+
19+
narc_shell = os.path.join(SPIDERMONKEY_DIR, "shell.js")
20+
21+
def handler(signum, frame):
22+
print ''
23+
# the exit code produced by ./js on SIGINT
24+
sys.exit(130)
25+
26+
signal.signal(signal.SIGINT, handler)
27+
28+
if __name__ == '__main__':
29+
op = OptionParser(usage='%prog [TEST-SPECS]')
30+
op.add_option('-f', '--file', dest='js_files', action='append',
31+
help='JS file to load', metavar='FILE')
32+
op.add_option('-e', '--expression', dest='js_exps', action='append',
33+
help='JS expression to evaluate')
34+
op.add_option('-i', '--interactive', dest='js_interactive', action='store_true',
35+
help='enable interactive shell')
36+
op.add_option('-I', '--interactive-meta', dest='js_interactive_meta', action='store_true',
37+
help='load Narcissus but run interactive SpiderMonkey shell')
38+
op.add_option('-E', '--expression-meta', dest='js_exps_meta', action='append',
39+
help='expression to evaluate with SpiderMonkey after loading Narcissus')
40+
op.add_option('-P', '--parse-only', dest='js_parseonly', action='store_true',
41+
help='stop after the parsing stage and output pretty-printed source code')
42+
op.add_option('-w', '--web-compatible', dest='js_webcompatible', action='store_true',
43+
help='disable non-standard Mozilla extensions')
44+
op.add_option('-p', '--paren-free', dest='js_parenfree', action='store_true',
45+
help='use experimental paren-free syntax')
46+
op.add_option('-d', '--desugar', dest='js_desugar', action='store_true',
47+
help='desugar SpiderMonkey language extensions')
48+
49+
(options, args) = op.parse_args()
50+
51+
cmd = ""
52+
53+
if options.js_webcompatible:
54+
cmd += 'Narcissus.options.mozillaMode = false; '
55+
56+
if options.js_parenfree:
57+
cmd += 'Narcissus.options.parenFreeMode = true; '
58+
59+
if options.js_desugar:
60+
cmd += 'Narcissus.options.desugarExtensions = true; '
61+
62+
if options.js_exps:
63+
for exp in options.js_exps:
64+
if options.js_parseonly:
65+
cmd += 'print(Narcissus.decompiler.pp(Narcissus.parser.parse("%s"))); ' % exp.replace('"', '\\"')
66+
else:
67+
#cmd += 'Narcissus.interpreter.evaluate("%s"); ' % exp.replace('"', '\\"')
68+
cmd += 'Narcissus.compiler.compile(Narcissus.parser.parse("%s")) || quit(1);' % exp.replace('"', '\\"')
69+
70+
if options.js_files:
71+
for file in options.js_files:
72+
if options.js_parseonly:
73+
cmd += 'print(Narcissus.decompiler.pp(Narcissus.parser.parse(snarf("%(file)s"), "%(file)s", 1))); ' % { 'file':file }
74+
else:
75+
cmd += 'Narcissus.compiler.compile(Narcissus.parser.parse(snarf("%(file)s"), "%(file)s", 1)) || quit(1);' % { 'file': file }
76+
77+
if (not options.js_exps) and (not options.js_files):
78+
options.js_interactive = True
79+
80+
argv = [js_cmd, '-f', narc_shell]
81+
82+
if options.js_exps_meta:
83+
argv += ['-e', cmd]
84+
for exp in options.js_exps_meta:
85+
argv += ['-e', exp]
86+
if options.js_interactive_meta:
87+
argv += ['-i']
88+
elif options.js_interactive_meta:
89+
argv += ['-e', cmd, '-i']
90+
else:
91+
if options.js_interactive:
92+
cmd += 'Narcissus.interpreter.repl();'
93+
argv = ['rlwrap'] + argv
94+
argv += ['-e', cmd]
95+
96+
try:
97+
retcode = Popen(argv).wait();
98+
except OSError as e:
99+
if e.errno is 2 and options.js_interactive:
100+
retcode = Popen(argv[1:]).wait()
101+
102+
exit(retcode)

foo.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function add2(n) {
2+
var o = n;
3+
{
4+
var p = o+2;
5+
}
6+
7+
p = o + 4;
8+
return p;
9+
}
10+
11+
function fib(n) {
12+
if (n === 0 || n === 1)
13+
return 1;
14+
else
15+
return fib(n-1) + fib(n-2);
16+
}
17+
18+
/*
19+
* not yet - 'this' isn't supported, and neither is 'new', and assigning into property accessors ('dot')
20+
*/
21+
/*
22+
function Fib() {
23+
this.gen = function(n) {
24+
if (n === 0 || n === 1)
25+
return 1;
26+
else
27+
return this.gen(n-1) + this.gen(n-2);
28+
};
29+
}
30+
*/
31+
32+
print("Fibonacci function");
33+
print(fib(0));
34+
print(fib(1));
35+
print(fib(2));
36+
print(fib(3));
37+
print(fib(4));
38+
print(fib(5));
39+
print(fib(6));
40+
print(fib(7));
41+
print(fib(8));
42+
print(fib(9));
43+
44+
print("function with local variables");
45+
var add2arg=99;
46+
print(add2(add2arg));
47+
48+
print ("Fibonacci object");

lib/browser.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* -*- Mode: JS; tab-width: 4; indent-tabs-mode: nil; -*-
2+
* vim: set sw=4 ts=8 et tw=78:
3+
/* ***** BEGIN LICENSE BLOCK *****
4+
*
5+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
6+
*
7+
* The contents of this file are subject to the Mozilla Public License Version
8+
* 1.1 (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at
10+
* http://www.mozilla.org/MPL/
11+
*
12+
* Software distributed under the License is distributed on an "AS IS" basis,
13+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14+
* for the specific language governing rights and limitations under the
15+
* License.
16+
*
17+
* The Original Code is the Narcissus JavaScript engine.
18+
*
19+
* The Initial Developer of the Original Code is
20+
* Brendan Eich <[email protected]>.
21+
* Portions created by the Initial Developer are Copyright (C) 2004
22+
* the Initial Developer. All Rights Reserved.
23+
*
24+
* Contributor(s):
25+
*
26+
* Alternatively, the contents of this file may be used under the terms of
27+
* either the GNU General Public License Version 2 or later (the "GPL"), or
28+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29+
* in which case the provisions of the GPL or the LGPL are applicable instead
30+
* of those above. If you wish to allow use of your version of this file only
31+
* under the terms of either the GPL or the LGPL, and not to allow others to
32+
* use your version of this file under the terms of the MPL, indicate your
33+
* decision by deleting the provisions above and replace them with the notice
34+
* and other provisions required by the GPL or the LGPL. If you do not delete
35+
* the provisions above, a recipient may use your version of this file under
36+
* the terms of any one of the MPL, the GPL or the LGPL.
37+
*
38+
* ***** END LICENSE BLOCK ***** */
39+
40+
/*
41+
* Narcissus - JS implemented in JS.
42+
*
43+
* Browser-specific tweaks needed for Narcissus to execute properly
44+
*/
45+
46+
var interpreter = require('./interpreter');
47+
var globalBase = interpreter.globalBase;
48+
49+
// Prevent setTimeout from breaking out to SpiderMonkey
50+
globalBase.setTimeout = function(code, delay) {
51+
var timeoutCode = (typeof code === "string") ?
52+
function() { interpreter.evaluate(code); } :
53+
code;
54+
return setTimeout(timeoutCode, delay);
55+
};
56+
57+
// Prevent setInterval from breaking out to SpiderMonkey
58+
globalBase.setInterval = function(code, delay) {
59+
var timeoutCode = (typeof code === "string") ?
60+
function() { interpreter.evaluate(code); } :
61+
code;
62+
return setInterval(timeoutCode, delay);
63+
};
64+
65+
// Hack to avoid problems with the Image constructor in Narcissus.
66+
globalBase.Image = function() {};

0 commit comments

Comments
 (0)