From 2b9882bcca39b7b0c9f84751c5edcf41e76b2b7b Mon Sep 17 00:00:00 2001 From: Scott Lawrence Date: Tue, 13 Dec 2011 12:17:48 -0500 Subject: [PATCH] Moving giant imports list from the library to the frontend (opening the possiblity for goinstall to work) --- .gitignore | 2 +- Makefile | 15 +++++++++++++-- kakapo.go | 6 ++++++ lisp/Makefile | 13 +------------ lisp/compat.go | 7 +++++++ {lisp/scanpkgs => scanpkgs}/main.go | 2 +- 6 files changed, 29 insertions(+), 16 deletions(-) rename {lisp/scanpkgs => scanpkgs}/main.go (99%) diff --git a/.gitignore b/.gitignore index bfcb822..5606109 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ _obj kakapo packages.go -lisp/scanpkgs/scanpkgs +scanpkgs/scanpkgs *.a repl.go *.out diff --git a/Makefile b/Makefile index 1a2de56..7f60c5c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ include ${GOROOT}/src/Make.inc TARG = kakapo -GOFILES = kakapo.go repl.go +GOFILES = kakapo.go repl.go packages.go PREREQ = lisp CLEANFILES = _go_.${O} ${TARG} lisp.a repl.go TXT2GO = ./txt2go.sh @@ -15,16 +15,27 @@ _go_.${O}: ${GOFILES} ${PREREQ} repl.go: repl.lsp ${TXT2GO} repl < repl.lsp > $@ +packages.go: scanpkgs/scanpkgs + scanpkgs/scanpkgs > packages.go + gofmt -w packages.go + lisp: make -Clisp cp lisp/_obj/lisp.a . +scanpkgs/scanpkgs: scanpkgs/scanpkgs.${O} + ${LD} -o $@ scanpkgs/scanpkgs.${O} + +scanpkgs/scanpkgs.${O}: scanpkgs/main.go + ${GC} -o $@ scanpkgs/main.go + clean: rm -f ${CLEANFILES} + rm -f scanpkgs/scanpkgs.${O} scanpkgs/scanpkgs make -Clisp clean fmt: - gofmt -w ${GOFILES} + gofmt -w kakapo.go make -Clisp fmt test: ${TARG} diff --git a/kakapo.go b/kakapo.go index 7b5e5cf..6da2106 100644 --- a/kakapo.go +++ b/kakapo.go @@ -23,6 +23,12 @@ func main() { return } + // Expose impots + for name, pkg := range _go_imports { + ExposeImport(name, pkg) + } + + // Expose globals ExposeGlobal("-interpreter", "Kakapo") ExposeGlobal("-interpreter-version", VERSION) diff --git a/lisp/Makefile b/lisp/Makefile index 650b273..90cdae7 100644 --- a/lisp/Makefile +++ b/lisp/Makefile @@ -3,21 +3,10 @@ include ${GOROOT}/src/Make.inc TARG = lisp BUILTINGO = cons.go math.go panic.go bool.go SRCFILES = parse.go eval.go util.go builtins.go syntax.go compat.go primitives.go scope.go interpret.go ${BUILTINGO} -GOFILES = ${SRCFILES} packages.go -CLEANFILES = packages.go +GOFILES = ${SRCFILES} include ${GOROOT}/src/Make.pkg -packages.go: scanpkgs/scanpkgs - scanpkgs/scanpkgs > packages.go - gofmt -w packages.go - -scanpkgs/scanpkgs: scanpkgs/scanpkgs.${O} - ${LD} -o $@ scanpkgs/scanpkgs.${O} - -scanpkgs/scanpkgs.${O}: scanpkgs/main.go - ${GC} -o $@ scanpkgs/main.go - fmt: gofmt -w ${SRCFILES} diff --git a/lisp/compat.go b/lisp/compat.go index 05d5f34..e0b965e 100644 --- a/lisp/compat.go +++ b/lisp/compat.go @@ -5,6 +5,13 @@ import ( "reflect" ) +// The map of available imports +var _go_imports = map[string]map[string]interface{}{} + +func ExposeImport(name string, pkg map[string]interface{}) { + _go_imports[name] = pkg +} + func builtinImport(sc *scope, ss []sexpr) sexpr { if len(ss) != 1 { panic("Invalid number of arguments") diff --git a/lisp/scanpkgs/main.go b/scanpkgs/main.go similarity index 99% rename from lisp/scanpkgs/main.go rename to scanpkgs/main.go index 575a699..1fd3a76 100644 --- a/lisp/scanpkgs/main.go +++ b/scanpkgs/main.go @@ -33,7 +33,7 @@ type item struct { } func main() { - fmt.Println("package lisp") + fmt.Println("package main") // find AR(1) findAr()