Contachit
Page Navigation
-
The = symbol, means "equal". There's no such thing as == in the Contachit language. The = symbol is only used to compare
if two things are equal, and NOT used for assignments.
-
There are two assignment operators.
-
The # symbol, is used to assign values.
-
The -> symbol, is used to inform a pointer WHAT it points to.
-
There are 3 different types of variables.
-
Automatic variables. These are NOT pointers, and their memory is considered to always exist while
it's in scope, and is automatically deleted when the scope is existed.
-
Pointer variables. These can ONLY point to other 'pointer' variables (or null), and ALWAYS own the
memory they point to (if any).
-
View_Pointer variables. These pointers can point to any other kind of pointer ('pointer' or 'view_pointer'), in addition to null, but
they NEVER actually own the memory they point to (if any).
-
Contachit uses keyword object, instead of class. Also, member access is always done via the '.' operator,
and never the '->' operator (which has a different meaning in Contachit).
-
In Contachit, the keywords function and method refer to different things (and they are NOT interchangable).
-
A function is the typical stand alone function.
-
A method is a function, which belongs to an object.
-
Comments are "first-class" members of the language. Objects, functions, methods and constructors have "required" comments. If you don't
create one of these required comments, Contachit will generate a parse error. This helps enforce code documentation.
-
Keyword 'new' does NOT mean "heap memory" is being created. All it means is a new object of any kind of memory (stack or heap) is
created. The type of memory created, depends on if '#' or '->' was used in declaration/assignment.
-
No need to end statements with ';' character.
Keyword bool
Notes
-
Variables of this type, can have the value true or false.
Keyword String
Notes
-
Notice of future change: Currently, the C++ translation of this data type uses "Glib::ustring", which is a UTF-8 enabled
string. However... I've noticed that when running some examples against valgrind (a memory checker for C/C++), it reports back the
possibility of memory leak (which is NOT acceptable), and thus subject to change. The good news, is that I can change the translation,
and replace "Glib::ustring" with something else, without affecting Contachit syntax.
Keywords
int8, int16, int32, int64
uint8, uint16, uint32, uint64
Notes
-
These integers are all hardware based, with fixed number of bits.
-
See the table below, for their respective numerical ranges.
Keywords
real_s
real_m
real_l
Notes
-
These are sometimes called "float" or "double" in other langauges.
-
These real numbers are all hardware based, with fixed number of bits.
-
See the table below, for their respective numerical ranges.
"automatic" variables.
"pointer" variables.
"view pointer" variables.
Notes:
-
value assignment statements use the # operator.
-
Any kind of variable ("automatic", "pointer", or "view pointer"), can be involved in a "value assignment" statement, on either
LHS or RHS of # operator.
-
It's a parse error to use a pointer (of any kind), in a "value assignment", without first verifying it's not null. This
can be done via "if_exists()", or "while_exists()".
"automatic" variables.
"pointer" variables.
"view pointer" variables.
Notes:
-
pointer assignment statements use the -> operator.
It's an arrow, which indicates "LHS variable refers to memory of RHS". This is a totally different meaning than in
C++, where it's used for class member access.
-
Memory Management among "pointer" and "view pointer" is unique to Contachit (as far as I'm aware). It
allows natively compiled code, to have automatic memory management, but without "garbage collection", or even "smart pointers".
-
New memory is created anytime a "pointer" variable points to:
- Literal value. For example, 7, true, false, 3.14, "Hello World".
- Constructor call, like "new abc::Robot( "Virginia" )".
-
The keyword 'new' is ONLY used in constructor calls, and not with literals.
-
Rules, for the different kind of variables, and what they can point to are;
- automatic variables are NEVER involved in a "pointer assignment" (either LHS or RHS).
- pointer variables, can ONLY point to other "pointer" variables, 'null', or '?'.
-
view pointer variables are more restrictive in their use. They are ONLY allowed to be used when absolutely necessary. The
rules for what they can point to are;
- Point to 'null'.
- Point to '?', when declaring a variable that belongs to an object.
- Point to formal parameter (assuming the LHS "view pointer" variable belongs to an object).
- Point to the result of a method call (assuming the return type of that method is a "view pointer").
Existing 'pointer' variable, referring to new memory.
Existing 'pointer' variable, referring to another 'pointer' variable.
'view pointer' variables, refering to 'pointer' variable.
Notes:
The 7 different kinds of "if" statements.
The 7 different kinds of "while" statements.
-
A function is the stand alone computational unit you're used to. Don't confuse it with method which
is basically a function that belongs to an object. These two terms are NOT interchangeable, and if I mention one or
the other, I'm being very specific.
-
Because Contachit code is contained in a single file (unlike C++, which has .h and .cpp), there's no separation of the function declaration and definition.
-
The order in which you write your functions does not matter. For example, in a single file, if you have two functions, and one function calls another, but
the function being called was not parsed yet, this is OK, as the parser will perform such validation after the entire file was parsed. The same principle
applies to objects as well.
-
Function Naming Convention (enforced by parser)
- Characters available for function names: [a-z0-9_] (Might be expanded in future)
- Examples of valid function names: "foo", "foo_bar", "foo7"
- Examples of in-valid function names: "Foo", "foo_", "7foo"
-
If you call a function, and it's return type is not void, their MUST be a LHS variable which receives the value returned. It's a parse error if
the return value is not handled.
-
Keyword function, and it's options.
-
Mandatory function comment.
-
Fake function.
-
Contachit uses the keyword object, rather than "class".
-
Member Access
-
Available access levels: public, private
Note: "private" in Contachit, is the same as "protected" in C++.
-
Anything that is "private" (variable or method) MUST have it's name prefixed with "_" character. For example, a private variable, could
be named "_x", and a private method could be named "_foo()".
-
Member access is ALWAYS performed using the '.' operator, unlike C++ which uses both '.' and '->'.
-
Object Naming Convention (enforced by parser)
- Characters available for object names: [a-zA-Z0-9_] (Might be expanded in future)
- The name MUST start out with capital letter, and if '_' is used, the letter following must also be capitalized.
- Examples of valid object names: "Foo", "Foo_Bar", "Foo7"
-
Examples of in-valid object names: "foo", "Foo_bar", "7Foo"
-
An object will have (in this order);
- [0..n] private variables
- [1..n] public constructors
- [0..n] methods (public or private)
-
Keyword object, and it's options.
-
Mandatory object comment.
-
Object with variable and methods.
-
Const object.
-
A method can be thought of as a function which belongs to an object. There are a few differences though.
-
Methods will have an access specifier of public or private.
-
Methods can access the object's variables and methods (even private ones), via the keyword this.
-
Method Naming Convention (enforced by parser)
- Characters available for method names: [a-z0-9_] (Might be expanded in future)
- Examples of valid method names: "foo", "foo_bar", "foo7", "_foo" (if private)
-
Examples of in-valid method names: "Foo", "foo_", "7foo"
-
If you call a method, and it's return type is not void, their MUST be a LHS variable which receives the value returned. It's a parse error if
the return value is not handled.
-
Keyword method, and it's options.
-
Mandatory method comment.
© 2023 Isaac Benson Powell