This commit is contained in:
Nicolas Kruse 2025-10-18 23:20:34 +02:00
commit f594bacf7b
3 changed files with 52 additions and 16 deletions

View File

@ -58,13 +58,11 @@ jobs:
python tools/make_example.py python tools/make_example.py
python tools/extract_code.py "bin/test.copapy" "bin/test.copapy.bin" python tools/extract_code.py "bin/test.copapy" "bin/test.copapy.bin"
objdump -D -b binary -m i386:x86-64 --adjust-vma=0x1000 bin/test.copapy.bin > bin/test.copapy.asm objdump -D -b binary -m i386:x86-64 --adjust-vma=0x1000 bin/test.copapy.bin > bin/test.copapy.asm
echo '<p>test.copapy.asm</p><pre>' >> $GITHUB_STEP_SUMMARY echo '<p>test.copapy.asm</p>' >> $GITHUB_STEP_SUMMARY
cat bin/test.copapy.asm >> $GITHUB_STEP_SUMMARY python tools/clean_asm.py bin/test.copapy.asm >> $GITHUB_STEP_SUMMARY
echo '</pre>' >> $GITHUB_STEP_SUMMARY objdump -d -x src/copapy/obj/stencils_x86_64_O3.o > bin/stencils_x86_64_O3.asm
objdump -d -j .text src/copapy/obj/stencils_x86_64_O3.o > bin/stencils_x86_64_O3.asm echo '<p>stencils_x86_64_O3.asm</p>' >> $GITHUB_STEP_SUMMARY
echo '<p>stencils_x86_64_O3.asm</p><pre>' >> $GITHUB_STEP_SUMMARY python tools/clean_asm.py bin/stencils_x86_64_O3.asm >> $GITHUB_STEP_SUMMARY
cat bin/stencils_x86_64_O3.asm >> $GITHUB_STEP_SUMMARY
echo '</pre>' >> $GITHUB_STEP_SUMMARY
- name: Run tests with pytest - name: Run tests with pytest
run: pytest run: pytest

View File

@ -5,20 +5,22 @@ Development is in a very early stage. Only very few components are in a working
# Introduction # Introduction
Copapy is a copy and patch based compiler. It compiles a python based language to machine code. The language can be considered as an embedded language. It uses the python interpreter for generating a directed graph of variables and operations. The compiler generates machine code by composing pre-compiled stencils derived from C code with gcc -O3. Copapy is a python based embedded domain specific language (eDSL) with a copy & patch compiler. It compiles to machine code. It uses the python interpreter for compilation. It generates a directed graph of variables and operations. The compiler generates machine code by composing pre-compiled stencils derived from C code with gcc -O3.
For code execution a runner executable receives the composed machine code, data and patch instructions. The patch instructions are used to correct memory address offsets. For code execution a executable or library receives the composed machine code, data and patch instructions. The patch instructions are used to correct memory address offsets.
The Project targets applications that profit from fast implementation (e.g. prototyping) and require realtime with low latency as well as minimizing risk of implementation errors reaching runtime. This applies primarily for applications interfacing hardware, where runtime errors might lead to physical damage. The Project targets applications that profit from fast implementation (e.g. prototyping) and require realtime with low latency as well as minimizing risk of implementation errors not cached during compile time. This applies primarily for applications interfacing hardware, where runtime errors might lead to physical damage. For example robotics, embedded systems and control systems.
The project aims to be: The language aims to be:
- Type save - Fast to write
- Having turing completeness only during compile time - Easy to read
- Predictable runtime - Type safe
- No software runtime errors - Having a predictable runtime
- Turing-complete only during compile time
- No runtime errors
- Immutable types - Immutable types
# Structure # How it works
## Compilation ## Compilation
The Compilation step starts with the directed graph of variables and operations generated by the python interpreter. The Compilation step starts with the directed graph of variables and operations generated by the python interpreter.

36
tools/clean_asm.py Normal file
View File

@ -0,0 +1,36 @@
import argparse
import re
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("path", type=str, help="Input file path")
args = parser.parse_args()
regex = r"(\:\n)(.*?)(^[^\n]+\n[^\n]+result_.*?\n\n)"
subst = "\\g<1><b>\\g<2></b><i>\\g<3></i>"
with open(args.path, 'rt') as f:
text = f.read()
outp_flag = "Disassembly of section .text" not in text
text = text.replace('\t', ' ' * 4)
text = text.replace('>', '&gt;')
text = text.replace('<', '&lt;')
text = re.sub(regex, subst, text, 0, re.MULTILINE | re.DOTALL)
text = re.sub(r"(?<= ) ", "&nbsp;", text, 0, re.MULTILINE | re.DOTALL)
print('<code>')
for line in text.splitlines():
if outp_flag:
print(line + '<br>')
if "Disassembly of section .text:" in line:
outp_flag = True
print('</code>')
if __name__ == "__main__":
main()