Permalink
Browse files

futzing with a few things

  • Loading branch information...
Paul Tagliamonte
Paul Tagliamonte committed Mar 21, 2013
1 parent c8eec0c commit 980cd493e02c3e320c84b6d1e1a65a443c262f14
Showing with 156 additions and 14 deletions.
  1. +6 −0 bin/hyc
  2. +6 −1 hy/__main__.py
  3. +3 −2 hy/compiler.py
  4. +23 −1 hy/importer.py
  5. +1 −0 setup.py
  6. +5 −4 site/coffee/main.coffee
  7. +104 −0 site/js/date.js
  8. +2 −1 site/less/layout.less
  9. +1 −0 site/templates/base.html
  10. +5 −5 site/templates/repl.html
View
@@ -0,0 +1,6 @@
+#!/usr/bin/env hy
+
+(import sys)
+(import-from hy.importer write-hy-as-pyc)
+
+(write-hy-as-pyc (get sys.argv 1))
View
@@ -1,7 +1,12 @@
-import hy
+import hy # NOQA
import imp
import sys
+# This just mocks the normalish behavior of the Python interp. Helpful to aid
+# with shiming existing apps that don't really "work" with Hy.
+#
+# You could say this script helps Hyjack a file.
+#
if len(sys.argv) > 1:
sys.argv.pop(0)
View
@@ -227,12 +227,13 @@ def compile_import_expression(self, expr):
@builds("import_as")
def compile_import_as_expression(self, expr):
expr.pop(0) # index
- modlist = [expr[i:i+2] for i in range(0, len(expr), 2)]
+ modlist = [expr[i:i + 2] for i in range(0, len(expr), 2)]
return ast.Import(
lineno=expr.start_line,
col_offset=expr.start_column,
module=str(expr.pop(0)),
- names=[ast.alias(name=str(x[0]), asname=str(x[1])) for x in modlist])
+ names=[ast.alias(name=str(x[0]),
+ asname=str(x[1])) for x in modlist])
@builds("import_from")
def compile_import_from_expression(self, expr):
View
@@ -21,8 +21,10 @@
from hy.compiler import hy_compile
from hy.lex import tokenize
from hy.core import process
+from py_compile import wr_long, MAGIC
+import marshal
import imp
import sys
import os
@@ -31,7 +33,7 @@
if sys.version_info[0] >= 3:
from io import StringIO
else:
- from StringIO import StringIO
+ from StringIO import StringIO # NOQA
def import_buffer_to_hst(fd):
@@ -64,6 +66,26 @@ def import_file_to_module(name, fpath):
return mod
+def write_hy_as_pyc(fname):
+ with open(fname, 'U') as f:
+ try:
+ timestamp = long(os.fstat(f.fileno()).st_mtime)
+ except AttributeError:
+ timestamp = long(os.stat(fname).st_mtime)
+
+ _ast = import_file_to_ast(fname)
+ code = compile(_ast, fname, "exec")
+ cfile = "%s.pyc" % fname[:-len(".hy")]
+
+ with open(cfile, 'wb') as fc:
+ fc.write('\0\0\0\0')
+ wr_long(fc, timestamp)
+ marshal.dump(code, fc)
+ fc.flush()
+ fc.seek(0, 0)
+ fc.write(MAGIC)
+
+
class HyFinder(object):
def is_package(self, fullname):
dirpath = "/".join(fullname.split("."))
View
@@ -34,6 +34,7 @@
version=__version__,
scripts=[
"bin/hy",
+ "bin/hyc",
],
packages=[
'hy',
View
@@ -37,20 +37,21 @@ HyCodeMirror.setSize("100%", "100%")
reload = ->
input = HyCodeMirror.getValue()
+ format = "h:mm:ss"
$.ajax({
url: "/hy2py",
type: "POST",
data: {'code': input},
success: (result) ->
PyCodeMirror.setValue(result)
- now = new Date().getTime()
- $("#build-msgs").text(now + " Updated.")
+ now = Date.parse("now").toString(format)
+ $("#build-msgs").prepend(now + " updated.<br />")
$("#repl-root").removeClass("error")
$("#repl-root").addClass("ok")
statusCode: {
500: (response) ->
- now = new Date().getTime()
- $("#build-msgs").text(now + " " + response.responseText)
+ now = Date.parse("now").toString(format)
+ $("#build-msgs").prepend(now + " " + response.responseText + "<br />")
$("#repl-root").removeClass("ok")
$("#repl-root").addClass("error")
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -78,7 +78,8 @@ h1 {
#build-msgs {
border-top: 1px solid rgba(82, 168, 236, 0.2);
- height: 10%;
+ height: 8%;
padding: 5px;
color: #777777;
+ overflow: hidden;
}
View
@@ -5,6 +5,7 @@
<link rel="stylesheet" href="{{ url_for("static", filename="css/pygments.css") }}" ></link>
<link rel="stylesheet" href="{{ url_for("static", filename="css/hy.css") }}" ></link>
<script src="{{ url_for("static", filename="js/jquery-1.9.1.min.js") }}" type="text/javascript" ></script>
+ <script src="{{ url_for("static", filename="js/date.js") }}" type="text/javascript" ></script>
<script src="{{ url_for("static", filename="js/main.js") }}" type="text/javascript" ></script>
{% block head %}{% endblock %}
</head>
View
@@ -16,7 +16,7 @@
{% block content %}
<div id='repl-root' class='repl-root' >
-<div class='repl' id='hython-repl'>
+ <div class='repl' id='hython-repl'>
<textarea id="hython-target">
;;;; This is Hy. Hy is a Lisp variant that
;;;; "compiles" to Python ASTs.
@@ -43,9 +43,9 @@
(print (add-two-numbers 1 2))
</textarea>
-</div>
-<div class='repl' id='python-repl'></div>
-<div class='clear'></div>
-<div class='msgs' id='build-msgs'></div>
+ </div>
+ <div class='repl' id='python-repl'></div>
+ <div class='clear'></div>
+ <div class='msgs' id='build-msgs'></div>
</div>
{% endblock %}

0 comments on commit 980cd49

Please sign in to comment.