~mna/snow unlisted

ad37f0ee9f399d38cac940eb0ca94f16f3e71ef1 — Martin Angers 1 year, 5 months ago
initial attempt
2 files changed, 64 insertions(+), 0 deletions(-)

A syntax/overview.snow
A  => README.md +6 -0
@@ 1,6 @@
# snow - a small, natively compiled, statically-typed programming language

* Use qbe as initial backend
* Small number of orthogonal concepts
* Developer-friendly, fun to work with
* Little magic

A  => syntax/overview.snow +58 -0
@@ 1,58 @@
# `mod` defines the current module name.
# A module is the namespace for the symbols defined inside it,
# and must be used to reference such a symbol when imported in
# a different module.
mod example

# `import` imports a module. If the import path is a valid identifier,
# it may be specified without quotes; otherwise, the import path is
# specified in quotes and resolved based on the compiler's module
# search path.
import http, json, "github.com/some3rdparty/other"

# This is a single-line comment. There is no multiline comment.

# `var` declares a (mutable) variable. Top-level variables are global to the
# module.
var s str

# A block can be started after most keywords (`var`, `let`, `import`,
# `type`, etc.) and the included statements all have that keyword apply, so the
# following declares 4 variables.
var {
  x i8
  y i32
  z u64
  b bool

# `let` declares a read-only "variable" or constant. It must be assigned
# before use, and can only be assigned once.
let pi = 3.1415

# Primitive types are the usual suspects:
# u8, u16, u32, u64 => unsigned integers
# i8, i16, i32, i64 => signed integers
# f32, f64 => floating-point numbers
# bool => boolean (true, false)

# The array is a built-in aggregate data type. It holds values of the same type.
var ar [4]u8 = [1, 2, 3, 4]

# The struct is another built-in aggregate data type. It holds a pre-defined number
# of values of possibly different types. A new data type is introduced by the
# `type` keyword.
type Person struct {
  # fields of a struct can be mutable or not.
  var age i8
  let id u32

  # methods are defined by implementing a function inside the struct block.
  # There is an implicit `self` argument, but it is seldom required to type
  # because unknown variables are automatically resolved by looking at the
  # struct fields.
  fn print() {
    printf("person: {}, age {}", id, age)