Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest version of llir/llvm #24

Merged
merged 15 commits into from
Dec 10, 2018
Merged

Conversation

mewmew
Copy link
Contributor

@mewmew mewmew commented Dec 10, 2018

This is a quite substantial change to Geode as it attempts to make use of an unmodified version of llir/llvm. To accomplish this, two Geode specific types are defined in the new pkg/gtypes package, a Geode struct type and a Geode slice type:

// SliceType type is a Geode slice type.
type SliceType struct {
	// Element type.
	ElemType types.Type

	// A Geode slice type is implemented as an LLVM struct type.
	//    { elem*, length }
	*types.StructType
}

// StructType type is a Geode struct type.
type StructType struct {
	// Field names.
	Names []string

	// A Geode struct type is implemented as an LLVM struct type.
	*types.StructType
}

Whether this is a good fit for Geode is yet to be determined.

The main benefit is that with this approach, Geode would be able to use updates to llir/llvm seamlessly, and all Geode specific features are implemented on top of the LLVM IR agnostic llir/llvm library.

With this PR, the latest version of llir/llvm is used (v0.3.0). All test cases of Geode are passing:

$ geode test
(1)	OKAY after return
(2)	OKAY arithmetic
(3)	OKAY array declaration 1
(4)	OKAY array declaration 2
(5)	OKAY classes 1 (Type Declaration)
(6)	OKAY classes 2 (Assigning and Accessing)
(7)	OKAY fibonacci
(8)	OKAY FizzBuzz
(9)	OKAY For Loops
(10)	OKAY global variables 1
(11)	OKAY global variables 2
(12)	OKAY global variables 3
(13)	OKAY global variables 4
(14)	OKAY Hello world
(15)	OKAY Conditional nesting
(16)	OKAY link
(17)	OKAY Minimal Program
(18)	OKAY Unicode 1: Function Names
(19)	OKAY Unicode 2: Variable Names
(20)	OKAY Unicode 3: String contents
(21)	OKAY unknown types 1
(22)	OKAY unknown types 2
(23)	OKAY while
->	23/23 (100%) tests ran successfully

This PR fixes #22 and superseeds PR #23.

Note: after this commit has been merged, the llvm subdirectory of the Geode repository may be removed, as the upstream llir/llvm repo is used unmodified. Also, a go.mod file has been added to track the specific versions of dependencies.

Also, use util.StdLibDir() in ast.SearchPaths instead of
hardcoded /usr/local/lib/geodelib.

After this commit, it is possible to use
relative paths for the standard library:

	$ export GEODELIB=./lib/
	$ geode test
	Total: 23 / 23 tests ran succesfully
This was done automatically, using the following script:

	find . -type f -name '*.go' | xargs -I '{}' sar -i "github.com/geode-lang/geode/llvm/" "github.com/llir/llvm/" '{}'

Where the sar tool is from the https://github.com/mewkiz/cmd repo,
and may be installed as follows:

	go get github.com/mewkiz/cmd/sar
This is to avoid confusion with the ir/types package.
Set the name of the comment pseudo-instruction to "nop" to
avoid it being unnamed, and thus increasing the local ID
counter.
Since ir.NewGetElementPtr is unaware of Geode types,
introduce an indirection through the ast.gep function
which only present the underlying LLVM IR element type
to ir.NewGetElementPtr.

Note, this is note the prettiest approach, but seems
to work. I'd be glad to discuss alternatives that may
be cleaner than this.
Test test cases are now passing.

	$ geode test
	->	23/23 (100%) tests ran succesfully
@mewmew
Copy link
Contributor Author

mewmew commented Dec 10, 2018

@nickwanninger Thanks a lot for releasing Geode! I've had a lot of fun playing around with it, and feel I've learned a lot by reading the code you wrote. Going through the code base of Geode and updating it to make use of the latest version of llir/llvm, also helped uncover a regression of the llir API with regards to usability, which has since been addressed in llir/llvm@cba8644

If you notice anything else that feels strange or quirky, please let us know. We definitely want to improve the API of llir/llvm to be more generally useful for anyone writing compilers, interpreters, static code analysis tools, etc.

Wish you all the best and hope you'll have a most lovely winter!

Cheerful regards from Sweden,
Robin

@nickwanninger
Copy link
Collaborator

Amazing work Robin. I really appreciate the feedback and I'm glad my code helped you get your project in a better state! Thanks a bunch!

@nickwanninger nickwanninger merged commit 39df3ac into geode-lang:master Dec 10, 2018
mewmew added a commit to mewpull/geode that referenced this pull request Dec 30, 2019
As part of PR geode-lang#24, Geode switched to using an unmodified version of
llir/llvm, as such the old copy of llvm is no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

build error: pkg/lexer/Token.go:12:2: cannot find package "github.com/geode-lang/geode/pkg/debug"
2 participants