Skip to content
Nick Wanninger edited this page Aug 28, 2018 · 4 revisions

Introduction

Geode is a work in progress, compiled, llvm langauge C written in go. It's primary goal is to build on C's type system with things like unknown types, type classes and more but still maintain a level of interoperability with pure C.

Installing

Installing Geode is simple, just follow the steps below and install a few dependencies

Dependencies

  • Golang with a $GOPATH setup in your env
  • The clang c compiler for linking binaries
  • make

Building

Once you have the dependencies setup, building is easy:

$ go get -u -d github.com/geode-lang/geode/...
$ cd $GOPATH/src/github.com/geode-lang/geode
$ make
$ sudo make install

This will build and install geode's executable binary to /usr/local/bin

Your first program

Create a file main.g

# main.g
is main
include "std:io"
func main int {
	io:print("Hello, World");
	return 0;
}

Running geode main.g will compile the program and run it. If things have been setup correctly, you should see the message printed to your screen.

Program Structure

Every Geode program is layed out in a similar manner to go. When you include a file, you are actually including the containing folder. include "foo/bar.g" includes all geode source files in ./foo/. All files are imported even if they don't share a package name.

Packages

A geode code package can be thought of in a similar way to c++'s namespaces. They exist purely to group code into packages to limit scope polution.

In every geode file, the first non-comment expression must be the is expression. This is how package names are set in a file. Package names are file global, so once you declare the package it cannot be changed in a single file. If you need another package name, create either more files, or new folders to house packages. If you wanted to declare a file as package foo, you would simply put is foo at the top of the file. Now, when other files include that directory and all of it's files, they will access foo functions/types/variables by prefixing all accesses with foo:. For example: foo:bar();

Includes

In order to include another geode library or package into a program, simply use the include expression. This is different from the C include, as it intelligently declares the headers for you - no more .h files. Once you include a file, all adjacent files will be includes as well, along with their namespaces. Including standard library packages has a slightly different syntax include "std:io" will include the standard io: package into the current file and allow access to functions relating to printing, files, etc...

Functions

Geode functions have several different syntaxes. The most simple function is quite typical:

func main int {
	return 0;
}

You'll notice that if a function takes no arguments, you can omit the parenthesis from the function declaration.

This function can be even further simplified with the explicit return syntax:

func main int -> 0;

This is simply syntactic sugar on top of the normal function syntax.

Function arguments are simple and typical, but can be used in a powerful way which will be seen later on.

is foo
func bar(int a, byte c, int* d) {
	# ...
}

Once Declared, a function is bound to the package that the file is bound to. In the above example, the function defined will be bound to foo:bar(...).

Function Calls

Function calls behave in the exact way you'd expect. foo(1, 2, 3) in the package main will make a call to main:foo() with 3 integer arguments. If you want to make a function call outside of the current package, simply prepend the name of the package. with a colon. io:print(...) for example, is the binding to C's printf function