diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/BytecodeHeader.md | 8 | ||||
-rw-r--r-- | doc/CompilerFlow.md | 6 | ||||
-rw-r--r-- | doc/Documentation.md | 31 | ||||
-rw-r--r-- | doc/Opcode.md | 14 | ||||
-rwxr-xr-x | doc/doc_extract.py | 20 |
5 files changed, 47 insertions, 32 deletions
diff --git a/doc/BytecodeHeader.md b/doc/BytecodeHeader.md deleted file mode 100644 index 684a5ef..0000000 --- a/doc/BytecodeHeader.md +++ /dev/null @@ -1,8 +0,0 @@ -# Header layout -|Size|Name |Description | -|----|-------------|----------------------------------------------------------------------------| -|4 |Magic number |The magic number used to identify an amalgam bytecode file. | -|1 |Major version|The major version of the bytecode. Updates in this is a breaking change. | -|1 |Minor version|The minor version of the bytecode. Updates in this are backwards compatible.| -|1 |Patch version|The patch version of the bytecode. Updates in this are only minor bug fixes.| -The versions in the header only changes for every release, not every change.
\ No newline at end of file diff --git a/doc/CompilerFlow.md b/doc/CompilerFlow.md deleted file mode 100644 index e42b94d..0000000 --- a/doc/CompilerFlow.md +++ /dev/null @@ -1,6 +0,0 @@ -# Compiler flow -(Tokenize&parse -> Resolve AST -> Generate SSA -> Generate bytecode) -> Generate program\ -Each step except the last is done using multiple threads in parallel and the output of each step is used -in the next step. The last step is not done in parallel because the last step is combining all bytecode -and writing it to a file, which is an IO bottlenecked operation and it won't benefit from multithreading -and may even lose performance because of it.
\ No newline at end of file diff --git a/doc/Documentation.md b/doc/Documentation.md new file mode 100644 index 0000000..34d1b41 --- /dev/null +++ b/doc/Documentation.md @@ -0,0 +1,31 @@ +# Opcode +Variable length opcodes. Sizes range from 1 to 4 bytes. +## Instruction formats +Instructions can be in 6 different formats: +1. 1 byte: Opcode +2. 2 bytes: Opcode + register +3. 3 bytes: Opcode + register + register +4. 3 bytes:\ +4.1 Opcode + intermediate\ +4.2 Opcode + data\ +4.3 Opcode + index\ +4.4 Opcode + offset +5. 4 bytes: Opcode + register + register + register +6. 4 bytes: Opcode + register + offset + +# Compiler flow +(Tokenize&parse -> Resolve AST -> Generate SSA -> Generate bytecode) -> Generate program\ +Each step except the last is done using multiple threads in parallel and the output of each step is used +in the next step. The last step is not done in parallel because the last step is combining all bytecode +and writing it to a file, which is an IO bottlenecked operation and it won't benefit from multithreading +and may even lose performance because of it. + +# Bytecode header +## Header layout +|Size|Name |Description | +|----|-------------|----------------------------------------------------------------------------| +|4 |Magic number |The magic number used to identify an amalgam bytecode file. | +|1 |Major version|The major version of the bytecode. Updates in this is a breaking change. | +|1 |Minor version|The minor version of the bytecode. Updates in this are backwards compatible.| +|1 |Patch version|The patch version of the bytecode. Updates in this are only minor bug fixes.| +The versions in the header only changes for every release, not every change.
\ No newline at end of file diff --git a/doc/Opcode.md b/doc/Opcode.md deleted file mode 100644 index 37fa4e2..0000000 --- a/doc/Opcode.md +++ /dev/null @@ -1,14 +0,0 @@ -# Opcode -Variable length opcodes. Sizes range from 1 to 4 bytes. -# Instruction formats -Instructions can be in 6 different formats: -1. 1 byte: Opcode -2. 2 bytes: Opcode + register -3. 3 bytes: Opcode + register + register -4. 3 bytes:\ -4.1 Opcode + intermediate\ -4.2 Opcode + data\ -4.3 Opcode + index\ -4.4 Opcode + offset -5. 4 bytes: Opcode + register + register + register -6. 4 bytes: Opcode + register + offset
\ No newline at end of file diff --git a/doc/doc_extract.py b/doc/doc_extract.py index 66ec7e5..ce192cb 100755 --- a/doc/doc_extract.py +++ b/doc/doc_extract.py @@ -55,6 +55,14 @@ def extract_docs(filepath): docs.append((doc_name, lstrip_lines(doc))) return docs +def convert_to_subsections(doc_str): + lines = [] + for line in doc_str.splitlines(): + if len(line) != 0 and line[0] == "#": + line = "##" + line[1:] + lines.append(line) + return "\n".join(lines) + def main(): script_path = os.path.realpath(sys.argv[0]) script_dir = os.path.dirname(script_path) @@ -64,13 +72,17 @@ def main(): source_files = get_source_files_recursive(amalgam_includes) source_files += get_source_files_recursive(amalgam_sources) + doc_data = [] for filepath in source_files: docs = extract_docs(filepath) for doc in docs: - doc_path = os.path.join(script_dir, doc[0] + ".md") - with open(doc_path, "w") as file: - file.write(doc[1]) - print("Wrote doc for %s into file %s" % (doc[0], doc_path)) + section = "# {}\n{}".format(doc[0], convert_to_subsections(doc[1])) + doc_data.append(section) + print("Added section %s to the documentation" % doc[0]) + + doc_path = os.path.join(script_dir, "Documentation.md") + with open(doc_path, "w") as file: + file.write("\n\n".join(doc_data)) if __name__ == "__main__": main() |