Aug 13, 2022Kuina-chan


This is the language specification 11 of Kuin Programming Language, and is about the compiler and the IDE.

1Kuin Compiler

There are two types of Kuin compilers: kuin.exe, which comes with an editor and debugger, and kuincl.exe, which can compile on the command line.

2Compilation Options For kuincl.exe

The compilation options for kuincl.exe are shown in Table 2-1.
Table 2-1: Compilation Options For kuincl.exe
Compilation Option Description Behavior When Omitted
-i file Specify the .kn file to compile. Show help on how to use the compiler.
-o file Specify the .exe file to output. Generate out.exe in the same directory as the .kn file specified by -i.
-s directory Specify the system directory. directory where the compiler is located/sys/
-c file Specify the .ico file to be set as the icon. Default icon.
-p directory Specify the location of the resource directory (/res/). The same directory as the .kn file specified by -i.
-f directory Specify a text file with the related file names. None.
-e execution environment Specify the execution environment. exe (executable file for windows)
-x additional option Additional options defined for each execution environment. None.
-r Do a release build. Do a debug build.
-h Show help on how to use the compiler. None.
-v Show compiler version. None.
-q Suppress output other than errors and warnings. None.
Either option can be omitted. Each compilation option is explained in detail below.

2.1-i



It's an acronym for input. Specify the .kn file where the main function exists.

2.2-o



It's an acronym for output. Specify the executable file to output. If you omit it, an executable file with the name out.exe will be generated in the same directory as the .kn file specified by -i.

2.3-s



It's an acronym for system. Specify the system directory. Usually, you can omit it.

2.4-c



It's the second letter of icon. If you specify an .ico file, that icon will be used for the executable and window icons. If you omit it, the default icon prepared by Kuin will be set.

2.5-p



It's an acronym for pack. Specify the location of the resource directory (/res/). If you omit it, "/res/" will be assumed to exist in the same directory as the .kn file specified by -i.

2.6-f



It's an acronym for files. Specify a text file with the related file names to be copied in the output directory.
Write the contents of the text file one line at a time, repeating "full path of the source file" and "relative path of the destination file from the destination directory".

2.7-e



It's an acronym for environment. Specify the execution environment shown in Table 2-2. If you omit it, it is regarded as "-e exe".
Table 2-2: Execution Environment
Compilation Option Execution Environment
-e exe Generate an executable file for Windows.
-e cpp Generate source code for C++.
-e web Generate HTML and JavaScript that can be executed in a web browser.
The specified value can be referenced in the program as a []char type using 'env("e")'. For example, if you specify "-e exe," you can write 'env("e")' in the program to get the value of '"exe"' as a constant.

2.8-x



It's an acronym for extra. Specify the additional options defined for each execution environment specified by -e. You can specify more than one of them (Table 2-3).
Table 2-3: Additional Options
-e Specification Compilation Option Description
Any Specification -x binary (Use of this function is prohibited during implementation.)
Any Specification -x hint Generate hint information for Kuin Editor (advanced feature).
exe -x dbgbreak To make it easier for the debugger to attach, a breakpoint exception (INT3) is raised after a message box is displayed immediately after the program starts.
exe -x pause Valid only when "-x wnd" is not specified. Execute the "pause" command at the end of the program (advanced feature).
exe -x wnd Make it a window application. If omitted, it becomes a console application.
cpp -x lib Generate an entry point for the library.
cpp -x nogc Disable garbage collection (GC) and release the allocated heap at the end of the program.
cpp -x nogcdb Valid only when "-x nogc" is specified. Double-buffering the heap (advanced feature).
web -x merge Merge the generated HTML and JavaScript into a single HTML for output.
web -x static Allow JavaScript to be executed by an external call instead of being executed immediately.
Users are free to create their own compilation options. The specified value can be referenced in the program as a []char type using "env()". For example, if you specify "-x option", you can write 'env("option")' in the program to get the value of '"true"' as a constant. As you can see, '"true"' will be returned if the option is defined, and the empty string '""' will be returned if it is not defined.
You can also specify the value of a compile option, as in "-x option=abc". In this case, the value of '"abc"' can be obtained as a constant by writing 'env("option")' in the program.

2.9-r



It's an acronym for release. If this option is specified, a release build will be performed; if it is omitted, a debug build will be performed.
The specified value can be referenced as a bool type from the dbg constant in the program. If you specify "-r", you can get the value of false by writing "dbg" in the program. If you do not specify "-r", then dbg will be true.

2.10-h



It's an acronym for help. This option will show you how to use kuincl.exe.

2.11-v



It's an acronym for version. This option will display the compiler version.

2.12-q



It's an acronym for quiet. This option suppresses all output except errors and warnings. Specify this option if you do not want to output anything as a log when the process succeeds.

3Compile-time Specification

The following is a summary of the compile-time specification of Kuin.

3.1Special Specification For Input File



The special specification of the file to be compiled is shown in Figure 3-1.
  • If none of the characters exist in the specified .kn, the program will output "Hello, world!"
  • If only one character "q" is written in the specified .kn, it will be a Quine program that outputs "q" (a program that outputs its own source code).
  • If only one letter f is written in the specified .kn, it will be a Fizz Buzz program.
  • If only the single letter "9" is written in the specified .kn, the program will output the lyrics of the nursery rhyme 99 Bottles of Beer.
  • For these, it is also acceptable to add a single newline to the end of the file. However, no more newlines, spaces, or other characters must be included in the file.
Figure 3-1: Special Specification For Input File
Reason For The Design

Since these programs are written so much more frequently than other programs, I thought the Kuin compiler should meet that demand.

3.2Difference Between Debug Build And Release Build



The difference between a debug build and a release build is shown in Table 3-1.
Table 3-1: Difference Between Debug Build And Release Build
Matter Debug Build Release Build
Usage Use routinely during development. Use only once upon completion.
Optimization No optimization, prioritize compilation speed. Optimize and prioritize execution speed.
Encryption Pack For Resource Data None Encryption packing.
Value Of dbg Constant dbg will be true. dbg will be false.
assert Check for assertions at runtime. Remove assert statements.
Array Out-of-range Access Check Raising an exception for out-of-range access. Do not check for out-of-range access.
Many other exceptions raised by the standard library and built-in functions will not be raised at release build time.
In general, development is done in a flow where a debugging build with fast compilation is used for careful verification, and a release build is used to generate files for distribution upon completion.

3.3Execution Environment Details



The environment in which the executable generated by the compiler runs is shown in Table 3-2.
Table 3-2: Execution Environment Details
Execution Environment Details
-e exe -x wnd A window application that runs on Windows 7 or later (Windows 10, etc.) in a 64-bit environment and can utilize graphics functions.
-e exe A console application that runs on Windows 7 or later (Windows 10, etc.) in a 64-bit environment and runs on the command prompt.
-e cpp C++ source code that can be built with Visual C++, g++, clang++, etc.
-e web HTML and JavaScript source code that runs on web browsers such as Chrome, Firefox, Edge, and Internet Explorer 11.
1660383059enf