Aug 13, 2022Kuina-chan

1Kuin Statements And Blocks
Statement Name Statement Contents Block Name Identifier(...) Block Contents end Block Name |
- var n: int
-
- func f(x: float)
- var y: float
- end func
Name | Classification | Description |
---|---|---|
alias | Statement | Type Alias Definition |
assert | Statement | Assertion |
break | Statement | Exit Block |
const | Statement | Constant Definition |
do | Statement | Execute Expression |
excode | Statement | Direct Writing Of Post-compilation Code |
include | Statement | Include Separate File |
ret | Statement | Exit Function |
skip | Statement | Skip Loop Once |
throw | Statement | Raising Exception |
var | Statement | Variable Definition |
block | Block | Basic Block |
class | Block | Class Definition |
enum | Block | Enum Definition |
for | Block | Counting Loop |
func | Block | Function Definition |
if | Block | Conditional Branch |
switch | Block | Branching By Value |
try | Block | Exception Handling |
while | Block | Conditional Loop |
Reason For The Design
The reason for specifying the block name in the end of block "end block name" is for readability reasons, as it is difficult to tell which block it corresponds to when there are many end of block symbols in a row, such as "}" in C or "end" in Pascal.
As with type checking at compile time, it is better for the compiler to check if the code is what the user intended to reduce bugs, so I let the user specify the block name and check the correspondence at compile time, even if it is a bit verbose.
The syntax "end block name" comes from Visual Basic.
2alias Statement
alias New Type Name: Existing Type Name |
3assert Statement
assert Conditional Expression |
4break Statement
break Block Identifier |
- It exits the process of block block, for block, if block, switch block, try block, and while block with the specified identifier.
- Exiting the block process means jumping to the position immediately after the end of the block.
Reason For The Design
In many languages, only the closest block can be exited, so exiting a multiple loop required a roundabout way of adding a flag variable. This is why I have made it possible to specify the identifier of the exiting block in Kuin.
In Kuin, many blocks, including if blocks, can be exited with a break statement, so to avoid confusion over which block to exit, I decided that the identifier could not be omitted.
5const Statement
const Constant Name: Type Name :: Value |
- Defined constants are replaced with values at compile time and do not consume memory at run time.
- The value specified in the const statement must be Compile-time Constant.
6do Statement
do Expression |
- The last operation to be evaluated must have side effects.
Reason For The Design
The reason for requiring the do syntax for the execution of a simple expression is to improve readability and compilation speed by enforcing a consistent rule that the meaning of the operation must be indicated at the beginning of the line.
However, since the execution of the expression is written with high frequency, I kept it to two characters to minimize the number of types as much as possible.
7excode Statement
excode String Value |
8include Statement
include Part Of The File Name |
9ret Statement
ret ret Return Value |
- If the process exits from a function that specifies the type of the return value without using the ret statement, the default value of the type will be returned as the return value.
Reason For The Design
In many languages it is "return", but in x86 assembly the abbreviation "ret" is used, and I adopted the shorter form.
10skip Statement
skip Block Identifier |
- It skips one loop of the for and while blocks for the specified identifier.
- Skipping the loop of a block means jumping to just before the end of that block.
Reason For The Design
In many languages it is "continue", but since it is long and cumbersome to type, I decided on "skip".
11throw Statement
throw Exception Code |
Reason For The Design
Many languages allow users to inherit exception classes to perform advanced exception handling, but this is often cumbersome and not used properly, so I decided to focus on exception codes that are easy to handle practically.
12var Statement
13block Block
block Processing end block block Block Name Processing end block |
14class Block
15enum Block
16for Block
for(Initial Value, Last Value) Processing end for for Block Name(Initial Value, Last Value) Processing end for for(Initial Value, Last Value, Increase/Decrease Value) Processing end for |
- The initial value, last value, and increase/decrease value must all be int.
- The increase/decrease value must be Compile-time Constant and a non-zero value.
- The count value of the for block can be obtained by referring to the block name as an int variable.
- The condition to repeat the loop is "count value<=last value" when "increase/decrease value>0", and "count value>=last value" when "increase/decrease value<0".
- The expressions specified by the initial value, last value, and increase/decrease value are evaluated just before entering the for block, and are not re-evaluated during the repeated loop.
Reason For The Design
In many languages, for requires the user to specify variables for the initial, last, and increase/decrease values, and specifying the wrong variables could lead to bugs, so I designed Kuin to be simpler and more focused on counting.
This makes it impossible to do things like increase by 2 as in other languages, but I think that while should be used for such complex operations.
17func Block
18if Block
if(Condition) Processing end if if Block Name(Condition) Processing end if if(Condition 1) Processing elif(Condition 2) Processing elif(Condition 3) Processing else Processing end if |
- The conditions must be bool.
- Evaluate the expressions for the conditions in turn, and if any of the conditions become true, execute the contents and exit the block.
- If none of the conditions are true, the contents of the else clause will be executed. If there is no else clause at this point, exit the block without doing anything.
- If the condition is Compile-time Constant and therefore the process that is always executed (the contents of if, elif, or else) is determined to be one, the if block is replaced with a block block, and the process that is never executed is deleted at compile time.
Reason For The Design
elif is an abbreviation for the so-called else if used in some languages such as Python.
19switch Block
switch(Value To Be Compared) case Value 1 Processing case Value 2 Processing end switch switch Block Name(Value To Be Compared) case Value 1 Processing case Value 2 Processing end switch switch(Value To Be Compared) case Value 1, Value 2 Processing case Lower Limit Of Value 3 to Upper Limit Of Value 3 Processing end switch switch(Value To Be Compared) case Value 1 Processing case Value 2 Processing default Processing end switch |
- The value must be of a type that allows comparison between large and small.
- There must be at least one case clause.
- It checks if there is a case that matches the value to be compared, and if there is, executes its contents and exits the block.
- If it matches more than one case, the first written case is adopted.
- If it does not match any case, the contents of the default clause are executed. If there is no default clause at this time, exit the block without doing anything.
- When the block name is referenced as if it were a variable, the value to be compared is returned in that type.
Reason For The Design
In C and other languages, if you don't write break at the end of a case, the process will go into the next case, but there are few situations where you want the process to go into the next case, and it is easy to cause bugs. So I designed Kuin to automatically exit the block without a break.
Instead, I have enriched the way we write conditions in the case clause so that we can write the same process for multiple values.
20try Block
try Processing catch Processing end try try Block Name Processing catch Processing end try try Processing catch Exception Code 1, Exception Code 2 Processing catch Lower Limit Of Exception Code to Upper Limit Of Exception Code Processing end try try Processing finally Processing end try try Processing catch Processing finally Processing end try |
- At least one of the catch and finally clauses must exist.
- It checks if there is a catch that matches the exception code of the exception that occurred, and if there is, executes its contents and exits the block.
- If it matches more than one catch, the first written catch is adopted.
- The finally clause is always executed just before exiting the block, regardless of whether the catch clause has been executed or not.
- If no exception code in any catch clause corresponds to the exception when it is raised, the exception will recur immediately after the block is exited.
- Do not use ret, break, skip, etc. within a finally clause to leave its own try block. This is because the exception that was raised will be dropped without recurrence and the process will continue.
- When the block name is referenced as a variable, the exception code is returned as int.
21while Block
while(Condition) Processing end while while Block Name(Condition) Processing end while while(Condition, skip) Processing end while |
Reason For The Design
This skip is equivalent to the do-while in C and other languages.