Commit d26e81b9 authored by Dylan Trotter's avatar Dylan Trotter

Set libdir to the fixed value __python__ and get rid of libdir and runtime grumpc flags.

parent d92762bb
......@@ -79,7 +79,7 @@ THIRD_PARTY_STDLIB_SRCS := $(shell find third_party/pypy -name '*.py') $(shell f
THIRD_PARTY_STDLIB_PACKAGES := $(foreach x,$(THIRD_PARTY_STDLIB_SRCS),$(patsubst third_party/stdlib/%.py,%,$(patsubst third_party/pypy/%.py,%,$(patsubst third_party/pypy/%/__init__.py,%,$(patsubst third_party/stdlib/%/__init__.py,%,$(x))))))
STDLIB_SRCS := $(GRUMPY_STDLIB_SRCS) $(THIRD_PARTY_STDLIB_SRCS)
STDLIB_PACKAGES := $(GRUMPY_STDLIB_PACKAGES) $(THIRD_PARTY_STDLIB_PACKAGES)
STDLIB := $(patsubst %,$(PKG_DIR)/grumpy/lib/%.a,$(STDLIB_PACKAGES))
STDLIB := $(patsubst %,$(PKG_DIR)/__python__/%.a,$(STDLIB_PACKAGES))
STDLIB_TESTS := \
itertools_test \
math_test \
......@@ -212,7 +212,7 @@ $(PYLINT_BIN):
@cd build/third_party/pylint-1.6.4 && $(PYTHON) setup.py install --prefix $(ROOT_DIR)/build
pylint: $(PYLINT_BIN)
@$(PYLINT_BIN) compiler/*.py $(addprefix tools/,benchcmp coverparse diffrange grumpc grumprun)
@$(PYTHON) $(PYLINT_BIN) compiler/*.py $(addprefix tools/,benchcmp coverparse diffrange grumpc grumprun)
lint: golint pylint
......@@ -221,19 +221,19 @@ lint: golint pylint
# ------------------------------------------------------------------------------
define GRUMPY_STDLIB
build/src/grumpy/lib/$(2)/module.go: $(1) $(COMPILER)
@mkdir -p build/src/grumpy/lib/$(2)
build/src/__python__/$(2)/module.go: $(1) $(COMPILER)
@mkdir -p build/src/__python__/$(2)
@$(COMPILER_BIN) -modname=$(notdir $(2)) $(1) > $$@
build/src/grumpy/lib/$(2)/module.d: $(1)
@mkdir -p build/src/grumpy/lib/$(2)
@$(PYTHON) -m modulefinder -p $(ROOT_DIR)/lib:$(ROOT_DIR)/third_party/stdlib:$(ROOT_DIR)/third_party/pypy $$< | awk '{if (($$$$1 == "m" || $$$$1 == "P") && $$$$2 != "__main__" && $$$$2 != "$(2)") {gsub(/\./, "/", $$$$2); print "$(PKG_DIR)/grumpy/lib/$(2).a: $(PKG_DIR)/grumpy/lib/" $$$$2 ".a"}}' > $$@
build/src/__python__/$(2)/module.d: $(1)
@mkdir -p build/src/__python__/$(2)
@$(PYTHON) -m modulefinder -p $(ROOT_DIR)/lib:$(ROOT_DIR)/third_party/stdlib:$(ROOT_DIR)/third_party/pypy $$< | awk '{if (($$$$1 == "m" || $$$$1 == "P") && $$$$2 != "__main__" && $$$$2 != "$(2)") {gsub(/\./, "/", $$$$2); print "$(PKG_DIR)/__python__/$(2).a: $(PKG_DIR)/__python__/" $$$$2 ".a"}}' > $$@
$(PKG_DIR)/grumpy/lib/$(2).a: build/src/grumpy/lib/$(2)/module.go $(RUNTIME)
@mkdir -p $(PKG_DIR)/grumpy/lib/$(dir $(2))
@go tool compile -o $$@ -p grumpy/lib/$(2) -complete -I $(PKG_DIR) -pack $$<
$(PKG_DIR)/__python__/$(2).a: build/src/__python__/$(2)/module.go $(RUNTIME)
@mkdir -p $(PKG_DIR)/__python__/$(dir $(2))
@go tool compile -o $$@ -p __python__/$(2) -complete -I $(PKG_DIR) -pack $$<
-include build/src/grumpy/lib/$(2)/module.d
-include build/src/__python__/$(2)/module.d
endef
......@@ -246,13 +246,13 @@ build/testing/$(patsubst %_test,%_test_,$(notdir $(1))).go:
@echo 'import (' >> $$@
@echo ' "os"' >> $$@
@echo ' "grumpy"' >> $$@
@echo ' mod "grumpy/lib/$(1)"' >> $$@
@echo ' mod "__python__/$(1)"' >> $$@
@echo ')' >> $$@
@echo 'func main() {' >> $$@
@echo ' os.Exit(grumpy.RunMain(mod.Code))' >> $$@
@echo '}' >> $$@
build/testing/$(notdir $(1)): build/testing/$(patsubst %_test,%_test_,$(notdir $(1))).go $(RUNTIME) $(PKG_DIR)/grumpy/lib/$(1).a
build/testing/$(notdir $(1)): build/testing/$(patsubst %_test,%_test_,$(notdir $(1))).go $(RUNTIME) $(PKG_DIR)/__python__/$(1).a
@go build -o $$@ $$<
build/testing/$(notdir $(1)).pass: build/testing/$(notdir $(1))
......
......@@ -60,9 +60,7 @@ class Block(object):
# Block objects by defining them here.
_filename = None
_full_package_name = None
_libroot = None
_buffer = None
_runtime = None
_strings = None
imports = None
_future_features = None
......@@ -88,14 +86,6 @@ class Block(object):
# pylint: disable=protected-access
return self._module_block._full_package_name
@property
def runtime(self):
return self._module_block._runtime # pylint: disable=protected-access
@property
def libroot(self):
return self._module_block._libroot # pylint: disable=protected-access
@property
def filename(self):
return self._module_block._filename # pylint: disable=protected-access
......@@ -157,12 +147,11 @@ class Block(object):
Returns:
A Package representing the import.
"""
return self.add_native_import('/'.join([self.libroot, name]))
return self.add_native_import('__python__/' + name)
def add_native_import(self, name):
alias = None
if name == 'grumpy':
name = self.runtime
alias = 'πg'
if name in self._module_block.imports:
return self._module_block.imports[name]
......@@ -225,12 +214,9 @@ class ModuleBlock(Block):
imports: A dict mapping fully qualified Go package names to Package objects.
"""
def __init__(self, full_package_name, runtime, libroot, filename, src,
future_features):
def __init__(self, full_package_name, filename, src, future_features):
Block.__init__(self, None, '<module>')
self._full_package_name = full_package_name
self._runtime = runtime
self._libroot = libroot
self._filename = filename
self._buffer = source.Buffer(src)
self._strings = set()
......
......@@ -47,19 +47,19 @@ class BlockTest(unittest.TestCase):
func1_block = block.FunctionBlock(module_block, 'func1', {}, False)
func2_block = block.FunctionBlock(func1_block, 'func2', {}, False)
package = func2_block.add_import('foo/bar')
self.assertEqual(package.name, 'grumpy/lib/foo/bar')
self.assertEqual(package.alias, 'π_grumpyΓlibΓfooΓbar')
self.assertEqual(module_block.imports, {'grumpy/lib/foo/bar': package})
self.assertEqual(package.name, '__python__/foo/bar')
self.assertEqual(package.alias, 'π___python__ΓfooΓbar')
self.assertEqual(module_block.imports, {'__python__/foo/bar': package})
def testAddImportRepeated(self):
b = _MakeModuleBlock()
package = b.add_import('foo')
self.assertEqual(package.name, 'grumpy/lib/foo')
self.assertEqual(package.alias, 'π_grumpyΓlibΓfoo')
self.assertEqual(b.imports, {'grumpy/lib/foo': package})
self.assertEqual(package.name, '__python__/foo')
self.assertEqual(package.alias, 'π___python__Γfoo')
self.assertEqual(b.imports, {'__python__/foo': package})
package2 = b.add_import('foo')
self.assertIs(package, package2)
self.assertEqual(b.imports, {'grumpy/lib/foo': package})
self.assertEqual(b.imports, {'__python__/foo': package})
def testLoop(self):
b = _MakeModuleBlock()
......@@ -246,8 +246,7 @@ class FunctionBlockVisitorTest(unittest.TestCase):
def _MakeModuleBlock():
return block.ModuleBlock('__main__', 'grumpy', 'grumpy/lib', '<test>', '',
stmt.FutureFeatures())
return block.ModuleBlock('__main__', '<test>', '', stmt.FutureFeatures())
def _ParseStmt(stmt_str):
......
......@@ -223,8 +223,7 @@ class ExprVisitorTest(unittest.TestCase):
testUnaryOpPos = _MakeExprTest('+4')
def _MakeModuleBlock():
return block.ModuleBlock('__main__', 'grumpy', 'grumpy/lib', '<test>', '',
stmt.FutureFeatures())
return block.ModuleBlock('__main__', '<test>', '', stmt.FutureFeatures())
def _ParseExpr(expr):
......
......@@ -601,15 +601,13 @@ class StatementVisitorTest(unittest.TestCase):
def _MakeModuleBlock():
return block.ModuleBlock('__main__', 'grumpy', 'grumpy/lib', '<test>', '',
stmt.FutureFeatures())
return block.ModuleBlock('__main__', '<test>', '', stmt.FutureFeatures())
def _ParseAndVisit(source):
mod = pythonparser.parse(source)
future_features = stmt.visit_future(mod)
b = block.ModuleBlock('__main__', 'grumpy', 'grumpy/lib', '<test>',
source, future_features)
b = block.ModuleBlock('__main__', '<test>', source, future_features)
visitor = stmt.StatementVisitor(b)
visitor.visit(mod)
return visitor
......
......@@ -37,8 +37,8 @@ class WriterTest(unittest.TestCase):
def testWriteBlock(self):
writer = util.Writer()
mod_block = block.ModuleBlock('__main__', 'grumpy', 'grumpy/lib', '<test>',
'', stmt.FutureFeatures())
mod_block = block.ModuleBlock('__main__', '<test>', '',
stmt.FutureFeatures())
writer.write_block(mod_block, 'BODY')
output = writer.getvalue()
dispatch = 'switch πF.State() {\n\tcase 0:\n\tdefault: panic'
......
......@@ -33,14 +33,10 @@ from grumpy.compiler import util
parser = argparse.ArgumentParser()
parser.add_argument('filename', help='Python source filename')
parser.add_argument('-modname', default='__main__', help='Python module name')
parser.add_argument('-runtime', default='grumpy',
help='Grumpy runtime package name')
parser.add_argument('-libroot', default='grumpy/lib',
help='Path where Grumpy standard library packages live')
def main(args):
for arg in ('filename', 'modname', 'runtime', 'libroot'):
for arg in ('filename', 'modname'):
if not getattr(args, arg, None):
print >> sys.stderr, '{} arg must not be empty'.format(arg)
return 1
......@@ -61,8 +57,8 @@ def main(args):
return 2
full_package_name = args.modname.replace('.', '/')
mod_block = block.ModuleBlock(full_package_name, args.runtime, args.libroot,
args.filename, py_contents, future_features)
mod_block = block.ModuleBlock(full_package_name, args.filename,
py_contents, future_features)
mod_block.add_native_import('grumpy')
visitor = stmt.StatementVisitor(mod_block)
# Indent so that the module body is aligned with the goto labels.
......
......@@ -36,7 +36,7 @@ package main
import (
\t"os"
\t"grumpy"
\t"grumpy/lib/$package"
\t"__python__/$package"
)
func main() {
\tos.Exit(grumpy.RunMain($alias.Code))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment