From 946976f66db4e5d8b4b996e77db7a22710963a10 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Fri, 3 Nov 2023 21:47:58 +0600 Subject: [PATCH] wip(builder): fix compile errs after moving to building the whole thing (multi-module builds) --- CONTRIBUTING.md | 20 +++- cmd/interpreter/main.go | 9 +- cmd/lsp/main.go | 11 +- go.mod | 21 +++- go.sum | 127 +++++++++++++++++++-- internal/builder/builder.go | 101 ++++++++++++++--- internal/builder/builder_test.go | 165 +++++++++++++++------------- internal/compiler/compiler.go | 14 +-- internal/compiler/src/src.go | 7 +- internal/interpreter/interpreter.go | 10 +- 10 files changed, 361 insertions(+), 124 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cee33ab2..734329eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ Issues must only be created for known bugs and understandable architecture issue ## VSCode Extension -Check out [tygo.yaml](./tygo.yaml). It depends on types defined in the `src` and `ts` packages and thus it's dangerous to rename those types. If you gonna do so make sure you don't brake TS types generation. +Check out [tygo.yaml](./tygo.yaml). It depends on types defined in the `src` and `typesystem` packages and thus it's dangerous to rename those types. If you gonna do so make sure you don't brake TS types generation. Check [web/CONTRIBUTING.md](./web/CONTRIBUTING.md). # Naming conventions @@ -49,8 +49,11 @@ Use `_` instead of space in for test-case names because go turns spaces into und ## FBP/DataFlow -- [Flow-Based Programming: A New Approach to Application Development](https://jpaulmorrison.com/fbp/1stedchaps.html) +- [Elements of Dataflow and Reactive Programming Systems](https://youtu.be/iFlT93wakVo?feature=shared) +- [The origins of Flow Based Programming with J Paul Morrison](https://youtu.be/up2yhNTsaDs?feature=shared) - [Dataflow and Reactive Programming Systems: A Practical Guide](https://www.amazon.com/Dataflow-Reactive-Programming-Systems-Practical/dp/1497422442) +- [Flow-Based Programming: A New Approach to Application Development](https://jpaulmorrison.com/fbp/1stedchaps.html) +- [Samuel Smith - "Flow Based Programming"](https://youtu.be/j3cP8uwf5YM?feature=shared) ## Golang @@ -92,6 +95,7 @@ Use `_` instead of space in for test-case names because go turns spaces into und - [Syntax Highlighter](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide) - [LSP Overview](https://microsoft.github.io/language-server-protocol/) - [Go library for LSP implementation](https://github.com/tliron/glsp) +- [LSP official docs](https://microsoft.github.io/language-server-protocol/) ## Subjective Recommendations @@ -102,6 +106,8 @@ Use `_` instead of space in for test-case names because go turns spaces into und - ["Propositions as Types" by Philip Wadler](https://youtu.be/IOiZatlZtGU?feature=shared) - ["Outperforming Imperative with Pure Functional Languages" by Richard Feldman](https://youtu.be/vzfy4EKwG_Y?feature=shared) - ["What Is a Strange Loop and What is it Like To Be One?" by Douglas Hofstadter (2013)](https://youtu.be/UT5CxsyKwxg?feature=shared) +- ["The Economics of Programming Languages" by Evan Czaplicki (Strange Loop 2023)](https://youtu.be/XZ3w_jec1v8?feature=shared) +- [Why Isn't Functional Programming the Norm? – Richard Feldman](https://youtu.be/QyJZzq0v7Z4?feature=shared) ### Books And Articles @@ -111,6 +117,16 @@ Use `_` instead of space in for test-case names because go turns spaces into und - [Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems](https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321) - [Code: The Hidden Language of Computer Hardware and Software](https://www.amazon.com/Code-Language-Computer-Hardware-Software/dp/0735611319) +### Other + +- [Go By Example](https://gobyexample.com/) +- Roadmaps: + - [Computer Science](https://roadmap.sh/computer-science) + - [Algorithms](https://neetcode.io/roadmap) + - [System Design](https://roadmap.sh/system-design) + - [Software Design Architecture](https://roadmap.sh/software-design-architecture) + - [Backend](https://roadmap.sh/backend) + # Community Here you can find help diff --git a/cmd/interpreter/main.go b/cmd/interpreter/main.go index ea992129..430d6933 100644 --- a/cmd/interpreter/main.go +++ b/cmd/interpreter/main.go @@ -49,8 +49,9 @@ func main() { // compiler analyzer := analyzer.MustNew(resolver) irgen := irgen.New() + p := parser.MustNew(false) comp := compiler.New( - parser.MustNew(false), + p, analyzer, irgen, ) @@ -60,7 +61,11 @@ func main() { comp, proto.NewAdapter(), runTime, - builder.MustNew("/Users/emil/projects/neva/std"), + builder.MustNew( + "/Users/emil/projects/neva/std", + "/Users/emil/projects/neva/thirdparty", + p, + ), ) path, err := filepath.Abs(os.Args[1]) diff --git a/cmd/lsp/main.go b/cmd/lsp/main.go index 165f0ddb..7ff268c5 100644 --- a/cmd/lsp/main.go +++ b/cmd/lsp/main.go @@ -38,11 +38,13 @@ type Indexer struct { type analyzerMessage string func (i Indexer) index(ctx context.Context, path string) (src.Module, analyzerMessage, error) { - rawMod, err := i.builder.BuildModule(ctx, path) + build, err := i.builder.Build(ctx, path) if err != nil { return src.Module{}, "", fmt.Errorf("builder: %w", err) } + rawMod := build.Modules[build.EntryModule] // TODO use all mods + parsedPkgs, err := i.parser.ParsePackages(ctx, rawMod.Packages) if err != nil { return src.Module{}, "", fmt.Errorf("parse prog: %w", err) @@ -77,11 +79,14 @@ func main() { //nolint:funlen commonlog.Configure(verbosity, nil) logger := commonlog.GetLoggerf("%s.server", serverName) + // parser + p := parser.MustNew(*isDebug) + // compiler terminator := typesystem.Terminator{} checker := typesystem.MustNewSubtypeChecker(terminator) resolver := typesystem.MustNewResolver(typesystem.Validator{}, checker, terminator) - builder := builder.MustNew("/Users/emil/projects/neva/std") + builder := builder.MustNew("/Users/emil/projects/neva/std", "/Users/emil/projects/neva/third_party/", p) // handler and server h := &protocol.Handler{} @@ -92,7 +97,7 @@ func main() { //nolint:funlen version: "0.0.1", indexer: Indexer{ builder: builder, - parser: parser.MustNew(*isDebug), + parser: p, analyzer: analyzer.MustNew(resolver), }, mod: make(chan src.Module), diff --git a/go.mod b/go.mod index caf5a1be..bdc9ce09 100644 --- a/go.mod +++ b/go.mod @@ -8,29 +8,48 @@ require ( ) require ( + github.com/go-git/go-git/v5 v5.6.1 github.com/tliron/commonlog v0.1.0 google.golang.org/protobuf v1.31.0 ) require ( + github.com/Microsoft/go-winio v0.6.0 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect + github.com/acomagu/bufpipe v1.0.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/cloudflare/circl v1.1.0 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/go-git/gcfg v1.5.0 // indirect + github.com/go-git/go-billy/v5 v5.4.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/iancoleman/strcase v0.2.0 // indirect + github.com/imdario/mergo v0.3.13 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect github.com/muesli/termenv v0.15.1 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect + github.com/sergi/go-diff v1.1.0 // indirect + github.com/skeema/knownhosts v1.1.0 // indirect github.com/sourcegraph/jsonrpc2 v0.2.0 // indirect github.com/tliron/kutil v0.1.68 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.8.0 // indirect + golang.org/x/mod v0.9.0 // indirect + golang.org/x/net v0.9.0 // indirect golang.org/x/sys v0.8.0 // indirect golang.org/x/term v0.7.0 // indirect + golang.org/x/tools v0.7.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect ) require ( @@ -40,5 +59,5 @@ require ( github.com/tliron/glsp v0.2.0 golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc golang.org/x/sync v0.3.0 - gopkg.in/yaml.v3 v3.0.1 // indirect + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 2ac435c6..7e5b065e 100644 --- a/go.sum +++ b/go.sum @@ -1,36 +1,79 @@ -github.com/99designs/gqlgen v0.17.39/go.mod h1:b62q1USk82GYIVjC60h02YguAZLqYZtvWml8KkhJps4= -github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= +github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= +github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= +github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= +github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= -github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cloudflare/circl v1.1.0 h1:bZgT/A+cikZnKIwn7xL2OBj012Bmvho/o6RpRvv3GKY= +github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= +github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= +github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4= +github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= +github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= +github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= +github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= +github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= +github.com/go-git/go-git-fixtures/v4 v4.3.1 h1:y5z6dd3qi8Hl+stezc8p3JxDkoTRqMAlKnXHuzrfjTQ= +github.com/go-git/go-git-fixtures/v4 v4.3.1/go.mod h1:8LHG1a3SRW71ettAD/jW13h8c6AqjVSeL11RAdgaqpo= +github.com/go-git/go-git/v5 v5.6.1 h1:q4ZRqQl4pR/ZJHc1L5CFjGA1a10u76aV1iC+nh+bHsk= +github.com/go-git/go-git/v5 v5.6.1/go.mod h1:mvyoL6Unz0PiTQrGQfSfiLFhBH1c1e84ylC2MDs4ee8= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= +github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= +github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= +github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= +github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mmcloughlin/avo v0.5.0/go.mod h1:ChHFdoV7ql95Wi7vuq2YT1bwCJqiWdZrQ1im3VujLYM= github.com/muesli/termenv v0.15.1 h1:UzuTb/+hhlBugQz28rpzey4ZuKcZ03MeKsoG7IJZIxs= github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -39,13 +82,20 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= -github.com/sosodev/duration v1.1.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0= +github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXijpFO6roag= github.com/sourcegraph/jsonrpc2 v0.2.0 h1:KjN/dC4fP6aN9030MZCJs9WQbTOjWHhrtKVpzzSrr/U= github.com/sourcegraph/jsonrpc2 v0.2.0/go.mod h1:ZafdZgk/axhT1cvZAPOhw+95nz2I/Ra5qMlU4gTRwIo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= @@ -56,42 +106,94 @@ github.com/tliron/glsp v0.2.0 h1:zhBD0wDVVqlpuPYtjmhIXI/8W5KQewPjaS4SYRevKYQ= github.com/tliron/glsp v0.2.0/go.mod h1:lQDXPfht/Um/FJLthIpGyXclyKq7uVUolignlAyK66Q= github.com/tliron/kutil v0.1.68 h1:CFq9ZgiZvtA4HiRZ47wBV98JxDMlB1cgbehCnJsBytM= github.com/tliron/kutil v0.1.68/go.mod h1:iQTTw/mzWWgpYi2Y9agD/uHPZXf1metD3ilrr9H4I68= -github.com/vektah/gqlparser/v2 v2.5.10/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc= github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/arch v0.1.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU= golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= +golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= +golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -99,8 +201,17 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/internal/builder/builder.go b/internal/builder/builder.go index d5dc21c3..2ab84260 100644 --- a/internal/builder/builder.go +++ b/internal/builder/builder.go @@ -7,33 +7,106 @@ import ( "path/filepath" "strings" + git "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" + "github.com/nevalang/neva/internal/compiler" - "github.com/nevalang/neva/internal/compiler/src" + "github.com/nevalang/neva/internal/compiler/parser" ) type Builder struct { - stdLibPath string + stdlibLocation string // path to standart library module + thirdPartyLocation string // path to third-party modules + parser parser.Parser // parser is needed to parse manifest files } -func (r Builder) BuildModule(ctx context.Context, workdir string) (compiler.RawModule, error) { - prog := map[string]compiler.RawPackage{} +func (b Builder) Build(ctx context.Context, workdir string) (compiler.Build, error) { + // build user module + mods := map[string]compiler.RawModule{} + entryMod, err := b.buildModule(ctx, workdir, mods) + if err != nil { + return compiler.Build{}, fmt.Errorf("build entry mod: %w", err) + } + mods["entry"] = entryMod - // read all packages in working directory recursively - if err := walk(workdir, prog); err != nil { - return compiler.RawModule{}, fmt.Errorf("walk: %w", err) + // build stdlib module + stdMod, err := b.buildModule(ctx, b.stdlibLocation, mods) + if err != nil { + return compiler.Build{}, fmt.Errorf("build entry mod: %w", err) + } + mods["std"] = stdMod + + return compiler.Build{ + EntryModule: "entry", + Modules: mods, + }, nil +} + +func (b Builder) buildModule( + ctx context.Context, + workdir string, + mods map[string]compiler.RawModule, +) (compiler.RawModule, error) { + rawManifest, err := readManifestYaml(workdir) + if err != nil { + return compiler.RawModule{}, fmt.Errorf("read manifest yaml: %w", err) + } + + manifest, err := b.parser.ParseManifest(rawManifest) + if err != nil { + return compiler.RawModule{}, fmt.Errorf("parse manifest: %w", err) + } + + // process module deps (download if needed and build) + for name, dep := range manifest.Deps { + depPath := fmt.Sprintf("%s/%s_%s", b.thirdPartyLocation, dep.Addr, dep.Version) + if _, err := os.Stat(depPath); err != nil { // check if directory with this dependency exists + if os.IsNotExist(err) { // if not, clone the repo + if _, err := git.PlainClone(depPath, false, &git.CloneOptions{ + URL: fmt.Sprintf("https://%s", dep.Addr), + ReferenceName: plumbing.NewTagReferenceName(dep.Version), + }); err != nil { + return compiler.RawModule{}, err + } + } else { // if it's an unknown error then return + return compiler.RawModule{}, fmt.Errorf("os stat: %w", err) + } + } + + rawMod, err := b.buildModule(ctx, depPath, mods) + if err != nil { + return compiler.RawModule{}, fmt.Errorf("build module: %v: %w", name, err) + } + + mods[name] = rawMod } - // read all packages in stdlib directory recursively - if err := walk(r.stdLibPath, prog); err != nil { + pkgs := map[string]compiler.RawPackage{} + + if err := walk(workdir, pkgs); err != nil { return compiler.RawModule{}, fmt.Errorf("walk: %w", err) } return compiler.RawModule{ - Manifest: src.Manifest{}, // TODO - Packages: map[string]compiler.RawPackage{}, + Manifest: manifest, + Packages: pkgs, }, nil } +func readManifestYaml(workdir string) ([]byte, error) { + rawManifest, err := os.ReadFile(workdir + "/neva.yml") + if err == nil { + return rawManifest, nil + } + + rawManifest, err = os.ReadFile(workdir + "/neva.yaml") + if err != nil { + return nil, fmt.Errorf("os read file: %w", err) + } + + return rawManifest, nil +} + // walk recursively traverses the directory assuming that is a neva module (set of packages with source code files). func walk(rootPath string, prog map[string]compiler.RawPackage) error { if err := filepath.Walk(rootPath, func(filePath string, info os.FileInfo, err error) error { @@ -76,8 +149,10 @@ func getPkgName(rootPath, filePath string) string { return strings.TrimPrefix(dirPath, rootPath+"/") } -func MustNew(stdPkgPath string) Builder { +func MustNew(stdPkgPath, thirdPartyLocation string, parser parser.Parser) Builder { return Builder{ - stdLibPath: stdPkgPath, + stdlibLocation: stdPkgPath, + thirdPartyLocation: thirdPartyLocation, + parser: parser, } } diff --git a/internal/builder/builder_test.go b/internal/builder/builder_test.go index 1aa4e0a7..164e0600 100644 --- a/internal/builder/builder_test.go +++ b/internal/builder/builder_test.go @@ -1,71 +1,117 @@ -package builder +package builder_test import ( + "context" "os" "path/filepath" "testing" + "github.com/nevalang/neva/internal/builder" "github.com/nevalang/neva/internal/compiler" + "github.com/nevalang/neva/internal/compiler/parser" + "github.com/nevalang/neva/internal/compiler/src" "github.com/stretchr/testify/require" + "golang.org/x/exp/maps" + "gopkg.in/yaml.v3" ) -func Test_walk(t *testing.T) { - require.NoError(t, setup()) - t.Cleanup(teardown(t)) +func Test_Build(t *testing.T) { + // === SETUP === + wd, err := os.Getwd() + require.NoError(t, err) + tmpPath := filepath.Join(wd, "tmp") + + manifest := src.Manifest{ + Compiler: "0.0.1", + Deps: map[string]src.Dependency{ + "github.com/nevalang/x": { + Addr: "github.com/nevalang/x", // this repo must be available throughout the network + Version: "0.0.1", // this tag must exist in the repo + }, + }, + } - actual := map[string]compiler.RawPackage{} - require.NoError(t, walk("tmp", actual)) + files := map[string][]string{ + "foo": {"1.neva", "2.neva"}, + "foo/bar": {"3.neva"}, + "baz": {"4.neva"}, + } - // []byte len=0; cap=512 -> default value for empty file - expected := map[string]compiler.RawPackage{ - "foo": { - "1": make([]byte, 0, 512), - "2": make([]byte, 0, 512), - }, - "foo/bar": { - "3": make([]byte, 0, 512), - }, - "baz": { - "4": make([]byte, 0, 512), + err = createMod(manifest, files, tmpPath) + require.NoError(t, err) + + // === TEARDOWN === + t.Cleanup(func() { + if err := os.RemoveAll(tmpPath); err != nil { + t.Fatal(err) + } + }) + + // === TEST === + builder := builder.MustNew( + "/Users/emil/projects/neva/std", + "/Users/emil/projects/neva/thirdparty", + parser.MustNew(false), + ) + + actualBuild, err := builder.Build(context.Background(), tmpPath) + require.NoError(t, err) + + expectedBuild := compiler.Build{ + EntryModule: "entry", + Modules: map[string]compiler.RawModule{ + "entry": { + Manifest: manifest, + // []byte len=0; cap=512 -> default value for empty file + Packages: map[string]compiler.RawPackage{ + "foo": { + "1": make([]byte, 0, 512), + "2": make([]byte, 0, 512), + }, + "foo/bar": { + "3": make([]byte, 0, 512), + }, + "baz": { + "4": make([]byte, 0, 512), + }, + }, + }, }, } - require.Equal(t, expected, actual) + require.Equal(t, expectedBuild, actualBuild) } -func createFile(path string, filename string) error { - fullPath := filepath.Join(path, filename) - file, err := os.Create(fullPath) - if err != nil { +func createMod(manifest src.Manifest, files map[string][]string, path string) error { + if err := os.MkdirAll(path, 0755); err != nil { //nolint:gofumpt return err } - defer file.Close() - return nil -} -func setup() error { - wd, err := os.Getwd() + if err := createFile(path, "neva.yml"); err != nil { + return err + } + + manifestPath := filepath.Join(path, "neva.yml") + + rawManifest, err := yaml.Marshal(manifest) if err != nil { return err } - dirs := []string{"tmp/foo", "tmp/foo/bar", "tmp/baz"} - for _, dir := range dirs { - dirPath := filepath.Join(wd, dir) + if err := os.WriteFile(manifestPath, rawManifest, 0644); err != nil { //nolint:gofumpt + return err + } + + for _, dir := range maps.Keys(files) { + dirPath := filepath.Join(path, dir) if err := os.MkdirAll(dirPath, 0755); err != nil { //nolint:gofumpt return err } } - files := map[string][]string{ - "tmp/foo": {"1.neva", "2.neva"}, - "tmp/foo/bar": {"3.neva"}, - "tmp/baz": {"4.neva"}, - } - for dir, files := range files { for _, fileName := range files { - filePath := filepath.Join(wd, dir) + filePath := filepath.Join(path, dir) if err := createFile(filePath, fileName); err != nil { return err } @@ -75,43 +121,12 @@ func setup() error { return nil } -func teardown(t *testing.T) func() { - return func() { - wd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - - files := []string{ - "tmp/foo/1.neva", - "tmp/foo/2.neva", - "tmp/foo/bar/3.neva", - "tmp/baz/4.neva", - } - - for _, file := range files { - filePath := filepath.Join(wd, file) - if err := os.Remove(filePath); err != nil { - t.Fatal(err) - } - } - - dirs := []string{ - "tmp/foo/bar", - "tmp/foo", - "tmp/baz", - } - - for _, dir := range dirs { - dirPath := filepath.Join(wd, dir) - if err := os.RemoveAll(dirPath); err != nil { - t.Fatal(err) - } - } - - tmpDirPath := filepath.Join(wd, "tmp") - if err := os.RemoveAll(tmpDirPath); err != nil { - t.Fatal(err) - } +func createFile(path string, filename string) error { + fullPath := filepath.Join(path, filename) + file, err := os.Create(fullPath) + if err != nil { + return err } + defer file.Close() + return nil } diff --git a/internal/compiler/compiler.go b/internal/compiler/compiler.go index ab4d2adb..f96298cb 100644 --- a/internal/compiler/compiler.go +++ b/internal/compiler/compiler.go @@ -15,11 +15,9 @@ type Compiler struct { } type ( - // Compilation context - Context struct { - MainModule string // Name of the module containing main package - MainPkg string // Name of the executable package in the main module - Modules map[string]RawModule // Set of all modules including both the main module and all its deps + Build struct { + EntryModule string + Modules map[string]RawModule } RawModule struct { @@ -42,8 +40,8 @@ type ( } ) -func (c Compiler) Compile(ctx context.Context, compilerCtx Context) (*ir.Program, error) { - rawMod := compilerCtx.Modules[compilerCtx.MainModule] // TODO support multimodule compilation +func (c Compiler) Compile(ctx context.Context, build Build, mainPkg string) (*ir.Program, error) { + rawMod := build.Modules[build.EntryModule] // TODO support multimodule compilation parsedPackages, err := c.parser.ParsePackages(ctx, rawMod.Packages) if err != nil { @@ -55,7 +53,7 @@ func (c Compiler) Compile(ctx context.Context, compilerCtx Context) (*ir.Program Packages: parsedPackages, } - analyzedProg, err := c.analyzer.AnalyzeExecutable(mod, compilerCtx.MainPkg) + analyzedProg, err := c.analyzer.AnalyzeExecutable(mod, mainPkg) if err != nil { return nil, fmt.Errorf("analyzer: %w", err) } diff --git a/internal/compiler/src/src.go b/internal/compiler/src/src.go index 7e0ce8c9..97e8d3a4 100644 --- a/internal/compiler/src/src.go +++ b/internal/compiler/src/src.go @@ -14,13 +14,12 @@ type Module struct { } type Manifest struct { - CompilerVersion string `json:"compilerVersion,omitempty" yaml:"compilerVersion,omitempty"` - Dependencies map[string]Dependency `json:"deps,omitempty" yaml:"deps,omitempty"` + Compiler string `json:"compiler,omitempty" yaml:"compiler,omitempty"` // want compiler version + Deps map[string]Dependency `json:"deps,omitempty" yaml:"deps,omitempty"` // third-party modules } type Dependency struct { - Name string `json:"name,omitempty"` - Repo string `json:"repo,omitempty"` + Addr string `json:"addr,omitempty"` // e.g. "github.com/nevalang/x" Version string `json:"version,omitempty"` } diff --git a/internal/interpreter/interpreter.go b/internal/interpreter/interpreter.go index fbe98d78..69eb93ae 100644 --- a/internal/interpreter/interpreter.go +++ b/internal/interpreter/interpreter.go @@ -18,18 +18,12 @@ type Interpreter struct { } func (i Interpreter) Interpret(ctx context.Context, pathToMainPkg string) (int, error) { - rawMod, err := i.builder.BuildModule(ctx, pathToMainPkg) + build, err := i.builder.Build(ctx, pathToMainPkg) if err != nil { return 0, fmt.Errorf("build: %w", err) } - irProg, err := i.compiler.Compile(ctx, compiler.Context{ - MainModule: "", - MainPkg: pathToMainPkg, - Modules: map[string]compiler.RawModule{ - "": rawMod, // TODO name? - }, - }) + irProg, err := i.compiler.Compile(ctx, build, pathToMainPkg) if err != nil { return 0, err }