Skip to content

Getting started

There are no packaged releases yet, so build am from source:

Terminal window
git clone https://github.com/itisrazza/amethyst.git
cd amethyst
dotnet build

Then make the am command available by adding an alias to your shell profile, pointing at your clone:

Terminal window
alias am='dotnet run --no-build --project ~/amethyst/src/Amethyst.Compiler.Cli --'

Tradition demands it, and who are we to argue with tradition. Programs start at a top-level main method. Create hello.am:

hello.am
def main: Void
puts "Hello, world!"
end

Compile and run it in one step:

Terminal window
am run hello.am
Hello, world!
greeter.am
class Greeter
property name: String
def initialize(name: String): Void
@name = name
end
def greet: Void
puts "Hi, #{name}!"
end
end
def main: Void
Greeter.new("Ada").greet
end
  • property name: String declares the @name instance variable with a getter and a setter. See Classes.
  • initialize is the constructor, called by Greeter.new.
  • "Hi, #{name}!" interpolates; inside the class, name reads the property.
  • Parentheses are optional when a method takes no arguments.
Terminal window
am run greeter.am
Hi, Ada!

am check lexes, parses and type-checks a file without compiling it. It’s a pessimist, so that production can be an optimist:

oops.am
def main: Void
var count: Int = "three"
end
Terminal window
am check oops.am
oops.am:2:3: error [AM3002] Type mismatch: expected 'Int', got 'String'

Diagnostic codes tell you which stage reported the problem:

Codes Stage
AM1xxx Lexer
AM2xxx Parser
AM3xxx Type checker
AM4xxx Code generation

am build compiles to a .NET assembly next to the source file, along with the runtimeconfig.json that dotnet needs to run it:

Terminal window
am build hello.am # writes hello.dll
am build hello.am -o app.dll # or choose the output path
dotnet hello.dll

Congratulations: you’ve written .NET without opening Visual Studio. Treat yourself.