Documentation
Introduction
This is the initial design document for the Cu language. At this stage, it summarizes the philosophy and proposed syntax, and is not a formal language specification. Before starting implementation, ambiguities in syntax, type rules, error handling, and execution model need to be finalized.
Design Philosophy
Three principles serve as the criteria for design decisions.
- Accessibility: Aiming for a language that is easy to learn and supports a wide range of developers and applications.
- Performance: Pursuing execution speed and memory usage from the language specification and runtime design stage.
- Control: Aiming to enable necessary control considering the characteristics of the execution environment and hardware.
Basic Syntax (Draft)
The following are under consideration. Not all are finalized or implemented.
File Format
main.cu29
Directives
#mode
#apply
Standard Output
Io.print(none: str = "Hello, World!")
Variable Declaration and Initialization
x: int = 1
name: str = "Cu"
pi: float = 3.14
enabled: bool = True
Candidate basic types: int (integer), float (floating-point), str (string), bool (boolean)
Reassignment
x: int = 1
x = 3
x += 1
Direct Value Specification with none
Io.print(none: str = "Cu")
Under consideration. Not confirmed to have the same meaning as None/null in other languages.
Function Definition
fnc: int = init() {
Io.print(none: str = "a")
return none: int = 0
}
Multiple Return Values
fnc: (int, str) = get_values() {
return none: int = 10, none: str = "Cu"
}
a, b = get_values()
Conditional Branching
if: pro = x == 0 {
Io.print(none: str = "x is 0!")
} elif: pro = x == 1 {
Io.print(none: str = "x is 1!")
} else {
Io.print(none: str = "x isn't 0 or 1!")
}
Loop: for
for: pro = 5 {
Io.print(none: str = "Hello")
}
Loop: while
while: pro = x == 0 {
Io.print(none: str = "x is 0")
}
while: pro = True {
Io.print(none: str = "Running")
}
Loop Control
break
continue
Operators and Multi-line Expressions
result: int = 10 + 20
value: int = result * 2
result: int = 10 +
20
Specification Status
| Item | Status |
|---|---|
| Language name Cu | Confirmed |
| Extension .cu29 | Confirmed |
| Initial implementation in Python | Policy |
| No classes in initial spec | Policy |
| APC three principles | Content confirmed |
| Syntax for variables, functions, conditionals | Draft |
| Meaning of none | Needs definition |
| Precise meaning of pro | Needs definition |
| Type system | Needs design |
| Memory management | Needs design |
| Compilation / execution model | Needs design |
| RTOS / hardware control features | Future consideration |
Important: This is currently an initial design document summarizing the philosophy and syntax proposals of Cu, not a formal language specification.
Cu Language