Introduction to Zinc

Zinc is a low level language between assembler, C and C++ with a syntax somewhat similar to Ruby.

Main Features

Low Level

The goal is to have a portable assembler. The compiler won't generate a lot of complex code from a simple expression in source code. It helps to write small and fast programs.

Every operations are explicits, there is no implicit operations such as conversions or calls to destructors.

All data types manipulated can be handled in a machine register: integers, chars or pointers. It is not possible to pass structures in arguments or return them from functions, they must be passed by pointer.

The language is not object oriented, but inheritance of structures is supported.

Identifiers Can Have Blanks

The most important feature and the most unusual.

If you consider that an identifier follows this regular expression [_A-Za-z][_A-Za-z0-9]*,then just consider that a zinc identifier can be a sequence of one or more identifiers separated by blanks. The grammar of zinc permit this.

e.g.:

OpenWindowWithAttributes(...)
or
open_window_with_attributes(...)
becomes:
open window with attributes (...)

I did this because I hate uppercase characters in the middle of identifiers and I'm too lazy to type shift to get the '_'. In addition, I find it more readable.

Iterators

Iterators are a simplified version of the smalltalk blocks. In fact, it is more similar to ruby's. They allow to enumerates sequence's elements without knowing the implementation. It also reduces the code: an enumeration is done with one operation instead of three (initialization, test end of iteration, advance to next element).

An iterator can invoke a block using the yield statement. This is a simple example, it should remind ruby users of something.

equ loop (start: int, limit: int)
  def i = start
  def n = limit
  while i <= n
    yield (i)
    ++i
  end
end

def sum = 0
loop (1, 10) ? x
  sum += x
end
printf ("%d\n", sum)

Since zinc is a low level language, this feature is implemented with enhanced macro expansion.

Reduces the Need of Explicit Type Definition

The compiler requires to know the type of every expressions but when it can be guessed automatically, it is not necessary to specify it. This applies to:

This feature helps refactoring: changing the type of data requires less change in source code.