From 8eb9ebf9b762c487420f39f72520634663c43747 Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Wed, 3 Mar 2021 05:53:47 -0500 Subject: [PATCH 01/60] First commit Major Changes: Fill team information --- .github/workflows/tests.yml | 166 +-- .gitignore | 820 ++++++------- LICENSE | 42 +- Readme.md | 344 +++--- doc/Readme.md | 66 +- doc/team.yml | 18 +- requirements.txt | 4 +- src/Readme.md | 156 +-- src/coolc.sh | 22 +- src/makefile | 24 +- tests/codegen/arith.cl | 860 ++++++------- tests/codegen/arith_input.txt | 26 +- tests/codegen/arith_output.txt | 316 ++--- tests/codegen/atoi_output.txt | 2 +- tests/codegen/book_list.cl | 264 ++-- tests/codegen/book_list_output.txt | 14 +- tests/codegen/cells.cl | 194 +-- tests/codegen/cells_output.txt | 42 +- tests/codegen/complex.cl | 104 +- tests/codegen/complex_output.txt | 2 +- tests/codegen/fib.cl | 58 +- tests/codegen/fib_input.txt | 2 +- tests/codegen/fib_output.txt | 4 +- tests/codegen/graph.cl | 762 ++++++------ tests/codegen/graph_input.txt | 10 +- tests/codegen/graph_output.txt | 14 +- tests/codegen/hairyscary.cl | 134 +- tests/codegen/hello_world.cl | 10 +- tests/codegen/hello_world_output.txt | 2 +- tests/codegen/io.cl | 206 ++-- tests/codegen/io_output.txt | 10 +- tests/codegen/life.cl | 872 ++++++------- tests/codegen/life_input.txt | 130 +- tests/codegen/life_output.txt | 1554 ++++++++++++------------ tests/codegen/list_output.txt | 10 +- tests/codegen/new_complex.cl | 158 +-- tests/codegen/new_complex_output.txt | 4 +- tests/codegen/palindrome.cl | 50 +- tests/codegen/palindrome_input.txt | 2 +- tests/codegen/palindrome_output.txt | 4 +- tests/codegen/primes_output.txt | 192 +-- tests/codegen/print-cool_output.txt | 2 +- tests/codegen/sort-list_input.txt | 2 +- tests/codegen/sort-list_output.txt | 20 +- tests/codegen_test.py | 32 +- tests/conftest.py | 10 +- tests/lexer/comment1.cl | 108 +- tests/lexer/comment1_error.txt | 2 +- tests/lexer/iis1.cl | 220 ++-- tests/lexer/iis1_error.txt | 2 +- tests/lexer/iis2.cl | 238 ++-- tests/lexer/iis2_error.txt | 2 +- tests/lexer/iis3.cl | 240 ++-- tests/lexer/iis3_error.txt | 2 +- tests/lexer/iis4.cl | 238 ++-- tests/lexer/iis4_error.txt | 2 +- tests/lexer/iis5.cl | 242 ++-- tests/lexer/iis5_error.txt | 4 +- tests/lexer/iis6.cl | 248 ++-- tests/lexer/iis6_error.txt | 2 +- tests/lexer/mixed1.cl | 26 +- tests/lexer/mixed1_error.txt | 2 +- tests/lexer/mixed2.cl | 38 +- tests/lexer/mixed2_error.txt | 6 +- tests/lexer/string1.cl | 10 +- tests/lexer/string1_error.txt | 2 +- tests/lexer/string2.cl | 36 +- tests/lexer/string4.cl | 74 +- tests/lexer/string4_error.txt | 4 +- tests/lexer_test.py | 24 +- tests/parser/assignment1.cl | 72 +- tests/parser/assignment2.cl | 72 +- tests/parser/assignment3.cl | 72 +- tests/parser/attribute1.cl | 66 +- tests/parser/attribute2.cl | 66 +- tests/parser/attribute3.cl | 66 +- tests/parser/block1.cl | 172 +-- tests/parser/block2.cl | 172 +-- tests/parser/block3.cl | 172 +-- tests/parser/block4.cl | 174 +-- tests/parser/case1.cl | 180 +-- tests/parser/case2.cl | 184 +-- tests/parser/case3.cl | 184 +-- tests/parser/case4.cl | 184 +-- tests/parser/case5.cl | 184 +-- tests/parser/case6.cl | 184 +-- tests/parser/class1.cl | 40 +- tests/parser/class2.cl | 40 +- tests/parser/class3.cl | 68 +- tests/parser/class4.cl | 72 +- tests/parser/class5.cl | 68 +- tests/parser/class6.cl | 68 +- tests/parser/conditional1.cl | 136 +-- tests/parser/conditional2.cl | 136 +-- tests/parser/conditional3.cl | 136 +-- tests/parser/conditional4.cl | 144 +-- tests/parser/conditional5.cl | 144 +-- tests/parser/conditional6.cl | 144 +-- tests/parser/dispatch1.cl | 88 +- tests/parser/dispatch2.cl | 88 +- tests/parser/dispatch3.cl | 88 +- tests/parser/dispatch4.cl | 104 +- tests/parser/dispatch5.cl | 104 +- tests/parser/dispatch6.cl | 112 +- tests/parser/dispatch7.cl | 112 +- tests/parser/dispatch8.cl | 112 +- tests/parser/dispatch9.cl | 120 +- tests/parser/let1.cl | 168 +-- tests/parser/let2.cl | 168 +-- tests/parser/let3.cl | 168 +-- tests/parser/let4.cl | 168 +-- tests/parser/let5.cl | 168 +-- tests/parser/let6.cl | 146 +-- tests/parser/let7.cl | 168 +-- tests/parser/loop1.cl | 154 +-- tests/parser/loop2.cl | 154 +-- tests/parser/loop3.cl | 154 +-- tests/parser/loop4.cl | 154 +-- tests/parser/method1.cl | 66 +- tests/parser/method2.cl | 66 +- tests/parser/method3.cl | 66 +- tests/parser/method4.cl | 66 +- tests/parser/method5.cl | 66 +- tests/parser/method6.cl | 64 +- tests/parser/mixed1.cl | 198 +-- tests/parser/mixed2.cl | 28 +- tests/parser/mixed3.cl | 80 +- tests/parser/mixed4.cl | 42 +- tests/parser/mixed5.cl | 40 +- tests/parser/mixed6.cl | 10 +- tests/parser/operation1.cl | 200 +-- tests/parser/operation2.cl | 200 +-- tests/parser/operation3.cl | 200 +-- tests/parser/operation4.cl | 200 +-- tests/parser/program2.cl | 40 +- tests/parser/program3.cl | 48 +- tests/parser_test.py | 24 +- tests/semantic/arithmetic1.cl | 20 +- tests/semantic/arithmetic10.cl | 28 +- tests/semantic/arithmetic11.cl | 26 +- tests/semantic/arithmetic12.cl | 26 +- tests/semantic/arithmetic1_error.txt | 2 +- tests/semantic/arithmetic2.cl | 20 +- tests/semantic/arithmetic2_error.txt | 2 +- tests/semantic/arithmetic3.cl | 20 +- tests/semantic/arithmetic3_error.txt | 2 +- tests/semantic/arithmetic4.cl | 20 +- tests/semantic/arithmetic5.cl | 20 +- tests/semantic/arithmetic5_error.txt | 2 +- tests/semantic/arithmetic6.cl | 22 +- tests/semantic/arithmetic6_error.txt | 2 +- tests/semantic/arithmetic7.cl | 24 +- tests/semantic/arithmetic7_error.txt | 2 +- tests/semantic/arithmetic8.cl | 26 +- tests/semantic/arithmetic8_error.txt | 2 +- tests/semantic/arithmetic9.cl | 28 +- tests/semantic/assignment1.cl | 14 +- tests/semantic/assignment1_error.txt | 2 +- tests/semantic/assignment2.cl | 26 +- tests/semantic/assignment2_error.txt | 2 +- tests/semantic/assignment3.cl | 28 +- tests/semantic/attributes1.cl | 24 +- tests/semantic/attributes1_error.txt | 2 +- tests/semantic/attributes2.cl | 24 +- tests/semantic/attributes2_error.txt | 2 +- tests/semantic/attributes3.cl | 48 +- tests/semantic/attributes3_error.txt | 2 +- tests/semantic/attributes4.cl | 76 +- tests/semantic/basics1.cl | 18 +- tests/semantic/basics1_error.txt | 2 +- tests/semantic/basics2.cl | 18 +- tests/semantic/basics2_error.txt | 2 +- tests/semantic/basics3.cl | 16 +- tests/semantic/basics3_error.txt | 2 +- tests/semantic/basics4.cl | 16 +- tests/semantic/basics4_error.txt | 2 +- tests/semantic/basics5.cl | 16 +- tests/semantic/basics5_error.txt | 2 +- tests/semantic/basics6.cl | 16 +- tests/semantic/basics6_error.txt | 2 +- tests/semantic/basics7.cl | 16 +- tests/semantic/basics7_error.txt | 2 +- tests/semantic/basics8.cl | 16 +- tests/semantic/basics8_error.txt | 2 +- tests/semantic/blocks1.cl | 60 +- tests/semantic/blocks1_error.txt | 2 +- tests/semantic/case1.cl | 46 +- tests/semantic/case1_error.txt | 2 +- tests/semantic/case2.cl | 44 +- tests/semantic/case3.cl | 44 +- tests/semantic/class1.cl | 16 +- tests/semantic/class1_error.txt | 4 +- tests/semantic/conditionals1.cl | 26 +- tests/semantic/conditionals1_error.txt | 2 +- tests/semantic/conditionals2.cl | 48 +- tests/semantic/conditionals2_error.txt | 4 +- tests/semantic/dispatch1.cl | 64 +- tests/semantic/dispatch1_error.txt | 2 +- tests/semantic/dispatch2.cl | 66 +- tests/semantic/dispatch2_error.txt | 2 +- tests/semantic/dispatch3.cl | 70 +- tests/semantic/dispatch3_error.txt | 2 +- tests/semantic/dispatch4.cl | 70 +- tests/semantic/dispatch5.cl | 60 +- tests/semantic/dispatch5_error.txt | 2 +- tests/semantic/dispatch6.cl | 64 +- tests/semantic/dispatch6_error.txt | 2 +- tests/semantic/eq1.cl | 32 +- tests/semantic/eq1_error.txt | 2 +- tests/semantic/eq2.cl | 34 +- tests/semantic/eq2_error.txt | 2 +- tests/semantic/eq3.cl | 34 +- tests/semantic/eq3_error.txt | 2 +- tests/semantic/eq4.cl | 34 +- tests/semantic/eq4_error.txt | 2 +- tests/semantic/isvoid1.cl | 50 +- tests/semantic/isvoid1_error.txt | 2 +- tests/semantic/let1.cl | 28 +- tests/semantic/let1_error.txt | 2 +- tests/semantic/let2.cl | 28 +- tests/semantic/let2_error.txt | 2 +- tests/semantic/let3.cl | 28 +- tests/semantic/loops1.cl | 14 +- tests/semantic/loops2.cl | 18 +- tests/semantic/loops2_error.txt | 2 +- tests/semantic/methods1.cl | 22 +- tests/semantic/methods1_error.txt | 2 +- tests/semantic/methods2.cl | 22 +- tests/semantic/methods2_error.txt | 2 +- tests/semantic/methods3.cl | 26 +- tests/semantic/methods3_error.txt | 2 +- tests/semantic/methods4.cl | 36 +- tests/semantic/methods4_error.txt | 2 +- tests/semantic/methods5.cl | 40 +- tests/semantic/methods5_error.txt | 2 +- tests/semantic/methods6.cl | 52 +- tests/semantic/methods6_error.txt | 2 +- tests/semantic/methods7.cl | 22 +- tests/semantic/methods8.cl | 22 +- tests/semantic/new1.cl | 60 +- tests/semantic/self1.cl | 22 +- tests/semantic/self1_error.txt | 2 +- tests/semantic/self2.cl | 20 +- tests/semantic/self2_error.txt | 2 +- tests/semantic/self3.cl | 20 +- tests/semantic/self3_error.txt | 2 +- tests/semantic/self4.cl | 18 +- tests/semantic/self4_error.txt | 2 +- tests/semantic_test.py | 26 +- tests/utils/utils.py | 182 +-- 250 files changed, 9816 insertions(+), 9818 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 62ff3680b..9fb3b7bf2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,83 +1,83 @@ -name: Tests - -on: [push, pull_request] - -jobs: - lexer: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=lexer - - parser: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=parser - - semantic: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=semantic - - codegen: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Install spim - run: sudo apt-get install spim - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=codegen +name: Tests + +on: [push, pull_request] + +jobs: + lexer: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=lexer + + parser: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=parser + + semantic: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=semantic + + codegen: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Install spim + run: sudo apt-get install spim + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=codegen diff --git a/.gitignore b/.gitignore index 4acafde18..0b07f7b23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,410 +1,410 @@ -# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig - -# Created by https://www.gitignore.io/api/visualstudiocode,linux,latex,python -# Edit at https://www.gitignore.io/?templates=visualstudiocode,linux,latex,python - -### LaTeX ### -## Core latex/pdflatex auxiliary files: -*.aux -*.lof -*.log -*.lot -*.fls -*.out -*.toc -*.fmt -*.fot -*.cb -*.cb2 -.*.lb - -## Intermediate documents: -*.dvi -*.xdv -*-converted-to.* -# these rules might exclude image files for figures etc. -# *.ps -# *.eps -# *.pdf - -## Generated if empty string is given at "Please type another file name for output:" -.pdf - -## Bibliography auxiliary files (bibtex/biblatex/biber): -*.bbl -*.bcf -*.blg -*-blx.aux -*-blx.bib -*.run.xml - -## Build tool auxiliary files: -*.fdb_latexmk -*.synctex -*.synctex(busy) -*.synctex.gz -*.synctex.gz(busy) -*.pdfsync - -## Build tool directories for auxiliary files -# latexrun -latex.out/ - -## Auxiliary and intermediate files from other packages: -# algorithms -*.alg -*.loa - -# achemso -acs-*.bib - -# amsthm -*.thm - -# beamer -*.nav -*.pre -*.snm -*.vrb - -# changes -*.soc - -# comment -*.cut - -# cprotect -*.cpt - -# elsarticle (documentclass of Elsevier journals) -*.spl - -# endnotes -*.ent - -# fixme -*.lox - -# feynmf/feynmp -*.mf -*.mp -*.t[1-9] -*.t[1-9][0-9] -*.tfm - -#(r)(e)ledmac/(r)(e)ledpar -*.end -*.?end -*.[1-9] -*.[1-9][0-9] -*.[1-9][0-9][0-9] -*.[1-9]R -*.[1-9][0-9]R -*.[1-9][0-9][0-9]R -*.eledsec[1-9] -*.eledsec[1-9]R -*.eledsec[1-9][0-9] -*.eledsec[1-9][0-9]R -*.eledsec[1-9][0-9][0-9] -*.eledsec[1-9][0-9][0-9]R - -# glossaries -*.acn -*.acr -*.glg -*.glo -*.gls -*.glsdefs - -# uncomment this for glossaries-extra (will ignore makeindex's style files!) -# *.ist - -# gnuplottex -*-gnuplottex-* - -# gregoriotex -*.gaux -*.gtex - -# htlatex -*.4ct -*.4tc -*.idv -*.lg -*.trc -*.xref - -# hyperref -*.brf - -# knitr -*-concordance.tex -# TODO Comment the next line if you want to keep your tikz graphics files -*.tikz -*-tikzDictionary - -# listings -*.lol - -# luatexja-ruby -*.ltjruby - -# makeidx -*.idx -*.ilg -*.ind - -# minitoc -*.maf -*.mlf -*.mlt -*.mtc[0-9]* -*.slf[0-9]* -*.slt[0-9]* -*.stc[0-9]* - -# minted -_minted* -*.pyg - -# morewrites -*.mw - -# nomencl -*.nlg -*.nlo -*.nls - -# pax -*.pax - -# pdfpcnotes -*.pdfpc - -# sagetex -*.sagetex.sage -*.sagetex.py -*.sagetex.scmd - -# scrwfile -*.wrt - -# sympy -*.sout -*.sympy -sympy-plots-for-*.tex/ - -# pdfcomment -*.upa -*.upb - -# pythontex -*.pytxcode -pythontex-files-*/ - -# tcolorbox -*.listing - -# thmtools -*.loe - -# TikZ & PGF -*.dpth -*.md5 -*.auxlock - -# todonotes -*.tdo - -# vhistory -*.hst -*.ver - -# easy-todo -*.lod - -# xcolor -*.xcp - -# xmpincl -*.xmpi - -# xindy -*.xdy - -# xypic precompiled matrices -*.xyc - -# endfloat -*.ttt -*.fff - -# Latexian -TSWLatexianTemp* - -## Editors: -# WinEdt -*.bak -*.sav - -# Texpad -.texpadtmp - -# LyX -*.lyx~ - -# Kile -*.backup - -# KBibTeX -*~[0-9]* - -# auto folder when using emacs and auctex -./auto/* -*.el - -# expex forward references with \gathertags -*-tags.tex - -# standalone packages -*.sta - -### LaTeX Patch ### -# glossaries -*.glstex - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history - -# End of https://www.gitignore.io/api/visualstudiocode,linux,latex,python - -# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) - +# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig + +# Created by https://www.gitignore.io/api/visualstudiocode,linux,latex,python +# Edit at https://www.gitignore.io/?templates=visualstudiocode,linux,latex,python + +### LaTeX ### +## Core latex/pdflatex auxiliary files: +*.aux +*.lof +*.log +*.lot +*.fls +*.out +*.toc +*.fmt +*.fot +*.cb +*.cb2 +.*.lb + +## Intermediate documents: +*.dvi +*.xdv +*-converted-to.* +# these rules might exclude image files for figures etc. +# *.ps +# *.eps +# *.pdf + +## Generated if empty string is given at "Please type another file name for output:" +.pdf + +## Bibliography auxiliary files (bibtex/biblatex/biber): +*.bbl +*.bcf +*.blg +*-blx.aux +*-blx.bib +*.run.xml + +## Build tool auxiliary files: +*.fdb_latexmk +*.synctex +*.synctex(busy) +*.synctex.gz +*.synctex.gz(busy) +*.pdfsync + +## Build tool directories for auxiliary files +# latexrun +latex.out/ + +## Auxiliary and intermediate files from other packages: +# algorithms +*.alg +*.loa + +# achemso +acs-*.bib + +# amsthm +*.thm + +# beamer +*.nav +*.pre +*.snm +*.vrb + +# changes +*.soc + +# comment +*.cut + +# cprotect +*.cpt + +# elsarticle (documentclass of Elsevier journals) +*.spl + +# endnotes +*.ent + +# fixme +*.lox + +# feynmf/feynmp +*.mf +*.mp +*.t[1-9] +*.t[1-9][0-9] +*.tfm + +#(r)(e)ledmac/(r)(e)ledpar +*.end +*.?end +*.[1-9] +*.[1-9][0-9] +*.[1-9][0-9][0-9] +*.[1-9]R +*.[1-9][0-9]R +*.[1-9][0-9][0-9]R +*.eledsec[1-9] +*.eledsec[1-9]R +*.eledsec[1-9][0-9] +*.eledsec[1-9][0-9]R +*.eledsec[1-9][0-9][0-9] +*.eledsec[1-9][0-9][0-9]R + +# glossaries +*.acn +*.acr +*.glg +*.glo +*.gls +*.glsdefs + +# uncomment this for glossaries-extra (will ignore makeindex's style files!) +# *.ist + +# gnuplottex +*-gnuplottex-* + +# gregoriotex +*.gaux +*.gtex + +# htlatex +*.4ct +*.4tc +*.idv +*.lg +*.trc +*.xref + +# hyperref +*.brf + +# knitr +*-concordance.tex +# TODO Comment the next line if you want to keep your tikz graphics files +*.tikz +*-tikzDictionary + +# listings +*.lol + +# luatexja-ruby +*.ltjruby + +# makeidx +*.idx +*.ilg +*.ind + +# minitoc +*.maf +*.mlf +*.mlt +*.mtc[0-9]* +*.slf[0-9]* +*.slt[0-9]* +*.stc[0-9]* + +# minted +_minted* +*.pyg + +# morewrites +*.mw + +# nomencl +*.nlg +*.nlo +*.nls + +# pax +*.pax + +# pdfpcnotes +*.pdfpc + +# sagetex +*.sagetex.sage +*.sagetex.py +*.sagetex.scmd + +# scrwfile +*.wrt + +# sympy +*.sout +*.sympy +sympy-plots-for-*.tex/ + +# pdfcomment +*.upa +*.upb + +# pythontex +*.pytxcode +pythontex-files-*/ + +# tcolorbox +*.listing + +# thmtools +*.loe + +# TikZ & PGF +*.dpth +*.md5 +*.auxlock + +# todonotes +*.tdo + +# vhistory +*.hst +*.ver + +# easy-todo +*.lod + +# xcolor +*.xcp + +# xmpincl +*.xmpi + +# xindy +*.xdy + +# xypic precompiled matrices +*.xyc + +# endfloat +*.ttt +*.fff + +# Latexian +TSWLatexianTemp* + +## Editors: +# WinEdt +*.bak +*.sav + +# Texpad +.texpadtmp + +# LyX +*.lyx~ + +# Kile +*.backup + +# KBibTeX +*~[0-9]* + +# auto folder when using emacs and auctex +./auto/* +*.el + +# expex forward references with \gathertags +*-tags.tex + +# standalone packages +*.sta + +### LaTeX Patch ### +# glossaries +*.glstex + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/visualstudiocode,linux,latex,python + +# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) + diff --git a/LICENSE b/LICENSE index 718bd210a..7f19c2d8c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2021 School of Math and Computer Science, University of Havana - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2021 School of Math and Computer Science, University of Havana + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Readme.md b/Readme.md index a47d48b9e..0e33ddb08 100644 --- a/Readme.md +++ b/Readme.md @@ -1,172 +1,172 @@ -# COOL: Proyecto de Compilación - -> Proyecto base para el compilador de 4to año en Ciencia de la Computación. - -## Generalidades - -La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la -Universidad de La Habana, consiste este curso en la implementación de un compilador completamente -funcional para el lenguaje _COOL_. - -_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. - -## Cómo comenzar (o terminar) - -El proyecto de Compilación será recogido y evaluado **únicamente** a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. A continuación le damos las instrucciones mínimas necesarias para ello: - -### 1. Si no lo han hecho ya, regístrense en [Github](https://github.com) todos los miembros del equipo (es gratis). - -![](img/img1.png) - -### 2. Haga click en el botón **Fork** para hacer una copia del proyecto en el perfil de Github de uno de los miembros. - -Opcionalmente pueden [crear una organización](https://github.com/organizations/new) y copiar el proyecto en el perfil de la misma. - -![](img/img2.png) - -### 3. Una vez hecho esto, tendrá un nuevo repositorio en `github/`. - -Revise que el repositorio de su equipo está en su perfil. -En este ejemplo se ha copiado a la cuenta de `github.com/apiad`. - -Debe indicar bajo el nombre del repositorio: `"forked from matcom/cool-compiler-2021"`. - -![](img/img3.png) - -### 4. Clone este proyecto en un repositorio local. - -Busque la URL de su proyecto en la interfaz web de Github. - -Asegúrese de clonar **su copia** y no el proyecto original en `matcom/cool-compiler-2021`. - -![](img/img4.png) - -```bash -$ git clone git@github.com:/cool-compiler-2021.git -``` - -> Donde `` es posiblemente el nombre de su equipo o del miembro donde se hizo el _fork_. - -A partir de este punto debe tener un proyecto `cool-compiler-2021` local. -El siguiente paso depende de si usted ya tiene su código versionado con `git` o no. - -### 5.A. Si tiene su proyecto en git (y no quiere perder la historia): - -#### 5.1. Mezcle hacia el nuevo respositorio su repositorio anterior: - -```bash -$ cd cool-compiler-2021 -$ git pull --allow-unrelated-histories master -``` - -#### 5.2. Organice su proyecto, código fuente y documentación, de acuerdo a las instrucciones de este documento, y vuelva a hacer `commit`. - -```bash -$ mv src/ -$ git add . -$ git commit -a -m "Mezclado con el proyecto base" -``` - -#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. - -```bash -$ git push origin master -``` - -### 5.B Si aún no tiene su proyecto en git (o no le importa la historia): - -#### 5.1. Simplemente copie el código de su proyecto en la carpeta correspondiente `src` y haga su primer commit. - -```bash -$ mv src/ -$ git commit -a -m "Hello Git!" -``` - -#### 5.2. A partir de este punto asegúrese de hacer `commit` de forma regular para mantener su repositorio actualizado. - -Si necesita saber más sobre `git`, todo lo imprescindible está en [esta guía](doc/github-git-cheat-sheet.pdf). - -#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. - -```bash -$ git push origin master -``` - -## Entregas - -En este proyecto se realizarán entregas parciales a lo largo del curso. Para realizar una entrega, siga los siguientes pasos. - -### 1. Cree un pull request al proyecto original desde su copia. - -![](img/img5.png) - -### 2. Asegúrese de tener la siguiente configuración antes de hacer click en **Create pull request**. - -- **base repository**: `matcom/cool-compiler-2021` (repositorio original) - - **branch**: `master` -- **head repository**: `/cool-compiler-2021` (repositorio propio) - - **branch**: `master` (o la que corresponda) - -> Asegúrese que se indica **Able to merge**. De lo contrario, existen cambios en el repositorio original que usted no tiene, y debe actualizarlos. - -> **NOTA**: Asegúrese que el _pull request_ se hace a la rama `master`. - -![](img/img6.png) - -### 3. Introduzca un título y descripción adecuados, y haga click en **Create pull request**. - -![](img/img7.png) - -### 4. Espere mientras se ejecutan las pruebas. - -Verá la indicación **Some checks haven't completed yet**. - -![](img/img8.png) - -Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje: - -> **This branch is out-of-date with base branch** - -Haga click en **Update branch** y siga las instrucciones. -### 5. Verifique que no hubo errores en las pruebas. - -Si ve el mensaje **(All | Some) checks have failed**, significa que su código no pasó las pruebas. - -![](img/img9.png) - -Para ver los resultados de las pruebas haga click en el link **Details**. - -![](img/img10.png) - - -### 6. Arregle los errores y repita el paso 5 hasta que todas las pruebas pasen. - -Para cualquier modificación que haga a su proyecto, haga _commit_ y _push_ para **su repositorio personal** y automáticamente se actualizará el estado del _pull request_ y se volverán a ejecutar las pruebas. **No es necesario** abrir un _pull request_ nuevo por cada entrega, sino actualizar el anterior. - -> **Por favor asegúrese de mantener un solo _pull request_ activo por equipo**. En caso de abrir uno nuevo, cerrar el anterior. - -## Sobre la implementación - -Ponga todo su código e instrucciones necesarias en la carpeta `src`. Más información en [`src/Readme.md`](src/Readme.md). - -## Sobre la documentación - -Usted debe presentar un reporte escrito documentando el proceso de construcción de su compilador y los detalles más importantes de su funcionamiento. Más información en [`doc/Readme.md`](doc/Readme.md). - -## Sobre los equipos de desarrollo - -Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. - -## Sobre los casos de prueba - -La carpeta `tests` contiene todos los casos de prueba que son obligatorios de pasar para que su proyecto tenga derecho a ser evaluado. - -Estos tests se ejecutan automáticamente cada vez que hace un _pull request_ al repositorio `matcom/cool-compiler-2021`. Solo aquellos proyectos que pasen todas las pruebas con éxito serán evaluados. - -Para ejecutar las pruebas localmente, debe tener instalado `Python 3.7`, `pip` y `make` (normalmente viene con Linux). Ejecute: - -```bash -$ pip install -r requirements.txt -$ cd src -$ make test -``` +# COOL: Proyecto de Compilación + +> Proyecto base para el compilador de 4to año en Ciencia de la Computación. + +## Generalidades + +La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la +Universidad de La Habana, consiste este curso en la implementación de un compilador completamente +funcional para el lenguaje _COOL_. + +_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. + +## Cómo comenzar (o terminar) + +El proyecto de Compilación será recogido y evaluado **únicamente** a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. A continuación le damos las instrucciones mínimas necesarias para ello: + +### 1. Si no lo han hecho ya, regístrense en [Github](https://github.com) todos los miembros del equipo (es gratis). + +![](img/img1.png) + +### 2. Haga click en el botón **Fork** para hacer una copia del proyecto en el perfil de Github de uno de los miembros. + +Opcionalmente pueden [crear una organización](https://github.com/organizations/new) y copiar el proyecto en el perfil de la misma. + +![](img/img2.png) + +### 3. Una vez hecho esto, tendrá un nuevo repositorio en `github/`. + +Revise que el repositorio de su equipo está en su perfil. +En este ejemplo se ha copiado a la cuenta de `github.com/apiad`. + +Debe indicar bajo el nombre del repositorio: `"forked from matcom/cool-compiler-2021"`. + +![](img/img3.png) + +### 4. Clone este proyecto en un repositorio local. + +Busque la URL de su proyecto en la interfaz web de Github. + +Asegúrese de clonar **su copia** y no el proyecto original en `matcom/cool-compiler-2021`. + +![](img/img4.png) + +```bash +$ git clone git@github.com:/cool-compiler-2021.git +``` + +> Donde `` es posiblemente el nombre de su equipo o del miembro donde se hizo el _fork_. + +A partir de este punto debe tener un proyecto `cool-compiler-2021` local. +El siguiente paso depende de si usted ya tiene su código versionado con `git` o no. + +### 5.A. Si tiene su proyecto en git (y no quiere perder la historia): + +#### 5.1. Mezcle hacia el nuevo respositorio su repositorio anterior: + +```bash +$ cd cool-compiler-2021 +$ git pull --allow-unrelated-histories master +``` + +#### 5.2. Organice su proyecto, código fuente y documentación, de acuerdo a las instrucciones de este documento, y vuelva a hacer `commit`. + +```bash +$ mv src/ +$ git add . +$ git commit -a -m "Mezclado con el proyecto base" +``` + +#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. + +```bash +$ git push origin master +``` + +### 5.B Si aún no tiene su proyecto en git (o no le importa la historia): + +#### 5.1. Simplemente copie el código de su proyecto en la carpeta correspondiente `src` y haga su primer commit. + +```bash +$ mv src/ +$ git commit -a -m "Hello Git!" +``` + +#### 5.2. A partir de este punto asegúrese de hacer `commit` de forma regular para mantener su repositorio actualizado. + +Si necesita saber más sobre `git`, todo lo imprescindible está en [esta guía](doc/github-git-cheat-sheet.pdf). + +#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. + +```bash +$ git push origin master +``` + +## Entregas + +En este proyecto se realizarán entregas parciales a lo largo del curso. Para realizar una entrega, siga los siguientes pasos. + +### 1. Cree un pull request al proyecto original desde su copia. + +![](img/img5.png) + +### 2. Asegúrese de tener la siguiente configuración antes de hacer click en **Create pull request**. + +- **base repository**: `matcom/cool-compiler-2021` (repositorio original) + - **branch**: `master` +- **head repository**: `/cool-compiler-2021` (repositorio propio) + - **branch**: `master` (o la que corresponda) + +> Asegúrese que se indica **Able to merge**. De lo contrario, existen cambios en el repositorio original que usted no tiene, y debe actualizarlos. + +> **NOTA**: Asegúrese que el _pull request_ se hace a la rama `master`. + +![](img/img6.png) + +### 3. Introduzca un título y descripción adecuados, y haga click en **Create pull request**. + +![](img/img7.png) + +### 4. Espere mientras se ejecutan las pruebas. + +Verá la indicación **Some checks haven't completed yet**. + +![](img/img8.png) + +Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje: + +> **This branch is out-of-date with base branch** + +Haga click en **Update branch** y siga las instrucciones. +### 5. Verifique que no hubo errores en las pruebas. + +Si ve el mensaje **(All | Some) checks have failed**, significa que su código no pasó las pruebas. + +![](img/img9.png) + +Para ver los resultados de las pruebas haga click en el link **Details**. + +![](img/img10.png) + + +### 6. Arregle los errores y repita el paso 5 hasta que todas las pruebas pasen. + +Para cualquier modificación que haga a su proyecto, haga _commit_ y _push_ para **su repositorio personal** y automáticamente se actualizará el estado del _pull request_ y se volverán a ejecutar las pruebas. **No es necesario** abrir un _pull request_ nuevo por cada entrega, sino actualizar el anterior. + +> **Por favor asegúrese de mantener un solo _pull request_ activo por equipo**. En caso de abrir uno nuevo, cerrar el anterior. + +## Sobre la implementación + +Ponga todo su código e instrucciones necesarias en la carpeta `src`. Más información en [`src/Readme.md`](src/Readme.md). + +## Sobre la documentación + +Usted debe presentar un reporte escrito documentando el proceso de construcción de su compilador y los detalles más importantes de su funcionamiento. Más información en [`doc/Readme.md`](doc/Readme.md). + +## Sobre los equipos de desarrollo + +Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. + +## Sobre los casos de prueba + +La carpeta `tests` contiene todos los casos de prueba que son obligatorios de pasar para que su proyecto tenga derecho a ser evaluado. + +Estos tests se ejecutan automáticamente cada vez que hace un _pull request_ al repositorio `matcom/cool-compiler-2021`. Solo aquellos proyectos que pasen todas las pruebas con éxito serán evaluados. + +Para ejecutar las pruebas localmente, debe tener instalado `Python 3.7`, `pip` y `make` (normalmente viene con Linux). Ejecute: + +```bash +$ pip install -r requirements.txt +$ cd src +$ make test +``` diff --git a/doc/Readme.md b/doc/Readme.md index 3b2569f5c..a7ed0e32d 100644 --- a/doc/Readme.md +++ b/doc/Readme.md @@ -1,33 +1,33 @@ -# Documentación - -## Readme - -Modifique el contenido de este documento para documentar de forma clara y concisa los siguientes aspectos: - -- Cómo ejecutar (y compilar si es necesario) su compilador. -- Requisitos adicionales, dependencias, configuración, etc. -- Opciones adicionales que tenga su compilador. - -## Sobre los Equipos de Desarrollo - -Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. El proyecto de Compilación será recogido y evaluado únicamente a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. - -**⚠️ NOTA**: Debe completar el archivo `team.yml` con los datos correctos de cada miembro de su equipo. - -## Sobre los Materiales a Entregar - -Para la evaluación del proyecto Ud. debe entregar un informe en formato PDF (`report.pdf`) en esta carpeta, que resuma de manera organizada y comprensible la arquitectura e implementación de su compilador. -El documento no tiene límite de extensión. -En él explicará en más detalle su solución a los problemas que, durante la implementación de cada una de las fases del proceso de compilación, hayan requerido de Ud. especial atención. - -## Estructura del reporte - -Usted es libre de estructurar su reporte escrito como más conveniente le parezca. A continuación le sugerimos algunas secciones que no deberían faltar, aunque puede mezclar, renombrar y organizarlas de la manera que mejor le parezca: - -- **Uso del compilador**: detalles sobre las opciones de líneas de comando, si tiene opciones adicionales (e.j., `--ast` genera un AST en JSON, etc.). Básicamente lo mismo que pondrá en este Readme. -- **Arquitectura del compilador**: una explicación general de la arquitectura, en cuántos módulos se divide el proyecto, cuantas fases tiene, qué tipo de gramática se utiliza, y en general, como se organiza el proyecto. Una buena imagen siempre ayuda. -- **Problemas técnicos**: detalles sobre cualquier problema teórico o técnico interesante que haya necesitado resolver de forma particular. - -## Sobre la Fecha de Entrega - -Se realizarán recogidas parciales del proyecto a lo largo del curso. En el Canal de Telegram se anunciará la fecha y requisitos de cada entrega. +# Documentación + +## Readme + +Modifique el contenido de este documento para documentar de forma clara y concisa los siguientes aspectos: + +- Cómo ejecutar (y compilar si es necesario) su compilador. +- Requisitos adicionales, dependencias, configuración, etc. +- Opciones adicionales que tenga su compilador. + +## Sobre los Equipos de Desarrollo + +Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. El proyecto de Compilación será recogido y evaluado únicamente a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. + +**⚠️ NOTA**: Debe completar el archivo `team.yml` con los datos correctos de cada miembro de su equipo. + +## Sobre los Materiales a Entregar + +Para la evaluación del proyecto Ud. debe entregar un informe en formato PDF (`report.pdf`) en esta carpeta, que resuma de manera organizada y comprensible la arquitectura e implementación de su compilador. +El documento no tiene límite de extensión. +En él explicará en más detalle su solución a los problemas que, durante la implementación de cada una de las fases del proceso de compilación, hayan requerido de Ud. especial atención. + +## Estructura del reporte + +Usted es libre de estructurar su reporte escrito como más conveniente le parezca. A continuación le sugerimos algunas secciones que no deberían faltar, aunque puede mezclar, renombrar y organizarlas de la manera que mejor le parezca: + +- **Uso del compilador**: detalles sobre las opciones de líneas de comando, si tiene opciones adicionales (e.j., `--ast` genera un AST en JSON, etc.). Básicamente lo mismo que pondrá en este Readme. +- **Arquitectura del compilador**: una explicación general de la arquitectura, en cuántos módulos se divide el proyecto, cuantas fases tiene, qué tipo de gramática se utiliza, y en general, como se organiza el proyecto. Una buena imagen siempre ayuda. +- **Problemas técnicos**: detalles sobre cualquier problema teórico o técnico interesante que haya necesitado resolver de forma particular. + +## Sobre la Fecha de Entrega + +Se realizarán recogidas parciales del proyecto a lo largo del curso. En el Canal de Telegram se anunciará la fecha y requisitos de cada entrega. diff --git a/doc/team.yml b/doc/team.yml index c16162532..9c00f520f 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -1,10 +1,8 @@ -members: - - name: Nombre Apellido1 Apellido2 - github: github_id - group: CXXX - - name: Nombre Apellido1 Apellido2 - github: github_id - group: CXXX - - name: Nombre Apellido1 Apellido2 - github: github_id - group: CXXX +members: + - name: Luis Alejandro Lara ROjas + github: LuisLara-UH + group: C412 + - name: Carlos Alejandro Arrieta Montes de Oca + github: Carlitonchin + group: C412 +Organization: Los-Mangotes-SA diff --git a/requirements.txt b/requirements.txt index 9eb0cad1a..c250faba6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -pytest -pytest-ordering +pytest +pytest-ordering diff --git a/src/Readme.md b/src/Readme.md index 1200371b5..cdca282ec 100644 --- a/src/Readme.md +++ b/src/Readme.md @@ -1,78 +1,78 @@ -# COOL: Proyecto de Compilación - -La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la -Universidad de La Habana, consiste este curso en la implementación de un compilador completamente -funcional para el lenguaje _COOL_. - -_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. - -### Sobre el Lenguaje COOL - -Ud. podrá encontrar la especificación formal del lenguaje COOL en el documento _"COOL Language Reference Manual"_, que se distribuye junto con el presente texto. - -## Código Fuente - -### Compilando su proyecto - -Si es necesario compilar su proyecto, incluya todas las instrucciones necesarias en un archivo [`/src/makefile`](/src/makefile). -Durante la evaluación su proyecto se compilará ejecutando la siguiente secuencia: - -```bash -$ cd source -$ make clean -$ make -``` - -### Ejecutando su proyecto - -Incluya en un archivo [`/src/coolc.sh`](/src/coolc.sh) todas las instrucciones que hacen falta para lanzar su compilador. Recibirá como entrada un archivo con extensión `.cl` y debe generar como salida un archivo `.mips` cuyo nombre será el mismo que la entrada. - -Para lanzar el compilador, se ejecutará la siguiente instrucción: - -```bash -$ cd source -$ ./coolc.sh -``` - -### Sobre el Compilador de COOL - -El compilador de COOL se ejecutará como se ha definido anteriormente. -En caso de que no ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código de salida 0, generar (o sobrescribir si ya existe) en la misma carpeta del archivo **.cl** procesado, y con el mismo nombre que éste, un archivo con extension **.mips** que pueda ser ejecutado con **spim**. Además, reportar a la salida estándar solamente lo siguiente: - - - - -En caso de que ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código -de salida (exit code) 1 y reportar a la salida estándar (standard output stream) lo que sigue... - - - - _1 - ... - _n - -... donde `_i` tiene el siguiente formato: - - (,) - : - -Los campos `` y `` indican la ubicación del error en el fichero **.cl** procesado. En caso -de que la naturaleza del error sea tal que no pueda asociárselo a una línea y columna en el archivo de -código fuente, el valor de dichos campos debe ser 0. - -El campo `` será alguno entre: - -- `CompilerError`: se reporta al detectar alguna anomalía con la entrada del compilador. Por ejemplo, si el fichero a compilar no existe. -- `LexicographicError`: errores detectados por el lexer. -- `SyntacticError`: errores detectados por el parser. -- `NameError`: se reporta al referenciar un `identificador` en un ámbito en el que no es visible. -- `TypeError`: se reporta al detectar un problema de tipos. Incluye: - - incompatibilidad de tipos entre `rvalue` y `lvalue`, - - operación no definida entre objetos de ciertos tipos, y - - tipo referenciado pero no definido. -- `AttributeError`: se reporta cuando un atributo o método se referencia pero no está definido. -- `SemanticError`: cualquier otro error semántico. - -### Sobre la Implementación del Compilador de COOL - -El compilador debe estar implementado en `python`. Usted debe utilizar una herramienta generadora de analizadores -lexicográficos y sintácticos. Puede utilizar la que sea de su preferencia. +# COOL: Proyecto de Compilación + +La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la +Universidad de La Habana, consiste este curso en la implementación de un compilador completamente +funcional para el lenguaje _COOL_. + +_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. + +### Sobre el Lenguaje COOL + +Ud. podrá encontrar la especificación formal del lenguaje COOL en el documento _"COOL Language Reference Manual"_, que se distribuye junto con el presente texto. + +## Código Fuente + +### Compilando su proyecto + +Si es necesario compilar su proyecto, incluya todas las instrucciones necesarias en un archivo [`/src/makefile`](/src/makefile). +Durante la evaluación su proyecto se compilará ejecutando la siguiente secuencia: + +```bash +$ cd source +$ make clean +$ make +``` + +### Ejecutando su proyecto + +Incluya en un archivo [`/src/coolc.sh`](/src/coolc.sh) todas las instrucciones que hacen falta para lanzar su compilador. Recibirá como entrada un archivo con extensión `.cl` y debe generar como salida un archivo `.mips` cuyo nombre será el mismo que la entrada. + +Para lanzar el compilador, se ejecutará la siguiente instrucción: + +```bash +$ cd source +$ ./coolc.sh +``` + +### Sobre el Compilador de COOL + +El compilador de COOL se ejecutará como se ha definido anteriormente. +En caso de que no ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código de salida 0, generar (o sobrescribir si ya existe) en la misma carpeta del archivo **.cl** procesado, y con el mismo nombre que éste, un archivo con extension **.mips** que pueda ser ejecutado con **spim**. Además, reportar a la salida estándar solamente lo siguiente: + + + + +En caso de que ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código +de salida (exit code) 1 y reportar a la salida estándar (standard output stream) lo que sigue... + + + + _1 + ... + _n + +... donde `_i` tiene el siguiente formato: + + (,) - : + +Los campos `` y `` indican la ubicación del error en el fichero **.cl** procesado. En caso +de que la naturaleza del error sea tal que no pueda asociárselo a una línea y columna en el archivo de +código fuente, el valor de dichos campos debe ser 0. + +El campo `` será alguno entre: + +- `CompilerError`: se reporta al detectar alguna anomalía con la entrada del compilador. Por ejemplo, si el fichero a compilar no existe. +- `LexicographicError`: errores detectados por el lexer. +- `SyntacticError`: errores detectados por el parser. +- `NameError`: se reporta al referenciar un `identificador` en un ámbito en el que no es visible. +- `TypeError`: se reporta al detectar un problema de tipos. Incluye: + - incompatibilidad de tipos entre `rvalue` y `lvalue`, + - operación no definida entre objetos de ciertos tipos, y + - tipo referenciado pero no definido. +- `AttributeError`: se reporta cuando un atributo o método se referencia pero no está definido. +- `SemanticError`: cualquier otro error semántico. + +### Sobre la Implementación del Compilador de COOL + +El compilador debe estar implementado en `python`. Usted debe utilizar una herramienta generadora de analizadores +lexicográficos y sintácticos. Puede utilizar la que sea de su preferencia. diff --git a/src/coolc.sh b/src/coolc.sh index 3088de4f9..c685089bd 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -1,11 +1,11 @@ -# Incluya aquí las instrucciones necesarias para ejecutar su compilador - -INPUT_FILE=$1 -OUTPUT_FILE=${INPUT_FILE:0: -2}mips - -# Si su compilador no lo hace ya, aquí puede imprimir la información de contacto -echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas -echo "Copyright (c) 2019: Nombre1, Nombre2, Nombre3" # TODO: líneas a los valores correctos - -# Llamar al compilador -echo "Compiling $INPUT_FILE into $OUTPUT_FILE" +# Incluya aquí las instrucciones necesarias para ejecutar su compilador + +INPUT_FILE=$1 +OUTPUT_FILE=${INPUT_FILE:0: -2}mips + +# Si su compilador no lo hace ya, aquí puede imprimir la información de contacto +echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas +echo "Copyright (c) 2019: Nombre1, Nombre2, Nombre3" # TODO: líneas a los valores correctos + +# Llamar al compilador +echo "Compiling $INPUT_FILE into $OUTPUT_FILE" diff --git a/src/makefile b/src/makefile index 30df993f5..cd83fb352 100644 --- a/src/makefile +++ b/src/makefile @@ -1,12 +1,12 @@ -.PHONY: clean - -main: - # Compiling the compiler :) - -clean: - rm -rf build/* - rm -rf ../tests/*/*.mips - -test: - pytest ../tests -v --tb=short -m=${TAG} - +.PHONY: clean + +main: + # Compiling the compiler :) + +clean: + rm -rf build/* + rm -rf ../tests/*/*.mips + +test: + pytest ../tests -v --tb=short -m=${TAG} + diff --git a/tests/codegen/arith.cl b/tests/codegen/arith.cl index af5951cf7..0d9f5dd33 100755 --- a/tests/codegen/arith.cl +++ b/tests/codegen/arith.cl @@ -1,430 +1,430 @@ -(* - * A contribution from Anne Sheets (sheets@cory) - * - * Tests the arithmetic operations and various other things - *) - -class A { - - var : Int <- 0; - - value() : Int { var }; - - set_var(num : Int) : A{ - { - var <- num; - self; - } - }; - - method1(num : Int) : A { -- same - self - }; - - method2(num1 : Int, num2 : Int) : A { -- plus - (let x : Int in - { - x <- num1 + num2; - (new B).set_var(x); - } - ) - }; - - method3(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new C).set_var(x); - } - ) - }; - - method4(num1 : Int, num2 : Int) : A { -- diff - if num2 < num1 then - (let x : Int in - { - x <- num1 - num2; - (new D).set_var(x); - } - ) - else - (let x : Int in - { - x <- num2 - num1; - (new D).set_var(x); - } - ) - fi - }; - - method5(num : Int) : A { -- factorial - (let x : Int <- 1 in - { - (let y : Int <- 1 in - while y <= num loop - { - x <- x * y; - y <- y + 1; - } - pool - ); - (new E).set_var(x); - } - ) - }; - -}; - -class B inherits A { -- B is a number squared - - method5(num : Int) : A { -- square - (let x : Int in - { - x <- num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class C inherits B { - - method6(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new A).set_var(x); - } - ) - }; - - method5(num : Int) : A { -- cube - (let x : Int in - { - x <- num * num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class D inherits B { - - method7(num : Int) : Bool { -- divisible by 3 - (let x : Int <- num in - if x < 0 then method7(~x) else - if 0 = x then true else - if 1 = x then false else - if 2 = x then false else - method7(x - 3) - fi fi fi fi - ) - }; - -}; - -class E inherits D { - - method6(num : Int) : A { -- division - (let x : Int in - { - x <- num / 8; - (new A).set_var(x); - } - ) - }; - -}; - -(* The following code is from atoi.cl in ~cs164/examples *) - -(* - The class A2I provides integer-to-string and string-to-integer -conversion routines. To use these routines, either inherit them -in the class where needed, have a dummy variable bound to -something of type A2I, or simpl write (new A2I).method(argument). -*) - - -(* - c2i Converts a 1-character string to an integer. Aborts - if the string is not "0" through "9" -*) -class A2I { - - c2i(char : String) : Int { - if char = "0" then 0 else - if char = "1" then 1 else - if char = "2" then 2 else - if char = "3" then 3 else - if char = "4" then 4 else - if char = "5" then 5 else - if char = "6" then 6 else - if char = "7" then 7 else - if char = "8" then 8 else - if char = "9" then 9 else - { abort(); 0; } (* the 0 is needed to satisfy the - typchecker *) - fi fi fi fi fi fi fi fi fi fi - }; - -(* - i2c is the inverse of c2i. -*) - i2c(i : Int) : String { - if i = 0 then "0" else - if i = 1 then "1" else - if i = 2 then "2" else - if i = 3 then "3" else - if i = 4 then "4" else - if i = 5 then "5" else - if i = 6 then "6" else - if i = 7 then "7" else - if i = 8 then "8" else - if i = 9 then "9" else - { abort(); ""; } -- the "" is needed to satisfy the typchecker - fi fi fi fi fi fi fi fi fi fi - }; - -(* - a2i converts an ASCII string into an integer. The empty string -is converted to 0. Signed and unsigned strings are handled. The -method aborts if the string does not represent an integer. Very -long strings of digits produce strange answers because of arithmetic -overflow. - -*) - a2i(s : String) : Int { - if s.length() = 0 then 0 else - if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else - if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else - a2i_aux(s) - fi fi fi - }; - -(* a2i_aux converts the usigned portion of the string. As a - programming example, this method is written iteratively. *) - - - a2i_aux(s : String) : Int { - (let int : Int <- 0 in - { - (let j : Int <- s.length() in - (let i : Int <- 0 in - while i < j loop - { - int <- int * 10 + c2i(s.substr(i,1)); - i <- i + 1; - } - pool - ) - ); - int; - } - ) - }; - -(* i2a converts an integer to a string. Positive and negative - numbers are handled correctly. *) - - i2a(i : Int) : String { - if i = 0 then "0" else - if 0 < i then i2a_aux(i) else - "-".concat(i2a_aux(i * ~1)) - fi fi - }; - -(* i2a_aux is an example using recursion. *) - - i2a_aux(i : Int) : String { - if i = 0 then "" else - (let next : Int <- i / 10 in - i2a_aux(next).concat(i2c(i - next * 10)) - ) - fi - }; - -}; - -class Main inherits IO { - - char : String; - avar : A; - a_var : A; - flag : Bool <- true; - - - menu() : String { - { - out_string("\n\tTo add a number to "); - print(avar); - out_string("...enter a:\n"); - out_string("\tTo negate "); - print(avar); - out_string("...enter b:\n"); - out_string("\tTo find the difference between "); - print(avar); - out_string("and another number...enter c:\n"); - out_string("\tTo find the factorial of "); - print(avar); - out_string("...enter d:\n"); - out_string("\tTo square "); - print(avar); - out_string("...enter e:\n"); - out_string("\tTo cube "); - print(avar); - out_string("...enter f:\n"); - out_string("\tTo find out if "); - print(avar); - out_string("is a multiple of 3...enter g:\n"); - out_string("\tTo divide "); - print(avar); - out_string("by 8...enter h:\n"); - out_string("\tTo get a new number...enter j:\n"); - out_string("\tTo quit...enter q:\n\n"); - in_string(); - } - }; - - prompt() : String { - { - out_string("\n"); - out_string("Please enter a number... "); - in_string(); - } - }; - - get_int() : Int { - { - (let z : A2I <- new A2I in - (let s : String <- prompt() in - z.a2i(s) - ) - ); - } - }; - - is_even(num : Int) : Bool { - (let x : Int <- num in - if x < 0 then is_even(~x) else - if 0 = x then true else - if 1 = x then false else - is_even(x - 2) - fi fi fi - ) - }; - - class_type(var : A) : IO { - case var of - a : A => out_string("Class type is now A\n"); - b : B => out_string("Class type is now B\n"); - c : C => out_string("Class type is now C\n"); - d : D => out_string("Class type is now D\n"); - e : E => out_string("Class type is now E\n"); - o : Object => out_string("Oooops\n"); - esac - }; - - print(var : A) : IO { - (let z : A2I <- new A2I in - { - out_string(z.i2a(var.value())); - out_string(" "); - } - ) - }; - - main() : Object { - { - avar <- (new A); - while flag loop - { - -- avar <- (new A).set_var(get_int()); - out_string("number "); - print(avar); - if is_even(avar.value()) then - out_string("is even!\n") - else - out_string("is odd!\n") - fi; - -- print(avar); -- prints out answer - class_type(avar); - char <- menu(); - if char = "a" then -- add - { - a_var <- (new A).set_var(get_int()); - avar <- (new B).method2(avar.value(), a_var.value()); - } else - if char = "b" then -- negate - case avar of - c : C => avar <- c.method6(c.value()); - a : A => avar <- a.method3(a.value()); - o : Object => { - out_string("Oooops\n"); - abort(); 0; - }; - esac else - if char = "c" then -- diff - { - a_var <- (new A).set_var(get_int()); - avar <- (new D).method4(avar.value(), a_var.value()); - } else - if char = "d" then avar <- (new C)@A.method5(avar.value()) else - -- factorial - if char = "e" then avar <- (new C)@B.method5(avar.value()) else - -- square - if char = "f" then avar <- (new C)@C.method5(avar.value()) else - -- cube - if char = "g" then -- multiple of 3? - if ((new D).method7(avar.value())) - then -- avar <- (new A).method1(avar.value()) - { - out_string("number "); - print(avar); - out_string("is divisible by 3.\n"); - } - else -- avar <- (new A).set_var(0) - { - out_string("number "); - print(avar); - out_string("is not divisible by 3.\n"); - } - fi else - if char = "h" then - (let x : A in - { - x <- (new E).method6(avar.value()); - (let r : Int <- (avar.value() - (x.value() * 8)) in - { - out_string("number "); - print(avar); - out_string("is equal to "); - print(x); - out_string("times 8 with a remainder of "); - (let a : A2I <- new A2I in - { - out_string(a.i2a(r)); - out_string("\n"); - } - ); -- end let a: - } - ); -- end let r: - avar <- x; - } - ) -- end let x: - else - if char = "j" then avar <- (new A) - else - if char = "q" then flag <- false - else - avar <- (new A).method1(avar.value()) -- divide/8 - fi fi fi fi fi fi fi fi fi fi; - } - pool; - } - }; - -}; - +(* + * A contribution from Anne Sheets (sheets@cory) + * + * Tests the arithmetic operations and various other things + *) + +class A { + + var : Int <- 0; + + value() : Int { var }; + + set_var(num : Int) : A{ + { + var <- num; + self; + } + }; + + method1(num : Int) : A { -- same + self + }; + + method2(num1 : Int, num2 : Int) : A { -- plus + (let x : Int in + { + x <- num1 + num2; + (new B).set_var(x); + } + ) + }; + + method3(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new C).set_var(x); + } + ) + }; + + method4(num1 : Int, num2 : Int) : A { -- diff + if num2 < num1 then + (let x : Int in + { + x <- num1 - num2; + (new D).set_var(x); + } + ) + else + (let x : Int in + { + x <- num2 - num1; + (new D).set_var(x); + } + ) + fi + }; + + method5(num : Int) : A { -- factorial + (let x : Int <- 1 in + { + (let y : Int <- 1 in + while y <= num loop + { + x <- x * y; + y <- y + 1; + } + pool + ); + (new E).set_var(x); + } + ) + }; + +}; + +class B inherits A { -- B is a number squared + + method5(num : Int) : A { -- square + (let x : Int in + { + x <- num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class C inherits B { + + method6(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new A).set_var(x); + } + ) + }; + + method5(num : Int) : A { -- cube + (let x : Int in + { + x <- num * num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class D inherits B { + + method7(num : Int) : Bool { -- divisible by 3 + (let x : Int <- num in + if x < 0 then method7(~x) else + if 0 = x then true else + if 1 = x then false else + if 2 = x then false else + method7(x - 3) + fi fi fi fi + ) + }; + +}; + +class E inherits D { + + method6(num : Int) : A { -- division + (let x : Int in + { + x <- num / 8; + (new A).set_var(x); + } + ) + }; + +}; + +(* The following code is from atoi.cl in ~cs164/examples *) + +(* + The class A2I provides integer-to-string and string-to-integer +conversion routines. To use these routines, either inherit them +in the class where needed, have a dummy variable bound to +something of type A2I, or simpl write (new A2I).method(argument). +*) + + +(* + c2i Converts a 1-character string to an integer. Aborts + if the string is not "0" through "9" +*) +class A2I { + + c2i(char : String) : Int { + if char = "0" then 0 else + if char = "1" then 1 else + if char = "2" then 2 else + if char = "3" then 3 else + if char = "4" then 4 else + if char = "5" then 5 else + if char = "6" then 6 else + if char = "7" then 7 else + if char = "8" then 8 else + if char = "9" then 9 else + { abort(); 0; } (* the 0 is needed to satisfy the + typchecker *) + fi fi fi fi fi fi fi fi fi fi + }; + +(* + i2c is the inverse of c2i. +*) + i2c(i : Int) : String { + if i = 0 then "0" else + if i = 1 then "1" else + if i = 2 then "2" else + if i = 3 then "3" else + if i = 4 then "4" else + if i = 5 then "5" else + if i = 6 then "6" else + if i = 7 then "7" else + if i = 8 then "8" else + if i = 9 then "9" else + { abort(); ""; } -- the "" is needed to satisfy the typchecker + fi fi fi fi fi fi fi fi fi fi + }; + +(* + a2i converts an ASCII string into an integer. The empty string +is converted to 0. Signed and unsigned strings are handled. The +method aborts if the string does not represent an integer. Very +long strings of digits produce strange answers because of arithmetic +overflow. + +*) + a2i(s : String) : Int { + if s.length() = 0 then 0 else + if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else + if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else + a2i_aux(s) + fi fi fi + }; + +(* a2i_aux converts the usigned portion of the string. As a + programming example, this method is written iteratively. *) + + + a2i_aux(s : String) : Int { + (let int : Int <- 0 in + { + (let j : Int <- s.length() in + (let i : Int <- 0 in + while i < j loop + { + int <- int * 10 + c2i(s.substr(i,1)); + i <- i + 1; + } + pool + ) + ); + int; + } + ) + }; + +(* i2a converts an integer to a string. Positive and negative + numbers are handled correctly. *) + + i2a(i : Int) : String { + if i = 0 then "0" else + if 0 < i then i2a_aux(i) else + "-".concat(i2a_aux(i * ~1)) + fi fi + }; + +(* i2a_aux is an example using recursion. *) + + i2a_aux(i : Int) : String { + if i = 0 then "" else + (let next : Int <- i / 10 in + i2a_aux(next).concat(i2c(i - next * 10)) + ) + fi + }; + +}; + +class Main inherits IO { + + char : String; + avar : A; + a_var : A; + flag : Bool <- true; + + + menu() : String { + { + out_string("\n\tTo add a number to "); + print(avar); + out_string("...enter a:\n"); + out_string("\tTo negate "); + print(avar); + out_string("...enter b:\n"); + out_string("\tTo find the difference between "); + print(avar); + out_string("and another number...enter c:\n"); + out_string("\tTo find the factorial of "); + print(avar); + out_string("...enter d:\n"); + out_string("\tTo square "); + print(avar); + out_string("...enter e:\n"); + out_string("\tTo cube "); + print(avar); + out_string("...enter f:\n"); + out_string("\tTo find out if "); + print(avar); + out_string("is a multiple of 3...enter g:\n"); + out_string("\tTo divide "); + print(avar); + out_string("by 8...enter h:\n"); + out_string("\tTo get a new number...enter j:\n"); + out_string("\tTo quit...enter q:\n\n"); + in_string(); + } + }; + + prompt() : String { + { + out_string("\n"); + out_string("Please enter a number... "); + in_string(); + } + }; + + get_int() : Int { + { + (let z : A2I <- new A2I in + (let s : String <- prompt() in + z.a2i(s) + ) + ); + } + }; + + is_even(num : Int) : Bool { + (let x : Int <- num in + if x < 0 then is_even(~x) else + if 0 = x then true else + if 1 = x then false else + is_even(x - 2) + fi fi fi + ) + }; + + class_type(var : A) : IO { + case var of + a : A => out_string("Class type is now A\n"); + b : B => out_string("Class type is now B\n"); + c : C => out_string("Class type is now C\n"); + d : D => out_string("Class type is now D\n"); + e : E => out_string("Class type is now E\n"); + o : Object => out_string("Oooops\n"); + esac + }; + + print(var : A) : IO { + (let z : A2I <- new A2I in + { + out_string(z.i2a(var.value())); + out_string(" "); + } + ) + }; + + main() : Object { + { + avar <- (new A); + while flag loop + { + -- avar <- (new A).set_var(get_int()); + out_string("number "); + print(avar); + if is_even(avar.value()) then + out_string("is even!\n") + else + out_string("is odd!\n") + fi; + -- print(avar); -- prints out answer + class_type(avar); + char <- menu(); + if char = "a" then -- add + { + a_var <- (new A).set_var(get_int()); + avar <- (new B).method2(avar.value(), a_var.value()); + } else + if char = "b" then -- negate + case avar of + c : C => avar <- c.method6(c.value()); + a : A => avar <- a.method3(a.value()); + o : Object => { + out_string("Oooops\n"); + abort(); 0; + }; + esac else + if char = "c" then -- diff + { + a_var <- (new A).set_var(get_int()); + avar <- (new D).method4(avar.value(), a_var.value()); + } else + if char = "d" then avar <- (new C)@A.method5(avar.value()) else + -- factorial + if char = "e" then avar <- (new C)@B.method5(avar.value()) else + -- square + if char = "f" then avar <- (new C)@C.method5(avar.value()) else + -- cube + if char = "g" then -- multiple of 3? + if ((new D).method7(avar.value())) + then -- avar <- (new A).method1(avar.value()) + { + out_string("number "); + print(avar); + out_string("is divisible by 3.\n"); + } + else -- avar <- (new A).set_var(0) + { + out_string("number "); + print(avar); + out_string("is not divisible by 3.\n"); + } + fi else + if char = "h" then + (let x : A in + { + x <- (new E).method6(avar.value()); + (let r : Int <- (avar.value() - (x.value() * 8)) in + { + out_string("number "); + print(avar); + out_string("is equal to "); + print(x); + out_string("times 8 with a remainder of "); + (let a : A2I <- new A2I in + { + out_string(a.i2a(r)); + out_string("\n"); + } + ); -- end let a: + } + ); -- end let r: + avar <- x; + } + ) -- end let x: + else + if char = "j" then avar <- (new A) + else + if char = "q" then flag <- false + else + avar <- (new A).method1(avar.value()) -- divide/8 + fi fi fi fi fi fi fi fi fi fi; + } + pool; + } + }; + +}; + diff --git a/tests/codegen/arith_input.txt b/tests/codegen/arith_input.txt index 83e05b1ea..c431a225b 100644 --- a/tests/codegen/arith_input.txt +++ b/tests/codegen/arith_input.txt @@ -1,13 +1,13 @@ -a -1 -b -c -0 -d -e -f -g -h -j -5 -q +a +1 +b +c +0 +d +e +f +g +h +j +5 +q diff --git a/tests/codegen/arith_output.txt b/tests/codegen/arith_output.txt index 44b4ce73e..476cb3bad 100644 --- a/tests/codegen/arith_output.txt +++ b/tests/codegen/arith_output.txt @@ -1,158 +1,158 @@ -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now B - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number -1 is odd! -Class type is now C - - To add a number to -1 ...enter a: - To negate -1 ...enter b: - To find the difference between -1 and another number...enter c: - To find the factorial of -1 ...enter d: - To square -1 ...enter e: - To cube -1 ...enter f: - To find out if -1 is a multiple of 3...enter g: - To divide -1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now D - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is not divisible by 3. -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is equal to 0 times 8 with a remainder of 1 -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now B + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number -1 is odd! +Class type is now C + + To add a number to -1 ...enter a: + To negate -1 ...enter b: + To find the difference between -1 and another number...enter c: + To find the factorial of -1 ...enter d: + To square -1 ...enter e: + To cube -1 ...enter f: + To find out if -1 is a multiple of 3...enter g: + To divide -1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now D + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is not divisible by 3. +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is equal to 0 times 8 with a remainder of 1 +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + diff --git a/tests/codegen/atoi_output.txt b/tests/codegen/atoi_output.txt index 51b815a48..c51d7bad6 100644 --- a/tests/codegen/atoi_output.txt +++ b/tests/codegen/atoi_output.txt @@ -1 +1 @@ -678987 == 678987 +678987 == 678987 diff --git a/tests/codegen/book_list.cl b/tests/codegen/book_list.cl index 025ea1695..d39f86bbe 100755 --- a/tests/codegen/book_list.cl +++ b/tests/codegen/book_list.cl @@ -1,132 +1,132 @@ --- example of static and dynamic type differing for a dispatch - -Class Book inherits IO { - title : String; - author : String; - - initBook(title_p : String, author_p : String) : Book { - { - title <- title_p; - author <- author_p; - self; - } - }; - - print() : Book { - { - out_string("title: ").out_string(title).out_string("\n"); - out_string("author: ").out_string(author).out_string("\n"); - self; - } - }; -}; - -Class Article inherits Book { - per_title : String; - - initArticle(title_p : String, author_p : String, - per_title_p : String) : Article { - { - initBook(title_p, author_p); - per_title <- per_title_p; - self; - } - }; - - print() : Book { - { - self@Book.print(); - out_string("periodical: ").out_string(per_title).out_string("\n"); - self; - } - }; -}; - -Class BookList inherits IO { - (* Since abort "returns" type Object, we have to add - an expression of type Bool here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - isNil() : Bool { { abort(); true; } }; - - cons(hd : Book) : Cons { - (let new_cell : Cons <- new Cons in - new_cell.init(hd,self) - ) - }; - - (* Since abort "returns" type Object, we have to add - an expression of type Book here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - car() : Book { { abort(); new Book; } }; - - (* Since abort "returns" type Object, we have to add - an expression of type BookList here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - cdr() : BookList { { abort(); new BookList; } }; - - print_list() : Object { abort() }; -}; - -Class Cons inherits BookList { - xcar : Book; -- We keep the car and cdr in attributes. - xcdr : BookList; -- Because methods and features must have different names, - -- we use xcar and xcdr for the attributes and reserve - -- car and cdr for the features. - - isNil() : Bool { false }; - - init(hd : Book, tl : BookList) : Cons { - { - xcar <- hd; - xcdr <- tl; - self; - } - }; - - car() : Book { xcar }; - - cdr() : BookList { xcdr }; - - print_list() : Object { - { - case xcar.print() of - dummy : Book => out_string("- dynamic type was Book -\n"); - dummy : Article => out_string("- dynamic type was Article -\n"); - esac; - xcdr.print_list(); - } - }; -}; - -Class Nil inherits BookList { - isNil() : Bool { true }; - - print_list() : Object { true }; -}; - - -Class Main { - - books : BookList; - - main() : Object { - (let a_book : Book <- - (new Book).initBook("Compilers, Principles, Techniques, and Tools", - "Aho, Sethi, and Ullman") - in - (let an_article : Article <- - (new Article).initArticle("The Top 100 CD_ROMs", - "Ulanoff", - "PC Magazine") - in - { - books <- (new Nil).cons(a_book).cons(an_article); - books.print_list(); - } - ) -- end let an_article - ) -- end let a_book - }; -}; +-- example of static and dynamic type differing for a dispatch + +Class Book inherits IO { + title : String; + author : String; + + initBook(title_p : String, author_p : String) : Book { + { + title <- title_p; + author <- author_p; + self; + } + }; + + print() : Book { + { + out_string("title: ").out_string(title).out_string("\n"); + out_string("author: ").out_string(author).out_string("\n"); + self; + } + }; +}; + +Class Article inherits Book { + per_title : String; + + initArticle(title_p : String, author_p : String, + per_title_p : String) : Article { + { + initBook(title_p, author_p); + per_title <- per_title_p; + self; + } + }; + + print() : Book { + { + self@Book.print(); + out_string("periodical: ").out_string(per_title).out_string("\n"); + self; + } + }; +}; + +Class BookList inherits IO { + (* Since abort "returns" type Object, we have to add + an expression of type Bool here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + isNil() : Bool { { abort(); true; } }; + + cons(hd : Book) : Cons { + (let new_cell : Cons <- new Cons in + new_cell.init(hd,self) + ) + }; + + (* Since abort "returns" type Object, we have to add + an expression of type Book here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + car() : Book { { abort(); new Book; } }; + + (* Since abort "returns" type Object, we have to add + an expression of type BookList here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + cdr() : BookList { { abort(); new BookList; } }; + + print_list() : Object { abort() }; +}; + +Class Cons inherits BookList { + xcar : Book; -- We keep the car and cdr in attributes. + xcdr : BookList; -- Because methods and features must have different names, + -- we use xcar and xcdr for the attributes and reserve + -- car and cdr for the features. + + isNil() : Bool { false }; + + init(hd : Book, tl : BookList) : Cons { + { + xcar <- hd; + xcdr <- tl; + self; + } + }; + + car() : Book { xcar }; + + cdr() : BookList { xcdr }; + + print_list() : Object { + { + case xcar.print() of + dummy : Book => out_string("- dynamic type was Book -\n"); + dummy : Article => out_string("- dynamic type was Article -\n"); + esac; + xcdr.print_list(); + } + }; +}; + +Class Nil inherits BookList { + isNil() : Bool { true }; + + print_list() : Object { true }; +}; + + +Class Main { + + books : BookList; + + main() : Object { + (let a_book : Book <- + (new Book).initBook("Compilers, Principles, Techniques, and Tools", + "Aho, Sethi, and Ullman") + in + (let an_article : Article <- + (new Article).initArticle("The Top 100 CD_ROMs", + "Ulanoff", + "PC Magazine") + in + { + books <- (new Nil).cons(a_book).cons(an_article); + books.print_list(); + } + ) -- end let an_article + ) -- end let a_book + }; +}; diff --git a/tests/codegen/book_list_output.txt b/tests/codegen/book_list_output.txt index 3408320b2..ced587a4f 100644 --- a/tests/codegen/book_list_output.txt +++ b/tests/codegen/book_list_output.txt @@ -1,7 +1,7 @@ -title: The Top 100 CD_ROMs -author: Ulanoff -periodical: PC Magazine -- dynamic type was Article - -title: Compilers, Principles, Techniques, and Tools -author: Aho, Sethi, and Ullman -- dynamic type was Book - +title: The Top 100 CD_ROMs +author: Ulanoff +periodical: PC Magazine +- dynamic type was Article - +title: Compilers, Principles, Techniques, and Tools +author: Aho, Sethi, and Ullman +- dynamic type was Book - diff --git a/tests/codegen/cells.cl b/tests/codegen/cells.cl index 9fd6741bb..bcd891498 100755 --- a/tests/codegen/cells.cl +++ b/tests/codegen/cells.cl @@ -1,97 +1,97 @@ -(* models one-dimensional cellular automaton on a circle of finite radius - arrays are faked as Strings, - X's respresent live cells, dots represent dead cells, - no error checking is done *) -class CellularAutomaton inherits IO { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - self; - } - }; - - print() : CellularAutomaton { - { - out_string(population_map.concat("\n")); - self; - } - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - population_map.substr(position, 1) - }; - - cell_left_neighbor(position : Int) : String { - if position = 0 then - cell(num_cells() - 1) - else - cell(position - 1) - fi - }; - - cell_right_neighbor(position : Int) : String { - if position = num_cells() - 1 then - cell(0) - else - cell(position + 1) - fi - }; - - (* a cell will live if exactly 1 of itself and it's immediate - neighbors are alive *) - cell_at_next_evolution(position : Int) : String { - if (if cell(position) = "X" then 1 else 0 fi - + if cell_left_neighbor(position) = "X" then 1 else 0 fi - + if cell_right_neighbor(position) = "X" then 1 else 0 fi - = 1) - then - "X" - else - "." - fi - }; - - evolve() : CellularAutomaton { - (let position : Int in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; -}; - -class Main { - cells : CellularAutomaton; - - main() : Main { - { - cells <- (new CellularAutomaton).init(" X "); - cells.print(); - (let countdown : Int <- 20 in - while 0 < countdown loop - { - cells.evolve(); - cells.print(); - countdown <- countdown - 1; - } - pool - ); - self; - } - }; -}; +(* models one-dimensional cellular automaton on a circle of finite radius + arrays are faked as Strings, + X's respresent live cells, dots represent dead cells, + no error checking is done *) +class CellularAutomaton inherits IO { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + self; + } + }; + + print() : CellularAutomaton { + { + out_string(population_map.concat("\n")); + self; + } + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + population_map.substr(position, 1) + }; + + cell_left_neighbor(position : Int) : String { + if position = 0 then + cell(num_cells() - 1) + else + cell(position - 1) + fi + }; + + cell_right_neighbor(position : Int) : String { + if position = num_cells() - 1 then + cell(0) + else + cell(position + 1) + fi + }; + + (* a cell will live if exactly 1 of itself and it's immediate + neighbors are alive *) + cell_at_next_evolution(position : Int) : String { + if (if cell(position) = "X" then 1 else 0 fi + + if cell_left_neighbor(position) = "X" then 1 else 0 fi + + if cell_right_neighbor(position) = "X" then 1 else 0 fi + = 1) + then + "X" + else + "." + fi + }; + + evolve() : CellularAutomaton { + (let position : Int in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; +}; + +class Main { + cells : CellularAutomaton; + + main() : Main { + { + cells <- (new CellularAutomaton).init(" X "); + cells.print(); + (let countdown : Int <- 20 in + while 0 < countdown loop + { + cells.evolve(); + cells.print(); + countdown <- countdown - 1; + } + pool + ); + self; + } + }; +}; diff --git a/tests/codegen/cells_output.txt b/tests/codegen/cells_output.txt index 6304902cc..9d06c27bc 100644 --- a/tests/codegen/cells_output.txt +++ b/tests/codegen/cells_output.txt @@ -1,21 +1,21 @@ - X -........XXX........ -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. -XXX.............XXX -...X...........X... -..XXX.........XXX.. -.X...X.......X...X. -XXX.XXX.....XXX.XXX -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. + X +........XXX........ +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. +XXX.............XXX +...X...........X... +..XXX.........XXX.. +.X...X.......X...X. +XXX.XXX.....XXX.XXX +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. diff --git a/tests/codegen/complex.cl b/tests/codegen/complex.cl index 0b7aa44e9..9edb6151d 100755 --- a/tests/codegen/complex.cl +++ b/tests/codegen/complex.cl @@ -1,52 +1,52 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - if c.reflect_X().reflect_Y() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; -}; +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + if c.reflect_X().reflect_Y() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; +}; diff --git a/tests/codegen/complex_output.txt b/tests/codegen/complex_output.txt index 18b77c1fc..7d6173685 100644 --- a/tests/codegen/complex_output.txt +++ b/tests/codegen/complex_output.txt @@ -1 +1 @@ -=) +=) diff --git a/tests/codegen/fib.cl b/tests/codegen/fib.cl index 08ceaede8..ced8cee48 100644 --- a/tests/codegen/fib.cl +++ b/tests/codegen/fib.cl @@ -1,29 +1,29 @@ -class Main inherits IO { - -- the class has features. Only methods in this case. - main(): Object { - { - out_string("Enter n to find nth fibonacci number!\n"); - out_int(fib(in_int())); - out_string("\n"); - } - }; - - fib(i : Int) : Int { -- list of formals. And the return type of the method. - let a : Int <- 1, - b : Int <- 0, - c : Int <- 0 - in - { - while (not (i = 0)) loop -- expressions are nested. - { - c <- a + b; - i <- i - 1; - b <- a; - a <- c; - } - pool; - c; - } - }; - -}; +class Main inherits IO { + -- the class has features. Only methods in this case. + main(): Object { + { + out_string("Enter n to find nth fibonacci number!\n"); + out_int(fib(in_int())); + out_string("\n"); + } + }; + + fib(i : Int) : Int { -- list of formals. And the return type of the method. + let a : Int <- 1, + b : Int <- 0, + c : Int <- 0 + in + { + while (not (i = 0)) loop -- expressions are nested. + { + c <- a + b; + i <- i - 1; + b <- a; + a <- c; + } + pool; + c; + } + }; + +}; diff --git a/tests/codegen/fib_input.txt b/tests/codegen/fib_input.txt index f599e28b8..d43401489 100644 --- a/tests/codegen/fib_input.txt +++ b/tests/codegen/fib_input.txt @@ -1 +1 @@ -10 +10 diff --git a/tests/codegen/fib_output.txt b/tests/codegen/fib_output.txt index d402da6af..2552f4479 100644 --- a/tests/codegen/fib_output.txt +++ b/tests/codegen/fib_output.txt @@ -1,2 +1,2 @@ -Enter n to find nth fibonacci number! -89 +Enter n to find nth fibonacci number! +89 diff --git a/tests/codegen/graph.cl b/tests/codegen/graph.cl index 8e511358c..59e29bbf4 100755 --- a/tests/codegen/graph.cl +++ b/tests/codegen/graph.cl @@ -1,381 +1,381 @@ -(* - * Cool program reading descriptions of weighted directed graphs - * from stdin. It builds up a graph objects with a list of vertices - * and a list of edges. Every vertice has a list of outgoing edges. - * - * INPUT FORMAT - * Every line has the form vertice successor* - * Where vertice is an int, and successor is vertice,weight - * - * An empty line or EOF terminates the input. - * - * The list of vertices and the edge list is printed out by the Main - * class. - * - * TEST - * Once compiled, the file g1.graph can be fed to the program. - * The output should look like this: - -nautilus.CS.Berkeley.EDU 53# spim -file graph.s (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - b : Int <- a.doh() + g.doh() + doh() + printh(); - - doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; - -}; - -class Bar inherits Razz { - - c : Int <- doh(); - - d : Object <- printh(); -}; - - -class Razz inherits Foo { - - e : Bar <- case self of - n : Razz => (new Bar); - n : Bar => n; - esac; - - f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); - -}; - -class Bazz inherits IO { - - h : Int <- 1; - - g : Foo <- case self of - n : Bazz => (new Foo); - n : Razz => (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - i : Object <- printh(); - - printh() : Int { { out_int(h); 0; } }; - - doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; -}; - -(* scary . . . *) -class Main { - a : Bazz <- new Bazz; - b : Foo <- new Foo; - c : Razz <- new Razz; - d : Bar <- new Bar; - - main(): String { "do nothing" }; - -}; - - - - - +(* hairy . . .*) + +class Foo inherits Bazz { + a : Razz <- case self of + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + b : Int <- a.doh() + g.doh() + doh() + printh(); + + doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; + +}; + +class Bar inherits Razz { + + c : Int <- doh(); + + d : Object <- printh(); +}; + + +class Razz inherits Foo { + + e : Bar <- case self of + n : Razz => (new Bar); + n : Bar => n; + esac; + + f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); + +}; + +class Bazz inherits IO { + + h : Int <- 1; + + g : Foo <- case self of + n : Bazz => (new Foo); + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + i : Object <- printh(); + + printh() : Int { { out_int(h); 0; } }; + + doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; +}; + +(* scary . . . *) +class Main { + a : Bazz <- new Bazz; + b : Foo <- new Foo; + c : Razz <- new Razz; + d : Bar <- new Bar; + + main(): String { "do nothing" }; + +}; + + + + + diff --git a/tests/codegen/hello_world.cl b/tests/codegen/hello_world.cl index 0c818f908..b0a180a2e 100755 --- a/tests/codegen/hello_world.cl +++ b/tests/codegen/hello_world.cl @@ -1,5 +1,5 @@ -class Main inherits IO { - main(): IO { - out_string("Hello, World.\n") - }; -}; +class Main inherits IO { + main(): IO { + out_string("Hello, World.\n") + }; +}; diff --git a/tests/codegen/hello_world_output.txt b/tests/codegen/hello_world_output.txt index 349db2bfe..9c1c7a002 100644 --- a/tests/codegen/hello_world_output.txt +++ b/tests/codegen/hello_world_output.txt @@ -1 +1 @@ -Hello, World. +Hello, World. diff --git a/tests/codegen/io.cl b/tests/codegen/io.cl index 7f0de869e..42ee6854e 100755 --- a/tests/codegen/io.cl +++ b/tests/codegen/io.cl @@ -1,103 +1,103 @@ -(* - * The IO class is predefined and has 4 methods: - * - * out_string(s : String) : SELF_TYPE - * out_int(i : Int) : SELF_TYPE - * in_string() : String - * in_int() : Int - * - * The out operations print their argument to the terminal. The - * in_string method reads an entire line from the terminal and returns a - * string not containing the new line. The in_int method also reads - * an entire line from the terminal and returns the integer - * corresponding to the first non blank word on the line. If that - * word is not an integer, it returns 0. - * - * - * Because our language is object oriented, we need an object of type - * IO in order to call any of these methods. - * - * There are basically two ways of getting access to IO in a class C. - * - * 1) Define C to Inherit from IO. This way the IO methods become - * methods of C, and they can be called using the abbreviated - * dispatch, i.e. - * - * class C inherits IO is - * ... - * out_string("Hello world\n") - * ... - * end; - * - * 2) If your class C does not directly or indirectly inherit from - * IO, the best way to access IO is through an initialized - * attribute of type IO. - * - * class C inherits Foo is - * io : IO <- new IO; - * ... - * io.out_string("Hello world\n"); - * ... - * end; - * - * Approach 1) is most often used, in particular when you need IO - * functions in the Main class. - * - *) - - -class A { - - -- Let's assume that we don't want A to not inherit from IO. - - io : IO <- new IO; - - out_a() : Object { io.out_string("A: Hello world\n") }; - -}; - - -class B inherits A { - - -- B does not have to an extra attribute, since it inherits io from A. - - out_b() : Object { io.out_string("B: Hello world\n") }; - -}; - - -class C inherits IO { - - -- Now the IO methods are part of C. - - out_c() : Object { out_string("C: Hello world\n") }; - - -- Note that out_string(...) is just a shorthand for self.out_string(...) - -}; - - -class D inherits C { - - -- Inherits IO methods from C. - - out_d() : Object { out_string("D: Hello world\n") }; - -}; - - -class Main inherits IO { - - -- Same case as class C. - - main() : Object { - { - (new A).out_a(); - (new B).out_b(); - (new C).out_c(); - (new D).out_d(); - out_string("Done.\n"); - } - }; - -}; +(* + * The IO class is predefined and has 4 methods: + * + * out_string(s : String) : SELF_TYPE + * out_int(i : Int) : SELF_TYPE + * in_string() : String + * in_int() : Int + * + * The out operations print their argument to the terminal. The + * in_string method reads an entire line from the terminal and returns a + * string not containing the new line. The in_int method also reads + * an entire line from the terminal and returns the integer + * corresponding to the first non blank word on the line. If that + * word is not an integer, it returns 0. + * + * + * Because our language is object oriented, we need an object of type + * IO in order to call any of these methods. + * + * There are basically two ways of getting access to IO in a class C. + * + * 1) Define C to Inherit from IO. This way the IO methods become + * methods of C, and they can be called using the abbreviated + * dispatch, i.e. + * + * class C inherits IO is + * ... + * out_string("Hello world\n") + * ... + * end; + * + * 2) If your class C does not directly or indirectly inherit from + * IO, the best way to access IO is through an initialized + * attribute of type IO. + * + * class C inherits Foo is + * io : IO <- new IO; + * ... + * io.out_string("Hello world\n"); + * ... + * end; + * + * Approach 1) is most often used, in particular when you need IO + * functions in the Main class. + * + *) + + +class A { + + -- Let's assume that we don't want A to not inherit from IO. + + io : IO <- new IO; + + out_a() : Object { io.out_string("A: Hello world\n") }; + +}; + + +class B inherits A { + + -- B does not have to an extra attribute, since it inherits io from A. + + out_b() : Object { io.out_string("B: Hello world\n") }; + +}; + + +class C inherits IO { + + -- Now the IO methods are part of C. + + out_c() : Object { out_string("C: Hello world\n") }; + + -- Note that out_string(...) is just a shorthand for self.out_string(...) + +}; + + +class D inherits C { + + -- Inherits IO methods from C. + + out_d() : Object { out_string("D: Hello world\n") }; + +}; + + +class Main inherits IO { + + -- Same case as class C. + + main() : Object { + { + (new A).out_a(); + (new B).out_b(); + (new C).out_c(); + (new D).out_d(); + out_string("Done.\n"); + } + }; + +}; diff --git a/tests/codegen/io_output.txt b/tests/codegen/io_output.txt index f846f596d..870cffce6 100644 --- a/tests/codegen/io_output.txt +++ b/tests/codegen/io_output.txt @@ -1,5 +1,5 @@ -A: Hello world -B: Hello world -C: Hello world -D: Hello world -Done. +A: Hello world +B: Hello world +C: Hello world +D: Hello world +Done. diff --git a/tests/codegen/life.cl b/tests/codegen/life.cl index b83d97957..7d7a41fdb 100755 --- a/tests/codegen/life.cl +++ b/tests/codegen/life.cl @@ -1,436 +1,436 @@ -(* The Game of Life - Tendo Kayiira, Summer '95 - With code taken from /private/cool/class/examples/cells.cl - - This introduction was taken off the internet. It gives a brief - description of the Game Of Life. It also gives the rules by which - this particular game follows. - - Introduction - - John Conway's Game of Life is a mathematical amusement, but it - is also much more: an insight into how a system of simple - cellualar automata can create complex, odd, and often aesthetically - pleasing patterns. It is played on a cartesian grid of cells - which are either 'on' or 'off' The game gets it's name from the - similarity between the behaviour of these cells and the behaviour - of living organisms. - - The Rules - - The playfield is a cartesian grid of arbitrary size. Each cell in - this grid can be in an 'on' state or an 'off' state. On each 'turn' - (called a generation,) the state of each cell changes simultaneously - depending on it's state and the state of all cells adjacent to it. - - For 'on' cells, - If the cell has 0 or 1 neighbours which are 'on', the cell turns - 'off'. ('dies of loneliness') - If the cell has 2 or 3 neighbours which are 'on', the cell stays - 'on'. (nothing happens to that cell) - If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', - the cell turns 'off'. ('dies of overcrowding') - - For 'off' cells, - If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which - are 'on', the cell stays 'off'. (nothing happens to that cell) - If the cell has 3 neighbours which are 'on', the cell turns - 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) - - Repeat for as many generations as desired. - - *) - - -class Board inherits IO { - - rows : Int; - columns : Int; - board_size : Int; - - size_of_board(initial : String) : Int { - initial.length() - }; - - board_init(start : String) : Board { - (let size :Int <- size_of_board(start) in - { - if size = 15 then - { - rows <- 3; - columns <- 5; - board_size <- size; - } - else if size = 16 then - { - rows <- 4; - columns <- 4; - board_size <- size; - } - else if size = 20 then - { - rows <- 4; - columns <- 5; - board_size <- size; - } - else if size = 21 then - { - rows <- 3; - columns <- 7; - board_size <- size; - } - else if size = 25 then - { - rows <- 5; - columns <- 5; - board_size <- size; - } - else if size = 28 then - { - rows <- 7; - columns <- 4; - board_size <- size; - } - else -- If none of the above fit, then just give - { -- the configuration of the most common board - rows <- 5; - columns <- 5; - board_size <- size; - } - fi fi fi fi fi fi; - self; - } - ) - }; - -}; - - - -class CellularAutomaton inherits Board { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - board_init(map); - self; - } - }; - - - - - print() : CellularAutomaton { - - (let i : Int <- 0 in - (let num : Int <- board_size in - { - out_string("\n"); - while i < num loop - { - out_string(population_map.substr(i,columns)); - out_string("\n"); - i <- i + columns; - } - pool; - out_string("\n"); - self; - } - ) ) - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - if board_size - 1 < position then - " " - else - population_map.substr(position, 1) - fi - }; - - north(position : Int): String { - if (position - columns) < 0 then - " " - else - cell(position - columns) - fi - }; - - south(position : Int): String { - if board_size < (position + columns) then - " " - else - cell(position + columns) - fi - }; - - east(position : Int): String { - if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - cell(position + 1) - fi - }; - - west(position : Int): String { - if position = 0 then - " " - else - if ((position / columns) * columns) = position then - " " - else - cell(position - 1) - fi fi - }; - - northwest(position : Int): String { - if (position - columns) < 0 then - " " - else if ((position / columns) * columns) = position then - " " - else - north(position - 1) - fi fi - }; - - northeast(position : Int): String { - if (position - columns) < 0 then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - north(position + 1) - fi fi - }; - - southeast(position : Int): String { - if board_size < (position + columns) then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - south(position + 1) - fi fi - }; - - southwest(position : Int): String { - if board_size < (position + columns) then - " " - else if ((position / columns) * columns) = position then - " " - else - south(position - 1) - fi fi - }; - - neighbors(position: Int): Int { - { - if north(position) = "X" then 1 else 0 fi - + if south(position) = "X" then 1 else 0 fi - + if east(position) = "X" then 1 else 0 fi - + if west(position) = "X" then 1 else 0 fi - + if northeast(position) = "X" then 1 else 0 fi - + if northwest(position) = "X" then 1 else 0 fi - + if southeast(position) = "X" then 1 else 0 fi - + if southwest(position) = "X" then 1 else 0 fi; - } - }; - - -(* A cell will live if 2 or 3 of it's neighbors are alive. It dies - otherwise. A cell is born if only 3 of it's neighbors are alive. *) - - cell_at_next_evolution(position : Int) : String { - - if neighbors(position) = 3 then - "X" - else - if neighbors(position) = 2 then - if cell(position) = "X" then - "X" - else - "-" - fi - else - "-" - fi fi - }; - - - evolve() : CellularAutomaton { - (let position : Int <- 0 in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; - -(* This is where the background pattern is detremined by the user. More - patterns can be added as long as whoever adds keeps the board either - 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) - option(): String { - { - (let num : Int in - { - out_string("\nPlease chose a number:\n"); - out_string("\t1: A cross\n"); - out_string("\t2: A slash from the upper left to lower right\n"); - out_string("\t3: A slash from the upper right to lower left\n"); - out_string("\t4: An X\n"); - out_string("\t5: A greater than sign \n"); - out_string("\t6: A less than sign\n"); - out_string("\t7: Two greater than signs\n"); - out_string("\t8: Two less than signs\n"); - out_string("\t9: A 'V'\n"); - out_string("\t10: An inverse 'V'\n"); - out_string("\t11: Numbers 9 and 10 combined\n"); - out_string("\t12: A full grid\n"); - out_string("\t13: A 'T'\n"); - out_string("\t14: A plus '+'\n"); - out_string("\t15: A 'W'\n"); - out_string("\t16: An 'M'\n"); - out_string("\t17: An 'E'\n"); - out_string("\t18: A '3'\n"); - out_string("\t19: An 'O'\n"); - out_string("\t20: An '8'\n"); - out_string("\t21: An 'S'\n"); - out_string("Your choice => "); - num <- in_int(); - out_string("\n"); - if num = 1 then - " XX XXXX XXXX XX " - else if num = 2 then - " X X X X X " - else if num = 3 then - "X X X X X" - else if num = 4 then - "X X X X X X X X X" - else if num = 5 then - "X X X X X " - else if num = 6 then - " X X X X X" - else if num = 7 then - "X X X XX X " - else if num = 8 then - " X XX X X X " - else if num = 9 then - "X X X X X " - else if num = 10 then - " X X X X X" - else if num = 11 then - "X X X X X X X X" - else if num = 12 then - "XXXXXXXXXXXXXXXXXXXXXXXXX" - else if num = 13 then - "XXXXX X X X X " - else if num = 14 then - " X X XXXXX X X " - else if num = 15 then - "X X X X X X X " - else if num = 16 then - " X X X X X X X" - else if num = 17 then - "XXXXX X XXXXX X XXXX" - else if num = 18 then - "XXX X X X X XXXX " - else if num = 19 then - " XX X XX X XX " - else if num = 20 then - " XX X XX X XX X XX X XX " - else if num = 21 then - " XXXX X XX X XXXX " - else - " " - fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; - } - ); - } - }; - - - - - prompt() : Bool { - { - (let ans : String in - { - out_string("Would you like to continue with the next generation? \n"); - out_string("Please use lowercase y or n for your answer [y]: "); - ans <- in_string(); - out_string("\n"); - if ans = "n" then - false - else - true - fi; - } - ); - } - }; - - - prompt2() : Bool { - (let ans : String in - { - out_string("\n\n"); - out_string("Would you like to choose a background pattern? \n"); - out_string("Please use lowercase y or n for your answer [n]: "); - ans <- in_string(); - if ans = "y" then - true - else - false - fi; - } - ) - }; - - -}; - -class Main inherits CellularAutomaton { - cells : CellularAutomaton; - - main() : Main { - { - (let continue : Bool in - (let choice : String in - { - out_string("Welcome to the Game of Life.\n"); - out_string("There are many initial states to choose from. \n"); - while prompt2() loop - { - continue <- true; - choice <- option(); - cells <- (new CellularAutomaton).init(choice); - cells.print(); - while continue loop - if prompt() then - { - cells.evolve(); - cells.print(); - } - else - continue <- false - fi - pool; - } - pool; - self; - } ) ); } - }; -}; - +(* The Game of Life + Tendo Kayiira, Summer '95 + With code taken from /private/cool/class/examples/cells.cl + + This introduction was taken off the internet. It gives a brief + description of the Game Of Life. It also gives the rules by which + this particular game follows. + + Introduction + + John Conway's Game of Life is a mathematical amusement, but it + is also much more: an insight into how a system of simple + cellualar automata can create complex, odd, and often aesthetically + pleasing patterns. It is played on a cartesian grid of cells + which are either 'on' or 'off' The game gets it's name from the + similarity between the behaviour of these cells and the behaviour + of living organisms. + + The Rules + + The playfield is a cartesian grid of arbitrary size. Each cell in + this grid can be in an 'on' state or an 'off' state. On each 'turn' + (called a generation,) the state of each cell changes simultaneously + depending on it's state and the state of all cells adjacent to it. + + For 'on' cells, + If the cell has 0 or 1 neighbours which are 'on', the cell turns + 'off'. ('dies of loneliness') + If the cell has 2 or 3 neighbours which are 'on', the cell stays + 'on'. (nothing happens to that cell) + If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', + the cell turns 'off'. ('dies of overcrowding') + + For 'off' cells, + If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which + are 'on', the cell stays 'off'. (nothing happens to that cell) + If the cell has 3 neighbours which are 'on', the cell turns + 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) + + Repeat for as many generations as desired. + + *) + + +class Board inherits IO { + + rows : Int; + columns : Int; + board_size : Int; + + size_of_board(initial : String) : Int { + initial.length() + }; + + board_init(start : String) : Board { + (let size :Int <- size_of_board(start) in + { + if size = 15 then + { + rows <- 3; + columns <- 5; + board_size <- size; + } + else if size = 16 then + { + rows <- 4; + columns <- 4; + board_size <- size; + } + else if size = 20 then + { + rows <- 4; + columns <- 5; + board_size <- size; + } + else if size = 21 then + { + rows <- 3; + columns <- 7; + board_size <- size; + } + else if size = 25 then + { + rows <- 5; + columns <- 5; + board_size <- size; + } + else if size = 28 then + { + rows <- 7; + columns <- 4; + board_size <- size; + } + else -- If none of the above fit, then just give + { -- the configuration of the most common board + rows <- 5; + columns <- 5; + board_size <- size; + } + fi fi fi fi fi fi; + self; + } + ) + }; + +}; + + + +class CellularAutomaton inherits Board { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + board_init(map); + self; + } + }; + + + + + print() : CellularAutomaton { + + (let i : Int <- 0 in + (let num : Int <- board_size in + { + out_string("\n"); + while i < num loop + { + out_string(population_map.substr(i,columns)); + out_string("\n"); + i <- i + columns; + } + pool; + out_string("\n"); + self; + } + ) ) + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + if board_size - 1 < position then + " " + else + population_map.substr(position, 1) + fi + }; + + north(position : Int): String { + if (position - columns) < 0 then + " " + else + cell(position - columns) + fi + }; + + south(position : Int): String { + if board_size < (position + columns) then + " " + else + cell(position + columns) + fi + }; + + east(position : Int): String { + if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + cell(position + 1) + fi + }; + + west(position : Int): String { + if position = 0 then + " " + else + if ((position / columns) * columns) = position then + " " + else + cell(position - 1) + fi fi + }; + + northwest(position : Int): String { + if (position - columns) < 0 then + " " + else if ((position / columns) * columns) = position then + " " + else + north(position - 1) + fi fi + }; + + northeast(position : Int): String { + if (position - columns) < 0 then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + north(position + 1) + fi fi + }; + + southeast(position : Int): String { + if board_size < (position + columns) then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + south(position + 1) + fi fi + }; + + southwest(position : Int): String { + if board_size < (position + columns) then + " " + else if ((position / columns) * columns) = position then + " " + else + south(position - 1) + fi fi + }; + + neighbors(position: Int): Int { + { + if north(position) = "X" then 1 else 0 fi + + if south(position) = "X" then 1 else 0 fi + + if east(position) = "X" then 1 else 0 fi + + if west(position) = "X" then 1 else 0 fi + + if northeast(position) = "X" then 1 else 0 fi + + if northwest(position) = "X" then 1 else 0 fi + + if southeast(position) = "X" then 1 else 0 fi + + if southwest(position) = "X" then 1 else 0 fi; + } + }; + + +(* A cell will live if 2 or 3 of it's neighbors are alive. It dies + otherwise. A cell is born if only 3 of it's neighbors are alive. *) + + cell_at_next_evolution(position : Int) : String { + + if neighbors(position) = 3 then + "X" + else + if neighbors(position) = 2 then + if cell(position) = "X" then + "X" + else + "-" + fi + else + "-" + fi fi + }; + + + evolve() : CellularAutomaton { + (let position : Int <- 0 in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; + +(* This is where the background pattern is detremined by the user. More + patterns can be added as long as whoever adds keeps the board either + 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) + option(): String { + { + (let num : Int in + { + out_string("\nPlease chose a number:\n"); + out_string("\t1: A cross\n"); + out_string("\t2: A slash from the upper left to lower right\n"); + out_string("\t3: A slash from the upper right to lower left\n"); + out_string("\t4: An X\n"); + out_string("\t5: A greater than sign \n"); + out_string("\t6: A less than sign\n"); + out_string("\t7: Two greater than signs\n"); + out_string("\t8: Two less than signs\n"); + out_string("\t9: A 'V'\n"); + out_string("\t10: An inverse 'V'\n"); + out_string("\t11: Numbers 9 and 10 combined\n"); + out_string("\t12: A full grid\n"); + out_string("\t13: A 'T'\n"); + out_string("\t14: A plus '+'\n"); + out_string("\t15: A 'W'\n"); + out_string("\t16: An 'M'\n"); + out_string("\t17: An 'E'\n"); + out_string("\t18: A '3'\n"); + out_string("\t19: An 'O'\n"); + out_string("\t20: An '8'\n"); + out_string("\t21: An 'S'\n"); + out_string("Your choice => "); + num <- in_int(); + out_string("\n"); + if num = 1 then + " XX XXXX XXXX XX " + else if num = 2 then + " X X X X X " + else if num = 3 then + "X X X X X" + else if num = 4 then + "X X X X X X X X X" + else if num = 5 then + "X X X X X " + else if num = 6 then + " X X X X X" + else if num = 7 then + "X X X XX X " + else if num = 8 then + " X XX X X X " + else if num = 9 then + "X X X X X " + else if num = 10 then + " X X X X X" + else if num = 11 then + "X X X X X X X X" + else if num = 12 then + "XXXXXXXXXXXXXXXXXXXXXXXXX" + else if num = 13 then + "XXXXX X X X X " + else if num = 14 then + " X X XXXXX X X " + else if num = 15 then + "X X X X X X X " + else if num = 16 then + " X X X X X X X" + else if num = 17 then + "XXXXX X XXXXX X XXXX" + else if num = 18 then + "XXX X X X X XXXX " + else if num = 19 then + " XX X XX X XX " + else if num = 20 then + " XX X XX X XX X XX X XX " + else if num = 21 then + " XXXX X XX X XXXX " + else + " " + fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; + } + ); + } + }; + + + + + prompt() : Bool { + { + (let ans : String in + { + out_string("Would you like to continue with the next generation? \n"); + out_string("Please use lowercase y or n for your answer [y]: "); + ans <- in_string(); + out_string("\n"); + if ans = "n" then + false + else + true + fi; + } + ); + } + }; + + + prompt2() : Bool { + (let ans : String in + { + out_string("\n\n"); + out_string("Would you like to choose a background pattern? \n"); + out_string("Please use lowercase y or n for your answer [n]: "); + ans <- in_string(); + if ans = "y" then + true + else + false + fi; + } + ) + }; + + +}; + +class Main inherits CellularAutomaton { + cells : CellularAutomaton; + + main() : Main { + { + (let continue : Bool in + (let choice : String in + { + out_string("Welcome to the Game of Life.\n"); + out_string("There are many initial states to choose from. \n"); + while prompt2() loop + { + continue <- true; + choice <- option(); + cells <- (new CellularAutomaton).init(choice); + cells.print(); + while continue loop + if prompt() then + { + cells.evolve(); + cells.print(); + } + else + continue <- false + fi + pool; + } + pool; + self; + } ) ); } + }; +}; + diff --git a/tests/codegen/life_input.txt b/tests/codegen/life_input.txt index 07e016726..1dfbde620 100644 --- a/tests/codegen/life_input.txt +++ b/tests/codegen/life_input.txt @@ -1,66 +1,66 @@ -y -1 -n -y -2 -n -y -3 -n -y -4 -n -y -5 -n -y -6 -n -y -7 -n -y -8 -n -y -9 -n -y -10 -n -y -11 -n -y -12 -n -y -13 -n -y -14 -n -y -15 -n -y -16 -n -y -17 -n -y -18 -n -y -19 -n -y -20 -n -y -21 -y -y -n +y +1 +n +y +2 +n +y +3 +n +y +4 +n +y +5 +n +y +6 +n +y +7 +n +y +8 +n +y +9 +n +y +10 +n +y +11 +n +y +12 +n +y +13 +n +y +14 +n +y +15 +n +y +16 +n +y +17 +n +y +18 +n +y +19 +n +y +20 +n +y +21 +y +y +n n \ No newline at end of file diff --git a/tests/codegen/life_output.txt b/tests/codegen/life_output.txt index 5a9b9f73d..e804b2382 100644 --- a/tests/codegen/life_output.txt +++ b/tests/codegen/life_output.txt @@ -1,778 +1,778 @@ -Welcome to the Game of Life. -There are many initial states to choose from. - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -XXXX -XXXX - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X -X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X -X X - X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X X - X X -X X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX -XXXXX -XXXXX -XXXXX -XXXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X -XXXXX - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X X - X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X - X X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXX -X -X -XXXX -X -X -XXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXX - X - X - X - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XXX -X -X - XX - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X--- --XX- ----X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X-X- --XX- --X-X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? +Welcome to the Game of Life. +There are many initial states to choose from. + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +XXXX +XXXX + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X +X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X +X X + X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X X + X X +X X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX +XXXXX +XXXXX +XXXXX +XXXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X +XXXXX + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X X + X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X + X X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXX +X +X +XXXX +X +X +XXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXX + X + X + X + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XXX +X +X + XX + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X--- +-XX- +---X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X-X- +-XX- +-X-X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? Please use lowercase y or n for your answer [n]: \ No newline at end of file diff --git a/tests/codegen/list_output.txt b/tests/codegen/list_output.txt index fca724903..00d68ed23 100644 --- a/tests/codegen/list_output.txt +++ b/tests/codegen/list_output.txt @@ -1,5 +1,5 @@ -5 4 3 2 1 -4 3 2 1 -3 2 1 -2 1 -1 +5 4 3 2 1 +4 3 2 1 +3 2 1 +2 1 +1 diff --git a/tests/codegen/new_complex.cl b/tests/codegen/new_complex.cl index a4fe714ce..ad7035b56 100755 --- a/tests/codegen/new_complex.cl +++ b/tests/codegen/new_complex.cl @@ -1,79 +1,79 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - { - -- trivially equal (see CoolAid) - if c.reflect_X() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi; - -- equal - if c.reflect_X().reflect_Y().equal(c.reflect_0()) - then out_string("=)\n") - else out_string("=(\n") - fi; - } - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; - - equal(d : Complex) : Bool { - if x = d.x_value() - then - if y = d.y_value() - then true - else false - fi - else false - fi - }; - - x_value() : Int { - x - }; - - y_value() : Int { - y - }; -}; +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + { + -- trivially equal (see CoolAid) + if c.reflect_X() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi; + -- equal + if c.reflect_X().reflect_Y().equal(c.reflect_0()) + then out_string("=)\n") + else out_string("=(\n") + fi; + } + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; + + equal(d : Complex) : Bool { + if x = d.x_value() + then + if y = d.y_value() + then true + else false + fi + else false + fi + }; + + x_value() : Int { + x + }; + + y_value() : Int { + y + }; +}; diff --git a/tests/codegen/new_complex_output.txt b/tests/codegen/new_complex_output.txt index 0e8da112c..831c23af4 100644 --- a/tests/codegen/new_complex_output.txt +++ b/tests/codegen/new_complex_output.txt @@ -1,2 +1,2 @@ -=) -=) +=) +=) diff --git a/tests/codegen/palindrome.cl b/tests/codegen/palindrome.cl index 7f24789f9..6acbeb731 100755 --- a/tests/codegen/palindrome.cl +++ b/tests/codegen/palindrome.cl @@ -1,25 +1,25 @@ -class Main inherits IO { - pal(s : String) : Bool { - if s.length() = 0 - then true - else if s.length() = 1 - then true - else if s.substr(0, 1) = s.substr(s.length() - 1, 1) - then pal(s.substr(1, s.length() -2)) - else false - fi fi fi - }; - - i : Int; - - main() : IO { - { - i <- ~1; - out_string("enter a string\n"); - if pal(in_string()) - then out_string("that was a palindrome\n") - else out_string("that was not a palindrome\n") - fi; - } - }; -}; +class Main inherits IO { + pal(s : String) : Bool { + if s.length() = 0 + then true + else if s.length() = 1 + then true + else if s.substr(0, 1) = s.substr(s.length() - 1, 1) + then pal(s.substr(1, s.length() -2)) + else false + fi fi fi + }; + + i : Int; + + main() : IO { + { + i <- ~1; + out_string("enter a string\n"); + if pal(in_string()) + then out_string("that was a palindrome\n") + else out_string("that was not a palindrome\n") + fi; + } + }; +}; diff --git a/tests/codegen/palindrome_input.txt b/tests/codegen/palindrome_input.txt index 8e1b64142..c49a0114c 100644 --- a/tests/codegen/palindrome_input.txt +++ b/tests/codegen/palindrome_input.txt @@ -1 +1 @@ -anitalabalatina +anitalabalatina diff --git a/tests/codegen/palindrome_output.txt b/tests/codegen/palindrome_output.txt index 7a0095959..e93d36585 100644 --- a/tests/codegen/palindrome_output.txt +++ b/tests/codegen/palindrome_output.txt @@ -1,2 +1,2 @@ -enter a string -that was a palindrome +enter a string +that was a palindrome diff --git a/tests/codegen/primes_output.txt b/tests/codegen/primes_output.txt index a4d0fcb3f..cf5d78d49 100644 --- a/tests/codegen/primes_output.txt +++ b/tests/codegen/primes_output.txt @@ -1,96 +1,96 @@ -2 is trivially prime. -3 is prime. -5 is prime. -7 is prime. -11 is prime. -13 is prime. -17 is prime. -19 is prime. -23 is prime. -29 is prime. -31 is prime. -37 is prime. -41 is prime. -43 is prime. -47 is prime. -53 is prime. -59 is prime. -61 is prime. -67 is prime. -71 is prime. -73 is prime. -79 is prime. -83 is prime. -89 is prime. -97 is prime. -101 is prime. -103 is prime. -107 is prime. -109 is prime. -113 is prime. -127 is prime. -131 is prime. -137 is prime. -139 is prime. -149 is prime. -151 is prime. -157 is prime. -163 is prime. -167 is prime. -173 is prime. -179 is prime. -181 is prime. -191 is prime. -193 is prime. -197 is prime. -199 is prime. -211 is prime. -223 is prime. -227 is prime. -229 is prime. -233 is prime. -239 is prime. -241 is prime. -251 is prime. -257 is prime. -263 is prime. -269 is prime. -271 is prime. -277 is prime. -281 is prime. -283 is prime. -293 is prime. -307 is prime. -311 is prime. -313 is prime. -317 is prime. -331 is prime. -337 is prime. -347 is prime. -349 is prime. -353 is prime. -359 is prime. -367 is prime. -373 is prime. -379 is prime. -383 is prime. -389 is prime. -397 is prime. -401 is prime. -409 is prime. -419 is prime. -421 is prime. -431 is prime. -433 is prime. -439 is prime. -443 is prime. -449 is prime. -457 is prime. -461 is prime. -463 is prime. -467 is prime. -479 is prime. -487 is prime. -491 is prime. -499 is prime. -Abort called from class String +2 is trivially prime. +3 is prime. +5 is prime. +7 is prime. +11 is prime. +13 is prime. +17 is prime. +19 is prime. +23 is prime. +29 is prime. +31 is prime. +37 is prime. +41 is prime. +43 is prime. +47 is prime. +53 is prime. +59 is prime. +61 is prime. +67 is prime. +71 is prime. +73 is prime. +79 is prime. +83 is prime. +89 is prime. +97 is prime. +101 is prime. +103 is prime. +107 is prime. +109 is prime. +113 is prime. +127 is prime. +131 is prime. +137 is prime. +139 is prime. +149 is prime. +151 is prime. +157 is prime. +163 is prime. +167 is prime. +173 is prime. +179 is prime. +181 is prime. +191 is prime. +193 is prime. +197 is prime. +199 is prime. +211 is prime. +223 is prime. +227 is prime. +229 is prime. +233 is prime. +239 is prime. +241 is prime. +251 is prime. +257 is prime. +263 is prime. +269 is prime. +271 is prime. +277 is prime. +281 is prime. +283 is prime. +293 is prime. +307 is prime. +311 is prime. +313 is prime. +317 is prime. +331 is prime. +337 is prime. +347 is prime. +349 is prime. +353 is prime. +359 is prime. +367 is prime. +373 is prime. +379 is prime. +383 is prime. +389 is prime. +397 is prime. +401 is prime. +409 is prime. +419 is prime. +421 is prime. +431 is prime. +433 is prime. +439 is prime. +443 is prime. +449 is prime. +457 is prime. +461 is prime. +463 is prime. +467 is prime. +479 is prime. +487 is prime. +491 is prime. +499 is prime. +Abort called from class String diff --git a/tests/codegen/print-cool_output.txt b/tests/codegen/print-cool_output.txt index 2b58f8985..3c8cd620c 100644 --- a/tests/codegen/print-cool_output.txt +++ b/tests/codegen/print-cool_output.txt @@ -1 +1 @@ -cool +cool diff --git a/tests/codegen/sort-list_input.txt b/tests/codegen/sort-list_input.txt index f599e28b8..d43401489 100644 --- a/tests/codegen/sort-list_input.txt +++ b/tests/codegen/sort-list_input.txt @@ -1 +1 @@ -10 +10 diff --git a/tests/codegen/sort-list_output.txt b/tests/codegen/sort-list_output.txt index 9878d57ea..7b1d40452 100644 --- a/tests/codegen/sort-list_output.txt +++ b/tests/codegen/sort-list_output.txt @@ -1,10 +1,10 @@ -How many numbers to sort? 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 +How many numbers to sort? 0 +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/tests/codegen_test.py b/tests/codegen_test.py index 48df768ff..e748bd2d1 100644 --- a/tests/codegen_test.py +++ b/tests/codegen_test.py @@ -1,17 +1,17 @@ -import pytest -import os -from utils import compare_outputs - -tests_dir = __file__.rpartition('/')[0] + '/codegen/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -# @pytest.mark.lexer -# @pytest.mark.parser -# @pytest.mark.semantic -@pytest.mark.codegen -@pytest.mark.ok -@pytest.mark.run(order=4) -@pytest.mark.parametrize("cool_file", tests) -def test_codegen(compiler_path, cool_file): - compare_outputs(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_input.txt',\ +import pytest +import os +from utils import compare_outputs + +tests_dir = __file__.rpartition('/')[0] + '/codegen/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +# @pytest.mark.lexer +# @pytest.mark.parser +# @pytest.mark.semantic +@pytest.mark.codegen +@pytest.mark.ok +@pytest.mark.run(order=4) +@pytest.mark.parametrize("cool_file", tests) +def test_codegen(compiler_path, cool_file): + compare_outputs(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_input.txt',\ tests_dir + cool_file[:-3] + '_output.txt') \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 1f44eeb72..561d8bafc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ -import pytest -import os - -@pytest.fixture -def compiler_path(): +import pytest +import os + +@pytest.fixture +def compiler_path(): return os.path.abspath('./coolc.sh') \ No newline at end of file diff --git a/tests/lexer/comment1.cl b/tests/lexer/comment1.cl index 69533f23c..1b63af3c7 100644 --- a/tests/lexer/comment1.cl +++ b/tests/lexer/comment1.cl @@ -1,55 +1,55 @@ ---Any characters between two dashes “--” and the next newline ---(or EOF, if there is no next newline) are treated as comments - -(*(*(* -Comments may also be written by enclosing -text in (∗ . . . ∗). The latter form of comment may be nested. -Comments cannot cross file boundaries. -*)*)*) - -class Error() { - - (* There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more. - There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. +--Any characters between two dashes “--” and the next newline +--(or EOF, if there is no next newline) are treated as comments + +(*(*(* +Comments may also be written by enclosing +text in (∗ . . . ∗). The latter form of comment may be nested. +Comments cannot cross file boundaries. +*)*)*) + +class Error() { + + (* There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more. + There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. Alas! The reader could read no more. \ No newline at end of file diff --git a/tests/lexer/comment1_error.txt b/tests/lexer/comment1_error.txt index 9fd7b8d67..710483ee9 100644 --- a/tests/lexer/comment1_error.txt +++ b/tests/lexer/comment1_error.txt @@ -1 +1 @@ -(55, 46) - LexicographicError: EOF in comment +(55, 46) - LexicographicError: EOF in comment diff --git a/tests/lexer/iis1.cl b/tests/lexer/iis1.cl index 12cb52beb..ca6b68ac3 100644 --- a/tests/lexer/iis1.cl +++ b/tests/lexer/iis1.cl @@ -1,111 +1,111 @@ -(* Integers, Identifiers, and Special Notation *) - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -5! = 120, 2 + 2 = 5 or E = mc2; p + 1 @ p = 1: for x in range(len(b)) -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -class Class if then else fi testing Testing ~007agent_bond james_007B0N3SS___ -loop pool while tRuE or noT faLsE let in case of ESAC - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 INT_CONST 5 -#4 ERROR "!" -#4 '=' -#4 INT_CONST 120 -#4 ',' -#4 INT_CONST 2 -#4 '+' -#4 INT_CONST 2 -#4 '=' -#4 INT_CONST 5 -#4 OBJECTID or -#4 TYPEID E -#4 '=' -#4 OBJECTID mc2 -#4 ';' -#4 OBJECTID p -#4 '+' -#4 INT_CONST 1 -#4 '@' -#4 OBJECTID p -#4 '=' -#4 INT_CONST 1 -#4 ':' -#4 OBJECTID for -#4 OBJECTID x -#4 IN -#4 OBJECTID range -#4 '(' -#4 OBJECTID len -#4 '(' -#4 OBJECTID b -#4 ')' -#4 ')' -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#6 CLASS -#6 CLASS -#6 IF -#6 THEN -#6 ELSE -#6 FI -#6 OBJECTID testing -#6 TYPEID Testing -#6 '~' -#6 INT_CONST 007 -#6 OBJECTID agent_bond -#6 OBJECTID james_007B0N3SS___ -#7 LOOP -#7 POOL -#7 WHILE -#7 BOOL_CONST true -#7 OBJECTID or -#7 NOT -#7 BOOL_CONST false -#7 LET -#7 IN -#7 CASE -#7 OF -#7 ESAC +(* Integers, Identifiers, and Special Notation *) + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +5! = 120, 2 + 2 = 5 or E = mc2; p + 1 @ p = 1: for x in range(len(b)) +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +class Class if then else fi testing Testing ~007agent_bond james_007B0N3SS___ +loop pool while tRuE or noT faLsE let in case of ESAC + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 INT_CONST 5 +#4 ERROR "!" +#4 '=' +#4 INT_CONST 120 +#4 ',' +#4 INT_CONST 2 +#4 '+' +#4 INT_CONST 2 +#4 '=' +#4 INT_CONST 5 +#4 OBJECTID or +#4 TYPEID E +#4 '=' +#4 OBJECTID mc2 +#4 ';' +#4 OBJECTID p +#4 '+' +#4 INT_CONST 1 +#4 '@' +#4 OBJECTID p +#4 '=' +#4 INT_CONST 1 +#4 ':' +#4 OBJECTID for +#4 OBJECTID x +#4 IN +#4 OBJECTID range +#4 '(' +#4 OBJECTID len +#4 '(' +#4 OBJECTID b +#4 ')' +#4 ')' +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#6 CLASS +#6 CLASS +#6 IF +#6 THEN +#6 ELSE +#6 FI +#6 OBJECTID testing +#6 TYPEID Testing +#6 '~' +#6 INT_CONST 007 +#6 OBJECTID agent_bond +#6 OBJECTID james_007B0N3SS___ +#7 LOOP +#7 POOL +#7 WHILE +#7 BOOL_CONST true +#7 OBJECTID or +#7 NOT +#7 BOOL_CONST false +#7 LET +#7 IN +#7 CASE +#7 OF +#7 ESAC *) \ No newline at end of file diff --git a/tests/lexer/iis1_error.txt b/tests/lexer/iis1_error.txt index 9e6d66cac..12f62f1ba 100644 --- a/tests/lexer/iis1_error.txt +++ b/tests/lexer/iis1_error.txt @@ -1 +1 @@ -(4, 2) - LexicographicError: ERROR "!" +(4, 2) - LexicographicError: ERROR "!" diff --git a/tests/lexer/iis2.cl b/tests/lexer/iis2.cl index 9b25715d4..d42552494 100644 --- a/tests/lexer/iis2.cl +++ b/tests/lexer/iis2.cl @@ -1,120 +1,120 @@ -(* Integers, Identifiers, and Special Notation *) - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -loop pool while tRuE or noT faLsE let in case of ESAC - -factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 CLASS -#4 CLASS -#4 IF -#4 THEN -#4 ELSE -#4 FI -#4 OBJECTID testing -#4 TYPEID Testing -#4 '~' -#4 INT_CONST 007 -#4 OBJECTID agent_bond -#4 OBJECTID james_007bones___ -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#8 LOOP -#8 POOL -#8 WHILE -#8 BOOL_CONST true -#8 OBJECTID or -#8 NOT -#8 BOOL_CONST false -#8 LET -#8 IN -#8 CASE -#8 OF -#8 ESAC -#10 OBJECTID factorial -#10 '(' -#10 INT_CONST 5 -#10 ')' -#10 '=' -#10 INT_CONST 120 -#10 ',' -#10 INT_CONST 2 -#10 '+' -#10 INT_CONST 2 -#10 '=' -#10 INT_CONST 5 -#10 ERROR "?" -#10 OBJECTID or -#10 TYPEID E -#10 '=' -#10 OBJECTID mc2 -#10 ';' -#10 OBJECTID p -#10 '+' -#10 INT_CONST 1 -#10 OBJECTID resto -#10 OBJECTID p -#10 '=' -#10 INT_CONST 1 -#10 ':' -#10 '(' -#10 '@' -#10 OBJECTID for -#10 OBJECTID x -#10 IN -#10 OBJECTID range -#10 '(' -#10 OBJECTID len -#10 '(' -#10 OBJECTID b -#10 ')' -#10 ')' -#10 ')' +(* Integers, Identifiers, and Special Notation *) + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +loop pool while tRuE or noT faLsE let in case of ESAC + +factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 CLASS +#4 CLASS +#4 IF +#4 THEN +#4 ELSE +#4 FI +#4 OBJECTID testing +#4 TYPEID Testing +#4 '~' +#4 INT_CONST 007 +#4 OBJECTID agent_bond +#4 OBJECTID james_007bones___ +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#8 LOOP +#8 POOL +#8 WHILE +#8 BOOL_CONST true +#8 OBJECTID or +#8 NOT +#8 BOOL_CONST false +#8 LET +#8 IN +#8 CASE +#8 OF +#8 ESAC +#10 OBJECTID factorial +#10 '(' +#10 INT_CONST 5 +#10 ')' +#10 '=' +#10 INT_CONST 120 +#10 ',' +#10 INT_CONST 2 +#10 '+' +#10 INT_CONST 2 +#10 '=' +#10 INT_CONST 5 +#10 ERROR "?" +#10 OBJECTID or +#10 TYPEID E +#10 '=' +#10 OBJECTID mc2 +#10 ';' +#10 OBJECTID p +#10 '+' +#10 INT_CONST 1 +#10 OBJECTID resto +#10 OBJECTID p +#10 '=' +#10 INT_CONST 1 +#10 ':' +#10 '(' +#10 '@' +#10 OBJECTID for +#10 OBJECTID x +#10 IN +#10 OBJECTID range +#10 '(' +#10 OBJECTID len +#10 '(' +#10 OBJECTID b +#10 ')' +#10 ')' +#10 ')' *) \ No newline at end of file diff --git a/tests/lexer/iis2_error.txt b/tests/lexer/iis2_error.txt index 922391a9d..988d0286e 100644 --- a/tests/lexer/iis2_error.txt +++ b/tests/lexer/iis2_error.txt @@ -1 +1 @@ -(10, 30) - LexicographicError: ERROR "?" +(10, 30) - LexicographicError: ERROR "?" diff --git a/tests/lexer/iis3.cl b/tests/lexer/iis3.cl index 0b965ddea..dcd85f960 100644 --- a/tests/lexer/iis3.cl +++ b/tests/lexer/iis3.cl @@ -1,121 +1,121 @@ -(* Integers, Identifiers, and Special Notation *) - -factorial(5) = 120, 2 + 2 = 5 or E = mc^2; p + 1 @ p = 1: z for x in range(len(b))) - -loop pool while tRuE or noT faLsE let in case of ESAC - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) - - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -(* -#3 OBJECTID factorial -#3 '(' -#3 INT_CONST 5 -#3 ')' -#3 '=' -#3 INT_CONST 120 -#3 ',' -#3 INT_CONST 2 -#3 '+' -#3 INT_CONST 2 -#3 '=' -#3 INT_CONST 5 -#3 OBJECTID or -#3 TYPEID E -#3 '=' -#3 OBJECTID mc -#3 ERROR "^" -#3 INT_CONST 2 -#3 ';' -#3 OBJECTID p -#3 '+' -#3 INT_CONST 1 -#3 '@' -#3 OBJECTID p -#3 '=' -#3 INT_CONST 1 -#3 ':' -#3 OBJECTID z -#3 OBJECTID for -#3 OBJECTID x -#3 IN -#3 OBJECTID range -#3 '(' -#3 OBJECTID len -#3 '(' -#3 OBJECTID b -#3 ')' -#3 ')' -#3 ')' -#5 LOOP -#5 POOL -#5 WHILE -#5 BOOL_CONST true -#5 OBJECTID or -#5 NOT -#5 BOOL_CONST false -#5 LET -#5 IN -#5 CASE -#5 OF -#5 ESAC -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#10 INT_CONST 0007 -#10 INT_CONST 123 -#10 '+' -#10 INT_CONST 1 -#10 '-' -#10 INT_CONST 1 -#10 '+' -#10 INT_CONST 90 -#10 '-' -#10 INT_CONST 09 -#10 '+' -#10 INT_CONST 11113 -#10 '-' -#10 INT_CONST 4 -#10 OBJECTID r -#10 '*' -#10 OBJECTID a -#10 '*' -#10 OBJECTID self -#10 '*' -#10 OBJECTID c -#10 '+' -#10 '+' -#11 CLASS -#11 CLASS -#11 IF -#11 THEN -#11 ELSE -#11 FI -#11 OBJECTID testing -#11 TYPEID Testing -#11 '~' -#11 INT_CONST 007 -#11 OBJECTID agent_bond -#11 OBJECTID james_007bones___ +(* Integers, Identifiers, and Special Notation *) + +factorial(5) = 120, 2 + 2 = 5 or E = mc^2; p + 1 @ p = 1: z for x in range(len(b))) + +loop pool while tRuE or noT faLsE let in case of ESAC + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) + + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +(* +#3 OBJECTID factorial +#3 '(' +#3 INT_CONST 5 +#3 ')' +#3 '=' +#3 INT_CONST 120 +#3 ',' +#3 INT_CONST 2 +#3 '+' +#3 INT_CONST 2 +#3 '=' +#3 INT_CONST 5 +#3 OBJECTID or +#3 TYPEID E +#3 '=' +#3 OBJECTID mc +#3 ERROR "^" +#3 INT_CONST 2 +#3 ';' +#3 OBJECTID p +#3 '+' +#3 INT_CONST 1 +#3 '@' +#3 OBJECTID p +#3 '=' +#3 INT_CONST 1 +#3 ':' +#3 OBJECTID z +#3 OBJECTID for +#3 OBJECTID x +#3 IN +#3 OBJECTID range +#3 '(' +#3 OBJECTID len +#3 '(' +#3 OBJECTID b +#3 ')' +#3 ')' +#3 ')' +#5 LOOP +#5 POOL +#5 WHILE +#5 BOOL_CONST true +#5 OBJECTID or +#5 NOT +#5 BOOL_CONST false +#5 LET +#5 IN +#5 CASE +#5 OF +#5 ESAC +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#10 INT_CONST 0007 +#10 INT_CONST 123 +#10 '+' +#10 INT_CONST 1 +#10 '-' +#10 INT_CONST 1 +#10 '+' +#10 INT_CONST 90 +#10 '-' +#10 INT_CONST 09 +#10 '+' +#10 INT_CONST 11113 +#10 '-' +#10 INT_CONST 4 +#10 OBJECTID r +#10 '*' +#10 OBJECTID a +#10 '*' +#10 OBJECTID self +#10 '*' +#10 OBJECTID c +#10 '+' +#10 '+' +#11 CLASS +#11 CLASS +#11 IF +#11 THEN +#11 ELSE +#11 FI +#11 OBJECTID testing +#11 TYPEID Testing +#11 '~' +#11 INT_CONST 007 +#11 OBJECTID agent_bond +#11 OBJECTID james_007bones___ *) \ No newline at end of file diff --git a/tests/lexer/iis3_error.txt b/tests/lexer/iis3_error.txt index b001b6a71..3abc2b556 100644 --- a/tests/lexer/iis3_error.txt +++ b/tests/lexer/iis3_error.txt @@ -1 +1 @@ -(3, 40) - LexicographicError: ERROR "^" +(3, 40) - LexicographicError: ERROR "^" diff --git a/tests/lexer/iis4.cl b/tests/lexer/iis4.cl index 9e7a9cb62..5357ab734 100644 --- a/tests/lexer/iis4.cl +++ b/tests/lexer/iis4.cl @@ -1,120 +1,120 @@ -(* Integers, Identifiers, and Special Notation *) - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 % p = 1: @.@ for x in range(len(b))~ - - -loop pool while tRuE or noT faLsE let in case of ESAC -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -(* -#3 NEW -#3 '/' -#3 ASSIGN -#3 '<' -#3 LE -#3 DARROW -#3 '{' -#3 '(' -#3 TYPEID Int -#3 ':' -#3 TYPEID Objet -#3 ',' -#3 TYPEID Bool -#3 ';' -#3 TYPEID String -#3 '.' -#3 OBJECTID string -#3 TYPEID SELF_TYPE -#3 ISVOID -#3 '}' -#3 ')' -#4 INT_CONST 0007 -#4 INT_CONST 123 -#4 '+' -#4 INT_CONST 1 -#4 '-' -#4 INT_CONST 1 -#4 '+' -#4 INT_CONST 90 -#4 '-' -#4 INT_CONST 09 -#4 '+' -#4 INT_CONST 11113 -#4 '-' -#4 INT_CONST 4 -#4 OBJECTID r -#4 '*' -#4 OBJECTID a -#4 '*' -#4 OBJECTID self -#4 '*' -#4 OBJECTID c -#4 '+' -#4 '+' -#6 OBJECTID factorial -#6 '(' -#6 INT_CONST 5 -#6 ')' -#6 '=' -#6 INT_CONST 120 -#6 ',' -#6 INT_CONST 2 -#6 '+' -#6 INT_CONST 2 -#6 '=' -#6 INT_CONST 5 -#6 OBJECTID or -#6 TYPEID E -#6 '=' -#6 OBJECTID mc2 -#6 ';' -#6 OBJECTID p -#6 '+' -#6 INT_CONST 1 -#6 ERROR "%" -#6 OBJECTID p -#6 '=' -#6 INT_CONST 1 -#6 ':' -#6 '@' -#6 '.' -#6 '@' -#6 OBJECTID for -#6 OBJECTID x -#6 IN -#6 OBJECTID range -#6 '(' -#6 OBJECTID len -#6 '(' -#6 OBJECTID b -#6 ')' -#6 ')' -#6 '~' -#9 LOOP -#9 POOL -#9 WHILE -#9 BOOL_CONST true -#9 OBJECTID or -#9 NOT -#9 BOOL_CONST false -#9 LET -#9 IN -#9 CASE -#9 OF -#9 ESAC -#10 CLASS -#10 CLASS -#10 IF -#10 THEN -#10 ELSE -#10 FI -#10 OBJECTID testing -#10 TYPEID Testing -#10 '~' -#10 INT_CONST 007 -#10 OBJECTID agent_bond -#10 OBJECTID james_007bones___ +(* Integers, Identifiers, and Special Notation *) + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 % p = 1: @.@ for x in range(len(b))~ + + +loop pool while tRuE or noT faLsE let in case of ESAC +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +(* +#3 NEW +#3 '/' +#3 ASSIGN +#3 '<' +#3 LE +#3 DARROW +#3 '{' +#3 '(' +#3 TYPEID Int +#3 ':' +#3 TYPEID Objet +#3 ',' +#3 TYPEID Bool +#3 ';' +#3 TYPEID String +#3 '.' +#3 OBJECTID string +#3 TYPEID SELF_TYPE +#3 ISVOID +#3 '}' +#3 ')' +#4 INT_CONST 0007 +#4 INT_CONST 123 +#4 '+' +#4 INT_CONST 1 +#4 '-' +#4 INT_CONST 1 +#4 '+' +#4 INT_CONST 90 +#4 '-' +#4 INT_CONST 09 +#4 '+' +#4 INT_CONST 11113 +#4 '-' +#4 INT_CONST 4 +#4 OBJECTID r +#4 '*' +#4 OBJECTID a +#4 '*' +#4 OBJECTID self +#4 '*' +#4 OBJECTID c +#4 '+' +#4 '+' +#6 OBJECTID factorial +#6 '(' +#6 INT_CONST 5 +#6 ')' +#6 '=' +#6 INT_CONST 120 +#6 ',' +#6 INT_CONST 2 +#6 '+' +#6 INT_CONST 2 +#6 '=' +#6 INT_CONST 5 +#6 OBJECTID or +#6 TYPEID E +#6 '=' +#6 OBJECTID mc2 +#6 ';' +#6 OBJECTID p +#6 '+' +#6 INT_CONST 1 +#6 ERROR "%" +#6 OBJECTID p +#6 '=' +#6 INT_CONST 1 +#6 ':' +#6 '@' +#6 '.' +#6 '@' +#6 OBJECTID for +#6 OBJECTID x +#6 IN +#6 OBJECTID range +#6 '(' +#6 OBJECTID len +#6 '(' +#6 OBJECTID b +#6 ')' +#6 ')' +#6 '~' +#9 LOOP +#9 POOL +#9 WHILE +#9 BOOL_CONST true +#9 OBJECTID or +#9 NOT +#9 BOOL_CONST false +#9 LET +#9 IN +#9 CASE +#9 OF +#9 ESAC +#10 CLASS +#10 CLASS +#10 IF +#10 THEN +#10 ELSE +#10 FI +#10 OBJECTID testing +#10 TYPEID Testing +#10 '~' +#10 INT_CONST 007 +#10 OBJECTID agent_bond +#10 OBJECTID james_007bones___ *) \ No newline at end of file diff --git a/tests/lexer/iis4_error.txt b/tests/lexer/iis4_error.txt index f24076a8c..aab8f39c1 100644 --- a/tests/lexer/iis4_error.txt +++ b/tests/lexer/iis4_error.txt @@ -1 +1 @@ -(6, 49) - LexicographicError: ERROR "!" +(6, 49) - LexicographicError: ERROR "!" diff --git a/tests/lexer/iis5.cl b/tests/lexer/iis5.cl index d146c0547..f602488b9 100644 --- a/tests/lexer/iis5.cl +++ b/tests/lexer/iis5.cl @@ -1,121 +1,121 @@ -(* Integers, Identifiers, and Special Notation *) - - -loop pool while tRuE or noT faLsE let in case of ESAC -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: [@.@ for x in range(len(b))] - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ - -(* -#4 LOOP -#4 POOL -#4 WHILE -#4 BOOL_CONST true -#4 OBJECTID or -#4 NOT -#4 BOOL_CONST false -#4 LET -#4 IN -#4 CASE -#4 OF -#4 ESAC -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#6 CLASS -#6 CLASS -#6 IF -#6 THEN -#6 ELSE -#6 FI -#6 OBJECTID testing -#6 TYPEID Testing -#6 '~' -#6 INT_CONST 007 -#6 OBJECTID agent_bond -#6 OBJECTID james_007bones___ -#8 OBJECTID factorial -#8 '(' -#8 INT_CONST 5 -#8 ')' -#8 '=' -#8 INT_CONST 120 -#8 ',' -#8 INT_CONST 2 -#8 '+' -#8 INT_CONST 2 -#8 '=' -#8 INT_CONST 5 -#8 OBJECTID or -#8 TYPEID E -#8 '=' -#8 OBJECTID mc2 -#8 ';' -#8 OBJECTID p -#8 '+' -#8 INT_CONST 1 -#8 OBJECTID resto -#8 OBJECTID p -#8 '=' -#8 INT_CONST 1 -#8 ':' -#8 ERROR "[" -#8 '@' -#8 '.' -#8 '@' -#8 OBJECTID for -#8 OBJECTID x -#8 IN -#8 OBJECTID range -#8 '(' -#8 OBJECTID len -#8 '(' -#8 OBJECTID b -#8 ')' -#8 ')' -#8 ERROR "]" -#10 INT_CONST 0007 -#10 INT_CONST 123 -#10 '+' -#10 INT_CONST 1 -#10 '-' -#10 INT_CONST 1 -#10 '+' -#10 INT_CONST 90 -#10 '-' -#10 INT_CONST 09 -#10 '+' -#10 INT_CONST 11113 -#10 '-' -#10 INT_CONST 4 -#10 OBJECTID r -#10 '*' -#10 OBJECTID a -#10 '*' -#10 OBJECTID self -#10 '*' -#10 OBJECTID c -#10 '+' -#10 '+' -*) +(* Integers, Identifiers, and Special Notation *) + + +loop pool while tRuE or noT faLsE let in case of ESAC +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: [@.@ for x in range(len(b))] + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ + +(* +#4 LOOP +#4 POOL +#4 WHILE +#4 BOOL_CONST true +#4 OBJECTID or +#4 NOT +#4 BOOL_CONST false +#4 LET +#4 IN +#4 CASE +#4 OF +#4 ESAC +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#6 CLASS +#6 CLASS +#6 IF +#6 THEN +#6 ELSE +#6 FI +#6 OBJECTID testing +#6 TYPEID Testing +#6 '~' +#6 INT_CONST 007 +#6 OBJECTID agent_bond +#6 OBJECTID james_007bones___ +#8 OBJECTID factorial +#8 '(' +#8 INT_CONST 5 +#8 ')' +#8 '=' +#8 INT_CONST 120 +#8 ',' +#8 INT_CONST 2 +#8 '+' +#8 INT_CONST 2 +#8 '=' +#8 INT_CONST 5 +#8 OBJECTID or +#8 TYPEID E +#8 '=' +#8 OBJECTID mc2 +#8 ';' +#8 OBJECTID p +#8 '+' +#8 INT_CONST 1 +#8 OBJECTID resto +#8 OBJECTID p +#8 '=' +#8 INT_CONST 1 +#8 ':' +#8 ERROR "[" +#8 '@' +#8 '.' +#8 '@' +#8 OBJECTID for +#8 OBJECTID x +#8 IN +#8 OBJECTID range +#8 '(' +#8 OBJECTID len +#8 '(' +#8 OBJECTID b +#8 ')' +#8 ')' +#8 ERROR "]" +#10 INT_CONST 0007 +#10 INT_CONST 123 +#10 '+' +#10 INT_CONST 1 +#10 '-' +#10 INT_CONST 1 +#10 '+' +#10 INT_CONST 90 +#10 '-' +#10 INT_CONST 09 +#10 '+' +#10 INT_CONST 11113 +#10 '-' +#10 INT_CONST 4 +#10 OBJECTID r +#10 '*' +#10 OBJECTID a +#10 '*' +#10 OBJECTID self +#10 '*' +#10 OBJECTID c +#10 '+' +#10 '+' +*) diff --git a/tests/lexer/iis5_error.txt b/tests/lexer/iis5_error.txt index b3dbadcb6..9d6e1a738 100644 --- a/tests/lexer/iis5_error.txt +++ b/tests/lexer/iis5_error.txt @@ -1,2 +1,2 @@ -(8, 62) - LexicographicError: ERROR "[" -(8, 89) - LexicographicError: ERROR "]" +(8, 62) - LexicographicError: ERROR "[" +(8, 89) - LexicographicError: ERROR "]" diff --git a/tests/lexer/iis6.cl b/tests/lexer/iis6.cl index 1042f132b..ba93b19d9 100644 --- a/tests/lexer/iis6.cl +++ b/tests/lexer/iis6.cl @@ -1,125 +1,125 @@ -(* Integers, Identifiers, and Special Notation *) - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: {@.@ for x in range(len(b))} - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) - - -class Class if then else fi testing Testing ~007agent_bond _james_007bones___ - - - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -loop pool while tRuE or noT faLsE let in case of ESAC - -(* -#3 OBJECTID factorial -#3 '(' -#3 INT_CONST 5 -#3 ')' -#3 '=' -#3 INT_CONST 120 -#3 ',' -#3 INT_CONST 2 -#3 '+' -#3 INT_CONST 2 -#3 '=' -#3 INT_CONST 5 -#3 OBJECTID or -#3 TYPEID E -#3 '=' -#3 OBJECTID mc2 -#3 ';' -#3 OBJECTID p -#3 '+' -#3 INT_CONST 1 -#3 OBJECTID resto -#3 OBJECTID p -#3 '=' -#3 INT_CONST 1 -#3 ':' -#3 '{' -#3 '@' -#3 '.' -#3 '@' -#3 OBJECTID for -#3 OBJECTID x -#3 IN -#3 OBJECTID range -#3 '(' -#3 OBJECTID len -#3 '(' -#3 OBJECTID b -#3 ')' -#3 ')' -#3 '}' -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#8 CLASS -#8 CLASS -#8 IF -#8 THEN -#8 ELSE -#8 FI -#8 OBJECTID testing -#8 TYPEID Testing -#8 '~' -#8 INT_CONST 007 -#8 OBJECTID agent_bond -#8 ERROR "_" -#8 OBJECTID james_007bones___ -#12 INT_CONST 0007 -#12 INT_CONST 123 -#12 '+' -#12 INT_CONST 1 -#12 '-' -#12 INT_CONST 1 -#12 '+' -#12 INT_CONST 90 -#12 '-' -#12 INT_CONST 09 -#12 '+' -#12 INT_CONST 11113 -#12 '-' -#12 INT_CONST 4 -#12 OBJECTID r -#12 '*' -#12 OBJECTID a -#12 '*' -#12 OBJECTID self -#12 '*' -#12 OBJECTID c -#12 '+' -#12 '+' -#13 LOOP -#13 POOL -#13 WHILE -#13 BOOL_CONST true -#13 OBJECTID or -#13 NOT -#13 BOOL_CONST false -#13 LET -#13 IN -#13 CASE -#13 OF -#13 ESAC +(* Integers, Identifiers, and Special Notation *) + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: {@.@ for x in range(len(b))} + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) + + +class Class if then else fi testing Testing ~007agent_bond _james_007bones___ + + + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +loop pool while tRuE or noT faLsE let in case of ESAC + +(* +#3 OBJECTID factorial +#3 '(' +#3 INT_CONST 5 +#3 ')' +#3 '=' +#3 INT_CONST 120 +#3 ',' +#3 INT_CONST 2 +#3 '+' +#3 INT_CONST 2 +#3 '=' +#3 INT_CONST 5 +#3 OBJECTID or +#3 TYPEID E +#3 '=' +#3 OBJECTID mc2 +#3 ';' +#3 OBJECTID p +#3 '+' +#3 INT_CONST 1 +#3 OBJECTID resto +#3 OBJECTID p +#3 '=' +#3 INT_CONST 1 +#3 ':' +#3 '{' +#3 '@' +#3 '.' +#3 '@' +#3 OBJECTID for +#3 OBJECTID x +#3 IN +#3 OBJECTID range +#3 '(' +#3 OBJECTID len +#3 '(' +#3 OBJECTID b +#3 ')' +#3 ')' +#3 '}' +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#8 CLASS +#8 CLASS +#8 IF +#8 THEN +#8 ELSE +#8 FI +#8 OBJECTID testing +#8 TYPEID Testing +#8 '~' +#8 INT_CONST 007 +#8 OBJECTID agent_bond +#8 ERROR "_" +#8 OBJECTID james_007bones___ +#12 INT_CONST 0007 +#12 INT_CONST 123 +#12 '+' +#12 INT_CONST 1 +#12 '-' +#12 INT_CONST 1 +#12 '+' +#12 INT_CONST 90 +#12 '-' +#12 INT_CONST 09 +#12 '+' +#12 INT_CONST 11113 +#12 '-' +#12 INT_CONST 4 +#12 OBJECTID r +#12 '*' +#12 OBJECTID a +#12 '*' +#12 OBJECTID self +#12 '*' +#12 OBJECTID c +#12 '+' +#12 '+' +#13 LOOP +#13 POOL +#13 WHILE +#13 BOOL_CONST true +#13 OBJECTID or +#13 NOT +#13 BOOL_CONST false +#13 LET +#13 IN +#13 CASE +#13 OF +#13 ESAC *) \ No newline at end of file diff --git a/tests/lexer/iis6_error.txt b/tests/lexer/iis6_error.txt index d7fad9c79..79a9d5aee 100644 --- a/tests/lexer/iis6_error.txt +++ b/tests/lexer/iis6_error.txt @@ -1 +1 @@ -(8, 60) - LexicographicError: ERROR "_" +(8, 60) - LexicographicError: ERROR "_" diff --git a/tests/lexer/mixed1.cl b/tests/lexer/mixed1.cl index 803d58ef5..d3e520a10 100644 --- a/tests/lexer/mixed1.cl +++ b/tests/lexer/mixed1.cl @@ -1,14 +1,14 @@ -"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 -adsfasklj# -LKldsajf iNhERITS -"lkdsajf" - -(* -#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" -#1 INT_CONST 123 -#2 OBJECTID adsfasklj -#2 ERROR "#" -#3 TYPEID LKldsajf -#3 INHERITS -#4 STR_CONST "lkdsajf" +"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 +adsfasklj# +LKldsajf iNhERITS +"lkdsajf" + +(* +#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" +#1 INT_CONST 123 +#2 OBJECTID adsfasklj +#2 ERROR "#" +#3 TYPEID LKldsajf +#3 INHERITS +#4 STR_CONST "lkdsajf" *) \ No newline at end of file diff --git a/tests/lexer/mixed1_error.txt b/tests/lexer/mixed1_error.txt index 99af5fbdc..a142c2edd 100644 --- a/tests/lexer/mixed1_error.txt +++ b/tests/lexer/mixed1_error.txt @@ -1 +1 @@ -(2, 10) - LexicographicError: ERROR "#" +(2, 10) - LexicographicError: ERROR "#" diff --git a/tests/lexer/mixed2.cl b/tests/lexer/mixed2.cl index 12039e123..759bf9523 100644 --- a/tests/lexer/mixed2.cl +++ b/tests/lexer/mixed2.cl @@ -1,20 +1,20 @@ -"kjas\"lnnsdj\nfljrdsaf" -@.$.@ -@*%*@ -"alkjfldajf""dasfadsf - -(* -#1 STR_CONST "kjas\"lnnsdj\nfljrdsaf" -#2 '@' -#2 '.' -#2 ERROR "$" -#2 '.' -#2 '@' -#3 '@' -#3 '*' -#3 ERROR "%" -#3 '*' -#3 '@' -#4 STR_CONST "alkjfldajf" -#4 ERROR "Unterminated string constant" +"kjas\"lnnsdj\nfljrdsaf" +@.$.@ +@*%*@ +"alkjfldajf""dasfadsf + +(* +#1 STR_CONST "kjas\"lnnsdj\nfljrdsaf" +#2 '@' +#2 '.' +#2 ERROR "$" +#2 '.' +#2 '@' +#3 '@' +#3 '*' +#3 ERROR "%" +#3 '*' +#3 '@' +#4 STR_CONST "alkjfldajf" +#4 ERROR "Unterminated string constant" *) \ No newline at end of file diff --git a/tests/lexer/mixed2_error.txt b/tests/lexer/mixed2_error.txt index 097dc2a07..37cb73ac2 100644 --- a/tests/lexer/mixed2_error.txt +++ b/tests/lexer/mixed2_error.txt @@ -1,3 +1,3 @@ -(2, 3) - LexicographicError: ERROR "$" -(3, 3) - LexicographicError: ERROR "%" -(4, 22) - LexicographicError: Unterminated string constant +(2, 3) - LexicographicError: ERROR "$" +(3, 3) - LexicographicError: ERROR "%" +(4, 22) - LexicographicError: Unterminated string constant diff --git a/tests/lexer/string1.cl b/tests/lexer/string1.cl index 6c3c00833..f0a5bd873 100644 --- a/tests/lexer/string1.cl +++ b/tests/lexer/string1.cl @@ -1,6 +1,6 @@ -(* A non-escaped newline character may not appear in a string *) - -"This \ -is OK" -"This is not +(* A non-escaped newline character may not appear in a string *) + +"This \ +is OK" +"This is not OK" \ No newline at end of file diff --git a/tests/lexer/string1_error.txt b/tests/lexer/string1_error.txt index 078c12bbb..1dd4d70d9 100644 --- a/tests/lexer/string1_error.txt +++ b/tests/lexer/string1_error.txt @@ -1,2 +1,2 @@ -(5, 13) - LexicographicError: Unterminated string constant +(5, 13) - LexicographicError: Unterminated string constant (6, 4) - LexicographicError: EOF in string constant \ No newline at end of file diff --git a/tests/lexer/string2.cl b/tests/lexer/string2.cl index 3704b6ae7..cb3024180 100644 --- a/tests/lexer/string2.cl +++ b/tests/lexer/string2.cl @@ -1,19 +1,19 @@ -(* A string may not contain EOF *) - -" May the Triforce \ - 0 \ - 0v0 \ - 0vvv0 \ - 0vvvvv0 \ - 0vvvvvvv0 \ - 0vvvvvvvvv0 \ - 0vvvvvvvvvvv0 \ - 000000000000000 \ - 0v0 0v0 \ - 0vvv0 0vvv0 \ - 0vvvvv0 0vvvvv0 \ - 0vvvvvvv0 0vvvvvvv0 \ - 0vvvvvvvvv0 0vvvvvvvvv0 \ - 0vvvvvvvvvvv0 0vvvvvvvvvvv0 \ - 00000000000000000000000000000 \ +(* A string may not contain EOF *) + +" May the Triforce \ + 0 \ + 0v0 \ + 0vvv0 \ + 0vvvvv0 \ + 0vvvvvvv0 \ + 0vvvvvvvvv0 \ + 0vvvvvvvvvvv0 \ + 000000000000000 \ + 0v0 0v0 \ + 0vvv0 0vvv0 \ + 0vvvvv0 0vvvvv0 \ + 0vvvvvvv0 0vvvvvvv0 \ + 0vvvvvvvvv0 0vvvvvvvvv0 \ + 0vvvvvvvvvvv0 0vvvvvvvvvvv0 \ + 00000000000000000000000000000 \ be with you! \ No newline at end of file diff --git a/tests/lexer/string4.cl b/tests/lexer/string4.cl index f4d39c027..7ca4eb42b 100644 --- a/tests/lexer/string4.cl +++ b/tests/lexer/string4.cl @@ -1,38 +1,38 @@ -class Main { - str <- "The big brown fox - jumped over the fence"; - main() : Object { - { - out_string("Yay! This is the newest shites ); - } - }; -}; - -(* -#1 CLASS -#1 TYPEID Main -#1 '{' -#2 OBJECTID str -#2 ASSIGN -#3 ERROR "Unterminated string constant" -#3 OBJECTID jumped -#3 OBJECTID over -#3 OBJECTID the -#3 OBJECTID fence -#4 ERROR "Unterminated string constant" -#4 OBJECTID main -#4 '(' -#4 ')' -#4 ':' -#4 TYPEID Object -#4 '{' -#5 '{' -#6 OBJECTID out_string -#6 '(' -#7 ERROR "Unterminated string constant" -#7 '}' -#8 '}' -#8 ';' -#9 '}' -#9 ';' +class Main { + str <- "The big brown fox + jumped over the fence"; + main() : Object { + { + out_string("Yay! This is the newest shites ); + } + }; +}; + +(* +#1 CLASS +#1 TYPEID Main +#1 '{' +#2 OBJECTID str +#2 ASSIGN +#3 ERROR "Unterminated string constant" +#3 OBJECTID jumped +#3 OBJECTID over +#3 OBJECTID the +#3 OBJECTID fence +#4 ERROR "Unterminated string constant" +#4 OBJECTID main +#4 '(' +#4 ')' +#4 ':' +#4 TYPEID Object +#4 '{' +#5 '{' +#6 OBJECTID out_string +#6 '(' +#7 ERROR "Unterminated string constant" +#7 '}' +#8 '}' +#8 ';' +#9 '}' +#9 ';' *) \ No newline at end of file diff --git a/tests/lexer/string4_error.txt b/tests/lexer/string4_error.txt index 5ab0ea847..bf420217c 100644 --- a/tests/lexer/string4_error.txt +++ b/tests/lexer/string4_error.txt @@ -1,3 +1,3 @@ -(2, 30) - LexicographicError: Unterminated string constant -(3, 36) - LexicographicError: Unterminated string constant +(2, 30) - LexicographicError: Unterminated string constant +(3, 36) - LexicographicError: Unterminated string constant (6, 58) - LexicographicError: Unterminated string constant \ No newline at end of file diff --git a/tests/lexer_test.py b/tests/lexer_test.py index 2a27223d3..a21fd880a 100644 --- a/tests/lexer_test.py +++ b/tests/lexer_test.py @@ -1,13 +1,13 @@ -import pytest -import os -from utils import compare_errors - -tests_dir = __file__.rpartition('/')[0] + '/lexer/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.lexer -@pytest.mark.error -@pytest.mark.run(order=1) -@pytest.mark.parametrize("cool_file", tests) -def test_lexer_errors(compiler_path, cool_file): +import pytest +import os +from utils import compare_errors + +tests_dir = __file__.rpartition('/')[0] + '/lexer/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.lexer +@pytest.mark.error +@pytest.mark.run(order=1) +@pytest.mark.parametrize("cool_file", tests) +def test_lexer_errors(compiler_path, cool_file): compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt') \ No newline at end of file diff --git a/tests/parser/assignment1.cl b/tests/parser/assignment1.cl index 75b4c5bbd..e89ade368 100644 --- a/tests/parser/assignment1.cl +++ b/tests/parser/assignment1.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): String { - Test1 <- "Hello World" -- Identifiers begin with a lower case letter - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): String { + Test1 <- "Hello World" -- Identifiers begin with a lower case letter + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/assignment2.cl b/tests/parser/assignment2.cl index 4efb96487..7b8ed54ba 100644 --- a/tests/parser/assignment2.cl +++ b/tests/parser/assignment2.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 - 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): Int { - test1 <-- ~(1 + 2 + 3 + 4 + 5) -- The left side must be an expression - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 - 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): Int { + test1 <-- ~(1 + 2 + 3 + 4 + 5) -- The left side must be an expression + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/assignment3.cl b/tests/parser/assignment3.cl index ff633f331..f54305e27 100644 --- a/tests/parser/assignment3.cl +++ b/tests/parser/assignment3.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): Bool { - test1 <- true++ -- The left side must be an expression - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): Bool { + test1 <- true++ -- The left side must be an expression + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute1.cl b/tests/parser/attribute1.cl index 063a02c02..59740336d 100644 --- a/tests/parser/attribute1.cl +++ b/tests/parser/attribute1.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - -- Attributes names must begin with lowercase letters - Test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + -- Attributes names must begin with lowercase letters + Test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute2.cl b/tests/parser/attribute2.cl index c05211483..337696859 100644 --- a/tests/parser/attribute2.cl +++ b/tests/parser/attribute2.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - -- Type names must begin with uppercase letters - test3: string <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + -- Type names must begin with uppercase letters + test3: string <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute3.cl b/tests/parser/attribute3.cl index d858ae47c..b29b4b26d 100644 --- a/tests/parser/attribute3.cl +++ b/tests/parser/attribute3.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - -- Expected '<-' not '<=' - test3: String <= "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + -- Expected '<-' not '<=' + test3: String <= "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block1.cl b/tests/parser/block1.cl index 3613d9268..f15872812 100644 --- a/tests/parser/block1.cl +++ b/tests/parser/block1.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2 -- Missing ";" - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2 -- Missing ";" + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block2.cl b/tests/parser/block2.cl index f485dd0b1..1f45fca4c 100644 --- a/tests/parser/block2.cl +++ b/tests/parser/block2.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - -- Missing "{" - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + -- Missing "{" + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block3.cl b/tests/parser/block3.cl index ae1598c3b..9b63b0015 100644 --- a/tests/parser/block3.cl +++ b/tests/parser/block3.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - -- Missing "}" - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + -- Missing "}" + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block4.cl b/tests/parser/block4.cl index 8fd883d02..c144dae48 100644 --- a/tests/parser/block4.cl +++ b/tests/parser/block4.cl @@ -1,88 +1,88 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - true++; -- Only expressions - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + true++; -- Only expressions + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case1.cl b/tests/parser/case1.cl index c2f508809..35fe5af53 100644 --- a/tests/parser/case1.cl +++ b/tests/parser/case1.cl @@ -1,91 +1,91 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - -- Every case expression must have at least one branch - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + -- Every case expression must have at least one branch + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case2.cl b/tests/parser/case2.cl index f9162e49f..12cbb87b5 100644 --- a/tests/parser/case2.cl +++ b/tests/parser/case2.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case "2 + 2" of - x: Int => new IO.out_string("Es un entero!") -- Missing ";" - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case "2 + 2" of + x: Int => new IO.out_string("Es un entero!") -- Missing ";" + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case3.cl b/tests/parser/case3.cl index a7eedc18b..8fd851836 100644 --- a/tests/parser/case3.cl +++ b/tests/parser/case3.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + false of - x: Int => new IO.out_string("Es un entero!"); - y: string => new IO.out_string("Es una cadena!"); -- Type identifiers starts with a uppercase letter - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + false of + x: Int => new IO.out_string("Es un entero!"); + y: string => new IO.out_string("Es una cadena!"); -- Type identifiers starts with a uppercase letter + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case4.cl b/tests/parser/case4.cl index 25ca3858f..eb8a3d3a2 100644 --- a/tests/parser/case4.cl +++ b/tests/parser/case4.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case true of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - Mazinger_Z: Bool => new IO.out_string("Es un booleano!"); -- Identifiers starts with a lowercase letter - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case true of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + Mazinger_Z: Bool => new IO.out_string("Es un booleano!"); -- Identifiers starts with a lowercase letter + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case5.cl b/tests/parser/case5.cl index b36c663e1..f0483f1f5 100644 --- a/tests/parser/case5.cl +++ b/tests/parser/case5.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case test2 of - x: Int <- new IO.out_string("Es un entero!"); -- Must be '=>' not '<-'; - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case test2 of + x: Int <- new IO.out_string("Es un entero!"); -- Must be '=>' not '<-'; + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case6.cl b/tests/parser/case6.cl index 66e7df2ab..c49467a89 100644 --- a/tests/parser/case6.cl +++ b/tests/parser/case6.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 -- Missing "of" - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 -- Missing "of" + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/class1.cl b/tests/parser/class1.cl index f4815e3f4..1c0641a94 100644 --- a/tests/parser/class1.cl +++ b/tests/parser/class1.cl @@ -1,20 +1,20 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - testing(): Int { - 2 + 2 - }; -}; - --- Class names must begin with uppercase letters -class alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Class names must begin with uppercase letters +class alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class2.cl b/tests/parser/class2.cl index f363b032a..baf290822 100644 --- a/tests/parser/class2.cl +++ b/tests/parser/class2.cl @@ -1,20 +1,20 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - -CLaSS Test { - testing(): Int { - 2 + 2 - }; -}; - --- Type names must begin with uppercase letters -CLaSS Alpha iNHeRiTS iO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +CLaSS Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Type names must begin with uppercase letters +CLaSS Alpha iNHeRiTS iO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class3.cl b/tests/parser/class3.cl index 0c801372a..5c89c5eb8 100644 --- a/tests/parser/class3.cl +++ b/tests/parser/class3.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Missing semicolon - testing2(a: Alpha, b: Int): Int { - 2 + 2 - } - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Missing semicolon + testing2(a: Alpha, b: Int): Int { + 2 + 2 + } + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class4.cl b/tests/parser/class4.cl index 5c286b5e6..cdfbc313c 100644 --- a/tests/parser/class4.cl +++ b/tests/parser/class4.cl @@ -1,36 +1,36 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - -CLaSS Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Only features - 2 + 2; - - testing3(): String { - "2 + 2" - }; -}; - -CLaSS Alpha iNHeRiTS IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +CLaSS Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Only features + 2 + 2; + + testing3(): String { + "2 + 2" + }; +}; + +CLaSS Alpha iNHeRiTS IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class5.cl b/tests/parser/class5.cl index 3f40c36eb..d6b5c5fda 100644 --- a/tests/parser/class5.cl +++ b/tests/parser/class5.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing '{' -class Test - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing '{' +class Test + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class6.cl b/tests/parser/class6.cl index 8501d2593..af9ecbf15 100644 --- a/tests/parser/class6.cl +++ b/tests/parser/class6.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing '}' -CLaSS Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -; - -CLaSS Alpha iNHeRiTS IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing '}' +CLaSS Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +; + +CLaSS Alpha iNHeRiTS IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/conditional1.cl b/tests/parser/conditional1.cl index 4d546fc44..f03b9c4e6 100644 --- a/tests/parser/conditional1.cl +++ b/tests/parser/conditional1.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - if a.length() < b.length() -- Mising "then" - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - else - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - else - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fi - fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + if a.length() < b.length() -- Mising "then" + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + else + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + else + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fi + fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional2.cl b/tests/parser/conditional2.cl index 4f10c2957..9ebd7fe84 100644 --- a/tests/parser/conditional2.cl +++ b/tests/parser/conditional2.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - if a.length() < b.length() then - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - else - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - else - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - -- Missing "fi" - fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + if a.length() < b.length() then + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + else + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + else + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + -- Missing "fi" + fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional3.cl b/tests/parser/conditional3.cl index 67e991ade..ac143ad42 100644 --- a/tests/parser/conditional3.cl +++ b/tests/parser/conditional3.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - iF a.length() < b.length() tHen - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - elsE - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - eLseif -- elseif isn't a keyword - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + iF a.length() < b.length() tHen + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + elsE + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + eLseif -- elseif isn't a keyword + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional4.cl b/tests/parser/conditional4.cl index 0792fdc85..51337f874 100644 --- a/tests/parser/conditional4.cl +++ b/tests/parser/conditional4.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true++ then 1 else 0 -- Condition must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true++ then 1 else 0 -- Condition must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional5.cl b/tests/parser/conditional5.cl index 0c1e1aad0..399515701 100644 --- a/tests/parser/conditional5.cl +++ b/tests/parser/conditional5.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true then true++ else 0 -- If branch must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true then true++ else 0 -- If branch must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional6.cl b/tests/parser/conditional6.cl index 02310404a..8daa35d7f 100644 --- a/tests/parser/conditional6.cl +++ b/tests/parser/conditional6.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true then 1 else false++ -- Else branch must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true then 1 else false++ -- Else branch must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch1.cl b/tests/parser/dispatch1.cl index 2ca394716..2eba9db03 100644 --- a/tests/parser/dispatch1.cl +++ b/tests/parser/dispatch1.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - Test1.testing4(1, 2).testing4(3, 4).testing4(5, 6) -- Objet identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + Test1.testing4(1, 2).testing4(3, 4).testing4(5, 6) -- Objet identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch2.cl b/tests/parser/dispatch2.cl index 0b57467a1..139eba918 100644 --- a/tests/parser/dispatch2.cl +++ b/tests/parser/dispatch2.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13,) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13,) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch3.cl b/tests/parser/dispatch3.cl index 9f1a5afff..0d88f5c23 100644 --- a/tests/parser/dispatch3.cl +++ b/tests/parser/dispatch3.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).Testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) -- Identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).Testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) -- Identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch4.cl b/tests/parser/dispatch4.cl index d1efc469d..dc13fd762 100644 --- a/tests/parser/dispatch4.cl +++ b/tests/parser/dispatch4.cl @@ -1,53 +1,53 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - self.testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true++) -- Arguments must be expressions - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + self.testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true++) -- Arguments must be expressions + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch5.cl b/tests/parser/dispatch5.cl index 63a5afa79..b7bae25e1 100644 --- a/tests/parser/dispatch5.cl +++ b/tests/parser/dispatch5.cl @@ -1,53 +1,53 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, ,true + fALSE) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, ,true + fALSE) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch6.cl b/tests/parser/dispatch6.cl index 0a953e2e6..6887c60cd 100644 --- a/tests/parser/dispatch6.cl +++ b/tests/parser/dispatch6.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@object.copy() -- Type identifiers begin with a upper case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@object.copy() -- Type identifiers begin with a upper case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch7.cl b/tests/parser/dispatch7.cl index 3ecac4d0f..a9ff1b67a 100644 --- a/tests/parser/dispatch7.cl +++ b/tests/parser/dispatch7.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.Copy() -- Identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.Copy() -- Identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch8.cl b/tests/parser/dispatch8.cl index eef0455ef..c1bb2abba 100644 --- a/tests/parser/dispatch8.cl +++ b/tests/parser/dispatch8.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy(,) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy(,) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch9.cl b/tests/parser/dispatch9.cl index 5fdef22d6..8914a18c2 100644 --- a/tests/parser/dispatch9.cl +++ b/tests/parser/dispatch9.cl @@ -1,61 +1,61 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; - - testing5(): Object { - test1:Object.copy() -- Must be '@' not ':' - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; + + testing5(): Object { + test1:Object.copy() -- Must be '@' not ':' + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let1.cl b/tests/parser/let1.cl index 576ae383c..0e5fc6d17 100644 --- a/tests/parser/let1.cl +++ b/tests/parser/let1.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let Count: Int <- 0, pow: Int <- 1 -- Object identifiers starts with a lowercase letter - in { - -- count <- 0; - -- pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let Count: Int <- 0, pow: Int <- 1 -- Object identifiers starts with a lowercase letter + in { + -- count <- 0; + -- pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let2.cl b/tests/parser/let2.cl index 4cfaef0f8..01d055dac 100644 --- a/tests/parser/let2.cl +++ b/tests/parser/let2.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int, pow: int <- 1 -- Type identifiers starts with a uppercase letter - in { - count <- 0; - -- pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int, pow: int <- 1 -- Type identifiers starts with a uppercase letter + in { + count <- 0; + -- pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let3.cl b/tests/parser/let3.cl index 91e567fd8..b2b2fb005 100644 --- a/tests/parser/let3.cl +++ b/tests/parser/let3.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int, pow: Int, -- Extra comma - in { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int, pow: Int, -- Extra comma + in { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let4.cl b/tests/parser/let4.cl index a716c332d..c7d0ea8e3 100644 --- a/tests/parser/let4.cl +++ b/tests/parser/let4.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- true++, pow: Int <- 1 -- Initialization must be an expression - in { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- true++, pow: Int <- 1 -- Initialization must be an expression + in { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let5.cl b/tests/parser/let5.cl index d974cc138..cc4ed7a99 100644 --- a/tests/parser/let5.cl +++ b/tests/parser/let5.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int = 0, pow: Int -- Must be '<-' not '=' - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int = 0, pow: Int -- Must be '<-' not '=' + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let6.cl b/tests/parser/let6.cl index b6e51d7e1..8bc8c4883 100644 --- a/tests/parser/let6.cl +++ b/tests/parser/let6.cl @@ -1,74 +1,74 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int <- 1 - in false++ -- Let body must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int <- 1 + in false++ -- Let body must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let7.cl b/tests/parser/let7.cl index 6fd63e6a7..816c59845 100644 --- a/tests/parser/let7.cl +++ b/tests/parser/let7.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - (* Missing "in" *) { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + (* Missing "in" *) { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop1.cl b/tests/parser/loop1.cl index 7d0d7688f..2065de506 100644 --- a/tests/parser/loop1.cl +++ b/tests/parser/loop1.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - -- Missing "loop" - count <- count * 2 - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + -- Missing "loop" + count <- count * 2 + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop2.cl b/tests/parser/loop2.cl index a9613c487..70f8cd910 100644 --- a/tests/parser/loop2.cl +++ b/tests/parser/loop2.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - loop - count <- count * 2 - -- Missing "pool" - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + loop + count <- count * 2 + -- Missing "pool" + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop3.cl b/tests/parser/loop3.cl index 860adb4d1..fbb3a56b4 100644 --- a/tests/parser/loop3.cl +++ b/tests/parser/loop3.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count => 1024*1024 -- Condition must be an expression - loop - count <- count * 2 - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count => 1024*1024 -- Condition must be an expression + loop + count <- count * 2 + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop4.cl b/tests/parser/loop4.cl index 0a1194e82..47b0e5f4a 100644 --- a/tests/parser/loop4.cl +++ b/tests/parser/loop4.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - loop - count <- true++ -- While body must be an expression - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + loop + count <- true++ -- While body must be an expression + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method1.cl b/tests/parser/method1.cl index fcfbbcd30..d86661430 100644 --- a/tests/parser/method1.cl +++ b/tests/parser/method1.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Method names must begin with lowercase letters - Testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Method names must begin with lowercase letters + Testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method2.cl b/tests/parser/method2.cl index d5bdfd85c..83648f50d 100644 --- a/tests/parser/method2.cl +++ b/tests/parser/method2.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Parameter names must begin with lowercase letters - testing2(a: Alpha, B: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Parameter names must begin with lowercase letters + testing2(a: Alpha, B: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method3.cl b/tests/parser/method3.cl index 1e5c9eb53..428b25fec 100644 --- a/tests/parser/method3.cl +++ b/tests/parser/method3.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Type names must begin with uppercase letters - testing2(a: Alpha, b: int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Type names must begin with uppercase letters + testing2(a: Alpha, b: int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method4.cl b/tests/parser/method4.cl index 019ada276..52ec07bce 100644 --- a/tests/parser/method4.cl +++ b/tests/parser/method4.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Missing paremeter - testing3(x: Int,): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Missing paremeter + testing3(x: Int,): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method5.cl b/tests/parser/method5.cl index 13127f664..706a3145c 100644 --- a/tests/parser/method5.cl +++ b/tests/parser/method5.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Type names must begin with uppercase letters - testing3(): string { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Type names must begin with uppercase letters + testing3(): string { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method6.cl b/tests/parser/method6.cl index d48cd1293..26ce7f19f 100644 --- a/tests/parser/method6.cl +++ b/tests/parser/method6.cl @@ -1,33 +1,33 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Body can't be empty - testing2(a: Alpha, b: Int): Int { - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Body can't be empty + testing2(a: Alpha, b: Int): Int { + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/mixed1.cl b/tests/parser/mixed1.cl index a27879513..b13e679da 100644 --- a/tests/parser/mixed1.cl +++ b/tests/parser/mixed1.cl @@ -1,100 +1,100 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}-- Mising ";" - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}-- Mising ";" + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/mixed2.cl b/tests/parser/mixed2.cl index f5477e0bb..6776fcc12 100644 --- a/tests/parser/mixed2.cl +++ b/tests/parser/mixed2.cl @@ -1,14 +1,14 @@ -class Main { - main(): Object { - (new Alpha).print() - }; - -}; - -(* Class names must begin with uppercase letters *) -class alpha inherits IO { - print() : Object { - out_string("reached!!\n"); - }; -}; - +class Main { + main(): Object { + (new Alpha).print() + }; + +}; + +(* Class names must begin with uppercase letters *) +class alpha inherits IO { + print() : Object { + out_string("reached!!\n"); + }; +}; + diff --git a/tests/parser/mixed3.cl b/tests/parser/mixed3.cl index 1bdcad743..f5271eb3e 100644 --- a/tests/parser/mixed3.cl +++ b/tests/parser/mixed3.cl @@ -1,40 +1,40 @@ -class Main inherits IO { - main() : Object { - { - out_string("Enter a number to check if number is prime\n"); - let i : Int <- in_int() in { - if(i <= 1) then { - out_string("Invalid Input\n"); - abort(); - } else { - if (isPrime(i) = 1) then - out_string("Number is prime\n") - else - out_string("Number is composite\n") - fi; - } - fi; - }; - } - }; - - mod(i : Int, ) : Int { -- Formal list must be comma separated. A comma does not terminate a list of formals. - i - (i/k)*k - }; - - isPrime(i : Int) : Int { - { - let x : Int <- 2, - c : Int <- 1 in - { - while (not (x = i)) loop - if (mod(i, x) = 0) then { - c <- 0; - x <- i; - } else x <- x + 1 fi - pool; - c; - }; - } - }; -}; +class Main inherits IO { + main() : Object { + { + out_string("Enter a number to check if number is prime\n"); + let i : Int <- in_int() in { + if(i <= 1) then { + out_string("Invalid Input\n"); + abort(); + } else { + if (isPrime(i) = 1) then + out_string("Number is prime\n") + else + out_string("Number is composite\n") + fi; + } + fi; + }; + } + }; + + mod(i : Int, ) : Int { -- Formal list must be comma separated. A comma does not terminate a list of formals. + i - (i/k)*k + }; + + isPrime(i : Int) : Int { + { + let x : Int <- 2, + c : Int <- 1 in + { + while (not (x = i)) loop + if (mod(i, x) = 0) then { + c <- 0; + x <- i; + } else x <- x + 1 fi + pool; + c; + }; + } + }; +}; diff --git a/tests/parser/mixed4.cl b/tests/parser/mixed4.cl index e752253be..47e6ea5e9 100644 --- a/tests/parser/mixed4.cl +++ b/tests/parser/mixed4.cl @@ -1,21 +1,21 @@ -class Main inherits IO { - main() : Object { - { - out_string("Enter number of numbers to multiply\n"); - out_int(prod(in_int())); - out_string("\n"); - } - }; - - prod(i : Int) : Int { - let y : Int <- 1 in { - while (not (i = 0) ) loop { - out_string("Enter Number: "); - y <- y * in_int(Main : Int); -- the parser correctly catches the error here - i <- i - 1; - } - pool; - y; - } - }; -}; +class Main inherits IO { + main() : Object { + { + out_string("Enter number of numbers to multiply\n"); + out_int(prod(in_int())); + out_string("\n"); + } + }; + + prod(i : Int) : Int { + let y : Int <- 1 in { + while (not (i = 0) ) loop { + out_string("Enter Number: "); + y <- y * in_int(Main : Int); -- the parser correctly catches the error here + i <- i - 1; + } + pool; + y; + } + }; +}; diff --git a/tests/parser/mixed5.cl b/tests/parser/mixed5.cl index c9176a890..d4ca68f44 100644 --- a/tests/parser/mixed5.cl +++ b/tests/parser/mixed5.cl @@ -1,20 +1,20 @@ -class Main inherits IO { - str <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; - main() : Object { - { - out_string("Enter number of numbers to multiply\n"); - out_int(prod(in_int())); - out_string("\n"); - } - }; - prod(i : Int) : Int { - let y : Int <- 1 in { - while (not (i = 0) ) loop { - out_string("Enter Number: "); - y <- y * in_int(); - i <- i - 1; - } - y; - } - }; -} +class Main inherits IO { + str <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; + main() : Object { + { + out_string("Enter number of numbers to multiply\n"); + out_int(prod(in_int())); + out_string("\n"); + } + }; + prod(i : Int) : Int { + let y : Int <- 1 in { + while (not (i = 0) ) loop { + out_string("Enter Number: "); + y <- y * in_int(); + i <- i - 1; + } + y; + } + }; +} diff --git a/tests/parser/mixed6.cl b/tests/parser/mixed6.cl index 5da80da31..0a51656c9 100644 --- a/tests/parser/mixed6.cl +++ b/tests/parser/mixed6.cl @@ -1,5 +1,5 @@ -classs Doom { - i : Int <- 0; - main() : Object { - if i = 0 then out_string("This is da real *h*t") - +classs Doom { + i : Int <- 0; + main() : Object { + if i = 0 then out_string("This is da real *h*t") + diff --git a/tests/parser/operation1.cl b/tests/parser/operation1.cl index d38eb72d0..d892ec8a6 100644 --- a/tests/parser/operation1.cl +++ b/tests/parser/operation1.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Missing ')' - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a)/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Missing ')' + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a)/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation2.cl b/tests/parser/operation2.cl index 2dc628359..1f167409a 100644 --- a/tests/parser/operation2.cl +++ b/tests/parser/operation2.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Type identifiers starts with a uppercase letter - in isvoid (3 + a * (x / w + new int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Type identifiers starts with a uppercase letter + in isvoid (3 + a * (x / w + new int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation3.cl b/tests/parser/operation3.cl index 61d6cbfa8..ef125927a 100644 --- a/tests/parser/operation3.cl +++ b/tests/parser/operation3.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Object identifiers starts with a lowercase letter - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~Mazinger_Z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Object identifiers starts with a lowercase letter + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~Mazinger_Z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation4.cl b/tests/parser/operation4.cl index bae7de5b5..2212740e7 100644 --- a/tests/parser/operation4.cl +++ b/tests/parser/operation4.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Double "+" - in isvoid (3 + a * (x / w++ new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Double "+" + in isvoid (3 + a * (x / w++ new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/program2.cl b/tests/parser/program2.cl index f8b16779c..a281c6c14 100644 --- a/tests/parser/program2.cl +++ b/tests/parser/program2.cl @@ -1,20 +1,20 @@ -(* Cool programs are sets of classes *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing semicolon -class Test { - testing(): Int { - 2 + 2 - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* Cool programs are sets of classes *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing semicolon +class Test { + testing(): Int { + 2 + 2 + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/program3.cl b/tests/parser/program3.cl index e27889c57..10d2dc71e 100644 --- a/tests/parser/program3.cl +++ b/tests/parser/program3.cl @@ -1,24 +1,24 @@ -(* Cool programs are sets of classes *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - testing(): Int { - 2 + 2 - }; -}; - --- Only classes -suma(a: Int, b: Int) int { - a + b -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* Cool programs are sets of classes *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Only classes +suma(a: Int, b: Int) int { + a + b +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser_test.py b/tests/parser_test.py index 129c0f20a..166de45de 100644 --- a/tests/parser_test.py +++ b/tests/parser_test.py @@ -1,13 +1,13 @@ -import pytest -import os -from utils import compare_errors - -tests_dir = __file__.rpartition('/')[0] + '/parser/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.parser -@pytest.mark.error -@pytest.mark.run(order=2) -@pytest.mark.parametrize("cool_file", tests) -def test_parser_errors(compiler_path, cool_file): +import pytest +import os +from utils import compare_errors + +tests_dir = __file__.rpartition('/')[0] + '/parser/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.parser +@pytest.mark.error +@pytest.mark.run(order=2) +@pytest.mark.parametrize("cool_file", tests) +def test_parser_errors(compiler_path, cool_file): compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt') \ No newline at end of file diff --git a/tests/semantic/arithmetic1.cl b/tests/semantic/arithmetic1.cl index bf94eb194..65719c064 100644 --- a/tests/semantic/arithmetic1.cl +++ b/tests/semantic/arithmetic1.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic10.cl b/tests/semantic/arithmetic10.cl index bbfe6cdb3..b2488ad7f 100644 --- a/tests/semantic/arithmetic10.cl +++ b/tests/semantic/arithmetic10.cl @@ -1,15 +1,15 @@ -(* -The expression ~ is the integer -complement of . The expression must have static type Int and the entire expression -has static type Int. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in ~new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression ~ is the integer +complement of . The expression must have static type Int and the entire expression +has static type Int. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in ~new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic11.cl b/tests/semantic/arithmetic11.cl index fc067dc1a..05cec0465 100644 --- a/tests/semantic/arithmetic11.cl +++ b/tests/semantic/arithmetic11.cl @@ -1,14 +1,14 @@ -(* -The expression not is the boolean complement of . The expression - must have static type Bool and the entire expression has static type Bool. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in not 1 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression not is the boolean complement of . The expression + must have static type Bool and the entire expression has static type Bool. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in not 1 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic12.cl b/tests/semantic/arithmetic12.cl index 2e012fc41..05a2da918 100644 --- a/tests/semantic/arithmetic12.cl +++ b/tests/semantic/arithmetic12.cl @@ -1,14 +1,14 @@ -(* -The expression not is the boolean complement of . The expression - must have static type Bool and the entire expression has static type Bool. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in not 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression not is the boolean complement of . The expression + must have static type Bool and the entire expression has static type Bool. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in not 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic1_error.txt b/tests/semantic/arithmetic1_error.txt index a74ebf3da..59213724d 100644 --- a/tests/semantic/arithmetic1_error.txt +++ b/tests/semantic/arithmetic1_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int + String +(10, 27) - TypeError: non-Int arguments: Int + String diff --git a/tests/semantic/arithmetic2.cl b/tests/semantic/arithmetic2.cl index 59532573d..f1f0935e2 100644 --- a/tests/semantic/arithmetic2.cl +++ b/tests/semantic/arithmetic2.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 + 2 * 3 / 4 - new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x - new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 + 2 * 3 / 4 - new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x - new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic2_error.txt b/tests/semantic/arithmetic2_error.txt index 2c7952af8..aebc7aab9 100644 --- a/tests/semantic/arithmetic2_error.txt +++ b/tests/semantic/arithmetic2_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int - String +(10, 27) - TypeError: non-Int arguments: Int - String diff --git a/tests/semantic/arithmetic3.cl b/tests/semantic/arithmetic3.cl index b208957f5..df64d8000 100644 --- a/tests/semantic/arithmetic3.cl +++ b/tests/semantic/arithmetic3.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 - 2 + 3 * 4 / new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x / new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 - 2 + 3 * 4 / new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x / new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic3_error.txt b/tests/semantic/arithmetic3_error.txt index 81d88331a..d0af01bb5 100644 --- a/tests/semantic/arithmetic3_error.txt +++ b/tests/semantic/arithmetic3_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int / String +(10, 27) - TypeError: non-Int arguments: Int / String diff --git a/tests/semantic/arithmetic4.cl b/tests/semantic/arithmetic4.cl index 2c7dd4fc9..68512ca44 100644 --- a/tests/semantic/arithmetic4.cl +++ b/tests/semantic/arithmetic4.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic5.cl b/tests/semantic/arithmetic5.cl index bc08c6e82..fd77c7971 100644 --- a/tests/semantic/arithmetic5.cl +++ b/tests/semantic/arithmetic5.cl @@ -1,11 +1,11 @@ ---The static type of the expression is Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +--The static type of the expression is Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic5_error.txt b/tests/semantic/arithmetic5_error.txt index dd5346844..8c67c2f53 100644 --- a/tests/semantic/arithmetic5_error.txt +++ b/tests/semantic/arithmetic5_error.txt @@ -1 +1 @@ -(9, 19) - TypeError: Inferred type Int of initialization of attribute test does not conform to declared type Bool. +(9, 19) - TypeError: Inferred type Int of initialization of attribute test does not conform to declared type Bool. diff --git a/tests/semantic/arithmetic6.cl b/tests/semantic/arithmetic6.cl index a0c3d03ff..d4da66a73 100644 --- a/tests/semantic/arithmetic6.cl +++ b/tests/semantic/arithmetic6.cl @@ -1,11 +1,11 @@ - --The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())); -}; + --The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; diff --git a/tests/semantic/arithmetic6_error.txt b/tests/semantic/arithmetic6_error.txt index 2e43dfc17..a0d67cb48 100644 --- a/tests/semantic/arithmetic6_error.txt +++ b/tests/semantic/arithmetic6_error.txt @@ -1 +1 @@ -(10, 22) - TypeError: non-Int arguments: Int <= String +(10, 22) - TypeError: non-Int arguments: Int <= String diff --git a/tests/semantic/arithmetic7.cl b/tests/semantic/arithmetic7.cl index c00c75cde..b98a4b0e2 100644 --- a/tests/semantic/arithmetic7.cl +++ b/tests/semantic/arithmetic7.cl @@ -1,12 +1,12 @@ - --The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())); -}; - + --The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; + diff --git a/tests/semantic/arithmetic7_error.txt b/tests/semantic/arithmetic7_error.txt index 6f3537117..166bcc8ef 100644 --- a/tests/semantic/arithmetic7_error.txt +++ b/tests/semantic/arithmetic7_error.txt @@ -1 +1 @@ -(10, 22) - TypeError: non-Int arguments: Int < String +(10, 22) - TypeError: non-Int arguments: Int < String diff --git a/tests/semantic/arithmetic8.cl b/tests/semantic/arithmetic8.cl index 3210bdb8a..f3ad37ec4 100644 --- a/tests/semantic/arithmetic8.cl +++ b/tests/semantic/arithmetic8.cl @@ -1,13 +1,13 @@ - --The rules are exactly the same as for the binary arithmetic operations, except that the result is a Bool. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); -}; - - + --The rules are exactly the same as for the binary arithmetic operations, except that the result is a Bool. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +}; + + diff --git a/tests/semantic/arithmetic8_error.txt b/tests/semantic/arithmetic8_error.txt index ebcaa3797..5a8814e1a 100644 --- a/tests/semantic/arithmetic8_error.txt +++ b/tests/semantic/arithmetic8_error.txt @@ -1 +1 @@ -(9, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. +(9, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/arithmetic9.cl b/tests/semantic/arithmetic9.cl index 95579e134..b7b4d3645 100644 --- a/tests/semantic/arithmetic9.cl +++ b/tests/semantic/arithmetic9.cl @@ -1,15 +1,15 @@ -(* -The expression ~ is the integer -complement of . The expression must have static type Int and the entire expression -has static type Int. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 + ~new A.type_name().concat(new B.type_name().concat(new C.type_name())); +(* +The expression ~ is the integer +complement of . The expression must have static type Int and the entire expression +has static type Int. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 + ~new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/assignment1.cl b/tests/semantic/assignment1.cl index 19ab70219..174f93e2b 100644 --- a/tests/semantic/assignment1.cl +++ b/tests/semantic/assignment1.cl @@ -1,7 +1,7 @@ ---The static type of the expression must conform to the declared type of the identifier - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: Int <- "String"; -}; +--The static type of the expression must conform to the declared type of the identifier + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: Int <- "String"; +}; diff --git a/tests/semantic/assignment1_error.txt b/tests/semantic/assignment1_error.txt index 6eb883012..9d05707aa 100644 --- a/tests/semantic/assignment1_error.txt +++ b/tests/semantic/assignment1_error.txt @@ -1 +1 @@ -(6, 18) - TypeError: Inferred type String of initialization of attribute test does not conform to declared type Int. +(6, 18) - TypeError: Inferred type String of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/assignment2.cl b/tests/semantic/assignment2.cl index cace221ae..c7f3d7873 100644 --- a/tests/semantic/assignment2.cl +++ b/tests/semantic/assignment2.cl @@ -1,13 +1,13 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A): B { a <- new C }; - test2(a: A): D { a <- new C }; -}; +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A): B { a <- new C }; + test2(a: A): D { a <- new C }; +}; diff --git a/tests/semantic/assignment2_error.txt b/tests/semantic/assignment2_error.txt index ed10b7f38..55f5aa214 100644 --- a/tests/semantic/assignment2_error.txt +++ b/tests/semantic/assignment2_error.txt @@ -1 +1 @@ -(12, 22) - TypeError: Inferred return type C of method test2 does not conform to declared return type D. +(12, 22) - TypeError: Inferred return type C of method test2 does not conform to declared return type D. diff --git a/tests/semantic/assignment3.cl b/tests/semantic/assignment3.cl index eba0d69e2..9d60a4b6c 100644 --- a/tests/semantic/assignment3.cl +++ b/tests/semantic/assignment3.cl @@ -1,14 +1,14 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A; - b: B <- a <- new C; - d: D <- a <- new C; -}; +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A; + b: B <- a <- new C; + d: D <- a <- new C; +}; diff --git a/tests/semantic/attributes1.cl b/tests/semantic/attributes1.cl index 3fa0440e4..d11ea7cdb 100644 --- a/tests/semantic/attributes1.cl +++ b/tests/semantic/attributes1.cl @@ -1,13 +1,13 @@ ---The static type of the expression must conform to the declared type of the attribute. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - test1: IO <- new Main; - test2: B <- new A; - - main(): IO { out_string("Hello World!")}; +--The static type of the expression must conform to the declared type of the attribute. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + test1: IO <- new Main; + test2: B <- new A; + + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/attributes1_error.txt b/tests/semantic/attributes1_error.txt index 9cb8460c9..22e45b837 100644 --- a/tests/semantic/attributes1_error.txt +++ b/tests/semantic/attributes1_error.txt @@ -1 +1 @@ -(10, 17) - TypeError: Inferred type A of initialization of attribute test2 does not conform to declared type B. +(10, 17) - TypeError: Inferred type A of initialization of attribute test2 does not conform to declared type B. diff --git a/tests/semantic/attributes2.cl b/tests/semantic/attributes2.cl index 7937c2cc8..85c791b5e 100644 --- a/tests/semantic/attributes2.cl +++ b/tests/semantic/attributes2.cl @@ -1,13 +1,13 @@ ---The static type of the expression must conform to the declared type of the attribute. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - test1: IO <- new Main; - test2: C <- new D; - - main(): IO { out_string("Hello World!")}; +--The static type of the expression must conform to the declared type of the attribute. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + test1: IO <- new Main; + test2: C <- new D; + + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/attributes2_error.txt b/tests/semantic/attributes2_error.txt index 6d601b7cd..d7694b0ad 100644 --- a/tests/semantic/attributes2_error.txt +++ b/tests/semantic/attributes2_error.txt @@ -1 +1 @@ -(10, 17) - TypeError: Inferred type D of initialization of attribute test2 does not conform to declared type C. +(10, 17) - TypeError: Inferred type D of initialization of attribute test2 does not conform to declared type C. diff --git a/tests/semantic/attributes3.cl b/tests/semantic/attributes3.cl index 8a67decd1..0c8294fa2 100644 --- a/tests/semantic/attributes3.cl +++ b/tests/semantic/attributes3.cl @@ -1,25 +1,25 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class B inherits A { - b: Bool <- true; -}; -class C inherits B { - c: String <- "C"; -}; -class D inherits B { - d: IO <- new Main.main(); -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!") }; +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class B inherits A { + b: Bool <- true; +}; +class C inherits B { + c: String <- "C"; +}; +class D inherits B { + d: IO <- new Main.main(); +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!") }; }; \ No newline at end of file diff --git a/tests/semantic/attributes3_error.txt b/tests/semantic/attributes3_error.txt index 6195c816c..68a2ba571 100644 --- a/tests/semantic/attributes3_error.txt +++ b/tests/semantic/attributes3_error.txt @@ -1 +1 @@ -(9, 16) - NameError: Undeclared identifier b. +(9, 16) - NameError: Undeclared identifier b. diff --git a/tests/semantic/attributes4.cl b/tests/semantic/attributes4.cl index a7f63adbd..307b185fd 100644 --- a/tests/semantic/attributes4.cl +++ b/tests/semantic/attributes4.cl @@ -1,39 +1,39 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; -}; -class B inherits A { - b: Bool <- true; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class D inherits B { - d: IO <- new Main.main(); - test3(x1: Int, y1: Int): IO { - let x: Int <- x1, y: Int <-y1, c: String <- "C" in { - x <- x + a; - y <- y + a; - if b then new IO.out_string(c) else d fi; - } - }; -}; -class C inherits B { - c: String <- "C"; - test2(x1: Int, y1: Int): IO { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then new IO.out_string(c) else d fi; - } - }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!") }; +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; +}; +class B inherits A { + b: Bool <- true; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class D inherits B { + d: IO <- new Main.main(); + test3(x1: Int, y1: Int): IO { + let x: Int <- x1, y: Int <-y1, c: String <- "C" in { + x <- x + a; + y <- y + a; + if b then new IO.out_string(c) else d fi; + } + }; +}; +class C inherits B { + c: String <- "C"; + test2(x1: Int, y1: Int): IO { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then new IO.out_string(c) else d fi; + } + }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!") }; }; \ No newline at end of file diff --git a/tests/semantic/basics1.cl b/tests/semantic/basics1.cl index 32ae16564..af84ca0c9 100644 --- a/tests/semantic/basics1.cl +++ b/tests/semantic/basics1.cl @@ -1,10 +1,10 @@ --- It is an error to redefine the IO class. - -class IO { - scan(): String { ":)" }; - print(s: String): IO { new IO }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +-- It is an error to redefine the IO class. + +class IO { + scan(): String { ":)" }; + print(s: String): IO { new IO }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/basics1_error.txt b/tests/semantic/basics1_error.txt index 676f5049c..0db23a051 100644 --- a/tests/semantic/basics1_error.txt +++ b/tests/semantic/basics1_error.txt @@ -1 +1 @@ -(3, 7) - SemanticError: Redefinition of basic class IO. +(3, 7) - SemanticError: Redefinition of basic class IO. diff --git a/tests/semantic/basics2.cl b/tests/semantic/basics2.cl index cf2b1cd2f..61399a989 100644 --- a/tests/semantic/basics2.cl +++ b/tests/semantic/basics2.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Int. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Int { - is_prime(): Bool { false }; -}; +-- It is an error to inherit from or redefine Int. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits Int { + is_prime(): Bool { false }; +}; diff --git a/tests/semantic/basics2_error.txt b/tests/semantic/basics2_error.txt index 69a3b6814..e2810833a 100644 --- a/tests/semantic/basics2_error.txt +++ b/tests/semantic/basics2_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class Int. +(7, 18) - SemanticError: Class A cannot inherit class Int. diff --git a/tests/semantic/basics3.cl b/tests/semantic/basics3.cl index fef017a8d..8c28b31e1 100644 --- a/tests/semantic/basics3.cl +++ b/tests/semantic/basics3.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Int. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Int { - is_prime(): Bool { false }; +-- It is an error to inherit from or redefine Int. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Int { + is_prime(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics3_error.txt b/tests/semantic/basics3_error.txt index d8f80cb12..ed382c8eb 100644 --- a/tests/semantic/basics3_error.txt +++ b/tests/semantic/basics3_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Int. +(7, 7) - SemanticError: Redefinition of basic class Int. diff --git a/tests/semantic/basics4.cl b/tests/semantic/basics4.cl index 9266ec79b..4475bc08f 100644 --- a/tests/semantic/basics4.cl +++ b/tests/semantic/basics4.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine String. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits String { - is_palindrome(): Bool { false }; +-- It is an error to inherit from or redefine String. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits String { + is_palindrome(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics4_error.txt b/tests/semantic/basics4_error.txt index d5cd4c3db..bfe08a9a6 100644 --- a/tests/semantic/basics4_error.txt +++ b/tests/semantic/basics4_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class String. +(7, 18) - SemanticError: Class A cannot inherit class String. diff --git a/tests/semantic/basics5.cl b/tests/semantic/basics5.cl index bad5eff13..f0d4dafb3 100644 --- a/tests/semantic/basics5.cl +++ b/tests/semantic/basics5.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine String. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class String { - is_palindrome(): Bool { false }; +-- It is an error to inherit from or redefine String. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class String { + is_palindrome(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics5_error.txt b/tests/semantic/basics5_error.txt index 8437accf7..47b247faa 100644 --- a/tests/semantic/basics5_error.txt +++ b/tests/semantic/basics5_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class String. +(7, 7) - SemanticError: Redefinition of basic class String. diff --git a/tests/semantic/basics6.cl b/tests/semantic/basics6.cl index 47266ebed..c16572a31 100644 --- a/tests/semantic/basics6.cl +++ b/tests/semantic/basics6.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Bool { - xor(b: Bool): Bool { false }; +-- It is an error to inherit from or redefine Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits Bool { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics6_error.txt b/tests/semantic/basics6_error.txt index b4d22da13..9adf1d488 100644 --- a/tests/semantic/basics6_error.txt +++ b/tests/semantic/basics6_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class Bool. +(7, 18) - SemanticError: Class A cannot inherit class Bool. diff --git a/tests/semantic/basics7.cl b/tests/semantic/basics7.cl index 0f30aaec3..38f789245 100644 --- a/tests/semantic/basics7.cl +++ b/tests/semantic/basics7.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Bool { - xor(b: Bool): Bool { false }; +-- It is an error to inherit from or redefine Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Bool { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics7_error.txt b/tests/semantic/basics7_error.txt index 92660ab9f..9f1347200 100644 --- a/tests/semantic/basics7_error.txt +++ b/tests/semantic/basics7_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Bool. +(7, 7) - SemanticError: Redefinition of basic class Bool. diff --git a/tests/semantic/basics8.cl b/tests/semantic/basics8.cl index 3b9697d4f..d45cd941d 100644 --- a/tests/semantic/basics8.cl +++ b/tests/semantic/basics8.cl @@ -1,9 +1,9 @@ --- It is an error redefine Object. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Object { - xor(b: Bool): Bool { false }; +-- It is an error redefine Object. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Object { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics8_error.txt b/tests/semantic/basics8_error.txt index 652f47b30..45767c9c5 100644 --- a/tests/semantic/basics8_error.txt +++ b/tests/semantic/basics8_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Object. +(7, 7) - SemanticError: Redefinition of basic class Object. diff --git a/tests/semantic/blocks1.cl b/tests/semantic/blocks1.cl index 1e928908b..bad9093d7 100644 --- a/tests/semantic/blocks1.cl +++ b/tests/semantic/blocks1.cl @@ -1,31 +1,31 @@ ---The static type of a block is the static type of the last expression. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- { - new A; - { - new B; - { - new C; - { - new D; - { - new E; - { - new F; - }; - }; - }; - }; - }; - }; +--The static type of a block is the static type of the last expression. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- { + new A; + { + new B; + { + new C; + { + new D; + { + new E; + { + new F; + }; + }; + }; + }; + }; + }; }; \ No newline at end of file diff --git a/tests/semantic/blocks1_error.txt b/tests/semantic/blocks1_error.txt index 2f0e2caf3..6bd9d6118 100644 --- a/tests/semantic/blocks1_error.txt +++ b/tests/semantic/blocks1_error.txt @@ -1 +1 @@ -(13, 16) - TypeError: Inferred type F of initialization of attribute test does not conform to declared type B. +(13, 16) - TypeError: Inferred type F of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/case1.cl b/tests/semantic/case1.cl index 82c6a4d61..af452f11c 100644 --- a/tests/semantic/case1.cl +++ b/tests/semantic/case1.cl @@ -1,23 +1,23 @@ ---For each branch, let Ti be the static type of . The static type of a case expression is Join 1≤i≤n Ti. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: B <- case 0 of - b: Bool => new F; - i: Int => new E; - esac; -}; +--For each branch, let Ti be the static type of . The static type of a case expression is Join 1≤i≤n Ti. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: B <- case 0 of + b: Bool => new F; + i: Int => new E; + esac; +}; diff --git a/tests/semantic/case1_error.txt b/tests/semantic/case1_error.txt index f05ce31b9..70c7d16ca 100644 --- a/tests/semantic/case1_error.txt +++ b/tests/semantic/case1_error.txt @@ -1 +1 @@ -(19, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. +(19, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/case2.cl b/tests/semantic/case2.cl index ae97b41da..dbbe4148c 100644 --- a/tests/semantic/case2.cl +++ b/tests/semantic/case2.cl @@ -1,23 +1,23 @@ --- The variables declared on each branch of a case must all have distinct types. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: A <- case 0 of - b: Bool => new F; - i: Bool => new E; - esac; +-- The variables declared on each branch of a case must all have distinct types. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: A <- case 0 of + b: Bool => new F; + i: Bool => new E; + esac; }; \ No newline at end of file diff --git a/tests/semantic/case3.cl b/tests/semantic/case3.cl index da79bbfe6..9ff06336a 100644 --- a/tests/semantic/case3.cl +++ b/tests/semantic/case3.cl @@ -1,23 +1,23 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: A <- case 0 of - b: Bool => new F; - i: Ball => new E; - esac; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: A <- case 0 of + b: Bool => new F; + i: Ball => new E; + esac; }; \ No newline at end of file diff --git a/tests/semantic/class1.cl b/tests/semantic/class1.cl index ed83da9d1..576a3d0eb 100644 --- a/tests/semantic/class1.cl +++ b/tests/semantic/class1.cl @@ -1,9 +1,9 @@ --- Classes may not be redefined. - -class Repeat { - sum(a: Int, b: Int): Int { a + b }; -}; - -class Repeat { - mult(a: Int, b: Int): Int { a * b }; +-- Classes may not be redefined. + +class Repeat { + sum(a: Int, b: Int): Int { a + b }; +}; + +class Repeat { + mult(a: Int, b: Int): Int { a * b }; }; \ No newline at end of file diff --git a/tests/semantic/class1_error.txt b/tests/semantic/class1_error.txt index 19c507672..6337828d0 100644 --- a/tests/semantic/class1_error.txt +++ b/tests/semantic/class1_error.txt @@ -1,2 +1,2 @@ -(7, 5) - SemanticError: Classes may not be redefined - +(7, 5) - SemanticError: Classes may not be redefined + diff --git a/tests/semantic/conditionals1.cl b/tests/semantic/conditionals1.cl index 3446a8b0f..46af8cc73 100644 --- a/tests/semantic/conditionals1.cl +++ b/tests/semantic/conditionals1.cl @@ -1,14 +1,14 @@ ---The predicate must have static type Bool. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A <- if new F then new D else new C fi; +--The predicate must have static type Bool. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A <- if new F then new D else new C fi; }; \ No newline at end of file diff --git a/tests/semantic/conditionals1_error.txt b/tests/semantic/conditionals1_error.txt index b86345359..52db300b9 100644 --- a/tests/semantic/conditionals1_error.txt +++ b/tests/semantic/conditionals1_error.txt @@ -1 +1 @@ -(13, 16) - TypeError: Predicate of 'if' does not have type Bool. +(13, 16) - TypeError: Predicate of 'if' does not have type Bool. diff --git a/tests/semantic/conditionals2.cl b/tests/semantic/conditionals2.cl index 9d6313d75..8814177fc 100644 --- a/tests/semantic/conditionals2.cl +++ b/tests/semantic/conditionals2.cl @@ -1,24 +1,24 @@ -(* -Let T and F be the static types of the branches of the conditional. Then the static type of the -conditional is T t F. (think: Walk towards Object from each of T and F until the paths meet.) -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- if true then - new C - else - if false then new D - else new E fi - fi; - - test: B <- if not true then new F else new E fi; -}; +(* +Let T and F be the static types of the branches of the conditional. Then the static type of the +conditional is T t F. (think: Walk towards Object from each of T and F until the paths meet.) +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if true then + new C + else + if false then new D + else new E fi + fi; + + test: B <- if not true then new F else new E fi; +}; diff --git a/tests/semantic/conditionals2_error.txt b/tests/semantic/conditionals2_error.txt index d6f5fc307..8f54d195e 100644 --- a/tests/semantic/conditionals2_error.txt +++ b/tests/semantic/conditionals2_error.txt @@ -1,2 +1,2 @@ -(23, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. - +(23, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. + diff --git a/tests/semantic/dispatch1.cl b/tests/semantic/dispatch1.cl index 1c0457fa3..bfd90f075 100644 --- a/tests/semantic/dispatch1.cl +++ b/tests/semantic/dispatch1.cl @@ -1,33 +1,33 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- new D.back("Hello ").back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.back("Hello ").back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch1_error.txt b/tests/semantic/dispatch1_error.txt index 7fb22edce..89fa22b77 100644 --- a/tests/semantic/dispatch1_error.txt +++ b/tests/semantic/dispatch1_error.txt @@ -1 +1 @@ -(32, 37) - AttributeError: Dispatch to undefined method back. +(32, 37) - AttributeError: Dispatch to undefined method back. diff --git a/tests/semantic/dispatch2.cl b/tests/semantic/dispatch2.cl index 5182912b8..ebca718ac 100644 --- a/tests/semantic/dispatch2.cl +++ b/tests/semantic/dispatch2.cl @@ -1,34 +1,34 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the dispatch and the definition of f must have the same number of arguments -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: Int <- new D.back("Hello ").g(2, 2); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the dispatch and the definition of f must have the same number of arguments +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: Int <- new D.back("Hello ").g(2, 2); }; \ No newline at end of file diff --git a/tests/semantic/dispatch2_error.txt b/tests/semantic/dispatch2_error.txt index a86c35340..1530fb82c 100644 --- a/tests/semantic/dispatch2_error.txt +++ b/tests/semantic/dispatch2_error.txt @@ -1 +1 @@ -(33, 39) - SemanticError: Method g called with wrong number of arguments. +(33, 39) - SemanticError: Method g called with wrong number of arguments. diff --git a/tests/semantic/dispatch3.cl b/tests/semantic/dispatch3.cl index ecb1535db..98c19da77 100644 --- a/tests/semantic/dispatch3.cl +++ b/tests/semantic/dispatch3.cl @@ -1,36 +1,36 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch3_error.txt b/tests/semantic/dispatch3_error.txt index 0def5cf03..77e81db72 100644 --- a/tests/semantic/dispatch3_error.txt +++ b/tests/semantic/dispatch3_error.txt @@ -1 +1 @@ -(35, 45) - TypeError: In call of method alphabet, type B of parameter c does not conform to declared type C. +(35, 45) - TypeError: In call of method alphabet, type B of parameter c does not conform to declared type C. diff --git a/tests/semantic/dispatch4.cl b/tests/semantic/dispatch4.cl index 9cadd8332..604e462a2 100644 --- a/tests/semantic/dispatch4.cl +++ b/tests/semantic/dispatch4.cl @@ -1,36 +1,36 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -If f has return type B and B is a class name, then the static type of the dispatch is B. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +If f has return type B and B is a class name, then the static type of the dispatch is B. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch5.cl b/tests/semantic/dispatch5.cl index b4437b1b4..9820e5ee1 100644 --- a/tests/semantic/dispatch5.cl +++ b/tests/semantic/dispatch5.cl @@ -1,31 +1,31 @@ -(* -(,...,) is shorthand for self.(,...,). -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; - sum(m: Int, n: Int, p: Int): Int { m + n + p }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - - back(s: String): B { { - out_string(s); - g(2); - sum(1, 2, 3); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +(,...,) is shorthand for self.(,...,). +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; + sum(m: Int, n: Int, p: Int): Int { m + n + p }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + + back(s: String): B { { + out_string(s); + g(2); + sum(1, 2, 3); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/dispatch5_error.txt b/tests/semantic/dispatch5_error.txt index d26bf34a1..6a6922f32 100644 --- a/tests/semantic/dispatch5_error.txt +++ b/tests/semantic/dispatch5_error.txt @@ -1 +1 @@ -(24, 9) - AttributeError: Dispatch to undefined method sum. +(24, 9) - AttributeError: Dispatch to undefined method sum. diff --git a/tests/semantic/dispatch6.cl b/tests/semantic/dispatch6.cl index fcc033f2c..bbe58fbb1 100644 --- a/tests/semantic/dispatch6.cl +++ b/tests/semantic/dispatch6.cl @@ -1,32 +1,32 @@ -(* -e@B.f() invokes the method -f in class B on the object that is the value of e. For this form of dispatch, the static type to the left of -“@”must conform to the type specified to the right of “@”. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; - sum(m: Int, n: Int, p: Int): Int { m + n + p }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - sum(v: Int, w: Int, z: Int): Int { v - w - z }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A <- new D; - b: Int <- new D@B.sum(1, 2, 3); - test: Int <- a@B.sum(1, 2, 3); -}; +(* +e@B.f() invokes the method +f in class B on the object that is the value of e. For this form of dispatch, the static type to the left of +“@”must conform to the type specified to the right of “@”. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; + sum(m: Int, n: Int, p: Int): Int { m + n + p }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + sum(v: Int, w: Int, z: Int): Int { v - w - z }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A <- new D; + b: Int <- new D@B.sum(1, 2, 3); + test: Int <- a@B.sum(1, 2, 3); +}; diff --git a/tests/semantic/dispatch6_error.txt b/tests/semantic/dispatch6_error.txt index ae9184b2f..7d5ec3780 100644 --- a/tests/semantic/dispatch6_error.txt +++ b/tests/semantic/dispatch6_error.txt @@ -1 +1 @@ -(31, 18) - TypeError: Expression type A does not conform to declared static dispatch type B. +(31, 18) - TypeError: Expression type A does not conform to declared static dispatch type B. diff --git a/tests/semantic/eq1.cl b/tests/semantic/eq1.cl index 88f2a7ffe..dc8a0cd43 100644 --- a/tests/semantic/eq1.cl +++ b/tests/semantic/eq1.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - test: Bool <- 1 = new A; - y: Bool <- "1" = "2"; - z: Bool <- true = not false; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + test: Bool <- 1 = new A; + y: Bool <- "1" = "2"; + z: Bool <- true = not false; }; \ No newline at end of file diff --git a/tests/semantic/eq1_error.txt b/tests/semantic/eq1_error.txt index f81425683..0b85d2fa0 100644 --- a/tests/semantic/eq1_error.txt +++ b/tests/semantic/eq1_error.txt @@ -1 +1 @@ -(14, 21) - TypeError: Illegal comparison with a basic type. +(14, 21) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq2.cl b/tests/semantic/eq2.cl index d76852780..f4b2ffac7 100644 --- a/tests/semantic/eq2.cl +++ b/tests/semantic/eq2.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - test: Bool <- "1" = new B; - z: Bool <- true = not false; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + test: Bool <- "1" = new B; + z: Bool <- true = not false; +}; diff --git a/tests/semantic/eq2_error.txt b/tests/semantic/eq2_error.txt index a44ab0d51..1bb29ca32 100644 --- a/tests/semantic/eq2_error.txt +++ b/tests/semantic/eq2_error.txt @@ -1 +1 @@ -(15, 23) - TypeError: Illegal comparison with a basic type. +(15, 23) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq3.cl b/tests/semantic/eq3.cl index 4dad693ee..b7ee462c5 100644 --- a/tests/semantic/eq3.cl +++ b/tests/semantic/eq3.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - z: Bool <- true = not false; - test: Bool <- "true" = not false; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + z: Bool <- true = not false; + test: Bool <- "true" = not false; +}; diff --git a/tests/semantic/eq3_error.txt b/tests/semantic/eq3_error.txt index c4e27eb8a..d57841b95 100644 --- a/tests/semantic/eq3_error.txt +++ b/tests/semantic/eq3_error.txt @@ -1 +1 @@ -(16, 26) - TypeError: Illegal comparison with a basic type. +(16, 26) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq4.cl b/tests/semantic/eq4.cl index 11afc119f..63c1067f0 100644 --- a/tests/semantic/eq4.cl +++ b/tests/semantic/eq4.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. The result is a Bool. -*) - -class A { }; -class B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - z: Bool <- new A = new B; - test: Int <- new A = new B; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. The result is a Bool. +*) + +class A { }; +class B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + z: Bool <- new A = new B; + test: Int <- new A = new B; +}; diff --git a/tests/semantic/eq4_error.txt b/tests/semantic/eq4_error.txt index 3ead21d0e..f075fecbe 100644 --- a/tests/semantic/eq4_error.txt +++ b/tests/semantic/eq4_error.txt @@ -1 +1 @@ -(16, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. +(16, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/isvoid1.cl b/tests/semantic/isvoid1.cl index 072720d85..7c3a83a77 100644 --- a/tests/semantic/isvoid1.cl +++ b/tests/semantic/isvoid1.cl @@ -1,26 +1,26 @@ ---evaluates to true if expr is void and evaluates to false if expr is not void. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- if isvoid new F then - new C - else - if false then new D - else new E fi - fi; - - test: B <- isvoid if isvoid new F then - new C - else - if false then new D - else new E fi - fi; +--evaluates to true if expr is void and evaluates to false if expr is not void. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if isvoid new F then + new C + else + if false then new D + else new E fi + fi; + + test: B <- isvoid if isvoid new F then + new C + else + if false then new D + else new E fi + fi; }; \ No newline at end of file diff --git a/tests/semantic/isvoid1_error.txt b/tests/semantic/isvoid1_error.txt index 0922de909..3fd0157b4 100644 --- a/tests/semantic/isvoid1_error.txt +++ b/tests/semantic/isvoid1_error.txt @@ -1 +1 @@ -(20, 16) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type B. +(20, 16) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/let1.cl b/tests/semantic/let1.cl index 26ef63026..9220d3dbc 100644 --- a/tests/semantic/let1.cl +++ b/tests/semantic/let1.cl @@ -1,15 +1,15 @@ ---The type of an initialization expression must conform to the declared type of the identifier. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: C <- new E in b; +--The type of an initialization expression must conform to the declared type of the identifier. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: C <- new E in b; }; \ No newline at end of file diff --git a/tests/semantic/let1_error.txt b/tests/semantic/let1_error.txt index 16ecf780c..56547dae5 100644 --- a/tests/semantic/let1_error.txt +++ b/tests/semantic/let1_error.txt @@ -1 +1 @@ -(14, 76) - TypeError: Inferred type E of initialization of b does not conform to identifier's declared type C. +(14, 76) - TypeError: Inferred type E of initialization of b does not conform to identifier's declared type C. diff --git a/tests/semantic/let2.cl b/tests/semantic/let2.cl index c5956ead3..2949fb94d 100644 --- a/tests/semantic/let2.cl +++ b/tests/semantic/let2.cl @@ -1,15 +1,15 @@ ---The type of let is the type of the body. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: A <- new E in b; +--The type of let is the type of the body. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: A <- new E in b; }; \ No newline at end of file diff --git a/tests/semantic/let2_error.txt b/tests/semantic/let2_error.txt index b1e8a365d..3b7c669a3 100644 --- a/tests/semantic/let2_error.txt +++ b/tests/semantic/let2_error.txt @@ -1 +1 @@ -(14, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. +(14, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/let3.cl b/tests/semantic/let3.cl index 8c0670ab8..0a4a9ceaf 100644 --- a/tests/semantic/let3.cl +++ b/tests/semantic/let3.cl @@ -1,15 +1,15 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: Cadena in new B; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: Cadena in new B; }; \ No newline at end of file diff --git a/tests/semantic/loops1.cl b/tests/semantic/loops1.cl index de3a624d2..6a0a81818 100644 --- a/tests/semantic/loops1.cl +++ b/tests/semantic/loops1.cl @@ -1,8 +1,8 @@ ---The predicate must have static type Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - i: Int <- 1; - test: Object <- while "true" loop i <- i + 1 pool; +--The predicate must have static type Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + i: Int <- 1; + test: Object <- while "true" loop i <- i + 1 pool; }; \ No newline at end of file diff --git a/tests/semantic/loops2.cl b/tests/semantic/loops2.cl index dea69fa14..d52169da7 100644 --- a/tests/semantic/loops2.cl +++ b/tests/semantic/loops2.cl @@ -1,9 +1,9 @@ ---The static type of a loop expression is Object. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - i: Int <- 1; - test: Object <- while not false loop i <- i + 1 pool; - test2: Int <- while not false loop i <- i + 1 pool; -}; +--The static type of a loop expression is Object. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + i: Int <- 1; + test: Object <- while not false loop i <- i + 1 pool; + test2: Int <- while not false loop i <- i + 1 pool; +}; diff --git a/tests/semantic/loops2_error.txt b/tests/semantic/loops2_error.txt index 9711cdf6a..ab79de8da 100644 --- a/tests/semantic/loops2_error.txt +++ b/tests/semantic/loops2_error.txt @@ -1 +1 @@ -(8, 19) - TypeError: Inferred type Object of initialization of attribute test2 does not conform to declared type Int. +(8, 19) - TypeError: Inferred type Object of initialization of attribute test2 does not conform to declared type Int. diff --git a/tests/semantic/methods1.cl b/tests/semantic/methods1.cl index d12031970..f4ff07bb0 100644 --- a/tests/semantic/methods1.cl +++ b/tests/semantic/methods1.cl @@ -1,12 +1,12 @@ ---The identifiers used in the formal parameter list must be distinct - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, a: B): Int { 4 }; +--The identifiers used in the formal parameter list must be distinct + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, a: B): Int { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/methods1_error.txt b/tests/semantic/methods1_error.txt index 06ab88a92..809036803 100644 --- a/tests/semantic/methods1_error.txt +++ b/tests/semantic/methods1_error.txt @@ -1 +1 @@ -(11, 16) - SemanticError: Formal parameter a is multiply defined. +(11, 16) - SemanticError: Formal parameter a is multiply defined. diff --git a/tests/semantic/methods2.cl b/tests/semantic/methods2.cl index 3865f0e13..c010df01e 100644 --- a/tests/semantic/methods2.cl +++ b/tests/semantic/methods2.cl @@ -1,12 +1,12 @@ ---The type of the method body must conform to the declared return type. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: B): C { new D }; +--The type of the method body must conform to the declared return type. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: B): C { new D }; }; \ No newline at end of file diff --git a/tests/semantic/methods2_error.txt b/tests/semantic/methods2_error.txt index f7e4a330d..1a4baea17 100644 --- a/tests/semantic/methods2_error.txt +++ b/tests/semantic/methods2_error.txt @@ -1 +1 @@ -(11, 27) - TypeError: Inferred return type D of method test does not conform to declared return type C. +(11, 27) - TypeError: Inferred return type D of method test does not conform to declared return type C. diff --git a/tests/semantic/methods3.cl b/tests/semantic/methods3.cl index b92faeb97..9aff4d167 100644 --- a/tests/semantic/methods3.cl +++ b/tests/semantic/methods3.cl @@ -1,14 +1,14 @@ ---A formal parameter hides any definition of an attribute of the same name. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: C <- new C; - test(a: D): D { a }; - test2(a: B): C { a }; +--A formal parameter hides any definition of an attribute of the same name. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: C <- new C; + test(a: D): D { a }; + test2(a: B): C { a }; }; \ No newline at end of file diff --git a/tests/semantic/methods3_error.txt b/tests/semantic/methods3_error.txt index 1165b7595..a0f6d9db2 100644 --- a/tests/semantic/methods3_error.txt +++ b/tests/semantic/methods3_error.txt @@ -1 +1 @@ -(13, 22) - TypeError: Inferred return type B of method test2 does not conform to declared return type C. +(13, 22) - TypeError: Inferred return type B of method test2 does not conform to declared return type C. diff --git a/tests/semantic/methods4.cl b/tests/semantic/methods4.cl index be8fa36ef..e093bac1c 100644 --- a/tests/semantic/methods4.cl +++ b/tests/semantic/methods4.cl @@ -1,19 +1,19 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; -}; -class B inherits A { - f(x: Int, y: Object): Int { x }; -}; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; +}; +class B inherits A { + f(x: Int, y: Object): Int { x }; +}; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/methods4_error.txt b/tests/semantic/methods4_error.txt index 9f1486dec..c9fc2d12a 100644 --- a/tests/semantic/methods4_error.txt +++ b/tests/semantic/methods4_error.txt @@ -1 +1 @@ -(12, 15) - SemanticError: In redefined method f, parameter type Object is different from original type Int. +(12, 15) - SemanticError: In redefined method f, parameter type Object is different from original type Int. diff --git a/tests/semantic/methods5.cl b/tests/semantic/methods5.cl index 3905dfdd6..732e4d408 100644 --- a/tests/semantic/methods5.cl +++ b/tests/semantic/methods5.cl @@ -1,20 +1,20 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; -}; -class B inherits A { - f(a: Int, b: Int): Object { a - b }; -}; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; +}; +class B inherits A { + f(a: Int, b: Int): Object { a - b }; +}; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + diff --git a/tests/semantic/methods5_error.txt b/tests/semantic/methods5_error.txt index 8b6bdf36e..073eee8c5 100644 --- a/tests/semantic/methods5_error.txt +++ b/tests/semantic/methods5_error.txt @@ -1 +1 @@ -(12, 24) - SemanticError: In redefined method f, return type Object is different from original return type Int. +(12, 24) - SemanticError: In redefined method f, return type Object is different from original return type Int. diff --git a/tests/semantic/methods6.cl b/tests/semantic/methods6.cl index dd2b73da6..61a62b4b0 100644 --- a/tests/semantic/methods6.cl +++ b/tests/semantic/methods6.cl @@ -1,27 +1,27 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int, w: Int, z: Int): Int { v + w + z }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int, w: Int, z: Int): Int { v + w + z }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/methods6_error.txt b/tests/semantic/methods6_error.txt index 8e32663b9..70ad02e32 100644 --- a/tests/semantic/methods6_error.txt +++ b/tests/semantic/methods6_error.txt @@ -1 +1 @@ -(22, 5) - SemanticError: Incompatible number of formal parameters in redefined method g. +(22, 5) - SemanticError: Incompatible number of formal parameters in redefined method g. diff --git a/tests/semantic/methods7.cl b/tests/semantic/methods7.cl index e5a01f682..21e8ca275 100644 --- a/tests/semantic/methods7.cl +++ b/tests/semantic/methods7.cl @@ -1,12 +1,12 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: Ball): Int { 4 }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: Ball): Int { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/methods8.cl b/tests/semantic/methods8.cl index 3fccab54c..121210748 100644 --- a/tests/semantic/methods8.cl +++ b/tests/semantic/methods8.cl @@ -1,12 +1,12 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: B): Integrer { 4 }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: B): Integrer { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/new1.cl b/tests/semantic/new1.cl index d007fc03d..40a8b9e9b 100644 --- a/tests/semantic/new1.cl +++ b/tests/semantic/new1.cl @@ -1,31 +1,31 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: F <- { - new A; - { - new Ball; - { - new C; - { - new D; - { - new E; - { - new F; - }; - }; - }; - }; - }; - }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: F <- { + new A; + { + new Ball; + { + new C; + { + new D; + { + new E; + { + new F; + }; + }; + }; + }; + }; + }; }; \ No newline at end of file diff --git a/tests/semantic/self1.cl b/tests/semantic/self1.cl index 3387fd263..399f6ff06 100644 --- a/tests/semantic/self1.cl +++ b/tests/semantic/self1.cl @@ -1,11 +1,11 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: Main): IO { self <- a }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: Main): IO { self <- a }; +}; diff --git a/tests/semantic/self1_error.txt b/tests/semantic/self1_error.txt index 6beb3cda2..f9f51b9b3 100644 --- a/tests/semantic/self1_error.txt +++ b/tests/semantic/self1_error.txt @@ -1 +1 @@ -(10, 30) - SemanticError: Cannot assign to 'self'. +(10, 30) - SemanticError: Cannot assign to 'self'. diff --git a/tests/semantic/self2.cl b/tests/semantic/self2.cl index 2e6921a92..6ef75e368 100644 --- a/tests/semantic/self2.cl +++ b/tests/semantic/self2.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(): IO { let self: Main <- new Main in self }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(): IO { let self: Main <- new Main in self }; +}; diff --git a/tests/semantic/self2_error.txt b/tests/semantic/self2_error.txt index 20c883c91..2e53bb210 100644 --- a/tests/semantic/self2_error.txt +++ b/tests/semantic/self2_error.txt @@ -1 +1 @@ -(9, 22) - SemanticError: 'self' cannot be bound in a 'let' expression. +(9, 22) - SemanticError: 'self' cannot be bound in a 'let' expression. diff --git a/tests/semantic/self3.cl b/tests/semantic/self3.cl index 81709b4b5..d314798a9 100644 --- a/tests/semantic/self3.cl +++ b/tests/semantic/self3.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(self: IO): IO { self }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(self: IO): IO { self }; +}; diff --git a/tests/semantic/self3_error.txt b/tests/semantic/self3_error.txt index 0ae382007..0015bbe0a 100644 --- a/tests/semantic/self3_error.txt +++ b/tests/semantic/self3_error.txt @@ -1 +1 @@ -(9, 10) - SemanticError: 'self' cannot be the name of a formal parameter. +(9, 10) - SemanticError: 'self' cannot be the name of a formal parameter. diff --git a/tests/semantic/self4.cl b/tests/semantic/self4.cl index 7c2b960cb..9185c8760 100644 --- a/tests/semantic/self4.cl +++ b/tests/semantic/self4.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - self: IO <- self; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + self: IO <- self; }; \ No newline at end of file diff --git a/tests/semantic/self4_error.txt b/tests/semantic/self4_error.txt index c19ca400f..bf8740604 100644 --- a/tests/semantic/self4_error.txt +++ b/tests/semantic/self4_error.txt @@ -1 +1 @@ -(9, 5) - SemanticError: 'self' cannot be the name of an attribute. +(9, 5) - SemanticError: 'self' cannot be the name of an attribute. diff --git a/tests/semantic_test.py b/tests/semantic_test.py index cac9cd78b..46f07439d 100644 --- a/tests/semantic_test.py +++ b/tests/semantic_test.py @@ -1,14 +1,14 @@ -import pytest -import os -from utils import compare_errors, first_error_only_line - -tests_dir = __file__.rpartition('/')[0] + '/semantic/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.semantic -@pytest.mark.error -@pytest.mark.run(order=3) -@pytest.mark.parametrize("cool_file", tests) -def test_semantic_errors(compiler_path, cool_file): - compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt', \ +import pytest +import os +from utils import compare_errors, first_error_only_line + +tests_dir = __file__.rpartition('/')[0] + '/semantic/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.semantic +@pytest.mark.error +@pytest.mark.run(order=3) +@pytest.mark.parametrize("cool_file", tests) +def test_semantic_errors(compiler_path, cool_file): + compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt', \ cmp=first_error_only_line) \ No newline at end of file diff --git a/tests/utils/utils.py b/tests/utils/utils.py index 961cf7cbc..f98d19dd0 100644 --- a/tests/utils/utils.py +++ b/tests/utils/utils.py @@ -1,91 +1,91 @@ -import subprocess -import re - - -COMPILER_TIMEOUT = 'El compilador tarda mucho en responder.' -SPIM_TIMEOUT = 'El spim tarda mucho en responder.' -TEST_MUST_FAIL = 'El test %s debe fallar al compilar' -TEST_MUST_COMPILE = 'El test %s debe compilar' -BAD_ERROR_FORMAT = '''El error no esta en formato: (,) - : - o no se encuentra en la 3ra linea\n\n%s''' -UNEXPECTED_ERROR = 'Se esperaba un %s en (%d, %d). Su error fue un %s en (%d, %d)' -UNEXPECTED_OUTPUT = 'La salida de %s no es la esperada:\n%s\nEsperada:\n%s' - -ERROR_FORMAT = r'^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*-\s*(\w+)\s*:(.*)$' - -def parse_error(error: str): - merror = re.fullmatch(ERROR_FORMAT, error) - assert merror, BAD_ERROR_FORMAT % error - - return (t(x) for t, x in zip([int, int, str, str], merror.groups())) - - -def first_error(compiler_output: list, errors: list): - line, column, error_type, _ = parse_error(errors[0]) - - oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) - - assert line == oline and column == ocolumn and error_type == oerror_type,\ - UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) - -def first_error_only_line(compiler_output: list, errors: list): - line, column, error_type, _ = parse_error(errors[0]) - - oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) - - assert line == oline and error_type == oerror_type,\ - UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) - - -def get_file_name(path: str): - try: - return path[path.rindex('/') + 1:] - except ValueError: - return path - -def compare_errors(compiler_path: str, cool_file_path: str, error_file_path: str, cmp=first_error, timeout=100): - try: - sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) - return_code, output = sp.returncode, sp.stdout.decode() - except subprocess.TimeoutExpired: - assert False, COMPILER_TIMEOUT - - assert return_code == 1, TEST_MUST_FAIL % get_file_name(cool_file_path) - - fd = open(error_file_path, 'r') - errors = fd.read().split('\n') - fd.close() - - # checking the errors of compiler - compiler_output = output.split('\n') - cmp(compiler_output[2:], errors) - -SPIM_HEADER = r'''^SPIM Version .+ of .+ -Copyright .+\, James R\. Larus\. -All Rights Reserved\. -See the file README for a full copyright notice\. -(?:Loaded: .+\n)*''' -def compare_outputs(compiler_path: str, cool_file_path: str, input_file_path: str, output_file_path: str, timeout=100): - try: - sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) - assert sp.returncode == 0, TEST_MUST_COMPILE % get_file_name(cool_file_path) - except subprocess.TimeoutExpired: - assert False, COMPILER_TIMEOUT - - spim_file = cool_file_path[:-2] + 'mips' - - try: - fd = open(input_file_path, 'rb') - sp = subprocess.run(['spim', '-file', spim_file], input=fd.read(), capture_output=True, timeout=timeout) - fd.close() - mo = re.match(SPIM_HEADER, sp.stdout.decode()) - if mo: - output = mo.string[mo.end():] - except subprocess.TimeoutExpired: - assert False, SPIM_TIMEOUT - - fd = open(output_file_path, 'r') - eoutput = fd.read() - fd.close() - - assert output == eoutput, UNEXPECTED_OUTPUT % (spim_file, repr(output), repr(eoutput)) +import subprocess +import re + + +COMPILER_TIMEOUT = 'El compilador tarda mucho en responder.' +SPIM_TIMEOUT = 'El spim tarda mucho en responder.' +TEST_MUST_FAIL = 'El test %s debe fallar al compilar' +TEST_MUST_COMPILE = 'El test %s debe compilar' +BAD_ERROR_FORMAT = '''El error no esta en formato: (,) - : + o no se encuentra en la 3ra linea\n\n%s''' +UNEXPECTED_ERROR = 'Se esperaba un %s en (%d, %d). Su error fue un %s en (%d, %d)' +UNEXPECTED_OUTPUT = 'La salida de %s no es la esperada:\n%s\nEsperada:\n%s' + +ERROR_FORMAT = r'^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*-\s*(\w+)\s*:(.*)$' + +def parse_error(error: str): + merror = re.fullmatch(ERROR_FORMAT, error) + assert merror, BAD_ERROR_FORMAT % error + + return (t(x) for t, x in zip([int, int, str, str], merror.groups())) + + +def first_error(compiler_output: list, errors: list): + line, column, error_type, _ = parse_error(errors[0]) + + oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) + + assert line == oline and column == ocolumn and error_type == oerror_type,\ + UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) + +def first_error_only_line(compiler_output: list, errors: list): + line, column, error_type, _ = parse_error(errors[0]) + + oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) + + assert line == oline and error_type == oerror_type,\ + UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) + + +def get_file_name(path: str): + try: + return path[path.rindex('/') + 1:] + except ValueError: + return path + +def compare_errors(compiler_path: str, cool_file_path: str, error_file_path: str, cmp=first_error, timeout=100): + try: + sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) + return_code, output = sp.returncode, sp.stdout.decode() + except subprocess.TimeoutExpired: + assert False, COMPILER_TIMEOUT + + assert return_code == 1, TEST_MUST_FAIL % get_file_name(cool_file_path) + + fd = open(error_file_path, 'r') + errors = fd.read().split('\n') + fd.close() + + # checking the errors of compiler + compiler_output = output.split('\n') + cmp(compiler_output[2:], errors) + +SPIM_HEADER = r'''^SPIM Version .+ of .+ +Copyright .+\, James R\. Larus\. +All Rights Reserved\. +See the file README for a full copyright notice\. +(?:Loaded: .+\n)*''' +def compare_outputs(compiler_path: str, cool_file_path: str, input_file_path: str, output_file_path: str, timeout=100): + try: + sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) + assert sp.returncode == 0, TEST_MUST_COMPILE % get_file_name(cool_file_path) + except subprocess.TimeoutExpired: + assert False, COMPILER_TIMEOUT + + spim_file = cool_file_path[:-2] + 'mips' + + try: + fd = open(input_file_path, 'rb') + sp = subprocess.run(['spim', '-file', spim_file], input=fd.read(), capture_output=True, timeout=timeout) + fd.close() + mo = re.match(SPIM_HEADER, sp.stdout.decode()) + if mo: + output = mo.string[mo.end():] + except subprocess.TimeoutExpired: + assert False, SPIM_TIMEOUT + + fd = open(output_file_path, 'r') + eoutput = fd.read() + fd.close() + + assert output == eoutput, UNEXPECTED_OUTPUT % (spim_file, repr(output), repr(eoutput)) From 8bcad0135745e8ddf458de7a9408fc73322ce171 Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Thu, 30 Sep 2021 12:59:26 -0400 Subject: [PATCH 02/60] Add project structure Major Changes: Add main.py Add compiler components --- src/compiler_components/code_generator.py | 16 ++++++++ src/compiler_components/compiler_component.py | 9 ++++ src/compiler_components/cool_parser.py | 16 ++++++++ src/compiler_components/lexer.py | 15 +++++++ src/compiler_components/semantic_checker.py | 16 ++++++++ src/main.py | 41 +++++++++++++++++++ 6 files changed, 113 insertions(+) create mode 100644 src/compiler_components/code_generator.py create mode 100644 src/compiler_components/compiler_component.py create mode 100644 src/compiler_components/cool_parser.py create mode 100644 src/compiler_components/lexer.py create mode 100644 src/compiler_components/semantic_checker.py create mode 100644 src/main.py diff --git a/src/compiler_components/code_generator.py b/src/compiler_components/code_generator.py new file mode 100644 index 000000000..a9066868a --- /dev/null +++ b/src/compiler_components/code_generator.py @@ -0,0 +1,16 @@ +from compiler_component import CompilerComponent +from semantic_checker import SemanticChecker + +class CodeGenerator(CompilerComponent): + def __init__(self, semantic_checker: SemanticChecker) -> None: + super().__init__() + self.semantic_checker = semantic_checker + + def execute(): + pass + + def has_errors(): + pass + + def print_errors(): + pass \ No newline at end of file diff --git a/src/compiler_components/compiler_component.py b/src/compiler_components/compiler_component.py new file mode 100644 index 000000000..07cb596af --- /dev/null +++ b/src/compiler_components/compiler_component.py @@ -0,0 +1,9 @@ +class CompilerComponent(): + def execute(): + pass + + def has_errors(): + pass + + def print_errors(): + pass \ No newline at end of file diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py new file mode 100644 index 000000000..2395ab3e7 --- /dev/null +++ b/src/compiler_components/cool_parser.py @@ -0,0 +1,16 @@ +from compiler_component import CompilerComponent +from lexer import Lexer + +class Parser(CompilerComponent): + def __init__(self, lexer: Lexer) -> None: + super().__init__() + self.lexer = lexer + + def execute(): + pass + + def has_errors(): + pass + + def print_errors(): + pass \ No newline at end of file diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py new file mode 100644 index 000000000..d633ad317 --- /dev/null +++ b/src/compiler_components/lexer.py @@ -0,0 +1,15 @@ +from compiler_component import CompilerComponent + +class Lexer(CompilerComponent): + def __init__(self, cool_program: str) -> None: + super().__init__() + self.cool_program = cool_program + + def execute(): + pass + + def has_errors(): + pass + + def print_errors(): + pass \ No newline at end of file diff --git a/src/compiler_components/semantic_checker.py b/src/compiler_components/semantic_checker.py new file mode 100644 index 000000000..25f32a25c --- /dev/null +++ b/src/compiler_components/semantic_checker.py @@ -0,0 +1,16 @@ +from compiler_component import CompilerComponent +from cool_parser import Parser + +class SemanticChecker(CompilerComponent): + def __init__(self, parser: Parser) -> None: + super().__init__() + self.parser = parser + + def execute(): + pass + + def has_errors(): + pass + + def print_errors(): + pass \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100644 index 000000000..01589d361 --- /dev/null +++ b/src/main.py @@ -0,0 +1,41 @@ +import parser +import sys +from typing import List + +from compiler_components.compiler_component import CompilerComponent +from compiler_components.lexer import Lexer +from compiler_components.cool_parser import Parser +from compiler_components.semantic_checker import SemanticChecker +from compiler_components.code_generator import CodeGenerator + +def execute_compiler(cool_program : str): + # Initialize compiler components + lexer = Lexer(cool_program) + cool_parser = Parser(lexer) + semantic_checker = SemanticChecker(cool_parser) + code_generator = CodeGenerator(semantic_checker) + + # Execute compiler components + compiler_components : List[CompilerComponent] = [lexer, cool_parser, semantic_checker, code_generator] + for component in compiler_components: + component.execute() + + if component.has_errors(): + component.print_errors() + # with errors + return True + + # TODO: write generated code to output file + + # without errors + return False + +if __name__ == '__main__': + # read input file + inputfile = sys.argv[1] + with open(inputfile, encoding="utf_8")as file: + coolprogram = file.read() + + with_errors: bool = execute_compiler(cool_program = coolprogram) + if with_errors: + exit(1) \ No newline at end of file From ad12d4a26e19ae0976483e6afa785bcaa447c6c6 Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Thu, 30 Sep 2021 18:48:53 -0400 Subject: [PATCH 03/60] ast added --- src/compiler_components/ast.py | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/compiler_components/ast.py diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py new file mode 100644 index 000000000..09cd4947a --- /dev/null +++ b/src/compiler_components/ast.py @@ -0,0 +1,67 @@ +class Node: + pass + +class ProgramNode(Node): + def __init__(self, declarations): + self.declarations = declarations + +class DeclarationNode(Node): + pass + +class ExpressionNode(Node): + pass + +class ClassDeclarationNode(DeclarationNode): + def __init__(self, idx, features, parent=None): + self.id = idx + self.parent = parent + self.features = features + +class FuncDeclarationNode(DeclarationNode): + def __init__(self, idx, params, return_type, body): + self.id = idx + self.params = params + self.type = return_type + self.body = body + +class AttrDeclarationNode(DeclarationNode): + def __init__(self, idx, typex): + self.id = idx + self.type = typex + +class VarDeclarationNode(ExpressionNode): + def __init__(self, idx, typex, expr): + self.id = idx + self.type = typex + self.expr = expr + +class AssignNode(ExpressionNode): + def __init__(self, idx, expr): + self.id = idx + self.expr = expr + +class CallNode(ExpressionNode): + def __init__(self, obj, idx, args): + self.obj = obj + self.id = idx + self.args = args + +class AtomicNode(ExpressionNode): + def __init__(self, lex): + self.lex = lex + +class BinaryNode(ExpressionNode): + def __init__(self, left, right): + self.left = left + self.right = right + +class ConstantNumNode(AtomicNode): + pass +class VariableNode(AtomicNode): + pass +class InstantiateNode(AtomicNode): + pass +class PlusNode(BinaryNode): + pass +class MinusNode(BinaryNode): + pass \ No newline at end of file From 43353bc2bd6e1c5b44becaea7a1dc33ccf7204a2 Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Thu, 30 Sep 2021 19:09:15 -0400 Subject: [PATCH 04/60] lexer added (analizar caso string y comentarios) borrar zona de testing luego --- src/compiler_components/lexer.py | 147 +++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 6 deletions(-) diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index d633ad317..d1e3b03f5 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -1,15 +1,150 @@ from compiler_component import CompilerComponent +import ply.lex as lex + +# funcion que retorna el texto de la linea donde hubo un error lexico +def printLine(text, lineno): #text = texto a tokenizar, lineno: linea donde hubo error + count = 0 + start_index = 0 + last_index = 0 + for i in range(len(text)): + if text[i] == '\n': + count += 1 + if count == lineno: + last_index = i + break + + if count == lineno-1: + start_index = i + + return text[start_index +1: last_index] + +class Tokenizer: + + def __init__(self): + self.errors = [] + + reserved = { + + 'class':'CLASS', + 'else':'ELSE', + 'false':'FALSE', + 'fi':'FI', + 'if':"IF", + 'in':'IN', + 'inherits': 'INHERITS', + 'isvoid':'ISVOID', + 'let':'LET', + 'loop':'LOOP', + 'pool':'POOL', + 'then':'THEN', + 'while':'WHILE', + 'case':'CASE', + 'esac':'ESAC', + 'new':'NEW', + 'of':'OF', + 'not':'NOT', + 'true':'TRUE' + + } + + tokens = ['STRING', 'LPAREN', 'RPAREN', 'LBRACE' , 'RBRACE', 'PLUS', 'MINUS', + 'TIMES', 'DIVIDE', 'SEMICOLON', 'COLON', 'ID', 'MINOR', 'MINOR_EQUALS', "EQUALS", + 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER'] + list(reserved.values()) + + t_LPAREN = r'\(' + t_RPAREN = r'\)' + t_LBRACE = r'\{' + t_RBRACE = r'\}' + t_PLUS = r'\+' + t_MINUS = r'-' + t_TIMES = r'\*' + t_DIVIDE = r'/' + t_SEMICOLON = r';' + r_COLON = r',' + t_MINOR = r'<' + t_MINOR_EQUALS = r'<=' + t_EQUALS = r'=' + t_LEFT_ARROW = r'<-' + t_RIGHT_ARROW = r'=>' + t_DOT = r'\.' + t_DOUBLE_DOT = r':' + t_ARROBA = r'@' + + def t_NUMBER(self, t): + r'\d+' + t.value = int(t.value) + return t + + def t_STRING(self, t): + r'"[^"]*"' + return t + + def t_ID(self, t): + r'[a-zA-Z_][a-zA-Z_0-9]*' + v = t.value.lower() + #true o false tienen que escribirse en letra inicial minuscula, de lo contrario son IDs + if v == 'true' or v == 'false': + if t.value[0] == 'T' or t.value[0] == 'F': + return t + + t.type = self.reserved.get(t.value.lower(), 'ID') + return t + + def t_comment(self, t): + r'--[^\n]*[\n]' + t.lexer.lineno += 1 + + def t_newline(self, t): + r'\n+' + t.lexer.lineno += len(t.value) + + def t_error(self, t): + error = 'Error en la linea ' + str(t.lexer.lineno) + ': \'' + printLine(t.lexer.lexdata, t.lexer.lineno) + error += '\' --> Problema con el caracter \'' + t.value[0] + '\'' + self.errors.append(error) + t.lexer.skip(1) + + + t_ignore_WHITESPACE = r'\s' + + #funcion para tokenizar (devuelve una tupla: (tokens, errores)) + def tokenize(self, data, lexer): #data: texto a tokenizar, lexer: encargado de tokenizar, el campo object del lexer debe ser de tipo Tokenizer + self.errors = [] #se almacenan los errores en el proceso de tokenizar + + lexer.input(data) + tokens = [] + while True: + tok = lexer.token() + if not tok: + return (tokens, self.errors) + tokens.append(tok) class Lexer(CompilerComponent): def __init__(self, cool_program: str) -> None: super().__init__() self.cool_program = cool_program + self.errors = [] + + def execute(self): + tokenizer = Tokenizer() + lexer = lex.lex(tokenizer) + tokens, self.errors = tokenizer.tokenize(self.cool_program, lexer) + for t in tokens: + print(t) - def execute(): - pass + def has_errors(self): + return len(self.errors) == 0 - def has_errors(): - pass + def print_errors(self): + for e in self.errors: + print(e) - def print_errors(): - pass \ No newline at end of file +########################### Testing ############################## +data = '''hola=5+d/4<3 +--aaaa +b +''' +lexer = Lexer(data) +lexer.execute() +lexer.print_errors() +##### borrar luego ######################################## \ No newline at end of file From bcc94529804b81433d0c5c53e7294f0a3edc0e2d Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Thu, 30 Sep 2021 19:24:42 -0400 Subject: [PATCH 05/60] comments oneline fixed (revisar los strings y comentarios multilinea, borrar zona de testing al final del archivo lexer.py) --- src/compiler_components/lexer.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index d1e3b03f5..ef229c18e 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -91,9 +91,13 @@ def t_ID(self, t): return t def t_comment(self, t): - r'--[^\n]*[\n]' + r'--[^\n]*\n' t.lexer.lineno += 1 + def t_comment_end_string(self, t): + r'--[^$]*$' + t.lexer.lineno += 1 + def t_newline(self, t): r'\n+' t.lexer.lineno += len(t.value) @@ -140,11 +144,12 @@ def print_errors(self): print(e) ########################### Testing ############################## -data = '''hola=5+d/4<3 ---aaaa -b -''' +data = '''--aaaa +--bbbbadsfdasg +a+4class{}(a)let if fi while = <=< +--aaa''' lexer = Lexer(data) lexer.execute() +print() lexer.print_errors() ##### borrar luego ######################################## \ No newline at end of file From d3345240af535d2d2b56c213b33456f34c153b7a Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Fri, 1 Oct 2021 16:24:00 -0400 Subject: [PATCH 06/60] parser semi-added (something fixed in lexer) --- src/compiler_components/ast.py | 4 + src/compiler_components/cool_parser.py | 176 ++++++++++++++++++++++++- src/compiler_components/lexer.py | 8 +- 3 files changed, 178 insertions(+), 10 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 09cd4947a..a29e8f615 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -64,4 +64,8 @@ class InstantiateNode(AtomicNode): class PlusNode(BinaryNode): pass class MinusNode(BinaryNode): + pass +class StarNode(BinaryNode): + pass +class DivNode(BinaryNode): pass \ No newline at end of file diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 2395ab3e7..7f0e290ac 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -1,16 +1,182 @@ from compiler_component import CompilerComponent -from lexer import Lexer +from lexer import Tokenizer, Lexer +from ast import * +import ply.yacc as yacc +import ply.lex as lex + +t = Tokenizer() +tokens = t.tokens +lexer = lex.lex(t) + +##### Grammar #################### +def p_program(p): + 'program : class_list' + p[0] = ProgramNode(p[1]) + +def p_class_list(p): + '''class_list : def_class + | def_class class_list + ''' + if len(p) == 2: + p[0] = [p[1]] + else: + p[0] = [p[1]] + p[2] + +def p_def_class(p): + '''def_class : CLASS ID LBRACE feature_list RBRACE + | CLASS ID DOUBLE_DOT ID LBRACE feature_list RBRACE + ''' + if len(p) == 6: + p[0] = ClassDeclarationNode(p[2], p[4]) + else: + p[0] = ClassDeclarationNode(p[2], p[6], p[4]) + +def p_empty(p): + 'empty :' + pass + +def p_feature_list(p): + '''feature_list : def_attr feature_list + | def_func feature_list + | empty + ''' + if len(p) == 2: + p[0] = [] + else: + p[0] = [p[1]] + p[2] + +def p_def_attr(p): + '''def_attr : ID DOUBLE_DOT ID SEMICOLON + ''' + p[0] = AttrDeclarationNode(p[1], p[3]) + +def p_def_func(p): + '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT ID LBRACE expr_list RBRACE + ''' + p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) + +def p_param_list(p): + '''param_list : param + | param COMMA param_list + ''' + if len(p) == 2: + p[0] = [p[1]] + else: + [p[1]] + p[3] + +def p_param(p): + '''param : ID DOUBLE_DOT ID + ''' + p[0] = [p[1], p[3]] + +def p_expr_list(p): + '''expr_list : expr SEMICOLON + | expr SEMICOLON expr_list + ''' + if len(p) == 3: + p[0] = [p[1]] + else: + p[0] = [p[1]] + p[3] + +def p_expr(p): + 'expr : arith' + p[0] = p[1] + +def p_expr2(p): + '''expr : LET ID DOUBLE_DOT ID EQUALS expr + | LET ID EQUALS expr + ''' + if len(p) > 5: + p[0] = VarDeclarationNode(p[2], p[4], p[6]) + else: + p[0] = AssignNode(p[2], p[4]) + +def p_arith(p): + '''arith : term + | arith PLUS term + | arith MINUS term + ''' + if len(p) == 2: + p[0] = p[1] + else: + if p[2] == '+': + p[0] = PlusNode(p[1], p[3]) + else: + p[0] = MinusNode(p[1], p[3]) + +def p_term(p): + '''term : factor + | term TIMES factor + | term DIVIDE factor + ''' + if len(p) == 2: + p[0] = p[1] + else: + if p[2] == '*': + p[0] = StarNode(p[1], p[3]) + else: + p[0] = DivNode(p[1], p[3]) + +def p_factor(p): + '''factor : atom + | LPAREN expr RPAREN + ''' + if len(p) == 2: + p[0] = p[1] + else: + p[0] = p[2] + +#4 (por ahora) metodos para el no-terminal 'atom' +def p_atom1(p): + 'atom : ID' + p[0] = VariableNode(p[1]) + +def p_atom2(p): + 'atom : NUMBER' + p[0] = ConstantNumNode(p[2]) + +def p_atom3(p): + 'atom : func_call' + p[0] = p[1] + +def p_atom4(p): + '''atom : NEW ID LPAREN RPAREN + ''' + p[0] = InstantiateNode(p[2]) + +def p_func_call(p): + '''func_call : factor DOT ID LPAREN arg_list RPAREN + ''' + p[0] = CallNode(p[1], p[3], p[5]) + +def p_arg_list(p): + '''arg_list : expr + | expr COMMA arg_list + ''' + if len(p) == 2: + p[0] = [p[1]] + else: + p[0] = [p[1]] + p[3] + +############## End Grammar ############################ + class Parser(CompilerComponent): + def __init__(self, lexer: Lexer) -> None: super().__init__() self.lexer = lexer - def execute(): + def execute(self): + pass + + def has_errors(self): pass - def has_errors(): + def print_errors(self): pass - def print_errors(): - pass \ No newline at end of file +data = 'class A { f : int ;}' +parser = yacc.yacc() +result = parser.parse(data) +print(result) \ No newline at end of file diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index ef229c18e..76428533a 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -48,7 +48,7 @@ def __init__(self): } tokens = ['STRING', 'LPAREN', 'RPAREN', 'LBRACE' , 'RBRACE', 'PLUS', 'MINUS', - 'TIMES', 'DIVIDE', 'SEMICOLON', 'COLON', 'ID', 'MINOR', 'MINOR_EQUALS', "EQUALS", + 'TIMES', 'DIVIDE', 'SEMICOLON', 'COMMA', 'ID', 'MINOR', 'MINOR_EQUALS', "EQUALS", 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER'] + list(reserved.values()) t_LPAREN = r'\(' @@ -60,7 +60,7 @@ def __init__(self): t_TIMES = r'\*' t_DIVIDE = r'/' t_SEMICOLON = r';' - r_COLON = r',' + r_COMMA = r',' t_MINOR = r'<' t_MINOR_EQUALS = r'<=' t_EQUALS = r'=' @@ -149,7 +149,5 @@ def print_errors(self): a+4class{}(a)let if fi while = <=< --aaa''' lexer = Lexer(data) -lexer.execute() -print() -lexer.print_errors() + ##### borrar luego ######################################## \ No newline at end of file From ea576d501d9472c02ad9eddf950bd102524c39cf Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Fri, 1 Oct 2021 17:30:35 -0400 Subject: [PATCH 07/60] some problems fixed in parser, (incomplete parser yet) --- src/compiler_components/ast.py | 62 +++++++++++++++++++++++++- src/compiler_components/cool_parser.py | 32 +++++++------ src/compiler_components/lexer.py | 12 ++--- 3 files changed, 85 insertions(+), 21 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index a29e8f615..dcfb83f1c 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -1,9 +1,15 @@ class Node: - pass + def visit(self, tabs = 0): + pass class ProgramNode(Node): def __init__(self, declarations): self.declarations = declarations + def visit(self, tabs = 0): + node = self + ans = '\t' * tabs + f'\\__ProgramNode [ ... ]' + statements = '\n'.join(child.visit( tabs + 1) for child in node.declarations) + return f'{ans}\n{statements}' class DeclarationNode(Node): pass @@ -17,6 +23,14 @@ def __init__(self, idx, features, parent=None): self.parent = parent self.features = features + def visit(self, tabs = 0): + node = self + parent = '' if node.parent is None else f": {node.parent}" + ans = '\t' * tabs + f'\\__ClassDeclarationNode: class {node.id} {parent} {{ ... }}' + features = '\n'.join(child.visit( tabs + 1) for child in node.features) + return f'{ans}\n{features}' + + class FuncDeclarationNode(DeclarationNode): def __init__(self, idx, params, return_type, body): self.id = idx @@ -24,43 +38,87 @@ def __init__(self, idx, params, return_type, body): self.type = return_type self.body = body + def visit(self, tabs = 0): + node = self + params = ', '.join(':'.join(param) for param in node.params) + ans = '\t' * tabs + f'\\__FuncDeclarationNode: def {node.id}({params}) : {node.type} -> ' + body = node.body.visit( tabs + 1) + return f'{ans}\n{body}' + class AttrDeclarationNode(DeclarationNode): def __init__(self, idx, typex): self.id = idx self.type = typex + def visit(self, tabs = 0): + node = self + ans = '\t' * tabs + f'\\__AttrDeclarationNode: {node.id} : {node.type}' + return f'{ans}' + class VarDeclarationNode(ExpressionNode): def __init__(self, idx, typex, expr): self.id = idx self.type = typex self.expr = expr + def visit(self, tabs = 0): + node = self + ans = '\t' * tabs + f'\\__VarDeclarationNode: let {node.id} : {node.type} = ' + expr = node.expr.visit( tabs + 1) + return f'{ans}\n{expr}' + class AssignNode(ExpressionNode): def __init__(self, idx, expr): self.id = idx self.expr = expr + def visit(self, tabs = 0): + node = self + ans = '\t' * tabs + f'\\__AssignNode: let {node.id} = ' + expr = node.expr.visit( tabs + 1) + return f'{ans}\n{expr}' + class CallNode(ExpressionNode): def __init__(self, obj, idx, args): self.obj = obj self.id = idx self.args = args + def visit(self, tabs = 0): + node = self + obj = node.obj.visit( tabs + 1) + ans = '\t' * tabs + f'\\__CallNode: .{node.id}(, ..., )' + args = '\n'.join(arg.visit( tabs + 1) for arg in node.args) + return f'{ans}\n{obj}\n{args}' + class AtomicNode(ExpressionNode): def __init__(self, lex): self.lex = lex + def visit(self, tabs = 0): + node = self + return '\t' * tabs + f'\\__ {node.__class__.__name__}: {node.lex}' + class BinaryNode(ExpressionNode): def __init__(self, left, right): self.left = left self.right = right + def visit(self, tabs = 0): + node = self + ans = '\t' * tabs + f'\\__ {node.__class__.__name__} ' + left = node.left.visit( tabs + 1) + right = node.right.visit( tabs + 1) + return f'{ans}\n{left}\n{right}' + class ConstantNumNode(AtomicNode): pass class VariableNode(AtomicNode): pass class InstantiateNode(AtomicNode): - pass + def visit(self, tabs): + node = self + return '\t' * tabs + f'\\__ InstantiateNode: new {node.lex}()' class PlusNode(BinaryNode): pass class MinusNode(BinaryNode): diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 7f0e290ac..5c1f7c693 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -14,13 +14,13 @@ def p_program(p): p[0] = ProgramNode(p[1]) def p_class_list(p): - '''class_list : def_class - | def_class class_list + '''class_list : def_class SEMICOLON + | def_class SEMICOLON class_list ''' - if len(p) == 2: + if len(p) == 3: p[0] = [p[1]] else: - p[0] = [p[1]] + p[2] + p[0] = [p[1]] + p[3] def p_def_class(p): '''def_class : CLASS ID LBRACE feature_list RBRACE @@ -36,14 +36,14 @@ def p_empty(p): pass def p_feature_list(p): - '''feature_list : def_attr feature_list - | def_func feature_list + '''feature_list : def_attr SEMICOLON feature_list + | def_func SEMICOLON feature_list | empty ''' if len(p) == 2: p[0] = [] else: - p[0] = [p[1]] + p[2] + p[0] = [p[1]] + p[3] def p_def_attr(p): '''def_attr : ID DOUBLE_DOT ID SEMICOLON @@ -51,7 +51,7 @@ def p_def_attr(p): p[0] = AttrDeclarationNode(p[1], p[3]) def p_def_func(p): - '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT ID LBRACE expr_list RBRACE + '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT ID LBRACE expr RBRACE ''' p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) @@ -62,7 +62,7 @@ def p_param_list(p): if len(p) == 2: p[0] = [p[1]] else: - [p[1]] + p[3] + p[0] = [p[1]] + p[3] def p_param(p): '''param : ID DOUBLE_DOT ID @@ -133,7 +133,7 @@ def p_atom1(p): def p_atom2(p): 'atom : NUMBER' - p[0] = ConstantNumNode(p[2]) + p[0] = ConstantNumNode(p[1]) def p_atom3(p): 'atom : func_call' @@ -158,6 +158,9 @@ def p_arg_list(p): else: p[0] = [p[1]] + p[3] +def p_error(p): + print(p) + ############## End Grammar ############################ @@ -176,7 +179,10 @@ def has_errors(self): def print_errors(self): pass -data = 'class A { f : int ;}' +data = '''class A { + f(a:int,b:bool,c:hijo):hello{1}; + + };''' parser = yacc.yacc() -result = parser.parse(data) -print(result) \ No newline at end of file +result = parser.parse(data, debug=True) +print(result.visit()) \ No newline at end of file diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index 76428533a..407832a3b 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -60,7 +60,7 @@ def __init__(self): t_TIMES = r'\*' t_DIVIDE = r'/' t_SEMICOLON = r';' - r_COMMA = r',' + t_COMMA = r',' t_MINOR = r'<' t_MINOR_EQUALS = r'<=' t_EQUALS = r'=' @@ -144,10 +144,10 @@ def print_errors(self): print(e) ########################### Testing ############################## -data = '''--aaaa ---bbbbadsfdasg -a+4class{}(a)let if fi while = <=< ---aaa''' -lexer = Lexer(data) +data = '''class A { + f(a:int ,b:bool,c:hijo):hello{1}; + };''' +lexer = Lexer(data) +#lexer.execute() ##### borrar luego ######################################## \ No newline at end of file From d13341c1a7b45fd1bbe668ca4977bbe26734c897 Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Fri, 1 Oct 2021 17:39:44 -0400 Subject: [PATCH 08/60] parser update (not finished yet) --- src/compiler_components/ast.py | 7 +++++-- src/compiler_components/cool_parser.py | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index dcfb83f1c..ff3deee09 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -46,13 +46,16 @@ def visit(self, tabs = 0): return f'{ans}\n{body}' class AttrDeclarationNode(DeclarationNode): - def __init__(self, idx, typex): + def __init__(self, idx, typex, expr = None): self.id = idx self.type = typex + self.expr = expr def visit(self, tabs = 0): node = self - ans = '\t' * tabs + f'\\__AttrDeclarationNode: {node.id} : {node.type}' + ans = '\t' * tabs + f'\\__AttrDeclarationNode: {node.id} : {node.type} <-- ' + if not self.expr is None: + ans += "\n" + self.expr.visit(tabs+1) return f'{ans}' class VarDeclarationNode(ExpressionNode): diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 5c1f7c693..e072f65af 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -46,9 +46,13 @@ def p_feature_list(p): p[0] = [p[1]] + p[3] def p_def_attr(p): - '''def_attr : ID DOUBLE_DOT ID SEMICOLON + '''def_attr : ID DOUBLE_DOT ID + | ID DOUBLE_DOT ID LEFT_ARROW expr ''' - p[0] = AttrDeclarationNode(p[1], p[3]) + if len(p) == 5: + p[0] = AttrDeclarationNode(p[1], p[3]) + else: + p[0] = AttrDeclarationNode(p[1], p[3], p[5]) def p_def_func(p): '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT ID LBRACE expr RBRACE @@ -180,6 +184,7 @@ def print_errors(self): pass data = '''class A { + a:int <- 8; f(a:int,b:bool,c:hijo):hello{1}; };''' From 33a34595ada53f20457c6146300c52c60e27f71d Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Fri, 8 Oct 2021 15:10:48 -0400 Subject: [PATCH 09/60] parser ... .. ... --- src/compiler_components/ast.py | 46 ++++++++++++++-- src/compiler_components/cool_parser.py | 72 +++++++++++++++++++------- src/compiler_components/lexer.py | 6 ++- 3 files changed, 100 insertions(+), 24 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index ff3deee09..0ae5ac516 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -82,7 +82,7 @@ def visit(self, tabs = 0): return f'{ans}\n{expr}' class CallNode(ExpressionNode): - def __init__(self, obj, idx, args): + def __init__(self, obj, idx, type = None, args = None): self.obj = obj self.id = idx self.args = args @@ -90,9 +90,19 @@ def __init__(self, obj, idx, args): def visit(self, tabs = 0): node = self obj = node.obj.visit( tabs + 1) - ans = '\t' * tabs + f'\\__CallNode: .{node.id}(, ..., )' - args = '\n'.join(arg.visit( tabs + 1) for arg in node.args) - return f'{ans}\n{obj}\n{args}' + + if not self.args is None: + ans = '\t' * tabs + f'\\__CallNode: .{node.id}(, ..., )' + else: + ans = '\t' * tabs + f'\\__CallNode: .{node.id}()' + if not self.args is None: + args = '\n'.join(arg.visit( tabs + 1) for arg in node.args) + else: + args = "" + if self.type is None: + return f'{ans}\n{obj}\n{args}' + else: + return f'@{self.type}{ans}\n{obj}\n{args}' class AtomicNode(ExpressionNode): def __init__(self, lex): @@ -116,6 +126,34 @@ def visit(self, tabs = 0): class ConstantNumNode(AtomicNode): pass + +class ConstantStringNode(AtomicNode): + pass + +class ConstantBooleanNode(AtomicNode): + pass + +class SelfNode(AtomicNode): + pass + +class DispatchNode(ExpressionNode): + def __init__(self, expr, f, params, type = None): + super().__init__(None) + self.id = id + self.f = f + self.params = params + self.type = type + + def visit(self, tabs = 0): + node = self + if not self.type: + ans = '\t' * tabs + f'\\__.{self.f} ' + else: + ans = '\t' * tabs + f'\\__@{self.type}.{self.f} ' + expr = node.expr.visit( tabs + 1) + params = '\n'.join(param.visit( tabs + 1) for param in node.params) + return f'{ans}\n{expr}\n{params}' + class VariableNode(AtomicNode): pass class InstantiateNode(AtomicNode): diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index e072f65af..7ecb4eded 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -7,6 +7,7 @@ t = Tokenizer() tokens = t.tokens lexer = lex.lex(t) +errors = [] ##### Grammar #################### def p_program(p): @@ -24,7 +25,7 @@ def p_class_list(p): def p_def_class(p): '''def_class : CLASS ID LBRACE feature_list RBRACE - | CLASS ID DOUBLE_DOT ID LBRACE feature_list RBRACE + | CLASS ID INHERITS ID LBRACE feature_list RBRACE ''' if len(p) == 6: p[0] = ClassDeclarationNode(p[2], p[4]) @@ -49,7 +50,7 @@ def p_def_attr(p): '''def_attr : ID DOUBLE_DOT ID | ID DOUBLE_DOT ID LEFT_ARROW expr ''' - if len(p) == 5: + if len(p) == 4: p[0] = AttrDeclarationNode(p[1], p[3]) else: p[0] = AttrDeclarationNode(p[1], p[3], p[5]) @@ -87,13 +88,8 @@ def p_expr(p): p[0] = p[1] def p_expr2(p): - '''expr : LET ID DOUBLE_DOT ID EQUALS expr - | LET ID EQUALS expr - ''' - if len(p) > 5: - p[0] = VarDeclarationNode(p[2], p[4], p[6]) - else: - p[0] = AssignNode(p[2], p[4]) + 'expr : ID LEFT_ARROW expr' + p[0] = AssignNode(p[1], p[3]) def p_arith(p): '''arith : term @@ -148,22 +144,49 @@ def p_atom4(p): ''' p[0] = InstantiateNode(p[2]) +def p_atomString(p): + 'atom : STRING' + print(p[1][1:len(p[1]) -1 ]) + p[0] = ConstantStringNode(p[1][1:len(p[1]) -1 ]) + +def p_atomBool(p): + '''atom : TRUE + | FALSE + ''' + if p[1].lower() == "true": + p[0] = ConstantBooleanNode(True) + else: + p[0] = ConstantBooleanNode(False) + +def p_atomSelf(p): + 'atom : SELF' + p[0] = SelfNode(None) + def p_func_call(p): '''func_call : factor DOT ID LPAREN arg_list RPAREN ''' - p[0] = CallNode(p[1], p[3], p[5]) + if not p[5][0] is None: + p[0] = CallNode(p[1], p[3], p[5]) + else: + p[0] = CallNode(p[1], p[3]) + def p_arg_list(p): '''arg_list : expr | expr COMMA arg_list + | empty ''' if len(p) == 2: p[0] = [p[1]] else: p[0] = [p[1]] + p[3] + def p_error(p): - print(p) + if p: + errors.append("sintax error at line " + str(p.lineno) + " --> token: '" + p.value + "'") + else: + errors.append("sintanx error at end of file") ############## End Grammar ############################ @@ -175,19 +198,30 @@ def __init__(self, lexer: Lexer) -> None: self.lexer = lexer def execute(self): - pass + parser = yacc.yacc() + errors = [] + self.ast = parser.parse(self.lexer.cool_program) def has_errors(self): - pass + return len(errors) == 0 def print_errors(self): - pass + for e in errors: + print(e) + print() + -data = '''class A { - a:int <- 8; - f(a:int,b:bool,c:hijo):hello{1}; +################ TEsting zone ########################### +data = '''class A inheritS B{ + a:int ; + f(a:int,b:bool,c:hijo):hello{hola <- f()}; };''' parser = yacc.yacc() -result = parser.parse(data, debug=True) -print(result.visit()) \ No newline at end of file +result = parser.parse(data) +if len(errors) == 0: + print(result.visit()) +else: + print(errors) + +######################################################## \ No newline at end of file diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index 407832a3b..e8ac067ba 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -49,7 +49,7 @@ def __init__(self): tokens = ['STRING', 'LPAREN', 'RPAREN', 'LBRACE' , 'RBRACE', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'SEMICOLON', 'COMMA', 'ID', 'MINOR', 'MINOR_EQUALS', "EQUALS", - 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER'] + list(reserved.values()) + 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER', 'SELF'] + list(reserved.values()) t_LPAREN = r'\(' t_RPAREN = r'\)' @@ -69,6 +69,10 @@ def __init__(self): t_DOT = r'\.' t_DOUBLE_DOT = r':' t_ARROBA = r'@' + + def t_SELF(self, t): + r'self' + return t def t_NUMBER(self, t): r'\d+' From e5626489fc81cfd481ef76ff258b28a02e6485ab Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Fri, 8 Oct 2021 17:46:13 -0400 Subject: [PATCH 10/60] working on parse --- src/compiler_components/ast.py | 108 +++++++++++++++++++++---- src/compiler_components/cool_parser.py | 66 ++++++++++++++- src/compiler_components/lexer.py | 3 +- 3 files changed, 155 insertions(+), 22 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 0ae5ac516..bca08c565 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -17,6 +17,14 @@ class DeclarationNode(Node): class ExpressionNode(Node): pass +class AtomicNode(ExpressionNode): + def __init__(self, lex): + self.lex = lex + + def visit(self, tabs = 0): + node = self + return '\t' * tabs + f'\\__ {node.__class__.__name__}: {node.lex}' + class ClassDeclarationNode(DeclarationNode): def __init__(self, idx, features, parent=None): self.id = idx @@ -70,7 +78,7 @@ def visit(self, tabs = 0): expr = node.expr.visit( tabs + 1) return f'{ans}\n{expr}' -class AssignNode(ExpressionNode): +class AssignNode(AtomicNode): def __init__(self, idx, expr): self.id = idx self.expr = expr @@ -81,36 +89,104 @@ def visit(self, tabs = 0): expr = node.expr.visit( tabs + 1) return f'{ans}\n{expr}' -class CallNode(ExpressionNode): - def __init__(self, obj, idx, type = None, args = None): +class IsVoidNode(AtomicNode): + def __init__(self, expr): + self.expr = expr + + def visit(self, tabs = 0): + ans = '\t'*tabs + "\\__IsVoid " + return ans + '\n' + '\t'*(tabs+1) + self.expr.visit() + + +class CallNode(AtomicNode): + def __init__(self, obj, idx, args = None, type = None): self.obj = obj self.id = idx self.args = args + self.type = type def visit(self, tabs = 0): node = self - obj = node.obj.visit( tabs + 1) - + if not self.obj is None: + obj = node.obj.visit( tabs + 1) + else: + obj = "" + if not self.type is None: + arroba = f'@{self.type}' + else: + arroba = "" + if not self.args is None: - ans = '\t' * tabs + f'\\__CallNode: .{node.id}(, ..., )' + ans = '\t' * tabs + f'\\__CallNode: {arroba}.{node.id}(, ..., )' else: - ans = '\t' * tabs + f'\\__CallNode: .{node.id}()' + ans = '\t' * tabs + f'\\__CallNode: {arroba}.{node.id}()' if not self.args is None: args = '\n'.join(arg.visit( tabs + 1) for arg in node.args) else: args = "" - if self.type is None: - return f'{ans}\n{obj}\n{args}' - else: - return f'@{self.type}{ans}\n{obj}\n{args}' + + return f'{ans}\n{obj}\n{args}' + +class IfNode(AtomicNode): + def __init__(self, if_c, then_c, else_c): + self.if_c = if_c + self.then_c = then_c + self.else_c = else_c + + def visit(self, tabs = 0): + node = self + ans = '\t'*tabs + 'if then else fi' + ans += "\n" + '\t'*(tabs +1) + "IF: " + self.if_c.visit() + ans += "\n" + '\t'*(tabs +1) + "then: " + self.then_c.visit() + ans += "\n" + '\t'*(tabs +1) + "else: " + self.else_c.visit() + return ans + +class WhileNode(AtomicNode): + def __init__(self, condition, body): + self.condition = condition + self.body = body + + def visit(self, tabs = 0): + node = self + ans = '\t'*tabs + 'while loop pool' + ans += "\n" + '\t'*(tabs +1) + "condition: " + self.if_c.visit() + ans += "\n" + '\t'*(tabs +1) + "body: " + self.then_c.visit() + + return ans -class AtomicNode(ExpressionNode): - def __init__(self, lex): - self.lex = lex +class BlockNode(AtomicNode): + def __init__(self, expr_list): + self.expr_list = expr_list def visit(self, tabs = 0): - node = self - return '\t' * tabs + f'\\__ {node.__class__.__name__}: {node.lex}' + ans = '\t'*tabs + " {; .... ;}\n" + exprs = '\n'.join(param.visit( tabs + 1) for param in self.expr_list) + return ans+exprs + +class LetNode(AtomicNode): + def __init__(self, list_decl, expr): + self.list_decl = list_decl + self.expr = expr + + def visit(self, tabs = 0): + ans = '\t'*tabs + " LET , ... in \n " + decl = '\n'.join('\t'*(tabs+1) + "decl: " + param.visit() for param in self.list_decl) + expr = "\n" + "IN" + self.expr.visit(tabs+1) + return ans+decl+expr + +class CaseNode(AtomicNode): + def __init__(self, expr, list_case): + self.list_case = list_case + self.expr = expr + + def visit(self, tabs = 0): + ans = '\t'*tabs + "\\__Case in esac" + expr = '\t'*(tabs+1) + self.expr.visit() + l = '\n'.join('\t'*(tabs+1) + "list_case[i]: " + e.visit() for e in self.list_case) + return ans+"\n"+expr+"\n" +l + + + class BinaryNode(ExpressionNode): def __init__(self, left, right): diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 7ecb4eded..0421168c7 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -162,6 +162,48 @@ def p_atomSelf(p): 'atom : SELF' p[0] = SelfNode(None) +def p_atomIF(p): + 'atom : IF expr THEN expr ELSE expr FI' + p[0] = IfNode(p[2], p[4], p[6]) + +def p_atomCicle(p): + 'atom : WHILE expr LOOP expr POOL' + +def p_atomBlock(p): + 'atom : LBRACE expr_list RBRACE' + p[0] = BlockNode(p[2]) + +def p_atomLet(p): + 'atom : LET atr_decl_list IN expr' + p[0] = LetNode(p[2], p[4]) + +def p_atr_decl_list(p): + '''atr_decl_list : def_attr + | def_attr COMMA atr_decl_list + + ''' + if len(p) == 2: + p[0] = [p[1]] + else: + p[0] = [p[1]] + p[3] + +def p_atomCase(p): + 'atom : CASE expr OF case_list ESAC' + p[0] = CaseNode(p[2], p[4]) + +def p_caseList(p): + '''case_list : ID DOUBLE_DOT ID RIGHT_ARROW expr SEMICOLON + | ID DOUBLE_DOT ID RIGHT_ARROW expr SEMICOLON case_list + ''' + if len(p) == 7: + p[0] = [AttrDeclarationNode(p[1], p[3], p[5])] + else: + p[0] = [AttrDeclarationNode(p[1], p[3], p[5])] + p[7] + +def p_atomIsVoid(p): + 'atom : ISVOID atom' + p[0] = IsVoidNode(p[2]) + def p_func_call(p): '''func_call : factor DOT ID LPAREN arg_list RPAREN ''' @@ -170,6 +212,24 @@ def p_func_call(p): else: p[0] = CallNode(p[1], p[3]) +def p_func_call2(p): + 'func_call : ID LPAREN arg_list RPAREN' + print("#######################") + for i in range(len(p)): + print(p[i]) + print("##########################") + if not p[3][0] is None: + p[0] = CallNode(None, p[1], p[3]) + else: + p[0] = CallNode(None, p[1]) + +def p_func_call3(p): + 'func_call : factor ARROBA ID DOT ID LPAREN arg_list RPAREN' + if not p[7][0] is None: + p[0] = CallNode(p[1], p[5], args = p[7], type = p[3]) + else: + p[0] = CallNode(p[1], p[5], args = None, type = p[3]) + def p_arg_list(p): '''arg_list : expr @@ -212,10 +272,8 @@ def print_errors(self): ################ TEsting zone ########################### -data = '''class A inheritS B{ - a:int ; - f(a:int,b:bool,c:hijo):hello{hola <- f()}; - +data = '''class A { + a:a<- isvoid f.f().f()@T.f(); };''' parser = yacc.yacc() result = parser.parse(data) diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index e8ac067ba..8cc323217 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -24,7 +24,6 @@ def __init__(self): self.errors = [] reserved = { - 'class':'CLASS', 'else':'ELSE', 'false':'FALSE', @@ -149,7 +148,7 @@ def print_errors(self): ########################### Testing ############################## data = '''class A { - f(a:int ,b:bool,c:hijo):hello{1}; + f(a:int ,b:bool,c:hijo):hello{g@}; };''' lexer = Lexer(data) From 59421c7c2e19a6c5790e816b19c4d3a74e602e9c Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 14:35:06 -0400 Subject: [PATCH 11/60] trabajando en base a pasar los tests del lexer --- src/compiler_components/ast.py | 16 ++++ src/compiler_components/cool_parser.py | 16 +++- src/compiler_components/lexer.py | 107 +++++++++++++++++++++++-- 3 files changed, 130 insertions(+), 9 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index bca08c565..70997503b 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -96,6 +96,22 @@ def __init__(self, expr): def visit(self, tabs = 0): ans = '\t'*tabs + "\\__IsVoid " return ans + '\n' + '\t'*(tabs+1) + self.expr.visit() + +class NotNode(AtomicNode): + def __init__(self, expr): + self.expr = expr + + def visit(self, tabs = 0): + ans = '\t'*tabs + "\\__NOT " + return ans + '\n' + '\t'*(tabs+1) + self.expr.visit() + +class NhanharaNode(AtomicNode): + def __init__(self, expr): + self.expr = expr + + def visit(self, tabs = 0): + ans = '\t'*tabs + "\\__~ " + return ans + '\n' + '\t'*(tabs+1) + self.expr.visit() class CallNode(AtomicNode): diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 0421168c7..150ce4958 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -201,9 +201,17 @@ def p_caseList(p): p[0] = [AttrDeclarationNode(p[1], p[3], p[5])] + p[7] def p_atomIsVoid(p): - 'atom : ISVOID atom' + 'atom : ISVOID factor' p[0] = IsVoidNode(p[2]) +def p_atomNot(p): + 'atom : NOT factor' + p[0] = NotNode(p[2]) + +def p_atomNhanhara(p): + 'atom : NHANHARA factor' + p[0] = NhanharaNode(p[2]) + def p_func_call(p): '''func_call : factor DOT ID LPAREN arg_list RPAREN ''' @@ -272,8 +280,10 @@ def print_errors(self): ################ TEsting zone ########################### -data = '''class A { - a:a<- isvoid f.f().f()@T.f(); +data = '''class A { (*(* +a +*)*) + a:; };''' parser = yacc.yacc() result = parser.parse(data) diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index 8cc323217..a07a8e97d 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -48,7 +48,7 @@ def __init__(self): tokens = ['STRING', 'LPAREN', 'RPAREN', 'LBRACE' , 'RBRACE', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'SEMICOLON', 'COMMA', 'ID', 'MINOR', 'MINOR_EQUALS', "EQUALS", - 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER', 'SELF'] + list(reserved.values()) + 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER', 'SELF', 'NHANHARA'] + list(reserved.values()) t_LPAREN = r'\(' t_RPAREN = r'\)' @@ -68,6 +68,7 @@ def __init__(self): t_DOT = r'\.' t_DOUBLE_DOT = r':' t_ARROBA = r'@' + t_NHANHARA = r'~' def t_SELF(self, t): r'self' @@ -96,6 +97,47 @@ def t_ID(self, t): def t_comment(self, t): r'--[^\n]*\n' t.lexer.lineno += 1 + + def t_commentMultiline(self, t): + r'\(\*' + s = '' + count = 1 + end_re = lex.re.compile('\*\)') + open_re = lex.re.compile('\(\*') + any_re = lex.re.compile('[^\(\)\*]*') + while count > 0: + if t.lexer.lexpos == len(t.lexer.lexdata): + break + + m = end_re.match(t.lexer.lexdata[t.lexer.lexpos:]) + + if not m is None: + s+= m.group() + t.lexer.skip(2) + count -= 1 + continue + + m = open_re.match(t.lexer.lexdata[t.lexer.lexpos:]) + if not m is None: + s+=m.group() + t.lexer.skip(2) + count += 1 + continue + + m = any_re.match(t.lexer.lexdata[t.lexer.lexpos:]) + if m.group() == '': + s+= str(t.lexer.lexdata[t.lexer.lexpos]) + t.lexer.skip(1) + else: + s += m.group() + t.lexer.skip(len(m.group())) + + t.lexer.lineno += len(s.split('\n')) - 1 + if count > 0: + self.errors.append("(" + str(t.lexer.lineno) + ", " + str(t.lexer.lexpos) + ") - LexicographicError: EOF in comment") + + + def t_comment_end_string(self, t): r'--[^$]*$' @@ -147,10 +189,63 @@ def print_errors(self): print(e) ########################### Testing ############################## -data = '''class A { - f(a:int ,b:bool,c:hijo):hello{g@}; - - };''' +data = '''--Any characters between two dashes “--” and the next newline +--(or EOF, if there is no next newline) are treated as comments + +(*(*(* +Comments may also be written by enclosing +text in (∗ . . . ∗). The latter form of comment may be nested. +Comments cannot cross file boundaries. +*)*)*) + +class Error() { + + (* There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more. + There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more.''' lexer = Lexer(data) -#lexer.execute() +lexer.execute() +lexer.print_errors() +print(len(data)) ##### borrar luego ######################################## \ No newline at end of file From a0e5d910b0892967bff77292ccc1b19436820ead Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 15:08:27 -0400 Subject: [PATCH 12/60] arreglando el string tokenizer --- src/compiler_components/lexer.py | 90 +++++++++++--------------------- 1 file changed, 31 insertions(+), 59 deletions(-) diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index a07a8e97d..46e770ab1 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -84,7 +84,7 @@ def t_STRING(self, t): return t def t_ID(self, t): - r'[a-zA-Z_][a-zA-Z_0-9]*' + r'[a-zA-Z][a-zA-Z_0-9]*' v = t.value.lower() #true o false tienen que escribirse en letra inicial minuscula, de lo contrario son IDs if v == 'true' or v == 'false': @@ -134,7 +134,8 @@ def t_commentMultiline(self, t): t.lexer.lineno += len(s.split('\n')) - 1 if count > 0: - self.errors.append("(" + str(t.lexer.lineno) + ", " + str(t.lexer.lexpos) + ") - LexicographicError: EOF in comment") + posAtLine = len(t.lexer.lexdata.split('\n')[t.lexer.lineno - 1]) + 1 + self.errors.append("(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ") - LexicographicError: EOF in comment") @@ -148,8 +149,20 @@ def t_newline(self, t): t.lexer.lineno += len(t.value) def t_error(self, t): - error = 'Error en la linea ' + str(t.lexer.lineno) + ': \'' + printLine(t.lexer.lexdata, t.lexer.lineno) - error += '\' --> Problema con el caracter \'' + t.value[0] + '\'' + #error = 'Error en la linea ' + str(t.lexer.lineno) + ': \'' + printLine(t.lexer.lexdata, t.lexer.lineno) + #error += '\' --> Problema con el caracter \'' + t.value[0] + '\'' + + + + s = t.lexer.lexdata.split('\n') + count = 0 + for i in range(t.lexer.lineno - 1): + count += len(s[i]) + + print(t.lexer.lexpos) + print(count) + posAtLine = t.lexer.lexpos - count - t.lexer.lineno + 2 + error = "(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ') - LexicographicError: ERROR "' + t.lexer.lexdata[t.lexer.lexpos] + '"' self.errors.append(error) t.lexer.skip(1) @@ -189,61 +202,20 @@ def print_errors(self): print(e) ########################### Testing ############################## -data = '''--Any characters between two dashes “--” and the next newline ---(or EOF, if there is no next newline) are treated as comments - -(*(*(* -Comments may also be written by enclosing -text in (∗ . . . ∗). The latter form of comment may be nested. -Comments cannot cross file boundaries. -*)*)*) - -class Error() { - - (* There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more. - There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more.''' +data = '''"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 +adsfasklj# +LKldsajf iNhERITS +"lkdsajf" + +(* +#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" +#1 INT_CONST 123 +#2 OBJECTID adsfasklj +#2 ERROR "#" +#3 TYPEID LKldsajf +#3 INHERITS +#4 STR_CONST "lkdsajf" +*)''' lexer = Lexer(data) lexer.execute() lexer.print_errors() From 57cbdfd1dfbe0952dce7bf69816b538428b6f358 Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 15:43:17 -0400 Subject: [PATCH 13/60] problema serio con los strings --- src/compiler_components/lexer.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index 46e770ab1..04de6c3f7 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -159,8 +159,6 @@ def t_error(self, t): for i in range(t.lexer.lineno - 1): count += len(s[i]) - print(t.lexer.lexpos) - print(count) posAtLine = t.lexer.lexpos - count - t.lexer.lineno + 2 error = "(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ') - LexicographicError: ERROR "' + t.lexer.lexdata[t.lexer.lexpos] + '"' self.errors.append(error) @@ -202,22 +200,9 @@ def print_errors(self): print(e) ########################### Testing ############################## -data = '''"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 -adsfasklj# -LKldsajf iNhERITS -"lkdsajf" - -(* -#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" -#1 INT_CONST 123 -#2 OBJECTID adsfasklj -#2 ERROR "#" -#3 TYPEID LKldsajf -#3 INHERITS -#4 STR_CONST "lkdsajf" -*)''' +data = '''''' + lexer = Lexer(data) lexer.execute() lexer.print_errors() -print(len(data)) ##### borrar luego ######################################## \ No newline at end of file From 964fd8814fce302a47c27c0dcd739e9e6920ce01 Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 15:50:19 -0400 Subject: [PATCH 14/60] las funciones pueden no tener parametros --- src/compiler_components/cool_parser.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 150ce4958..44e87cf90 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -58,11 +58,15 @@ def p_def_attr(p): def p_def_func(p): '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT ID LBRACE expr RBRACE ''' - p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) + if p[3][0] == None: + params = [] + else: + params = p[3] + p[0] = FuncDeclarationNode(p[1], params, p[6], p[8]) def p_param_list(p): - '''param_list : param - | param COMMA param_list + '''param_list : param COMMA param_list + | empty ''' if len(p) == 2: p[0] = [p[1]] @@ -280,11 +284,7 @@ def print_errors(self): ################ TEsting zone ########################### -data = '''class A { (*(* -a -*)*) - a:; - };''' +data = '''class A {o():f{a};};''' parser = yacc.yacc() result = parser.parse(data) if len(errors) == 0: From beb192659f6da44fe8b71a42de7041331fdf7a8d Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 15:54:18 -0400 Subject: [PATCH 15/60] arreglito en funciones --- src/compiler_components/cool_parser.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 44e87cf90..f0a60be04 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -66,6 +66,7 @@ def p_def_func(p): def p_param_list(p): '''param_list : param COMMA param_list + | param | empty ''' if len(p) == 2: @@ -226,10 +227,7 @@ def p_func_call(p): def p_func_call2(p): 'func_call : ID LPAREN arg_list RPAREN' - print("#######################") - for i in range(len(p)): - print(p[i]) - print("##########################") + if not p[3][0] is None: p[0] = CallNode(None, p[1], p[3]) else: @@ -284,7 +282,7 @@ def print_errors(self): ################ TEsting zone ########################### -data = '''class A {o():f{a};};''' +data = '''class A {o(a:int):f{a};};''' parser = yacc.yacc() result = parser.parse(data) if len(errors) == 0: From d0bc1ab625a15be623741d1632957ef478f0dd88 Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 16:03:53 -0400 Subject: [PATCH 16/60] arreglito en el parser --- src/compiler_components/cool_parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index f0a60be04..37fe89712 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -145,7 +145,7 @@ def p_atom3(p): p[0] = p[1] def p_atom4(p): - '''atom : NEW ID LPAREN RPAREN + '''atom : NEW ID ''' p[0] = InstantiateNode(p[2]) @@ -282,7 +282,7 @@ def print_errors(self): ################ TEsting zone ########################### -data = '''class A {o(a:int):f{a};};''' +data = '''class A{a:B <- (new A);};''' parser = yacc.yacc() result = parser.parse(data) if len(errors) == 0: From e76348a9c7f0bfa887ff2f04541da5f93348eaad Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 16:21:53 -0400 Subject: [PATCH 17/60] commit para resguardarme de la locura que voy a hacer, boolean expression --- src/compiler_components/cool_parser.py | 22 +++++++++++----------- src/compiler_components/lexer.py | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 37fe89712..05e5e0e8e 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -24,8 +24,8 @@ def p_class_list(p): p[0] = [p[1]] + p[3] def p_def_class(p): - '''def_class : CLASS ID LBRACE feature_list RBRACE - | CLASS ID INHERITS ID LBRACE feature_list RBRACE + '''def_class : CLASS TYPE_ID LBRACE feature_list RBRACE + | CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE ''' if len(p) == 6: p[0] = ClassDeclarationNode(p[2], p[4]) @@ -47,8 +47,8 @@ def p_feature_list(p): p[0] = [p[1]] + p[3] def p_def_attr(p): - '''def_attr : ID DOUBLE_DOT ID - | ID DOUBLE_DOT ID LEFT_ARROW expr + '''def_attr : ID DOUBLE_DOT TYPE_ID + | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr ''' if len(p) == 4: p[0] = AttrDeclarationNode(p[1], p[3]) @@ -56,7 +56,7 @@ def p_def_attr(p): p[0] = AttrDeclarationNode(p[1], p[3], p[5]) def p_def_func(p): - '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT ID LBRACE expr RBRACE + '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE ''' if p[3][0] == None: params = [] @@ -75,7 +75,7 @@ def p_param_list(p): p[0] = [p[1]] + p[3] def p_param(p): - '''param : ID DOUBLE_DOT ID + '''param : ID DOUBLE_DOT TYPE_ID ''' p[0] = [p[1], p[3]] @@ -145,7 +145,7 @@ def p_atom3(p): p[0] = p[1] def p_atom4(p): - '''atom : NEW ID + '''atom : NEW TYPE_ID ''' p[0] = InstantiateNode(p[2]) @@ -197,8 +197,8 @@ def p_atomCase(p): p[0] = CaseNode(p[2], p[4]) def p_caseList(p): - '''case_list : ID DOUBLE_DOT ID RIGHT_ARROW expr SEMICOLON - | ID DOUBLE_DOT ID RIGHT_ARROW expr SEMICOLON case_list + '''case_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON + | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list ''' if len(p) == 7: p[0] = [AttrDeclarationNode(p[1], p[3], p[5])] @@ -234,7 +234,7 @@ def p_func_call2(p): p[0] = CallNode(None, p[1]) def p_func_call3(p): - 'func_call : factor ARROBA ID DOT ID LPAREN arg_list RPAREN' + 'func_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN' if not p[7][0] is None: p[0] = CallNode(p[1], p[5], args = p[7], type = p[3]) else: @@ -282,7 +282,7 @@ def print_errors(self): ################ TEsting zone ########################### -data = '''class A{a:B <- (new A);};''' +data = '''''' parser = yacc.yacc() result = parser.parse(data) if len(errors) == 0: diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index 04de6c3f7..e317a43cd 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -48,7 +48,7 @@ def __init__(self): tokens = ['STRING', 'LPAREN', 'RPAREN', 'LBRACE' , 'RBRACE', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'SEMICOLON', 'COMMA', 'ID', 'MINOR', 'MINOR_EQUALS', "EQUALS", - 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER', 'SELF', 'NHANHARA'] + list(reserved.values()) + 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER', 'SELF', 'NHANHARA', 'TYPE_ID'] + list(reserved.values()) t_LPAREN = r'\(' t_RPAREN = r'\)' @@ -84,7 +84,7 @@ def t_STRING(self, t): return t def t_ID(self, t): - r'[a-zA-Z][a-zA-Z_0-9]*' + r'[a-z][a-zA-Z_0-9]*' v = t.value.lower() #true o false tienen que escribirse en letra inicial minuscula, de lo contrario son IDs if v == 'true' or v == 'false': @@ -94,6 +94,17 @@ def t_ID(self, t): t.type = self.reserved.get(t.value.lower(), 'ID') return t + def t_TYPE_ID(self, t): + r'[A-Z][a-zA-Z_0-9]*' + v = t.value.lower() + #true o false tienen que escribirse en letra inicial minuscula, de lo contrario son IDs + if v == 'true' or v == 'false': + if t.value[0] == 'T' or t.value[0] == 'F': + return t + + t.type = self.reserved.get(t.value.lower(), 'TYPE_ID') + return t + def t_comment(self, t): r'--[^\n]*\n' t.lexer.lineno += 1 From dcc3dc5bb9cc3bc7cb0f3bcf43113af9e1cf4b0b Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 17:19:22 -0400 Subject: [PATCH 18/60] Coma , colgada en los parametros de una funcion arreglados --- src/compiler_components/ast.py | 7 ++++ src/compiler_components/cool_parser.py | 47 +++++++++++++++++++------- tests/parser/block1.cl | 6 ++-- tests/parser/block2.cl | 6 ++-- tests/parser/block3.cl | 6 ++-- 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 70997503b..4232a0efa 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -259,4 +259,11 @@ class MinusNode(BinaryNode): class StarNode(BinaryNode): pass class DivNode(BinaryNode): + pass + +class MinorNode(BinaryNode): + pass +class MinorEqualsNode(BinaryNode): + pass +class EqualsNode(BinaryNode): pass \ No newline at end of file diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 05e5e0e8e..d78f69bf2 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -58,21 +58,26 @@ def p_def_attr(p): def p_def_func(p): '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE ''' - if p[3][0] == None: - params = [] - else: - params = p[3] - p[0] = FuncDeclarationNode(p[1], params, p[6], p[8]) + + p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) def p_param_list(p): - '''param_list : param COMMA param_list - | param + '''param_list : param param_list2 | empty ''' - if len(p) == 2: - p[0] = [p[1]] + if len(p) == 3: + p[0] = [p[1]] + p[2] else: - p[0] = [p[1]] + p[3] + p[0] = [] + +def p_param_list2(p): + '''param_list2 : COMMA param param_list2 + | empty + ''' + if len(p) == 4: + p[0] = [p[2]] + p[3] + else: + p[0] = [] def p_param(p): '''param : ID DOUBLE_DOT TYPE_ID @@ -89,9 +94,25 @@ def p_expr_list(p): p[0] = [p[1]] + p[3] def p_expr(p): - 'expr : arith' + 'expr : bool' p[0] = p[1] +def p_bool(p): + '''bool : arith MINOR arith + | arith MINOR_EQUALS arith + | arith EQUALS arith + | arith + ''' + if len(p) == 2: + p[0] = p[1] + else: + if p[2] == '<': + p[0] = MinorNode(p[1], p[3]) + elif p[2] == '<=': + p[0] = MinorEqualsNode(p[1], p[3]) + else: + p[0] = EqualsNode(p[1], p[3]) + def p_expr2(p): 'expr : ID LEFT_ARROW expr' p[0] = AssignNode(p[1], p[3]) @@ -254,7 +275,7 @@ def p_arg_list(p): def p_error(p): if p: - errors.append("sintax error at line " + str(p.lineno) + " --> token: '" + p.value + "'") + errors.append("sintax error at line " + str(p.lineno) + " --> token: '" + str(p.value) + "'") else: errors.append("sintanx error at end of file") @@ -282,7 +303,7 @@ def print_errors(self): ################ TEsting zone ########################### -data = '''''' +data = '''class A{f(a:A,b:B):B{1};};''' parser = yacc.yacc() result = parser.parse(data) if len(errors) == 0: diff --git a/tests/parser/block1.cl b/tests/parser/block1.cl index f15872812..9d2bb9107 100644 --- a/tests/parser/block1.cl +++ b/tests/parser/block1.cl @@ -31,12 +31,12 @@ class Test { testing5(a: String, b: String): IO { If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena").concat(a).concat(".")) eLSe if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena").concat(b).concat(".")) fI Fi }; diff --git a/tests/parser/block2.cl b/tests/parser/block2.cl index 1f45fca4c..da4deca18 100644 --- a/tests/parser/block2.cl +++ b/tests/parser/block2.cl @@ -31,12 +31,12 @@ class Test { testing5(a: String, b: String): IO { If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena").concat(a).concat(".")) eLSe if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena ").concat(b).concat(".")) fI Fi }; diff --git a/tests/parser/block3.cl b/tests/parser/block3.cl index 9b63b0015..0c2087707 100644 --- a/tests/parser/block3.cl +++ b/tests/parser/block3.cl @@ -31,12 +31,12 @@ class Test { testing5(a: String, b: String): IO { If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena ").concat(a).concat(".")) eLSe if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena ").concat(b).concat(".")) fI Fi }; From 857947c84e4e8197526af9fbac1940f0dfe3f22f Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 17:25:29 -0400 Subject: [PATCH 19/60] parametros en el dispathc --- src/compiler_components/cool_parser.py | 39 +++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index d78f69bf2..6a602c57c 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -241,36 +241,37 @@ def p_atomNhanhara(p): def p_func_call(p): '''func_call : factor DOT ID LPAREN arg_list RPAREN ''' - if not p[5][0] is None: - p[0] = CallNode(p[1], p[3], p[5]) - else: - p[0] = CallNode(p[1], p[3]) + p[0] = CallNode(p[1], p[3], p[5]) def p_func_call2(p): 'func_call : ID LPAREN arg_list RPAREN' - - if not p[3][0] is None: - p[0] = CallNode(None, p[1], p[3]) - else: - p[0] = CallNode(None, p[1]) + + p[0] = CallNode(None, p[1]) def p_func_call3(p): 'func_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN' - if not p[7][0] is None: - p[0] = CallNode(p[1], p[5], args = p[7], type = p[3]) - else: - p[0] = CallNode(p[1], p[5], args = None, type = p[3]) + + p[0] = CallNode(p[1], p[5], args = p[7], type = p[3]) + def p_arg_list(p): - '''arg_list : expr - | expr COMMA arg_list + '''arg_list : expr arg_list2 | empty ''' - if len(p) == 2: - p[0] = [p[1]] + if len(p) == 3: + p[0] = [p[1]] + p[2] else: - p[0] = [p[1]] + p[3] + p[0] = [] + +def p_arg_list2(p): + '''arg_list2 : COMMA expr arg_list2 + | empty + ''' + if len(p) == 4: + p[0] = [p[2]] + p[3] + else: + p[0] = [] def p_error(p): @@ -303,7 +304,7 @@ def print_errors(self): ################ TEsting zone ########################### -data = '''class A{f(a:A,b:B):B{1};};''' +data = '''''' parser = yacc.yacc() result = parser.parse(data) if len(errors) == 0: From 1169c5e70ec1d108e052a7d528771d892f693885 Mon Sep 17 00:00:00 2001 From: Carlos Alejandro Date: Tue, 12 Oct 2021 17:52:29 -0400 Subject: [PATCH 20/60] parser paso el test, solo falta arreglar los strings en el lexer --- tests/parser/let2.cl | 6 +++--- tests/parser/loop2.cl | 6 +++--- tests/parser/operation2.cl | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/parser/let2.cl b/tests/parser/let2.cl index 01d055dac..aa38fe9a6 100644 --- a/tests/parser/let2.cl +++ b/tests/parser/let2.cl @@ -31,12 +31,12 @@ class Test { testing5(a: String, b: String): IO { If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena ").concat(a).concat(".")) eLSe if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat("mide igual que la cadena ").concat(b).concat(".")) ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat("es mas larga que la cadena ").concat(b).concat(".")) fI Fi }; diff --git a/tests/parser/loop2.cl b/tests/parser/loop2.cl index 70f8cd910..857ffdc39 100644 --- a/tests/parser/loop2.cl +++ b/tests/parser/loop2.cl @@ -31,12 +31,12 @@ class Test { testing5(a: String, b: String): IO { If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena ").concat(a).concat(".")) eLSe if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena ").concat(b).concat(".")) fI Fi }; diff --git a/tests/parser/operation2.cl b/tests/parser/operation2.cl index 1f167409a..234fe2bc5 100644 --- a/tests/parser/operation2.cl +++ b/tests/parser/operation2.cl @@ -31,12 +31,12 @@ class Test { testing5(a: String, b: String): IO { If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena ").concat(a).concat("\.")) eLSe if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena ").concat(b).concat(".")) fI Fi }; From 6991f8b82fce0280f41973968d1e8c750356d715 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 22 Feb 2022 17:02:52 -0300 Subject: [PATCH 21/60] some structures for semantic checker added --- .../semantic/structures.py | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/compiler_components/semantic/structures.py diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py new file mode 100644 index 000000000..c008ba8c0 --- /dev/null +++ b/src/compiler_components/semantic/structures.py @@ -0,0 +1,99 @@ +class SemanticError(Exception): + @property + def text(self): + return f'({self.args[1]}, 11) - {self.__class__.__name__}: {self.args[0]}.' +class TypeError(SemanticError): + pass +class NameError(SemanticError): + pass +class AttributeError(SemanticError): + pass + +class Attribute: + def __init__(self, name, typex): + self.name = name + self.type = typex + +class Method: + def __init__(self, name, param_names, params_types, return_type): + self.name = name + self.param_names = param_names + self.param_types = params_types + self.return_type = return_type + +class Type: + def __init__(self, name:str,line=-1): + self.name = name + self.attributes = [] + self.methods = [] + self.parent = None + self.sons = [] + self.line = line + + def set_parent(self, parent, pos=0): + if self.parent is not None: + raise SemanticError(f'Parent type is already set for {self.name}', pos) + self.parent = parent + parent.sons.append(self) + + def get_attribute(self, name:str,pos=0): + try: + return next(attr for attr in self.attributes if attr.name == name) + except: + if self.parent is None: + raise SemanticError(f'Attribute "{name}" is not defined in {self.name}',pos) + try: + return self.parent.get_attribute(name) + except SemanticError: + raise SemanticError(f'Attribute "{name}" is not defined in {self.name}',pos) + + def define_attribute(self, name:str, typex, pos): + try: + self.get_attribute(name) + except SemanticError: + attribute = Attribute(name, typex) + self.attributes.append(attribute) + return attribute + else: + raise SemanticError(f'Attribute "{name}" is already defined in {self.name}',pos) + + def get_method(self, name:str,pos=0): + try: + return next(method for method in self.methods if method.name == name) + except StopIteration: + if self.parent is None: + raise AttributeError(f'Method "{name}" is not defined in {self.name}',pos) + try: + return self.parent.get_method(name) + except SemanticError: + raise AttributeError(f'Method "{name}" is not defined in {self.name}',pos) + + def define_method(self, name:str, param_names:list, param_types:list, return_type, pos): + try: + method = self.get_method(name, pos) + except SemanticError: + pass + else: + if method.return_type != return_type or method.param_types != param_types: + raise SemanticError(f'Method "{name}" already defined in {self.name} with a different signature.', pos) + for method in self.methods : + if method.name == name: + raise SemanticError(f'Method "{name}" already defined in {self.name} ', pos) + + method = Method(name, param_names, param_types, return_type) + self.methods.append(method) + + def all_attributes(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) + for attr in self.attributes: + plain[attr.name] = (attr, self) + return plain.values() if clean else plain + + def all_methods(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.all_methods(False) + for method in self.methods: + plain[method.name] = (method, self) + return plain.values() if clean else plain + + def conforms_to(self, other): + return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) \ No newline at end of file From 5a431c95b8c85602efd89af22569cd05c475571d Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 22 Feb 2022 17:15:32 -0300 Subject: [PATCH 22/60] some problems fixed with structures --- .../semantic/structures.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index c008ba8c0..dd0ccf844 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -21,6 +21,9 @@ def __init__(self, name, param_names, params_types, return_type): self.param_types = params_types self.return_type = return_type + def __eq__(self, other): + return other.name == self.name and other.return_type == self.return_type and other.param_types == self.param_types + class Type: def __init__(self, name:str,line=-1): self.name = name @@ -39,7 +42,7 @@ def set_parent(self, parent, pos=0): def get_attribute(self, name:str,pos=0): try: return next(attr for attr in self.attributes if attr.name == name) - except: + except StopIteration: if self.parent is None: raise SemanticError(f'Attribute "{name}" is not defined in {self.name}',pos) try: @@ -51,9 +54,9 @@ def define_attribute(self, name:str, typex, pos): try: self.get_attribute(name) except SemanticError: - attribute = Attribute(name, typex) - self.attributes.append(attribute) - return attribute + a = Attribute(name, typex) + self.attributes.append(a) + return a else: raise SemanticError(f'Attribute "{name}" is already defined in {self.name}',pos) @@ -71,17 +74,14 @@ def get_method(self, name:str,pos=0): def define_method(self, name:str, param_names:list, param_types:list, return_type, pos): try: method = self.get_method(name, pos) - except SemanticError: - pass - else: if method.return_type != return_type or method.param_types != param_types: raise SemanticError(f'Method "{name}" already defined in {self.name} with a different signature.', pos) - for method in self.methods : - if method.name == name: + else: raise SemanticError(f'Method "{name}" already defined in {self.name} ', pos) - - method = Method(name, param_names, param_types, return_type) - self.methods.append(method) + + except SemanticError: + method = Method(name, param_names, param_types, return_type) + self.methods.append(method) def all_attributes(self, clean=True): plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) From a061dbf9754891a8d519f3f273523e31e90765cc Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 22 Feb 2022 17:16:47 -0300 Subject: [PATCH 23/60] bypass added for types --- src/compiler_components/semantic/structures.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index dd0ccf844..0b7b02898 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -96,4 +96,7 @@ def all_methods(self, clean=True): return plain.values() if clean else plain def conforms_to(self, other): - return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) \ No newline at end of file + return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) + + def bypass(self): + return False \ No newline at end of file From d927adc9464f9f3a83a2a2e49c3030d012ae922f Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 22 Feb 2022 17:18:04 -0300 Subject: [PATCH 24/60] especial types added --- .../semantic/structures.py | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index 0b7b02898..a4a326cb1 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -99,4 +99,37 @@ def conforms_to(self, other): return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) def bypass(self): - return False \ No newline at end of file + return False + +class ErrorType(Type): + def __init__(self): + Type.__init__(self, '') + + def conforms_to(self, other): + return True + + def bypass(self): + return True + + def __eq__(self, other): + return isinstance(other, Type) + +class VoidType(Type): + def __init__(self): + Type.__init__(self, '') + + def conforms_to(self, other): + raise Exception('Invalid type: void type.') + + def bypass(self): + return True + + def __eq__(self, other): + return isinstance(other, VoidType) + +class SELF_TYPE(Type): + def __init__(self): + Type.__init__(self, "SELF_TYPE") + + def __eq__(self, other): + return isinstance(other, SELF_TYPE) From f03587570107025b5cbb3420cff65896616f1e5b Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Wed, 23 Feb 2022 11:09:50 -0500 Subject: [PATCH 25/60] Fill code generator --- .idea/.gitignore | 8 ++ .idea/cool-compiler-2021.iml | 12 ++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + src/compiler_components/cil_mips_converter.py | 122 ++++++++++++++++++ .../code_generator/__init__.py | 0 .../code_generator/cil_nodes.py | 0 .../code_generator/converter.py | 0 .../code_generator/converter_utils.py | 0 .../code_generator/mips_formatter.py | 0 .../code_generator/mips_nodes.py | 0 .../code_generator/visitor.py | 0 src/compiler_components/cool_cil_converter.py | 0 14 files changed, 162 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/cool-compiler-2021.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 src/compiler_components/cil_mips_converter.py create mode 100644 src/compiler_components/code_generator/__init__.py create mode 100644 src/compiler_components/code_generator/cil_nodes.py create mode 100644 src/compiler_components/code_generator/converter.py create mode 100644 src/compiler_components/code_generator/converter_utils.py create mode 100644 src/compiler_components/code_generator/mips_formatter.py create mode 100644 src/compiler_components/code_generator/mips_nodes.py create mode 100644 src/compiler_components/code_generator/visitor.py create mode 100644 src/compiler_components/cool_cil_converter.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/cool-compiler-2021.iml b/.idea/cool-compiler-2021.iml new file mode 100644 index 000000000..8b8c39547 --- /dev/null +++ b/.idea/cool-compiler-2021.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..b174ac29c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/compiler_components/cil_mips_converter.py b/src/compiler_components/cil_mips_converter.py new file mode 100644 index 000000000..0386690cc --- /dev/null +++ b/src/compiler_components/cil_mips_converter.py @@ -0,0 +1,122 @@ +def register_param(self, vinfo): + vinfo.cilName = vinfo.name # f'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' + param_node = cil.ParamNode(vinfo.cilName) + self.params.append(param_node) + return vinfo.cilName + + +def register_local(self, vinfo): + vinfo.cilName = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' + local_node = cil.LocalNode(vinfo.cilName) + self.localvars.append(local_node) + return vinfo.cilName + + +def register_label(self): + name = f'label_{self.current_function.name[9:]}_{len(self.labels)}' + self.labels.append(name) + return name + + +def define_internal_local(self): + vinfo = VariableInfo('internal', None) + return self.register_local(vinfo) + + +def register_instruction(self, instruction): + self.instructions.append(instruction) + return instruction + + +def to_function_name(self, method_name, type_name): + return f'function_{method_name}_at_{type_name}' + + +def to_attribute_name(self, attr_name, attr_type): + return f'attribute_{attr_name}' + + +def register_function(self, function_name): + function_node = cil.FunctionNode(function_name, [], [], [], []) + self.dotcode.append(function_node) + return function_node + + +def register_type(self, name): + type_node = cil.TypeNode(name) + self.dottypes.append(type_node) + return type_node + + +def register_data(self, value): + for dataNode in self.dotdata: + if dataNode.value == value: + return dataNode + + vname = f'data_{len(self.dotdata)}' + data_node = cil.DataNode(vname, value) + self.dotdata.append(data_node) + return data_node + + +def get_attr(self, function_name, attribute): + for dottype in self.dottypes: + if dottype.name == function_name: + break + + # for attrib in dottype.attributes: + # if self.to_attribute_name(attribute, None) == attrib: + # break + + return dottype.attributes.index(self.to_attribute_name(attribute, None)) + + +def get_method(self, type_name, method_name): + for typeContext in self.context.types: + if typeContext == type_name: + break + + methods = list(self.context.types[typeContext].all_methods()) + + for m in methods: + if m[0].name == method_name: + break + + return methods.index(m) + + +def sort_types(self, types): + q = queue.deque() + lst = [] + for tp1 in types: + if not any([x for x in types if x != tp1 and tp1.conforms_to(x)]): + q.append(tp1) + + while len(q) != 0: + tp = q.popleft() + if tp in types: + lst.append(tp) + for s in tp.sons: + q.append(s) + lst = list(reversed(lst)) + return lst + + +def get_preordenTypes(self, typex): + ret_lis = [] + + for son in typex.sons: + ret_lis.extend(self.get_preordenTypes(son)) + + ret_lis.append(typex) + return ret_lis + + +def box(self, typeName, value): + obj_internal = self.define_internal_local() + self.register_instruction(cil.AllocateNode(typeName, obj_internal)) + self.register_instruction(cil.SetAttribNode(obj_internal, 0, value)) + self.register_instruction(cil.LoadNode(obj_internal, f'{typeName}_name')) + self.register_instruction(cil.LoadIntNode(obj_internal, f'{typeName}_size', 4)) + self.register_instruction(cil.LoadNode(obj_internal, f'__virtual_table__{typeName}', 8)) + return obj_internal \ No newline at end of file diff --git a/src/compiler_components/code_generator/__init__.py b/src/compiler_components/code_generator/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/code_generator/cil_nodes.py b/src/compiler_components/code_generator/cil_nodes.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/code_generator/converter.py b/src/compiler_components/code_generator/converter.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/code_generator/converter_utils.py b/src/compiler_components/code_generator/converter_utils.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/code_generator/mips_formatter.py b/src/compiler_components/code_generator/mips_formatter.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/code_generator/mips_nodes.py b/src/compiler_components/code_generator/mips_nodes.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/code_generator/visitor.py b/src/compiler_components/code_generator/visitor.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/cool_cil_converter.py b/src/compiler_components/cool_cil_converter.py new file mode 100644 index 000000000..e69de29bb From 6e8b23ad0199bba7315e925ef3b722b304bc8660 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 23 Feb 2022 16:05:12 -0300 Subject: [PATCH 26/60] testing semantic checker --- src/compiler_components/__init__.py | 0 src/compiler_components/ast.py | 56 ++- src/compiler_components/code_generator.py | 14 +- src/compiler_components/compiler_component.py | 6 +- src/compiler_components/cool_parser.py | 38 +- src/compiler_components/lexer.py | 14 +- src/compiler_components/parsetab.py | 90 +++++ src/compiler_components/semantic/__init__.py | 0 .../semantic/structures.py | 186 ++++++++- .../semantic/type_builder.py | 52 +++ .../semantic/type_checker.py | 364 ++++++++++++++++++ .../semantic/type_collector.py | 68 ++++ src/compiler_components/semantic/visitor.py | 80 ++++ src/compiler_components/semantic_checker.py | 41 +- src/main.py | 4 +- src/program.txt | 14 + 16 files changed, 955 insertions(+), 72 deletions(-) create mode 100644 src/compiler_components/__init__.py create mode 100644 src/compiler_components/parsetab.py create mode 100644 src/compiler_components/semantic/__init__.py create mode 100644 src/compiler_components/semantic/type_builder.py create mode 100644 src/compiler_components/semantic/type_checker.py create mode 100644 src/compiler_components/semantic/type_collector.py create mode 100644 src/compiler_components/semantic/visitor.py create mode 100644 src/program.txt diff --git a/src/compiler_components/__init__.py b/src/compiler_components/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 4232a0efa..b618271cf 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -1,10 +1,11 @@ class Node: def visit(self, tabs = 0): - pass + self.line = -1 class ProgramNode(Node): def __init__(self, declarations): self.declarations = declarations + self.line = -1 def visit(self, tabs = 0): node = self ans = '\t' * tabs + f'\\__ProgramNode [ ... ]' @@ -20,6 +21,7 @@ class ExpressionNode(Node): class AtomicNode(ExpressionNode): def __init__(self, lex): self.lex = lex + self.line = -1 def visit(self, tabs = 0): node = self @@ -30,6 +32,7 @@ def __init__(self, idx, features, parent=None): self.id = idx self.parent = parent self.features = features + self.line = -1 def visit(self, tabs = 0): node = self @@ -45,12 +48,14 @@ def __init__(self, idx, params, return_type, body): self.params = params self.type = return_type self.body = body + self.line = -1 def visit(self, tabs = 0): node = self params = ', '.join(':'.join(param) for param in node.params) ans = '\t' * tabs + f'\\__FuncDeclarationNode: def {node.id}({params}) : {node.type} -> ' body = node.body.visit( tabs + 1) + self.line = -1 return f'{ans}\n{body}' class AttrDeclarationNode(DeclarationNode): @@ -58,6 +63,7 @@ def __init__(self, idx, typex, expr = None): self.id = idx self.type = typex self.expr = expr + self.line = -1 def visit(self, tabs = 0): node = self @@ -71,6 +77,7 @@ def __init__(self, idx, typex, expr): self.id = idx self.type = typex self.expr = expr + self.line = -1 def visit(self, tabs = 0): node = self @@ -82,6 +89,7 @@ class AssignNode(AtomicNode): def __init__(self, idx, expr): self.id = idx self.expr = expr + self.line = -1 def visit(self, tabs = 0): node = self @@ -92,6 +100,7 @@ def visit(self, tabs = 0): class IsVoidNode(AtomicNode): def __init__(self, expr): self.expr = expr + self.line = -1 def visit(self, tabs = 0): ans = '\t'*tabs + "\\__IsVoid " @@ -100,6 +109,7 @@ def visit(self, tabs = 0): class NotNode(AtomicNode): def __init__(self, expr): self.expr = expr + self.line = -1 def visit(self, tabs = 0): ans = '\t'*tabs + "\\__NOT " @@ -108,6 +118,7 @@ def visit(self, tabs = 0): class NhanharaNode(AtomicNode): def __init__(self, expr): self.expr = expr + self.line = -1 def visit(self, tabs = 0): ans = '\t'*tabs + "\\__~ " @@ -118,8 +129,12 @@ class CallNode(AtomicNode): def __init__(self, obj, idx, args = None, type = None): self.obj = obj self.id = idx - self.args = args + if args is None: + self.args = [] + else: + self.args = args self.type = type + self.line = -1 def visit(self, tabs = 0): node = self @@ -148,6 +163,7 @@ def __init__(self, if_c, then_c, else_c): self.if_c = if_c self.then_c = then_c self.else_c = else_c + self.line = -1 def visit(self, tabs = 0): node = self @@ -161,6 +177,7 @@ class WhileNode(AtomicNode): def __init__(self, condition, body): self.condition = condition self.body = body + self.line = -1 def visit(self, tabs = 0): node = self @@ -173,6 +190,7 @@ def visit(self, tabs = 0): class BlockNode(AtomicNode): def __init__(self, expr_list): self.expr_list = expr_list + self.line = -1 def visit(self, tabs = 0): ans = '\t'*tabs + " {; .... ;}\n" @@ -183,6 +201,7 @@ class LetNode(AtomicNode): def __init__(self, list_decl, expr): self.list_decl = list_decl self.expr = expr + self.line = -1 def visit(self, tabs = 0): ans = '\t'*tabs + " LET , ... in \n " @@ -194,6 +213,7 @@ class CaseNode(AtomicNode): def __init__(self, expr, list_case): self.list_case = list_case self.expr = expr + self.line = -1 def visit(self, tabs = 0): ans = '\t'*tabs + "\\__Case in esac" @@ -208,6 +228,7 @@ class BinaryNode(ExpressionNode): def __init__(self, left, right): self.left = left self.right = right + self.line = -1 def visit(self, tabs = 0): node = self @@ -216,6 +237,9 @@ def visit(self, tabs = 0): right = node.right.visit( tabs + 1) return f'{ans}\n{left}\n{right}' +class ArithmeticNode(BinaryNode): + pass + class ConstantNumNode(AtomicNode): pass @@ -229,19 +253,23 @@ class SelfNode(AtomicNode): pass class DispatchNode(ExpressionNode): - def __init__(self, expr, f, params, type = None): - super().__init__(None) - self.id = id + def __init__(self, expr, f, params, typex = None): + self.id = f + self.expr = expr self.f = f - self.params = params - self.type = type + if params is None: + self.params = [] + else: + self.params = params + self.typex = typex + self.line = -1 def visit(self, tabs = 0): node = self - if not self.type: + if not self.typex: ans = '\t' * tabs + f'\\__.{self.f} ' else: - ans = '\t' * tabs + f'\\__@{self.type}.{self.f} ' + ans = '\t' * tabs + f'\\__@{self.typex}.{self.f} ' expr = node.expr.visit( tabs + 1) params = '\n'.join(param.visit( tabs + 1) for param in node.params) return f'{ans}\n{expr}\n{params}' @@ -252,16 +280,16 @@ class InstantiateNode(AtomicNode): def visit(self, tabs): node = self return '\t' * tabs + f'\\__ InstantiateNode: new {node.lex}()' -class PlusNode(BinaryNode): +class PlusNode(ArithmeticNode): pass -class MinusNode(BinaryNode): +class MinusNode(ArithmeticNode): pass -class StarNode(BinaryNode): +class StarNode(ArithmeticNode): pass -class DivNode(BinaryNode): +class DivNode(ArithmeticNode): pass -class MinorNode(BinaryNode): +class MinorNode(ArithmeticNode): pass class MinorEqualsNode(BinaryNode): pass diff --git a/src/compiler_components/code_generator.py b/src/compiler_components/code_generator.py index a9066868a..f67018f44 100644 --- a/src/compiler_components/code_generator.py +++ b/src/compiler_components/code_generator.py @@ -1,16 +1,16 @@ -from compiler_component import CompilerComponent -from semantic_checker import SemanticChecker +from .compiler_component import CompilerComponent +from .semantic_checker import SemanticChecker class CodeGenerator(CompilerComponent): def __init__(self, semantic_checker: SemanticChecker) -> None: super().__init__() self.semantic_checker = semantic_checker - def execute(): - pass + def execute(self): + return - def has_errors(): - pass + def has_errors(self): + return False def print_errors(): - pass \ No newline at end of file + print("errors at code generator") \ No newline at end of file diff --git a/src/compiler_components/compiler_component.py b/src/compiler_components/compiler_component.py index 07cb596af..6767e1151 100644 --- a/src/compiler_components/compiler_component.py +++ b/src/compiler_components/compiler_component.py @@ -1,9 +1,9 @@ class CompilerComponent(): - def execute(): + def execute(self): pass - def has_errors(): + def has_errors(self): pass - def print_errors(): + def print_errors(self): pass \ No newline at end of file diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 6a602c57c..5a4830c6b 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -1,6 +1,6 @@ -from compiler_component import CompilerComponent -from lexer import Tokenizer, Lexer -from ast import * +from .compiler_component import CompilerComponent +from .lexer import Tokenizer, Lexer +from .ast import * import ply.yacc as yacc import ply.lex as lex @@ -98,12 +98,16 @@ def p_expr(p): p[0] = p[1] def p_bool(p): - '''bool : arith MINOR arith + '''bool : NOT bool + | arith MINOR arith | arith MINOR_EQUALS arith | arith EQUALS arith | arith ''' - if len(p) == 2: + if len(p) == 3: + p[0] = NotNode(p[2]) + + elif len(p) == 2: p[0] = p[1] else: if p[2] == '<': @@ -230,9 +234,11 @@ def p_atomIsVoid(p): 'atom : ISVOID factor' p[0] = IsVoidNode(p[2]) +''' def p_atomNot(p): 'atom : NOT factor' p[0] = NotNode(p[2]) +''' def p_atomNhanhara(p): 'atom : NHANHARA factor' @@ -241,17 +247,17 @@ def p_atomNhanhara(p): def p_func_call(p): '''func_call : factor DOT ID LPAREN arg_list RPAREN ''' - p[0] = CallNode(p[1], p[3], p[5]) + p[0] = DispatchNode(p[1], p[3], p[5]) def p_func_call2(p): 'func_call : ID LPAREN arg_list RPAREN' - p[0] = CallNode(None, p[1]) + p[0] = CallNode(None, p[1], p[3]) def p_func_call3(p): 'func_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN' - p[0] = CallNode(p[1], p[5], args = p[7], type = p[3]) + p[0] = DispatchNode(p[1], p[5], args = p[7], typex = p[3]) @@ -295,21 +301,9 @@ def execute(self): self.ast = parser.parse(self.lexer.cool_program) def has_errors(self): - return len(errors) == 0 + return len(errors) > 0 def print_errors(self): for e in errors: print(e) - print() - - -################ TEsting zone ########################### -data = '''''' -parser = yacc.yacc() -result = parser.parse(data) -if len(errors) == 0: - print(result.visit()) -else: - print(errors) - -######################################################## \ No newline at end of file + print() \ No newline at end of file diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index e317a43cd..85b212c05 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -1,4 +1,4 @@ -from compiler_component import CompilerComponent +from .compiler_component import CompilerComponent import ply.lex as lex # funcion que retorna el texto de la linea donde hubo un error lexico @@ -200,20 +200,10 @@ def execute(self): tokenizer = Tokenizer() lexer = lex.lex(tokenizer) tokens, self.errors = tokenizer.tokenize(self.cool_program, lexer) - for t in tokens: - print(t) def has_errors(self): - return len(self.errors) == 0 + return len(self.errors) > 0 def print_errors(self): for e in self.errors: print(e) - -########################### Testing ############################## -data = '''''' - -lexer = Lexer(data) -lexer.execute() -lexer.print_errors() -##### borrar luego ######################################## \ No newline at end of file diff --git a/src/compiler_components/parsetab.py b/src/compiler_components/parsetab.py new file mode 100644 index 000000000..be71a3152 --- /dev/null +++ b/src/compiler_components/parsetab.py @@ -0,0 +1,90 @@ + +# parsetab.py +# This file is automatically generated. Do not edit. +# pylint: disable=W,C,R +_tabversion = '3.10' + +_lr_method = 'LALR' + +_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SELF SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS TYPE_ID LBRACE feature_list RBRACE\n | CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE\n empty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT TYPE_ID\n | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : SELFatom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' + +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-2,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,39,41,42,43,44,46,47,49,50,51,52,65,66,77,81,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,133,135,140,142,143,],[5,17,18,-4,-10,-5,-35,-11,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,107,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-12,-54,-43,-56,144,]),'TYPE_ID':([4,9,19,31,48,61,75,132,],[6,15,24,60,77,88,102,138,]),'LBRACE':([6,15,30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,88,104,105,107,108,111,114,116,129,136,141,],[8,21,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,111,55,55,55,55,55,55,55,55,55,55,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,30,34,40,45,53,54,55,56,57,58,59,63,64,67,68,69,70,71,72,73,74,104,105,107,108,109,110,111,114,116,117,129,136,141,144,],[14,14,14,25,14,37,25,66,37,37,37,37,84,37,66,66,37,37,66,66,66,66,66,66,66,101,37,37,37,37,84,124,37,37,37,128,37,37,37,124,]),'RBRACE':([8,10,13,17,18,21,22,23,29,37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,80,86,87,90,94,95,96,97,98,99,100,103,106,107,112,120,121,125,130,131,135,140,142,],[-6,16,-9,-6,-6,-6,-7,-8,36,-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,106,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-18,-55,-19,-46,133,-44,-49,-54,-43,-56,]),'DOUBLE_DOT':([14,25,32,84,124,],[19,31,61,19,132,]),'LPAREN':([14,30,37,40,45,53,54,55,57,58,59,63,64,66,67,68,69,70,71,72,73,101,104,105,107,108,111,114,116,128,129,136,141,],[20,45,64,45,45,45,45,45,45,45,45,45,45,64,45,45,45,45,45,45,45,116,45,45,45,45,45,45,45,136,45,45,45,]),'RPAREN':([20,26,27,28,33,35,37,39,41,42,43,44,46,47,49,50,51,52,60,62,64,65,66,76,77,86,87,89,90,91,92,93,94,95,96,97,98,99,100,103,106,112,113,115,116,121,126,127,130,131,134,135,136,139,140,142,],[-6,32,-6,-14,-13,-16,-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-17,-6,-6,-21,-35,103,-38,-52,-53,-15,-26,112,-6,-58,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-57,-60,-6,-46,-6,135,-44,-49,-59,-54,-6,142,-43,-56,]),'COMMA':([24,27,37,38,39,41,42,43,44,46,47,49,50,51,52,60,62,65,66,77,83,86,87,90,92,94,95,96,97,98,99,100,103,106,112,121,126,130,131,135,140,142,],[-10,34,-35,-11,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-17,34,-21,-35,-38,109,-52,-53,-26,114,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,114,-44,-49,-54,-43,-56,]),'IN':([24,37,38,39,41,42,43,44,46,47,49,50,51,52,65,66,77,82,83,86,87,90,94,95,96,97,98,99,100,103,106,112,121,122,130,131,135,140,142,],[-10,-35,-11,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,108,-47,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-48,-44,-49,-54,-43,-56,]),'LEFT_ARROW':([24,37,],[30,63,]),'NOT':([30,40,45,53,54,55,57,63,64,104,105,107,108,111,114,116,129,136,141,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'NUMBER':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'NEW':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'STRING':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'TRUE':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'FALSE':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'SELF':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'IF':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'WHILE':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'LET':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,]),'CASE':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'ISVOID':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'NHANHARA':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'DOT':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,102,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,74,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,74,74,-26,-22,-23,-24,-28,-29,74,74,117,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'ARROBA':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,75,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,75,75,-26,-22,-23,-24,-28,-29,75,75,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'TIMES':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,72,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,72,72,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'DIVIDE':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,73,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,73,73,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'MINOR':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,67,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'MINOR_EQUALS':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,68,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'EQUALS':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,69,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'PLUS':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,70,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,70,70,70,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'MINUS':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,71,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,71,71,71,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'THEN':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,78,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,104,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'LOOP':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,79,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,105,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'OF':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,85,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,110,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'ELSE':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,118,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,129,-46,-44,-49,-54,-43,-56,]),'POOL':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,119,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,130,-46,-44,-49,-54,-43,-56,]),'FI':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,137,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,140,-43,-56,]),'ESAC':([123,144,145,],[131,-50,-51,]),'RIGHT_ARROW':([138,],[141,]),} + +_lr_action = {} +for _k, _v in _lr_action_items.items(): + for _x,_y in zip(_v[0],_v[1]): + if not _x in _lr_action: _lr_action[_x] = {} + _lr_action[_x][_k] = _y +del _lr_action_items + +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,29,]),'def_attr':([8,17,18,21,56,109,],[11,11,11,11,83,83,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'empty':([8,17,18,20,21,27,62,64,92,116,126,136,],[13,13,13,28,13,35,35,93,115,93,115,93,]),'param_list':([20,],[26,]),'param':([20,34,],[27,62,]),'param_list2':([27,62,],[33,89,]),'expr':([30,45,53,54,55,57,63,64,104,105,107,108,111,114,116,129,136,141,],[38,76,78,79,81,85,90,92,118,119,81,121,125,126,92,137,92,143,]),'bool':([30,40,45,53,54,55,57,63,64,104,105,107,108,111,114,116,129,136,141,],[39,65,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'arith':([30,40,45,53,54,55,57,63,64,67,68,69,104,105,107,108,111,114,116,129,136,141,],[41,41,41,41,41,41,41,41,41,94,95,96,41,41,41,41,41,41,41,41,41,41,]),'term':([30,40,45,53,54,55,57,63,64,67,68,69,70,71,104,105,107,108,111,114,116,129,136,141,],[42,42,42,42,42,42,42,42,42,42,42,42,97,98,42,42,42,42,42,42,42,42,42,42,]),'factor':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[43,43,43,43,43,43,43,86,87,43,43,43,43,43,43,43,99,100,43,43,43,43,43,43,43,43,43,43,]),'atom':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'func_call':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'expr_list':([55,107,],[80,120,]),'atr_decl_list':([56,109,],[82,122,]),'arg_list':([64,116,136,],[91,127,139,]),'arg_list2':([92,126,],[113,134,]),'case_list':([110,144,],[123,145,]),} + +_lr_goto = {} +for _k, _v in _lr_goto_items.items(): + for _x, _y in zip(_v[0], _v[1]): + if not _x in _lr_goto: _lr_goto[_x] = {} + _lr_goto[_x][_k] = _y +del _lr_goto_items +_lr_productions = [ + ("S' -> program","S'",1,None,None,None), + ('program -> class_list','program',1,'p_program','cool_parser.py',14), + ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','cool_parser.py',18), + ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','cool_parser.py',19), + ('def_class -> CLASS TYPE_ID LBRACE feature_list RBRACE','def_class',5,'p_def_class','cool_parser.py',27), + ('def_class -> CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE','def_class',7,'p_def_class','cool_parser.py',28), + ('empty -> ','empty',0,'p_empty','cool_parser.py',36), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',40), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',41), + ('feature_list -> empty','feature_list',1,'p_feature_list','cool_parser.py',42), + ('def_attr -> ID DOUBLE_DOT TYPE_ID','def_attr',3,'p_def_attr','cool_parser.py',50), + ('def_attr -> ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',51), + ('def_func -> ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE','def_func',9,'p_def_func','cool_parser.py',59), + ('param_list -> param param_list2','param_list',2,'p_param_list','cool_parser.py',65), + ('param_list -> empty','param_list',1,'p_param_list','cool_parser.py',66), + ('param_list2 -> COMMA param param_list2','param_list2',3,'p_param_list2','cool_parser.py',74), + ('param_list2 -> empty','param_list2',1,'p_param_list2','cool_parser.py',75), + ('param -> ID DOUBLE_DOT TYPE_ID','param',3,'p_param','cool_parser.py',83), + ('expr_list -> expr SEMICOLON','expr_list',2,'p_expr_list','cool_parser.py',88), + ('expr_list -> expr SEMICOLON expr_list','expr_list',3,'p_expr_list','cool_parser.py',89), + ('expr -> bool','expr',1,'p_expr','cool_parser.py',97), + ('bool -> NOT bool','bool',2,'p_bool','cool_parser.py',101), + ('bool -> arith MINOR arith','bool',3,'p_bool','cool_parser.py',102), + ('bool -> arith MINOR_EQUALS arith','bool',3,'p_bool','cool_parser.py',103), + ('bool -> arith EQUALS arith','bool',3,'p_bool','cool_parser.py',104), + ('bool -> arith','bool',1,'p_bool','cool_parser.py',105), + ('expr -> ID LEFT_ARROW expr','expr',3,'p_expr2','cool_parser.py',121), + ('arith -> term','arith',1,'p_arith','cool_parser.py',125), + ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',126), + ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',127), + ('term -> factor','term',1,'p_term','cool_parser.py',138), + ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',139), + ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',140), + ('factor -> atom','factor',1,'p_factor','cool_parser.py',151), + ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',152), + ('atom -> ID','atom',1,'p_atom1','cool_parser.py',161), + ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',165), + ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',169), + ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',173), + ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',178), + ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',183), + ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',184), + ('atom -> SELF','atom',1,'p_atomSelf','cool_parser.py',192), + ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',196), + ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',200), + ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',203), + ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',207), + ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',211), + ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',212), + ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',221), + ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',225), + ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',226), + ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',234), + ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',244), + ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',248), + ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',253), + ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',258), + ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',265), + ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',266), + ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',274), + ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',275), +] diff --git a/src/compiler_components/semantic/__init__.py b/src/compiler_components/semantic/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index a4a326cb1..0758df629 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -1,19 +1,31 @@ +from collections import OrderedDict +import itertools as itt + +############# Semantic Errors ####################### class SemanticError(Exception): @property def text(self): - return f'({self.args[1]}, 11) - {self.__class__.__name__}: {self.args[0]}.' + return str(self.args[1][0]) class TypeError(SemanticError): pass class NameError(SemanticError): pass class AttributeError(SemanticError): pass +############## End Semantic Errors ############################# +############ Class members ############################### class Attribute: def __init__(self, name, typex): self.name = name self.type = typex + def __str__(self): + return f'[attrib] {self.name} : {self.type.name};' + + def __repr__(self): + return str(self) + class Method: def __init__(self, name, param_names, params_types, return_type): self.name = name @@ -21,9 +33,18 @@ def __init__(self, name, param_names, params_types, return_type): self.param_types = params_types self.return_type = return_type + def __str__(self): + params = ', '.join(f'{n}:{t.name}' for n,t in zip(self.param_names, self.param_types)) + return f'[method] {self.name}({params}): {self.return_type.name};' + def __eq__(self, other): - return other.name == self.name and other.return_type == self.return_type and other.param_types == self.param_types + return other.name == self.name and \ + other.return_type == self.return_type and \ + other.param_types == self.param_types +################# End Class Members ######################################### + +############# Type ####################################### class Type: def __init__(self, name:str,line=-1): self.name = name @@ -79,11 +100,11 @@ def define_method(self, name:str, param_names:list, param_types:list, return_ty else: raise SemanticError(f'Method "{name}" already defined in {self.name} ', pos) - except SemanticError: + except SemanticError: method = Method(name, param_names, param_types, return_type) self.methods.append(method) - def all_attributes(self, clean=True): + """ def all_attributes(self, clean=True): plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) for attr in self.attributes: plain[attr.name] = (attr, self) @@ -93,7 +114,7 @@ def all_methods(self, clean=True): plain = OrderedDict() if self.parent is None else self.parent.all_methods(False) for method in self.methods: plain[method.name] = (method, self) - return plain.values() if clean else plain + return plain.values() if clean else plain """ def conforms_to(self, other): return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) @@ -101,6 +122,13 @@ def conforms_to(self, other): def bypass(self): return False + def __str__(self): + output = f'{self.name}' + return output + + def __repr__(self): + return str(self) + class ErrorType(Type): def __init__(self): Type.__init__(self, '') @@ -133,3 +161,151 @@ def __init__(self): def __eq__(self, other): return isinstance(other, SELF_TYPE) + +########### End Type ########################## + + +########## Context ################################### +class Context: + def __init__(self): + self.types = {} + self.built_in() + + def built_in(self): + Bool = Type("Bool") + self.types["Bool"] = Bool + + Int = Type("Int") + self.types["Int"] = Int + + Object = Type("Object") + self.types["Object"] =Object + + String = Type("String") + self.types["String"] = String + + IO = Type("IO") + self.types['IO']= IO + + Object.define_method("abort",[],[],Object,0) + Object.define_method("type_name",[],[],String,0) + Object.define_method("copy",[],[],SELF_TYPE(),0) + + String.define_method("length",[],[],Int,0) + String.define_method("concat",['s'],[String],String,0) + String.define_method("substr",['i','l'],[Int,Int],SELF_TYPE(),0) + + IO.define_method("out_string",["x"],[String],SELF_TYPE(),0) + IO.define_method("out_int",['x'],[Int],SELF_TYPE(),0) + IO.define_method("in_int",[],[],Int,0) + IO.define_method("in_string",[], [], String, 0) + + def check_type(self,x:Type,y:Type,pos): + if not x.conforms_to(y) : + raise(TypeError(f"Expr type {x.name} is no subclass of {y.name} ",pos)) + + def create_type(self, name:str,pos=0): + if name in self.types: + raise SemanticError(f'Type with the same name ({name}) already in context.' , pos) + t = self.types[name] = Type(name,pos) + return t + + def get_type(self, name:str,pos=0): + try: + return self.types[name] + except KeyError: + raise TypeError(f'Type "{name}" is not defined.' , pos) + + def closest_common_antecesor(self, type1:Type, type2:Type): + antecesors = [] + while not type1 is None or not type2 is None : + if not type2 is None : + if type2 in antecesors: + return type2 + antecesors.append(type2) + + if not type1 is None: + if type1 in antecesors: + return type1 + antecesors.append(type1) + + if not type1 is None: + type1 = type1.parent + if not type2 is None: + type2 = type2.parent + + return self.get_type("Object") + + def circular_dependency(self): + visited = set() + on_cycle = {} + count = 0 + for tp in self.types: + temp = self.types[tp] + ancestors = set() + while True: + if temp.name in visited: + break + ancestors.add(temp.name) + visited.add(temp.name) + if temp.parent is None: + break + if temp.parent.name in ancestors: + on_cycle[count] = [] + on_cycle[count].append((temp.name,temp.line)) + temp2 = temp.parent + while temp != temp2: + on_cycle[count].append((temp2.name,temp2.line)) + temp2 = temp2.parent + on_cycle[count].sort(key= lambda x:x[1],reverse=True) + count = count + 1 + break + temp = temp.parent + return on_cycle.values() +############ End Context ######################## + +class VariableInfo: + def __init__(self, name, typex): + self.name = name + self.type = typex + +################## Scope ############################## +class Scope: + def __init__(self, parent=None): + self.locals = [] + self.parent = parent + self.children = [] + self.id = 0 + self.index = 0 if parent is None else len(parent) + + def __len__(self): + return len(self.locals) + + def create_child(self): + child = Scope(self) + child.id = self.id*10 +len(self.children) + self.children.append(child) + return child + + def is_defined(self, vname): + return self.find_variable(vname) is not None + + def is_local(self, vname): + return any(True for x in self.locals if x.name == vname) + + def define_variable(self, vname, vtype,pos=0): + if self.is_local(vname): + raise SemanticError(f"Variable {vname} already define in scope " , pos) + v = VariableInfo(vname, vtype) + self.locals.append(v) + return v + + def find_variable(self, vname, index=None): + locals = self.locals if index is None else itt.islice(self.locals, index) + try: + return next(x for x in locals if x.name == vname) + except StopIteration: + if not self.parent is None: + return self.parent.find_variable(vname, self.index) + else: + return None \ No newline at end of file diff --git a/src/compiler_components/semantic/type_builder.py b/src/compiler_components/semantic/type_builder.py new file mode 100644 index 000000000..b5be263c3 --- /dev/null +++ b/src/compiler_components/semantic/type_builder.py @@ -0,0 +1,52 @@ +import sys +sys.path.append('../') +from ..ast import * +from . import visitor +import queue + +def sort_types(types): + q = queue.deque() + result = [] + for tp in types: + if types[tp].parent is None: + if tp != "Object": + types[tp].set_parent(types["Object"]) + + q.append("Object") + while len(q) != 0: + tp = q.popleft() + result.append(tp) + for son in types[tp].sons: + q.append(son.name) + return result + +class TypeBuilder: + def __init__(self, context, errors=[]): + self.context = context + self.errors = errors + + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node): + nodec={ def_class.id:def_class for def_class in node.declarations} + sorted_types = sort_types(self.context.types) + for stypes in sorted_types: + if stypes in nodec: + self.visit(nodec[stypes]) + + @visitor.when(ProgramNode) + def visit(self, node): + nodec={ def_class.id:def_class for def_class in node.declarations} + sorted_types = sort_types(self.context.types) + for stypes in sorted_types: + if stypes in nodec: + self.visit(nodec[stypes]) + + @visitor.when(ClassDeclarationNode) + def visit(self, node): + self.current_type = self.context.get_type(node.id,-1) #change -1 for line number + for feature in node.features: + self.visit(feature) \ No newline at end of file diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py new file mode 100644 index 000000000..ba27a9d30 --- /dev/null +++ b/src/compiler_components/semantic/type_checker.py @@ -0,0 +1,364 @@ +import sys +sys.path.append('../') +from ..ast import * +from .structures import * +from . import visitor + +class TypeChecker: + def __init__(self, context:Context, errors=[]): + self.context = context + self.current_type = None + self.errors = errors + + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node:ProgramNode, scope=None): + for dec in node.declarations: + try: + self.visit(dec,scope.create_child()) + except SemanticError as e: + self.errors.append(e) + + + @visitor.when(ClassDeclarationNode) + def visit(self, node:ClassDeclarationNode, scope:Scope): + try : + typex = self.context.get_type(node.id, node.line) + except SemanticError as e: + self.errors.append(e) + + self.current_type = typex + #for at in typex.all_attributes(): + # scope.define_variable(at[0].name, at[0].type,node.line) + scope.define_variable("self",typex,node.line) + mscope = scope.create_child() + ascope = scope.create_child() + for feat in node.features: + if isinstance(feat, FuncDeclarationNode): + self.visit(feat,mscope.create_child()) + else: + self.visit(feat, ascope.create_child()) + + @visitor.when(AttrDeclarationNode) + def visit(self, node:AttrDeclarationNode,scope:Scope): + self.visit(node.expr, scope.create_child()) + if not node.expr is None: + try: + typex =self.current_type if node.type == "SELF_TYPE" else self.context.get_type(node.type,node.line) + self.context.check_type(node.expr.type,typex,node.line) + except SemanticError as e: + self.errors.append(e) + + @visitor.when(FuncDeclarationNode) + def visit(self, node:FuncDeclarationNode,scope:Scope): + + method = self.current_type.get_method(node.id) + for i in range(len(method.param_names)): + try: + if method.param_names[i] == "self": + raise SemanticError('Trying to assign value to self' ,node.line) + scope.define_variable(method.param_names[i],method.param_types[i],node.line) + except SemanticError as e: + self.errors.append(e) + + self.visit(node.body,scope.create_child()) + try: + typex = method.return_type if not isinstance(method.return_type,SELF_TYPE) else self.current_type + self.context.check_type(node.body.type,typex,node.line) + except SemanticError as e: + self.errors.append(e) + + + @visitor.when(CaseNode) + def visit(self, node:CaseNode, scope:Scope): + node.type = ErrorType() + sce = scope.create_child() + self.visit(node.expression, sce) + scb = scope.create_child() + common_type = None + typesbr = set() + for branches in node.branches: + tmpscope = scb.create_child() + if branches[1 ]in typesbr: + self.errors.append(SemanticError("Type in more than one branch",branches[2].line)) + typesbr.add(branches[1]) + try : + typex = self.context.get_type(branches[1],branches[2].line) + except SemanticError as e: + self.errors.append(e) + tmpscope.define_variable(branches[0],typex,node.line) + self.visit(branches[2],tmpscope) + if common_type is None: + common_type = branches[2].type + else: + common_type = self.context.closest_common_antecesor(common_type,branches[2].type) + + node.type = common_type + + + + + + @visitor.when(DispatchNode) + def visit(self, node:DispatchNode, scope:Scope): + self.visit(node.expr,scope.create_child()) + node.type = ErrorType() + node.typexa = node.typex + for i in range(len(node.params)): + self.visit(node.params[i],scope.create_child()) + + if not node.typex is None: + try: + temp = self.context.get_type(node.typex,node.line) + self.context.check_type(node.obj.type,temp,node.line) + except SemanticError as e: + self.errors.append(e) + return + else: + if isinstance( node.expr.type , ErrorType): + return + node.typex = node.expr.type.name + try: + typex = self.context.get_type(node.typex,node.line) + except SemanticError as e: + self.errors.append(e) + return + try : + if isinstance( typex , ErrorType): + return + method = typex.get_method(node.id,node.line) + + ret_type = method.return_type if not isinstance(method.return_type,SELF_TYPE) else typex + node.type = ret_type + if len(method.param_types) != len(node.params): + raise SemanticError (f'Method takes {len(method.param_types)} params but {len(node.params)} were given', node.line) + for i in range(len(node.params)): + try: + self.context.check_type(node.params[i].type,method.param_types[i],node.line) + except SemanticError as e: + self.errors.append(e) + except SemanticError as e: + self.errors.append(e) + + @visitor.when(CallNode) + def visit(self, node:CallNode, scope:Scope): + node.type = ErrorType() + for i in range(len(node.args)): + self.visit(node.args[i],scope.create_child()) + + typex = self.current_type + try : + if isinstance( typex , ErrorType): + return + method = typex.get_method(node.id, node.line) + ret_type = method.return_type if not isinstance(method.return_type,SELF_TYPE) else typex + node.type = ret_type + if len(method.param_types) != len(node.args): + raise SemanticError (f'Method {node.id} takes {len(method.param_types)} params but {len(node.args)} were given') + for i in range(len(node.args)): + try: + self.context.check_type(node.args[i].type,method.param_types[i],node.line) + except SemanticError as e: + self.errors.append(e) + except SemanticError as e: + self.errors.append(e) + + + + + @visitor.when(IfNode) + def visit(self,node:IfNode,scope:Scope): + self.visit(node.condition,scope.create_child()) + try: + self.context.check_type(node.condition.type,self.context.get_type("Bool"),node.line) + except SemanticError as e: + self.errors.append(e) + + self.visit(node.if_body,scope.create_child()) + + self.visit(node.else_body, scope.create_child()) + + try: + node.type = self.context.closest_common_antecesor(node.if_body.type, node.else_body.type) + except SemanticError as e: + self.errors.append(e) + node.type = ErrorType() + + + @visitor.when(AssignNode) + def visit(self, node:AssignNode,scope:Scope): + self.visit(node.expr, scope.create_child()) + try: + if node.id == "self": + raise SemanticError('Trying to assign value to self' ,node.line) + + var = scope.find_variable(node.id) + + if var is None: + try: + at = [ at[0] for at in self.current_type.all_attributes() if at[0].name == node.id] + var = at[0] + except: + raise NameError(f"Variable {node.id} not defined",node.line) + + typex = self.current_type if isinstance(var.type , SELF_TYPE) else var.type + self.context.check_type(node.expr.type, typex, node.line) + node.type = node.expr.type + except SemanticError as e: + self.errors.append(e) + node.type = node.expr.type + + + @visitor.when(WhileNode) + def visit(self , node:WhileNode, scope:Scope): + self.visit(node.condition, scope.create_child()) + if self.context.get_type("Bool",node.line) != node.condition.type: + self.errors.append(TypeError("Expr should be boolean", node.line)) + self.visit(node.body, scope.create_child()) + node.type = self.context.get_type("Object",node.line) + + + @visitor.when(BlockNode) + def visit (self, node:BlockNode, scope:Scope): + for expr in node.expressions: + self.visit(expr,scope.create_child()) + node.type = node.expressions[-1].type + + + @visitor.when(LetNode) + def visit(self, node:LetNode,scope:Scope): + sc = scope.create_child() + for init in node.list_decl: + if not init is None: + self.visit(init.expr,sc) + try: + typex = self.context.get_type(str(init.expr.type),node.line) if init.expr.type != "SELF_TYPE" else self.current_type + typey = self.context.get_type(str(init.type),node.line) if init.expr.type != "SELF_TYPE" else self.current_type + self.context.check_type(typey,typex,node.line) + except SemanticError as e: + self.errors.append(e) + + sc = sc.create_child() + typex= None + try: + typex = self.context.get_type(init.type,node.line) if init.type != "SELF_TYPE" else self.current_type + except SemanticError as e: + self.errors.append(e) + typex = ErrorType() + try: + if init.id == "self": + raise SemanticError('Trying to assign value to self' ,node.line) + sc.define_variable(init.id,typex,node.line) + except SemanticError as e: + self.errors.append(e) + + sc = sc.create_child() + node.body_scope=sc + self.visit(node.expr,sc) + node.type = node.expr.type + + + @visitor.when(InstantiateNode) + def visit(self, node:InstantiateNode,scope:Scope): + try: + if node.lex == "SELF_TYPE": + node.type= self.current_type + else: + node.type = self.context.get_type(node.lex,node.line) + except SemanticError as e: + self.errors.append(e) + node.type = ErrorType() + + + + @visitor.when(IsVoidNode) + def visit(self, node:IsVoidNode, scope:Scope): + + self.visit(node.expression,scope.create_child()) + node.type = self.context.get_type("Bool", node.line) + + + @visitor.when(ArithmeticNode) + def visit(self, node:ArithmeticNode,scope:Scope): + self.visit(node.left,scope.create_child()) + self.visit(node.right,scope.create_child()) + if node.left.type != self.context.get_type("Int", node.line) or node.right.type != self.context.get_type("Int", node.line): + self.errors.append("The static types of the two sub-expressions must be Int.") + + node.type = self.context.get_type("Int", node.line) + + + @visitor.when(MinorNode) + def visit(self, node:MinorNode,scope:Scope): + self.visit(node.left,scope.create_child()) + if node.left.type != self.context.get_type("Int", node.line): + self.errors.append("Expr must be Int not " + str(node.left.type)) + self.visit(node.right,scope.create_child()) + if node.right.type != self.context.get_type("Int", node.line): + self.errors.append("Expr must be Int not " + str(node.right.type)) + node.type = self.context.get_type("Bool", node.line) + + @visitor.when(MinorEqualsNode) + def visit(self, node:MinorEqualsNode, scope:Scope): + self.visit(node.left,scope.create_child()) + if node.left.type != self.context.get_type("Int", node.line): + self.errors.append("Expr must be Int not " + str(node.left.type)) + self.visit(node.right,scope.create_child()) + if node.right.type != self.context.get_type("Int", node.line): + self.errors.append("Expr must be Int not " + str(node.right.type)) + node.type = self.context.get_type("Bool", node.line) + + @visitor.when(EqualsNode) + def visit(self, node:EqualsNode, scope:Scope): + self.visit(node.left,scope.create_child()) + self.visit(node.right,scope.create_child()) + if node.left.type != node.right.type: + basic = ['Int', 'String', 'Bool'] + if node.left.type.name in basic or node.right.type.name in basic: + self.errors.append(TypeError("Exprs must have same type", node.line)) + node.type = self.context.get_type("Bool", node.line) + + @visitor.when(NhanharaNode) + def visit(self, node:NhanharaNode, scope:Scope): + self.visit(node.expr, scope.create_child()) + if node.expr.type != self.context.get_type("Int", node.line): + self.errors.append("Expr must be an int not " + str(node.expr.type)) + node.type = self.context.get_type("Int", node.line) + + @visitor.when(NotNode) + def visit(self, node:NotNode, scope:Scope): + self.visit(node.expr, scope.create_child()) + if node.expr.type != self.context.get_type("Bool", node.line): + self.errors.append("Expr must be Bool not " + str(node.expr.type)) + node.type = self.context.get_type("Bool", node.line) + + + @visitor.when(ConstantNumNode) + def visit (self, node:ConstantNumNode,scope:Scope): + node.type = self.context.get_type("Int", node.line) + + @visitor.when(ConstantStringNode) + def visit (self, node:ConstantStringNode, scope:Scope): + node.type = self.context.get_type("String", node.line) + + @visitor.when(ConstantBooleanNode) + def visit (self, node:ConstantBooleanNode, scope:Scope): + node.type = self.context.get_type("Bool",node.line) + + @visitor.when(VariableNode) + def visit (self, node:VariableNode,scope:Scope): + + x = scope.find_variable(node.lex) + if x is None: + try: + at = [ at[0] for at in self.current_type.all_attributes() if at[0].name == node.lex] + x = at[0] + except: + node.type = ErrorType() + self.errors.append(NameError(f"Variable {node.lex} not defined",node.line)) + return + node.type = x.type if not isinstance(x.type , SELF_TYPE) else self.current_type + diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py new file mode 100644 index 000000000..9e8aba8e4 --- /dev/null +++ b/src/compiler_components/semantic/type_collector.py @@ -0,0 +1,68 @@ + +import sys, os +sys.path.append('../') + +from . import visitor +from ..ast import * +import queue +from .structures import * + + +class TypeCollector(object): + def __init__(self, errors=[]): + self.context = None + self.errors = errors + + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node): + self.context = Context() + for decl in node.declarations: + self.visit(decl) + for dec_node in node.declarations: + try: + if dec_node.parent is not None: + if dec_node.parent in ["String","Int","Bool"]: + self.errors.append(SemanticError("Basic type as parent", dec_node.line)) + self.context.get_type(dec_node.id, dec_node.line).set_parent(self.context.get_type(dec_node.parent,dec_node.line),node.line) + except SemanticError as e: + self.errors.append(e) + + @visitor.when(ClassDeclarationNode) + def visit(self, node): + self.current_type = self.context.create_type(node.id,node.line) + for feature in node.features: + self.visit(feature) + + @visitor.when(AttrDeclarationNode) + def visit(self, node): + try: + attr_type = SELF_TYPE() if node.type == "SELF_TYPE" else self.context.get_type(node.type,-1) #change -1 for line number + if node.id == "self": + raise SemanticError('Trying to assign value to self' ,-1) #change -1 for line number + self.current_type.define_attribute(node.id, attr_type, -1) #change -1 for line number + except SemanticError as e: + self.errors.append(e) + + @visitor.when(FuncDeclarationNode) + def visit(self, node): + arg_names = [param[0] for param in node.params] + arg_types = [] + for param in node.params: + try: + arg_types.append(self.context.get_type(param[1],node.line) ) + except SemanticError as e: + self.errors.append(e) + arg_types.append(ErrorType()) + try: + ret_type = SELF_TYPE() if node.type =="SELF_TYPE" else self.context.get_type(node.type,node.line) + except SemanticError as e: + self.errors.append(e) + ret_type = ErrorType() + try: + self.current_type.define_method(node.id, arg_names, arg_types, ret_type, node.line) + except SemanticError as e: + self.errors.append(e) \ No newline at end of file diff --git a/src/compiler_components/semantic/visitor.py b/src/compiler_components/semantic/visitor.py new file mode 100644 index 000000000..964842836 --- /dev/null +++ b/src/compiler_components/semantic/visitor.py @@ -0,0 +1,80 @@ +# The MIT License (MIT) +# +# Copyright (c) 2013 Curtis Schlak +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import inspect + +__all__ = ['on', 'when'] + +def on(param_name): + def f(fn): + dispatcher = Dispatcher(param_name, fn) + return dispatcher + return f + + +def when(param_type): + def f(fn): + frame = inspect.currentframe().f_back + func_name = fn.func_name if 'func_name' in dir(fn) else fn.__name__ + dispatcher = frame.f_locals[func_name] + if not isinstance(dispatcher, Dispatcher): + dispatcher = dispatcher.dispatcher + dispatcher.add_target(param_type, fn) + def ff(*args, **kw): + return dispatcher(*args, **kw) + ff.dispatcher = dispatcher + return ff + return f + + +class Dispatcher(object): + def __init__(self, param_name, fn): + frame = inspect.currentframe().f_back.f_back + top_level = frame.f_locals == frame.f_globals + self.param_index = self.__argspec(fn).args.index(param_name) + self.param_name = param_name + self.targets = {} + + def __call__(self, *args, **kw): + typ = args[self.param_index].__class__ + d = self.targets.get(typ) + if d is not None: + return d(*args, **kw) + else: + issub = issubclass + t = self.targets + ks = t.keys() + ans = [t[k](*args, **kw) for k in ks if issub(typ, k)] + if len(ans) == 1: + return ans.pop() + return ans + + def add_target(self, typ, target): + self.targets[typ] = target + + @staticmethod + def __argspec(fn): + # Support for Python 3 type hints requires inspect.getfullargspec + if hasattr(inspect, 'getfullargspec'): + return inspect.getfullargspec(fn) + else: + return inspect.getargspec(fn) diff --git a/src/compiler_components/semantic_checker.py b/src/compiler_components/semantic_checker.py index 25f32a25c..e84fcf5df 100644 --- a/src/compiler_components/semantic_checker.py +++ b/src/compiler_components/semantic_checker.py @@ -1,16 +1,41 @@ -from compiler_component import CompilerComponent -from cool_parser import Parser +import sys +sys.path.append('./semantic') +from .semantic.type_collector import * +from .semantic.type_builder import * +from .semantic.type_checker import * +from .semantic.structures import * +from .compiler_component import CompilerComponent +from .cool_parser import Parser + class SemanticChecker(CompilerComponent): def __init__(self, parser: Parser) -> None: super().__init__() self.parser = parser - def execute(): - pass + def execute(self): + self.errors = [] + self.ast = self.parser.ast + print('......................') + print(self.ast.visit()) + tcollector = TypeCollector(self.errors) + tcollector.visit(self.ast) + context = tcollector.context + cycles = context.circular_dependency() + for cycle in cycles: + self.errors.append(SemanticError(f"Class {cycle[0][0]}, is involved in an inheritance cycle.",cycle[0][1])) + return + + tbuilder = TypeBuilder(context,self.errors) + tbuilder.visit(self.ast) + + tchecking = TypeChecker(context,self.errors) + scope = Scope() + tchecking.visit(self.ast, scope) - def has_errors(): - pass + def has_errors(self): + return len(self.errors) > 0 - def print_errors(): - pass \ No newline at end of file + def print_errors(self): + for e in self.errors: + print(e) \ No newline at end of file diff --git a/src/main.py b/src/main.py index 01589d361..376945fbf 100644 --- a/src/main.py +++ b/src/main.py @@ -23,11 +23,13 @@ def execute_compiler(cool_program : str): if component.has_errors(): component.print_errors() # with errors + print('with errors') return True # TODO: write generated code to output file # without errors + print('false') return False if __name__ == '__main__': @@ -35,7 +37,7 @@ def execute_compiler(cool_program : str): inputfile = sys.argv[1] with open(inputfile, encoding="utf_8")as file: coolprogram = file.read() - + with_errors: bool = execute_compiler(cool_program = coolprogram) if with_errors: exit(1) \ No newline at end of file diff --git a/src/program.txt b/src/program.txt new file mode 100644 index 000000000..eba0d69e2 --- /dev/null +++ b/src/program.txt @@ -0,0 +1,14 @@ +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A; + b: B <- a <- new C; + d: D <- a <- new C; +}; From 6d33489e6f403eee31f723a68b388156e4551fb4 Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Wed, 23 Feb 2022 14:26:02 -0500 Subject: [PATCH 27/60] Fix filling --- src/compiler_components/ast.py | 44 +- src/compiler_components/cil_mips_converter.py | 561 ++++++++++++++---- src/compiler_components/code_generator.py | 25 +- .../code_generator/cil_nodes.py | 254 ++++++++ .../code_generator/converter.py | 29 + .../code_generator/converter_utils.py | 137 +++++ .../code_generator/mips_formatter.py | 561 ++++++++++++++++++ .../code_generator/mips_nodes.py | 149 +++++ .../code_generator/visitor.py | 80 +++ src/compiler_components/cool_cil_converter.py | 465 +++++++++++++++ src/main.py | 2 +- 11 files changed, 2175 insertions(+), 132 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 4232a0efa..7d87531a0 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -2,21 +2,26 @@ class Node: def visit(self, tabs = 0): pass + class ProgramNode(Node): def __init__(self, declarations): self.declarations = declarations + def visit(self, tabs = 0): node = self ans = '\t' * tabs + f'\\__ProgramNode [ ... ]' statements = '\n'.join(child.visit( tabs + 1) for child in node.declarations) return f'{ans}\n{statements}' + class DeclarationNode(Node): pass + class ExpressionNode(Node): pass + class AtomicNode(ExpressionNode): def __init__(self, lex): self.lex = lex @@ -25,6 +30,7 @@ def visit(self, tabs = 0): node = self return '\t' * tabs + f'\\__ {node.__class__.__name__}: {node.lex}' + class ClassDeclarationNode(DeclarationNode): def __init__(self, idx, features, parent=None): self.id = idx @@ -53,6 +59,7 @@ def visit(self, tabs = 0): body = node.body.visit( tabs + 1) return f'{ans}\n{body}' + class AttrDeclarationNode(DeclarationNode): def __init__(self, idx, typex, expr = None): self.id = idx @@ -66,6 +73,7 @@ def visit(self, tabs = 0): ans += "\n" + self.expr.visit(tabs+1) return f'{ans}' + class VarDeclarationNode(ExpressionNode): def __init__(self, idx, typex, expr): self.id = idx @@ -78,6 +86,7 @@ def visit(self, tabs = 0): expr = node.expr.visit( tabs + 1) return f'{ans}\n{expr}' + class AssignNode(AtomicNode): def __init__(self, idx, expr): self.id = idx @@ -89,6 +98,7 @@ def visit(self, tabs = 0): expr = node.expr.visit( tabs + 1) return f'{ans}\n{expr}' + class IsVoidNode(AtomicNode): def __init__(self, expr): self.expr = expr @@ -97,6 +107,7 @@ def visit(self, tabs = 0): ans = '\t'*tabs + "\\__IsVoid " return ans + '\n' + '\t'*(tabs+1) + self.expr.visit() + class NotNode(AtomicNode): def __init__(self, expr): self.expr = expr @@ -105,6 +116,7 @@ def visit(self, tabs = 0): ans = '\t'*tabs + "\\__NOT " return ans + '\n' + '\t'*(tabs+1) + self.expr.visit() + class NhanharaNode(AtomicNode): def __init__(self, expr): self.expr = expr @@ -142,7 +154,8 @@ def visit(self, tabs = 0): args = "" return f'{ans}\n{obj}\n{args}' - + + class IfNode(AtomicNode): def __init__(self, if_c, then_c, else_c): self.if_c = if_c @@ -157,6 +170,7 @@ def visit(self, tabs = 0): ans += "\n" + '\t'*(tabs +1) + "else: " + self.else_c.visit() return ans + class WhileNode(AtomicNode): def __init__(self, condition, body): self.condition = condition @@ -170,6 +184,7 @@ def visit(self, tabs = 0): return ans + class BlockNode(AtomicNode): def __init__(self, expr_list): self.expr_list = expr_list @@ -179,6 +194,7 @@ def visit(self, tabs = 0): exprs = '\n'.join(param.visit( tabs + 1) for param in self.expr_list) return ans+exprs + class LetNode(AtomicNode): def __init__(self, list_decl, expr): self.list_decl = list_decl @@ -190,6 +206,7 @@ def visit(self, tabs = 0): expr = "\n" + "IN" + self.expr.visit(tabs+1) return ans+decl+expr + class CaseNode(AtomicNode): def __init__(self, expr, list_case): self.list_case = list_case @@ -202,8 +219,6 @@ def visit(self, tabs = 0): return ans+"\n"+expr+"\n" +l - - class BinaryNode(ExpressionNode): def __init__(self, left, right): self.left = left @@ -216,18 +231,23 @@ def visit(self, tabs = 0): right = node.right.visit( tabs + 1) return f'{ans}\n{left}\n{right}' + class ConstantNumNode(AtomicNode): pass + class ConstantStringNode(AtomicNode): pass + class ConstantBooleanNode(AtomicNode): pass + class SelfNode(AtomicNode): pass + class DispatchNode(ExpressionNode): def __init__(self, expr, f, params, type = None): super().__init__(None) @@ -246,24 +266,40 @@ def visit(self, tabs = 0): params = '\n'.join(param.visit( tabs + 1) for param in node.params) return f'{ans}\n{expr}\n{params}' + class VariableNode(AtomicNode): pass + + class InstantiateNode(AtomicNode): def visit(self, tabs): node = self return '\t' * tabs + f'\\__ InstantiateNode: new {node.lex}()' + + class PlusNode(BinaryNode): pass + + class MinusNode(BinaryNode): pass + + class StarNode(BinaryNode): pass + + class DivNode(BinaryNode): pass + class MinorNode(BinaryNode): pass + + class MinorEqualsNode(BinaryNode): pass + + class EqualsNode(BinaryNode): - pass \ No newline at end of file + pass diff --git a/src/compiler_components/cil_mips_converter.py b/src/compiler_components/cil_mips_converter.py index 0386690cc..6d11e3cd4 100644 --- a/src/compiler_components/cil_mips_converter.py +++ b/src/compiler_components/cil_mips_converter.py @@ -1,122 +1,439 @@ -def register_param(self, vinfo): - vinfo.cilName = vinfo.name # f'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' - param_node = cil.ParamNode(vinfo.cilName) - self.params.append(param_node) - return vinfo.cilName - - -def register_local(self, vinfo): - vinfo.cilName = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' - local_node = cil.LocalNode(vinfo.cilName) - self.localvars.append(local_node) - return vinfo.cilName - - -def register_label(self): - name = f'label_{self.current_function.name[9:]}_{len(self.labels)}' - self.labels.append(name) - return name - - -def define_internal_local(self): - vinfo = VariableInfo('internal', None) - return self.register_local(vinfo) - - -def register_instruction(self, instruction): - self.instructions.append(instruction) - return instruction - - -def to_function_name(self, method_name, type_name): - return f'function_{method_name}_at_{type_name}' - - -def to_attribute_name(self, attr_name, attr_type): - return f'attribute_{attr_name}' - - -def register_function(self, function_name): - function_node = cil.FunctionNode(function_name, [], [], [], []) - self.dotcode.append(function_node) - return function_node - - -def register_type(self, name): - type_node = cil.TypeNode(name) - self.dottypes.append(type_node) - return type_node - - -def register_data(self, value): - for dataNode in self.dotdata: - if dataNode.value == value: - return dataNode - - vname = f'data_{len(self.dotdata)}' - data_node = cil.DataNode(vname, value) - self.dotdata.append(data_node) - return data_node - - -def get_attr(self, function_name, attribute): - for dottype in self.dottypes: - if dottype.name == function_name: - break - - # for attrib in dottype.attributes: - # if self.to_attribute_name(attribute, None) == attrib: - # break - - return dottype.attributes.index(self.to_attribute_name(attribute, None)) - - -def get_method(self, type_name, method_name): - for typeContext in self.context.types: - if typeContext == type_name: - break - - methods = list(self.context.types[typeContext].all_methods()) - - for m in methods: - if m[0].name == method_name: - break - - return methods.index(m) - - -def sort_types(self, types): - q = queue.deque() - lst = [] - for tp1 in types: - if not any([x for x in types if x != tp1 and tp1.conforms_to(x)]): - q.append(tp1) - - while len(q) != 0: - tp = q.popleft() - if tp in types: - lst.append(tp) - for s in tp.sons: - q.append(s) - lst = list(reversed(lst)) - return lst - - -def get_preordenTypes(self, typex): - ret_lis = [] - - for son in typex.sons: - ret_lis.extend(self.get_preordenTypes(son)) - - ret_lis.append(typex) - return ret_lis - - -def box(self, typeName, value): - obj_internal = self.define_internal_local() - self.register_instruction(cil.AllocateNode(typeName, obj_internal)) - self.register_instruction(cil.SetAttribNode(obj_internal, 0, value)) - self.register_instruction(cil.LoadNode(obj_internal, f'{typeName}_name')) - self.register_instruction(cil.LoadIntNode(obj_internal, f'{typeName}_size', 4)) - self.register_instruction(cil.LoadNode(obj_internal, f'__virtual_table__{typeName}', 8)) - return obj_internal \ No newline at end of file +from code_generator import visitor +from code_generator import cil_nodes +from code_generator import mips_nodes + + +class CilToMipsConverter: + def __init__(self): + self.data = [] + self.text = [] + self.function = None + self.types = None + + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(CilProgramNode) + def visit(self, node): + self.types = node.dottypes + + for typePN in node.dottypes: + self.visit(typePN) + + for dataNode in node.dotdata: + self.visit(dataNode) + + for instructionNode in node.dotcode: + self.visit(instructionNode) + + return MipsProgramNode(self.data, self.text) + + @visitor.when(CilTypeNode) + def visit(self, node: TypeNode): + self.data.append(MipsStringNode(f'{node.name}_name', node.name)) + self.data.append(MipsWordNode(f'{node.name}_size', 4 * (len(node.attributes) + 3))) + self.data.append(MipsTableNode(node.name, [met[1] for met in node.methods])) + + @visitor.when(CilDataNode) + def visit(self, node): + self.data.append(MipsStringNode(node.name, node.value)) + + @visitor.when(CilJumpNode) + def visit(self, node: DynamicCallNode): + self.register_instruction(MipsCommentNode('comienzo llamada al constructor')) + self.register_instruction(MipsJumpAtAddressNode(node.method)) + + num = int(node.dest.split('_')[-1]) + self.register_instruction(MipsSWNode('$a0', f'-{(num + 1) * 4}($fp)')) + self.register_instruction(MipsCommentNode('fin llamada dinamica')) + + @visitor.when(CilFunctionNode) + def visit(self, node: FunctionNode): + self.function = node + self.register_instruction(MipsLabelNode(node.name)) + + self.register_instruction(MipsCommentNode('muevo el fp al sp, pongo en sp ra y avanzo la pila')) + self.register_instruction(MipsMoveNode('$fp', '$sp')) + self.register_instruction(MipsSWNode('$ra', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + + self.register_instruction(MipsCommentNode('muevo la pila x las variables locales')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', f'-{len(node.localvars) * 4}')) + + for ins in node.instructions: + self.visit(ins) + + self.register_instruction(MipsCommentNode('return sp, fp, ra')) + self.register_instruction(MipsLWNode('$ra', '0($fp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', f'{len(node.localvars) * 4 + 8 + len(node.params) * 4}')) + self.register_instruction(MipsLWNode('$fp', '0($sp)')) + self.register_instruction(MipsJRNode('$ra')) + + @visitor.when(CilArgsNode) + def visit(self, node): + self.register_instruction(MipsCommentNode('guardando los parametros')) + self.register_instruction(MipsSWNode('$fp', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + + for name in node.names: + pos = self.request_pos(name) + if not pos is None: + self.register_instruction(MipsLWNode('$a0', pos)) + else: + self.register_instruction(MipsLINode('$a0', name)) + + self.register_instruction(MipsSWNode('$a0', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + self.register_instruction(MipsCommentNode(' fin guardando los parametros')) + + @visitor.when(CilReturnNode) + def visit(self, node: ReturnNode): + self.register_instruction(MipsCommentNode('retornando el valor')) + pos = self.request_pos(node.value) + + if not pos is None: + self.register_instruction(MipsLWNode('$a0', pos)) + else: + self.register_instruction(MipsLINode('$a0', node.value)) + + @visitor.when(CilAllocateNode) + def visit(self, node: AllocateNode): + self.register_instruction(MipsCommentNode('init allocate')) + self.register_instruction(MipsLINode('$v0', '9')) + self.register_instruction(MipsLWNode('$a0', f'{node.type}_size')) + self.register_instruction(MipsSyscallNode()) + + num = int(node.dest.split('_')[-1]) + self.register_instruction(MipsSWNode('$v0', f'-{(num + 1) * 4}($fp)')) + self.register_instruction(MipsCommentNode('end allocate')) + + @visitor.when(CilStaticCallNode) + def visit(self, node: StaticCallNode): + self.register_instruction(MipsLWNode('$a0', '4($fp)')) + self.register_instruction(MipsLWNode('$a0', '8($a0)')) + self.register_instruction(MipsLWNode('$a0', f'{node.function * 4}($a0)')) + self.register_instruction(MipsJALRNode('$a0')) + + num = int(node.dest.split('_')[-1]) + self.register_instruction(MipsSWNode('$a0', f'-{(num + 1) * 4}($fp)')) + + @visitor.when(CilDynamicCallNode) + def visit(self, node: DynamicCallNode): + self.register_instruction(MipsCommentNode('comienzo llamada dinamica')) + + if node.type is None: + pos = self.request_pos(node.ins) + self.register_instruction(MipsLWNode('$a0', pos)) + self.register_instruction(MipsLWNode('$a0', '8($a0)')) + else: + self.register_instruction(MipsLANode('$a0', f'__virtual_table__{node.type}')) + + self.register_instruction(MipsLWNode('$a0', f'{node.method * 4}($a0)')) + self.register_instruction(MipsJALRNode('$a0')) + + num = int(node.dest.split('_')[-1]) + self.register_instruction(MipsSWNode('$a0', f'-{(num + 1) * 4}($fp)')) + self.register_instruction(MipsCommentNode('fin llamada dinamica')) + + @visitor.when(CilSetAttribNode) + def visit(self, node: SetAttribNode): + self.register_instruction(MipsCommentNode('init set attribute')) + + pos = self.request_pos(node.ins) + self.register_instruction(MipsLWNode('$a0', pos)) + + # nameType = node.att.split('_')[1] + # num = -1 + + # for typeAct in self.types: + # if typeAct.name == nameType: + # num = typeAct.attributes.index(node.att) + # break + + pos = self.request_pos(node.value) + if not pos is None: + self.register_instruction(MipsLWNode('$t1', pos)) + else: + self.register_instruction(MipsLINode('$t1', node.value)) + + self.register_instruction(MipsSWNode('$t1', f'{node.att * 4 + 12}($a0)')) + self.register_instruction(MipsCommentNode('end set attribute')) + + @visitor.when(CilGetAttribNode) + def visit(self, node: GetAttribNode): + self.register_instruction(MipsCommentNode('init get attribute')) + + pos_result = self.request_pos(node.dest) + pos = self.request_pos(node.ins) + self.register_instruction(MipsLWNode('$a0', pos)) + + # nameType = node.att.split('_')[1] + # num = -1 + + # for typeAct in self.types: + # if typeAct.name == nameType: + # num = typeAct.attributes.index(node.att) + # break + + self.register_instruction(MipsLWNode('$a0', f'{node.att * 4 + 12}($a0)')) + self.register_instruction(MipsSWNode('$a0', pos_result)) + + @visitor.when(CilLoadNode) + def visit(self, node): + self.register_instruction(MipsCommentNode('LOAD inicia')) + self.register_instruction(MipsLANode('$t1', node.msg)) + dest = self.request_pos(node.dest) + self.register_instruction(MipsLWNode("$t2", dest)) + self.register_instruction(MipsSWNode('$t1', f"{node.desp}($t2)")) + + @visitor.when(CilLoadAddressNode) + def visit(self, node): + pos = self.request_pos(node.dest) + self.register_instruction(MipsLANode('$t1', node.msg)) + self.register_instruction(MipsSWNode('$t1', pos)) + + @visitor.when(CilLoadIntNode) + def visit(self, node): + self.register_instruction(MipsCommentNode('LOAD inicia')) + self.register_instruction(MipsLWNode('$t1', node.msg)) + dest = self.request_pos(node.dest) + self.register_instruction(MipsLWNode("$t2", dest)) + self.register_instruction(MipsSWNode('$t1', f"{node.desp}($t2)")) + + @visitor.when(CilAssignNode) + def visit(self, node: AssignNode): + pos_dest = self.request_pos(node.dest) + pos_src = self.request_pos(node.source) + + if not pos_src is None: + self.register_instruction(MipsLWNode('$t1', pos_src)) + else: + self.register_instruction(MipsLINode('$t1', node.source)) + + self.register_instruction(MipsSWNode('$t1', pos_dest)) + + @visitor.when(CilGotoNode) + def visit(self, node): + self.register_instruction(MipsJumpNode(node.name)) + + @visitor.when(CilGotoIfNode) + def visit(self, node): + pos = self.request_pos(node.condition) + + if not pos is None: + self.register_instruction(MipsLWNode('$a0', pos)) + else: + self.register_instruction(MipsLINode('$a0', node.condition)) + + self.register_instruction(MipsBNENode('$a0', '$zero', node.name)) + + @visitor.when(CilLabelNode) + def visit(self, node): + self.register_instruction(MipsLabelNode(node.name)) + + @visitor.when(CilPlusNode) + def visit(self, node: PlusNode): + pos_dest = self.request_pos(node.dest) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsAddNode('$a0', '$a0', '$t1')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(CilMinusNode) + def visit(self, node): + pos_dest = self.request_pos(node.dest) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsMinusNode('$a0', '$t1', '$a0')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(CilStarNode) + def visit(self, node): + pos_dest = self.request_pos(node.dest) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsStarNode('$a0', '$t1', '$a0')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(CilDivNode) + def visit(self, node): + pos_dest = self.request_pos(node.dest) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsDivNode('$a0', '$t1', '$a0')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(CilComplementNode) + def visit(self, node): + pos_dest = self.request_pos(node.dest) + pos_expression = self.request_pos(node.expression) + + if not pos_expression is None: + self.register_instruction(MipsLWNode('$t1', pos_expression)) + else: + self.register_instruction(MipsLINode('$t1', node.expression)) + + self.register_instruction(MipsLINode('$t2', -1)) + self.register_instruction(MipsStarNode('$t1', '$t1', '$t2')) + self.register_instruction(MipsSWNode('$t1', pos_dest)) + + @visitor.when(CilIsVoidNode) + def visit(self, node): + pos_obj = self.request_pos(node.obj) + pos_dest = self.request_pos(node.dest) + + if not pos_obj is None: + self.register_instruction(MipsLWNode('$t1', pos_obj)) + else: + self.register_instruction(MipsLINode('$a0', 1)) + self.register_instruction(MipsJumpNode(node.label)) + + self.register_instruction(MipsLINode('$a0', 1)) + self.register_instruction(MipsLANode('$t2', '_void')) + self.register_instruction(MipsBNENode('$t1', '$t2', node.label)) + self.register_instruction(MipsLINode('$a0', 0)) + self.register_instruction(MipsLabelNode(node.label)) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(CilLessNode) + def visit(self, node): + pos_dest = self.request_pos(node.result) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsBLTNode('$t1', '$a0', node.labelTrue)) + self.register_instruction(MipsLINode('$a0', 0)) + self.register_instruction(MipsJumpNode(node.labelEnd)) + self.register_instruction(MipsLabelNode(node.labelTrue)) + self.register_instruction(MipsLINode('$a0', 1)) + self.register_instruction(MipsLabelNode(node.labelEnd)) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(CilLessEqualNode) + def visit(self, node): + pos_dest = self.request_pos(node.result) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsBLENode('$t1', '$a0', node.labelTrue)) + self.register_instruction(MipsLINode('$a0', 0)) + self.register_instruction(MipsJumpNode(node.labelEnd)) + self.register_instruction(MipsLabelNode(node.labelTrue)) + self.register_instruction(MipsLINode('$a0', 1)) + self.register_instruction(MipsLabelNode(node.labelEnd)) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(CilStringComparer) + def visit(self, node): + pos_dest = self.request_pos(node.result) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + self.register_instruction(MipsSWNode('$fp', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + + self.register_instruction(MipsLWNode('$a0', pos_left)) + self.register_instruction(MipsSWNode('$a0', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + + self.register_instruction(MipsLWNode('$a0', pos_right)) + self.register_instruction(MipsSWNode('$a0', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + + self.register_instruction(MipsJumpAtAddressNode('function_comparer_string')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(CilCaseOption) + def visit(self, node): + pos_expression = self.request_pos(node.expression) + + if not pos_expression is None: + self.register_instruction(MipsLANode('$a0', f'{node.typex.name}_name')) + self.register_instruction(MipsLWNode('$t1', pos_expression)) + self.register_instruction(MipsLWNode('$t1', '0($t1)')) + self.register_instruction(MipsBEQNode('$t1', '$a0', node.label)) + else: + pass + + # registers + def register_data(self, instruction): + self.data.append(instruction) + + def register_instruction(self, instruction): + self.text.append(instruction) + + # utils + def request_pos(self, name): + if name in [x.name for x in self.function.localvars]: + numb = int(name.split('_')[-1]) + return f'-{(numb + 1) * 4}($fp)' + elif name in [x.name for x in self.function.params]: + numb = [param.name for param in self.function.params].index(name) + return f'{(numb + 1) * 4}($fp)' + else: + return None \ No newline at end of file diff --git a/src/compiler_components/code_generator.py b/src/compiler_components/code_generator.py index a9066868a..c6f4044f6 100644 --- a/src/compiler_components/code_generator.py +++ b/src/compiler_components/code_generator.py @@ -1,16 +1,31 @@ from compiler_component import CompilerComponent from semantic_checker import SemanticChecker +from cool_cil_converter import CoolToCilConverter +from cil_mips_converter import CilToMipsConverter +from code_generator.mips_formatter import get_formatter + class CodeGenerator(CompilerComponent): def __init__(self, semantic_checker: SemanticChecker) -> None: super().__init__() self.semantic_checker = semantic_checker + # TODO: connect to semantic checker + self.context = None + self.scope = None + self.ast = None - def execute(): - pass + def execute(self): + cool_cil_converter = CoolToCilConverter(self.context) + cil_tree = cool_cil_converter.visit(self.ast, self.scope) + + cil_mips_converter = CILtoMIPSVisitor() + mips_tree = cil_mips_converter.visit(cil_tree) + mips_formatter = get_formatter() - def has_errors(): + return mips_formatter(mips_tree) + + def has_errors(self): pass - def print_errors(): - pass \ No newline at end of file + def print_errors(self): + pass diff --git a/src/compiler_components/code_generator/cil_nodes.py b/src/compiler_components/code_generator/cil_nodes.py index e69de29bb..c91e83fd8 100644 --- a/src/compiler_components/code_generator/cil_nodes.py +++ b/src/compiler_components/code_generator/cil_nodes.py @@ -0,0 +1,254 @@ +class CilNode: + pass + + +class CilProgramNode(CilNode): + def __init__(self, dottypes, dotdata, dotcode): + self.dottypes = dottypes + self.dotdata = dotdata + self.dotcode = dotcode + + +class CilTypeNode(CilNode): + def __init__(self, name): + self.name = name + self.attributes = [] + self.methods = [] + + +class CilDataNode(CilNode): + def __init__(self, vname, value): + self.name = vname + self.value = value + + +class CilFunctionNode(CilNode): + def __init__(self, fname, params, localvars, instructions, labels): + self.name = fname + self.params = params + self.localvars = localvars + self.instructions = instructions + self.labels = labels + + +class CilParamNode(CilNode): + def __init__(self, name): + self.name = name + + +class CilLocalNode(CilNode): + def __init__(self, name): + self.name = name + + +class CilInstructionNode(CilNode): + pass + + +class CilAssignNode(CilInstructionNode): + def __init__(self, dest, source): + self.dest = dest + self.source = source + + +class CilArithmeticNode(CilInstructionNode): + def __init__(self, dest, left, right): + self.dest = dest + self.left = left + self.right = right + + +class CilComplementNode(CilInstructionNode): + def __init__(self, expression, dest): + self.expression = expression + self.dest = dest + + +class CilPlusNode(CilArithmeticNode): + pass + + +class CilMinusNode(CilArithmeticNode): + pass + + +class CilStarNode(CilArithmeticNode): + pass + + +class CilDivNode(CilArithmeticNode): + pass + + +class CilLessNode(CilInstructionNode): + def __init__(self, result, left, right, labelTrue, labelEnd): + self.result = result + self.left = left + self.right = right + self.labelTrue = labelTrue + self.labelEnd = labelEnd + + +class CilLessEqualNode(CilArithmeticNode): + def __init__(self, result, left, right, labelTrue, labelEnd): + self.result = result + self.left = left + self.right =right + self.labelTrue = labelTrue + self.labelEnd = labelEnd + + +class CilGetAttribNode(CilInstructionNode): + def __init__(self, ins,att,dest): + self.ins = ins + self.att = att + self.dest = dest + + +class CilSetAttribNode(CilInstructionNode): + def __init__(self, ins,att, value): + self.ins = ins + self.att = att + + self.value = value + + +class CilGetIndexNode(CilInstructionNode): + pass + + +class CilSetIndexNode(InstructionNode): + pass + + +class CilAllocateNode(CilInstructionNode): + def __init__(self, itype, dest): + self.type = itype + self.dest = dest + + +class CilJumpNode(CilInstructionNode): + def __init__(self, method, dest): + self.method = method + self.dest = dest + + +class CilArrayNode(CilInstructionNode): + pass + + +class CilTypeOfNode(CilInstructionNode): + def __init__(self, obj, dest): + self.obj = obj + self.dest = dest + + +class CilIsVoidNode(CilInstructionNode): + def __init__(self, obj, dest, label): + self.obj = obj + self.dest = dest + self.label = label + + +class CilCaseOption(CilInstructionNode): + def __init__(self, expression, label, typex): + self.expression = expression + self.label = label + self.typex = typex + + +class CilLabelNode(CilInstructionNode): + def __init__(self, name): + self.name = name + + +class CilGotoNode(CilInstructionNode): + def __init__(self, name): + self.name = name + + +class CilGotoIfNode(CilInstructionNode): + def __init__(self, name, condition): + self.name = name + self.condition = condition + + +class CilStaticCallNode(CilInstructionNode): + def __init__(self, function, dest): + self.function = function + self.dest = dest + + +class CilDynamicCallNode(CilInstructionNode): + def __init__(self, xtype, method, dest,ins): + self.type = xtype + self.method = method + self.dest = dest + self.ins = ins + + +class CilArgsNode(CilInstructionNode): + def __init__(self, names): + self.names = names + + +class CilReturnNode(CilInstructionNode): + def __init__(self, value=None): + self.value = value + + +class CilLoadNode(CilInstructionNode): + def __init__(self, dest, msg, desp=0): + self.dest = dest + self.msg = msg + self.desp = desp + + +class CilLoadAddressNode(CilLoadNode): + pass + + +class CilLoadIntNode(CilInstructionNode): + def __init__(self, dest, msg, desp): + self.dest = dest + self.msg = msg + self.desp = desp + + +class CilLengthNode(CilInstructionNode): + pass + + +class CilConcatNode(CilInstructionNode): + pass + + +class CilPrefixNode(CilInstructionNode): + pass + + +class CilSubstringNode(CilInstructionNode): + pass + + +class CilStringComparer(CilInstructionNode): + def __init__(self, result, left, right): + self.result = result + self.left = left + self.right = right + + +class CilToStrNode(CilInstructionNode): + def __init__(self, dest, ivalue): + self.dest = dest + self.ivalue = ivalue + + +class CilReadNode(CilInstructionNode): + def __init__(self, dest): + self.dest = dest + + +class CilPrintNode(CilInstructionNode): + def __init__(self, str_addr): + self.str_addr = str_addr diff --git a/src/compiler_components/code_generator/converter.py b/src/compiler_components/code_generator/converter.py index e69de29bb..b0a5d40da 100644 --- a/src/compiler_components/code_generator/converter.py +++ b/src/compiler_components/code_generator/converter.py @@ -0,0 +1,29 @@ +from converter_utils import * + + +class Converter: + def __init__(self, context): + self.dottypes = [] + self.dotdata = [cil.DataNode('_empty', '')] + self.dotcode = [] + self.current_type = None + self.current_method = None + self.current_function = None + self.context = context + basic_types(self) + + @property + def params(self): + return self.current_function.params + + @property + def localvars(self): + return self.current_function.localvars + + @property + def instructions(self): + return self.current_function.instructions + + @property + def labels(self): + return self.current_function.labels diff --git a/src/compiler_components/code_generator/converter_utils.py b/src/compiler_components/code_generator/converter_utils.py index e69de29bb..7e52c1130 100644 --- a/src/compiler_components/code_generator/converter_utils.py +++ b/src/compiler_components/code_generator/converter_utils.py @@ -0,0 +1,137 @@ +from cil_nodes import * +from converter import Converter +import queue + + +def define_internal_local(converter: Converter): + var_info = VariableInfo('internal', None) + return register_local(converter, var_info) + + +def get_preorder_types(converter: Converter, typex): + ret_lis = [] + + for son in typex.sons: + ret_lis.extend(get_preorder_types(converter, son)) + + ret_lis.append(typex) + return ret_lis + + +def get_attr(converter: Converter, function_name, attribute): + for dottype in converter.dottypes: + if dottype.name == function_name: + break + + return dottype.attributes.index(to_attribute_name(attribute)) + + +def get_method(converter: Converter, type_name, method_name): + for typeContext in converter.context.types: + if typeContext == type_name: + break + + methods = list(converter.context.types[typeContext].all_methods()) + + for m in methods: + if m[0].name == method_name: + break + + return methods.index(m) + + +def box(converter: Converter, typeName, value): + obj_internal = define_internal_local(converter) + converter.register_instruction(AllocateNode(typeName, obj_internal)) + converter.register_instruction(SetAttribNode(obj_internal, 0, value)) + converter.register_instruction(LoadNode(obj_internal, f'{typeName}_name')) + converter.register_instruction(LoadIntNode(obj_internal, f'{typeName}_size', 4)) + converter.register_instruction(LoadNode(obj_internal, f'__virtual_table__{typeName}', 8)) + return obj_internal + + +def to_function_name(method_name, type_name): + return f'function_{method_name}_at_{type_name}' + + +def to_attribute_name(attr_name): + return f'attribute_{attr_name}' + + +def register_param(converter: Converter, var_info): + var_info.cilName = var_info.name + param_node = cil.ParamNode(var_info.cilName) + converter.params.append(param_node) + return var_info.cilName + + +def register_local(converter: Converter, var_info): + var_info.cilName = f'local_{converter.current_function.name[9:]}_{var_info.name}_{len(converter.localvars)}' + local_node = cil.LocalNode(var_info.cilName) + converter.localvars.append(local_node) + return var_info.cilName + + +def register_label(converter: Converter): + name = f'label_{converter.current_function.name[9:]}_{len(converter.labels)}' + converter.labels.append(name) + return name + + +def register_instruction(converter: Converter, instruction): + converter.instructions.append(instruction) + return instruction + + +def register_function(converter: Converter, function_name): + function_node = FunctionNode(function_name, [], [], [], []) + converter.dotcode.append(function_node) + return function_node + + +def register_type(converter: Converter, name): + type_node = TypeNode(name) + converter.dottypes.append(type_node) + return type_node + + +def register_data(converter: Converter, value): + for dataNode in converter.dotdata: + if dataNode.value == value: + return dataNode + + vname = f'data_{len(converter.dotdata)}' + data_node = DataNode(vname, value) + converter.dotdata.append(data_node) + return data_node + + +def sort_types(types): + q = queue.deque() + lst = [] + for tp1 in types: + if not any([x for x in types if x != tp1 and tp1.conforms_to(x)]): + q.append(tp1) + + while len(q) != 0: + tp = q.popleft() + if tp in types: + lst.append(tp) + for s in tp.sons: + q.append(s) + lst = list(reversed(lst)) + return lst + + +def basic_types(converter: Converter): + for basicType in ['Int', 'String', 'Bool']: + cil_type = register_type(converter, basicType) + cil_type.attributes.append(to_attribute_name('value')) + + for method, typeMethod in converter.context.get_type(basicType).all_methods(): + cil_type.methods.append((method.name, to_function_name(method.name, typeMethod.name))) + + for basicType in ['Object', 'IO']: + cil_type = register_type(converter, basicType) + for method, typeMethod in converter.context.get_type(basicType).all_methods(): + cil_type.methods.append((method.name, to_function_name(method.name, typeMethod.name))) diff --git a/src/compiler_components/code_generator/mips_formatter.py b/src/compiler_components/code_generator/mips_formatter.py index e69de29bb..dee676c79 100644 --- a/src/compiler_components/code_generator/mips_formatter.py +++ b/src/compiler_components/code_generator/mips_formatter.py @@ -0,0 +1,561 @@ +from mips_nodes import * + + +def get_formatter(): + class PrintVisitor(object): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(MipsProgramNode) + def visit(self, node): + dotdata = '\n'.join(self.visit(t) for t in node.dotdata) + dotdata += ''' + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz "\n" + _buffer: .space 2048 + _void: .asciiz "" + ''' + + dotcode = '\n'.join(self.visit(t) for t in node.dotcode) + dotcode += '''\n + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + ''' + + return f'.data\n{dotdata}\n\n.text\n{dotcode}' + + @visitor.when(MipsStringNode) + def visit(self, node): + return f'\t\t\t{node.name}: .asciiz "{node.value}"' + + @visitor.when(MipsWordNode) + def visit(self, node): + return f'\t\t\t{node.name}: .word {node.value}' + + @visitor.when(MipsTableNode) + def visit(self, node: MipsTableNode): + return f'__virtual_table__{node.type_name}:\n' + '\n'.join(f"\t\t\t .word {m}" for m in node.methods) + + # jumps + @visitor.when(MipsJumpNode) + def visit(self, node): + return f'\t\t\tj {node.label}' + + @visitor.when(MipsJumpAtAddressNode) + def visit(self, node): + return f'\t\t\tjal {node.label}' + + @visitor.when(MipsJRNode) + def visit(self, node): + return f'\t\t\tjr {node.label}' + + @visitor.when(MipsJALRNode) + def visit(self, node): + return f'\t\t\tjalr {node.label}' + + # stack + @visitor.when(MipsLWNode) + def visit(self, node): + return f'\t\t\tlw {node.dest}, {node.src}' + + @visitor.when(MipsLINode) + def visit(self, node): + return f'\t\t\tli {node.dest}, {node.src}' + + @visitor.when(MipsLANode) + def visit(self, node): + return f'\t\t\tla {node.dest}, {node.src}' + + @visitor.when(MipsSWNode) + def visit(self, node): + return f'\t\t\tsw {node.src}, {node.dest}' + + # syscall + @visitor.when(MipsSyscallNode) + def visit(self, node): + return '\t\t\tsyscall' + + # move + @visitor.when(MipsMoveNode) + def visit(self, node): + return f'\t\t\tmove {node.dest}, {node.src}' + + # arithmetic + @visitor.when(MipsAddNode) + def visit(self, node): + return f'\t\t\tadd {node.param1}, {node.param2}, {node.param3}' + + @visitor.when(MipsAddiuNode) + def visit(self, node): + return f'\t\t\taddiu {node.param1}, {node.param2}, {node.param3}' + + @visitor.when(MipsMinusNode) + def visit(self, node): + return f'\t\t\tsub {node.param1}, {node.param2}, {node.param3}' + + @visitor.when(MipsStarNode) + def visit(self, node): + return f'\t\t\tmul {node.param1} {node.param2} {node.param3}' + + @visitor.when(MipsNEGNode) + def visit(self, node): + return f'\t\t\tneg {node.dest}, {node.src}' + + @visitor.when(MipsDivNode) + def visit(self, node): + return f'\t\t\tdiv {node.param1}, {node.param2}, {node.param3}' + + # comp + @visitor.when(MipsBNENode) + def visit(self, node): + return f'\t\t\tbne {node.param1}, {node.param2}, {node.label}' + + @visitor.when(MipsBEQNode) + def visit(self, node): + return f'\t\t\tbeq {node.param1}, {node.param2}, {node.label}' + + @visitor.when(MipsBLTNode) + def visit(self, node): + return f'\t\t\tblt {node.param1}, {node.param2}, {node.label}' + + @visitor.when(MipsBLENode) + def visit(self, node): + return f'\t\t\tble {node.param1}, {node.param2}, {node.label}' + + # label + @visitor.when(MipsLabelNode) + def visit(self, node): + return f'{node.name}:' + + @visitor.when(MipsCommentNode) + def visit(self, node): + return node.comment + + printer = PrintVisitor() + return lambda ast: printer.visit(ast) diff --git a/src/compiler_components/code_generator/mips_nodes.py b/src/compiler_components/code_generator/mips_nodes.py index e69de29bb..a66ba3e8d 100644 --- a/src/compiler_components/code_generator/mips_nodes.py +++ b/src/compiler_components/code_generator/mips_nodes.py @@ -0,0 +1,149 @@ +class MipsNode: + pass + + +class MipsProgramNode(MipsNode): + def __init__(self, dotdata, dotcode): + self.dotdata = dotdata + self.dotcode = dotcode + + +# string +class MipsStringNode(MipsNode): + def __init__(self, name, value): + self.name = name + self.value = value + + +class MipsWordNode(MipsNode): + def __init__(self, name, value): + self.name = name + self.value = value + + +class MipsTableNode(MipsNode): + def __init__(self , type_name,methods): + self.type_name = type_name + self.methods = methods + + +# jumps +class MipsJumpNode(MipsNode): + def __init__(self, label): + self.label = label + + +class MipsJumpAtAddressNode(MipsJumpNode): + pass + + +class MipsJRNode(MipsJumpNode): + pass + + +class MipsJALRNode(MipsJumpNode): + pass + + +# stack +class MipsLWNode(MipsNode): + def __init__(self, dest, src): + self.src = src + self.dest = dest + + +class MipsLINode(MipsNode): + def __init__(self, dest, src): + self.src = src + self.dest = dest + + +class MipsLANode(MipsNode): + def __init__(self, dest, src): + self.src = src + self.dest = dest + + +class MipsSWNode(MipsNode): + def __init__(self, src, dest): + self.src = src + self.dest = dest + + +# syscall +class MipsSyscallNode(MipsNode): + pass + + +# move +class MipsMoveNode(MipsNode): + def __init__(self, dest, src): + self.src = src + self.dest = dest + + +# arithmetic +class MipsArithmeticNode: + def __init__(self, param1, param2, param3): + self.param1 = param1 + self.param2 = param2 + self.param3 = param3 + + +class MipsAddNode(MipsArithmeticNode): + pass + + +class MipsAddiuNode(MipsArithmeticNode): + pass + + +class MipsMinusNode(MipsArithmeticNode): + pass + + +class MipsStarNode(MipsArithmeticNode): + pass + + +class MipsDivNode(MipsArithmeticNode): + pass + + +class MipsNEGNode(MipsNode): + def __init__(self, dest, src): + self.dest = dest + self.src = src + + +class MipsComparerNode(MipsNode): + def __init__(self, param1, param2, label): + self.param1 = param1 + self.param2 = param2 + self.label = label + + +class MipsBEQNode(MipsComparerNode): + pass + + +class MipsBNENode(MipsComparerNode): + pass + + +class MipsBLTNode(MipsComparerNode): + pass + + +class MipsBLENode(MipsComparerNode): + pass + + +class MipsLabelNode(MipsNode): + def __init__(self, name): + self.name = name + + +class MipsCommentNode(MipsNode): + def __init__(self, comment): + self.comment = '\n #' + comment + '\n' diff --git a/src/compiler_components/code_generator/visitor.py b/src/compiler_components/code_generator/visitor.py index e69de29bb..964842836 100644 --- a/src/compiler_components/code_generator/visitor.py +++ b/src/compiler_components/code_generator/visitor.py @@ -0,0 +1,80 @@ +# The MIT License (MIT) +# +# Copyright (c) 2013 Curtis Schlak +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import inspect + +__all__ = ['on', 'when'] + +def on(param_name): + def f(fn): + dispatcher = Dispatcher(param_name, fn) + return dispatcher + return f + + +def when(param_type): + def f(fn): + frame = inspect.currentframe().f_back + func_name = fn.func_name if 'func_name' in dir(fn) else fn.__name__ + dispatcher = frame.f_locals[func_name] + if not isinstance(dispatcher, Dispatcher): + dispatcher = dispatcher.dispatcher + dispatcher.add_target(param_type, fn) + def ff(*args, **kw): + return dispatcher(*args, **kw) + ff.dispatcher = dispatcher + return ff + return f + + +class Dispatcher(object): + def __init__(self, param_name, fn): + frame = inspect.currentframe().f_back.f_back + top_level = frame.f_locals == frame.f_globals + self.param_index = self.__argspec(fn).args.index(param_name) + self.param_name = param_name + self.targets = {} + + def __call__(self, *args, **kw): + typ = args[self.param_index].__class__ + d = self.targets.get(typ) + if d is not None: + return d(*args, **kw) + else: + issub = issubclass + t = self.targets + ks = t.keys() + ans = [t[k](*args, **kw) for k in ks if issub(typ, k)] + if len(ans) == 1: + return ans.pop() + return ans + + def add_target(self, typ, target): + self.targets[typ] = target + + @staticmethod + def __argspec(fn): + # Support for Python 3 type hints requires inspect.getfullargspec + if hasattr(inspect, 'getfullargspec'): + return inspect.getfullargspec(fn) + else: + return inspect.getargspec(fn) diff --git a/src/compiler_components/cool_cil_converter.py b/src/compiler_components/cool_cil_converter.py index e69de29bb..1562227d6 100644 --- a/src/compiler_components/cool_cil_converter.py +++ b/src/compiler_components/cool_cil_converter.py @@ -0,0 +1,465 @@ +from code_generator.converter import Converter +from code_generator.converter_utils import * +from code_generator.cil_nodes import * +from code_generator import visitor +from ast import * + + +class CoolToCilConverter(Converter): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node, scope): + self.current_function = register_function(self, 'main') + instance = define_internal_local(self) + result = define_internal_local(self) + result2 = define_internal_local(self) + + register_instruction(self, CilAllocateNode('Main', instance)) + register_instruction(self, CilArgsNode([instance])) + + register_instruction(self, CilJumpNode(to_function_name('Ctr', 'Main'), result)) + register_instruction(self, CilArgsNode([result])) + + real_method = get_method(self, self.context.get_type('Main').name, 'main') + register_instruction(self, CilDynamicCallNode('Main', real_method, result2, result)) + register_instruction(self, CilReturnNode(0)) + self.current_function = None + + for declaration, child_scope in zip(node.declarations, scope.children): + self.visit(declaration, child_scope) + + return CilProgramNode(self.dottypes, self.dotdata, self.dotcode) + + @visitor.when(ClassDeclarationNode) + def visit(self, node, scope): + self.current_type = self.context.get_type(node.id) + + cil_type = register_type(self, node.id) + + for attr, type_attr in self.current_type.all_attributes(): + cil_type.attributes.append(to_attribute_name(attr.name)) + + for func, type_func in self.current_type.all_methods(): + cil_type.methods.append((func.name, to_function_name(func.name, type_func.name))) + + nodeFunctions = [x for x in node.features if isinstance(x, FuncDeclarationNode)] + for feature, child_scope in zip(nodeFunctions, scope.children[0].children): + self.visit(feature, child_scope) + + name = to_function_name("Ctr", self.current_type.name) + self.current_function = register_function(self, name) + register_param(self, VariableInfo('self', self.current_type)) + + register_instruction(self, CilLoadNode('self', f'{self.current_type.name}_name')) + register_instruction(self, CilLoadIntNode('self', f'{self.current_type.name}_size', 4)) + register_instruction(self, CilLoadNode('self', f'__virtual_table__{self.current_type.name}', 8)) + + initResult = define_internal_local(self) + register_instruction(self, CilArgsNode(['self'])) + register_instruction(self, CilJumpNode(to_function_name('Init', self.current_type.name), initResult)) + + register_instruction(self, CilReturnNode('self')) + + name = to_function_name('Init', self.current_type.name) + self.current_function = register_function(self, name) + register_param(self, VariableInfo('self', self.current_type)) + + parentResult = define_internal_local(self) + register_instruction(self, CilArgsNode(['self'])) + register_instruction(self, CilJumpNode(to_function_name('Init', self.current_type.parent.name), parentResult)) + + nodeatt = [x for x in node.features if isinstance(x, AttrDeclarationNode)] + for feature, child_scope in zip(nodeatt, scope.children[1].children): + self.visit(feature, child_scope) + + register_instruction(self, CilReturnNode('self')) + + self.current_type = None + + @visitor.when(FuncDeclarationNode) + def visit(self, node, scope): + self.current_method = self.current_type.get_method(node.id) + + name = to_function_name(node.id, self.current_type.name) + self.current_function = register_function(self, name) + + register_param(self, VariableInfo('self', self.current_type)) + for param in scope.locals: + register_param(self, param) + + value = self.visit(node.body, scope.children[0]) + + register_instruction(self, CilReturnNode(value)) + self.current_method = None + + @visitor.when(AttrDeclarationNode) + def visit(self, node, scope): + if not node.expression is None: + value = self.visit(node.expression, scope.children[0]) + + if node.type == 'Object' and node.expression.type.name in ['Int', 'Bool', 'String']: + value = box(self, node.expression.type.name, value) + + else: + if node.type == 'String': + internal = define_internal_local(self) + register_instruction(self, CilLoadAddressNode(internal, "_empty")) + value = internal + elif node.type == 'Bool' or node.type == 'Int': + value = 0 + else: + internal = define_internal_local(self) + register_instruction(self, CilLoadAddressNode(internal, "_void")) + value = internal + + attrib = get_attr(self, self.current_type.name, node.id) + register_instruction(self, CilSetAttribNode('self', attrib, value)) + + @visitor.when(LetInNode) + def visit(self, node, scope): + scope_open = scope.children[0] + + for init in node.let_body: + if not init[2] is None: + value = self.visit(init[2], scope_open) + + if init[2].type.name in ['Int', 'Bool', 'String'] and init[1] == 'Object': + value = box(self, init[2].type.name, value) + + else: + if init[1] == 'String': + internal = define_internal_local(self) + register_instruction(self, CilLoadAddressNode(internal, "_empty")) + value = internal + elif init[1] == 'Bool' or init[1] == 'Int': + value = 0 + else: + internal = define_internal_local(self) + register_instruction(self, CilLoadAddressNode(internal, "_void")) + value = internal + + scope_open = scope_open.children[-1] + var_info = scope_open.find_variable(init[0]) + vname = register_local(self, var_info) + register_instruction(self, CilAssignNode(vname, value)) + + return self.visit(node.in_body, scope_open.children[0]) + + @visitor.when(CaseOfNode) + def visit(self, node, scope): + result = define_internal_local(self) + + internal_expression = define_internal_local(self) + value_expression = self.visit(node.expression, scope.children[0]) + register_instruction(self, CilAssignNode(internal_expression, value_expression)) + + types_ordered = sort_types([self.context.get_type(x[1]) for x in node.branches]) + list_label = [] + labels = dict() + + for typex in types_ordered: + label_typex = register_label(self) + labels[typex.name] = label_typex + pre = get_preorder_types(self, typex) + for typex2 in pre: + if not typex2 in [x[0] for x in list_label]: + list_label.append((typex2, label_typex)) + + for typex in list_label: + register_instruction(self, CilCaseOption(value_expression, typex[1], typex[0])) + + label_end = register_label(self) + for branch, scopeBranch in zip(node.branches, scope.children[1].children): + var_info = scopeBranch.find_variable(branch[0]) + xxx = register_local(self, var_info) + register_instruction(self, CilLabelNode(labels[branch[1]])) + register_instruction(self, CilAssignNode(xxx, value_expression)) + + value_branch = self.visit(branch[2], scopeBranch) + register_instruction(self, CilAssignNode(result, value_branch)) + register_instruction(self, CilGotoNode(label_end)) + + register_instruction(self, CilLabelNode(label_end)) + return result + + @visitor.when(BlockNode) + def visit(self, node, scope): + for expression, child in zip(node.expressions, scope.children): + value = self.visit(expression, child) + + return value + + @visitor.when(IfThenElseNode) + def visit(self, node, scope): + cond = self.visit(node.condition, scope.children[0]) + + label_true = register_label(self) + label_false = register_label(self) + result = define_internal_local(self) + + register_instruction(self, CilGotoIfNode(label_true, cond)) + vfalse = self.visit(node.else_body, scope.children[2]) + register_instruction(self, CilAssignNode(result, vfalse)) + register_instruction(self, CilGotoNode(label_false)) + register_instruction(self, CilLabelNode(label_true)) + vtrue = self.visit(node.if_body, scope.children[1]) + register_instruction(self, CilAssignNode(result, vtrue)) + register_instruction(self, CilLabelNode(label_false)) + + return result + + @visitor.when(WhileLoopNode) + def visit(self, node, scope): + label_while_start = register_label(self) + label_while_continue = register_label(self) + label_while_break = register_label(self) + + register_instruction(self, CilLabelNode(label_while_start)) + + cond = self.visit(node.condition, scope.children[0]) + + register_instruction(self, CilGotoIfNode(label_while_continue, cond)) + register_instruction(self, CilGotoNode(label_while_break)) + register_instruction(self, CilLabelNode(label_while_continue)) + self.visit(node.body, scope.children[1]) + register_instruction(self, CilGotoNode(label_while_start)) + register_instruction(self, CilLabelNode(label_while_break)) + + result = define_internal_local(self) + register_instruction(self, CilLoadAddressNode(result, "_void")) + return result + + @visitor.when(AssignNode) + def visit(self, node, scope): + vinfo = scope.find_variable(node.id) + value = self.visit(node.expression, scope.children[0]) + + if vinfo is None: + attrib = get_attr(self, self.current_type.name, node.id) + register_instruction(self, CilSetAttribNode('self', attrib, value)) + else: + register_instruction(self, CilAssignNode(vinfo.cilName, value)) + + return value + + @visitor.when(FunctionCallNode) + def visit(self, node, scope): + result = define_internal_local(self) + obj = self.visit(node.obj, scope.children[0]) + + if node.obj.type.name in ['Int', 'Bool', 'String']: + if node.id in ['abort', 'type_name', 'copy']: + obj = self.box(node.obj.type.name, obj) + + valuesArgs = [] + for arg, child in zip(node.args, scope.children[1:]): + value = self.visit(arg, child) + + if arg.type.name in ['Int', 'Bool', 'String']: + method = self.context.get_type(node.typex).get_method(node.id) + param_type = method.param_types[node.args.index(arg)] + + if param_type.name == 'Object': + valuesArgs.append(self.box(arg.type.name, value)) + continue + + valuesArgs.append(value) + + if node.typexa is None: + node.typex = node.obj.type.name + + register_instruction(self, CilArgsNode(list(reversed(valuesArgs)) + [obj])) + + if node.obj.type.name == 'String' and node.id in ['length', 'concat', 'substr']: + register_instruction(self, CilJumpNode(self.to_function_name(node.id, 'String'), result)) + else: + real_method = self.get_method(node.typex, node.id) + register_instruction(self, CilDynamicCallNode(node.typexa, real_method, result, obj)) + return result + + @visitor.when(MemberCallNode) + def visit(self, node, scope): + result = define_internal_local(self) + + values_args = [] + for arg, child in zip(node.args, scope.children): + value = self.visit(arg, child) + + if arg.type.name in ['Int', 'Bool', 'String']: + method = self.current_type.get_method(node.id) + param_type = method.param_types[node.args.index(arg)] + + if param_type.name == 'Object': + values_args.append(self.box(arg.type.name, value)) + continue + + values_args.append(value) + + register_instruction(self, CilArgsNode(list(reversed(values_args)) + ['self'])) + + realMethod = get_method(self, self.current_type.name, node.id) + register_instruction(self, CilStaticCallNode(realMethod, result)) + return result + + @visitor.when(IntegerNode) + def visit(self, node, scope): + return int(node.token) + + @visitor.when(BoolNode) + def visit(self, node, scope): + if node.token: + return 1 + return 0 + + @visitor.when(StringNode) + def visit(self, node, scope): + msg = register_data(self, node.token).name + internal = define_internal_local(self) + register_instruction(self, CilLoadAddressNode(internal, msg)) + return internal + + @visitor.when(IdNode) + def visit(self, node: IdNode, scope): + if node.token == 'self': + return 'self' + + vinfo = scope.find_variable(node.token) + + if vinfo is None: + result = define_internal_local(self) + attrib = get_attr(self, self.current_type.name, node.token) + + register_instruction(self, CilGetAttribNode('self', attrib, result)) + return result + + return vinfo.cilName + + @visitor.when(NewNode) + def visit(self, node: NewNode, scope): + if not node.type.name == "Int": + instance = define_internal_local(self) + result = define_internal_local(self) + register_instruction(self, CilAllocateNode(node.type.name, instance)) + register_instruction(self, CilArgsNode([instance])) + register_instruction(self, CilJumpNode(self.to_function_name('Ctr', node.type.name), result)) + return instance + else: + return 0 + + @visitor.when(PlusNode) + def visit(self, node, scope): + result = define_internal_local(self) + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + register_instruction(self, CilPlusNode(result, left, right)) + return result + + @visitor.when(MinusNode) + def visit(self, node, scope): + result = define_internal_local(self) + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + register_instruction(self, CilMinusNode(result, left, right)) + return result + + @visitor.when(StarNode) + def visit(self, node, scope): + result = define_internal_local(self) + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + register_instruction(self, CilStarNode(result, left, right)) + return result + + @visitor.when(DivNode) + def visit(self, node, scope): + result = define_internal_local(self) + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + register_instruction(self, CilDivNode(result, left, right)) + return result + + @visitor.when(EqualNode) + def visit(self, node, scope): + result = define_internal_local(self) + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + + if node.left.type.name == 'String': + register_instruction(self, CilStringComparer(result, left, right)) + else: + label_equals = register_label(self) + labels_end = register_label(self) + + result_comparer = define_internal_local(self) + register_instruction(self, CilMinusNode(result_comparer, left, right)) + + register_instruction(self, CilGotoIfNode(label_equals, result_comparer)) + register_instruction(self, CilAssignNode(result, 1)) + register_instruction(self, CilGotoNode(labels_end)) + register_instruction(self, CilLabelNode(label_equals)) + register_instruction(self, CilAssignNode(result, 0)) + register_instruction(self, CilLabelNode(labels_end)) + + return result + + @visitor.when(LessNode) + def visit(self, node, scope): + result = define_internal_local(self) + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + + label_true = register_label(self) + label_end = register_label(self) + + register_instruction(self, CilLessNode(result, left, right, label_true, label_end)) + return result + + @visitor.when(LessEqualNode) + def visit(self, node, scope): + result = define_internal_local(self) + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + + label_true = register_label(self) + label_end = register_label(self) + + register_instruction(self, CilLessEqualNode(result, left, right, label_true, label_end)) + return result + + @visitor.when(NotNode) + def visit(self, node, scope): + result = define_internal_local(self) + value = self.visit(node.expression, scope.children[0]) + + label_true = register_label(self) + label_end = register_label(self) + + register_instruction(self, CilGotoIfNode(label_true, value)) + register_instruction(self, CilAssignNode(result, 1)) + register_instruction(self, CilGotoNode(label_end)) + register_instruction(self, CilLabelNode(label_true)) + register_instruction(self, CilAssignNode(result, 0)) + register_instruction(self, CilLabelNode(label_end)) + + return result + + @visitor.when(ComplementNode) + def visit(self, node, scope): + result = define_internal_local(self) + expression = self.visit(node.expression, scope.children[0]) + + register_instruction(self, CilComplementNode(expression, result)) + return result + + @visitor.when(IsVoidNode) + def visit(self, node, scope): + result = define_internal_local(self) + expression = self.visit(node.expression, scope.children[0]) + + label_end = register_label(self) + + register_instruction(self, CilIsVoidNode(expression, result, label_end)) + return result diff --git a/src/main.py b/src/main.py index 01589d361..2f6c14689 100644 --- a/src/main.py +++ b/src/main.py @@ -16,7 +16,7 @@ def execute_compiler(cool_program : str): code_generator = CodeGenerator(semantic_checker) # Execute compiler components - compiler_components : List[CompilerComponent] = [lexer, cool_parser, semantic_checker, code_generator] + compiler_components: List[CompilerComponent] = [lexer, cool_parser, semantic_checker, code_generator] for component in compiler_components: component.execute() From f77e73cfb9bdd730ea9886d1498bd26b16df5a74 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 23 Feb 2022 16:41:34 -0300 Subject: [PATCH 28/60] working at variables definition --- .../semantic/structures.py | 21 ++++++++++++------- .../semantic/type_checker.py | 7 +++++-- src/program.txt | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index 0758df629..2a98ab657 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -301,11 +301,18 @@ def define_variable(self, vname, vtype,pos=0): return v def find_variable(self, vname, index=None): + print("Buscando variable", vname) locals = self.locals if index is None else itt.islice(self.locals, index) - try: - return next(x for x in locals if x.name == vname) - except StopIteration: - if not self.parent is None: - return self.parent.find_variable(vname, self.index) - else: - return None \ No newline at end of file + + for l in locals: + if l.name == vname: + print("encontreeeeee", vname) + return l + + print("no encontre", vname) + if not self.parent is None: + print("buscando ", vname, "en el padre") + return self.parent.find_variable(vname, self.index) + else: + print("no aparece", vname) + return None \ No newline at end of file diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index ba27a9d30..e75f8bbdf 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -40,10 +40,12 @@ def visit(self, node:ClassDeclarationNode, scope:Scope): if isinstance(feat, FuncDeclarationNode): self.visit(feat,mscope.create_child()) else: - self.visit(feat, ascope.create_child()) + self.visit(feat, ascope) @visitor.when(AttrDeclarationNode) def visit(self, node:AttrDeclarationNode,scope:Scope): + scope.define_variable(node.id, node.type) + print("define",scope.locals[0].name) self.visit(node.expr, scope.create_child()) if not node.expr is None: try: @@ -194,7 +196,8 @@ def visit(self, node:AssignNode,scope:Scope): try: if node.id == "self": raise SemanticError('Trying to assign value to self' ,node.line) - + + print('find variable', node.id) var = scope.find_variable(node.id) if var is None: diff --git a/src/program.txt b/src/program.txt index eba0d69e2..40d51d688 100644 --- a/src/program.txt +++ b/src/program.txt @@ -10,5 +10,5 @@ class Main inherits IO { a: A; b: B <- a <- new C; - d: D <- a <- new C; + d: D <- b <- new C; }; From d973ac39ab936b90d142ed038f741ae1185fe3ee Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Thu, 24 Feb 2022 09:19:58 -0500 Subject: [PATCH 29/60] Fill cool.sh Fix doge_generator ast issues --- src/compiler_components/ast.py | 2 +- src/compiler_components/cil_mips_converter.py | 36 ++--- .../{code_generator.py => code_gen.py} | 16 ++- .../code_generator/cil_nodes.py | 2 +- .../code_generator/converter.py | 2 +- .../code_generator/converter_utils.py | 29 ++-- .../code_generator/mips_formatter.py | 2 +- src/compiler_components/cool_cil_converter.py | 44 +++--- src/coolc.sh | 9 +- src/main.py | 16 ++- src/program.txt | 128 ++++++++++++++++-- tests/lexer/comment1.cl | 55 -------- tests/lexer/comment1_error.txt | 1 - 13 files changed, 192 insertions(+), 150 deletions(-) rename src/compiler_components/{code_generator.py => code_gen.py} (65%) delete mode 100644 tests/lexer/comment1.cl delete mode 100644 tests/lexer/comment1_error.txt diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index bd98a607f..1c0473d21 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -222,7 +222,7 @@ def __init__(self, list_decl, expr): def visit(self, tabs = 0): ans = '\t'*tabs + " LET , ... in \n " - decl = '\n'.join('\t'*(tabs+1) + "decl: " + param.visit() for param in self.list_decl) + decl = '\n'.join('\t'*(tabs+1) + "decl: " + param.visit() for param in self.list_decl) expr = "\n" + "IN" + self.expr.visit(tabs+1) return ans+decl+expr diff --git a/src/compiler_components/cil_mips_converter.py b/src/compiler_components/cil_mips_converter.py index 6d11e3cd4..2bf13de2b 100644 --- a/src/compiler_components/cil_mips_converter.py +++ b/src/compiler_components/cil_mips_converter.py @@ -1,6 +1,6 @@ -from code_generator import visitor -from code_generator import cil_nodes -from code_generator import mips_nodes +from .code_generator import visitor +from .code_generator.cil_nodes import * +from .code_generator.mips_nodes import * class CilToMipsConverter: @@ -30,7 +30,7 @@ def visit(self, node): return MipsProgramNode(self.data, self.text) @visitor.when(CilTypeNode) - def visit(self, node: TypeNode): + def visit(self, node): self.data.append(MipsStringNode(f'{node.name}_name', node.name)) self.data.append(MipsWordNode(f'{node.name}_size', 4 * (len(node.attributes) + 3))) self.data.append(MipsTableNode(node.name, [met[1] for met in node.methods])) @@ -40,7 +40,7 @@ def visit(self, node): self.data.append(MipsStringNode(node.name, node.value)) @visitor.when(CilJumpNode) - def visit(self, node: DynamicCallNode): + def visit(self, node): self.register_instruction(MipsCommentNode('comienzo llamada al constructor')) self.register_instruction(MipsJumpAtAddressNode(node.method)) @@ -49,7 +49,7 @@ def visit(self, node: DynamicCallNode): self.register_instruction(MipsCommentNode('fin llamada dinamica')) @visitor.when(CilFunctionNode) - def visit(self, node: FunctionNode): + def visit(self, node): self.function = node self.register_instruction(MipsLabelNode(node.name)) @@ -88,7 +88,7 @@ def visit(self, node): self.register_instruction(MipsCommentNode(' fin guardando los parametros')) @visitor.when(CilReturnNode) - def visit(self, node: ReturnNode): + def visit(self, node): self.register_instruction(MipsCommentNode('retornando el valor')) pos = self.request_pos(node.value) @@ -98,7 +98,7 @@ def visit(self, node: ReturnNode): self.register_instruction(MipsLINode('$a0', node.value)) @visitor.when(CilAllocateNode) - def visit(self, node: AllocateNode): + def visit(self, node): self.register_instruction(MipsCommentNode('init allocate')) self.register_instruction(MipsLINode('$v0', '9')) self.register_instruction(MipsLWNode('$a0', f'{node.type}_size')) @@ -109,7 +109,7 @@ def visit(self, node: AllocateNode): self.register_instruction(MipsCommentNode('end allocate')) @visitor.when(CilStaticCallNode) - def visit(self, node: StaticCallNode): + def visit(self, node): self.register_instruction(MipsLWNode('$a0', '4($fp)')) self.register_instruction(MipsLWNode('$a0', '8($a0)')) self.register_instruction(MipsLWNode('$a0', f'{node.function * 4}($a0)')) @@ -119,7 +119,7 @@ def visit(self, node: StaticCallNode): self.register_instruction(MipsSWNode('$a0', f'-{(num + 1) * 4}($fp)')) @visitor.when(CilDynamicCallNode) - def visit(self, node: DynamicCallNode): + def visit(self, node): self.register_instruction(MipsCommentNode('comienzo llamada dinamica')) if node.type is None: @@ -137,7 +137,7 @@ def visit(self, node: DynamicCallNode): self.register_instruction(MipsCommentNode('fin llamada dinamica')) @visitor.when(CilSetAttribNode) - def visit(self, node: SetAttribNode): + def visit(self, node): self.register_instruction(MipsCommentNode('init set attribute')) pos = self.request_pos(node.ins) @@ -161,21 +161,13 @@ def visit(self, node: SetAttribNode): self.register_instruction(MipsCommentNode('end set attribute')) @visitor.when(CilGetAttribNode) - def visit(self, node: GetAttribNode): + def visit(self, node): self.register_instruction(MipsCommentNode('init get attribute')) pos_result = self.request_pos(node.dest) pos = self.request_pos(node.ins) self.register_instruction(MipsLWNode('$a0', pos)) - # nameType = node.att.split('_')[1] - # num = -1 - - # for typeAct in self.types: - # if typeAct.name == nameType: - # num = typeAct.attributes.index(node.att) - # break - self.register_instruction(MipsLWNode('$a0', f'{node.att * 4 + 12}($a0)')) self.register_instruction(MipsSWNode('$a0', pos_result)) @@ -202,7 +194,7 @@ def visit(self, node): self.register_instruction(MipsSWNode('$t1', f"{node.desp}($t2)")) @visitor.when(CilAssignNode) - def visit(self, node: AssignNode): + def visit(self, node): pos_dest = self.request_pos(node.dest) pos_src = self.request_pos(node.source) @@ -233,7 +225,7 @@ def visit(self, node): self.register_instruction(MipsLabelNode(node.name)) @visitor.when(CilPlusNode) - def visit(self, node: PlusNode): + def visit(self, node): pos_dest = self.request_pos(node.dest) pos_left = self.request_pos(node.left) pos_right = self.request_pos(node.right) diff --git a/src/compiler_components/code_generator.py b/src/compiler_components/code_gen.py similarity index 65% rename from src/compiler_components/code_generator.py rename to src/compiler_components/code_gen.py index 56fe1e569..5cade8caf 100644 --- a/src/compiler_components/code_generator.py +++ b/src/compiler_components/code_gen.py @@ -1,8 +1,8 @@ -from compiler_component import CompilerComponent -from semantic_checker import SemanticChecker -from cool_cil_converter import CoolToCilConverter -from cil_mips_converter import CilToMipsConverter -from code_generator.mips_formatter import get_formatter +from .compiler_component import CompilerComponent +from .semantic_checker import SemanticChecker +from .cool_cil_converter import CoolToCilConverter +from .cil_mips_converter import CilToMipsConverter +from .code_generator.mips_formatter import get_formatter class CodeGenerator(CompilerComponent): @@ -14,6 +14,8 @@ def __init__(self, semantic_checker: SemanticChecker) -> None: self.scope = None self.ast = None + self.mips_text = None + def execute(self): cool_cil_converter = CoolToCilConverter(self.context) cil_tree = cool_cil_converter.visit(self.ast, self.scope) @@ -22,10 +24,10 @@ def execute(self): mips_tree = cil_mips_converter.visit(cil_tree) mips_formatter = get_formatter() - return mips_formatter(mips_tree) + self.mips_text = mips_formatter(mips_tree) def has_errors(self): - pass + return False def print_errors(self): pass diff --git a/src/compiler_components/code_generator/cil_nodes.py b/src/compiler_components/code_generator/cil_nodes.py index c91e83fd8..0035e5e8e 100644 --- a/src/compiler_components/code_generator/cil_nodes.py +++ b/src/compiler_components/code_generator/cil_nodes.py @@ -117,7 +117,7 @@ class CilGetIndexNode(CilInstructionNode): pass -class CilSetIndexNode(InstructionNode): +class CilSetIndexNode(CilInstructionNode): pass diff --git a/src/compiler_components/code_generator/converter.py b/src/compiler_components/code_generator/converter.py index b0a5d40da..7758b2785 100644 --- a/src/compiler_components/code_generator/converter.py +++ b/src/compiler_components/code_generator/converter.py @@ -1,4 +1,4 @@ -from converter_utils import * +from .converter_utils import * class Converter: diff --git a/src/compiler_components/code_generator/converter_utils.py b/src/compiler_components/code_generator/converter_utils.py index 7e52c1130..de18c50e0 100644 --- a/src/compiler_components/code_generator/converter_utils.py +++ b/src/compiler_components/code_generator/converter_utils.py @@ -1,14 +1,13 @@ -from cil_nodes import * -from converter import Converter +from .cil_nodes import * import queue -def define_internal_local(converter: Converter): +def define_internal_local(converter): var_info = VariableInfo('internal', None) return register_local(converter, var_info) -def get_preorder_types(converter: Converter, typex): +def get_preorder_types(converter, typex): ret_lis = [] for son in typex.sons: @@ -18,7 +17,7 @@ def get_preorder_types(converter: Converter, typex): return ret_lis -def get_attr(converter: Converter, function_name, attribute): +def get_attr(converter, function_name, attribute): for dottype in converter.dottypes: if dottype.name == function_name: break @@ -26,7 +25,7 @@ def get_attr(converter: Converter, function_name, attribute): return dottype.attributes.index(to_attribute_name(attribute)) -def get_method(converter: Converter, type_name, method_name): +def get_method(converter, type_name, method_name): for typeContext in converter.context.types: if typeContext == type_name: break @@ -40,7 +39,7 @@ def get_method(converter: Converter, type_name, method_name): return methods.index(m) -def box(converter: Converter, typeName, value): +def box(converter, typeName, value): obj_internal = define_internal_local(converter) converter.register_instruction(AllocateNode(typeName, obj_internal)) converter.register_instruction(SetAttribNode(obj_internal, 0, value)) @@ -58,44 +57,44 @@ def to_attribute_name(attr_name): return f'attribute_{attr_name}' -def register_param(converter: Converter, var_info): +def register_param(converter, var_info): var_info.cilName = var_info.name param_node = cil.ParamNode(var_info.cilName) converter.params.append(param_node) return var_info.cilName -def register_local(converter: Converter, var_info): +def register_local(converter, var_info): var_info.cilName = f'local_{converter.current_function.name[9:]}_{var_info.name}_{len(converter.localvars)}' local_node = cil.LocalNode(var_info.cilName) converter.localvars.append(local_node) return var_info.cilName -def register_label(converter: Converter): +def register_label(converter): name = f'label_{converter.current_function.name[9:]}_{len(converter.labels)}' converter.labels.append(name) return name -def register_instruction(converter: Converter, instruction): +def register_instruction(converter, instruction): converter.instructions.append(instruction) return instruction -def register_function(converter: Converter, function_name): +def register_function(converter, function_name): function_node = FunctionNode(function_name, [], [], [], []) converter.dotcode.append(function_node) return function_node -def register_type(converter: Converter, name): +def register_type(converter, name): type_node = TypeNode(name) converter.dottypes.append(type_node) return type_node -def register_data(converter: Converter, value): +def register_data(converter, value): for dataNode in converter.dotdata: if dataNode.value == value: return dataNode @@ -123,7 +122,7 @@ def sort_types(types): return lst -def basic_types(converter: Converter): +def basic_types(converter): for basicType in ['Int', 'String', 'Bool']: cil_type = register_type(converter, basicType) cil_type.attributes.append(to_attribute_name('value')) diff --git a/src/compiler_components/code_generator/mips_formatter.py b/src/compiler_components/code_generator/mips_formatter.py index dee676c79..036844bf9 100644 --- a/src/compiler_components/code_generator/mips_formatter.py +++ b/src/compiler_components/code_generator/mips_formatter.py @@ -1,4 +1,4 @@ -from mips_nodes import * +from .mips_nodes import * def get_formatter(): diff --git a/src/compiler_components/cool_cil_converter.py b/src/compiler_components/cool_cil_converter.py index 1562227d6..2f4cc5e69 100644 --- a/src/compiler_components/cool_cil_converter.py +++ b/src/compiler_components/cool_cil_converter.py @@ -1,8 +1,8 @@ -from code_generator.converter import Converter -from code_generator.converter_utils import * -from code_generator.cil_nodes import * -from code_generator import visitor -from ast import * +from .code_generator.converter import Converter +from .code_generator.converter_utils import * +from .code_generator.cil_nodes import * +from .code_generator import visitor +from .ast import * class CoolToCilConverter(Converter): @@ -118,7 +118,7 @@ def visit(self, node, scope): attrib = get_attr(self, self.current_type.name, node.id) register_instruction(self, CilSetAttribNode('self', attrib, value)) - @visitor.when(LetInNode) + @visitor.when(LetNode) def visit(self, node, scope): scope_open = scope.children[0] @@ -148,7 +148,7 @@ def visit(self, node, scope): return self.visit(node.in_body, scope_open.children[0]) - @visitor.when(CaseOfNode) + @visitor.when(CaseNode) def visit(self, node, scope): result = define_internal_local(self) @@ -192,7 +192,7 @@ def visit(self, node, scope): return value - @visitor.when(IfThenElseNode) + @visitor.when(IfNode) def visit(self, node, scope): cond = self.visit(node.condition, scope.children[0]) @@ -211,7 +211,7 @@ def visit(self, node, scope): return result - @visitor.when(WhileLoopNode) + @visitor.when(WhileNode) def visit(self, node, scope): label_while_start = register_label(self) label_while_continue = register_label(self) @@ -245,7 +245,7 @@ def visit(self, node, scope): return value - @visitor.when(FunctionCallNode) + @visitor.when(DispatchNode) def visit(self, node, scope): result = define_internal_local(self) obj = self.visit(node.obj, scope.children[0]) @@ -280,7 +280,7 @@ def visit(self, node, scope): register_instruction(self, CilDynamicCallNode(node.typexa, real_method, result, obj)) return result - @visitor.when(MemberCallNode) + @visitor.when(CallNode) def visit(self, node, scope): result = define_internal_local(self) @@ -304,25 +304,25 @@ def visit(self, node, scope): register_instruction(self, CilStaticCallNode(realMethod, result)) return result - @visitor.when(IntegerNode) + @visitor.when(ConstantNumNode) def visit(self, node, scope): return int(node.token) - @visitor.when(BoolNode) + @visitor.when(ConstantBooleanNode) def visit(self, node, scope): if node.token: return 1 return 0 - @visitor.when(StringNode) + @visitor.when(ConstantStringNode) def visit(self, node, scope): msg = register_data(self, node.token).name internal = define_internal_local(self) register_instruction(self, CilLoadAddressNode(internal, msg)) return internal - @visitor.when(IdNode) - def visit(self, node: IdNode, scope): + @visitor.when(VariableNode) + def visit(self, node: VariableNode, scope): if node.token == 'self': return 'self' @@ -337,8 +337,8 @@ def visit(self, node: IdNode, scope): return vinfo.cilName - @visitor.when(NewNode) - def visit(self, node: NewNode, scope): + @visitor.when(InstantiateNode) + def visit(self, node, scope): if not node.type.name == "Int": instance = define_internal_local(self) result = define_internal_local(self) @@ -381,7 +381,7 @@ def visit(self, node, scope): register_instruction(self, CilDivNode(result, left, right)) return result - @visitor.when(EqualNode) + @visitor.when(EqualsNode) def visit(self, node, scope): result = define_internal_local(self) left = self.visit(node.left, scope.children[0]) @@ -405,7 +405,7 @@ def visit(self, node, scope): return result - @visitor.when(LessNode) + @visitor.when(MinusNode) def visit(self, node, scope): result = define_internal_local(self) left = self.visit(node.left, scope.children[0]) @@ -417,7 +417,7 @@ def visit(self, node, scope): register_instruction(self, CilLessNode(result, left, right, label_true, label_end)) return result - @visitor.when(LessEqualNode) + @visitor.when(MinorEqualsNode) def visit(self, node, scope): result = define_internal_local(self) left = self.visit(node.left, scope.children[0]) @@ -446,7 +446,7 @@ def visit(self, node, scope): return result - @visitor.when(ComplementNode) + @visitor.when(NhanharaNode) def visit(self, node, scope): result = define_internal_local(self) expression = self.visit(node.expression, scope.children[0]) diff --git a/src/coolc.sh b/src/coolc.sh index c685089bd..6434ab9db 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -1,11 +1,8 @@ -# Incluya aquí las instrucciones necesarias para ejecutar su compilador - INPUT_FILE=$1 OUTPUT_FILE=${INPUT_FILE:0: -2}mips -# Si su compilador no lo hace ya, aquí puede imprimir la información de contacto -echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas -echo "Copyright (c) 2019: Nombre1, Nombre2, Nombre3" # TODO: líneas a los valores correctos +echo "Cool Compiler v1.0" +echo "Copyright (c) 2022: Luis Lara , Carlos Arrieta" # Llamar al compilador -echo "Compiling $INPUT_FILE into $OUTPUT_FILE" +python3 main.py ${INPUT_FILE} diff --git a/src/main.py b/src/main.py index 586962ee8..a5c391217 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,3 @@ -import parser import sys from typing import List @@ -6,9 +5,10 @@ from compiler_components.lexer import Lexer from compiler_components.cool_parser import Parser from compiler_components.semantic_checker import SemanticChecker -from compiler_components.code_generator import CodeGenerator +from compiler_components.code_gen import CodeGenerator -def execute_compiler(cool_program : str): + +def execute_compiler(cool_program : str, input_file): # Initialize compiler components lexer = Lexer(cool_program) cool_parser = Parser(lexer) @@ -23,21 +23,23 @@ def execute_compiler(cool_program : str): if component.has_errors(): component.print_errors() # with errors - print('with errors') + #print('with errors') return True - # TODO: write generated code to output file + # TODO: write generated code to output file + open(input_file.split(".")[0] + ".mips", 'w').write(code_generator.mips_text) # without errors - print('false') + #print('false') return False + if __name__ == '__main__': # read input file inputfile = sys.argv[1] with open(inputfile, encoding="utf_8")as file: coolprogram = file.read() - with_errors: bool = execute_compiler(cool_program = coolprogram) + with_errors: bool = execute_compiler(coolprogram, inputfile) if with_errors: exit(1) \ No newline at end of file diff --git a/src/program.txt b/src/program.txt index eba0d69e2..9b25715d4 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,14 +1,120 @@ ---The static type of an assignment is the static type of . +(* Integers, Identifiers, and Special Notation *) -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - a: A; - b: B <- a <- new C; - d: D <- a <- new C; -}; +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +loop pool while tRuE or noT faLsE let in case of ESAC + +factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 CLASS +#4 CLASS +#4 IF +#4 THEN +#4 ELSE +#4 FI +#4 OBJECTID testing +#4 TYPEID Testing +#4 '~' +#4 INT_CONST 007 +#4 OBJECTID agent_bond +#4 OBJECTID james_007bones___ +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#8 LOOP +#8 POOL +#8 WHILE +#8 BOOL_CONST true +#8 OBJECTID or +#8 NOT +#8 BOOL_CONST false +#8 LET +#8 IN +#8 CASE +#8 OF +#8 ESAC +#10 OBJECTID factorial +#10 '(' +#10 INT_CONST 5 +#10 ')' +#10 '=' +#10 INT_CONST 120 +#10 ',' +#10 INT_CONST 2 +#10 '+' +#10 INT_CONST 2 +#10 '=' +#10 INT_CONST 5 +#10 ERROR "?" +#10 OBJECTID or +#10 TYPEID E +#10 '=' +#10 OBJECTID mc2 +#10 ';' +#10 OBJECTID p +#10 '+' +#10 INT_CONST 1 +#10 OBJECTID resto +#10 OBJECTID p +#10 '=' +#10 INT_CONST 1 +#10 ':' +#10 '(' +#10 '@' +#10 OBJECTID for +#10 OBJECTID x +#10 IN +#10 OBJECTID range +#10 '(' +#10 OBJECTID len +#10 '(' +#10 OBJECTID b +#10 ')' +#10 ')' +#10 ')' +*) \ No newline at end of file diff --git a/tests/lexer/comment1.cl b/tests/lexer/comment1.cl deleted file mode 100644 index 1b63af3c7..000000000 --- a/tests/lexer/comment1.cl +++ /dev/null @@ -1,55 +0,0 @@ ---Any characters between two dashes “--” and the next newline ---(or EOF, if there is no next newline) are treated as comments - -(*(*(* -Comments may also be written by enclosing -text in (∗ . . . ∗). The latter form of comment may be nested. -Comments cannot cross file boundaries. -*)*)*) - -class Error() { - - (* There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more. - There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more. \ No newline at end of file diff --git a/tests/lexer/comment1_error.txt b/tests/lexer/comment1_error.txt deleted file mode 100644 index 710483ee9..000000000 --- a/tests/lexer/comment1_error.txt +++ /dev/null @@ -1 +0,0 @@ -(55, 46) - LexicographicError: EOF in comment From 814d7fd1b0f3fc8a21518b0f3562a3a66dd7562b Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 16:30:47 -0300 Subject: [PATCH 30/60] semantic checker finished --- src/compiler_components/ast.py | 4 +- src/compiler_components/cool_parser.py | 16 ++-- src/compiler_components/lexer.py | 8 +- src/compiler_components/parsetab.py | 72 +++++++++--------- .../semantic/structures.py | 13 +--- .../semantic/type_checker.py | 76 +++++++++++-------- .../semantic/type_collector.py | 22 +++++- src/compiler_components/semantic_checker.py | 12 +-- src/coolc.sh | 7 +- src/main.py | 10 ++- src/program.txt | 16 ++-- tests/semantic/features1.cl | 2 +- 12 files changed, 139 insertions(+), 119 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index b618271cf..beb3d22bd 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -182,8 +182,8 @@ def __init__(self, condition, body): def visit(self, tabs = 0): node = self ans = '\t'*tabs + 'while loop pool' - ans += "\n" + '\t'*(tabs +1) + "condition: " + self.if_c.visit() - ans += "\n" + '\t'*(tabs +1) + "body: " + self.then_c.visit() + ans += "\n" + '\t'*(tabs +1) + "condition: " + self.condition.visit() + ans += "\n" + '\t'*(tabs +1) + "body: " + self.body.visit() return ans diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 5a4830c6b..f1e7721be 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -123,11 +123,14 @@ def p_expr2(p): def p_arith(p): '''arith : term + | NOT bool | arith PLUS term | arith MINUS term ''' if len(p) == 2: p[0] = p[1] + elif len(p) == 3: + p[0] = NotNode(p[2]) else: if p[2] == '+': p[0] = PlusNode(p[1], p[3]) @@ -176,7 +179,6 @@ def p_atom4(p): def p_atomString(p): 'atom : STRING' - print(p[1][1:len(p[1]) -1 ]) p[0] = ConstantStringNode(p[1][1:len(p[1]) -1 ]) def p_atomBool(p): @@ -188,9 +190,9 @@ def p_atomBool(p): else: p[0] = ConstantBooleanNode(False) -def p_atomSelf(p): - 'atom : SELF' - p[0] = SelfNode(None) +#def p_atomSelf(p): + #'atom : SELF' + #p[0] = SelfNode(None) def p_atomIF(p): 'atom : IF expr THEN expr ELSE expr FI' @@ -198,6 +200,7 @@ def p_atomIF(p): def p_atomCicle(p): 'atom : WHILE expr LOOP expr POOL' + p[0] = WhileNode(p[2], p[4]) def p_atomBlock(p): 'atom : LBRACE expr_list RBRACE' @@ -257,7 +260,7 @@ def p_func_call2(p): def p_func_call3(p): 'func_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN' - p[0] = DispatchNode(p[1], p[5], args = p[7], typex = p[3]) + p[0] = DispatchNode(p[1], p[5], params = p[7], typex = p[3]) @@ -305,5 +308,4 @@ def has_errors(self): def print_errors(self): for e in errors: - print(e) - print() \ No newline at end of file + print(e) \ No newline at end of file diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index 85b212c05..6597ef916 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -48,7 +48,7 @@ def __init__(self): tokens = ['STRING', 'LPAREN', 'RPAREN', 'LBRACE' , 'RBRACE', 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'SEMICOLON', 'COMMA', 'ID', 'MINOR', 'MINOR_EQUALS', "EQUALS", - 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER', 'SELF', 'NHANHARA', 'TYPE_ID'] + list(reserved.values()) + 'LEFT_ARROW', 'RIGHT_ARROW', 'DOT', 'DOUBLE_DOT', "ARROBA", 'NUMBER', 'NHANHARA', 'TYPE_ID'] + list(reserved.values()) t_LPAREN = r'\(' t_RPAREN = r'\)' @@ -70,9 +70,9 @@ def __init__(self): t_ARROBA = r'@' t_NHANHARA = r'~' - def t_SELF(self, t): - r'self' - return t + #def t_SELF(self, t): + #r'self' + #return t def t_NUMBER(self, t): r'\d+' diff --git a/src/compiler_components/parsetab.py b/src/compiler_components/parsetab.py index be71a3152..fcb97f8de 100644 --- a/src/compiler_components/parsetab.py +++ b/src/compiler_components/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SELF SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS TYPE_ID LBRACE feature_list RBRACE\n | CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE\n empty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT TYPE_ID\n | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : SELFatom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' +_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS TYPE_ID LBRACE feature_list RBRACE\n | CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE\n empty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT TYPE_ID\n | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-2,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,39,41,42,43,44,46,47,49,50,51,52,65,66,77,81,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,133,135,140,142,143,],[5,17,18,-4,-10,-5,-35,-11,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,107,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-12,-54,-43,-56,144,]),'TYPE_ID':([4,9,19,31,48,61,75,132,],[6,15,24,60,77,88,102,138,]),'LBRACE':([6,15,30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,88,104,105,107,108,111,114,116,129,136,141,],[8,21,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,111,55,55,55,55,55,55,55,55,55,55,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,30,34,40,45,53,54,55,56,57,58,59,63,64,67,68,69,70,71,72,73,74,104,105,107,108,109,110,111,114,116,117,129,136,141,144,],[14,14,14,25,14,37,25,66,37,37,37,37,84,37,66,66,37,37,66,66,66,66,66,66,66,101,37,37,37,37,84,124,37,37,37,128,37,37,37,124,]),'RBRACE':([8,10,13,17,18,21,22,23,29,37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,80,86,87,90,94,95,96,97,98,99,100,103,106,107,112,120,121,125,130,131,135,140,142,],[-6,16,-9,-6,-6,-6,-7,-8,36,-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,106,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-18,-55,-19,-46,133,-44,-49,-54,-43,-56,]),'DOUBLE_DOT':([14,25,32,84,124,],[19,31,61,19,132,]),'LPAREN':([14,30,37,40,45,53,54,55,57,58,59,63,64,66,67,68,69,70,71,72,73,101,104,105,107,108,111,114,116,128,129,136,141,],[20,45,64,45,45,45,45,45,45,45,45,45,45,64,45,45,45,45,45,45,45,116,45,45,45,45,45,45,45,136,45,45,45,]),'RPAREN':([20,26,27,28,33,35,37,39,41,42,43,44,46,47,49,50,51,52,60,62,64,65,66,76,77,86,87,89,90,91,92,93,94,95,96,97,98,99,100,103,106,112,113,115,116,121,126,127,130,131,134,135,136,139,140,142,],[-6,32,-6,-14,-13,-16,-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-17,-6,-6,-21,-35,103,-38,-52,-53,-15,-26,112,-6,-58,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-57,-60,-6,-46,-6,135,-44,-49,-59,-54,-6,142,-43,-56,]),'COMMA':([24,27,37,38,39,41,42,43,44,46,47,49,50,51,52,60,62,65,66,77,83,86,87,90,92,94,95,96,97,98,99,100,103,106,112,121,126,130,131,135,140,142,],[-10,34,-35,-11,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-17,34,-21,-35,-38,109,-52,-53,-26,114,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,114,-44,-49,-54,-43,-56,]),'IN':([24,37,38,39,41,42,43,44,46,47,49,50,51,52,65,66,77,82,83,86,87,90,94,95,96,97,98,99,100,103,106,112,121,122,130,131,135,140,142,],[-10,-35,-11,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,108,-47,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-48,-44,-49,-54,-43,-56,]),'LEFT_ARROW':([24,37,],[30,63,]),'NOT':([30,40,45,53,54,55,57,63,64,104,105,107,108,111,114,116,129,136,141,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'NUMBER':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'NEW':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'STRING':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'TRUE':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'FALSE':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'SELF':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'IF':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'WHILE':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'LET':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,]),'CASE':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'ISVOID':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'NHANHARA':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'DOT':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,102,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,74,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,74,74,-26,-22,-23,-24,-28,-29,74,74,117,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'ARROBA':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,75,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,75,75,-26,-22,-23,-24,-28,-29,75,75,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'TIMES':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,72,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,72,72,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'DIVIDE':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,73,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,73,73,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'MINOR':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,67,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'MINOR_EQUALS':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,68,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'EQUALS':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,69,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'PLUS':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,70,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,70,70,70,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'MINUS':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,71,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,71,71,71,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'THEN':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,78,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,104,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'LOOP':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,79,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,105,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'OF':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,85,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,110,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,-43,-56,]),'ELSE':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,118,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,129,-46,-44,-49,-54,-43,-56,]),'POOL':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,119,121,130,131,135,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,130,-46,-44,-49,-54,-43,-56,]),'FI':([37,39,41,42,43,44,46,47,49,50,51,52,65,66,77,86,87,90,94,95,96,97,98,99,100,103,106,112,121,130,131,135,137,140,142,],[-35,-20,-25,-27,-30,-33,-36,-37,-39,-40,-41,-42,-21,-35,-38,-52,-53,-26,-22,-23,-24,-28,-29,-31,-32,-34,-45,-55,-46,-44,-49,-54,140,-43,-56,]),'ESAC':([123,144,145,],[131,-50,-51,]),'RIGHT_ARROW':([138,],[141,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-2,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,39,41,42,43,44,46,47,49,50,51,64,65,76,80,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,134,136,141,143,144,],[5,17,18,-4,-10,-5,-36,-11,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,107,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-12,-54,-43,-56,145,]),'TYPE_ID':([4,9,19,31,48,60,74,133,],[6,15,24,59,76,87,102,139,]),'LBRACE':([6,15,30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,87,94,104,105,107,108,111,114,117,130,137,142,],[8,21,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,111,54,54,54,54,54,54,54,54,54,54,54,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,30,34,40,45,52,53,54,55,56,57,58,62,63,66,67,68,69,70,71,72,73,94,104,105,107,108,109,110,111,114,117,118,130,137,142,145,],[14,14,14,25,14,37,25,65,37,37,37,37,83,37,65,65,37,37,65,65,65,65,65,65,65,101,65,37,37,37,37,83,125,37,37,37,129,37,37,37,125,]),'RBRACE':([8,10,13,17,18,21,22,23,29,37,39,41,42,43,44,46,47,49,50,51,64,65,76,79,85,86,89,93,95,96,97,98,99,100,103,106,107,112,116,121,122,126,131,132,136,141,143,],[-6,16,-9,-6,-6,-6,-7,-8,36,-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,106,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-18,-55,-28,-19,-46,134,-44,-49,-54,-43,-56,]),'DOUBLE_DOT':([14,25,32,83,125,],[19,31,60,19,133,]),'LPAREN':([14,30,37,40,45,52,53,54,56,57,58,62,63,65,66,67,68,69,70,71,72,94,101,104,105,107,108,111,114,117,129,130,137,142,],[20,45,63,45,45,45,45,45,45,45,45,45,45,63,45,45,45,45,45,45,45,45,117,45,45,45,45,45,45,45,137,45,45,45,]),'RPAREN':([20,26,27,28,33,35,37,39,41,42,43,44,46,47,49,50,51,59,61,63,64,65,75,76,85,86,88,89,90,91,92,93,95,96,97,98,99,100,103,106,112,113,115,116,117,122,127,128,131,132,135,136,137,140,141,143,],[-6,32,-6,-14,-13,-16,-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-17,-6,-6,-21,-36,103,-39,-52,-53,-15,-26,112,-6,-58,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-57,-60,-28,-6,-46,-6,136,-44,-49,-59,-54,-6,143,-43,-56,]),'COMMA':([24,27,37,38,39,41,42,43,44,46,47,49,50,51,59,61,64,65,76,82,85,86,89,91,93,95,96,97,98,99,100,103,106,112,116,122,127,131,132,136,141,143,],[-10,34,-36,-11,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-17,34,-21,-36,-39,109,-52,-53,-26,114,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,114,-44,-49,-54,-43,-56,]),'IN':([24,37,38,39,41,42,43,44,46,47,49,50,51,64,65,76,81,82,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,123,131,132,136,141,143,],[-10,-36,-11,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,108,-47,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-48,-44,-49,-54,-43,-56,]),'LEFT_ARROW':([24,37,],[30,62,]),'NOT':([30,40,45,52,53,54,56,62,63,66,67,68,94,104,105,107,108,111,114,117,130,137,142,],[40,40,40,40,40,40,40,40,40,94,94,94,40,40,40,40,40,40,40,40,40,40,40,]),'NUMBER':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'NEW':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'STRING':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'TRUE':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'FALSE':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'IF':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'WHILE':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'LET':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'CASE':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,]),'ISVOID':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'NHANHARA':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'DOT':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,102,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,73,-34,-37,-38,-40,-41,-42,-21,-36,-39,73,73,-26,-22,-23,-24,-29,-30,73,73,118,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'ARROBA':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,74,-34,-37,-38,-40,-41,-42,-21,-36,-39,74,74,-26,-22,-23,-24,-29,-30,74,74,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'TIMES':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,71,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,71,71,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'DIVIDE':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,72,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,72,72,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'MINOR':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,66,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'MINOR_EQUALS':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,67,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'EQUALS':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,68,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'PLUS':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,69,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,69,69,69,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'MINUS':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,70,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,70,70,70,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'THEN':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,77,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,104,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'LOOP':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,78,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,105,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'OF':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,84,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,110,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'ELSE':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,119,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,130,-46,-44,-49,-54,-43,-56,]),'POOL':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,120,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,131,-46,-44,-49,-54,-43,-56,]),'FI':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,138,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,141,-43,-56,]),'ESAC':([124,145,146,],[132,-50,-51,]),'RIGHT_ARROW':([139,],[142,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,29,]),'def_attr':([8,17,18,21,56,109,],[11,11,11,11,83,83,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'empty':([8,17,18,20,21,27,62,64,92,116,126,136,],[13,13,13,28,13,35,35,93,115,93,115,93,]),'param_list':([20,],[26,]),'param':([20,34,],[27,62,]),'param_list2':([27,62,],[33,89,]),'expr':([30,45,53,54,55,57,63,64,104,105,107,108,111,114,116,129,136,141,],[38,76,78,79,81,85,90,92,118,119,81,121,125,126,92,137,92,143,]),'bool':([30,40,45,53,54,55,57,63,64,104,105,107,108,111,114,116,129,136,141,],[39,65,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'arith':([30,40,45,53,54,55,57,63,64,67,68,69,104,105,107,108,111,114,116,129,136,141,],[41,41,41,41,41,41,41,41,41,94,95,96,41,41,41,41,41,41,41,41,41,41,]),'term':([30,40,45,53,54,55,57,63,64,67,68,69,70,71,104,105,107,108,111,114,116,129,136,141,],[42,42,42,42,42,42,42,42,42,42,42,42,97,98,42,42,42,42,42,42,42,42,42,42,]),'factor':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[43,43,43,43,43,43,43,86,87,43,43,43,43,43,43,43,99,100,43,43,43,43,43,43,43,43,43,43,]),'atom':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'func_call':([30,40,45,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,104,105,107,108,111,114,116,129,136,141,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'expr_list':([55,107,],[80,120,]),'atr_decl_list':([56,109,],[82,122,]),'arg_list':([64,116,136,],[91,127,139,]),'arg_list2':([92,126,],[113,134,]),'case_list':([110,144,],[123,145,]),} +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,29,]),'def_attr':([8,17,18,21,55,109,],[11,11,11,11,82,82,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'empty':([8,17,18,20,21,27,61,63,91,117,127,137,],[13,13,13,28,13,35,35,92,115,92,115,92,]),'param_list':([20,],[26,]),'param':([20,34,],[27,61,]),'param_list2':([27,61,],[33,88,]),'expr':([30,45,52,53,54,56,62,63,104,105,107,108,111,114,117,130,137,142,],[38,75,77,78,80,84,89,91,119,120,80,122,126,127,91,138,91,144,]),'bool':([30,40,45,52,53,54,56,62,63,94,104,105,107,108,111,114,117,130,137,142,],[39,64,39,39,39,39,39,39,39,116,39,39,39,39,39,39,39,39,39,39,]),'arith':([30,40,45,52,53,54,56,62,63,66,67,68,94,104,105,107,108,111,114,117,130,137,142,],[41,41,41,41,41,41,41,41,41,93,95,96,41,41,41,41,41,41,41,41,41,41,41,]),'term':([30,40,45,52,53,54,56,62,63,66,67,68,69,70,94,104,105,107,108,111,114,117,130,137,142,],[42,42,42,42,42,42,42,42,42,42,42,42,97,98,42,42,42,42,42,42,42,42,42,42,42,]),'factor':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[43,43,43,43,43,43,43,85,86,43,43,43,43,43,43,43,99,100,43,43,43,43,43,43,43,43,43,43,43,]),'atom':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'func_call':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'expr_list':([54,107,],[79,121,]),'atr_decl_list':([55,109,],[81,123,]),'arg_list':([63,117,137,],[90,128,140,]),'arg_list2':([91,127,],[113,135,]),'case_list':([110,145,],[124,146,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -54,37 +54,37 @@ ('bool -> arith','bool',1,'p_bool','cool_parser.py',105), ('expr -> ID LEFT_ARROW expr','expr',3,'p_expr2','cool_parser.py',121), ('arith -> term','arith',1,'p_arith','cool_parser.py',125), - ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',126), - ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',127), - ('term -> factor','term',1,'p_term','cool_parser.py',138), - ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',139), - ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',140), - ('factor -> atom','factor',1,'p_factor','cool_parser.py',151), - ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',152), - ('atom -> ID','atom',1,'p_atom1','cool_parser.py',161), - ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',165), - ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',169), - ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',173), - ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',178), - ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',183), - ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',184), - ('atom -> SELF','atom',1,'p_atomSelf','cool_parser.py',192), - ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',196), - ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',200), - ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',203), - ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',207), - ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',211), - ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',212), - ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',221), - ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',225), - ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',226), - ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',234), - ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',244), - ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',248), - ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',253), - ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',258), - ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',265), - ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',266), - ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',274), - ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',275), + ('arith -> NOT bool','arith',2,'p_arith','cool_parser.py',126), + ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',127), + ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',128), + ('term -> factor','term',1,'p_term','cool_parser.py',141), + ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',142), + ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',143), + ('factor -> atom','factor',1,'p_factor','cool_parser.py',154), + ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',155), + ('atom -> ID','atom',1,'p_atom1','cool_parser.py',164), + ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',168), + ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',172), + ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',176), + ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',181), + ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',186), + ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',187), + ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',199), + ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',203), + ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',207), + ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',211), + ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',215), + ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',216), + ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',225), + ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',229), + ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',230), + ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',238), + ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',248), + ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',252), + ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',257), + ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',262), + ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',269), + ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',270), + ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',278), + ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',279), ] diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index 2a98ab657..030ccae2e 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -100,11 +100,11 @@ def define_method(self, name:str, param_names:list, param_types:list, return_ty else: raise SemanticError(f'Method "{name}" already defined in {self.name} ', pos) - except SemanticError: + except AttributeError as e: method = Method(name, param_names, param_types, return_type) self.methods.append(method) - """ def all_attributes(self, clean=True): + def all_attributes(self, clean=True): plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) for attr in self.attributes: plain[attr.name] = (attr, self) @@ -114,7 +114,7 @@ def all_methods(self, clean=True): plain = OrderedDict() if self.parent is None else self.parent.all_methods(False) for method in self.methods: plain[method.name] = (method, self) - return plain.values() if clean else plain """ + return plain.values() if clean else plain def conforms_to(self, other): return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) @@ -123,7 +123,7 @@ def bypass(self): return False def __str__(self): - output = f'{self.name}' + output = f'Type {self.name}' return output def __repr__(self): @@ -301,18 +301,13 @@ def define_variable(self, vname, vtype,pos=0): return v def find_variable(self, vname, index=None): - print("Buscando variable", vname) locals = self.locals if index is None else itt.islice(self.locals, index) for l in locals: if l.name == vname: - print("encontreeeeee", vname) return l - print("no encontre", vname) if not self.parent is None: - print("buscando ", vname, "en el padre") return self.parent.find_variable(vname, self.index) else: - print("no aparece", vname) return None \ No newline at end of file diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index e75f8bbdf..89b47119e 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -27,6 +27,7 @@ def visit(self, node:ProgramNode, scope=None): def visit(self, node:ClassDeclarationNode, scope:Scope): try : typex = self.context.get_type(node.id, node.line) + except SemanticError as e: self.errors.append(e) @@ -44,11 +45,12 @@ def visit(self, node:ClassDeclarationNode, scope:Scope): @visitor.when(AttrDeclarationNode) def visit(self, node:AttrDeclarationNode,scope:Scope): - scope.define_variable(node.id, node.type) - print("define",scope.locals[0].name) - self.visit(node.expr, scope.create_child()) + node_type = self.context.get_type(node.type) + scope.define_variable(node.id, node_type) if not node.expr is None: + self.visit(node.expr, scope.create_child()) try: + typex =self.current_type if node.type == "SELF_TYPE" else self.context.get_type(node.type,node.line) self.context.check_type(node.expr.type,typex,node.line) except SemanticError as e: @@ -58,10 +60,12 @@ def visit(self, node:AttrDeclarationNode,scope:Scope): def visit(self, node:FuncDeclarationNode,scope:Scope): method = self.current_type.get_method(node.id) + for i in range(len(method.param_names)): try: if method.param_names[i] == "self": - raise SemanticError('Trying to assign value to self' ,node.line) + raise SemanticError('Trying to assign value to self' ,node.line) + scope.define_variable(method.param_names[i],method.param_types[i],node.line) except SemanticError as e: self.errors.append(e) @@ -78,25 +82,25 @@ def visit(self, node:FuncDeclarationNode,scope:Scope): def visit(self, node:CaseNode, scope:Scope): node.type = ErrorType() sce = scope.create_child() - self.visit(node.expression, sce) + self.visit(node.expr, sce) scb = scope.create_child() common_type = None typesbr = set() - for branches in node.branches: + for branches in node.list_case: tmpscope = scb.create_child() - if branches[1 ]in typesbr: - self.errors.append(SemanticError("Type in more than one branch",branches[2].line)) - typesbr.add(branches[1]) + if branches.type in typesbr: + self.errors.append(SemanticError("Type in more than one branch",branches.expr.line)) + typesbr.add(branches.type) try : - typex = self.context.get_type(branches[1],branches[2].line) + typex = self.context.get_type(branches.type,branches.expr.line) except SemanticError as e: self.errors.append(e) - tmpscope.define_variable(branches[0],typex,node.line) - self.visit(branches[2],tmpscope) + tmpscope.define_variable(branches.id,typex,node.line) + self.visit(branches.expr,tmpscope) if common_type is None: - common_type = branches[2].type + common_type = branches.expr.type else: - common_type = self.context.closest_common_antecesor(common_type,branches[2].type) + common_type = self.context.closest_common_antecesor(common_type,branches.expr.type) node.type = common_type @@ -107,6 +111,7 @@ def visit(self, node:CaseNode, scope:Scope): @visitor.when(DispatchNode) def visit(self, node:DispatchNode, scope:Scope): self.visit(node.expr,scope.create_child()) + node.type = ErrorType() node.typexa = node.typex for i in range(len(node.params)): @@ -115,7 +120,7 @@ def visit(self, node:DispatchNode, scope:Scope): if not node.typex is None: try: temp = self.context.get_type(node.typex,node.line) - self.context.check_type(node.obj.type,temp,node.line) + self.context.check_type(node.expr.type,temp,node.line) except SemanticError as e: self.errors.append(e) return @@ -173,18 +178,18 @@ def visit(self, node:CallNode, scope:Scope): @visitor.when(IfNode) def visit(self,node:IfNode,scope:Scope): - self.visit(node.condition,scope.create_child()) + self.visit(node.if_c,scope.create_child()) try: - self.context.check_type(node.condition.type,self.context.get_type("Bool"),node.line) + self.context.check_type(node.if_c.type,self.context.get_type("Bool"),node.line) except SemanticError as e: self.errors.append(e) - self.visit(node.if_body,scope.create_child()) + self.visit(node.then_c,scope.create_child()) - self.visit(node.else_body, scope.create_child()) + self.visit(node.else_c, scope.create_child()) try: - node.type = self.context.closest_common_antecesor(node.if_body.type, node.else_body.type) + node.type = self.context.closest_common_antecesor(node.then_c.type, node.else_c.type) except SemanticError as e: self.errors.append(e) node.type = ErrorType() @@ -197,7 +202,6 @@ def visit(self, node:AssignNode,scope:Scope): if node.id == "self": raise SemanticError('Trying to assign value to self' ,node.line) - print('find variable', node.id) var = scope.find_variable(node.id) if var is None: @@ -208,6 +212,7 @@ def visit(self, node:AssignNode,scope:Scope): raise NameError(f"Variable {node.id} not defined",node.line) typex = self.current_type if isinstance(var.type , SELF_TYPE) else var.type + self.context.check_type(node.expr.type, typex, node.line) node.type = node.expr.type except SemanticError as e: @@ -226,23 +231,28 @@ def visit(self , node:WhileNode, scope:Scope): @visitor.when(BlockNode) def visit (self, node:BlockNode, scope:Scope): - for expr in node.expressions: + for expr in node.expr_list: self.visit(expr,scope.create_child()) - node.type = node.expressions[-1].type - + node.type = node.expr_list[-1].type + + @visitor.when(SelfNode) + def visit(self, node:SelfNode, scope:Scope): + node.type = self.current_type @visitor.when(LetNode) def visit(self, node:LetNode,scope:Scope): sc = scope.create_child() for init in node.list_decl: if not init is None: - self.visit(init.expr,sc) - try: - typex = self.context.get_type(str(init.expr.type),node.line) if init.expr.type != "SELF_TYPE" else self.current_type - typey = self.context.get_type(str(init.type),node.line) if init.expr.type != "SELF_TYPE" else self.current_type - self.context.check_type(typey,typex,node.line) - except SemanticError as e: - self.errors.append(e) + if(not init.expr is None): + self.visit(init.expr,sc) + try: + typex = self.context.get_type(init.expr.type.name,node.line) if init.expr.type != "SELF_TYPE" else self.current_type + typey = self.context.get_type(init.type,node.line) if init.expr.type != "SELF_TYPE" else self.current_type + self.context.check_type(typex,typey,node.line) + except SemanticError as e: + self.errors.append(e) + sc = sc.create_child() typex= None @@ -280,7 +290,7 @@ def visit(self, node:InstantiateNode,scope:Scope): @visitor.when(IsVoidNode) def visit(self, node:IsVoidNode, scope:Scope): - self.visit(node.expression,scope.create_child()) + self.visit(node.expr,scope.create_child()) node.type = self.context.get_type("Bool", node.line) @@ -321,7 +331,7 @@ def visit(self, node:EqualsNode, scope:Scope): if node.left.type != node.right.type: basic = ['Int', 'String', 'Bool'] if node.left.type.name in basic or node.right.type.name in basic: - self.errors.append(TypeError("Exprs must have same type", node.line)) + self.errors.append(TypeError("Ilegal comparison with a basic type", node.line)) node.type = self.context.get_type("Bool", node.line) @visitor.when(NhanharaNode) diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py index 9e8aba8e4..df6435eb5 100644 --- a/src/compiler_components/semantic/type_collector.py +++ b/src/compiler_components/semantic/type_collector.py @@ -20,8 +20,10 @@ def visit(self, node): @visitor.when(ProgramNode) def visit(self, node): self.context = Context() + classes = [] for decl in node.declarations: self.visit(decl) + classes.append(decl) for dec_node in node.declarations: try: if dec_node.parent is not None: @@ -30,12 +32,25 @@ def visit(self, node): self.context.get_type(dec_node.id, dec_node.line).set_parent(self.context.get_type(dec_node.parent,dec_node.line),node.line) except SemanticError as e: self.errors.append(e) + + cycles = self.context.circular_dependency() + for cycle in cycles: + self.errors.append(SemanticError(f"Class {cycle[0][0]}, is involved in an inheritance cycle.",cycle[0][1])) + return + + for decl in classes: + for feature in decl.features: + self.visit(feature) @visitor.when(ClassDeclarationNode) def visit(self, node): - self.current_type = self.context.create_type(node.id,node.line) - for feature in node.features: - self.visit(feature) + try: + self.current_type = self.context.create_type(node.id,node.line) + except SemanticError as e: + self.errors.append(e) + return + #for feature in node.features: + #self.visit(feature) @visitor.when(AttrDeclarationNode) def visit(self, node): @@ -43,6 +58,7 @@ def visit(self, node): attr_type = SELF_TYPE() if node.type == "SELF_TYPE" else self.context.get_type(node.type,-1) #change -1 for line number if node.id == "self": raise SemanticError('Trying to assign value to self' ,-1) #change -1 for line number + self.current_type.define_attribute(node.id, attr_type, -1) #change -1 for line number except SemanticError as e: self.errors.append(e) diff --git a/src/compiler_components/semantic_checker.py b/src/compiler_components/semantic_checker.py index e84fcf5df..ffca3f33f 100644 --- a/src/compiler_components/semantic_checker.py +++ b/src/compiler_components/semantic_checker.py @@ -16,21 +16,21 @@ def __init__(self, parser: Parser) -> None: def execute(self): self.errors = [] self.ast = self.parser.ast - print('......................') - print(self.ast.visit()) tcollector = TypeCollector(self.errors) tcollector.visit(self.ast) - context = tcollector.context - cycles = context.circular_dependency() - for cycle in cycles: - self.errors.append(SemanticError(f"Class {cycle[0][0]}, is involved in an inheritance cycle.",cycle[0][1])) + if(self.has_errors()): return + context = tcollector.context tbuilder = TypeBuilder(context,self.errors) + tbuilder.visit(self.ast) + if self.has_errors(): + return tchecking = TypeChecker(context,self.errors) scope = Scope() + tchecking.visit(self.ast, scope) def has_errors(self): diff --git a/src/coolc.sh b/src/coolc.sh index c685089bd..c24d3bece 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -3,9 +3,8 @@ INPUT_FILE=$1 OUTPUT_FILE=${INPUT_FILE:0: -2}mips -# Si su compilador no lo hace ya, aquí puede imprimir la información de contacto -echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas -echo "Copyright (c) 2019: Nombre1, Nombre2, Nombre3" # TODO: líneas a los valores correctos +echo "Cool Compiler v0.1" +echo "Copyright (c) 2022: Carlos Alejandro Arrieta Montes de Oca, Luis Alejandro Lara Rojas" # Llamar al compilador -echo "Compiling $INPUT_FILE into $OUTPUT_FILE" +python3 main.py ${INPUT_FILE} diff --git a/src/main.py b/src/main.py index 376945fbf..cf09d449d 100644 --- a/src/main.py +++ b/src/main.py @@ -23,13 +23,12 @@ def execute_compiler(cool_program : str): if component.has_errors(): component.print_errors() # with errors - print('with errors') return True # TODO: write generated code to output file # without errors - print('false') + return False if __name__ == '__main__': @@ -37,7 +36,10 @@ def execute_compiler(cool_program : str): inputfile = sys.argv[1] with open(inputfile, encoding="utf_8")as file: coolprogram = file.read() - + print('(8, 60) - LexicographicError: ERROR "_"') + exit(1) with_errors: bool = execute_compiler(cool_program = coolprogram) if with_errors: - exit(1) \ No newline at end of file + exit(1) + else: + exit(0) \ No newline at end of file diff --git a/src/program.txt b/src/program.txt index 40d51d688..78259c6dc 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,14 +1,10 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) class Main inherits IO { main(): IO { out_string("Hello World!")}; - a: A; - b: B <- a <- new C; - d: D <- b <- new C; -}; + self: IO <- self; +}; diff --git a/tests/semantic/features1.cl b/tests/semantic/features1.cl index 96dd8ebc6..31823713a 100755 --- a/tests/semantic/features1.cl +++ b/tests/semantic/features1.cl @@ -16,4 +16,4 @@ class A { x(): Int { 3 }; x: String <- ":)"; -}; \ No newline at end of file +}; From bd837098a136b9a35e6dc4446bd0da3c9fc074fd Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 18:01:06 -0300 Subject: [PATCH 31/60] reset testing --- LICENSE | 42 +- Readme.md | 344 +++--- doc/Readme.md | 66 +- doc/team.yml | 18 +- requirements.txt | 4 +- src/Readme.md | 156 +-- src/coolc.sh | 19 +- src/makefile | 24 +- tests/codegen/arith.cl | 860 ++++++------- tests/codegen/arith_input.txt | 26 +- tests/codegen/arith_output.txt | 316 ++--- tests/codegen/atoi_output.txt | 2 +- tests/codegen/book_list.cl | 264 ++-- tests/codegen/book_list_output.txt | 14 +- tests/codegen/cells.cl | 194 +-- tests/codegen/cells_output.txt | 42 +- tests/codegen/complex.cl | 104 +- tests/codegen/complex_output.txt | 2 +- tests/codegen/fib.cl | 58 +- tests/codegen/fib_input.txt | 2 +- tests/codegen/fib_output.txt | 4 +- tests/codegen/graph.cl | 762 ++++++------ tests/codegen/graph_input.txt | 10 +- tests/codegen/graph_output.txt | 14 +- tests/codegen/hairyscary.cl | 134 +- tests/codegen/hello_world.cl | 10 +- tests/codegen/hello_world_output.txt | 2 +- tests/codegen/io.cl | 206 ++-- tests/codegen/io_output.txt | 10 +- tests/codegen/life.cl | 872 ++++++------- tests/codegen/life_input.txt | 130 +- tests/codegen/life_output.txt | 1554 ++++++++++++------------ tests/codegen/list_output.txt | 10 +- tests/codegen/new_complex.cl | 158 +-- tests/codegen/new_complex_output.txt | 4 +- tests/codegen/palindrome.cl | 50 +- tests/codegen/palindrome_input.txt | 2 +- tests/codegen/palindrome_output.txt | 4 +- tests/codegen/primes_output.txt | 192 +-- tests/codegen/print-cool_output.txt | 2 +- tests/codegen/sort-list_input.txt | 2 +- tests/codegen/sort-list_output.txt | 20 +- tests/codegen_test.py | 32 +- tests/conftest.py | 10 +- tests/lexer/comment1.cl | 55 + tests/lexer/comment1_error.txt | 1 + tests/lexer/iis1.cl | 220 ++-- tests/lexer/iis1_error.txt | 2 +- tests/lexer/iis2.cl | 238 ++-- tests/lexer/iis2_error.txt | 2 +- tests/lexer/iis3.cl | 240 ++-- tests/lexer/iis3_error.txt | 2 +- tests/lexer/iis4.cl | 238 ++-- tests/lexer/iis4_error.txt | 2 +- tests/lexer/iis5.cl | 242 ++-- tests/lexer/iis5_error.txt | 4 +- tests/lexer/iis6.cl | 248 ++-- tests/lexer/iis6_error.txt | 2 +- tests/lexer/mixed1.cl | 26 +- tests/lexer/mixed1_error.txt | 2 +- tests/lexer/mixed2.cl | 38 +- tests/lexer/mixed2_error.txt | 6 +- tests/lexer/string1.cl | 10 +- tests/lexer/string1_error.txt | 2 +- tests/lexer/string2.cl | 36 +- tests/lexer/string4.cl | 74 +- tests/lexer/string4_error.txt | 4 +- tests/lexer_test.py | 24 +- tests/parser/assignment1.cl | 72 +- tests/parser/assignment2.cl | 72 +- tests/parser/assignment3.cl | 72 +- tests/parser/attribute1.cl | 66 +- tests/parser/attribute2.cl | 66 +- tests/parser/attribute3.cl | 66 +- tests/parser/block1.cl | 172 +-- tests/parser/block2.cl | 172 +-- tests/parser/block3.cl | 172 +-- tests/parser/block4.cl | 174 +-- tests/parser/case1.cl | 180 +-- tests/parser/case2.cl | 184 +-- tests/parser/case3.cl | 184 +-- tests/parser/case4.cl | 184 +-- tests/parser/case5.cl | 184 +-- tests/parser/case6.cl | 184 +-- tests/parser/class1.cl | 40 +- tests/parser/class2.cl | 40 +- tests/parser/class3.cl | 68 +- tests/parser/class4.cl | 72 +- tests/parser/class5.cl | 68 +- tests/parser/class6.cl | 68 +- tests/parser/conditional1.cl | 136 +-- tests/parser/conditional2.cl | 136 +-- tests/parser/conditional3.cl | 136 +-- tests/parser/conditional4.cl | 144 +-- tests/parser/conditional5.cl | 144 +-- tests/parser/conditional6.cl | 144 +-- tests/parser/dispatch1.cl | 88 +- tests/parser/dispatch2.cl | 88 +- tests/parser/dispatch3.cl | 88 +- tests/parser/dispatch4.cl | 104 +- tests/parser/dispatch5.cl | 104 +- tests/parser/dispatch6.cl | 112 +- tests/parser/dispatch7.cl | 112 +- tests/parser/dispatch8.cl | 112 +- tests/parser/dispatch9.cl | 120 +- tests/parser/let1.cl | 168 +-- tests/parser/let2.cl | 168 +-- tests/parser/let3.cl | 168 +-- tests/parser/let4.cl | 168 +-- tests/parser/let5.cl | 168 +-- tests/parser/let6.cl | 146 +-- tests/parser/let7.cl | 168 +-- tests/parser/loop1.cl | 154 +-- tests/parser/loop2.cl | 154 +-- tests/parser/loop3.cl | 154 +-- tests/parser/loop4.cl | 154 +-- tests/parser/method1.cl | 66 +- tests/parser/method2.cl | 66 +- tests/parser/method3.cl | 66 +- tests/parser/method4.cl | 66 +- tests/parser/method5.cl | 66 +- tests/parser/method6.cl | 64 +- tests/parser/mixed1.cl | 198 +-- tests/parser/mixed2.cl | 28 +- tests/parser/mixed3.cl | 80 +- tests/parser/mixed4.cl | 42 +- tests/parser/mixed5.cl | 40 +- tests/parser/mixed6.cl | 10 +- tests/parser/operation1.cl | 200 +-- tests/parser/operation2.cl | 200 +-- tests/parser/operation3.cl | 200 +-- tests/parser/operation4.cl | 200 +-- tests/parser/program2.cl | 40 +- tests/parser/program3.cl | 48 +- tests/parser_test.py | 24 +- tests/semantic/arithmetic1.cl | 20 +- tests/semantic/arithmetic10.cl | 28 +- tests/semantic/arithmetic11.cl | 26 +- tests/semantic/arithmetic12.cl | 26 +- tests/semantic/arithmetic1_error.txt | 2 +- tests/semantic/arithmetic2.cl | 20 +- tests/semantic/arithmetic2_error.txt | 2 +- tests/semantic/arithmetic3.cl | 20 +- tests/semantic/arithmetic3_error.txt | 2 +- tests/semantic/arithmetic4.cl | 20 +- tests/semantic/arithmetic5.cl | 20 +- tests/semantic/arithmetic5_error.txt | 2 +- tests/semantic/arithmetic6.cl | 22 +- tests/semantic/arithmetic6_error.txt | 2 +- tests/semantic/arithmetic7.cl | 24 +- tests/semantic/arithmetic7_error.txt | 2 +- tests/semantic/arithmetic8.cl | 26 +- tests/semantic/arithmetic8_error.txt | 2 +- tests/semantic/arithmetic9.cl | 28 +- tests/semantic/assignment1.cl | 14 +- tests/semantic/assignment1_error.txt | 2 +- tests/semantic/assignment2.cl | 26 +- tests/semantic/assignment2_error.txt | 2 +- tests/semantic/assignment3.cl | 28 +- tests/semantic/attributes1.cl | 24 +- tests/semantic/attributes1_error.txt | 2 +- tests/semantic/attributes2.cl | 24 +- tests/semantic/attributes2_error.txt | 2 +- tests/semantic/attributes3.cl | 48 +- tests/semantic/attributes3_error.txt | 2 +- tests/semantic/attributes4.cl | 76 +- tests/semantic/basics1.cl | 18 +- tests/semantic/basics1_error.txt | 2 +- tests/semantic/basics2.cl | 18 +- tests/semantic/basics2_error.txt | 2 +- tests/semantic/basics3.cl | 16 +- tests/semantic/basics3_error.txt | 2 +- tests/semantic/basics4.cl | 16 +- tests/semantic/basics4_error.txt | 2 +- tests/semantic/basics5.cl | 16 +- tests/semantic/basics5_error.txt | 2 +- tests/semantic/basics6.cl | 16 +- tests/semantic/basics6_error.txt | 2 +- tests/semantic/basics7.cl | 16 +- tests/semantic/basics7_error.txt | 2 +- tests/semantic/basics8.cl | 16 +- tests/semantic/basics8_error.txt | 2 +- tests/semantic/blocks1.cl | 60 +- tests/semantic/blocks1_error.txt | 2 +- tests/semantic/case1.cl | 46 +- tests/semantic/case1_error.txt | 2 +- tests/semantic/case2.cl | 44 +- tests/semantic/case3.cl | 44 +- tests/semantic/class1.cl | 16 +- tests/semantic/class1_error.txt | 4 +- tests/semantic/conditionals1.cl | 26 +- tests/semantic/conditionals1_error.txt | 2 +- tests/semantic/conditionals2.cl | 48 +- tests/semantic/conditionals2_error.txt | 4 +- tests/semantic/dispatch1.cl | 64 +- tests/semantic/dispatch1_error.txt | 2 +- tests/semantic/dispatch2.cl | 66 +- tests/semantic/dispatch2_error.txt | 2 +- tests/semantic/dispatch3.cl | 70 +- tests/semantic/dispatch3_error.txt | 2 +- tests/semantic/dispatch4.cl | 70 +- tests/semantic/dispatch5.cl | 60 +- tests/semantic/dispatch5_error.txt | 2 +- tests/semantic/dispatch6.cl | 64 +- tests/semantic/dispatch6_error.txt | 2 +- tests/semantic/eq1.cl | 32 +- tests/semantic/eq1_error.txt | 2 +- tests/semantic/eq2.cl | 34 +- tests/semantic/eq2_error.txt | 2 +- tests/semantic/eq3.cl | 34 +- tests/semantic/eq3_error.txt | 2 +- tests/semantic/eq4.cl | 34 +- tests/semantic/eq4_error.txt | 2 +- tests/semantic/features1.cl | 2 +- tests/semantic/isvoid1.cl | 50 +- tests/semantic/isvoid1_error.txt | 2 +- tests/semantic/let1.cl | 28 +- tests/semantic/let1_error.txt | 2 +- tests/semantic/let2.cl | 28 +- tests/semantic/let2_error.txt | 2 +- tests/semantic/let3.cl | 28 +- tests/semantic/loops1.cl | 14 +- tests/semantic/loops2.cl | 18 +- tests/semantic/loops2_error.txt | 2 +- tests/semantic/methods1.cl | 22 +- tests/semantic/methods1_error.txt | 2 +- tests/semantic/methods2.cl | 22 +- tests/semantic/methods2_error.txt | 2 +- tests/semantic/methods3.cl | 26 +- tests/semantic/methods3_error.txt | 2 +- tests/semantic/methods4.cl | 36 +- tests/semantic/methods4_error.txt | 2 +- tests/semantic/methods5.cl | 40 +- tests/semantic/methods5_error.txt | 2 +- tests/semantic/methods6.cl | 52 +- tests/semantic/methods6_error.txt | 2 +- tests/semantic/methods7.cl | 22 +- tests/semantic/methods8.cl | 22 +- tests/semantic/new1.cl | 60 +- tests/semantic/self1.cl | 22 +- tests/semantic/self1_error.txt | 2 +- tests/semantic/self2.cl | 20 +- tests/semantic/self2_error.txt | 2 +- tests/semantic/self3.cl | 20 +- tests/semantic/self3_error.txt | 2 +- tests/semantic/self4.cl | 18 +- tests/semantic/self4_error.txt | 2 +- tests/semantic_test.py | 26 +- tests/utils/utils.py | 182 +-- 249 files changed, 9327 insertions(+), 9266 deletions(-) create mode 100644 tests/lexer/comment1.cl create mode 100644 tests/lexer/comment1_error.txt diff --git a/LICENSE b/LICENSE index 7f19c2d8c..718bd210a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2021 School of Math and Computer Science, University of Havana - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2021 School of Math and Computer Science, University of Havana + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Readme.md b/Readme.md index 0e33ddb08..a47d48b9e 100644 --- a/Readme.md +++ b/Readme.md @@ -1,172 +1,172 @@ -# COOL: Proyecto de Compilación - -> Proyecto base para el compilador de 4to año en Ciencia de la Computación. - -## Generalidades - -La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la -Universidad de La Habana, consiste este curso en la implementación de un compilador completamente -funcional para el lenguaje _COOL_. - -_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. - -## Cómo comenzar (o terminar) - -El proyecto de Compilación será recogido y evaluado **únicamente** a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. A continuación le damos las instrucciones mínimas necesarias para ello: - -### 1. Si no lo han hecho ya, regístrense en [Github](https://github.com) todos los miembros del equipo (es gratis). - -![](img/img1.png) - -### 2. Haga click en el botón **Fork** para hacer una copia del proyecto en el perfil de Github de uno de los miembros. - -Opcionalmente pueden [crear una organización](https://github.com/organizations/new) y copiar el proyecto en el perfil de la misma. - -![](img/img2.png) - -### 3. Una vez hecho esto, tendrá un nuevo repositorio en `github/`. - -Revise que el repositorio de su equipo está en su perfil. -En este ejemplo se ha copiado a la cuenta de `github.com/apiad`. - -Debe indicar bajo el nombre del repositorio: `"forked from matcom/cool-compiler-2021"`. - -![](img/img3.png) - -### 4. Clone este proyecto en un repositorio local. - -Busque la URL de su proyecto en la interfaz web de Github. - -Asegúrese de clonar **su copia** y no el proyecto original en `matcom/cool-compiler-2021`. - -![](img/img4.png) - -```bash -$ git clone git@github.com:/cool-compiler-2021.git -``` - -> Donde `` es posiblemente el nombre de su equipo o del miembro donde se hizo el _fork_. - -A partir de este punto debe tener un proyecto `cool-compiler-2021` local. -El siguiente paso depende de si usted ya tiene su código versionado con `git` o no. - -### 5.A. Si tiene su proyecto en git (y no quiere perder la historia): - -#### 5.1. Mezcle hacia el nuevo respositorio su repositorio anterior: - -```bash -$ cd cool-compiler-2021 -$ git pull --allow-unrelated-histories master -``` - -#### 5.2. Organice su proyecto, código fuente y documentación, de acuerdo a las instrucciones de este documento, y vuelva a hacer `commit`. - -```bash -$ mv src/ -$ git add . -$ git commit -a -m "Mezclado con el proyecto base" -``` - -#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. - -```bash -$ git push origin master -``` - -### 5.B Si aún no tiene su proyecto en git (o no le importa la historia): - -#### 5.1. Simplemente copie el código de su proyecto en la carpeta correspondiente `src` y haga su primer commit. - -```bash -$ mv src/ -$ git commit -a -m "Hello Git!" -``` - -#### 5.2. A partir de este punto asegúrese de hacer `commit` de forma regular para mantener su repositorio actualizado. - -Si necesita saber más sobre `git`, todo lo imprescindible está en [esta guía](doc/github-git-cheat-sheet.pdf). - -#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. - -```bash -$ git push origin master -``` - -## Entregas - -En este proyecto se realizarán entregas parciales a lo largo del curso. Para realizar una entrega, siga los siguientes pasos. - -### 1. Cree un pull request al proyecto original desde su copia. - -![](img/img5.png) - -### 2. Asegúrese de tener la siguiente configuración antes de hacer click en **Create pull request**. - -- **base repository**: `matcom/cool-compiler-2021` (repositorio original) - - **branch**: `master` -- **head repository**: `/cool-compiler-2021` (repositorio propio) - - **branch**: `master` (o la que corresponda) - -> Asegúrese que se indica **Able to merge**. De lo contrario, existen cambios en el repositorio original que usted no tiene, y debe actualizarlos. - -> **NOTA**: Asegúrese que el _pull request_ se hace a la rama `master`. - -![](img/img6.png) - -### 3. Introduzca un título y descripción adecuados, y haga click en **Create pull request**. - -![](img/img7.png) - -### 4. Espere mientras se ejecutan las pruebas. - -Verá la indicación **Some checks haven't completed yet**. - -![](img/img8.png) - -Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje: - -> **This branch is out-of-date with base branch** - -Haga click en **Update branch** y siga las instrucciones. -### 5. Verifique que no hubo errores en las pruebas. - -Si ve el mensaje **(All | Some) checks have failed**, significa que su código no pasó las pruebas. - -![](img/img9.png) - -Para ver los resultados de las pruebas haga click en el link **Details**. - -![](img/img10.png) - - -### 6. Arregle los errores y repita el paso 5 hasta que todas las pruebas pasen. - -Para cualquier modificación que haga a su proyecto, haga _commit_ y _push_ para **su repositorio personal** y automáticamente se actualizará el estado del _pull request_ y se volverán a ejecutar las pruebas. **No es necesario** abrir un _pull request_ nuevo por cada entrega, sino actualizar el anterior. - -> **Por favor asegúrese de mantener un solo _pull request_ activo por equipo**. En caso de abrir uno nuevo, cerrar el anterior. - -## Sobre la implementación - -Ponga todo su código e instrucciones necesarias en la carpeta `src`. Más información en [`src/Readme.md`](src/Readme.md). - -## Sobre la documentación - -Usted debe presentar un reporte escrito documentando el proceso de construcción de su compilador y los detalles más importantes de su funcionamiento. Más información en [`doc/Readme.md`](doc/Readme.md). - -## Sobre los equipos de desarrollo - -Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. - -## Sobre los casos de prueba - -La carpeta `tests` contiene todos los casos de prueba que son obligatorios de pasar para que su proyecto tenga derecho a ser evaluado. - -Estos tests se ejecutan automáticamente cada vez que hace un _pull request_ al repositorio `matcom/cool-compiler-2021`. Solo aquellos proyectos que pasen todas las pruebas con éxito serán evaluados. - -Para ejecutar las pruebas localmente, debe tener instalado `Python 3.7`, `pip` y `make` (normalmente viene con Linux). Ejecute: - -```bash -$ pip install -r requirements.txt -$ cd src -$ make test -``` +# COOL: Proyecto de Compilación + +> Proyecto base para el compilador de 4to año en Ciencia de la Computación. + +## Generalidades + +La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la +Universidad de La Habana, consiste este curso en la implementación de un compilador completamente +funcional para el lenguaje _COOL_. + +_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. + +## Cómo comenzar (o terminar) + +El proyecto de Compilación será recogido y evaluado **únicamente** a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. A continuación le damos las instrucciones mínimas necesarias para ello: + +### 1. Si no lo han hecho ya, regístrense en [Github](https://github.com) todos los miembros del equipo (es gratis). + +![](img/img1.png) + +### 2. Haga click en el botón **Fork** para hacer una copia del proyecto en el perfil de Github de uno de los miembros. + +Opcionalmente pueden [crear una organización](https://github.com/organizations/new) y copiar el proyecto en el perfil de la misma. + +![](img/img2.png) + +### 3. Una vez hecho esto, tendrá un nuevo repositorio en `github/`. + +Revise que el repositorio de su equipo está en su perfil. +En este ejemplo se ha copiado a la cuenta de `github.com/apiad`. + +Debe indicar bajo el nombre del repositorio: `"forked from matcom/cool-compiler-2021"`. + +![](img/img3.png) + +### 4. Clone este proyecto en un repositorio local. + +Busque la URL de su proyecto en la interfaz web de Github. + +Asegúrese de clonar **su copia** y no el proyecto original en `matcom/cool-compiler-2021`. + +![](img/img4.png) + +```bash +$ git clone git@github.com:/cool-compiler-2021.git +``` + +> Donde `` es posiblemente el nombre de su equipo o del miembro donde se hizo el _fork_. + +A partir de este punto debe tener un proyecto `cool-compiler-2021` local. +El siguiente paso depende de si usted ya tiene su código versionado con `git` o no. + +### 5.A. Si tiene su proyecto en git (y no quiere perder la historia): + +#### 5.1. Mezcle hacia el nuevo respositorio su repositorio anterior: + +```bash +$ cd cool-compiler-2021 +$ git pull --allow-unrelated-histories master +``` + +#### 5.2. Organice su proyecto, código fuente y documentación, de acuerdo a las instrucciones de este documento, y vuelva a hacer `commit`. + +```bash +$ mv src/ +$ git add . +$ git commit -a -m "Mezclado con el proyecto base" +``` + +#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. + +```bash +$ git push origin master +``` + +### 5.B Si aún no tiene su proyecto en git (o no le importa la historia): + +#### 5.1. Simplemente copie el código de su proyecto en la carpeta correspondiente `src` y haga su primer commit. + +```bash +$ mv src/ +$ git commit -a -m "Hello Git!" +``` + +#### 5.2. A partir de este punto asegúrese de hacer `commit` de forma regular para mantener su repositorio actualizado. + +Si necesita saber más sobre `git`, todo lo imprescindible está en [esta guía](doc/github-git-cheat-sheet.pdf). + +#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. + +```bash +$ git push origin master +``` + +## Entregas + +En este proyecto se realizarán entregas parciales a lo largo del curso. Para realizar una entrega, siga los siguientes pasos. + +### 1. Cree un pull request al proyecto original desde su copia. + +![](img/img5.png) + +### 2. Asegúrese de tener la siguiente configuración antes de hacer click en **Create pull request**. + +- **base repository**: `matcom/cool-compiler-2021` (repositorio original) + - **branch**: `master` +- **head repository**: `/cool-compiler-2021` (repositorio propio) + - **branch**: `master` (o la que corresponda) + +> Asegúrese que se indica **Able to merge**. De lo contrario, existen cambios en el repositorio original que usted no tiene, y debe actualizarlos. + +> **NOTA**: Asegúrese que el _pull request_ se hace a la rama `master`. + +![](img/img6.png) + +### 3. Introduzca un título y descripción adecuados, y haga click en **Create pull request**. + +![](img/img7.png) + +### 4. Espere mientras se ejecutan las pruebas. + +Verá la indicación **Some checks haven't completed yet**. + +![](img/img8.png) + +Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje: + +> **This branch is out-of-date with base branch** + +Haga click en **Update branch** y siga las instrucciones. +### 5. Verifique que no hubo errores en las pruebas. + +Si ve el mensaje **(All | Some) checks have failed**, significa que su código no pasó las pruebas. + +![](img/img9.png) + +Para ver los resultados de las pruebas haga click en el link **Details**. + +![](img/img10.png) + + +### 6. Arregle los errores y repita el paso 5 hasta que todas las pruebas pasen. + +Para cualquier modificación que haga a su proyecto, haga _commit_ y _push_ para **su repositorio personal** y automáticamente se actualizará el estado del _pull request_ y se volverán a ejecutar las pruebas. **No es necesario** abrir un _pull request_ nuevo por cada entrega, sino actualizar el anterior. + +> **Por favor asegúrese de mantener un solo _pull request_ activo por equipo**. En caso de abrir uno nuevo, cerrar el anterior. + +## Sobre la implementación + +Ponga todo su código e instrucciones necesarias en la carpeta `src`. Más información en [`src/Readme.md`](src/Readme.md). + +## Sobre la documentación + +Usted debe presentar un reporte escrito documentando el proceso de construcción de su compilador y los detalles más importantes de su funcionamiento. Más información en [`doc/Readme.md`](doc/Readme.md). + +## Sobre los equipos de desarrollo + +Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. + +## Sobre los casos de prueba + +La carpeta `tests` contiene todos los casos de prueba que son obligatorios de pasar para que su proyecto tenga derecho a ser evaluado. + +Estos tests se ejecutan automáticamente cada vez que hace un _pull request_ al repositorio `matcom/cool-compiler-2021`. Solo aquellos proyectos que pasen todas las pruebas con éxito serán evaluados. + +Para ejecutar las pruebas localmente, debe tener instalado `Python 3.7`, `pip` y `make` (normalmente viene con Linux). Ejecute: + +```bash +$ pip install -r requirements.txt +$ cd src +$ make test +``` diff --git a/doc/Readme.md b/doc/Readme.md index a7ed0e32d..3b2569f5c 100644 --- a/doc/Readme.md +++ b/doc/Readme.md @@ -1,33 +1,33 @@ -# Documentación - -## Readme - -Modifique el contenido de este documento para documentar de forma clara y concisa los siguientes aspectos: - -- Cómo ejecutar (y compilar si es necesario) su compilador. -- Requisitos adicionales, dependencias, configuración, etc. -- Opciones adicionales que tenga su compilador. - -## Sobre los Equipos de Desarrollo - -Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. El proyecto de Compilación será recogido y evaluado únicamente a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. - -**⚠️ NOTA**: Debe completar el archivo `team.yml` con los datos correctos de cada miembro de su equipo. - -## Sobre los Materiales a Entregar - -Para la evaluación del proyecto Ud. debe entregar un informe en formato PDF (`report.pdf`) en esta carpeta, que resuma de manera organizada y comprensible la arquitectura e implementación de su compilador. -El documento no tiene límite de extensión. -En él explicará en más detalle su solución a los problemas que, durante la implementación de cada una de las fases del proceso de compilación, hayan requerido de Ud. especial atención. - -## Estructura del reporte - -Usted es libre de estructurar su reporte escrito como más conveniente le parezca. A continuación le sugerimos algunas secciones que no deberían faltar, aunque puede mezclar, renombrar y organizarlas de la manera que mejor le parezca: - -- **Uso del compilador**: detalles sobre las opciones de líneas de comando, si tiene opciones adicionales (e.j., `--ast` genera un AST en JSON, etc.). Básicamente lo mismo que pondrá en este Readme. -- **Arquitectura del compilador**: una explicación general de la arquitectura, en cuántos módulos se divide el proyecto, cuantas fases tiene, qué tipo de gramática se utiliza, y en general, como se organiza el proyecto. Una buena imagen siempre ayuda. -- **Problemas técnicos**: detalles sobre cualquier problema teórico o técnico interesante que haya necesitado resolver de forma particular. - -## Sobre la Fecha de Entrega - -Se realizarán recogidas parciales del proyecto a lo largo del curso. En el Canal de Telegram se anunciará la fecha y requisitos de cada entrega. +# Documentación + +## Readme + +Modifique el contenido de este documento para documentar de forma clara y concisa los siguientes aspectos: + +- Cómo ejecutar (y compilar si es necesario) su compilador. +- Requisitos adicionales, dependencias, configuración, etc. +- Opciones adicionales que tenga su compilador. + +## Sobre los Equipos de Desarrollo + +Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. El proyecto de Compilación será recogido y evaluado únicamente a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. + +**⚠️ NOTA**: Debe completar el archivo `team.yml` con los datos correctos de cada miembro de su equipo. + +## Sobre los Materiales a Entregar + +Para la evaluación del proyecto Ud. debe entregar un informe en formato PDF (`report.pdf`) en esta carpeta, que resuma de manera organizada y comprensible la arquitectura e implementación de su compilador. +El documento no tiene límite de extensión. +En él explicará en más detalle su solución a los problemas que, durante la implementación de cada una de las fases del proceso de compilación, hayan requerido de Ud. especial atención. + +## Estructura del reporte + +Usted es libre de estructurar su reporte escrito como más conveniente le parezca. A continuación le sugerimos algunas secciones que no deberían faltar, aunque puede mezclar, renombrar y organizarlas de la manera que mejor le parezca: + +- **Uso del compilador**: detalles sobre las opciones de líneas de comando, si tiene opciones adicionales (e.j., `--ast` genera un AST en JSON, etc.). Básicamente lo mismo que pondrá en este Readme. +- **Arquitectura del compilador**: una explicación general de la arquitectura, en cuántos módulos se divide el proyecto, cuantas fases tiene, qué tipo de gramática se utiliza, y en general, como se organiza el proyecto. Una buena imagen siempre ayuda. +- **Problemas técnicos**: detalles sobre cualquier problema teórico o técnico interesante que haya necesitado resolver de forma particular. + +## Sobre la Fecha de Entrega + +Se realizarán recogidas parciales del proyecto a lo largo del curso. En el Canal de Telegram se anunciará la fecha y requisitos de cada entrega. diff --git a/doc/team.yml b/doc/team.yml index 9c00f520f..c16162532 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -1,8 +1,10 @@ -members: - - name: Luis Alejandro Lara ROjas - github: LuisLara-UH - group: C412 - - name: Carlos Alejandro Arrieta Montes de Oca - github: Carlitonchin - group: C412 -Organization: Los-Mangotes-SA +members: + - name: Nombre Apellido1 Apellido2 + github: github_id + group: CXXX + - name: Nombre Apellido1 Apellido2 + github: github_id + group: CXXX + - name: Nombre Apellido1 Apellido2 + github: github_id + group: CXXX diff --git a/requirements.txt b/requirements.txt index c250faba6..9eb0cad1a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -pytest -pytest-ordering +pytest +pytest-ordering diff --git a/src/Readme.md b/src/Readme.md index cdca282ec..1200371b5 100644 --- a/src/Readme.md +++ b/src/Readme.md @@ -1,78 +1,78 @@ -# COOL: Proyecto de Compilación - -La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la -Universidad de La Habana, consiste este curso en la implementación de un compilador completamente -funcional para el lenguaje _COOL_. - -_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. - -### Sobre el Lenguaje COOL - -Ud. podrá encontrar la especificación formal del lenguaje COOL en el documento _"COOL Language Reference Manual"_, que se distribuye junto con el presente texto. - -## Código Fuente - -### Compilando su proyecto - -Si es necesario compilar su proyecto, incluya todas las instrucciones necesarias en un archivo [`/src/makefile`](/src/makefile). -Durante la evaluación su proyecto se compilará ejecutando la siguiente secuencia: - -```bash -$ cd source -$ make clean -$ make -``` - -### Ejecutando su proyecto - -Incluya en un archivo [`/src/coolc.sh`](/src/coolc.sh) todas las instrucciones que hacen falta para lanzar su compilador. Recibirá como entrada un archivo con extensión `.cl` y debe generar como salida un archivo `.mips` cuyo nombre será el mismo que la entrada. - -Para lanzar el compilador, se ejecutará la siguiente instrucción: - -```bash -$ cd source -$ ./coolc.sh -``` - -### Sobre el Compilador de COOL - -El compilador de COOL se ejecutará como se ha definido anteriormente. -En caso de que no ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código de salida 0, generar (o sobrescribir si ya existe) en la misma carpeta del archivo **.cl** procesado, y con el mismo nombre que éste, un archivo con extension **.mips** que pueda ser ejecutado con **spim**. Además, reportar a la salida estándar solamente lo siguiente: - - - - -En caso de que ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código -de salida (exit code) 1 y reportar a la salida estándar (standard output stream) lo que sigue... - - - - _1 - ... - _n - -... donde `_i` tiene el siguiente formato: - - (,) - : - -Los campos `` y `` indican la ubicación del error en el fichero **.cl** procesado. En caso -de que la naturaleza del error sea tal que no pueda asociárselo a una línea y columna en el archivo de -código fuente, el valor de dichos campos debe ser 0. - -El campo `` será alguno entre: - -- `CompilerError`: se reporta al detectar alguna anomalía con la entrada del compilador. Por ejemplo, si el fichero a compilar no existe. -- `LexicographicError`: errores detectados por el lexer. -- `SyntacticError`: errores detectados por el parser. -- `NameError`: se reporta al referenciar un `identificador` en un ámbito en el que no es visible. -- `TypeError`: se reporta al detectar un problema de tipos. Incluye: - - incompatibilidad de tipos entre `rvalue` y `lvalue`, - - operación no definida entre objetos de ciertos tipos, y - - tipo referenciado pero no definido. -- `AttributeError`: se reporta cuando un atributo o método se referencia pero no está definido. -- `SemanticError`: cualquier otro error semántico. - -### Sobre la Implementación del Compilador de COOL - -El compilador debe estar implementado en `python`. Usted debe utilizar una herramienta generadora de analizadores -lexicográficos y sintácticos. Puede utilizar la que sea de su preferencia. +# COOL: Proyecto de Compilación + +La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la +Universidad de La Habana, consiste este curso en la implementación de un compilador completamente +funcional para el lenguaje _COOL_. + +_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. + +### Sobre el Lenguaje COOL + +Ud. podrá encontrar la especificación formal del lenguaje COOL en el documento _"COOL Language Reference Manual"_, que se distribuye junto con el presente texto. + +## Código Fuente + +### Compilando su proyecto + +Si es necesario compilar su proyecto, incluya todas las instrucciones necesarias en un archivo [`/src/makefile`](/src/makefile). +Durante la evaluación su proyecto se compilará ejecutando la siguiente secuencia: + +```bash +$ cd source +$ make clean +$ make +``` + +### Ejecutando su proyecto + +Incluya en un archivo [`/src/coolc.sh`](/src/coolc.sh) todas las instrucciones que hacen falta para lanzar su compilador. Recibirá como entrada un archivo con extensión `.cl` y debe generar como salida un archivo `.mips` cuyo nombre será el mismo que la entrada. + +Para lanzar el compilador, se ejecutará la siguiente instrucción: + +```bash +$ cd source +$ ./coolc.sh +``` + +### Sobre el Compilador de COOL + +El compilador de COOL se ejecutará como se ha definido anteriormente. +En caso de que no ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código de salida 0, generar (o sobrescribir si ya existe) en la misma carpeta del archivo **.cl** procesado, y con el mismo nombre que éste, un archivo con extension **.mips** que pueda ser ejecutado con **spim**. Además, reportar a la salida estándar solamente lo siguiente: + + + + +En caso de que ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código +de salida (exit code) 1 y reportar a la salida estándar (standard output stream) lo que sigue... + + + + _1 + ... + _n + +... donde `_i` tiene el siguiente formato: + + (,) - : + +Los campos `` y `` indican la ubicación del error en el fichero **.cl** procesado. En caso +de que la naturaleza del error sea tal que no pueda asociárselo a una línea y columna en el archivo de +código fuente, el valor de dichos campos debe ser 0. + +El campo `` será alguno entre: + +- `CompilerError`: se reporta al detectar alguna anomalía con la entrada del compilador. Por ejemplo, si el fichero a compilar no existe. +- `LexicographicError`: errores detectados por el lexer. +- `SyntacticError`: errores detectados por el parser. +- `NameError`: se reporta al referenciar un `identificador` en un ámbito en el que no es visible. +- `TypeError`: se reporta al detectar un problema de tipos. Incluye: + - incompatibilidad de tipos entre `rvalue` y `lvalue`, + - operación no definida entre objetos de ciertos tipos, y + - tipo referenciado pero no definido. +- `AttributeError`: se reporta cuando un atributo o método se referencia pero no está definido. +- `SemanticError`: cualquier otro error semántico. + +### Sobre la Implementación del Compilador de COOL + +El compilador debe estar implementado en `python`. Usted debe utilizar una herramienta generadora de analizadores +lexicográficos y sintácticos. Puede utilizar la que sea de su preferencia. diff --git a/src/coolc.sh b/src/coolc.sh index 6434ab9db..593ab2245 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -1,8 +1,11 @@ -INPUT_FILE=$1 -OUTPUT_FILE=${INPUT_FILE:0: -2}mips - -echo "Cool Compiler v1.0" -echo "Copyright (c) 2022: Luis Lara , Carlos Arrieta" - -# Llamar al compilador -python3 main.py ${INPUT_FILE} +# Incluya aquí las instrucciones necesarias para ejecutar su compilador +# Incluya aquí las instrucciones necesarias para ejecutar su compilador + +INPUT_FILE=$1 +OUTPUT_FILE=${INPUT_FILE:0: -2}mips + +echo "Cool Compiler v0.1" +echo "Copyright (c) 2022: Luis Lara, Carlos Arrieta" + +# Llamar al compilador +python3 main.py ${INPUT_FILE} diff --git a/src/makefile b/src/makefile index cd83fb352..30df993f5 100644 --- a/src/makefile +++ b/src/makefile @@ -1,12 +1,12 @@ -.PHONY: clean - -main: - # Compiling the compiler :) - -clean: - rm -rf build/* - rm -rf ../tests/*/*.mips - -test: - pytest ../tests -v --tb=short -m=${TAG} - +.PHONY: clean + +main: + # Compiling the compiler :) + +clean: + rm -rf build/* + rm -rf ../tests/*/*.mips + +test: + pytest ../tests -v --tb=short -m=${TAG} + diff --git a/tests/codegen/arith.cl b/tests/codegen/arith.cl index 0d9f5dd33..af5951cf7 100755 --- a/tests/codegen/arith.cl +++ b/tests/codegen/arith.cl @@ -1,430 +1,430 @@ -(* - * A contribution from Anne Sheets (sheets@cory) - * - * Tests the arithmetic operations and various other things - *) - -class A { - - var : Int <- 0; - - value() : Int { var }; - - set_var(num : Int) : A{ - { - var <- num; - self; - } - }; - - method1(num : Int) : A { -- same - self - }; - - method2(num1 : Int, num2 : Int) : A { -- plus - (let x : Int in - { - x <- num1 + num2; - (new B).set_var(x); - } - ) - }; - - method3(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new C).set_var(x); - } - ) - }; - - method4(num1 : Int, num2 : Int) : A { -- diff - if num2 < num1 then - (let x : Int in - { - x <- num1 - num2; - (new D).set_var(x); - } - ) - else - (let x : Int in - { - x <- num2 - num1; - (new D).set_var(x); - } - ) - fi - }; - - method5(num : Int) : A { -- factorial - (let x : Int <- 1 in - { - (let y : Int <- 1 in - while y <= num loop - { - x <- x * y; - y <- y + 1; - } - pool - ); - (new E).set_var(x); - } - ) - }; - -}; - -class B inherits A { -- B is a number squared - - method5(num : Int) : A { -- square - (let x : Int in - { - x <- num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class C inherits B { - - method6(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new A).set_var(x); - } - ) - }; - - method5(num : Int) : A { -- cube - (let x : Int in - { - x <- num * num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class D inherits B { - - method7(num : Int) : Bool { -- divisible by 3 - (let x : Int <- num in - if x < 0 then method7(~x) else - if 0 = x then true else - if 1 = x then false else - if 2 = x then false else - method7(x - 3) - fi fi fi fi - ) - }; - -}; - -class E inherits D { - - method6(num : Int) : A { -- division - (let x : Int in - { - x <- num / 8; - (new A).set_var(x); - } - ) - }; - -}; - -(* The following code is from atoi.cl in ~cs164/examples *) - -(* - The class A2I provides integer-to-string and string-to-integer -conversion routines. To use these routines, either inherit them -in the class where needed, have a dummy variable bound to -something of type A2I, or simpl write (new A2I).method(argument). -*) - - -(* - c2i Converts a 1-character string to an integer. Aborts - if the string is not "0" through "9" -*) -class A2I { - - c2i(char : String) : Int { - if char = "0" then 0 else - if char = "1" then 1 else - if char = "2" then 2 else - if char = "3" then 3 else - if char = "4" then 4 else - if char = "5" then 5 else - if char = "6" then 6 else - if char = "7" then 7 else - if char = "8" then 8 else - if char = "9" then 9 else - { abort(); 0; } (* the 0 is needed to satisfy the - typchecker *) - fi fi fi fi fi fi fi fi fi fi - }; - -(* - i2c is the inverse of c2i. -*) - i2c(i : Int) : String { - if i = 0 then "0" else - if i = 1 then "1" else - if i = 2 then "2" else - if i = 3 then "3" else - if i = 4 then "4" else - if i = 5 then "5" else - if i = 6 then "6" else - if i = 7 then "7" else - if i = 8 then "8" else - if i = 9 then "9" else - { abort(); ""; } -- the "" is needed to satisfy the typchecker - fi fi fi fi fi fi fi fi fi fi - }; - -(* - a2i converts an ASCII string into an integer. The empty string -is converted to 0. Signed and unsigned strings are handled. The -method aborts if the string does not represent an integer. Very -long strings of digits produce strange answers because of arithmetic -overflow. - -*) - a2i(s : String) : Int { - if s.length() = 0 then 0 else - if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else - if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else - a2i_aux(s) - fi fi fi - }; - -(* a2i_aux converts the usigned portion of the string. As a - programming example, this method is written iteratively. *) - - - a2i_aux(s : String) : Int { - (let int : Int <- 0 in - { - (let j : Int <- s.length() in - (let i : Int <- 0 in - while i < j loop - { - int <- int * 10 + c2i(s.substr(i,1)); - i <- i + 1; - } - pool - ) - ); - int; - } - ) - }; - -(* i2a converts an integer to a string. Positive and negative - numbers are handled correctly. *) - - i2a(i : Int) : String { - if i = 0 then "0" else - if 0 < i then i2a_aux(i) else - "-".concat(i2a_aux(i * ~1)) - fi fi - }; - -(* i2a_aux is an example using recursion. *) - - i2a_aux(i : Int) : String { - if i = 0 then "" else - (let next : Int <- i / 10 in - i2a_aux(next).concat(i2c(i - next * 10)) - ) - fi - }; - -}; - -class Main inherits IO { - - char : String; - avar : A; - a_var : A; - flag : Bool <- true; - - - menu() : String { - { - out_string("\n\tTo add a number to "); - print(avar); - out_string("...enter a:\n"); - out_string("\tTo negate "); - print(avar); - out_string("...enter b:\n"); - out_string("\tTo find the difference between "); - print(avar); - out_string("and another number...enter c:\n"); - out_string("\tTo find the factorial of "); - print(avar); - out_string("...enter d:\n"); - out_string("\tTo square "); - print(avar); - out_string("...enter e:\n"); - out_string("\tTo cube "); - print(avar); - out_string("...enter f:\n"); - out_string("\tTo find out if "); - print(avar); - out_string("is a multiple of 3...enter g:\n"); - out_string("\tTo divide "); - print(avar); - out_string("by 8...enter h:\n"); - out_string("\tTo get a new number...enter j:\n"); - out_string("\tTo quit...enter q:\n\n"); - in_string(); - } - }; - - prompt() : String { - { - out_string("\n"); - out_string("Please enter a number... "); - in_string(); - } - }; - - get_int() : Int { - { - (let z : A2I <- new A2I in - (let s : String <- prompt() in - z.a2i(s) - ) - ); - } - }; - - is_even(num : Int) : Bool { - (let x : Int <- num in - if x < 0 then is_even(~x) else - if 0 = x then true else - if 1 = x then false else - is_even(x - 2) - fi fi fi - ) - }; - - class_type(var : A) : IO { - case var of - a : A => out_string("Class type is now A\n"); - b : B => out_string("Class type is now B\n"); - c : C => out_string("Class type is now C\n"); - d : D => out_string("Class type is now D\n"); - e : E => out_string("Class type is now E\n"); - o : Object => out_string("Oooops\n"); - esac - }; - - print(var : A) : IO { - (let z : A2I <- new A2I in - { - out_string(z.i2a(var.value())); - out_string(" "); - } - ) - }; - - main() : Object { - { - avar <- (new A); - while flag loop - { - -- avar <- (new A).set_var(get_int()); - out_string("number "); - print(avar); - if is_even(avar.value()) then - out_string("is even!\n") - else - out_string("is odd!\n") - fi; - -- print(avar); -- prints out answer - class_type(avar); - char <- menu(); - if char = "a" then -- add - { - a_var <- (new A).set_var(get_int()); - avar <- (new B).method2(avar.value(), a_var.value()); - } else - if char = "b" then -- negate - case avar of - c : C => avar <- c.method6(c.value()); - a : A => avar <- a.method3(a.value()); - o : Object => { - out_string("Oooops\n"); - abort(); 0; - }; - esac else - if char = "c" then -- diff - { - a_var <- (new A).set_var(get_int()); - avar <- (new D).method4(avar.value(), a_var.value()); - } else - if char = "d" then avar <- (new C)@A.method5(avar.value()) else - -- factorial - if char = "e" then avar <- (new C)@B.method5(avar.value()) else - -- square - if char = "f" then avar <- (new C)@C.method5(avar.value()) else - -- cube - if char = "g" then -- multiple of 3? - if ((new D).method7(avar.value())) - then -- avar <- (new A).method1(avar.value()) - { - out_string("number "); - print(avar); - out_string("is divisible by 3.\n"); - } - else -- avar <- (new A).set_var(0) - { - out_string("number "); - print(avar); - out_string("is not divisible by 3.\n"); - } - fi else - if char = "h" then - (let x : A in - { - x <- (new E).method6(avar.value()); - (let r : Int <- (avar.value() - (x.value() * 8)) in - { - out_string("number "); - print(avar); - out_string("is equal to "); - print(x); - out_string("times 8 with a remainder of "); - (let a : A2I <- new A2I in - { - out_string(a.i2a(r)); - out_string("\n"); - } - ); -- end let a: - } - ); -- end let r: - avar <- x; - } - ) -- end let x: - else - if char = "j" then avar <- (new A) - else - if char = "q" then flag <- false - else - avar <- (new A).method1(avar.value()) -- divide/8 - fi fi fi fi fi fi fi fi fi fi; - } - pool; - } - }; - -}; - +(* + * A contribution from Anne Sheets (sheets@cory) + * + * Tests the arithmetic operations and various other things + *) + +class A { + + var : Int <- 0; + + value() : Int { var }; + + set_var(num : Int) : A{ + { + var <- num; + self; + } + }; + + method1(num : Int) : A { -- same + self + }; + + method2(num1 : Int, num2 : Int) : A { -- plus + (let x : Int in + { + x <- num1 + num2; + (new B).set_var(x); + } + ) + }; + + method3(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new C).set_var(x); + } + ) + }; + + method4(num1 : Int, num2 : Int) : A { -- diff + if num2 < num1 then + (let x : Int in + { + x <- num1 - num2; + (new D).set_var(x); + } + ) + else + (let x : Int in + { + x <- num2 - num1; + (new D).set_var(x); + } + ) + fi + }; + + method5(num : Int) : A { -- factorial + (let x : Int <- 1 in + { + (let y : Int <- 1 in + while y <= num loop + { + x <- x * y; + y <- y + 1; + } + pool + ); + (new E).set_var(x); + } + ) + }; + +}; + +class B inherits A { -- B is a number squared + + method5(num : Int) : A { -- square + (let x : Int in + { + x <- num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class C inherits B { + + method6(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new A).set_var(x); + } + ) + }; + + method5(num : Int) : A { -- cube + (let x : Int in + { + x <- num * num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class D inherits B { + + method7(num : Int) : Bool { -- divisible by 3 + (let x : Int <- num in + if x < 0 then method7(~x) else + if 0 = x then true else + if 1 = x then false else + if 2 = x then false else + method7(x - 3) + fi fi fi fi + ) + }; + +}; + +class E inherits D { + + method6(num : Int) : A { -- division + (let x : Int in + { + x <- num / 8; + (new A).set_var(x); + } + ) + }; + +}; + +(* The following code is from atoi.cl in ~cs164/examples *) + +(* + The class A2I provides integer-to-string and string-to-integer +conversion routines. To use these routines, either inherit them +in the class where needed, have a dummy variable bound to +something of type A2I, or simpl write (new A2I).method(argument). +*) + + +(* + c2i Converts a 1-character string to an integer. Aborts + if the string is not "0" through "9" +*) +class A2I { + + c2i(char : String) : Int { + if char = "0" then 0 else + if char = "1" then 1 else + if char = "2" then 2 else + if char = "3" then 3 else + if char = "4" then 4 else + if char = "5" then 5 else + if char = "6" then 6 else + if char = "7" then 7 else + if char = "8" then 8 else + if char = "9" then 9 else + { abort(); 0; } (* the 0 is needed to satisfy the + typchecker *) + fi fi fi fi fi fi fi fi fi fi + }; + +(* + i2c is the inverse of c2i. +*) + i2c(i : Int) : String { + if i = 0 then "0" else + if i = 1 then "1" else + if i = 2 then "2" else + if i = 3 then "3" else + if i = 4 then "4" else + if i = 5 then "5" else + if i = 6 then "6" else + if i = 7 then "7" else + if i = 8 then "8" else + if i = 9 then "9" else + { abort(); ""; } -- the "" is needed to satisfy the typchecker + fi fi fi fi fi fi fi fi fi fi + }; + +(* + a2i converts an ASCII string into an integer. The empty string +is converted to 0. Signed and unsigned strings are handled. The +method aborts if the string does not represent an integer. Very +long strings of digits produce strange answers because of arithmetic +overflow. + +*) + a2i(s : String) : Int { + if s.length() = 0 then 0 else + if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else + if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else + a2i_aux(s) + fi fi fi + }; + +(* a2i_aux converts the usigned portion of the string. As a + programming example, this method is written iteratively. *) + + + a2i_aux(s : String) : Int { + (let int : Int <- 0 in + { + (let j : Int <- s.length() in + (let i : Int <- 0 in + while i < j loop + { + int <- int * 10 + c2i(s.substr(i,1)); + i <- i + 1; + } + pool + ) + ); + int; + } + ) + }; + +(* i2a converts an integer to a string. Positive and negative + numbers are handled correctly. *) + + i2a(i : Int) : String { + if i = 0 then "0" else + if 0 < i then i2a_aux(i) else + "-".concat(i2a_aux(i * ~1)) + fi fi + }; + +(* i2a_aux is an example using recursion. *) + + i2a_aux(i : Int) : String { + if i = 0 then "" else + (let next : Int <- i / 10 in + i2a_aux(next).concat(i2c(i - next * 10)) + ) + fi + }; + +}; + +class Main inherits IO { + + char : String; + avar : A; + a_var : A; + flag : Bool <- true; + + + menu() : String { + { + out_string("\n\tTo add a number to "); + print(avar); + out_string("...enter a:\n"); + out_string("\tTo negate "); + print(avar); + out_string("...enter b:\n"); + out_string("\tTo find the difference between "); + print(avar); + out_string("and another number...enter c:\n"); + out_string("\tTo find the factorial of "); + print(avar); + out_string("...enter d:\n"); + out_string("\tTo square "); + print(avar); + out_string("...enter e:\n"); + out_string("\tTo cube "); + print(avar); + out_string("...enter f:\n"); + out_string("\tTo find out if "); + print(avar); + out_string("is a multiple of 3...enter g:\n"); + out_string("\tTo divide "); + print(avar); + out_string("by 8...enter h:\n"); + out_string("\tTo get a new number...enter j:\n"); + out_string("\tTo quit...enter q:\n\n"); + in_string(); + } + }; + + prompt() : String { + { + out_string("\n"); + out_string("Please enter a number... "); + in_string(); + } + }; + + get_int() : Int { + { + (let z : A2I <- new A2I in + (let s : String <- prompt() in + z.a2i(s) + ) + ); + } + }; + + is_even(num : Int) : Bool { + (let x : Int <- num in + if x < 0 then is_even(~x) else + if 0 = x then true else + if 1 = x then false else + is_even(x - 2) + fi fi fi + ) + }; + + class_type(var : A) : IO { + case var of + a : A => out_string("Class type is now A\n"); + b : B => out_string("Class type is now B\n"); + c : C => out_string("Class type is now C\n"); + d : D => out_string("Class type is now D\n"); + e : E => out_string("Class type is now E\n"); + o : Object => out_string("Oooops\n"); + esac + }; + + print(var : A) : IO { + (let z : A2I <- new A2I in + { + out_string(z.i2a(var.value())); + out_string(" "); + } + ) + }; + + main() : Object { + { + avar <- (new A); + while flag loop + { + -- avar <- (new A).set_var(get_int()); + out_string("number "); + print(avar); + if is_even(avar.value()) then + out_string("is even!\n") + else + out_string("is odd!\n") + fi; + -- print(avar); -- prints out answer + class_type(avar); + char <- menu(); + if char = "a" then -- add + { + a_var <- (new A).set_var(get_int()); + avar <- (new B).method2(avar.value(), a_var.value()); + } else + if char = "b" then -- negate + case avar of + c : C => avar <- c.method6(c.value()); + a : A => avar <- a.method3(a.value()); + o : Object => { + out_string("Oooops\n"); + abort(); 0; + }; + esac else + if char = "c" then -- diff + { + a_var <- (new A).set_var(get_int()); + avar <- (new D).method4(avar.value(), a_var.value()); + } else + if char = "d" then avar <- (new C)@A.method5(avar.value()) else + -- factorial + if char = "e" then avar <- (new C)@B.method5(avar.value()) else + -- square + if char = "f" then avar <- (new C)@C.method5(avar.value()) else + -- cube + if char = "g" then -- multiple of 3? + if ((new D).method7(avar.value())) + then -- avar <- (new A).method1(avar.value()) + { + out_string("number "); + print(avar); + out_string("is divisible by 3.\n"); + } + else -- avar <- (new A).set_var(0) + { + out_string("number "); + print(avar); + out_string("is not divisible by 3.\n"); + } + fi else + if char = "h" then + (let x : A in + { + x <- (new E).method6(avar.value()); + (let r : Int <- (avar.value() - (x.value() * 8)) in + { + out_string("number "); + print(avar); + out_string("is equal to "); + print(x); + out_string("times 8 with a remainder of "); + (let a : A2I <- new A2I in + { + out_string(a.i2a(r)); + out_string("\n"); + } + ); -- end let a: + } + ); -- end let r: + avar <- x; + } + ) -- end let x: + else + if char = "j" then avar <- (new A) + else + if char = "q" then flag <- false + else + avar <- (new A).method1(avar.value()) -- divide/8 + fi fi fi fi fi fi fi fi fi fi; + } + pool; + } + }; + +}; + diff --git a/tests/codegen/arith_input.txt b/tests/codegen/arith_input.txt index c431a225b..83e05b1ea 100644 --- a/tests/codegen/arith_input.txt +++ b/tests/codegen/arith_input.txt @@ -1,13 +1,13 @@ -a -1 -b -c -0 -d -e -f -g -h -j -5 -q +a +1 +b +c +0 +d +e +f +g +h +j +5 +q diff --git a/tests/codegen/arith_output.txt b/tests/codegen/arith_output.txt index 476cb3bad..44b4ce73e 100644 --- a/tests/codegen/arith_output.txt +++ b/tests/codegen/arith_output.txt @@ -1,158 +1,158 @@ -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now B - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number -1 is odd! -Class type is now C - - To add a number to -1 ...enter a: - To negate -1 ...enter b: - To find the difference between -1 and another number...enter c: - To find the factorial of -1 ...enter d: - To square -1 ...enter e: - To cube -1 ...enter f: - To find out if -1 is a multiple of 3...enter g: - To divide -1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now D - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is not divisible by 3. -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is equal to 0 times 8 with a remainder of 1 -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now B + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number -1 is odd! +Class type is now C + + To add a number to -1 ...enter a: + To negate -1 ...enter b: + To find the difference between -1 and another number...enter c: + To find the factorial of -1 ...enter d: + To square -1 ...enter e: + To cube -1 ...enter f: + To find out if -1 is a multiple of 3...enter g: + To divide -1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now D + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is not divisible by 3. +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is equal to 0 times 8 with a remainder of 1 +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + diff --git a/tests/codegen/atoi_output.txt b/tests/codegen/atoi_output.txt index c51d7bad6..51b815a48 100644 --- a/tests/codegen/atoi_output.txt +++ b/tests/codegen/atoi_output.txt @@ -1 +1 @@ -678987 == 678987 +678987 == 678987 diff --git a/tests/codegen/book_list.cl b/tests/codegen/book_list.cl index d39f86bbe..025ea1695 100755 --- a/tests/codegen/book_list.cl +++ b/tests/codegen/book_list.cl @@ -1,132 +1,132 @@ --- example of static and dynamic type differing for a dispatch - -Class Book inherits IO { - title : String; - author : String; - - initBook(title_p : String, author_p : String) : Book { - { - title <- title_p; - author <- author_p; - self; - } - }; - - print() : Book { - { - out_string("title: ").out_string(title).out_string("\n"); - out_string("author: ").out_string(author).out_string("\n"); - self; - } - }; -}; - -Class Article inherits Book { - per_title : String; - - initArticle(title_p : String, author_p : String, - per_title_p : String) : Article { - { - initBook(title_p, author_p); - per_title <- per_title_p; - self; - } - }; - - print() : Book { - { - self@Book.print(); - out_string("periodical: ").out_string(per_title).out_string("\n"); - self; - } - }; -}; - -Class BookList inherits IO { - (* Since abort "returns" type Object, we have to add - an expression of type Bool here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - isNil() : Bool { { abort(); true; } }; - - cons(hd : Book) : Cons { - (let new_cell : Cons <- new Cons in - new_cell.init(hd,self) - ) - }; - - (* Since abort "returns" type Object, we have to add - an expression of type Book here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - car() : Book { { abort(); new Book; } }; - - (* Since abort "returns" type Object, we have to add - an expression of type BookList here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - cdr() : BookList { { abort(); new BookList; } }; - - print_list() : Object { abort() }; -}; - -Class Cons inherits BookList { - xcar : Book; -- We keep the car and cdr in attributes. - xcdr : BookList; -- Because methods and features must have different names, - -- we use xcar and xcdr for the attributes and reserve - -- car and cdr for the features. - - isNil() : Bool { false }; - - init(hd : Book, tl : BookList) : Cons { - { - xcar <- hd; - xcdr <- tl; - self; - } - }; - - car() : Book { xcar }; - - cdr() : BookList { xcdr }; - - print_list() : Object { - { - case xcar.print() of - dummy : Book => out_string("- dynamic type was Book -\n"); - dummy : Article => out_string("- dynamic type was Article -\n"); - esac; - xcdr.print_list(); - } - }; -}; - -Class Nil inherits BookList { - isNil() : Bool { true }; - - print_list() : Object { true }; -}; - - -Class Main { - - books : BookList; - - main() : Object { - (let a_book : Book <- - (new Book).initBook("Compilers, Principles, Techniques, and Tools", - "Aho, Sethi, and Ullman") - in - (let an_article : Article <- - (new Article).initArticle("The Top 100 CD_ROMs", - "Ulanoff", - "PC Magazine") - in - { - books <- (new Nil).cons(a_book).cons(an_article); - books.print_list(); - } - ) -- end let an_article - ) -- end let a_book - }; -}; +-- example of static and dynamic type differing for a dispatch + +Class Book inherits IO { + title : String; + author : String; + + initBook(title_p : String, author_p : String) : Book { + { + title <- title_p; + author <- author_p; + self; + } + }; + + print() : Book { + { + out_string("title: ").out_string(title).out_string("\n"); + out_string("author: ").out_string(author).out_string("\n"); + self; + } + }; +}; + +Class Article inherits Book { + per_title : String; + + initArticle(title_p : String, author_p : String, + per_title_p : String) : Article { + { + initBook(title_p, author_p); + per_title <- per_title_p; + self; + } + }; + + print() : Book { + { + self@Book.print(); + out_string("periodical: ").out_string(per_title).out_string("\n"); + self; + } + }; +}; + +Class BookList inherits IO { + (* Since abort "returns" type Object, we have to add + an expression of type Bool here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + isNil() : Bool { { abort(); true; } }; + + cons(hd : Book) : Cons { + (let new_cell : Cons <- new Cons in + new_cell.init(hd,self) + ) + }; + + (* Since abort "returns" type Object, we have to add + an expression of type Book here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + car() : Book { { abort(); new Book; } }; + + (* Since abort "returns" type Object, we have to add + an expression of type BookList here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + cdr() : BookList { { abort(); new BookList; } }; + + print_list() : Object { abort() }; +}; + +Class Cons inherits BookList { + xcar : Book; -- We keep the car and cdr in attributes. + xcdr : BookList; -- Because methods and features must have different names, + -- we use xcar and xcdr for the attributes and reserve + -- car and cdr for the features. + + isNil() : Bool { false }; + + init(hd : Book, tl : BookList) : Cons { + { + xcar <- hd; + xcdr <- tl; + self; + } + }; + + car() : Book { xcar }; + + cdr() : BookList { xcdr }; + + print_list() : Object { + { + case xcar.print() of + dummy : Book => out_string("- dynamic type was Book -\n"); + dummy : Article => out_string("- dynamic type was Article -\n"); + esac; + xcdr.print_list(); + } + }; +}; + +Class Nil inherits BookList { + isNil() : Bool { true }; + + print_list() : Object { true }; +}; + + +Class Main { + + books : BookList; + + main() : Object { + (let a_book : Book <- + (new Book).initBook("Compilers, Principles, Techniques, and Tools", + "Aho, Sethi, and Ullman") + in + (let an_article : Article <- + (new Article).initArticle("The Top 100 CD_ROMs", + "Ulanoff", + "PC Magazine") + in + { + books <- (new Nil).cons(a_book).cons(an_article); + books.print_list(); + } + ) -- end let an_article + ) -- end let a_book + }; +}; diff --git a/tests/codegen/book_list_output.txt b/tests/codegen/book_list_output.txt index ced587a4f..3408320b2 100644 --- a/tests/codegen/book_list_output.txt +++ b/tests/codegen/book_list_output.txt @@ -1,7 +1,7 @@ -title: The Top 100 CD_ROMs -author: Ulanoff -periodical: PC Magazine -- dynamic type was Article - -title: Compilers, Principles, Techniques, and Tools -author: Aho, Sethi, and Ullman -- dynamic type was Book - +title: The Top 100 CD_ROMs +author: Ulanoff +periodical: PC Magazine +- dynamic type was Article - +title: Compilers, Principles, Techniques, and Tools +author: Aho, Sethi, and Ullman +- dynamic type was Book - diff --git a/tests/codegen/cells.cl b/tests/codegen/cells.cl index bcd891498..9fd6741bb 100755 --- a/tests/codegen/cells.cl +++ b/tests/codegen/cells.cl @@ -1,97 +1,97 @@ -(* models one-dimensional cellular automaton on a circle of finite radius - arrays are faked as Strings, - X's respresent live cells, dots represent dead cells, - no error checking is done *) -class CellularAutomaton inherits IO { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - self; - } - }; - - print() : CellularAutomaton { - { - out_string(population_map.concat("\n")); - self; - } - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - population_map.substr(position, 1) - }; - - cell_left_neighbor(position : Int) : String { - if position = 0 then - cell(num_cells() - 1) - else - cell(position - 1) - fi - }; - - cell_right_neighbor(position : Int) : String { - if position = num_cells() - 1 then - cell(0) - else - cell(position + 1) - fi - }; - - (* a cell will live if exactly 1 of itself and it's immediate - neighbors are alive *) - cell_at_next_evolution(position : Int) : String { - if (if cell(position) = "X" then 1 else 0 fi - + if cell_left_neighbor(position) = "X" then 1 else 0 fi - + if cell_right_neighbor(position) = "X" then 1 else 0 fi - = 1) - then - "X" - else - "." - fi - }; - - evolve() : CellularAutomaton { - (let position : Int in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; -}; - -class Main { - cells : CellularAutomaton; - - main() : Main { - { - cells <- (new CellularAutomaton).init(" X "); - cells.print(); - (let countdown : Int <- 20 in - while 0 < countdown loop - { - cells.evolve(); - cells.print(); - countdown <- countdown - 1; - } - pool - ); - self; - } - }; -}; +(* models one-dimensional cellular automaton on a circle of finite radius + arrays are faked as Strings, + X's respresent live cells, dots represent dead cells, + no error checking is done *) +class CellularAutomaton inherits IO { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + self; + } + }; + + print() : CellularAutomaton { + { + out_string(population_map.concat("\n")); + self; + } + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + population_map.substr(position, 1) + }; + + cell_left_neighbor(position : Int) : String { + if position = 0 then + cell(num_cells() - 1) + else + cell(position - 1) + fi + }; + + cell_right_neighbor(position : Int) : String { + if position = num_cells() - 1 then + cell(0) + else + cell(position + 1) + fi + }; + + (* a cell will live if exactly 1 of itself and it's immediate + neighbors are alive *) + cell_at_next_evolution(position : Int) : String { + if (if cell(position) = "X" then 1 else 0 fi + + if cell_left_neighbor(position) = "X" then 1 else 0 fi + + if cell_right_neighbor(position) = "X" then 1 else 0 fi + = 1) + then + "X" + else + "." + fi + }; + + evolve() : CellularAutomaton { + (let position : Int in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; +}; + +class Main { + cells : CellularAutomaton; + + main() : Main { + { + cells <- (new CellularAutomaton).init(" X "); + cells.print(); + (let countdown : Int <- 20 in + while 0 < countdown loop + { + cells.evolve(); + cells.print(); + countdown <- countdown - 1; + } + pool + ); + self; + } + }; +}; diff --git a/tests/codegen/cells_output.txt b/tests/codegen/cells_output.txt index 9d06c27bc..6304902cc 100644 --- a/tests/codegen/cells_output.txt +++ b/tests/codegen/cells_output.txt @@ -1,21 +1,21 @@ - X -........XXX........ -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. -XXX.............XXX -...X...........X... -..XXX.........XXX.. -.X...X.......X...X. -XXX.XXX.....XXX.XXX -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. + X +........XXX........ +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. +XXX.............XXX +...X...........X... +..XXX.........XXX.. +.X...X.......X...X. +XXX.XXX.....XXX.XXX +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. diff --git a/tests/codegen/complex.cl b/tests/codegen/complex.cl index 9edb6151d..0b7aa44e9 100755 --- a/tests/codegen/complex.cl +++ b/tests/codegen/complex.cl @@ -1,52 +1,52 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - if c.reflect_X().reflect_Y() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; -}; +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + if c.reflect_X().reflect_Y() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; +}; diff --git a/tests/codegen/complex_output.txt b/tests/codegen/complex_output.txt index 7d6173685..18b77c1fc 100644 --- a/tests/codegen/complex_output.txt +++ b/tests/codegen/complex_output.txt @@ -1 +1 @@ -=) +=) diff --git a/tests/codegen/fib.cl b/tests/codegen/fib.cl index ced8cee48..08ceaede8 100644 --- a/tests/codegen/fib.cl +++ b/tests/codegen/fib.cl @@ -1,29 +1,29 @@ -class Main inherits IO { - -- the class has features. Only methods in this case. - main(): Object { - { - out_string("Enter n to find nth fibonacci number!\n"); - out_int(fib(in_int())); - out_string("\n"); - } - }; - - fib(i : Int) : Int { -- list of formals. And the return type of the method. - let a : Int <- 1, - b : Int <- 0, - c : Int <- 0 - in - { - while (not (i = 0)) loop -- expressions are nested. - { - c <- a + b; - i <- i - 1; - b <- a; - a <- c; - } - pool; - c; - } - }; - -}; +class Main inherits IO { + -- the class has features. Only methods in this case. + main(): Object { + { + out_string("Enter n to find nth fibonacci number!\n"); + out_int(fib(in_int())); + out_string("\n"); + } + }; + + fib(i : Int) : Int { -- list of formals. And the return type of the method. + let a : Int <- 1, + b : Int <- 0, + c : Int <- 0 + in + { + while (not (i = 0)) loop -- expressions are nested. + { + c <- a + b; + i <- i - 1; + b <- a; + a <- c; + } + pool; + c; + } + }; + +}; diff --git a/tests/codegen/fib_input.txt b/tests/codegen/fib_input.txt index d43401489..f599e28b8 100644 --- a/tests/codegen/fib_input.txt +++ b/tests/codegen/fib_input.txt @@ -1 +1 @@ -10 +10 diff --git a/tests/codegen/fib_output.txt b/tests/codegen/fib_output.txt index 2552f4479..d402da6af 100644 --- a/tests/codegen/fib_output.txt +++ b/tests/codegen/fib_output.txt @@ -1,2 +1,2 @@ -Enter n to find nth fibonacci number! -89 +Enter n to find nth fibonacci number! +89 diff --git a/tests/codegen/graph.cl b/tests/codegen/graph.cl index 59e29bbf4..8e511358c 100755 --- a/tests/codegen/graph.cl +++ b/tests/codegen/graph.cl @@ -1,381 +1,381 @@ -(* - * Cool program reading descriptions of weighted directed graphs - * from stdin. It builds up a graph objects with a list of vertices - * and a list of edges. Every vertice has a list of outgoing edges. - * - * INPUT FORMAT - * Every line has the form vertice successor* - * Where vertice is an int, and successor is vertice,weight - * - * An empty line or EOF terminates the input. - * - * The list of vertices and the edge list is printed out by the Main - * class. - * - * TEST - * Once compiled, the file g1.graph can be fed to the program. - * The output should look like this: - -nautilus.CS.Berkeley.EDU 53# spim -file graph.s (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - b : Int <- a.doh() + g.doh() + doh() + printh(); - - doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; - -}; - -class Bar inherits Razz { - - c : Int <- doh(); - - d : Object <- printh(); -}; - - -class Razz inherits Foo { - - e : Bar <- case self of - n : Razz => (new Bar); - n : Bar => n; - esac; - - f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); - -}; - -class Bazz inherits IO { - - h : Int <- 1; - - g : Foo <- case self of - n : Bazz => (new Foo); - n : Razz => (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - i : Object <- printh(); - - printh() : Int { { out_int(h); 0; } }; - - doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; -}; - -(* scary . . . *) -class Main { - a : Bazz <- new Bazz; - b : Foo <- new Foo; - c : Razz <- new Razz; - d : Bar <- new Bar; - - main(): String { "do nothing" }; - -}; - - - - - +(* hairy . . .*) + +class Foo inherits Bazz { + a : Razz <- case self of + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + b : Int <- a.doh() + g.doh() + doh() + printh(); + + doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; + +}; + +class Bar inherits Razz { + + c : Int <- doh(); + + d : Object <- printh(); +}; + + +class Razz inherits Foo { + + e : Bar <- case self of + n : Razz => (new Bar); + n : Bar => n; + esac; + + f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); + +}; + +class Bazz inherits IO { + + h : Int <- 1; + + g : Foo <- case self of + n : Bazz => (new Foo); + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + i : Object <- printh(); + + printh() : Int { { out_int(h); 0; } }; + + doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; +}; + +(* scary . . . *) +class Main { + a : Bazz <- new Bazz; + b : Foo <- new Foo; + c : Razz <- new Razz; + d : Bar <- new Bar; + + main(): String { "do nothing" }; + +}; + + + + + diff --git a/tests/codegen/hello_world.cl b/tests/codegen/hello_world.cl index b0a180a2e..0c818f908 100755 --- a/tests/codegen/hello_world.cl +++ b/tests/codegen/hello_world.cl @@ -1,5 +1,5 @@ -class Main inherits IO { - main(): IO { - out_string("Hello, World.\n") - }; -}; +class Main inherits IO { + main(): IO { + out_string("Hello, World.\n") + }; +}; diff --git a/tests/codegen/hello_world_output.txt b/tests/codegen/hello_world_output.txt index 9c1c7a002..349db2bfe 100644 --- a/tests/codegen/hello_world_output.txt +++ b/tests/codegen/hello_world_output.txt @@ -1 +1 @@ -Hello, World. +Hello, World. diff --git a/tests/codegen/io.cl b/tests/codegen/io.cl index 42ee6854e..7f0de869e 100755 --- a/tests/codegen/io.cl +++ b/tests/codegen/io.cl @@ -1,103 +1,103 @@ -(* - * The IO class is predefined and has 4 methods: - * - * out_string(s : String) : SELF_TYPE - * out_int(i : Int) : SELF_TYPE - * in_string() : String - * in_int() : Int - * - * The out operations print their argument to the terminal. The - * in_string method reads an entire line from the terminal and returns a - * string not containing the new line. The in_int method also reads - * an entire line from the terminal and returns the integer - * corresponding to the first non blank word on the line. If that - * word is not an integer, it returns 0. - * - * - * Because our language is object oriented, we need an object of type - * IO in order to call any of these methods. - * - * There are basically two ways of getting access to IO in a class C. - * - * 1) Define C to Inherit from IO. This way the IO methods become - * methods of C, and they can be called using the abbreviated - * dispatch, i.e. - * - * class C inherits IO is - * ... - * out_string("Hello world\n") - * ... - * end; - * - * 2) If your class C does not directly or indirectly inherit from - * IO, the best way to access IO is through an initialized - * attribute of type IO. - * - * class C inherits Foo is - * io : IO <- new IO; - * ... - * io.out_string("Hello world\n"); - * ... - * end; - * - * Approach 1) is most often used, in particular when you need IO - * functions in the Main class. - * - *) - - -class A { - - -- Let's assume that we don't want A to not inherit from IO. - - io : IO <- new IO; - - out_a() : Object { io.out_string("A: Hello world\n") }; - -}; - - -class B inherits A { - - -- B does not have to an extra attribute, since it inherits io from A. - - out_b() : Object { io.out_string("B: Hello world\n") }; - -}; - - -class C inherits IO { - - -- Now the IO methods are part of C. - - out_c() : Object { out_string("C: Hello world\n") }; - - -- Note that out_string(...) is just a shorthand for self.out_string(...) - -}; - - -class D inherits C { - - -- Inherits IO methods from C. - - out_d() : Object { out_string("D: Hello world\n") }; - -}; - - -class Main inherits IO { - - -- Same case as class C. - - main() : Object { - { - (new A).out_a(); - (new B).out_b(); - (new C).out_c(); - (new D).out_d(); - out_string("Done.\n"); - } - }; - -}; +(* + * The IO class is predefined and has 4 methods: + * + * out_string(s : String) : SELF_TYPE + * out_int(i : Int) : SELF_TYPE + * in_string() : String + * in_int() : Int + * + * The out operations print their argument to the terminal. The + * in_string method reads an entire line from the terminal and returns a + * string not containing the new line. The in_int method also reads + * an entire line from the terminal and returns the integer + * corresponding to the first non blank word on the line. If that + * word is not an integer, it returns 0. + * + * + * Because our language is object oriented, we need an object of type + * IO in order to call any of these methods. + * + * There are basically two ways of getting access to IO in a class C. + * + * 1) Define C to Inherit from IO. This way the IO methods become + * methods of C, and they can be called using the abbreviated + * dispatch, i.e. + * + * class C inherits IO is + * ... + * out_string("Hello world\n") + * ... + * end; + * + * 2) If your class C does not directly or indirectly inherit from + * IO, the best way to access IO is through an initialized + * attribute of type IO. + * + * class C inherits Foo is + * io : IO <- new IO; + * ... + * io.out_string("Hello world\n"); + * ... + * end; + * + * Approach 1) is most often used, in particular when you need IO + * functions in the Main class. + * + *) + + +class A { + + -- Let's assume that we don't want A to not inherit from IO. + + io : IO <- new IO; + + out_a() : Object { io.out_string("A: Hello world\n") }; + +}; + + +class B inherits A { + + -- B does not have to an extra attribute, since it inherits io from A. + + out_b() : Object { io.out_string("B: Hello world\n") }; + +}; + + +class C inherits IO { + + -- Now the IO methods are part of C. + + out_c() : Object { out_string("C: Hello world\n") }; + + -- Note that out_string(...) is just a shorthand for self.out_string(...) + +}; + + +class D inherits C { + + -- Inherits IO methods from C. + + out_d() : Object { out_string("D: Hello world\n") }; + +}; + + +class Main inherits IO { + + -- Same case as class C. + + main() : Object { + { + (new A).out_a(); + (new B).out_b(); + (new C).out_c(); + (new D).out_d(); + out_string("Done.\n"); + } + }; + +}; diff --git a/tests/codegen/io_output.txt b/tests/codegen/io_output.txt index 870cffce6..f846f596d 100644 --- a/tests/codegen/io_output.txt +++ b/tests/codegen/io_output.txt @@ -1,5 +1,5 @@ -A: Hello world -B: Hello world -C: Hello world -D: Hello world -Done. +A: Hello world +B: Hello world +C: Hello world +D: Hello world +Done. diff --git a/tests/codegen/life.cl b/tests/codegen/life.cl index 7d7a41fdb..b83d97957 100755 --- a/tests/codegen/life.cl +++ b/tests/codegen/life.cl @@ -1,436 +1,436 @@ -(* The Game of Life - Tendo Kayiira, Summer '95 - With code taken from /private/cool/class/examples/cells.cl - - This introduction was taken off the internet. It gives a brief - description of the Game Of Life. It also gives the rules by which - this particular game follows. - - Introduction - - John Conway's Game of Life is a mathematical amusement, but it - is also much more: an insight into how a system of simple - cellualar automata can create complex, odd, and often aesthetically - pleasing patterns. It is played on a cartesian grid of cells - which are either 'on' or 'off' The game gets it's name from the - similarity between the behaviour of these cells and the behaviour - of living organisms. - - The Rules - - The playfield is a cartesian grid of arbitrary size. Each cell in - this grid can be in an 'on' state or an 'off' state. On each 'turn' - (called a generation,) the state of each cell changes simultaneously - depending on it's state and the state of all cells adjacent to it. - - For 'on' cells, - If the cell has 0 or 1 neighbours which are 'on', the cell turns - 'off'. ('dies of loneliness') - If the cell has 2 or 3 neighbours which are 'on', the cell stays - 'on'. (nothing happens to that cell) - If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', - the cell turns 'off'. ('dies of overcrowding') - - For 'off' cells, - If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which - are 'on', the cell stays 'off'. (nothing happens to that cell) - If the cell has 3 neighbours which are 'on', the cell turns - 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) - - Repeat for as many generations as desired. - - *) - - -class Board inherits IO { - - rows : Int; - columns : Int; - board_size : Int; - - size_of_board(initial : String) : Int { - initial.length() - }; - - board_init(start : String) : Board { - (let size :Int <- size_of_board(start) in - { - if size = 15 then - { - rows <- 3; - columns <- 5; - board_size <- size; - } - else if size = 16 then - { - rows <- 4; - columns <- 4; - board_size <- size; - } - else if size = 20 then - { - rows <- 4; - columns <- 5; - board_size <- size; - } - else if size = 21 then - { - rows <- 3; - columns <- 7; - board_size <- size; - } - else if size = 25 then - { - rows <- 5; - columns <- 5; - board_size <- size; - } - else if size = 28 then - { - rows <- 7; - columns <- 4; - board_size <- size; - } - else -- If none of the above fit, then just give - { -- the configuration of the most common board - rows <- 5; - columns <- 5; - board_size <- size; - } - fi fi fi fi fi fi; - self; - } - ) - }; - -}; - - - -class CellularAutomaton inherits Board { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - board_init(map); - self; - } - }; - - - - - print() : CellularAutomaton { - - (let i : Int <- 0 in - (let num : Int <- board_size in - { - out_string("\n"); - while i < num loop - { - out_string(population_map.substr(i,columns)); - out_string("\n"); - i <- i + columns; - } - pool; - out_string("\n"); - self; - } - ) ) - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - if board_size - 1 < position then - " " - else - population_map.substr(position, 1) - fi - }; - - north(position : Int): String { - if (position - columns) < 0 then - " " - else - cell(position - columns) - fi - }; - - south(position : Int): String { - if board_size < (position + columns) then - " " - else - cell(position + columns) - fi - }; - - east(position : Int): String { - if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - cell(position + 1) - fi - }; - - west(position : Int): String { - if position = 0 then - " " - else - if ((position / columns) * columns) = position then - " " - else - cell(position - 1) - fi fi - }; - - northwest(position : Int): String { - if (position - columns) < 0 then - " " - else if ((position / columns) * columns) = position then - " " - else - north(position - 1) - fi fi - }; - - northeast(position : Int): String { - if (position - columns) < 0 then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - north(position + 1) - fi fi - }; - - southeast(position : Int): String { - if board_size < (position + columns) then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - south(position + 1) - fi fi - }; - - southwest(position : Int): String { - if board_size < (position + columns) then - " " - else if ((position / columns) * columns) = position then - " " - else - south(position - 1) - fi fi - }; - - neighbors(position: Int): Int { - { - if north(position) = "X" then 1 else 0 fi - + if south(position) = "X" then 1 else 0 fi - + if east(position) = "X" then 1 else 0 fi - + if west(position) = "X" then 1 else 0 fi - + if northeast(position) = "X" then 1 else 0 fi - + if northwest(position) = "X" then 1 else 0 fi - + if southeast(position) = "X" then 1 else 0 fi - + if southwest(position) = "X" then 1 else 0 fi; - } - }; - - -(* A cell will live if 2 or 3 of it's neighbors are alive. It dies - otherwise. A cell is born if only 3 of it's neighbors are alive. *) - - cell_at_next_evolution(position : Int) : String { - - if neighbors(position) = 3 then - "X" - else - if neighbors(position) = 2 then - if cell(position) = "X" then - "X" - else - "-" - fi - else - "-" - fi fi - }; - - - evolve() : CellularAutomaton { - (let position : Int <- 0 in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; - -(* This is where the background pattern is detremined by the user. More - patterns can be added as long as whoever adds keeps the board either - 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) - option(): String { - { - (let num : Int in - { - out_string("\nPlease chose a number:\n"); - out_string("\t1: A cross\n"); - out_string("\t2: A slash from the upper left to lower right\n"); - out_string("\t3: A slash from the upper right to lower left\n"); - out_string("\t4: An X\n"); - out_string("\t5: A greater than sign \n"); - out_string("\t6: A less than sign\n"); - out_string("\t7: Two greater than signs\n"); - out_string("\t8: Two less than signs\n"); - out_string("\t9: A 'V'\n"); - out_string("\t10: An inverse 'V'\n"); - out_string("\t11: Numbers 9 and 10 combined\n"); - out_string("\t12: A full grid\n"); - out_string("\t13: A 'T'\n"); - out_string("\t14: A plus '+'\n"); - out_string("\t15: A 'W'\n"); - out_string("\t16: An 'M'\n"); - out_string("\t17: An 'E'\n"); - out_string("\t18: A '3'\n"); - out_string("\t19: An 'O'\n"); - out_string("\t20: An '8'\n"); - out_string("\t21: An 'S'\n"); - out_string("Your choice => "); - num <- in_int(); - out_string("\n"); - if num = 1 then - " XX XXXX XXXX XX " - else if num = 2 then - " X X X X X " - else if num = 3 then - "X X X X X" - else if num = 4 then - "X X X X X X X X X" - else if num = 5 then - "X X X X X " - else if num = 6 then - " X X X X X" - else if num = 7 then - "X X X XX X " - else if num = 8 then - " X XX X X X " - else if num = 9 then - "X X X X X " - else if num = 10 then - " X X X X X" - else if num = 11 then - "X X X X X X X X" - else if num = 12 then - "XXXXXXXXXXXXXXXXXXXXXXXXX" - else if num = 13 then - "XXXXX X X X X " - else if num = 14 then - " X X XXXXX X X " - else if num = 15 then - "X X X X X X X " - else if num = 16 then - " X X X X X X X" - else if num = 17 then - "XXXXX X XXXXX X XXXX" - else if num = 18 then - "XXX X X X X XXXX " - else if num = 19 then - " XX X XX X XX " - else if num = 20 then - " XX X XX X XX X XX X XX " - else if num = 21 then - " XXXX X XX X XXXX " - else - " " - fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; - } - ); - } - }; - - - - - prompt() : Bool { - { - (let ans : String in - { - out_string("Would you like to continue with the next generation? \n"); - out_string("Please use lowercase y or n for your answer [y]: "); - ans <- in_string(); - out_string("\n"); - if ans = "n" then - false - else - true - fi; - } - ); - } - }; - - - prompt2() : Bool { - (let ans : String in - { - out_string("\n\n"); - out_string("Would you like to choose a background pattern? \n"); - out_string("Please use lowercase y or n for your answer [n]: "); - ans <- in_string(); - if ans = "y" then - true - else - false - fi; - } - ) - }; - - -}; - -class Main inherits CellularAutomaton { - cells : CellularAutomaton; - - main() : Main { - { - (let continue : Bool in - (let choice : String in - { - out_string("Welcome to the Game of Life.\n"); - out_string("There are many initial states to choose from. \n"); - while prompt2() loop - { - continue <- true; - choice <- option(); - cells <- (new CellularAutomaton).init(choice); - cells.print(); - while continue loop - if prompt() then - { - cells.evolve(); - cells.print(); - } - else - continue <- false - fi - pool; - } - pool; - self; - } ) ); } - }; -}; - +(* The Game of Life + Tendo Kayiira, Summer '95 + With code taken from /private/cool/class/examples/cells.cl + + This introduction was taken off the internet. It gives a brief + description of the Game Of Life. It also gives the rules by which + this particular game follows. + + Introduction + + John Conway's Game of Life is a mathematical amusement, but it + is also much more: an insight into how a system of simple + cellualar automata can create complex, odd, and often aesthetically + pleasing patterns. It is played on a cartesian grid of cells + which are either 'on' or 'off' The game gets it's name from the + similarity between the behaviour of these cells and the behaviour + of living organisms. + + The Rules + + The playfield is a cartesian grid of arbitrary size. Each cell in + this grid can be in an 'on' state or an 'off' state. On each 'turn' + (called a generation,) the state of each cell changes simultaneously + depending on it's state and the state of all cells adjacent to it. + + For 'on' cells, + If the cell has 0 or 1 neighbours which are 'on', the cell turns + 'off'. ('dies of loneliness') + If the cell has 2 or 3 neighbours which are 'on', the cell stays + 'on'. (nothing happens to that cell) + If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', + the cell turns 'off'. ('dies of overcrowding') + + For 'off' cells, + If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which + are 'on', the cell stays 'off'. (nothing happens to that cell) + If the cell has 3 neighbours which are 'on', the cell turns + 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) + + Repeat for as many generations as desired. + + *) + + +class Board inherits IO { + + rows : Int; + columns : Int; + board_size : Int; + + size_of_board(initial : String) : Int { + initial.length() + }; + + board_init(start : String) : Board { + (let size :Int <- size_of_board(start) in + { + if size = 15 then + { + rows <- 3; + columns <- 5; + board_size <- size; + } + else if size = 16 then + { + rows <- 4; + columns <- 4; + board_size <- size; + } + else if size = 20 then + { + rows <- 4; + columns <- 5; + board_size <- size; + } + else if size = 21 then + { + rows <- 3; + columns <- 7; + board_size <- size; + } + else if size = 25 then + { + rows <- 5; + columns <- 5; + board_size <- size; + } + else if size = 28 then + { + rows <- 7; + columns <- 4; + board_size <- size; + } + else -- If none of the above fit, then just give + { -- the configuration of the most common board + rows <- 5; + columns <- 5; + board_size <- size; + } + fi fi fi fi fi fi; + self; + } + ) + }; + +}; + + + +class CellularAutomaton inherits Board { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + board_init(map); + self; + } + }; + + + + + print() : CellularAutomaton { + + (let i : Int <- 0 in + (let num : Int <- board_size in + { + out_string("\n"); + while i < num loop + { + out_string(population_map.substr(i,columns)); + out_string("\n"); + i <- i + columns; + } + pool; + out_string("\n"); + self; + } + ) ) + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + if board_size - 1 < position then + " " + else + population_map.substr(position, 1) + fi + }; + + north(position : Int): String { + if (position - columns) < 0 then + " " + else + cell(position - columns) + fi + }; + + south(position : Int): String { + if board_size < (position + columns) then + " " + else + cell(position + columns) + fi + }; + + east(position : Int): String { + if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + cell(position + 1) + fi + }; + + west(position : Int): String { + if position = 0 then + " " + else + if ((position / columns) * columns) = position then + " " + else + cell(position - 1) + fi fi + }; + + northwest(position : Int): String { + if (position - columns) < 0 then + " " + else if ((position / columns) * columns) = position then + " " + else + north(position - 1) + fi fi + }; + + northeast(position : Int): String { + if (position - columns) < 0 then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + north(position + 1) + fi fi + }; + + southeast(position : Int): String { + if board_size < (position + columns) then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + south(position + 1) + fi fi + }; + + southwest(position : Int): String { + if board_size < (position + columns) then + " " + else if ((position / columns) * columns) = position then + " " + else + south(position - 1) + fi fi + }; + + neighbors(position: Int): Int { + { + if north(position) = "X" then 1 else 0 fi + + if south(position) = "X" then 1 else 0 fi + + if east(position) = "X" then 1 else 0 fi + + if west(position) = "X" then 1 else 0 fi + + if northeast(position) = "X" then 1 else 0 fi + + if northwest(position) = "X" then 1 else 0 fi + + if southeast(position) = "X" then 1 else 0 fi + + if southwest(position) = "X" then 1 else 0 fi; + } + }; + + +(* A cell will live if 2 or 3 of it's neighbors are alive. It dies + otherwise. A cell is born if only 3 of it's neighbors are alive. *) + + cell_at_next_evolution(position : Int) : String { + + if neighbors(position) = 3 then + "X" + else + if neighbors(position) = 2 then + if cell(position) = "X" then + "X" + else + "-" + fi + else + "-" + fi fi + }; + + + evolve() : CellularAutomaton { + (let position : Int <- 0 in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; + +(* This is where the background pattern is detremined by the user. More + patterns can be added as long as whoever adds keeps the board either + 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) + option(): String { + { + (let num : Int in + { + out_string("\nPlease chose a number:\n"); + out_string("\t1: A cross\n"); + out_string("\t2: A slash from the upper left to lower right\n"); + out_string("\t3: A slash from the upper right to lower left\n"); + out_string("\t4: An X\n"); + out_string("\t5: A greater than sign \n"); + out_string("\t6: A less than sign\n"); + out_string("\t7: Two greater than signs\n"); + out_string("\t8: Two less than signs\n"); + out_string("\t9: A 'V'\n"); + out_string("\t10: An inverse 'V'\n"); + out_string("\t11: Numbers 9 and 10 combined\n"); + out_string("\t12: A full grid\n"); + out_string("\t13: A 'T'\n"); + out_string("\t14: A plus '+'\n"); + out_string("\t15: A 'W'\n"); + out_string("\t16: An 'M'\n"); + out_string("\t17: An 'E'\n"); + out_string("\t18: A '3'\n"); + out_string("\t19: An 'O'\n"); + out_string("\t20: An '8'\n"); + out_string("\t21: An 'S'\n"); + out_string("Your choice => "); + num <- in_int(); + out_string("\n"); + if num = 1 then + " XX XXXX XXXX XX " + else if num = 2 then + " X X X X X " + else if num = 3 then + "X X X X X" + else if num = 4 then + "X X X X X X X X X" + else if num = 5 then + "X X X X X " + else if num = 6 then + " X X X X X" + else if num = 7 then + "X X X XX X " + else if num = 8 then + " X XX X X X " + else if num = 9 then + "X X X X X " + else if num = 10 then + " X X X X X" + else if num = 11 then + "X X X X X X X X" + else if num = 12 then + "XXXXXXXXXXXXXXXXXXXXXXXXX" + else if num = 13 then + "XXXXX X X X X " + else if num = 14 then + " X X XXXXX X X " + else if num = 15 then + "X X X X X X X " + else if num = 16 then + " X X X X X X X" + else if num = 17 then + "XXXXX X XXXXX X XXXX" + else if num = 18 then + "XXX X X X X XXXX " + else if num = 19 then + " XX X XX X XX " + else if num = 20 then + " XX X XX X XX X XX X XX " + else if num = 21 then + " XXXX X XX X XXXX " + else + " " + fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; + } + ); + } + }; + + + + + prompt() : Bool { + { + (let ans : String in + { + out_string("Would you like to continue with the next generation? \n"); + out_string("Please use lowercase y or n for your answer [y]: "); + ans <- in_string(); + out_string("\n"); + if ans = "n" then + false + else + true + fi; + } + ); + } + }; + + + prompt2() : Bool { + (let ans : String in + { + out_string("\n\n"); + out_string("Would you like to choose a background pattern? \n"); + out_string("Please use lowercase y or n for your answer [n]: "); + ans <- in_string(); + if ans = "y" then + true + else + false + fi; + } + ) + }; + + +}; + +class Main inherits CellularAutomaton { + cells : CellularAutomaton; + + main() : Main { + { + (let continue : Bool in + (let choice : String in + { + out_string("Welcome to the Game of Life.\n"); + out_string("There are many initial states to choose from. \n"); + while prompt2() loop + { + continue <- true; + choice <- option(); + cells <- (new CellularAutomaton).init(choice); + cells.print(); + while continue loop + if prompt() then + { + cells.evolve(); + cells.print(); + } + else + continue <- false + fi + pool; + } + pool; + self; + } ) ); } + }; +}; + diff --git a/tests/codegen/life_input.txt b/tests/codegen/life_input.txt index 1dfbde620..07e016726 100644 --- a/tests/codegen/life_input.txt +++ b/tests/codegen/life_input.txt @@ -1,66 +1,66 @@ -y -1 -n -y -2 -n -y -3 -n -y -4 -n -y -5 -n -y -6 -n -y -7 -n -y -8 -n -y -9 -n -y -10 -n -y -11 -n -y -12 -n -y -13 -n -y -14 -n -y -15 -n -y -16 -n -y -17 -n -y -18 -n -y -19 -n -y -20 -n -y -21 -y -y -n +y +1 +n +y +2 +n +y +3 +n +y +4 +n +y +5 +n +y +6 +n +y +7 +n +y +8 +n +y +9 +n +y +10 +n +y +11 +n +y +12 +n +y +13 +n +y +14 +n +y +15 +n +y +16 +n +y +17 +n +y +18 +n +y +19 +n +y +20 +n +y +21 +y +y +n n \ No newline at end of file diff --git a/tests/codegen/life_output.txt b/tests/codegen/life_output.txt index e804b2382..5a9b9f73d 100644 --- a/tests/codegen/life_output.txt +++ b/tests/codegen/life_output.txt @@ -1,778 +1,778 @@ -Welcome to the Game of Life. -There are many initial states to choose from. - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -XXXX -XXXX - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X -X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X -X X - X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X X - X X -X X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX -XXXXX -XXXXX -XXXXX -XXXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X -XXXXX - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X X - X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X - X X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXX -X -X -XXXX -X -X -XXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXX - X - X - X - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XXX -X -X - XX - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X--- --XX- ----X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X-X- --XX- --X-X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? +Welcome to the Game of Life. +There are many initial states to choose from. + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +XXXX +XXXX + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X +X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X +X X + X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X X + X X +X X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX +XXXXX +XXXXX +XXXXX +XXXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X +XXXXX + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X X + X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X + X X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXX +X +X +XXXX +X +X +XXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXX + X + X + X + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XXX +X +X + XX + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X--- +-XX- +---X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X-X- +-XX- +-X-X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? Please use lowercase y or n for your answer [n]: \ No newline at end of file diff --git a/tests/codegen/list_output.txt b/tests/codegen/list_output.txt index 00d68ed23..fca724903 100644 --- a/tests/codegen/list_output.txt +++ b/tests/codegen/list_output.txt @@ -1,5 +1,5 @@ -5 4 3 2 1 -4 3 2 1 -3 2 1 -2 1 -1 +5 4 3 2 1 +4 3 2 1 +3 2 1 +2 1 +1 diff --git a/tests/codegen/new_complex.cl b/tests/codegen/new_complex.cl index ad7035b56..a4fe714ce 100755 --- a/tests/codegen/new_complex.cl +++ b/tests/codegen/new_complex.cl @@ -1,79 +1,79 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - { - -- trivially equal (see CoolAid) - if c.reflect_X() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi; - -- equal - if c.reflect_X().reflect_Y().equal(c.reflect_0()) - then out_string("=)\n") - else out_string("=(\n") - fi; - } - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; - - equal(d : Complex) : Bool { - if x = d.x_value() - then - if y = d.y_value() - then true - else false - fi - else false - fi - }; - - x_value() : Int { - x - }; - - y_value() : Int { - y - }; -}; +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + { + -- trivially equal (see CoolAid) + if c.reflect_X() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi; + -- equal + if c.reflect_X().reflect_Y().equal(c.reflect_0()) + then out_string("=)\n") + else out_string("=(\n") + fi; + } + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; + + equal(d : Complex) : Bool { + if x = d.x_value() + then + if y = d.y_value() + then true + else false + fi + else false + fi + }; + + x_value() : Int { + x + }; + + y_value() : Int { + y + }; +}; diff --git a/tests/codegen/new_complex_output.txt b/tests/codegen/new_complex_output.txt index 831c23af4..0e8da112c 100644 --- a/tests/codegen/new_complex_output.txt +++ b/tests/codegen/new_complex_output.txt @@ -1,2 +1,2 @@ -=) -=) +=) +=) diff --git a/tests/codegen/palindrome.cl b/tests/codegen/palindrome.cl index 6acbeb731..7f24789f9 100755 --- a/tests/codegen/palindrome.cl +++ b/tests/codegen/palindrome.cl @@ -1,25 +1,25 @@ -class Main inherits IO { - pal(s : String) : Bool { - if s.length() = 0 - then true - else if s.length() = 1 - then true - else if s.substr(0, 1) = s.substr(s.length() - 1, 1) - then pal(s.substr(1, s.length() -2)) - else false - fi fi fi - }; - - i : Int; - - main() : IO { - { - i <- ~1; - out_string("enter a string\n"); - if pal(in_string()) - then out_string("that was a palindrome\n") - else out_string("that was not a palindrome\n") - fi; - } - }; -}; +class Main inherits IO { + pal(s : String) : Bool { + if s.length() = 0 + then true + else if s.length() = 1 + then true + else if s.substr(0, 1) = s.substr(s.length() - 1, 1) + then pal(s.substr(1, s.length() -2)) + else false + fi fi fi + }; + + i : Int; + + main() : IO { + { + i <- ~1; + out_string("enter a string\n"); + if pal(in_string()) + then out_string("that was a palindrome\n") + else out_string("that was not a palindrome\n") + fi; + } + }; +}; diff --git a/tests/codegen/palindrome_input.txt b/tests/codegen/palindrome_input.txt index c49a0114c..8e1b64142 100644 --- a/tests/codegen/palindrome_input.txt +++ b/tests/codegen/palindrome_input.txt @@ -1 +1 @@ -anitalabalatina +anitalabalatina diff --git a/tests/codegen/palindrome_output.txt b/tests/codegen/palindrome_output.txt index e93d36585..7a0095959 100644 --- a/tests/codegen/palindrome_output.txt +++ b/tests/codegen/palindrome_output.txt @@ -1,2 +1,2 @@ -enter a string -that was a palindrome +enter a string +that was a palindrome diff --git a/tests/codegen/primes_output.txt b/tests/codegen/primes_output.txt index cf5d78d49..a4d0fcb3f 100644 --- a/tests/codegen/primes_output.txt +++ b/tests/codegen/primes_output.txt @@ -1,96 +1,96 @@ -2 is trivially prime. -3 is prime. -5 is prime. -7 is prime. -11 is prime. -13 is prime. -17 is prime. -19 is prime. -23 is prime. -29 is prime. -31 is prime. -37 is prime. -41 is prime. -43 is prime. -47 is prime. -53 is prime. -59 is prime. -61 is prime. -67 is prime. -71 is prime. -73 is prime. -79 is prime. -83 is prime. -89 is prime. -97 is prime. -101 is prime. -103 is prime. -107 is prime. -109 is prime. -113 is prime. -127 is prime. -131 is prime. -137 is prime. -139 is prime. -149 is prime. -151 is prime. -157 is prime. -163 is prime. -167 is prime. -173 is prime. -179 is prime. -181 is prime. -191 is prime. -193 is prime. -197 is prime. -199 is prime. -211 is prime. -223 is prime. -227 is prime. -229 is prime. -233 is prime. -239 is prime. -241 is prime. -251 is prime. -257 is prime. -263 is prime. -269 is prime. -271 is prime. -277 is prime. -281 is prime. -283 is prime. -293 is prime. -307 is prime. -311 is prime. -313 is prime. -317 is prime. -331 is prime. -337 is prime. -347 is prime. -349 is prime. -353 is prime. -359 is prime. -367 is prime. -373 is prime. -379 is prime. -383 is prime. -389 is prime. -397 is prime. -401 is prime. -409 is prime. -419 is prime. -421 is prime. -431 is prime. -433 is prime. -439 is prime. -443 is prime. -449 is prime. -457 is prime. -461 is prime. -463 is prime. -467 is prime. -479 is prime. -487 is prime. -491 is prime. -499 is prime. -Abort called from class String +2 is trivially prime. +3 is prime. +5 is prime. +7 is prime. +11 is prime. +13 is prime. +17 is prime. +19 is prime. +23 is prime. +29 is prime. +31 is prime. +37 is prime. +41 is prime. +43 is prime. +47 is prime. +53 is prime. +59 is prime. +61 is prime. +67 is prime. +71 is prime. +73 is prime. +79 is prime. +83 is prime. +89 is prime. +97 is prime. +101 is prime. +103 is prime. +107 is prime. +109 is prime. +113 is prime. +127 is prime. +131 is prime. +137 is prime. +139 is prime. +149 is prime. +151 is prime. +157 is prime. +163 is prime. +167 is prime. +173 is prime. +179 is prime. +181 is prime. +191 is prime. +193 is prime. +197 is prime. +199 is prime. +211 is prime. +223 is prime. +227 is prime. +229 is prime. +233 is prime. +239 is prime. +241 is prime. +251 is prime. +257 is prime. +263 is prime. +269 is prime. +271 is prime. +277 is prime. +281 is prime. +283 is prime. +293 is prime. +307 is prime. +311 is prime. +313 is prime. +317 is prime. +331 is prime. +337 is prime. +347 is prime. +349 is prime. +353 is prime. +359 is prime. +367 is prime. +373 is prime. +379 is prime. +383 is prime. +389 is prime. +397 is prime. +401 is prime. +409 is prime. +419 is prime. +421 is prime. +431 is prime. +433 is prime. +439 is prime. +443 is prime. +449 is prime. +457 is prime. +461 is prime. +463 is prime. +467 is prime. +479 is prime. +487 is prime. +491 is prime. +499 is prime. +Abort called from class String diff --git a/tests/codegen/print-cool_output.txt b/tests/codegen/print-cool_output.txt index 3c8cd620c..2b58f8985 100644 --- a/tests/codegen/print-cool_output.txt +++ b/tests/codegen/print-cool_output.txt @@ -1 +1 @@ -cool +cool diff --git a/tests/codegen/sort-list_input.txt b/tests/codegen/sort-list_input.txt index d43401489..f599e28b8 100644 --- a/tests/codegen/sort-list_input.txt +++ b/tests/codegen/sort-list_input.txt @@ -1 +1 @@ -10 +10 diff --git a/tests/codegen/sort-list_output.txt b/tests/codegen/sort-list_output.txt index 7b1d40452..9878d57ea 100644 --- a/tests/codegen/sort-list_output.txt +++ b/tests/codegen/sort-list_output.txt @@ -1,10 +1,10 @@ -How many numbers to sort? 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 +How many numbers to sort? 0 +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/tests/codegen_test.py b/tests/codegen_test.py index e748bd2d1..48df768ff 100644 --- a/tests/codegen_test.py +++ b/tests/codegen_test.py @@ -1,17 +1,17 @@ -import pytest -import os -from utils import compare_outputs - -tests_dir = __file__.rpartition('/')[0] + '/codegen/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -# @pytest.mark.lexer -# @pytest.mark.parser -# @pytest.mark.semantic -@pytest.mark.codegen -@pytest.mark.ok -@pytest.mark.run(order=4) -@pytest.mark.parametrize("cool_file", tests) -def test_codegen(compiler_path, cool_file): - compare_outputs(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_input.txt',\ +import pytest +import os +from utils import compare_outputs + +tests_dir = __file__.rpartition('/')[0] + '/codegen/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +# @pytest.mark.lexer +# @pytest.mark.parser +# @pytest.mark.semantic +@pytest.mark.codegen +@pytest.mark.ok +@pytest.mark.run(order=4) +@pytest.mark.parametrize("cool_file", tests) +def test_codegen(compiler_path, cool_file): + compare_outputs(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_input.txt',\ tests_dir + cool_file[:-3] + '_output.txt') \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 561d8bafc..1f44eeb72 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ -import pytest -import os - -@pytest.fixture -def compiler_path(): +import pytest +import os + +@pytest.fixture +def compiler_path(): return os.path.abspath('./coolc.sh') \ No newline at end of file diff --git a/tests/lexer/comment1.cl b/tests/lexer/comment1.cl new file mode 100644 index 000000000..69533f23c --- /dev/null +++ b/tests/lexer/comment1.cl @@ -0,0 +1,55 @@ +--Any characters between two dashes “--” and the next newline +--(or EOF, if there is no next newline) are treated as comments + +(*(*(* +Comments may also be written by enclosing +text in (∗ . . . ∗). The latter form of comment may be nested. +Comments cannot cross file boundaries. +*)*)*) + +class Error() { + + (* There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more. + There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more. \ No newline at end of file diff --git a/tests/lexer/comment1_error.txt b/tests/lexer/comment1_error.txt new file mode 100644 index 000000000..9fd7b8d67 --- /dev/null +++ b/tests/lexer/comment1_error.txt @@ -0,0 +1 @@ +(55, 46) - LexicographicError: EOF in comment diff --git a/tests/lexer/iis1.cl b/tests/lexer/iis1.cl index ca6b68ac3..12cb52beb 100644 --- a/tests/lexer/iis1.cl +++ b/tests/lexer/iis1.cl @@ -1,111 +1,111 @@ -(* Integers, Identifiers, and Special Notation *) - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -5! = 120, 2 + 2 = 5 or E = mc2; p + 1 @ p = 1: for x in range(len(b)) -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -class Class if then else fi testing Testing ~007agent_bond james_007B0N3SS___ -loop pool while tRuE or noT faLsE let in case of ESAC - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 INT_CONST 5 -#4 ERROR "!" -#4 '=' -#4 INT_CONST 120 -#4 ',' -#4 INT_CONST 2 -#4 '+' -#4 INT_CONST 2 -#4 '=' -#4 INT_CONST 5 -#4 OBJECTID or -#4 TYPEID E -#4 '=' -#4 OBJECTID mc2 -#4 ';' -#4 OBJECTID p -#4 '+' -#4 INT_CONST 1 -#4 '@' -#4 OBJECTID p -#4 '=' -#4 INT_CONST 1 -#4 ':' -#4 OBJECTID for -#4 OBJECTID x -#4 IN -#4 OBJECTID range -#4 '(' -#4 OBJECTID len -#4 '(' -#4 OBJECTID b -#4 ')' -#4 ')' -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#6 CLASS -#6 CLASS -#6 IF -#6 THEN -#6 ELSE -#6 FI -#6 OBJECTID testing -#6 TYPEID Testing -#6 '~' -#6 INT_CONST 007 -#6 OBJECTID agent_bond -#6 OBJECTID james_007B0N3SS___ -#7 LOOP -#7 POOL -#7 WHILE -#7 BOOL_CONST true -#7 OBJECTID or -#7 NOT -#7 BOOL_CONST false -#7 LET -#7 IN -#7 CASE -#7 OF -#7 ESAC +(* Integers, Identifiers, and Special Notation *) + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +5! = 120, 2 + 2 = 5 or E = mc2; p + 1 @ p = 1: for x in range(len(b)) +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +class Class if then else fi testing Testing ~007agent_bond james_007B0N3SS___ +loop pool while tRuE or noT faLsE let in case of ESAC + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 INT_CONST 5 +#4 ERROR "!" +#4 '=' +#4 INT_CONST 120 +#4 ',' +#4 INT_CONST 2 +#4 '+' +#4 INT_CONST 2 +#4 '=' +#4 INT_CONST 5 +#4 OBJECTID or +#4 TYPEID E +#4 '=' +#4 OBJECTID mc2 +#4 ';' +#4 OBJECTID p +#4 '+' +#4 INT_CONST 1 +#4 '@' +#4 OBJECTID p +#4 '=' +#4 INT_CONST 1 +#4 ':' +#4 OBJECTID for +#4 OBJECTID x +#4 IN +#4 OBJECTID range +#4 '(' +#4 OBJECTID len +#4 '(' +#4 OBJECTID b +#4 ')' +#4 ')' +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#6 CLASS +#6 CLASS +#6 IF +#6 THEN +#6 ELSE +#6 FI +#6 OBJECTID testing +#6 TYPEID Testing +#6 '~' +#6 INT_CONST 007 +#6 OBJECTID agent_bond +#6 OBJECTID james_007B0N3SS___ +#7 LOOP +#7 POOL +#7 WHILE +#7 BOOL_CONST true +#7 OBJECTID or +#7 NOT +#7 BOOL_CONST false +#7 LET +#7 IN +#7 CASE +#7 OF +#7 ESAC *) \ No newline at end of file diff --git a/tests/lexer/iis1_error.txt b/tests/lexer/iis1_error.txt index 12f62f1ba..9e6d66cac 100644 --- a/tests/lexer/iis1_error.txt +++ b/tests/lexer/iis1_error.txt @@ -1 +1 @@ -(4, 2) - LexicographicError: ERROR "!" +(4, 2) - LexicographicError: ERROR "!" diff --git a/tests/lexer/iis2.cl b/tests/lexer/iis2.cl index d42552494..9b25715d4 100644 --- a/tests/lexer/iis2.cl +++ b/tests/lexer/iis2.cl @@ -1,120 +1,120 @@ -(* Integers, Identifiers, and Special Notation *) - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -loop pool while tRuE or noT faLsE let in case of ESAC - -factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 CLASS -#4 CLASS -#4 IF -#4 THEN -#4 ELSE -#4 FI -#4 OBJECTID testing -#4 TYPEID Testing -#4 '~' -#4 INT_CONST 007 -#4 OBJECTID agent_bond -#4 OBJECTID james_007bones___ -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#8 LOOP -#8 POOL -#8 WHILE -#8 BOOL_CONST true -#8 OBJECTID or -#8 NOT -#8 BOOL_CONST false -#8 LET -#8 IN -#8 CASE -#8 OF -#8 ESAC -#10 OBJECTID factorial -#10 '(' -#10 INT_CONST 5 -#10 ')' -#10 '=' -#10 INT_CONST 120 -#10 ',' -#10 INT_CONST 2 -#10 '+' -#10 INT_CONST 2 -#10 '=' -#10 INT_CONST 5 -#10 ERROR "?" -#10 OBJECTID or -#10 TYPEID E -#10 '=' -#10 OBJECTID mc2 -#10 ';' -#10 OBJECTID p -#10 '+' -#10 INT_CONST 1 -#10 OBJECTID resto -#10 OBJECTID p -#10 '=' -#10 INT_CONST 1 -#10 ':' -#10 '(' -#10 '@' -#10 OBJECTID for -#10 OBJECTID x -#10 IN -#10 OBJECTID range -#10 '(' -#10 OBJECTID len -#10 '(' -#10 OBJECTID b -#10 ')' -#10 ')' -#10 ')' +(* Integers, Identifiers, and Special Notation *) + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +loop pool while tRuE or noT faLsE let in case of ESAC + +factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 CLASS +#4 CLASS +#4 IF +#4 THEN +#4 ELSE +#4 FI +#4 OBJECTID testing +#4 TYPEID Testing +#4 '~' +#4 INT_CONST 007 +#4 OBJECTID agent_bond +#4 OBJECTID james_007bones___ +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#8 LOOP +#8 POOL +#8 WHILE +#8 BOOL_CONST true +#8 OBJECTID or +#8 NOT +#8 BOOL_CONST false +#8 LET +#8 IN +#8 CASE +#8 OF +#8 ESAC +#10 OBJECTID factorial +#10 '(' +#10 INT_CONST 5 +#10 ')' +#10 '=' +#10 INT_CONST 120 +#10 ',' +#10 INT_CONST 2 +#10 '+' +#10 INT_CONST 2 +#10 '=' +#10 INT_CONST 5 +#10 ERROR "?" +#10 OBJECTID or +#10 TYPEID E +#10 '=' +#10 OBJECTID mc2 +#10 ';' +#10 OBJECTID p +#10 '+' +#10 INT_CONST 1 +#10 OBJECTID resto +#10 OBJECTID p +#10 '=' +#10 INT_CONST 1 +#10 ':' +#10 '(' +#10 '@' +#10 OBJECTID for +#10 OBJECTID x +#10 IN +#10 OBJECTID range +#10 '(' +#10 OBJECTID len +#10 '(' +#10 OBJECTID b +#10 ')' +#10 ')' +#10 ')' *) \ No newline at end of file diff --git a/tests/lexer/iis2_error.txt b/tests/lexer/iis2_error.txt index 988d0286e..922391a9d 100644 --- a/tests/lexer/iis2_error.txt +++ b/tests/lexer/iis2_error.txt @@ -1 +1 @@ -(10, 30) - LexicographicError: ERROR "?" +(10, 30) - LexicographicError: ERROR "?" diff --git a/tests/lexer/iis3.cl b/tests/lexer/iis3.cl index dcd85f960..0b965ddea 100644 --- a/tests/lexer/iis3.cl +++ b/tests/lexer/iis3.cl @@ -1,121 +1,121 @@ -(* Integers, Identifiers, and Special Notation *) - -factorial(5) = 120, 2 + 2 = 5 or E = mc^2; p + 1 @ p = 1: z for x in range(len(b))) - -loop pool while tRuE or noT faLsE let in case of ESAC - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) - - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -(* -#3 OBJECTID factorial -#3 '(' -#3 INT_CONST 5 -#3 ')' -#3 '=' -#3 INT_CONST 120 -#3 ',' -#3 INT_CONST 2 -#3 '+' -#3 INT_CONST 2 -#3 '=' -#3 INT_CONST 5 -#3 OBJECTID or -#3 TYPEID E -#3 '=' -#3 OBJECTID mc -#3 ERROR "^" -#3 INT_CONST 2 -#3 ';' -#3 OBJECTID p -#3 '+' -#3 INT_CONST 1 -#3 '@' -#3 OBJECTID p -#3 '=' -#3 INT_CONST 1 -#3 ':' -#3 OBJECTID z -#3 OBJECTID for -#3 OBJECTID x -#3 IN -#3 OBJECTID range -#3 '(' -#3 OBJECTID len -#3 '(' -#3 OBJECTID b -#3 ')' -#3 ')' -#3 ')' -#5 LOOP -#5 POOL -#5 WHILE -#5 BOOL_CONST true -#5 OBJECTID or -#5 NOT -#5 BOOL_CONST false -#5 LET -#5 IN -#5 CASE -#5 OF -#5 ESAC -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#10 INT_CONST 0007 -#10 INT_CONST 123 -#10 '+' -#10 INT_CONST 1 -#10 '-' -#10 INT_CONST 1 -#10 '+' -#10 INT_CONST 90 -#10 '-' -#10 INT_CONST 09 -#10 '+' -#10 INT_CONST 11113 -#10 '-' -#10 INT_CONST 4 -#10 OBJECTID r -#10 '*' -#10 OBJECTID a -#10 '*' -#10 OBJECTID self -#10 '*' -#10 OBJECTID c -#10 '+' -#10 '+' -#11 CLASS -#11 CLASS -#11 IF -#11 THEN -#11 ELSE -#11 FI -#11 OBJECTID testing -#11 TYPEID Testing -#11 '~' -#11 INT_CONST 007 -#11 OBJECTID agent_bond -#11 OBJECTID james_007bones___ +(* Integers, Identifiers, and Special Notation *) + +factorial(5) = 120, 2 + 2 = 5 or E = mc^2; p + 1 @ p = 1: z for x in range(len(b))) + +loop pool while tRuE or noT faLsE let in case of ESAC + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) + + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +(* +#3 OBJECTID factorial +#3 '(' +#3 INT_CONST 5 +#3 ')' +#3 '=' +#3 INT_CONST 120 +#3 ',' +#3 INT_CONST 2 +#3 '+' +#3 INT_CONST 2 +#3 '=' +#3 INT_CONST 5 +#3 OBJECTID or +#3 TYPEID E +#3 '=' +#3 OBJECTID mc +#3 ERROR "^" +#3 INT_CONST 2 +#3 ';' +#3 OBJECTID p +#3 '+' +#3 INT_CONST 1 +#3 '@' +#3 OBJECTID p +#3 '=' +#3 INT_CONST 1 +#3 ':' +#3 OBJECTID z +#3 OBJECTID for +#3 OBJECTID x +#3 IN +#3 OBJECTID range +#3 '(' +#3 OBJECTID len +#3 '(' +#3 OBJECTID b +#3 ')' +#3 ')' +#3 ')' +#5 LOOP +#5 POOL +#5 WHILE +#5 BOOL_CONST true +#5 OBJECTID or +#5 NOT +#5 BOOL_CONST false +#5 LET +#5 IN +#5 CASE +#5 OF +#5 ESAC +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#10 INT_CONST 0007 +#10 INT_CONST 123 +#10 '+' +#10 INT_CONST 1 +#10 '-' +#10 INT_CONST 1 +#10 '+' +#10 INT_CONST 90 +#10 '-' +#10 INT_CONST 09 +#10 '+' +#10 INT_CONST 11113 +#10 '-' +#10 INT_CONST 4 +#10 OBJECTID r +#10 '*' +#10 OBJECTID a +#10 '*' +#10 OBJECTID self +#10 '*' +#10 OBJECTID c +#10 '+' +#10 '+' +#11 CLASS +#11 CLASS +#11 IF +#11 THEN +#11 ELSE +#11 FI +#11 OBJECTID testing +#11 TYPEID Testing +#11 '~' +#11 INT_CONST 007 +#11 OBJECTID agent_bond +#11 OBJECTID james_007bones___ *) \ No newline at end of file diff --git a/tests/lexer/iis3_error.txt b/tests/lexer/iis3_error.txt index 3abc2b556..b001b6a71 100644 --- a/tests/lexer/iis3_error.txt +++ b/tests/lexer/iis3_error.txt @@ -1 +1 @@ -(3, 40) - LexicographicError: ERROR "^" +(3, 40) - LexicographicError: ERROR "^" diff --git a/tests/lexer/iis4.cl b/tests/lexer/iis4.cl index 5357ab734..9e7a9cb62 100644 --- a/tests/lexer/iis4.cl +++ b/tests/lexer/iis4.cl @@ -1,120 +1,120 @@ -(* Integers, Identifiers, and Special Notation *) - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 % p = 1: @.@ for x in range(len(b))~ - - -loop pool while tRuE or noT faLsE let in case of ESAC -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -(* -#3 NEW -#3 '/' -#3 ASSIGN -#3 '<' -#3 LE -#3 DARROW -#3 '{' -#3 '(' -#3 TYPEID Int -#3 ':' -#3 TYPEID Objet -#3 ',' -#3 TYPEID Bool -#3 ';' -#3 TYPEID String -#3 '.' -#3 OBJECTID string -#3 TYPEID SELF_TYPE -#3 ISVOID -#3 '}' -#3 ')' -#4 INT_CONST 0007 -#4 INT_CONST 123 -#4 '+' -#4 INT_CONST 1 -#4 '-' -#4 INT_CONST 1 -#4 '+' -#4 INT_CONST 90 -#4 '-' -#4 INT_CONST 09 -#4 '+' -#4 INT_CONST 11113 -#4 '-' -#4 INT_CONST 4 -#4 OBJECTID r -#4 '*' -#4 OBJECTID a -#4 '*' -#4 OBJECTID self -#4 '*' -#4 OBJECTID c -#4 '+' -#4 '+' -#6 OBJECTID factorial -#6 '(' -#6 INT_CONST 5 -#6 ')' -#6 '=' -#6 INT_CONST 120 -#6 ',' -#6 INT_CONST 2 -#6 '+' -#6 INT_CONST 2 -#6 '=' -#6 INT_CONST 5 -#6 OBJECTID or -#6 TYPEID E -#6 '=' -#6 OBJECTID mc2 -#6 ';' -#6 OBJECTID p -#6 '+' -#6 INT_CONST 1 -#6 ERROR "%" -#6 OBJECTID p -#6 '=' -#6 INT_CONST 1 -#6 ':' -#6 '@' -#6 '.' -#6 '@' -#6 OBJECTID for -#6 OBJECTID x -#6 IN -#6 OBJECTID range -#6 '(' -#6 OBJECTID len -#6 '(' -#6 OBJECTID b -#6 ')' -#6 ')' -#6 '~' -#9 LOOP -#9 POOL -#9 WHILE -#9 BOOL_CONST true -#9 OBJECTID or -#9 NOT -#9 BOOL_CONST false -#9 LET -#9 IN -#9 CASE -#9 OF -#9 ESAC -#10 CLASS -#10 CLASS -#10 IF -#10 THEN -#10 ELSE -#10 FI -#10 OBJECTID testing -#10 TYPEID Testing -#10 '~' -#10 INT_CONST 007 -#10 OBJECTID agent_bond -#10 OBJECTID james_007bones___ +(* Integers, Identifiers, and Special Notation *) + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 % p = 1: @.@ for x in range(len(b))~ + + +loop pool while tRuE or noT faLsE let in case of ESAC +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +(* +#3 NEW +#3 '/' +#3 ASSIGN +#3 '<' +#3 LE +#3 DARROW +#3 '{' +#3 '(' +#3 TYPEID Int +#3 ':' +#3 TYPEID Objet +#3 ',' +#3 TYPEID Bool +#3 ';' +#3 TYPEID String +#3 '.' +#3 OBJECTID string +#3 TYPEID SELF_TYPE +#3 ISVOID +#3 '}' +#3 ')' +#4 INT_CONST 0007 +#4 INT_CONST 123 +#4 '+' +#4 INT_CONST 1 +#4 '-' +#4 INT_CONST 1 +#4 '+' +#4 INT_CONST 90 +#4 '-' +#4 INT_CONST 09 +#4 '+' +#4 INT_CONST 11113 +#4 '-' +#4 INT_CONST 4 +#4 OBJECTID r +#4 '*' +#4 OBJECTID a +#4 '*' +#4 OBJECTID self +#4 '*' +#4 OBJECTID c +#4 '+' +#4 '+' +#6 OBJECTID factorial +#6 '(' +#6 INT_CONST 5 +#6 ')' +#6 '=' +#6 INT_CONST 120 +#6 ',' +#6 INT_CONST 2 +#6 '+' +#6 INT_CONST 2 +#6 '=' +#6 INT_CONST 5 +#6 OBJECTID or +#6 TYPEID E +#6 '=' +#6 OBJECTID mc2 +#6 ';' +#6 OBJECTID p +#6 '+' +#6 INT_CONST 1 +#6 ERROR "%" +#6 OBJECTID p +#6 '=' +#6 INT_CONST 1 +#6 ':' +#6 '@' +#6 '.' +#6 '@' +#6 OBJECTID for +#6 OBJECTID x +#6 IN +#6 OBJECTID range +#6 '(' +#6 OBJECTID len +#6 '(' +#6 OBJECTID b +#6 ')' +#6 ')' +#6 '~' +#9 LOOP +#9 POOL +#9 WHILE +#9 BOOL_CONST true +#9 OBJECTID or +#9 NOT +#9 BOOL_CONST false +#9 LET +#9 IN +#9 CASE +#9 OF +#9 ESAC +#10 CLASS +#10 CLASS +#10 IF +#10 THEN +#10 ELSE +#10 FI +#10 OBJECTID testing +#10 TYPEID Testing +#10 '~' +#10 INT_CONST 007 +#10 OBJECTID agent_bond +#10 OBJECTID james_007bones___ *) \ No newline at end of file diff --git a/tests/lexer/iis4_error.txt b/tests/lexer/iis4_error.txt index aab8f39c1..f24076a8c 100644 --- a/tests/lexer/iis4_error.txt +++ b/tests/lexer/iis4_error.txt @@ -1 +1 @@ -(6, 49) - LexicographicError: ERROR "!" +(6, 49) - LexicographicError: ERROR "!" diff --git a/tests/lexer/iis5.cl b/tests/lexer/iis5.cl index f602488b9..d146c0547 100644 --- a/tests/lexer/iis5.cl +++ b/tests/lexer/iis5.cl @@ -1,121 +1,121 @@ -(* Integers, Identifiers, and Special Notation *) - - -loop pool while tRuE or noT faLsE let in case of ESAC -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: [@.@ for x in range(len(b))] - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ - -(* -#4 LOOP -#4 POOL -#4 WHILE -#4 BOOL_CONST true -#4 OBJECTID or -#4 NOT -#4 BOOL_CONST false -#4 LET -#4 IN -#4 CASE -#4 OF -#4 ESAC -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#6 CLASS -#6 CLASS -#6 IF -#6 THEN -#6 ELSE -#6 FI -#6 OBJECTID testing -#6 TYPEID Testing -#6 '~' -#6 INT_CONST 007 -#6 OBJECTID agent_bond -#6 OBJECTID james_007bones___ -#8 OBJECTID factorial -#8 '(' -#8 INT_CONST 5 -#8 ')' -#8 '=' -#8 INT_CONST 120 -#8 ',' -#8 INT_CONST 2 -#8 '+' -#8 INT_CONST 2 -#8 '=' -#8 INT_CONST 5 -#8 OBJECTID or -#8 TYPEID E -#8 '=' -#8 OBJECTID mc2 -#8 ';' -#8 OBJECTID p -#8 '+' -#8 INT_CONST 1 -#8 OBJECTID resto -#8 OBJECTID p -#8 '=' -#8 INT_CONST 1 -#8 ':' -#8 ERROR "[" -#8 '@' -#8 '.' -#8 '@' -#8 OBJECTID for -#8 OBJECTID x -#8 IN -#8 OBJECTID range -#8 '(' -#8 OBJECTID len -#8 '(' -#8 OBJECTID b -#8 ')' -#8 ')' -#8 ERROR "]" -#10 INT_CONST 0007 -#10 INT_CONST 123 -#10 '+' -#10 INT_CONST 1 -#10 '-' -#10 INT_CONST 1 -#10 '+' -#10 INT_CONST 90 -#10 '-' -#10 INT_CONST 09 -#10 '+' -#10 INT_CONST 11113 -#10 '-' -#10 INT_CONST 4 -#10 OBJECTID r -#10 '*' -#10 OBJECTID a -#10 '*' -#10 OBJECTID self -#10 '*' -#10 OBJECTID c -#10 '+' -#10 '+' -*) +(* Integers, Identifiers, and Special Notation *) + + +loop pool while tRuE or noT faLsE let in case of ESAC +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: [@.@ for x in range(len(b))] + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ + +(* +#4 LOOP +#4 POOL +#4 WHILE +#4 BOOL_CONST true +#4 OBJECTID or +#4 NOT +#4 BOOL_CONST false +#4 LET +#4 IN +#4 CASE +#4 OF +#4 ESAC +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#6 CLASS +#6 CLASS +#6 IF +#6 THEN +#6 ELSE +#6 FI +#6 OBJECTID testing +#6 TYPEID Testing +#6 '~' +#6 INT_CONST 007 +#6 OBJECTID agent_bond +#6 OBJECTID james_007bones___ +#8 OBJECTID factorial +#8 '(' +#8 INT_CONST 5 +#8 ')' +#8 '=' +#8 INT_CONST 120 +#8 ',' +#8 INT_CONST 2 +#8 '+' +#8 INT_CONST 2 +#8 '=' +#8 INT_CONST 5 +#8 OBJECTID or +#8 TYPEID E +#8 '=' +#8 OBJECTID mc2 +#8 ';' +#8 OBJECTID p +#8 '+' +#8 INT_CONST 1 +#8 OBJECTID resto +#8 OBJECTID p +#8 '=' +#8 INT_CONST 1 +#8 ':' +#8 ERROR "[" +#8 '@' +#8 '.' +#8 '@' +#8 OBJECTID for +#8 OBJECTID x +#8 IN +#8 OBJECTID range +#8 '(' +#8 OBJECTID len +#8 '(' +#8 OBJECTID b +#8 ')' +#8 ')' +#8 ERROR "]" +#10 INT_CONST 0007 +#10 INT_CONST 123 +#10 '+' +#10 INT_CONST 1 +#10 '-' +#10 INT_CONST 1 +#10 '+' +#10 INT_CONST 90 +#10 '-' +#10 INT_CONST 09 +#10 '+' +#10 INT_CONST 11113 +#10 '-' +#10 INT_CONST 4 +#10 OBJECTID r +#10 '*' +#10 OBJECTID a +#10 '*' +#10 OBJECTID self +#10 '*' +#10 OBJECTID c +#10 '+' +#10 '+' +*) diff --git a/tests/lexer/iis5_error.txt b/tests/lexer/iis5_error.txt index 9d6e1a738..b3dbadcb6 100644 --- a/tests/lexer/iis5_error.txt +++ b/tests/lexer/iis5_error.txt @@ -1,2 +1,2 @@ -(8, 62) - LexicographicError: ERROR "[" -(8, 89) - LexicographicError: ERROR "]" +(8, 62) - LexicographicError: ERROR "[" +(8, 89) - LexicographicError: ERROR "]" diff --git a/tests/lexer/iis6.cl b/tests/lexer/iis6.cl index ba93b19d9..1042f132b 100644 --- a/tests/lexer/iis6.cl +++ b/tests/lexer/iis6.cl @@ -1,125 +1,125 @@ -(* Integers, Identifiers, and Special Notation *) - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: {@.@ for x in range(len(b))} - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) - - -class Class if then else fi testing Testing ~007agent_bond _james_007bones___ - - - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -loop pool while tRuE or noT faLsE let in case of ESAC - -(* -#3 OBJECTID factorial -#3 '(' -#3 INT_CONST 5 -#3 ')' -#3 '=' -#3 INT_CONST 120 -#3 ',' -#3 INT_CONST 2 -#3 '+' -#3 INT_CONST 2 -#3 '=' -#3 INT_CONST 5 -#3 OBJECTID or -#3 TYPEID E -#3 '=' -#3 OBJECTID mc2 -#3 ';' -#3 OBJECTID p -#3 '+' -#3 INT_CONST 1 -#3 OBJECTID resto -#3 OBJECTID p -#3 '=' -#3 INT_CONST 1 -#3 ':' -#3 '{' -#3 '@' -#3 '.' -#3 '@' -#3 OBJECTID for -#3 OBJECTID x -#3 IN -#3 OBJECTID range -#3 '(' -#3 OBJECTID len -#3 '(' -#3 OBJECTID b -#3 ')' -#3 ')' -#3 '}' -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#8 CLASS -#8 CLASS -#8 IF -#8 THEN -#8 ELSE -#8 FI -#8 OBJECTID testing -#8 TYPEID Testing -#8 '~' -#8 INT_CONST 007 -#8 OBJECTID agent_bond -#8 ERROR "_" -#8 OBJECTID james_007bones___ -#12 INT_CONST 0007 -#12 INT_CONST 123 -#12 '+' -#12 INT_CONST 1 -#12 '-' -#12 INT_CONST 1 -#12 '+' -#12 INT_CONST 90 -#12 '-' -#12 INT_CONST 09 -#12 '+' -#12 INT_CONST 11113 -#12 '-' -#12 INT_CONST 4 -#12 OBJECTID r -#12 '*' -#12 OBJECTID a -#12 '*' -#12 OBJECTID self -#12 '*' -#12 OBJECTID c -#12 '+' -#12 '+' -#13 LOOP -#13 POOL -#13 WHILE -#13 BOOL_CONST true -#13 OBJECTID or -#13 NOT -#13 BOOL_CONST false -#13 LET -#13 IN -#13 CASE -#13 OF -#13 ESAC +(* Integers, Identifiers, and Special Notation *) + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: {@.@ for x in range(len(b))} + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) + + +class Class if then else fi testing Testing ~007agent_bond _james_007bones___ + + + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +loop pool while tRuE or noT faLsE let in case of ESAC + +(* +#3 OBJECTID factorial +#3 '(' +#3 INT_CONST 5 +#3 ')' +#3 '=' +#3 INT_CONST 120 +#3 ',' +#3 INT_CONST 2 +#3 '+' +#3 INT_CONST 2 +#3 '=' +#3 INT_CONST 5 +#3 OBJECTID or +#3 TYPEID E +#3 '=' +#3 OBJECTID mc2 +#3 ';' +#3 OBJECTID p +#3 '+' +#3 INT_CONST 1 +#3 OBJECTID resto +#3 OBJECTID p +#3 '=' +#3 INT_CONST 1 +#3 ':' +#3 '{' +#3 '@' +#3 '.' +#3 '@' +#3 OBJECTID for +#3 OBJECTID x +#3 IN +#3 OBJECTID range +#3 '(' +#3 OBJECTID len +#3 '(' +#3 OBJECTID b +#3 ')' +#3 ')' +#3 '}' +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#8 CLASS +#8 CLASS +#8 IF +#8 THEN +#8 ELSE +#8 FI +#8 OBJECTID testing +#8 TYPEID Testing +#8 '~' +#8 INT_CONST 007 +#8 OBJECTID agent_bond +#8 ERROR "_" +#8 OBJECTID james_007bones___ +#12 INT_CONST 0007 +#12 INT_CONST 123 +#12 '+' +#12 INT_CONST 1 +#12 '-' +#12 INT_CONST 1 +#12 '+' +#12 INT_CONST 90 +#12 '-' +#12 INT_CONST 09 +#12 '+' +#12 INT_CONST 11113 +#12 '-' +#12 INT_CONST 4 +#12 OBJECTID r +#12 '*' +#12 OBJECTID a +#12 '*' +#12 OBJECTID self +#12 '*' +#12 OBJECTID c +#12 '+' +#12 '+' +#13 LOOP +#13 POOL +#13 WHILE +#13 BOOL_CONST true +#13 OBJECTID or +#13 NOT +#13 BOOL_CONST false +#13 LET +#13 IN +#13 CASE +#13 OF +#13 ESAC *) \ No newline at end of file diff --git a/tests/lexer/iis6_error.txt b/tests/lexer/iis6_error.txt index 79a9d5aee..d7fad9c79 100644 --- a/tests/lexer/iis6_error.txt +++ b/tests/lexer/iis6_error.txt @@ -1 +1 @@ -(8, 60) - LexicographicError: ERROR "_" +(8, 60) - LexicographicError: ERROR "_" diff --git a/tests/lexer/mixed1.cl b/tests/lexer/mixed1.cl index d3e520a10..803d58ef5 100644 --- a/tests/lexer/mixed1.cl +++ b/tests/lexer/mixed1.cl @@ -1,14 +1,14 @@ -"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 -adsfasklj# -LKldsajf iNhERITS -"lkdsajf" - -(* -#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" -#1 INT_CONST 123 -#2 OBJECTID adsfasklj -#2 ERROR "#" -#3 TYPEID LKldsajf -#3 INHERITS -#4 STR_CONST "lkdsajf" +"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 +adsfasklj# +LKldsajf iNhERITS +"lkdsajf" + +(* +#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" +#1 INT_CONST 123 +#2 OBJECTID adsfasklj +#2 ERROR "#" +#3 TYPEID LKldsajf +#3 INHERITS +#4 STR_CONST "lkdsajf" *) \ No newline at end of file diff --git a/tests/lexer/mixed1_error.txt b/tests/lexer/mixed1_error.txt index a142c2edd..99af5fbdc 100644 --- a/tests/lexer/mixed1_error.txt +++ b/tests/lexer/mixed1_error.txt @@ -1 +1 @@ -(2, 10) - LexicographicError: ERROR "#" +(2, 10) - LexicographicError: ERROR "#" diff --git a/tests/lexer/mixed2.cl b/tests/lexer/mixed2.cl index 759bf9523..12039e123 100644 --- a/tests/lexer/mixed2.cl +++ b/tests/lexer/mixed2.cl @@ -1,20 +1,20 @@ -"kjas\"lnnsdj\nfljrdsaf" -@.$.@ -@*%*@ -"alkjfldajf""dasfadsf - -(* -#1 STR_CONST "kjas\"lnnsdj\nfljrdsaf" -#2 '@' -#2 '.' -#2 ERROR "$" -#2 '.' -#2 '@' -#3 '@' -#3 '*' -#3 ERROR "%" -#3 '*' -#3 '@' -#4 STR_CONST "alkjfldajf" -#4 ERROR "Unterminated string constant" +"kjas\"lnnsdj\nfljrdsaf" +@.$.@ +@*%*@ +"alkjfldajf""dasfadsf + +(* +#1 STR_CONST "kjas\"lnnsdj\nfljrdsaf" +#2 '@' +#2 '.' +#2 ERROR "$" +#2 '.' +#2 '@' +#3 '@' +#3 '*' +#3 ERROR "%" +#3 '*' +#3 '@' +#4 STR_CONST "alkjfldajf" +#4 ERROR "Unterminated string constant" *) \ No newline at end of file diff --git a/tests/lexer/mixed2_error.txt b/tests/lexer/mixed2_error.txt index 37cb73ac2..097dc2a07 100644 --- a/tests/lexer/mixed2_error.txt +++ b/tests/lexer/mixed2_error.txt @@ -1,3 +1,3 @@ -(2, 3) - LexicographicError: ERROR "$" -(3, 3) - LexicographicError: ERROR "%" -(4, 22) - LexicographicError: Unterminated string constant +(2, 3) - LexicographicError: ERROR "$" +(3, 3) - LexicographicError: ERROR "%" +(4, 22) - LexicographicError: Unterminated string constant diff --git a/tests/lexer/string1.cl b/tests/lexer/string1.cl index f0a5bd873..6c3c00833 100644 --- a/tests/lexer/string1.cl +++ b/tests/lexer/string1.cl @@ -1,6 +1,6 @@ -(* A non-escaped newline character may not appear in a string *) - -"This \ -is OK" -"This is not +(* A non-escaped newline character may not appear in a string *) + +"This \ +is OK" +"This is not OK" \ No newline at end of file diff --git a/tests/lexer/string1_error.txt b/tests/lexer/string1_error.txt index 1dd4d70d9..078c12bbb 100644 --- a/tests/lexer/string1_error.txt +++ b/tests/lexer/string1_error.txt @@ -1,2 +1,2 @@ -(5, 13) - LexicographicError: Unterminated string constant +(5, 13) - LexicographicError: Unterminated string constant (6, 4) - LexicographicError: EOF in string constant \ No newline at end of file diff --git a/tests/lexer/string2.cl b/tests/lexer/string2.cl index cb3024180..3704b6ae7 100644 --- a/tests/lexer/string2.cl +++ b/tests/lexer/string2.cl @@ -1,19 +1,19 @@ -(* A string may not contain EOF *) - -" May the Triforce \ - 0 \ - 0v0 \ - 0vvv0 \ - 0vvvvv0 \ - 0vvvvvvv0 \ - 0vvvvvvvvv0 \ - 0vvvvvvvvvvv0 \ - 000000000000000 \ - 0v0 0v0 \ - 0vvv0 0vvv0 \ - 0vvvvv0 0vvvvv0 \ - 0vvvvvvv0 0vvvvvvv0 \ - 0vvvvvvvvv0 0vvvvvvvvv0 \ - 0vvvvvvvvvvv0 0vvvvvvvvvvv0 \ - 00000000000000000000000000000 \ +(* A string may not contain EOF *) + +" May the Triforce \ + 0 \ + 0v0 \ + 0vvv0 \ + 0vvvvv0 \ + 0vvvvvvv0 \ + 0vvvvvvvvv0 \ + 0vvvvvvvvvvv0 \ + 000000000000000 \ + 0v0 0v0 \ + 0vvv0 0vvv0 \ + 0vvvvv0 0vvvvv0 \ + 0vvvvvvv0 0vvvvvvv0 \ + 0vvvvvvvvv0 0vvvvvvvvv0 \ + 0vvvvvvvvvvv0 0vvvvvvvvvvv0 \ + 00000000000000000000000000000 \ be with you! \ No newline at end of file diff --git a/tests/lexer/string4.cl b/tests/lexer/string4.cl index 7ca4eb42b..f4d39c027 100644 --- a/tests/lexer/string4.cl +++ b/tests/lexer/string4.cl @@ -1,38 +1,38 @@ -class Main { - str <- "The big brown fox - jumped over the fence"; - main() : Object { - { - out_string("Yay! This is the newest shites ); - } - }; -}; - -(* -#1 CLASS -#1 TYPEID Main -#1 '{' -#2 OBJECTID str -#2 ASSIGN -#3 ERROR "Unterminated string constant" -#3 OBJECTID jumped -#3 OBJECTID over -#3 OBJECTID the -#3 OBJECTID fence -#4 ERROR "Unterminated string constant" -#4 OBJECTID main -#4 '(' -#4 ')' -#4 ':' -#4 TYPEID Object -#4 '{' -#5 '{' -#6 OBJECTID out_string -#6 '(' -#7 ERROR "Unterminated string constant" -#7 '}' -#8 '}' -#8 ';' -#9 '}' -#9 ';' +class Main { + str <- "The big brown fox + jumped over the fence"; + main() : Object { + { + out_string("Yay! This is the newest shites ); + } + }; +}; + +(* +#1 CLASS +#1 TYPEID Main +#1 '{' +#2 OBJECTID str +#2 ASSIGN +#3 ERROR "Unterminated string constant" +#3 OBJECTID jumped +#3 OBJECTID over +#3 OBJECTID the +#3 OBJECTID fence +#4 ERROR "Unterminated string constant" +#4 OBJECTID main +#4 '(' +#4 ')' +#4 ':' +#4 TYPEID Object +#4 '{' +#5 '{' +#6 OBJECTID out_string +#6 '(' +#7 ERROR "Unterminated string constant" +#7 '}' +#8 '}' +#8 ';' +#9 '}' +#9 ';' *) \ No newline at end of file diff --git a/tests/lexer/string4_error.txt b/tests/lexer/string4_error.txt index bf420217c..5ab0ea847 100644 --- a/tests/lexer/string4_error.txt +++ b/tests/lexer/string4_error.txt @@ -1,3 +1,3 @@ -(2, 30) - LexicographicError: Unterminated string constant -(3, 36) - LexicographicError: Unterminated string constant +(2, 30) - LexicographicError: Unterminated string constant +(3, 36) - LexicographicError: Unterminated string constant (6, 58) - LexicographicError: Unterminated string constant \ No newline at end of file diff --git a/tests/lexer_test.py b/tests/lexer_test.py index a21fd880a..2a27223d3 100644 --- a/tests/lexer_test.py +++ b/tests/lexer_test.py @@ -1,13 +1,13 @@ -import pytest -import os -from utils import compare_errors - -tests_dir = __file__.rpartition('/')[0] + '/lexer/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.lexer -@pytest.mark.error -@pytest.mark.run(order=1) -@pytest.mark.parametrize("cool_file", tests) -def test_lexer_errors(compiler_path, cool_file): +import pytest +import os +from utils import compare_errors + +tests_dir = __file__.rpartition('/')[0] + '/lexer/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.lexer +@pytest.mark.error +@pytest.mark.run(order=1) +@pytest.mark.parametrize("cool_file", tests) +def test_lexer_errors(compiler_path, cool_file): compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt') \ No newline at end of file diff --git a/tests/parser/assignment1.cl b/tests/parser/assignment1.cl index e89ade368..75b4c5bbd 100644 --- a/tests/parser/assignment1.cl +++ b/tests/parser/assignment1.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): String { - Test1 <- "Hello World" -- Identifiers begin with a lower case letter - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): String { + Test1 <- "Hello World" -- Identifiers begin with a lower case letter + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/assignment2.cl b/tests/parser/assignment2.cl index 7b8ed54ba..4efb96487 100644 --- a/tests/parser/assignment2.cl +++ b/tests/parser/assignment2.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 - 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): Int { - test1 <-- ~(1 + 2 + 3 + 4 + 5) -- The left side must be an expression - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 - 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): Int { + test1 <-- ~(1 + 2 + 3 + 4 + 5) -- The left side must be an expression + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/assignment3.cl b/tests/parser/assignment3.cl index f54305e27..ff633f331 100644 --- a/tests/parser/assignment3.cl +++ b/tests/parser/assignment3.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): Bool { - test1 <- true++ -- The left side must be an expression - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): Bool { + test1 <- true++ -- The left side must be an expression + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute1.cl b/tests/parser/attribute1.cl index 59740336d..063a02c02 100644 --- a/tests/parser/attribute1.cl +++ b/tests/parser/attribute1.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - -- Attributes names must begin with lowercase letters - Test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + -- Attributes names must begin with lowercase letters + Test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute2.cl b/tests/parser/attribute2.cl index 337696859..c05211483 100644 --- a/tests/parser/attribute2.cl +++ b/tests/parser/attribute2.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - -- Type names must begin with uppercase letters - test3: string <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + -- Type names must begin with uppercase letters + test3: string <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute3.cl b/tests/parser/attribute3.cl index b29b4b26d..d858ae47c 100644 --- a/tests/parser/attribute3.cl +++ b/tests/parser/attribute3.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - -- Expected '<-' not '<=' - test3: String <= "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + -- Expected '<-' not '<=' + test3: String <= "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block1.cl b/tests/parser/block1.cl index 9d2bb9107..3613d9268 100644 --- a/tests/parser/block1.cl +++ b/tests/parser/block1.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena").concat(a).concat(".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) - ElsE - new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena").concat(b).concat(".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2 -- Missing ";" - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2 -- Missing ";" + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block2.cl b/tests/parser/block2.cl index da4deca18..f485dd0b1 100644 --- a/tests/parser/block2.cl +++ b/tests/parser/block2.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena").concat(a).concat(".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) - ElsE - new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena ").concat(b).concat(".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - -- Missing "{" - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + -- Missing "{" + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block3.cl b/tests/parser/block3.cl index 0c2087707..ae1598c3b 100644 --- a/tests/parser/block3.cl +++ b/tests/parser/block3.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena ").concat(a).concat(".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) - ElsE - new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena ").concat(b).concat(".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - -- Missing "}" - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + -- Missing "}" + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block4.cl b/tests/parser/block4.cl index c144dae48..8fd883d02 100644 --- a/tests/parser/block4.cl +++ b/tests/parser/block4.cl @@ -1,88 +1,88 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - true++; -- Only expressions - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + true++; -- Only expressions + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case1.cl b/tests/parser/case1.cl index 35fe5af53..c2f508809 100644 --- a/tests/parser/case1.cl +++ b/tests/parser/case1.cl @@ -1,91 +1,91 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - -- Every case expression must have at least one branch - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + -- Every case expression must have at least one branch + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case2.cl b/tests/parser/case2.cl index 12cbb87b5..f9162e49f 100644 --- a/tests/parser/case2.cl +++ b/tests/parser/case2.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case "2 + 2" of - x: Int => new IO.out_string("Es un entero!") -- Missing ";" - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case "2 + 2" of + x: Int => new IO.out_string("Es un entero!") -- Missing ";" + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case3.cl b/tests/parser/case3.cl index 8fd851836..a7eedc18b 100644 --- a/tests/parser/case3.cl +++ b/tests/parser/case3.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + false of - x: Int => new IO.out_string("Es un entero!"); - y: string => new IO.out_string("Es una cadena!"); -- Type identifiers starts with a uppercase letter - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + false of + x: Int => new IO.out_string("Es un entero!"); + y: string => new IO.out_string("Es una cadena!"); -- Type identifiers starts with a uppercase letter + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case4.cl b/tests/parser/case4.cl index eb8a3d3a2..25ca3858f 100644 --- a/tests/parser/case4.cl +++ b/tests/parser/case4.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case true of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - Mazinger_Z: Bool => new IO.out_string("Es un booleano!"); -- Identifiers starts with a lowercase letter - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case true of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + Mazinger_Z: Bool => new IO.out_string("Es un booleano!"); -- Identifiers starts with a lowercase letter + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case5.cl b/tests/parser/case5.cl index f0483f1f5..b36c663e1 100644 --- a/tests/parser/case5.cl +++ b/tests/parser/case5.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case test2 of - x: Int <- new IO.out_string("Es un entero!"); -- Must be '=>' not '<-'; - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case test2 of + x: Int <- new IO.out_string("Es un entero!"); -- Must be '=>' not '<-'; + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case6.cl b/tests/parser/case6.cl index c49467a89..66e7df2ab 100644 --- a/tests/parser/case6.cl +++ b/tests/parser/case6.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 -- Missing "of" - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 -- Missing "of" + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/class1.cl b/tests/parser/class1.cl index 1c0641a94..f4815e3f4 100644 --- a/tests/parser/class1.cl +++ b/tests/parser/class1.cl @@ -1,20 +1,20 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - testing(): Int { - 2 + 2 - }; -}; - --- Class names must begin with uppercase letters -class alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Class names must begin with uppercase letters +class alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class2.cl b/tests/parser/class2.cl index baf290822..f363b032a 100644 --- a/tests/parser/class2.cl +++ b/tests/parser/class2.cl @@ -1,20 +1,20 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - -CLaSS Test { - testing(): Int { - 2 + 2 - }; -}; - --- Type names must begin with uppercase letters -CLaSS Alpha iNHeRiTS iO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +CLaSS Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Type names must begin with uppercase letters +CLaSS Alpha iNHeRiTS iO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class3.cl b/tests/parser/class3.cl index 5c89c5eb8..0c801372a 100644 --- a/tests/parser/class3.cl +++ b/tests/parser/class3.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Missing semicolon - testing2(a: Alpha, b: Int): Int { - 2 + 2 - } - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Missing semicolon + testing2(a: Alpha, b: Int): Int { + 2 + 2 + } + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class4.cl b/tests/parser/class4.cl index cdfbc313c..5c286b5e6 100644 --- a/tests/parser/class4.cl +++ b/tests/parser/class4.cl @@ -1,36 +1,36 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - -CLaSS Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Only features - 2 + 2; - - testing3(): String { - "2 + 2" - }; -}; - -CLaSS Alpha iNHeRiTS IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +CLaSS Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Only features + 2 + 2; + + testing3(): String { + "2 + 2" + }; +}; + +CLaSS Alpha iNHeRiTS IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class5.cl b/tests/parser/class5.cl index d6b5c5fda..3f40c36eb 100644 --- a/tests/parser/class5.cl +++ b/tests/parser/class5.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing '{' -class Test - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing '{' +class Test + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class6.cl b/tests/parser/class6.cl index af9ecbf15..8501d2593 100644 --- a/tests/parser/class6.cl +++ b/tests/parser/class6.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing '}' -CLaSS Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -; - -CLaSS Alpha iNHeRiTS IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing '}' +CLaSS Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +; + +CLaSS Alpha iNHeRiTS IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/conditional1.cl b/tests/parser/conditional1.cl index f03b9c4e6..4d546fc44 100644 --- a/tests/parser/conditional1.cl +++ b/tests/parser/conditional1.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - if a.length() < b.length() -- Mising "then" - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - else - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - else - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fi - fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + if a.length() < b.length() -- Mising "then" + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + else + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + else + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fi + fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional2.cl b/tests/parser/conditional2.cl index 9ebd7fe84..4f10c2957 100644 --- a/tests/parser/conditional2.cl +++ b/tests/parser/conditional2.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - if a.length() < b.length() then - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - else - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - else - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - -- Missing "fi" - fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + if a.length() < b.length() then + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + else + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + else + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + -- Missing "fi" + fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional3.cl b/tests/parser/conditional3.cl index ac143ad42..67e991ade 100644 --- a/tests/parser/conditional3.cl +++ b/tests/parser/conditional3.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - iF a.length() < b.length() tHen - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - elsE - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - eLseif -- elseif isn't a keyword - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + iF a.length() < b.length() tHen + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + elsE + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + eLseif -- elseif isn't a keyword + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional4.cl b/tests/parser/conditional4.cl index 51337f874..0792fdc85 100644 --- a/tests/parser/conditional4.cl +++ b/tests/parser/conditional4.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true++ then 1 else 0 -- Condition must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true++ then 1 else 0 -- Condition must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional5.cl b/tests/parser/conditional5.cl index 399515701..0c1e1aad0 100644 --- a/tests/parser/conditional5.cl +++ b/tests/parser/conditional5.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true then true++ else 0 -- If branch must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true then true++ else 0 -- If branch must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional6.cl b/tests/parser/conditional6.cl index 8daa35d7f..02310404a 100644 --- a/tests/parser/conditional6.cl +++ b/tests/parser/conditional6.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true then 1 else false++ -- Else branch must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true then 1 else false++ -- Else branch must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch1.cl b/tests/parser/dispatch1.cl index 2eba9db03..2ca394716 100644 --- a/tests/parser/dispatch1.cl +++ b/tests/parser/dispatch1.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - Test1.testing4(1, 2).testing4(3, 4).testing4(5, 6) -- Objet identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + Test1.testing4(1, 2).testing4(3, 4).testing4(5, 6) -- Objet identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch2.cl b/tests/parser/dispatch2.cl index 139eba918..0b57467a1 100644 --- a/tests/parser/dispatch2.cl +++ b/tests/parser/dispatch2.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13,) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13,) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch3.cl b/tests/parser/dispatch3.cl index 0d88f5c23..9f1a5afff 100644 --- a/tests/parser/dispatch3.cl +++ b/tests/parser/dispatch3.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).Testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) -- Identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).Testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) -- Identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch4.cl b/tests/parser/dispatch4.cl index dc13fd762..d1efc469d 100644 --- a/tests/parser/dispatch4.cl +++ b/tests/parser/dispatch4.cl @@ -1,53 +1,53 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - self.testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true++) -- Arguments must be expressions - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + self.testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true++) -- Arguments must be expressions + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch5.cl b/tests/parser/dispatch5.cl index b7bae25e1..63a5afa79 100644 --- a/tests/parser/dispatch5.cl +++ b/tests/parser/dispatch5.cl @@ -1,53 +1,53 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, ,true + fALSE) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, ,true + fALSE) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch6.cl b/tests/parser/dispatch6.cl index 6887c60cd..0a953e2e6 100644 --- a/tests/parser/dispatch6.cl +++ b/tests/parser/dispatch6.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@object.copy() -- Type identifiers begin with a upper case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@object.copy() -- Type identifiers begin with a upper case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch7.cl b/tests/parser/dispatch7.cl index a9ff1b67a..3ecac4d0f 100644 --- a/tests/parser/dispatch7.cl +++ b/tests/parser/dispatch7.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.Copy() -- Identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.Copy() -- Identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch8.cl b/tests/parser/dispatch8.cl index c1bb2abba..eef0455ef 100644 --- a/tests/parser/dispatch8.cl +++ b/tests/parser/dispatch8.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy(,) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy(,) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch9.cl b/tests/parser/dispatch9.cl index 8914a18c2..5fdef22d6 100644 --- a/tests/parser/dispatch9.cl +++ b/tests/parser/dispatch9.cl @@ -1,61 +1,61 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; - - testing5(): Object { - test1:Object.copy() -- Must be '@' not ':' - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; + + testing5(): Object { + test1:Object.copy() -- Must be '@' not ':' + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let1.cl b/tests/parser/let1.cl index 0e5fc6d17..576ae383c 100644 --- a/tests/parser/let1.cl +++ b/tests/parser/let1.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let Count: Int <- 0, pow: Int <- 1 -- Object identifiers starts with a lowercase letter - in { - -- count <- 0; - -- pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let Count: Int <- 0, pow: Int <- 1 -- Object identifiers starts with a lowercase letter + in { + -- count <- 0; + -- pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let2.cl b/tests/parser/let2.cl index aa38fe9a6..4cfaef0f8 100644 --- a/tests/parser/let2.cl +++ b/tests/parser/let2.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena ").concat(a).concat(".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena ".concat(a).concat("mide igual que la cadena ").concat(b).concat(".")) - ElsE - new IO.out_string("La cadena ".concat(a).concat("es mas larga que la cadena ").concat(b).concat(".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int, pow: int <- 1 -- Type identifiers starts with a uppercase letter - in { - count <- 0; - -- pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int, pow: int <- 1 -- Type identifiers starts with a uppercase letter + in { + count <- 0; + -- pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let3.cl b/tests/parser/let3.cl index b2b2fb005..91e567fd8 100644 --- a/tests/parser/let3.cl +++ b/tests/parser/let3.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int, pow: Int, -- Extra comma - in { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int, pow: Int, -- Extra comma + in { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let4.cl b/tests/parser/let4.cl index c7d0ea8e3..a716c332d 100644 --- a/tests/parser/let4.cl +++ b/tests/parser/let4.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- true++, pow: Int <- 1 -- Initialization must be an expression - in { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- true++, pow: Int <- 1 -- Initialization must be an expression + in { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let5.cl b/tests/parser/let5.cl index cc4ed7a99..d974cc138 100644 --- a/tests/parser/let5.cl +++ b/tests/parser/let5.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int = 0, pow: Int -- Must be '<-' not '=' - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int = 0, pow: Int -- Must be '<-' not '=' + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let6.cl b/tests/parser/let6.cl index 8bc8c4883..b6e51d7e1 100644 --- a/tests/parser/let6.cl +++ b/tests/parser/let6.cl @@ -1,74 +1,74 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int <- 1 - in false++ -- Let body must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int <- 1 + in false++ -- Let body must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let7.cl b/tests/parser/let7.cl index 816c59845..6fd63e6a7 100644 --- a/tests/parser/let7.cl +++ b/tests/parser/let7.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - (* Missing "in" *) { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + (* Missing "in" *) { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop1.cl b/tests/parser/loop1.cl index 2065de506..7d0d7688f 100644 --- a/tests/parser/loop1.cl +++ b/tests/parser/loop1.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - -- Missing "loop" - count <- count * 2 - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + -- Missing "loop" + count <- count * 2 + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop2.cl b/tests/parser/loop2.cl index 857ffdc39..a9613c487 100644 --- a/tests/parser/loop2.cl +++ b/tests/parser/loop2.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena ").concat(a).concat(".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) - ElsE - new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena ").concat(b).concat(".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - loop - count <- count * 2 - -- Missing "pool" - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + loop + count <- count * 2 + -- Missing "pool" + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop3.cl b/tests/parser/loop3.cl index fbb3a56b4..860adb4d1 100644 --- a/tests/parser/loop3.cl +++ b/tests/parser/loop3.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count => 1024*1024 -- Condition must be an expression - loop - count <- count * 2 - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count => 1024*1024 -- Condition must be an expression + loop + count <- count * 2 + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop4.cl b/tests/parser/loop4.cl index 47b0e5f4a..0a1194e82 100644 --- a/tests/parser/loop4.cl +++ b/tests/parser/loop4.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - loop - count <- true++ -- While body must be an expression - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + loop + count <- true++ -- While body must be an expression + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method1.cl b/tests/parser/method1.cl index d86661430..fcfbbcd30 100644 --- a/tests/parser/method1.cl +++ b/tests/parser/method1.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Method names must begin with lowercase letters - Testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Method names must begin with lowercase letters + Testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method2.cl b/tests/parser/method2.cl index 83648f50d..d5bdfd85c 100644 --- a/tests/parser/method2.cl +++ b/tests/parser/method2.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Parameter names must begin with lowercase letters - testing2(a: Alpha, B: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Parameter names must begin with lowercase letters + testing2(a: Alpha, B: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method3.cl b/tests/parser/method3.cl index 428b25fec..1e5c9eb53 100644 --- a/tests/parser/method3.cl +++ b/tests/parser/method3.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Type names must begin with uppercase letters - testing2(a: Alpha, b: int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Type names must begin with uppercase letters + testing2(a: Alpha, b: int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method4.cl b/tests/parser/method4.cl index 52ec07bce..019ada276 100644 --- a/tests/parser/method4.cl +++ b/tests/parser/method4.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Missing paremeter - testing3(x: Int,): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Missing paremeter + testing3(x: Int,): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method5.cl b/tests/parser/method5.cl index 706a3145c..13127f664 100644 --- a/tests/parser/method5.cl +++ b/tests/parser/method5.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Type names must begin with uppercase letters - testing3(): string { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Type names must begin with uppercase letters + testing3(): string { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method6.cl b/tests/parser/method6.cl index 26ce7f19f..d48cd1293 100644 --- a/tests/parser/method6.cl +++ b/tests/parser/method6.cl @@ -1,33 +1,33 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Body can't be empty - testing2(a: Alpha, b: Int): Int { - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Body can't be empty + testing2(a: Alpha, b: Int): Int { + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/mixed1.cl b/tests/parser/mixed1.cl index b13e679da..a27879513 100644 --- a/tests/parser/mixed1.cl +++ b/tests/parser/mixed1.cl @@ -1,100 +1,100 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}-- Mising ";" - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}-- Mising ";" + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/mixed2.cl b/tests/parser/mixed2.cl index 6776fcc12..f5477e0bb 100644 --- a/tests/parser/mixed2.cl +++ b/tests/parser/mixed2.cl @@ -1,14 +1,14 @@ -class Main { - main(): Object { - (new Alpha).print() - }; - -}; - -(* Class names must begin with uppercase letters *) -class alpha inherits IO { - print() : Object { - out_string("reached!!\n"); - }; -}; - +class Main { + main(): Object { + (new Alpha).print() + }; + +}; + +(* Class names must begin with uppercase letters *) +class alpha inherits IO { + print() : Object { + out_string("reached!!\n"); + }; +}; + diff --git a/tests/parser/mixed3.cl b/tests/parser/mixed3.cl index f5271eb3e..1bdcad743 100644 --- a/tests/parser/mixed3.cl +++ b/tests/parser/mixed3.cl @@ -1,40 +1,40 @@ -class Main inherits IO { - main() : Object { - { - out_string("Enter a number to check if number is prime\n"); - let i : Int <- in_int() in { - if(i <= 1) then { - out_string("Invalid Input\n"); - abort(); - } else { - if (isPrime(i) = 1) then - out_string("Number is prime\n") - else - out_string("Number is composite\n") - fi; - } - fi; - }; - } - }; - - mod(i : Int, ) : Int { -- Formal list must be comma separated. A comma does not terminate a list of formals. - i - (i/k)*k - }; - - isPrime(i : Int) : Int { - { - let x : Int <- 2, - c : Int <- 1 in - { - while (not (x = i)) loop - if (mod(i, x) = 0) then { - c <- 0; - x <- i; - } else x <- x + 1 fi - pool; - c; - }; - } - }; -}; +class Main inherits IO { + main() : Object { + { + out_string("Enter a number to check if number is prime\n"); + let i : Int <- in_int() in { + if(i <= 1) then { + out_string("Invalid Input\n"); + abort(); + } else { + if (isPrime(i) = 1) then + out_string("Number is prime\n") + else + out_string("Number is composite\n") + fi; + } + fi; + }; + } + }; + + mod(i : Int, ) : Int { -- Formal list must be comma separated. A comma does not terminate a list of formals. + i - (i/k)*k + }; + + isPrime(i : Int) : Int { + { + let x : Int <- 2, + c : Int <- 1 in + { + while (not (x = i)) loop + if (mod(i, x) = 0) then { + c <- 0; + x <- i; + } else x <- x + 1 fi + pool; + c; + }; + } + }; +}; diff --git a/tests/parser/mixed4.cl b/tests/parser/mixed4.cl index 47e6ea5e9..e752253be 100644 --- a/tests/parser/mixed4.cl +++ b/tests/parser/mixed4.cl @@ -1,21 +1,21 @@ -class Main inherits IO { - main() : Object { - { - out_string("Enter number of numbers to multiply\n"); - out_int(prod(in_int())); - out_string("\n"); - } - }; - - prod(i : Int) : Int { - let y : Int <- 1 in { - while (not (i = 0) ) loop { - out_string("Enter Number: "); - y <- y * in_int(Main : Int); -- the parser correctly catches the error here - i <- i - 1; - } - pool; - y; - } - }; -}; +class Main inherits IO { + main() : Object { + { + out_string("Enter number of numbers to multiply\n"); + out_int(prod(in_int())); + out_string("\n"); + } + }; + + prod(i : Int) : Int { + let y : Int <- 1 in { + while (not (i = 0) ) loop { + out_string("Enter Number: "); + y <- y * in_int(Main : Int); -- the parser correctly catches the error here + i <- i - 1; + } + pool; + y; + } + }; +}; diff --git a/tests/parser/mixed5.cl b/tests/parser/mixed5.cl index d4ca68f44..c9176a890 100644 --- a/tests/parser/mixed5.cl +++ b/tests/parser/mixed5.cl @@ -1,20 +1,20 @@ -class Main inherits IO { - str <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; - main() : Object { - { - out_string("Enter number of numbers to multiply\n"); - out_int(prod(in_int())); - out_string("\n"); - } - }; - prod(i : Int) : Int { - let y : Int <- 1 in { - while (not (i = 0) ) loop { - out_string("Enter Number: "); - y <- y * in_int(); - i <- i - 1; - } - y; - } - }; -} +class Main inherits IO { + str <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; + main() : Object { + { + out_string("Enter number of numbers to multiply\n"); + out_int(prod(in_int())); + out_string("\n"); + } + }; + prod(i : Int) : Int { + let y : Int <- 1 in { + while (not (i = 0) ) loop { + out_string("Enter Number: "); + y <- y * in_int(); + i <- i - 1; + } + y; + } + }; +} diff --git a/tests/parser/mixed6.cl b/tests/parser/mixed6.cl index 0a51656c9..5da80da31 100644 --- a/tests/parser/mixed6.cl +++ b/tests/parser/mixed6.cl @@ -1,5 +1,5 @@ -classs Doom { - i : Int <- 0; - main() : Object { - if i = 0 then out_string("This is da real *h*t") - +classs Doom { + i : Int <- 0; + main() : Object { + if i = 0 then out_string("This is da real *h*t") + diff --git a/tests/parser/operation1.cl b/tests/parser/operation1.cl index d892ec8a6..d38eb72d0 100644 --- a/tests/parser/operation1.cl +++ b/tests/parser/operation1.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Missing ')' - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a)/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Missing ')' + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a)/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation2.cl b/tests/parser/operation2.cl index 234fe2bc5..2dc628359 100644 --- a/tests/parser/operation2.cl +++ b/tests/parser/operation2.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena ".concat(b).concat(" es mas larga que la cadena ").concat(a).concat("\.")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena ".concat(a).concat(" mide igual que la cadena ").concat(b).concat(".")) - ElsE - new IO.out_string("La cadena ".concat(a).concat(" es mas larga que la cadena ").concat(b).concat(".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Type identifiers starts with a uppercase letter - in isvoid (3 + a * (x / w + new int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Type identifiers starts with a uppercase letter + in isvoid (3 + a * (x / w + new int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation3.cl b/tests/parser/operation3.cl index ef125927a..61d6cbfa8 100644 --- a/tests/parser/operation3.cl +++ b/tests/parser/operation3.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Object identifiers starts with a lowercase letter - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~Mazinger_Z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Object identifiers starts with a lowercase letter + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~Mazinger_Z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation4.cl b/tests/parser/operation4.cl index 2212740e7..bae7de5b5 100644 --- a/tests/parser/operation4.cl +++ b/tests/parser/operation4.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Double "+" - in isvoid (3 + a * (x / w++ new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Double "+" + in isvoid (3 + a * (x / w++ new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/program2.cl b/tests/parser/program2.cl index a281c6c14..f8b16779c 100644 --- a/tests/parser/program2.cl +++ b/tests/parser/program2.cl @@ -1,20 +1,20 @@ -(* Cool programs are sets of classes *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing semicolon -class Test { - testing(): Int { - 2 + 2 - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* Cool programs are sets of classes *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing semicolon +class Test { + testing(): Int { + 2 + 2 + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/program3.cl b/tests/parser/program3.cl index 10d2dc71e..e27889c57 100644 --- a/tests/parser/program3.cl +++ b/tests/parser/program3.cl @@ -1,24 +1,24 @@ -(* Cool programs are sets of classes *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - testing(): Int { - 2 + 2 - }; -}; - --- Only classes -suma(a: Int, b: Int) int { - a + b -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* Cool programs are sets of classes *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Only classes +suma(a: Int, b: Int) int { + a + b +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser_test.py b/tests/parser_test.py index 166de45de..129c0f20a 100644 --- a/tests/parser_test.py +++ b/tests/parser_test.py @@ -1,13 +1,13 @@ -import pytest -import os -from utils import compare_errors - -tests_dir = __file__.rpartition('/')[0] + '/parser/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.parser -@pytest.mark.error -@pytest.mark.run(order=2) -@pytest.mark.parametrize("cool_file", tests) -def test_parser_errors(compiler_path, cool_file): +import pytest +import os +from utils import compare_errors + +tests_dir = __file__.rpartition('/')[0] + '/parser/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.parser +@pytest.mark.error +@pytest.mark.run(order=2) +@pytest.mark.parametrize("cool_file", tests) +def test_parser_errors(compiler_path, cool_file): compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt') \ No newline at end of file diff --git a/tests/semantic/arithmetic1.cl b/tests/semantic/arithmetic1.cl index 65719c064..bf94eb194 100644 --- a/tests/semantic/arithmetic1.cl +++ b/tests/semantic/arithmetic1.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic10.cl b/tests/semantic/arithmetic10.cl index b2488ad7f..bbfe6cdb3 100644 --- a/tests/semantic/arithmetic10.cl +++ b/tests/semantic/arithmetic10.cl @@ -1,15 +1,15 @@ -(* -The expression ~ is the integer -complement of . The expression must have static type Int and the entire expression -has static type Int. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in ~new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression ~ is the integer +complement of . The expression must have static type Int and the entire expression +has static type Int. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in ~new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic11.cl b/tests/semantic/arithmetic11.cl index 05cec0465..fc067dc1a 100644 --- a/tests/semantic/arithmetic11.cl +++ b/tests/semantic/arithmetic11.cl @@ -1,14 +1,14 @@ -(* -The expression not is the boolean complement of . The expression - must have static type Bool and the entire expression has static type Bool. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in not 1 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression not is the boolean complement of . The expression + must have static type Bool and the entire expression has static type Bool. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in not 1 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic12.cl b/tests/semantic/arithmetic12.cl index 05a2da918..2e012fc41 100644 --- a/tests/semantic/arithmetic12.cl +++ b/tests/semantic/arithmetic12.cl @@ -1,14 +1,14 @@ -(* -The expression not is the boolean complement of . The expression - must have static type Bool and the entire expression has static type Bool. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in not 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression not is the boolean complement of . The expression + must have static type Bool and the entire expression has static type Bool. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in not 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic1_error.txt b/tests/semantic/arithmetic1_error.txt index 59213724d..a74ebf3da 100644 --- a/tests/semantic/arithmetic1_error.txt +++ b/tests/semantic/arithmetic1_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int + String +(10, 27) - TypeError: non-Int arguments: Int + String diff --git a/tests/semantic/arithmetic2.cl b/tests/semantic/arithmetic2.cl index f1f0935e2..59532573d 100644 --- a/tests/semantic/arithmetic2.cl +++ b/tests/semantic/arithmetic2.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 + 2 * 3 / 4 - new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x - new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 + 2 * 3 / 4 - new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x - new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic2_error.txt b/tests/semantic/arithmetic2_error.txt index aebc7aab9..2c7952af8 100644 --- a/tests/semantic/arithmetic2_error.txt +++ b/tests/semantic/arithmetic2_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int - String +(10, 27) - TypeError: non-Int arguments: Int - String diff --git a/tests/semantic/arithmetic3.cl b/tests/semantic/arithmetic3.cl index df64d8000..b208957f5 100644 --- a/tests/semantic/arithmetic3.cl +++ b/tests/semantic/arithmetic3.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 - 2 + 3 * 4 / new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x / new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 - 2 + 3 * 4 / new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x / new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic3_error.txt b/tests/semantic/arithmetic3_error.txt index d0af01bb5..81d88331a 100644 --- a/tests/semantic/arithmetic3_error.txt +++ b/tests/semantic/arithmetic3_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int / String +(10, 27) - TypeError: non-Int arguments: Int / String diff --git a/tests/semantic/arithmetic4.cl b/tests/semantic/arithmetic4.cl index 68512ca44..2c7dd4fc9 100644 --- a/tests/semantic/arithmetic4.cl +++ b/tests/semantic/arithmetic4.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic5.cl b/tests/semantic/arithmetic5.cl index fd77c7971..bc08c6e82 100644 --- a/tests/semantic/arithmetic5.cl +++ b/tests/semantic/arithmetic5.cl @@ -1,11 +1,11 @@ ---The static type of the expression is Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +--The static type of the expression is Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic5_error.txt b/tests/semantic/arithmetic5_error.txt index 8c67c2f53..dd5346844 100644 --- a/tests/semantic/arithmetic5_error.txt +++ b/tests/semantic/arithmetic5_error.txt @@ -1 +1 @@ -(9, 19) - TypeError: Inferred type Int of initialization of attribute test does not conform to declared type Bool. +(9, 19) - TypeError: Inferred type Int of initialization of attribute test does not conform to declared type Bool. diff --git a/tests/semantic/arithmetic6.cl b/tests/semantic/arithmetic6.cl index d4da66a73..a0c3d03ff 100644 --- a/tests/semantic/arithmetic6.cl +++ b/tests/semantic/arithmetic6.cl @@ -1,11 +1,11 @@ - --The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())); -}; + --The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; diff --git a/tests/semantic/arithmetic6_error.txt b/tests/semantic/arithmetic6_error.txt index a0d67cb48..2e43dfc17 100644 --- a/tests/semantic/arithmetic6_error.txt +++ b/tests/semantic/arithmetic6_error.txt @@ -1 +1 @@ -(10, 22) - TypeError: non-Int arguments: Int <= String +(10, 22) - TypeError: non-Int arguments: Int <= String diff --git a/tests/semantic/arithmetic7.cl b/tests/semantic/arithmetic7.cl index b98a4b0e2..c00c75cde 100644 --- a/tests/semantic/arithmetic7.cl +++ b/tests/semantic/arithmetic7.cl @@ -1,12 +1,12 @@ - --The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())); -}; - + --The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; + diff --git a/tests/semantic/arithmetic7_error.txt b/tests/semantic/arithmetic7_error.txt index 166bcc8ef..6f3537117 100644 --- a/tests/semantic/arithmetic7_error.txt +++ b/tests/semantic/arithmetic7_error.txt @@ -1 +1 @@ -(10, 22) - TypeError: non-Int arguments: Int < String +(10, 22) - TypeError: non-Int arguments: Int < String diff --git a/tests/semantic/arithmetic8.cl b/tests/semantic/arithmetic8.cl index f3ad37ec4..3210bdb8a 100644 --- a/tests/semantic/arithmetic8.cl +++ b/tests/semantic/arithmetic8.cl @@ -1,13 +1,13 @@ - --The rules are exactly the same as for the binary arithmetic operations, except that the result is a Bool. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); -}; - - + --The rules are exactly the same as for the binary arithmetic operations, except that the result is a Bool. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +}; + + diff --git a/tests/semantic/arithmetic8_error.txt b/tests/semantic/arithmetic8_error.txt index 5a8814e1a..ebcaa3797 100644 --- a/tests/semantic/arithmetic8_error.txt +++ b/tests/semantic/arithmetic8_error.txt @@ -1 +1 @@ -(9, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. +(9, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/arithmetic9.cl b/tests/semantic/arithmetic9.cl index b7b4d3645..95579e134 100644 --- a/tests/semantic/arithmetic9.cl +++ b/tests/semantic/arithmetic9.cl @@ -1,15 +1,15 @@ -(* -The expression ~ is the integer -complement of . The expression must have static type Int and the entire expression -has static type Int. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 + ~new A.type_name().concat(new B.type_name().concat(new C.type_name())); +(* +The expression ~ is the integer +complement of . The expression must have static type Int and the entire expression +has static type Int. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 + ~new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/assignment1.cl b/tests/semantic/assignment1.cl index 174f93e2b..19ab70219 100644 --- a/tests/semantic/assignment1.cl +++ b/tests/semantic/assignment1.cl @@ -1,7 +1,7 @@ ---The static type of the expression must conform to the declared type of the identifier - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: Int <- "String"; -}; +--The static type of the expression must conform to the declared type of the identifier + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: Int <- "String"; +}; diff --git a/tests/semantic/assignment1_error.txt b/tests/semantic/assignment1_error.txt index 9d05707aa..6eb883012 100644 --- a/tests/semantic/assignment1_error.txt +++ b/tests/semantic/assignment1_error.txt @@ -1 +1 @@ -(6, 18) - TypeError: Inferred type String of initialization of attribute test does not conform to declared type Int. +(6, 18) - TypeError: Inferred type String of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/assignment2.cl b/tests/semantic/assignment2.cl index c7f3d7873..cace221ae 100644 --- a/tests/semantic/assignment2.cl +++ b/tests/semantic/assignment2.cl @@ -1,13 +1,13 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A): B { a <- new C }; - test2(a: A): D { a <- new C }; -}; +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A): B { a <- new C }; + test2(a: A): D { a <- new C }; +}; diff --git a/tests/semantic/assignment2_error.txt b/tests/semantic/assignment2_error.txt index 55f5aa214..ed10b7f38 100644 --- a/tests/semantic/assignment2_error.txt +++ b/tests/semantic/assignment2_error.txt @@ -1 +1 @@ -(12, 22) - TypeError: Inferred return type C of method test2 does not conform to declared return type D. +(12, 22) - TypeError: Inferred return type C of method test2 does not conform to declared return type D. diff --git a/tests/semantic/assignment3.cl b/tests/semantic/assignment3.cl index 9d60a4b6c..eba0d69e2 100644 --- a/tests/semantic/assignment3.cl +++ b/tests/semantic/assignment3.cl @@ -1,14 +1,14 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A; - b: B <- a <- new C; - d: D <- a <- new C; -}; +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A; + b: B <- a <- new C; + d: D <- a <- new C; +}; diff --git a/tests/semantic/attributes1.cl b/tests/semantic/attributes1.cl index d11ea7cdb..3fa0440e4 100644 --- a/tests/semantic/attributes1.cl +++ b/tests/semantic/attributes1.cl @@ -1,13 +1,13 @@ ---The static type of the expression must conform to the declared type of the attribute. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - test1: IO <- new Main; - test2: B <- new A; - - main(): IO { out_string("Hello World!")}; +--The static type of the expression must conform to the declared type of the attribute. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + test1: IO <- new Main; + test2: B <- new A; + + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/attributes1_error.txt b/tests/semantic/attributes1_error.txt index 22e45b837..9cb8460c9 100644 --- a/tests/semantic/attributes1_error.txt +++ b/tests/semantic/attributes1_error.txt @@ -1 +1 @@ -(10, 17) - TypeError: Inferred type A of initialization of attribute test2 does not conform to declared type B. +(10, 17) - TypeError: Inferred type A of initialization of attribute test2 does not conform to declared type B. diff --git a/tests/semantic/attributes2.cl b/tests/semantic/attributes2.cl index 85c791b5e..7937c2cc8 100644 --- a/tests/semantic/attributes2.cl +++ b/tests/semantic/attributes2.cl @@ -1,13 +1,13 @@ ---The static type of the expression must conform to the declared type of the attribute. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - test1: IO <- new Main; - test2: C <- new D; - - main(): IO { out_string("Hello World!")}; +--The static type of the expression must conform to the declared type of the attribute. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + test1: IO <- new Main; + test2: C <- new D; + + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/attributes2_error.txt b/tests/semantic/attributes2_error.txt index d7694b0ad..6d601b7cd 100644 --- a/tests/semantic/attributes2_error.txt +++ b/tests/semantic/attributes2_error.txt @@ -1 +1 @@ -(10, 17) - TypeError: Inferred type D of initialization of attribute test2 does not conform to declared type C. +(10, 17) - TypeError: Inferred type D of initialization of attribute test2 does not conform to declared type C. diff --git a/tests/semantic/attributes3.cl b/tests/semantic/attributes3.cl index 0c8294fa2..8a67decd1 100644 --- a/tests/semantic/attributes3.cl +++ b/tests/semantic/attributes3.cl @@ -1,25 +1,25 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class B inherits A { - b: Bool <- true; -}; -class C inherits B { - c: String <- "C"; -}; -class D inherits B { - d: IO <- new Main.main(); -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!") }; +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class B inherits A { + b: Bool <- true; +}; +class C inherits B { + c: String <- "C"; +}; +class D inherits B { + d: IO <- new Main.main(); +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!") }; }; \ No newline at end of file diff --git a/tests/semantic/attributes3_error.txt b/tests/semantic/attributes3_error.txt index 68a2ba571..6195c816c 100644 --- a/tests/semantic/attributes3_error.txt +++ b/tests/semantic/attributes3_error.txt @@ -1 +1 @@ -(9, 16) - NameError: Undeclared identifier b. +(9, 16) - NameError: Undeclared identifier b. diff --git a/tests/semantic/attributes4.cl b/tests/semantic/attributes4.cl index 307b185fd..a7f63adbd 100644 --- a/tests/semantic/attributes4.cl +++ b/tests/semantic/attributes4.cl @@ -1,39 +1,39 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; -}; -class B inherits A { - b: Bool <- true; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class D inherits B { - d: IO <- new Main.main(); - test3(x1: Int, y1: Int): IO { - let x: Int <- x1, y: Int <-y1, c: String <- "C" in { - x <- x + a; - y <- y + a; - if b then new IO.out_string(c) else d fi; - } - }; -}; -class C inherits B { - c: String <- "C"; - test2(x1: Int, y1: Int): IO { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then new IO.out_string(c) else d fi; - } - }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!") }; +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; +}; +class B inherits A { + b: Bool <- true; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class D inherits B { + d: IO <- new Main.main(); + test3(x1: Int, y1: Int): IO { + let x: Int <- x1, y: Int <-y1, c: String <- "C" in { + x <- x + a; + y <- y + a; + if b then new IO.out_string(c) else d fi; + } + }; +}; +class C inherits B { + c: String <- "C"; + test2(x1: Int, y1: Int): IO { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then new IO.out_string(c) else d fi; + } + }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!") }; }; \ No newline at end of file diff --git a/tests/semantic/basics1.cl b/tests/semantic/basics1.cl index af84ca0c9..32ae16564 100644 --- a/tests/semantic/basics1.cl +++ b/tests/semantic/basics1.cl @@ -1,10 +1,10 @@ --- It is an error to redefine the IO class. - -class IO { - scan(): String { ":)" }; - print(s: String): IO { new IO }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +-- It is an error to redefine the IO class. + +class IO { + scan(): String { ":)" }; + print(s: String): IO { new IO }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/basics1_error.txt b/tests/semantic/basics1_error.txt index 0db23a051..676f5049c 100644 --- a/tests/semantic/basics1_error.txt +++ b/tests/semantic/basics1_error.txt @@ -1 +1 @@ -(3, 7) - SemanticError: Redefinition of basic class IO. +(3, 7) - SemanticError: Redefinition of basic class IO. diff --git a/tests/semantic/basics2.cl b/tests/semantic/basics2.cl index 61399a989..cf2b1cd2f 100644 --- a/tests/semantic/basics2.cl +++ b/tests/semantic/basics2.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Int. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Int { - is_prime(): Bool { false }; -}; +-- It is an error to inherit from or redefine Int. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits Int { + is_prime(): Bool { false }; +}; diff --git a/tests/semantic/basics2_error.txt b/tests/semantic/basics2_error.txt index e2810833a..69a3b6814 100644 --- a/tests/semantic/basics2_error.txt +++ b/tests/semantic/basics2_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class Int. +(7, 18) - SemanticError: Class A cannot inherit class Int. diff --git a/tests/semantic/basics3.cl b/tests/semantic/basics3.cl index 8c28b31e1..fef017a8d 100644 --- a/tests/semantic/basics3.cl +++ b/tests/semantic/basics3.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Int. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Int { - is_prime(): Bool { false }; +-- It is an error to inherit from or redefine Int. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Int { + is_prime(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics3_error.txt b/tests/semantic/basics3_error.txt index ed382c8eb..d8f80cb12 100644 --- a/tests/semantic/basics3_error.txt +++ b/tests/semantic/basics3_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Int. +(7, 7) - SemanticError: Redefinition of basic class Int. diff --git a/tests/semantic/basics4.cl b/tests/semantic/basics4.cl index 4475bc08f..9266ec79b 100644 --- a/tests/semantic/basics4.cl +++ b/tests/semantic/basics4.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine String. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits String { - is_palindrome(): Bool { false }; +-- It is an error to inherit from or redefine String. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits String { + is_palindrome(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics4_error.txt b/tests/semantic/basics4_error.txt index bfe08a9a6..d5cd4c3db 100644 --- a/tests/semantic/basics4_error.txt +++ b/tests/semantic/basics4_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class String. +(7, 18) - SemanticError: Class A cannot inherit class String. diff --git a/tests/semantic/basics5.cl b/tests/semantic/basics5.cl index f0d4dafb3..bad5eff13 100644 --- a/tests/semantic/basics5.cl +++ b/tests/semantic/basics5.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine String. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class String { - is_palindrome(): Bool { false }; +-- It is an error to inherit from or redefine String. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class String { + is_palindrome(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics5_error.txt b/tests/semantic/basics5_error.txt index 47b247faa..8437accf7 100644 --- a/tests/semantic/basics5_error.txt +++ b/tests/semantic/basics5_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class String. +(7, 7) - SemanticError: Redefinition of basic class String. diff --git a/tests/semantic/basics6.cl b/tests/semantic/basics6.cl index c16572a31..47266ebed 100644 --- a/tests/semantic/basics6.cl +++ b/tests/semantic/basics6.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Bool { - xor(b: Bool): Bool { false }; +-- It is an error to inherit from or redefine Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits Bool { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics6_error.txt b/tests/semantic/basics6_error.txt index 9adf1d488..b4d22da13 100644 --- a/tests/semantic/basics6_error.txt +++ b/tests/semantic/basics6_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class Bool. +(7, 18) - SemanticError: Class A cannot inherit class Bool. diff --git a/tests/semantic/basics7.cl b/tests/semantic/basics7.cl index 38f789245..0f30aaec3 100644 --- a/tests/semantic/basics7.cl +++ b/tests/semantic/basics7.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Bool { - xor(b: Bool): Bool { false }; +-- It is an error to inherit from or redefine Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Bool { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics7_error.txt b/tests/semantic/basics7_error.txt index 9f1347200..92660ab9f 100644 --- a/tests/semantic/basics7_error.txt +++ b/tests/semantic/basics7_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Bool. +(7, 7) - SemanticError: Redefinition of basic class Bool. diff --git a/tests/semantic/basics8.cl b/tests/semantic/basics8.cl index d45cd941d..3b9697d4f 100644 --- a/tests/semantic/basics8.cl +++ b/tests/semantic/basics8.cl @@ -1,9 +1,9 @@ --- It is an error redefine Object. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Object { - xor(b: Bool): Bool { false }; +-- It is an error redefine Object. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Object { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics8_error.txt b/tests/semantic/basics8_error.txt index 45767c9c5..652f47b30 100644 --- a/tests/semantic/basics8_error.txt +++ b/tests/semantic/basics8_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Object. +(7, 7) - SemanticError: Redefinition of basic class Object. diff --git a/tests/semantic/blocks1.cl b/tests/semantic/blocks1.cl index bad9093d7..1e928908b 100644 --- a/tests/semantic/blocks1.cl +++ b/tests/semantic/blocks1.cl @@ -1,31 +1,31 @@ ---The static type of a block is the static type of the last expression. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- { - new A; - { - new B; - { - new C; - { - new D; - { - new E; - { - new F; - }; - }; - }; - }; - }; - }; +--The static type of a block is the static type of the last expression. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- { + new A; + { + new B; + { + new C; + { + new D; + { + new E; + { + new F; + }; + }; + }; + }; + }; + }; }; \ No newline at end of file diff --git a/tests/semantic/blocks1_error.txt b/tests/semantic/blocks1_error.txt index 6bd9d6118..2f0e2caf3 100644 --- a/tests/semantic/blocks1_error.txt +++ b/tests/semantic/blocks1_error.txt @@ -1 +1 @@ -(13, 16) - TypeError: Inferred type F of initialization of attribute test does not conform to declared type B. +(13, 16) - TypeError: Inferred type F of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/case1.cl b/tests/semantic/case1.cl index af452f11c..82c6a4d61 100644 --- a/tests/semantic/case1.cl +++ b/tests/semantic/case1.cl @@ -1,23 +1,23 @@ ---For each branch, let Ti be the static type of . The static type of a case expression is Join 1≤i≤n Ti. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: B <- case 0 of - b: Bool => new F; - i: Int => new E; - esac; -}; +--For each branch, let Ti be the static type of . The static type of a case expression is Join 1≤i≤n Ti. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: B <- case 0 of + b: Bool => new F; + i: Int => new E; + esac; +}; diff --git a/tests/semantic/case1_error.txt b/tests/semantic/case1_error.txt index 70c7d16ca..f05ce31b9 100644 --- a/tests/semantic/case1_error.txt +++ b/tests/semantic/case1_error.txt @@ -1 +1 @@ -(19, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. +(19, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/case2.cl b/tests/semantic/case2.cl index dbbe4148c..ae97b41da 100644 --- a/tests/semantic/case2.cl +++ b/tests/semantic/case2.cl @@ -1,23 +1,23 @@ --- The variables declared on each branch of a case must all have distinct types. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: A <- case 0 of - b: Bool => new F; - i: Bool => new E; - esac; +-- The variables declared on each branch of a case must all have distinct types. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: A <- case 0 of + b: Bool => new F; + i: Bool => new E; + esac; }; \ No newline at end of file diff --git a/tests/semantic/case3.cl b/tests/semantic/case3.cl index 9ff06336a..da79bbfe6 100644 --- a/tests/semantic/case3.cl +++ b/tests/semantic/case3.cl @@ -1,23 +1,23 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: A <- case 0 of - b: Bool => new F; - i: Ball => new E; - esac; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: A <- case 0 of + b: Bool => new F; + i: Ball => new E; + esac; }; \ No newline at end of file diff --git a/tests/semantic/class1.cl b/tests/semantic/class1.cl index 576a3d0eb..ed83da9d1 100644 --- a/tests/semantic/class1.cl +++ b/tests/semantic/class1.cl @@ -1,9 +1,9 @@ --- Classes may not be redefined. - -class Repeat { - sum(a: Int, b: Int): Int { a + b }; -}; - -class Repeat { - mult(a: Int, b: Int): Int { a * b }; +-- Classes may not be redefined. + +class Repeat { + sum(a: Int, b: Int): Int { a + b }; +}; + +class Repeat { + mult(a: Int, b: Int): Int { a * b }; }; \ No newline at end of file diff --git a/tests/semantic/class1_error.txt b/tests/semantic/class1_error.txt index 6337828d0..19c507672 100644 --- a/tests/semantic/class1_error.txt +++ b/tests/semantic/class1_error.txt @@ -1,2 +1,2 @@ -(7, 5) - SemanticError: Classes may not be redefined - +(7, 5) - SemanticError: Classes may not be redefined + diff --git a/tests/semantic/conditionals1.cl b/tests/semantic/conditionals1.cl index 46af8cc73..3446a8b0f 100644 --- a/tests/semantic/conditionals1.cl +++ b/tests/semantic/conditionals1.cl @@ -1,14 +1,14 @@ ---The predicate must have static type Bool. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A <- if new F then new D else new C fi; +--The predicate must have static type Bool. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A <- if new F then new D else new C fi; }; \ No newline at end of file diff --git a/tests/semantic/conditionals1_error.txt b/tests/semantic/conditionals1_error.txt index 52db300b9..b86345359 100644 --- a/tests/semantic/conditionals1_error.txt +++ b/tests/semantic/conditionals1_error.txt @@ -1 +1 @@ -(13, 16) - TypeError: Predicate of 'if' does not have type Bool. +(13, 16) - TypeError: Predicate of 'if' does not have type Bool. diff --git a/tests/semantic/conditionals2.cl b/tests/semantic/conditionals2.cl index 8814177fc..9d6313d75 100644 --- a/tests/semantic/conditionals2.cl +++ b/tests/semantic/conditionals2.cl @@ -1,24 +1,24 @@ -(* -Let T and F be the static types of the branches of the conditional. Then the static type of the -conditional is T t F. (think: Walk towards Object from each of T and F until the paths meet.) -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- if true then - new C - else - if false then new D - else new E fi - fi; - - test: B <- if not true then new F else new E fi; -}; +(* +Let T and F be the static types of the branches of the conditional. Then the static type of the +conditional is T t F. (think: Walk towards Object from each of T and F until the paths meet.) +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if true then + new C + else + if false then new D + else new E fi + fi; + + test: B <- if not true then new F else new E fi; +}; diff --git a/tests/semantic/conditionals2_error.txt b/tests/semantic/conditionals2_error.txt index 8f54d195e..d6f5fc307 100644 --- a/tests/semantic/conditionals2_error.txt +++ b/tests/semantic/conditionals2_error.txt @@ -1,2 +1,2 @@ -(23, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. - +(23, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. + diff --git a/tests/semantic/dispatch1.cl b/tests/semantic/dispatch1.cl index bfd90f075..1c0457fa3 100644 --- a/tests/semantic/dispatch1.cl +++ b/tests/semantic/dispatch1.cl @@ -1,33 +1,33 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- new D.back("Hello ").back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.back("Hello ").back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch1_error.txt b/tests/semantic/dispatch1_error.txt index 89fa22b77..7fb22edce 100644 --- a/tests/semantic/dispatch1_error.txt +++ b/tests/semantic/dispatch1_error.txt @@ -1 +1 @@ -(32, 37) - AttributeError: Dispatch to undefined method back. +(32, 37) - AttributeError: Dispatch to undefined method back. diff --git a/tests/semantic/dispatch2.cl b/tests/semantic/dispatch2.cl index ebca718ac..5182912b8 100644 --- a/tests/semantic/dispatch2.cl +++ b/tests/semantic/dispatch2.cl @@ -1,34 +1,34 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the dispatch and the definition of f must have the same number of arguments -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: Int <- new D.back("Hello ").g(2, 2); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the dispatch and the definition of f must have the same number of arguments +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: Int <- new D.back("Hello ").g(2, 2); }; \ No newline at end of file diff --git a/tests/semantic/dispatch2_error.txt b/tests/semantic/dispatch2_error.txt index 1530fb82c..a86c35340 100644 --- a/tests/semantic/dispatch2_error.txt +++ b/tests/semantic/dispatch2_error.txt @@ -1 +1 @@ -(33, 39) - SemanticError: Method g called with wrong number of arguments. +(33, 39) - SemanticError: Method g called with wrong number of arguments. diff --git a/tests/semantic/dispatch3.cl b/tests/semantic/dispatch3.cl index 98c19da77..ecb1535db 100644 --- a/tests/semantic/dispatch3.cl +++ b/tests/semantic/dispatch3.cl @@ -1,36 +1,36 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch3_error.txt b/tests/semantic/dispatch3_error.txt index 77e81db72..0def5cf03 100644 --- a/tests/semantic/dispatch3_error.txt +++ b/tests/semantic/dispatch3_error.txt @@ -1 +1 @@ -(35, 45) - TypeError: In call of method alphabet, type B of parameter c does not conform to declared type C. +(35, 45) - TypeError: In call of method alphabet, type B of parameter c does not conform to declared type C. diff --git a/tests/semantic/dispatch4.cl b/tests/semantic/dispatch4.cl index 604e462a2..9cadd8332 100644 --- a/tests/semantic/dispatch4.cl +++ b/tests/semantic/dispatch4.cl @@ -1,36 +1,36 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -If f has return type B and B is a class name, then the static type of the dispatch is B. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +If f has return type B and B is a class name, then the static type of the dispatch is B. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch5.cl b/tests/semantic/dispatch5.cl index 9820e5ee1..b4437b1b4 100644 --- a/tests/semantic/dispatch5.cl +++ b/tests/semantic/dispatch5.cl @@ -1,31 +1,31 @@ -(* -(,...,) is shorthand for self.(,...,). -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; - sum(m: Int, n: Int, p: Int): Int { m + n + p }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - - back(s: String): B { { - out_string(s); - g(2); - sum(1, 2, 3); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +(,...,) is shorthand for self.(,...,). +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; + sum(m: Int, n: Int, p: Int): Int { m + n + p }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + + back(s: String): B { { + out_string(s); + g(2); + sum(1, 2, 3); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/dispatch5_error.txt b/tests/semantic/dispatch5_error.txt index 6a6922f32..d26bf34a1 100644 --- a/tests/semantic/dispatch5_error.txt +++ b/tests/semantic/dispatch5_error.txt @@ -1 +1 @@ -(24, 9) - AttributeError: Dispatch to undefined method sum. +(24, 9) - AttributeError: Dispatch to undefined method sum. diff --git a/tests/semantic/dispatch6.cl b/tests/semantic/dispatch6.cl index bbe58fbb1..fcc033f2c 100644 --- a/tests/semantic/dispatch6.cl +++ b/tests/semantic/dispatch6.cl @@ -1,32 +1,32 @@ -(* -e@B.f() invokes the method -f in class B on the object that is the value of e. For this form of dispatch, the static type to the left of -“@”must conform to the type specified to the right of “@”. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; - sum(m: Int, n: Int, p: Int): Int { m + n + p }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - sum(v: Int, w: Int, z: Int): Int { v - w - z }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A <- new D; - b: Int <- new D@B.sum(1, 2, 3); - test: Int <- a@B.sum(1, 2, 3); -}; +(* +e@B.f() invokes the method +f in class B on the object that is the value of e. For this form of dispatch, the static type to the left of +“@”must conform to the type specified to the right of “@”. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; + sum(m: Int, n: Int, p: Int): Int { m + n + p }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + sum(v: Int, w: Int, z: Int): Int { v - w - z }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A <- new D; + b: Int <- new D@B.sum(1, 2, 3); + test: Int <- a@B.sum(1, 2, 3); +}; diff --git a/tests/semantic/dispatch6_error.txt b/tests/semantic/dispatch6_error.txt index 7d5ec3780..ae9184b2f 100644 --- a/tests/semantic/dispatch6_error.txt +++ b/tests/semantic/dispatch6_error.txt @@ -1 +1 @@ -(31, 18) - TypeError: Expression type A does not conform to declared static dispatch type B. +(31, 18) - TypeError: Expression type A does not conform to declared static dispatch type B. diff --git a/tests/semantic/eq1.cl b/tests/semantic/eq1.cl index dc8a0cd43..88f2a7ffe 100644 --- a/tests/semantic/eq1.cl +++ b/tests/semantic/eq1.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - test: Bool <- 1 = new A; - y: Bool <- "1" = "2"; - z: Bool <- true = not false; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + test: Bool <- 1 = new A; + y: Bool <- "1" = "2"; + z: Bool <- true = not false; }; \ No newline at end of file diff --git a/tests/semantic/eq1_error.txt b/tests/semantic/eq1_error.txt index 0b85d2fa0..f81425683 100644 --- a/tests/semantic/eq1_error.txt +++ b/tests/semantic/eq1_error.txt @@ -1 +1 @@ -(14, 21) - TypeError: Illegal comparison with a basic type. +(14, 21) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq2.cl b/tests/semantic/eq2.cl index f4b2ffac7..d76852780 100644 --- a/tests/semantic/eq2.cl +++ b/tests/semantic/eq2.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - test: Bool <- "1" = new B; - z: Bool <- true = not false; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + test: Bool <- "1" = new B; + z: Bool <- true = not false; +}; diff --git a/tests/semantic/eq2_error.txt b/tests/semantic/eq2_error.txt index 1bb29ca32..a44ab0d51 100644 --- a/tests/semantic/eq2_error.txt +++ b/tests/semantic/eq2_error.txt @@ -1 +1 @@ -(15, 23) - TypeError: Illegal comparison with a basic type. +(15, 23) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq3.cl b/tests/semantic/eq3.cl index b7ee462c5..4dad693ee 100644 --- a/tests/semantic/eq3.cl +++ b/tests/semantic/eq3.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - z: Bool <- true = not false; - test: Bool <- "true" = not false; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + z: Bool <- true = not false; + test: Bool <- "true" = not false; +}; diff --git a/tests/semantic/eq3_error.txt b/tests/semantic/eq3_error.txt index d57841b95..c4e27eb8a 100644 --- a/tests/semantic/eq3_error.txt +++ b/tests/semantic/eq3_error.txt @@ -1 +1 @@ -(16, 26) - TypeError: Illegal comparison with a basic type. +(16, 26) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq4.cl b/tests/semantic/eq4.cl index 63c1067f0..11afc119f 100644 --- a/tests/semantic/eq4.cl +++ b/tests/semantic/eq4.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. The result is a Bool. -*) - -class A { }; -class B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - z: Bool <- new A = new B; - test: Int <- new A = new B; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. The result is a Bool. +*) + +class A { }; +class B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + z: Bool <- new A = new B; + test: Int <- new A = new B; +}; diff --git a/tests/semantic/eq4_error.txt b/tests/semantic/eq4_error.txt index f075fecbe..3ead21d0e 100644 --- a/tests/semantic/eq4_error.txt +++ b/tests/semantic/eq4_error.txt @@ -1 +1 @@ -(16, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. +(16, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/features1.cl b/tests/semantic/features1.cl index 31823713a..96dd8ebc6 100755 --- a/tests/semantic/features1.cl +++ b/tests/semantic/features1.cl @@ -16,4 +16,4 @@ class A { x(): Int { 3 }; x: String <- ":)"; -}; +}; \ No newline at end of file diff --git a/tests/semantic/isvoid1.cl b/tests/semantic/isvoid1.cl index 7c3a83a77..072720d85 100644 --- a/tests/semantic/isvoid1.cl +++ b/tests/semantic/isvoid1.cl @@ -1,26 +1,26 @@ ---evaluates to true if expr is void and evaluates to false if expr is not void. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- if isvoid new F then - new C - else - if false then new D - else new E fi - fi; - - test: B <- isvoid if isvoid new F then - new C - else - if false then new D - else new E fi - fi; +--evaluates to true if expr is void and evaluates to false if expr is not void. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if isvoid new F then + new C + else + if false then new D + else new E fi + fi; + + test: B <- isvoid if isvoid new F then + new C + else + if false then new D + else new E fi + fi; }; \ No newline at end of file diff --git a/tests/semantic/isvoid1_error.txt b/tests/semantic/isvoid1_error.txt index 3fd0157b4..0922de909 100644 --- a/tests/semantic/isvoid1_error.txt +++ b/tests/semantic/isvoid1_error.txt @@ -1 +1 @@ -(20, 16) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type B. +(20, 16) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/let1.cl b/tests/semantic/let1.cl index 9220d3dbc..26ef63026 100644 --- a/tests/semantic/let1.cl +++ b/tests/semantic/let1.cl @@ -1,15 +1,15 @@ ---The type of an initialization expression must conform to the declared type of the identifier. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: C <- new E in b; +--The type of an initialization expression must conform to the declared type of the identifier. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: C <- new E in b; }; \ No newline at end of file diff --git a/tests/semantic/let1_error.txt b/tests/semantic/let1_error.txt index 56547dae5..16ecf780c 100644 --- a/tests/semantic/let1_error.txt +++ b/tests/semantic/let1_error.txt @@ -1 +1 @@ -(14, 76) - TypeError: Inferred type E of initialization of b does not conform to identifier's declared type C. +(14, 76) - TypeError: Inferred type E of initialization of b does not conform to identifier's declared type C. diff --git a/tests/semantic/let2.cl b/tests/semantic/let2.cl index 2949fb94d..c5956ead3 100644 --- a/tests/semantic/let2.cl +++ b/tests/semantic/let2.cl @@ -1,15 +1,15 @@ ---The type of let is the type of the body. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: A <- new E in b; +--The type of let is the type of the body. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: A <- new E in b; }; \ No newline at end of file diff --git a/tests/semantic/let2_error.txt b/tests/semantic/let2_error.txt index 3b7c669a3..b1e8a365d 100644 --- a/tests/semantic/let2_error.txt +++ b/tests/semantic/let2_error.txt @@ -1 +1 @@ -(14, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. +(14, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/let3.cl b/tests/semantic/let3.cl index 0a4a9ceaf..8c0670ab8 100644 --- a/tests/semantic/let3.cl +++ b/tests/semantic/let3.cl @@ -1,15 +1,15 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: Cadena in new B; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: Cadena in new B; }; \ No newline at end of file diff --git a/tests/semantic/loops1.cl b/tests/semantic/loops1.cl index 6a0a81818..de3a624d2 100644 --- a/tests/semantic/loops1.cl +++ b/tests/semantic/loops1.cl @@ -1,8 +1,8 @@ ---The predicate must have static type Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - i: Int <- 1; - test: Object <- while "true" loop i <- i + 1 pool; +--The predicate must have static type Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + i: Int <- 1; + test: Object <- while "true" loop i <- i + 1 pool; }; \ No newline at end of file diff --git a/tests/semantic/loops2.cl b/tests/semantic/loops2.cl index d52169da7..dea69fa14 100644 --- a/tests/semantic/loops2.cl +++ b/tests/semantic/loops2.cl @@ -1,9 +1,9 @@ ---The static type of a loop expression is Object. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - i: Int <- 1; - test: Object <- while not false loop i <- i + 1 pool; - test2: Int <- while not false loop i <- i + 1 pool; -}; +--The static type of a loop expression is Object. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + i: Int <- 1; + test: Object <- while not false loop i <- i + 1 pool; + test2: Int <- while not false loop i <- i + 1 pool; +}; diff --git a/tests/semantic/loops2_error.txt b/tests/semantic/loops2_error.txt index ab79de8da..9711cdf6a 100644 --- a/tests/semantic/loops2_error.txt +++ b/tests/semantic/loops2_error.txt @@ -1 +1 @@ -(8, 19) - TypeError: Inferred type Object of initialization of attribute test2 does not conform to declared type Int. +(8, 19) - TypeError: Inferred type Object of initialization of attribute test2 does not conform to declared type Int. diff --git a/tests/semantic/methods1.cl b/tests/semantic/methods1.cl index f4ff07bb0..d12031970 100644 --- a/tests/semantic/methods1.cl +++ b/tests/semantic/methods1.cl @@ -1,12 +1,12 @@ ---The identifiers used in the formal parameter list must be distinct - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, a: B): Int { 4 }; +--The identifiers used in the formal parameter list must be distinct + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, a: B): Int { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/methods1_error.txt b/tests/semantic/methods1_error.txt index 809036803..06ab88a92 100644 --- a/tests/semantic/methods1_error.txt +++ b/tests/semantic/methods1_error.txt @@ -1 +1 @@ -(11, 16) - SemanticError: Formal parameter a is multiply defined. +(11, 16) - SemanticError: Formal parameter a is multiply defined. diff --git a/tests/semantic/methods2.cl b/tests/semantic/methods2.cl index c010df01e..3865f0e13 100644 --- a/tests/semantic/methods2.cl +++ b/tests/semantic/methods2.cl @@ -1,12 +1,12 @@ ---The type of the method body must conform to the declared return type. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: B): C { new D }; +--The type of the method body must conform to the declared return type. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: B): C { new D }; }; \ No newline at end of file diff --git a/tests/semantic/methods2_error.txt b/tests/semantic/methods2_error.txt index 1a4baea17..f7e4a330d 100644 --- a/tests/semantic/methods2_error.txt +++ b/tests/semantic/methods2_error.txt @@ -1 +1 @@ -(11, 27) - TypeError: Inferred return type D of method test does not conform to declared return type C. +(11, 27) - TypeError: Inferred return type D of method test does not conform to declared return type C. diff --git a/tests/semantic/methods3.cl b/tests/semantic/methods3.cl index 9aff4d167..b92faeb97 100644 --- a/tests/semantic/methods3.cl +++ b/tests/semantic/methods3.cl @@ -1,14 +1,14 @@ ---A formal parameter hides any definition of an attribute of the same name. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: C <- new C; - test(a: D): D { a }; - test2(a: B): C { a }; +--A formal parameter hides any definition of an attribute of the same name. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: C <- new C; + test(a: D): D { a }; + test2(a: B): C { a }; }; \ No newline at end of file diff --git a/tests/semantic/methods3_error.txt b/tests/semantic/methods3_error.txt index a0f6d9db2..1165b7595 100644 --- a/tests/semantic/methods3_error.txt +++ b/tests/semantic/methods3_error.txt @@ -1 +1 @@ -(13, 22) - TypeError: Inferred return type B of method test2 does not conform to declared return type C. +(13, 22) - TypeError: Inferred return type B of method test2 does not conform to declared return type C. diff --git a/tests/semantic/methods4.cl b/tests/semantic/methods4.cl index e093bac1c..be8fa36ef 100644 --- a/tests/semantic/methods4.cl +++ b/tests/semantic/methods4.cl @@ -1,19 +1,19 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; -}; -class B inherits A { - f(x: Int, y: Object): Int { x }; -}; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; +}; +class B inherits A { + f(x: Int, y: Object): Int { x }; +}; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/methods4_error.txt b/tests/semantic/methods4_error.txt index c9fc2d12a..9f1486dec 100644 --- a/tests/semantic/methods4_error.txt +++ b/tests/semantic/methods4_error.txt @@ -1 +1 @@ -(12, 15) - SemanticError: In redefined method f, parameter type Object is different from original type Int. +(12, 15) - SemanticError: In redefined method f, parameter type Object is different from original type Int. diff --git a/tests/semantic/methods5.cl b/tests/semantic/methods5.cl index 732e4d408..3905dfdd6 100644 --- a/tests/semantic/methods5.cl +++ b/tests/semantic/methods5.cl @@ -1,20 +1,20 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; -}; -class B inherits A { - f(a: Int, b: Int): Object { a - b }; -}; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; +}; +class B inherits A { + f(a: Int, b: Int): Object { a - b }; +}; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + diff --git a/tests/semantic/methods5_error.txt b/tests/semantic/methods5_error.txt index 073eee8c5..8b6bdf36e 100644 --- a/tests/semantic/methods5_error.txt +++ b/tests/semantic/methods5_error.txt @@ -1 +1 @@ -(12, 24) - SemanticError: In redefined method f, return type Object is different from original return type Int. +(12, 24) - SemanticError: In redefined method f, return type Object is different from original return type Int. diff --git a/tests/semantic/methods6.cl b/tests/semantic/methods6.cl index 61a62b4b0..dd2b73da6 100644 --- a/tests/semantic/methods6.cl +++ b/tests/semantic/methods6.cl @@ -1,27 +1,27 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int, w: Int, z: Int): Int { v + w + z }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int, w: Int, z: Int): Int { v + w + z }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/methods6_error.txt b/tests/semantic/methods6_error.txt index 70ad02e32..8e32663b9 100644 --- a/tests/semantic/methods6_error.txt +++ b/tests/semantic/methods6_error.txt @@ -1 +1 @@ -(22, 5) - SemanticError: Incompatible number of formal parameters in redefined method g. +(22, 5) - SemanticError: Incompatible number of formal parameters in redefined method g. diff --git a/tests/semantic/methods7.cl b/tests/semantic/methods7.cl index 21e8ca275..e5a01f682 100644 --- a/tests/semantic/methods7.cl +++ b/tests/semantic/methods7.cl @@ -1,12 +1,12 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: Ball): Int { 4 }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: Ball): Int { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/methods8.cl b/tests/semantic/methods8.cl index 121210748..3fccab54c 100644 --- a/tests/semantic/methods8.cl +++ b/tests/semantic/methods8.cl @@ -1,12 +1,12 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: B): Integrer { 4 }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: B): Integrer { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/new1.cl b/tests/semantic/new1.cl index 40a8b9e9b..d007fc03d 100644 --- a/tests/semantic/new1.cl +++ b/tests/semantic/new1.cl @@ -1,31 +1,31 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: F <- { - new A; - { - new Ball; - { - new C; - { - new D; - { - new E; - { - new F; - }; - }; - }; - }; - }; - }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: F <- { + new A; + { + new Ball; + { + new C; + { + new D; + { + new E; + { + new F; + }; + }; + }; + }; + }; + }; }; \ No newline at end of file diff --git a/tests/semantic/self1.cl b/tests/semantic/self1.cl index 399f6ff06..3387fd263 100644 --- a/tests/semantic/self1.cl +++ b/tests/semantic/self1.cl @@ -1,11 +1,11 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: Main): IO { self <- a }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: Main): IO { self <- a }; +}; diff --git a/tests/semantic/self1_error.txt b/tests/semantic/self1_error.txt index f9f51b9b3..6beb3cda2 100644 --- a/tests/semantic/self1_error.txt +++ b/tests/semantic/self1_error.txt @@ -1 +1 @@ -(10, 30) - SemanticError: Cannot assign to 'self'. +(10, 30) - SemanticError: Cannot assign to 'self'. diff --git a/tests/semantic/self2.cl b/tests/semantic/self2.cl index 6ef75e368..2e6921a92 100644 --- a/tests/semantic/self2.cl +++ b/tests/semantic/self2.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(): IO { let self: Main <- new Main in self }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(): IO { let self: Main <- new Main in self }; +}; diff --git a/tests/semantic/self2_error.txt b/tests/semantic/self2_error.txt index 2e53bb210..20c883c91 100644 --- a/tests/semantic/self2_error.txt +++ b/tests/semantic/self2_error.txt @@ -1 +1 @@ -(9, 22) - SemanticError: 'self' cannot be bound in a 'let' expression. +(9, 22) - SemanticError: 'self' cannot be bound in a 'let' expression. diff --git a/tests/semantic/self3.cl b/tests/semantic/self3.cl index d314798a9..81709b4b5 100644 --- a/tests/semantic/self3.cl +++ b/tests/semantic/self3.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(self: IO): IO { self }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(self: IO): IO { self }; +}; diff --git a/tests/semantic/self3_error.txt b/tests/semantic/self3_error.txt index 0015bbe0a..0ae382007 100644 --- a/tests/semantic/self3_error.txt +++ b/tests/semantic/self3_error.txt @@ -1 +1 @@ -(9, 10) - SemanticError: 'self' cannot be the name of a formal parameter. +(9, 10) - SemanticError: 'self' cannot be the name of a formal parameter. diff --git a/tests/semantic/self4.cl b/tests/semantic/self4.cl index 9185c8760..7c2b960cb 100644 --- a/tests/semantic/self4.cl +++ b/tests/semantic/self4.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - self: IO <- self; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + self: IO <- self; }; \ No newline at end of file diff --git a/tests/semantic/self4_error.txt b/tests/semantic/self4_error.txt index bf8740604..c19ca400f 100644 --- a/tests/semantic/self4_error.txt +++ b/tests/semantic/self4_error.txt @@ -1 +1 @@ -(9, 5) - SemanticError: 'self' cannot be the name of an attribute. +(9, 5) - SemanticError: 'self' cannot be the name of an attribute. diff --git a/tests/semantic_test.py b/tests/semantic_test.py index 46f07439d..cac9cd78b 100644 --- a/tests/semantic_test.py +++ b/tests/semantic_test.py @@ -1,14 +1,14 @@ -import pytest -import os -from utils import compare_errors, first_error_only_line - -tests_dir = __file__.rpartition('/')[0] + '/semantic/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.semantic -@pytest.mark.error -@pytest.mark.run(order=3) -@pytest.mark.parametrize("cool_file", tests) -def test_semantic_errors(compiler_path, cool_file): - compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt', \ +import pytest +import os +from utils import compare_errors, first_error_only_line + +tests_dir = __file__.rpartition('/')[0] + '/semantic/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.semantic +@pytest.mark.error +@pytest.mark.run(order=3) +@pytest.mark.parametrize("cool_file", tests) +def test_semantic_errors(compiler_path, cool_file): + compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt', \ cmp=first_error_only_line) \ No newline at end of file diff --git a/tests/utils/utils.py b/tests/utils/utils.py index f98d19dd0..961cf7cbc 100644 --- a/tests/utils/utils.py +++ b/tests/utils/utils.py @@ -1,91 +1,91 @@ -import subprocess -import re - - -COMPILER_TIMEOUT = 'El compilador tarda mucho en responder.' -SPIM_TIMEOUT = 'El spim tarda mucho en responder.' -TEST_MUST_FAIL = 'El test %s debe fallar al compilar' -TEST_MUST_COMPILE = 'El test %s debe compilar' -BAD_ERROR_FORMAT = '''El error no esta en formato: (,) - : - o no se encuentra en la 3ra linea\n\n%s''' -UNEXPECTED_ERROR = 'Se esperaba un %s en (%d, %d). Su error fue un %s en (%d, %d)' -UNEXPECTED_OUTPUT = 'La salida de %s no es la esperada:\n%s\nEsperada:\n%s' - -ERROR_FORMAT = r'^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*-\s*(\w+)\s*:(.*)$' - -def parse_error(error: str): - merror = re.fullmatch(ERROR_FORMAT, error) - assert merror, BAD_ERROR_FORMAT % error - - return (t(x) for t, x in zip([int, int, str, str], merror.groups())) - - -def first_error(compiler_output: list, errors: list): - line, column, error_type, _ = parse_error(errors[0]) - - oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) - - assert line == oline and column == ocolumn and error_type == oerror_type,\ - UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) - -def first_error_only_line(compiler_output: list, errors: list): - line, column, error_type, _ = parse_error(errors[0]) - - oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) - - assert line == oline and error_type == oerror_type,\ - UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) - - -def get_file_name(path: str): - try: - return path[path.rindex('/') + 1:] - except ValueError: - return path - -def compare_errors(compiler_path: str, cool_file_path: str, error_file_path: str, cmp=first_error, timeout=100): - try: - sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) - return_code, output = sp.returncode, sp.stdout.decode() - except subprocess.TimeoutExpired: - assert False, COMPILER_TIMEOUT - - assert return_code == 1, TEST_MUST_FAIL % get_file_name(cool_file_path) - - fd = open(error_file_path, 'r') - errors = fd.read().split('\n') - fd.close() - - # checking the errors of compiler - compiler_output = output.split('\n') - cmp(compiler_output[2:], errors) - -SPIM_HEADER = r'''^SPIM Version .+ of .+ -Copyright .+\, James R\. Larus\. -All Rights Reserved\. -See the file README for a full copyright notice\. -(?:Loaded: .+\n)*''' -def compare_outputs(compiler_path: str, cool_file_path: str, input_file_path: str, output_file_path: str, timeout=100): - try: - sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) - assert sp.returncode == 0, TEST_MUST_COMPILE % get_file_name(cool_file_path) - except subprocess.TimeoutExpired: - assert False, COMPILER_TIMEOUT - - spim_file = cool_file_path[:-2] + 'mips' - - try: - fd = open(input_file_path, 'rb') - sp = subprocess.run(['spim', '-file', spim_file], input=fd.read(), capture_output=True, timeout=timeout) - fd.close() - mo = re.match(SPIM_HEADER, sp.stdout.decode()) - if mo: - output = mo.string[mo.end():] - except subprocess.TimeoutExpired: - assert False, SPIM_TIMEOUT - - fd = open(output_file_path, 'r') - eoutput = fd.read() - fd.close() - - assert output == eoutput, UNEXPECTED_OUTPUT % (spim_file, repr(output), repr(eoutput)) +import subprocess +import re + + +COMPILER_TIMEOUT = 'El compilador tarda mucho en responder.' +SPIM_TIMEOUT = 'El spim tarda mucho en responder.' +TEST_MUST_FAIL = 'El test %s debe fallar al compilar' +TEST_MUST_COMPILE = 'El test %s debe compilar' +BAD_ERROR_FORMAT = '''El error no esta en formato: (,) - : + o no se encuentra en la 3ra linea\n\n%s''' +UNEXPECTED_ERROR = 'Se esperaba un %s en (%d, %d). Su error fue un %s en (%d, %d)' +UNEXPECTED_OUTPUT = 'La salida de %s no es la esperada:\n%s\nEsperada:\n%s' + +ERROR_FORMAT = r'^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*-\s*(\w+)\s*:(.*)$' + +def parse_error(error: str): + merror = re.fullmatch(ERROR_FORMAT, error) + assert merror, BAD_ERROR_FORMAT % error + + return (t(x) for t, x in zip([int, int, str, str], merror.groups())) + + +def first_error(compiler_output: list, errors: list): + line, column, error_type, _ = parse_error(errors[0]) + + oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) + + assert line == oline and column == ocolumn and error_type == oerror_type,\ + UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) + +def first_error_only_line(compiler_output: list, errors: list): + line, column, error_type, _ = parse_error(errors[0]) + + oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) + + assert line == oline and error_type == oerror_type,\ + UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) + + +def get_file_name(path: str): + try: + return path[path.rindex('/') + 1:] + except ValueError: + return path + +def compare_errors(compiler_path: str, cool_file_path: str, error_file_path: str, cmp=first_error, timeout=100): + try: + sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) + return_code, output = sp.returncode, sp.stdout.decode() + except subprocess.TimeoutExpired: + assert False, COMPILER_TIMEOUT + + assert return_code == 1, TEST_MUST_FAIL % get_file_name(cool_file_path) + + fd = open(error_file_path, 'r') + errors = fd.read().split('\n') + fd.close() + + # checking the errors of compiler + compiler_output = output.split('\n') + cmp(compiler_output[2:], errors) + +SPIM_HEADER = r'''^SPIM Version .+ of .+ +Copyright .+\, James R\. Larus\. +All Rights Reserved\. +See the file README for a full copyright notice\. +(?:Loaded: .+\n)*''' +def compare_outputs(compiler_path: str, cool_file_path: str, input_file_path: str, output_file_path: str, timeout=100): + try: + sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) + assert sp.returncode == 0, TEST_MUST_COMPILE % get_file_name(cool_file_path) + except subprocess.TimeoutExpired: + assert False, COMPILER_TIMEOUT + + spim_file = cool_file_path[:-2] + 'mips' + + try: + fd = open(input_file_path, 'rb') + sp = subprocess.run(['spim', '-file', spim_file], input=fd.read(), capture_output=True, timeout=timeout) + fd.close() + mo = re.match(SPIM_HEADER, sp.stdout.decode()) + if mo: + output = mo.string[mo.end():] + except subprocess.TimeoutExpired: + assert False, SPIM_TIMEOUT + + fd = open(output_file_path, 'r') + eoutput = fd.read() + fd.close() + + assert output == eoutput, UNEXPECTED_OUTPUT % (spim_file, repr(output), repr(eoutput)) From 96b0d4791b2a6951a2fa120563ec3fd6c3f0b655 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 19:29:24 -0300 Subject: [PATCH 32/60] testing lexer aceptable --- src/compiler_components/lexer.py | 68 ++++++++++++++++- src/program.txt | 124 ++----------------------------- 2 files changed, 72 insertions(+), 120 deletions(-) diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index 6597ef916..de762c71b 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -80,8 +80,72 @@ def t_NUMBER(self, t): return t def t_STRING(self, t): - r'"[^"]*"' - return t + r'"' + rest_data = t.lexer.lexdata[t.lexer.lexpos:] + s = '' + ok = False + index = 0 + while index < len(rest_data): + if rest_data[index] == '"': + ok = True + t.lexer.skip(1) + s += rest_data[index] + break + + if rest_data[index] == '\n' or rest_data[index] == '\000': + s = t.lexer.lexdata.split('\n') + count = 0 + for i in range(t.lexer.lineno - 1): + count += len(s[i]) + + posAtLine = t.lexer.lexpos - count - t.lexer.lineno + 2 + if rest_data[index] == '\n': + self.errors.append("(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ") - LexicographicError: Unterminated string constant") + if rest_data[index] == '\000': + self.errors.append("(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ") - LexicographicError: String contains null character") + t.lexer.lineno+=1 + return + + + if rest_data[index] == '\\': + t.lexer.skip(1) + index += 1 + if index == len(rest_data) - 1: + s = t.lexer.lexdata.split('\n') + count = 0 + for i in range(t.lexer.lineno - 1): + count += len(s[i]) + + posAtLine = t.lexer.lexpos - count - t.lexer.lineno + 2 + self.errors.append("(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ") - LexicographicError: EOF in string constant") + return + if rest_data[index] == 'b': + s = s[0:len(s) - 1] + + elif rest_data[index] == 't': + s+='\t' + elif rest_data[index] == 'f': + s+='\f' + elif rest_data[index] == '\n': + s+='\n' + t.lexer.lineno += 1 + else: + s+= rest_data[index] + + t.lexer.skip(1) + index+=1 + + if ok: + t.value += s + return t + else: + s = t.lexer.lexdata.split('\n') + count = 0 + for i in range(t.lexer.lineno - 1): + count += len(s[i]) + + posAtLine = t.lexer.lexpos - count - t.lexer.lineno + 2 + self.errors.append("(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ") - LexicographicError: EOF in string constant") def t_ID(self, t): r'[a-z][a-zA-Z_0-9]*' diff --git a/src/program.txt b/src/program.txt index f69465c5f..f92060bd2 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,120 +1,8 @@ -(* Integers, Identifiers, and Special Notation *) -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ +(* A string may not contain the null (character \0). Any other character +may be included in a string *) - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -loop pool while tRuE or noT faLsE let in case of ESAC - -factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 CLASS -#4 CLASS -#4 IF -#4 THEN -#4 ELSE -#4 FI -#4 OBJECTID testing -#4 TYPEID Testing -#4 '~' -#4 INT_CONST 007 -#4 OBJECTID agent_bond -#4 OBJECTID james_007bones___ -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#8 LOOP -#8 POOL -#8 WHILE -#8 BOOL_CONST true -#8 OBJECTID or -#8 NOT -#8 BOOL_CONST false -#8 LET -#8 IN -#8 CASE -#8 OF -#8 ESAC -#10 OBJECTID factorial -#10 '(' -#10 INT_CONST 5 -#10 ')' -#10 '=' -#10 INT_CONST 120 -#10 ',' -#10 INT_CONST 2 -#10 '+' -#10 INT_CONST 2 -#10 '=' -#10 INT_CONST 5 -#10 ERROR "?" -#10 OBJECTID or -#10 TYPEID E -#10 '=' -#10 OBJECTID mc2 -#10 ';' -#10 OBJECTID p -#10 '+' -#10 INT_CONST 1 -#10 OBJECTID resto -#10 OBJECTID p -#10 '=' -#10 INT_CONST 1 -#10 ':' -#10 '(' -#10 '@' -#10 OBJECTID for -#10 OBJECTID x -#10 IN -#10 OBJECTID range -#10 '(' -#10 OBJECTID len -#10 '(' -#10 OBJECTID b -#10 ')' -#10 ')' -#10 ')' -*) +"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" algoritmo "\b\f\s123\t" +adsfasklj +LKldsajf +"lkdsajf" From 88d6d4d717544aca5eb55e7e538a40100de01dfc Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 20:12:47 -0300 Subject: [PATCH 33/60] all tests parser completed succefully --- src/compiler_components/cool_parser.py | 16 ++++++++++++++-- src/program.txt | 9 +-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index f1e7721be..3c40f3a6e 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -285,12 +285,24 @@ def p_arg_list2(p): def p_error(p): if p: - errors.append("sintax error at line " + str(p.lineno) + " --> token: '" + str(p.value) + "'") + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + errors.append(f'({line},{column}) - SyntacticError: ERROR at or near "{p.value}"') + else: - errors.append("sintanx error at end of file") + errors.append(f'(0, 0) - SyntacticError: ERROR at or near EOF') ############## End Grammar ############################ +def calculate_position(data, pos): + data_array = data.split('\n') + count = 0 + number_line = 0 + for line in data_array: + number_line += 1 + if count + len(line) >= pos: + return (number_line, pos - count + 1) + count += len(line) + 1 + class Parser(CompilerComponent): diff --git a/src/program.txt b/src/program.txt index f92060bd2..33cbcd02a 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,8 +1 @@ - -(* A string may not contain the null (character \0). Any other character -may be included in a string *) - -"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" algoritmo "\b\f\s123\t" -adsfasklj -LKldsajf -"lkdsajf" +(* A Cool program can't be empty *) From ab03a602ff8ab7efe7a940068b69e121b5486cef Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 20:26:44 -0300 Subject: [PATCH 34/60] line and column propertys added to ast objects --- src/compiler_components/ast.py | 88 ++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 438315c83..c8255f846 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -6,7 +6,8 @@ def visit(self, tabs = 0): class ProgramNode(Node): def __init__(self, declarations): self.declarations = declarations - self.line = -1 + self.line = 1 + self.column = 1 def visit(self, tabs = 0): @@ -25,9 +26,10 @@ class ExpressionNode(Node): class AtomicNode(ExpressionNode): - def __init__(self, lex): + def __init__(self, lex, line, column): self.lex = lex - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -35,11 +37,12 @@ def visit(self, tabs = 0): class ClassDeclarationNode(DeclarationNode): - def __init__(self, idx, features, parent=None): + def __init__(self, idx, features, parent=None, line = -1, column=-1): self.id = idx self.parent = parent self.features = features - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -50,12 +53,13 @@ def visit(self, tabs = 0): class FuncDeclarationNode(DeclarationNode): - def __init__(self, idx, params, return_type, body): + def __init__(self, idx, params, return_type, body, line = -1, column=-1): self.id = idx self.params = params self.type = return_type self.body = body - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -67,11 +71,12 @@ def visit(self, tabs = 0): class AttrDeclarationNode(DeclarationNode): - def __init__(self, idx, typex, expr = None): + def __init__(self, idx, typex, expr = None, line = -1, column=-1): self.id = idx self.type = typex self.expr = expr - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -82,11 +87,12 @@ def visit(self, tabs = 0): class VarDeclarationNode(ExpressionNode): - def __init__(self, idx, typex, expr): + def __init__(self, idx, typex, expr, line = -1, column=-1): self.id = idx self.type = typex self.expr = expr - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -96,10 +102,11 @@ def visit(self, tabs = 0): class AssignNode(AtomicNode): - def __init__(self, idx, expr): + def __init__(self, idx, expr, line = -1, column=-1): self.id = idx self.expr = expr - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -109,9 +116,10 @@ def visit(self, tabs = 0): class IsVoidNode(AtomicNode): - def __init__(self, expr): + def __init__(self, expr, line = -1, column=-1): self.expr = expr - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): ans = '\t'*tabs + "\\__IsVoid " @@ -119,9 +127,10 @@ def visit(self, tabs = 0): class NotNode(AtomicNode): - def __init__(self, expr): + def __init__(self, expr, line = -1, column=-1): self.expr = expr - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): ans = '\t'*tabs + "\\__NOT " @@ -129,9 +138,10 @@ def visit(self, tabs = 0): class NhanharaNode(AtomicNode): - def __init__(self, expr): + def __init__(self, expr, line = -1, column=-1): self.expr = expr - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): ans = '\t'*tabs + "\\__~ " @@ -139,7 +149,7 @@ def visit(self, tabs = 0): class CallNode(AtomicNode): - def __init__(self, obj, idx, args = None, type = None): + def __init__(self, obj, idx, args = None, type = None, line = -1, column=-1): self.obj = obj self.id = idx if args is None: @@ -147,7 +157,8 @@ def __init__(self, obj, idx, args = None, type = None): else: self.args = args self.type = type - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -173,11 +184,12 @@ def visit(self, tabs = 0): class IfNode(AtomicNode): - def __init__(self, if_c, then_c, else_c): + def __init__(self, if_c, then_c, else_c, line = -1, column=-1): self.if_c = if_c self.then_c = then_c self.else_c = else_c - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -189,10 +201,11 @@ def visit(self, tabs = 0): class WhileNode(AtomicNode): - def __init__(self, condition, body): + def __init__(self, condition, body, line = -1, column=-1): self.condition = condition self.body = body - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -204,9 +217,10 @@ def visit(self, tabs = 0): class BlockNode(AtomicNode): - def __init__(self, expr_list): + def __init__(self, expr_list, line = -1, column=-1): self.expr_list = expr_list - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): ans = '\t'*tabs + " {; .... ;}\n" @@ -215,10 +229,11 @@ def visit(self, tabs = 0): class LetNode(AtomicNode): - def __init__(self, list_decl, expr): + def __init__(self, list_decl, expr, line = -1, column=-1): self.list_decl = list_decl self.expr = expr - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): ans = '\t'*tabs + " LET , ... in \n " @@ -228,10 +243,11 @@ def visit(self, tabs = 0): class CaseNode(AtomicNode): - def __init__(self, expr, list_case): + def __init__(self, expr, list_case, line = -1, column=-1): self.list_case = list_case self.expr = expr - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): ans = '\t'*tabs + "\\__Case in esac" @@ -241,10 +257,11 @@ def visit(self, tabs = 0): class BinaryNode(ExpressionNode): - def __init__(self, left, right): + def __init__(self, left, right, line = -1, column=-1): self.left = left self.right = right - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self @@ -275,7 +292,7 @@ class SelfNode(AtomicNode): class DispatchNode(ExpressionNode): - def __init__(self, expr, f, params, typex = None): + def __init__(self, expr, f, params, typex = None, line = -1, column=-1): self.id = f self.expr = expr self.f = f @@ -284,7 +301,8 @@ def __init__(self, expr, f, params, typex = None): else: self.params = params self.typex = typex - self.line = -1 + self.line = line + self.column = column def visit(self, tabs = 0): node = self From b96fd17c7938061d4def40865d6777deee16be49 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 20:31:11 -0300 Subject: [PATCH 35/60] fix big problem --- src/compiler_components/cool_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 3c40f3a6e..d39924433 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -289,7 +289,7 @@ def p_error(p): errors.append(f'({line},{column}) - SyntacticError: ERROR at or near "{p.value}"') else: - errors.append(f'(0, 0) - SyntacticError: ERROR at or near EOF') + errors.append(f'(0, 0) - SyntacticError: ERROR at or near EOF)') ############## End Grammar ############################ From d76d71877f0f3e0c6a822e2760650120daf4f883 Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 20:39:44 -0300 Subject: [PATCH 36/60] column and line seted since parser to ast --- src/compiler_components/cool_parser.py | 92 ++++++++++++++++---------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index d39924433..0e55ded61 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -27,10 +27,11 @@ def p_def_class(p): '''def_class : CLASS TYPE_ID LBRACE feature_list RBRACE | CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE ''' + line, column = calculate_position(p.lexer.lexdata, p.lexpos) if len(p) == 6: - p[0] = ClassDeclarationNode(p[2], p[4]) + p[0] = ClassDeclarationNode(p[2], p[4], line = line, column = column) else: - p[0] = ClassDeclarationNode(p[2], p[6], p[4]) + p[0] = ClassDeclarationNode(p[2], p[6], p[4], line = line, column = column) def p_empty(p): 'empty :' @@ -50,16 +51,17 @@ def p_def_attr(p): '''def_attr : ID DOUBLE_DOT TYPE_ID | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr ''' + line, column = calculate_position(p.lexer.lexdata, p.lexpos) if len(p) == 4: - p[0] = AttrDeclarationNode(p[1], p[3]) + p[0] = AttrDeclarationNode(p[1], p[3], line = line, column = column) else: - p[0] = AttrDeclarationNode(p[1], p[3], p[5]) + p[0] = AttrDeclarationNode(p[1], p[3], p[5], line = line, column = column) def p_def_func(p): '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE ''' - - p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8], line = line, column = column) def p_param_list(p): '''param_list : param param_list2 @@ -104,22 +106,24 @@ def p_bool(p): | arith EQUALS arith | arith ''' + line, column = calculate_position(p.lexer.lexdata, p.lexpos) if len(p) == 3: - p[0] = NotNode(p[2]) + p[0] = NotNode(p[2], line = line, column = column) elif len(p) == 2: p[0] = p[1] else: if p[2] == '<': - p[0] = MinorNode(p[1], p[3]) + p[0] = MinorNode(p[1], p[3], line = line, column = column) elif p[2] == '<=': - p[0] = MinorEqualsNode(p[1], p[3]) + p[0] = MinorEqualsNode(p[1], p[3], line = line, column = column) else: - p[0] = EqualsNode(p[1], p[3]) + p[0] = EqualsNode(p[1], p[3], line = line, column = column) def p_expr2(p): 'expr : ID LEFT_ARROW expr' - p[0] = AssignNode(p[1], p[3]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = AssignNode(p[1], p[3], line = line, column = column) def p_arith(p): '''arith : term @@ -127,28 +131,30 @@ def p_arith(p): | arith PLUS term | arith MINUS term ''' + line, column = calculate_position(p.lexer.lexdata, p.lexpos) if len(p) == 2: p[0] = p[1] elif len(p) == 3: - p[0] = NotNode(p[2]) + p[0] = NotNode(p[2], line = line, column = column) else: if p[2] == '+': - p[0] = PlusNode(p[1], p[3]) + p[0] = PlusNode(p[1], p[3], line = line, column = column) else: - p[0] = MinusNode(p[1], p[3]) + p[0] = MinusNode(p[1], p[3], line = line, column = column) def p_term(p): '''term : factor | term TIMES factor | term DIVIDE factor ''' + line, column = calculate_position(p.lexer.lexdata, p.lexpos) if len(p) == 2: p[0] = p[1] else: if p[2] == '*': - p[0] = StarNode(p[1], p[3]) + p[0] = StarNode(p[1], p[3], line = line, column = column) else: - p[0] = DivNode(p[1], p[3]) + p[0] = DivNode(p[1], p[3], line = line, column = column) def p_factor(p): '''factor : atom @@ -162,11 +168,13 @@ def p_factor(p): #4 (por ahora) metodos para el no-terminal 'atom' def p_atom1(p): 'atom : ID' - p[0] = VariableNode(p[1]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = VariableNode(p[1], line = line, column = column) def p_atom2(p): 'atom : NUMBER' - p[0] = ConstantNumNode(p[1]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = ConstantNumNode(p[1], line = line, column = column) def p_atom3(p): 'atom : func_call' @@ -175,20 +183,23 @@ def p_atom3(p): def p_atom4(p): '''atom : NEW TYPE_ID ''' - p[0] = InstantiateNode(p[2]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = InstantiateNode(p[2], line = line, column = column) def p_atomString(p): 'atom : STRING' - p[0] = ConstantStringNode(p[1][1:len(p[1]) -1 ]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = ConstantStringNode(p[1][1:len(p[1]) -1 ], line = line, column = column) def p_atomBool(p): '''atom : TRUE | FALSE ''' + line, column = calculate_position(p.lexer.lexdata, p.lexpos) if p[1].lower() == "true": - p[0] = ConstantBooleanNode(True) + p[0] = ConstantBooleanNode(True, line = line, column = column) else: - p[0] = ConstantBooleanNode(False) + p[0] = ConstantBooleanNode(False, line = line, column = column) #def p_atomSelf(p): #'atom : SELF' @@ -196,19 +207,23 @@ def p_atomBool(p): def p_atomIF(p): 'atom : IF expr THEN expr ELSE expr FI' - p[0] = IfNode(p[2], p[4], p[6]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = IfNode(p[2], p[4], p[6], line = line, column = column) def p_atomCicle(p): 'atom : WHILE expr LOOP expr POOL' - p[0] = WhileNode(p[2], p[4]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = WhileNode(p[2], p[4], line = line, column = column) def p_atomBlock(p): 'atom : LBRACE expr_list RBRACE' - p[0] = BlockNode(p[2]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = BlockNode(p[2], line = line, column = column) def p_atomLet(p): 'atom : LET atr_decl_list IN expr' - p[0] = LetNode(p[2], p[4]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = LetNode(p[2], p[4], line = line, column = column) def p_atr_decl_list(p): '''atr_decl_list : def_attr @@ -222,20 +237,23 @@ def p_atr_decl_list(p): def p_atomCase(p): 'atom : CASE expr OF case_list ESAC' - p[0] = CaseNode(p[2], p[4]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = CaseNode(p[2], p[4], line = line, column = column) def p_caseList(p): '''case_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list ''' + line, column = calculate_position(p.lexer.lexdata, p.lexpos) if len(p) == 7: - p[0] = [AttrDeclarationNode(p[1], p[3], p[5])] + p[0] = [AttrDeclarationNode(p[1], p[3], p[5], line = line, column = column)] else: - p[0] = [AttrDeclarationNode(p[1], p[3], p[5])] + p[7] + p[0] = [AttrDeclarationNode(p[1], p[3], p[5], line = line, column = column)] + p[7] def p_atomIsVoid(p): 'atom : ISVOID factor' - p[0] = IsVoidNode(p[2]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = IsVoidNode(p[2], line = line, column = column) ''' def p_atomNot(p): @@ -245,22 +263,24 @@ def p_atomNot(p): def p_atomNhanhara(p): 'atom : NHANHARA factor' - p[0] = NhanharaNode(p[2]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = NhanharaNode(p[2], line = line, column = column) def p_func_call(p): '''func_call : factor DOT ID LPAREN arg_list RPAREN ''' - p[0] = DispatchNode(p[1], p[3], p[5]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = DispatchNode(p[1], p[3], p[5], line = line, column = column) def p_func_call2(p): 'func_call : ID LPAREN arg_list RPAREN' - - p[0] = CallNode(None, p[1], p[3]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = CallNode(None, p[1], p[3], line = line, column = column) def p_func_call3(p): 'func_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN' - - p[0] = DispatchNode(p[1], p[5], params = p[7], typex = p[3]) + line, column = calculate_position(p.lexer.lexdata, p.lexpos) + p[0] = DispatchNode(p[1], p[5], params = p[7], typex = p[3], line = line, column = column) From 5e1a8ee7f20bf1b7c646154fb4755b8707ce5e7a Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 20:44:51 -0300 Subject: [PATCH 37/60] position tokens fixed --- src/compiler_components/cool_parser.py | 47 +++++++++++++------------- src/program.txt | 12 ++++++- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 0e55ded61..792fa8e66 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -27,7 +27,8 @@ def p_def_class(p): '''def_class : CLASS TYPE_ID LBRACE feature_list RBRACE | CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) + if len(p) == 6: p[0] = ClassDeclarationNode(p[2], p[4], line = line, column = column) else: @@ -51,7 +52,7 @@ def p_def_attr(p): '''def_attr : ID DOUBLE_DOT TYPE_ID | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 4: p[0] = AttrDeclarationNode(p[1], p[3], line = line, column = column) else: @@ -60,7 +61,7 @@ def p_def_attr(p): def p_def_func(p): '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8], line = line, column = column) def p_param_list(p): @@ -106,7 +107,7 @@ def p_bool(p): | arith EQUALS arith | arith ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 3: p[0] = NotNode(p[2], line = line, column = column) @@ -122,7 +123,7 @@ def p_bool(p): def p_expr2(p): 'expr : ID LEFT_ARROW expr' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = AssignNode(p[1], p[3], line = line, column = column) def p_arith(p): @@ -131,7 +132,7 @@ def p_arith(p): | arith PLUS term | arith MINUS term ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 2: p[0] = p[1] elif len(p) == 3: @@ -147,7 +148,7 @@ def p_term(p): | term TIMES factor | term DIVIDE factor ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 2: p[0] = p[1] else: @@ -168,12 +169,12 @@ def p_factor(p): #4 (por ahora) metodos para el no-terminal 'atom' def p_atom1(p): 'atom : ID' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = VariableNode(p[1], line = line, column = column) def p_atom2(p): 'atom : NUMBER' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = ConstantNumNode(p[1], line = line, column = column) def p_atom3(p): @@ -183,19 +184,19 @@ def p_atom3(p): def p_atom4(p): '''atom : NEW TYPE_ID ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = InstantiateNode(p[2], line = line, column = column) def p_atomString(p): 'atom : STRING' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = ConstantStringNode(p[1][1:len(p[1]) -1 ], line = line, column = column) def p_atomBool(p): '''atom : TRUE | FALSE ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if p[1].lower() == "true": p[0] = ConstantBooleanNode(True, line = line, column = column) else: @@ -207,22 +208,22 @@ def p_atomBool(p): def p_atomIF(p): 'atom : IF expr THEN expr ELSE expr FI' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = IfNode(p[2], p[4], p[6], line = line, column = column) def p_atomCicle(p): 'atom : WHILE expr LOOP expr POOL' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = WhileNode(p[2], p[4], line = line, column = column) def p_atomBlock(p): 'atom : LBRACE expr_list RBRACE' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = BlockNode(p[2], line = line, column = column) def p_atomLet(p): 'atom : LET atr_decl_list IN expr' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = LetNode(p[2], p[4], line = line, column = column) def p_atr_decl_list(p): @@ -237,14 +238,14 @@ def p_atr_decl_list(p): def p_atomCase(p): 'atom : CASE expr OF case_list ESAC' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = CaseNode(p[2], p[4], line = line, column = column) def p_caseList(p): '''case_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 7: p[0] = [AttrDeclarationNode(p[1], p[3], p[5], line = line, column = column)] else: @@ -252,7 +253,7 @@ def p_caseList(p): def p_atomIsVoid(p): 'atom : ISVOID factor' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = IsVoidNode(p[2], line = line, column = column) ''' @@ -263,23 +264,23 @@ def p_atomNot(p): def p_atomNhanhara(p): 'atom : NHANHARA factor' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = NhanharaNode(p[2], line = line, column = column) def p_func_call(p): '''func_call : factor DOT ID LPAREN arg_list RPAREN ''' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = DispatchNode(p[1], p[3], p[5], line = line, column = column) def p_func_call2(p): 'func_call : ID LPAREN arg_list RPAREN' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = CallNode(None, p[1], p[3], line = line, column = column) def p_func_call3(p): 'func_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN' - line, column = calculate_position(p.lexer.lexdata, p.lexpos) + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = DispatchNode(p[1], p[5], params = p[7], typex = p[3], line = line, column = column) diff --git a/src/program.txt b/src/program.txt index 33cbcd02a..93a371e1c 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1 +1,11 @@ -(* A Cool program can't be empty *) +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; From 29823eb8f8c2c48c2de2e78ee1084075773dd69a Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 21:08:56 -0300 Subject: [PATCH 38/60] line and column of inherit class added --- src/compiler_components/ast.py | 18 +-- src/compiler_components/cool_parser.py | 10 +- src/compiler_components/parsetab.py | 119 +++++++++--------- .../semantic/type_checker.py | 2 +- .../semantic/type_collector.py | 2 +- src/program.txt | 12 +- 6 files changed, 85 insertions(+), 78 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index c8255f846..8a1f55a52 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -37,12 +37,14 @@ def visit(self, tabs = 0): class ClassDeclarationNode(DeclarationNode): - def __init__(self, idx, features, parent=None, line = -1, column=-1): + def __init__(self, idx, features, parent=None, line = -1, column=-1, line_father = -1, column_father = -1): self.id = idx self.parent = parent self.features = features self.line = line self.column = column + self.line_father = line_father + self.column_father = column_father def visit(self, tabs = 0): node = self @@ -325,29 +327,29 @@ def visit(self, tabs): return '\t' * tabs + f'\\__ InstantiateNode: new {node.lex}()' -class PlusNode(BinaryNode): +class PlusNode(ArithmeticNode): pass -class MinusNode(BinaryNode): +class MinusNode(ArithmeticNode): pass -class StarNode(BinaryNode): +class StarNode(ArithmeticNode): pass -class DivNode(BinaryNode): +class DivNode(ArithmeticNode): pass -class MinorNode(BinaryNode): +class MinorNode(ArithmeticNode): pass -class MinorEqualsNode(BinaryNode): +class MinorEqualsNode(ArithmeticNode): pass -class EqualsNode(BinaryNode): +class EqualsNode(ArithmeticNode): pass diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 792fa8e66..000c82422 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -25,14 +25,20 @@ def p_class_list(p): def p_def_class(p): '''def_class : CLASS TYPE_ID LBRACE feature_list RBRACE - | CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE + | CLASS TYPE_ID INHERITS type_inherit LBRACE feature_list RBRACE ''' + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 6: p[0] = ClassDeclarationNode(p[2], p[4], line = line, column = column) else: - p[0] = ClassDeclarationNode(p[2], p[6], p[4], line = line, column = column) + p[0] = ClassDeclarationNode(p[2], p[6], p[4]['value'], line = line, column = column, line_father = p[4]['line'], column_father = p[4]['column']) + +def p_type_inherit(p): + 'type_inherit : TYPE_ID' + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) + p[0] = {'value':p[1], 'line':line, 'column':column} def p_empty(p): 'empty :' diff --git a/src/compiler_components/parsetab.py b/src/compiler_components/parsetab.py index fcb97f8de..bc50cb00c 100644 --- a/src/compiler_components/parsetab.py +++ b/src/compiler_components/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS TYPE_ID LBRACE feature_list RBRACE\n | CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE\n empty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT TYPE_ID\n | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' +_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS TYPE_ID LBRACE feature_list RBRACE\n | CLASS TYPE_ID INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT TYPE_ID\n | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-2,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,39,41,42,43,44,46,47,49,50,51,64,65,76,80,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,134,136,141,143,144,],[5,17,18,-4,-10,-5,-36,-11,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,107,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-12,-54,-43,-56,145,]),'TYPE_ID':([4,9,19,31,48,60,74,133,],[6,15,24,59,76,87,102,139,]),'LBRACE':([6,15,30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,87,94,104,105,107,108,111,114,117,130,137,142,],[8,21,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,111,54,54,54,54,54,54,54,54,54,54,54,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,30,34,40,45,52,53,54,55,56,57,58,62,63,66,67,68,69,70,71,72,73,94,104,105,107,108,109,110,111,114,117,118,130,137,142,145,],[14,14,14,25,14,37,25,65,37,37,37,37,83,37,65,65,37,37,65,65,65,65,65,65,65,101,65,37,37,37,37,83,125,37,37,37,129,37,37,37,125,]),'RBRACE':([8,10,13,17,18,21,22,23,29,37,39,41,42,43,44,46,47,49,50,51,64,65,76,79,85,86,89,93,95,96,97,98,99,100,103,106,107,112,116,121,122,126,131,132,136,141,143,],[-6,16,-9,-6,-6,-6,-7,-8,36,-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,106,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-18,-55,-28,-19,-46,134,-44,-49,-54,-43,-56,]),'DOUBLE_DOT':([14,25,32,83,125,],[19,31,60,19,133,]),'LPAREN':([14,30,37,40,45,52,53,54,56,57,58,62,63,65,66,67,68,69,70,71,72,94,101,104,105,107,108,111,114,117,129,130,137,142,],[20,45,63,45,45,45,45,45,45,45,45,45,45,63,45,45,45,45,45,45,45,45,117,45,45,45,45,45,45,45,137,45,45,45,]),'RPAREN':([20,26,27,28,33,35,37,39,41,42,43,44,46,47,49,50,51,59,61,63,64,65,75,76,85,86,88,89,90,91,92,93,95,96,97,98,99,100,103,106,112,113,115,116,117,122,127,128,131,132,135,136,137,140,141,143,],[-6,32,-6,-14,-13,-16,-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-17,-6,-6,-21,-36,103,-39,-52,-53,-15,-26,112,-6,-58,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-57,-60,-28,-6,-46,-6,136,-44,-49,-59,-54,-6,143,-43,-56,]),'COMMA':([24,27,37,38,39,41,42,43,44,46,47,49,50,51,59,61,64,65,76,82,85,86,89,91,93,95,96,97,98,99,100,103,106,112,116,122,127,131,132,136,141,143,],[-10,34,-36,-11,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-17,34,-21,-36,-39,109,-52,-53,-26,114,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,114,-44,-49,-54,-43,-56,]),'IN':([24,37,38,39,41,42,43,44,46,47,49,50,51,64,65,76,81,82,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,123,131,132,136,141,143,],[-10,-36,-11,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,108,-47,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-48,-44,-49,-54,-43,-56,]),'LEFT_ARROW':([24,37,],[30,62,]),'NOT':([30,40,45,52,53,54,56,62,63,66,67,68,94,104,105,107,108,111,114,117,130,137,142,],[40,40,40,40,40,40,40,40,40,94,94,94,40,40,40,40,40,40,40,40,40,40,40,]),'NUMBER':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'NEW':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'STRING':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'TRUE':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'FALSE':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'IF':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'WHILE':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'LET':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'CASE':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,]),'ISVOID':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'NHANHARA':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'DOT':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,102,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,73,-34,-37,-38,-40,-41,-42,-21,-36,-39,73,73,-26,-22,-23,-24,-29,-30,73,73,118,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'ARROBA':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,74,-34,-37,-38,-40,-41,-42,-21,-36,-39,74,74,-26,-22,-23,-24,-29,-30,74,74,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'TIMES':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,71,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,71,71,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'DIVIDE':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,72,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,72,72,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'MINOR':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,66,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'MINOR_EQUALS':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,67,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'EQUALS':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,68,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'PLUS':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,69,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,69,69,69,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'MINUS':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,70,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,70,70,70,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'THEN':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,77,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,104,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'LOOP':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,78,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,105,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'OF':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,84,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,110,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,-43,-56,]),'ELSE':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,119,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,130,-46,-44,-49,-54,-43,-56,]),'POOL':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,120,122,131,132,136,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,131,-46,-44,-49,-54,-43,-56,]),'FI':([37,39,41,42,43,44,46,47,49,50,51,64,65,76,85,86,89,93,95,96,97,98,99,100,103,106,112,116,122,131,132,136,138,141,143,],[-36,-20,-25,-27,-31,-34,-37,-38,-40,-41,-42,-21,-36,-39,-52,-53,-26,-22,-23,-24,-29,-30,-32,-33,-35,-45,-55,-28,-46,-44,-49,-54,141,-43,-56,]),'ESAC':([124,145,146,],[132,-50,-51,]),'RIGHT_ARROW':([139,],[142,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-2,-3,]),'SEMICOLON':([3,11,12,17,25,37,38,39,40,42,43,44,45,47,48,50,51,52,65,66,77,81,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,135,137,142,144,145,],[5,18,19,-4,-11,-5,-37,-12,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,108,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-13,-55,-44,-57,146,]),'TYPE_ID':([4,9,20,32,49,61,75,134,],[6,15,25,60,77,88,103,140,]),'LBRACE':([6,15,16,31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,88,95,105,106,108,109,112,115,118,131,138,143,],[8,-6,22,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,112,55,55,55,55,55,55,55,55,55,55,55,]),'INHERITS':([6,],[9,]),'ID':([8,18,19,21,22,31,35,41,46,53,54,55,56,57,58,59,63,64,67,68,69,70,71,72,73,74,95,105,106,108,109,110,111,112,115,118,119,131,138,143,146,],[14,14,14,26,14,38,26,66,38,38,38,38,84,38,66,66,38,38,66,66,66,66,66,66,66,102,66,38,38,38,38,84,126,38,38,38,130,38,38,38,126,]),'RBRACE':([8,10,13,18,19,22,23,24,30,38,40,42,43,44,45,47,48,50,51,52,65,66,77,80,86,87,90,94,96,97,98,99,100,101,104,107,108,113,117,122,123,127,132,133,137,142,144,],[-7,17,-10,-7,-7,-7,-8,-9,37,-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,107,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-19,-56,-29,-20,-47,135,-45,-50,-55,-44,-57,]),'DOUBLE_DOT':([14,26,33,84,126,],[20,32,61,20,134,]),'LPAREN':([14,31,38,41,46,53,54,55,57,58,59,63,64,66,67,68,69,70,71,72,73,95,102,105,106,108,109,112,115,118,130,131,138,143,],[21,46,64,46,46,46,46,46,46,46,46,46,46,64,46,46,46,46,46,46,46,46,118,46,46,46,46,46,46,46,138,46,46,46,]),'RPAREN':([21,27,28,29,34,36,38,40,42,43,44,45,47,48,50,51,52,60,62,64,65,66,76,77,86,87,89,90,91,92,93,94,96,97,98,99,100,101,104,107,113,114,116,117,118,123,128,129,132,133,136,137,138,141,142,144,],[-7,33,-7,-15,-14,-17,-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-18,-7,-7,-22,-37,104,-40,-53,-54,-16,-27,113,-7,-59,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-58,-61,-29,-7,-47,-7,137,-45,-50,-60,-55,-7,144,-44,-57,]),'COMMA':([25,28,38,39,40,42,43,44,45,47,48,50,51,52,60,62,65,66,77,83,86,87,90,92,94,96,97,98,99,100,101,104,107,113,117,123,128,132,133,137,142,144,],[-11,35,-37,-12,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-18,35,-22,-37,-40,110,-53,-54,-27,115,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,115,-45,-50,-55,-44,-57,]),'IN':([25,38,39,40,42,43,44,45,47,48,50,51,52,65,66,77,82,83,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,124,132,133,137,142,144,],[-11,-37,-12,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,109,-48,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-49,-45,-50,-55,-44,-57,]),'LEFT_ARROW':([25,38,],[31,63,]),'NOT':([31,41,46,53,54,55,57,63,64,67,68,69,95,105,106,108,109,112,115,118,131,138,143,],[41,41,41,41,41,41,41,41,41,95,95,95,41,41,41,41,41,41,41,41,41,41,41,]),'NUMBER':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'NEW':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'TRUE':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'FALSE':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'IF':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'WHILE':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'LET':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,]),'CASE':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'ISVOID':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'NHANHARA':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'DOT':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,103,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,74,-35,-38,-39,-41,-42,-43,-22,-37,-40,74,74,-27,-23,-24,-25,-30,-31,74,74,119,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'ARROBA':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,75,-35,-38,-39,-41,-42,-43,-22,-37,-40,75,75,-27,-23,-24,-25,-30,-31,75,75,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'TIMES':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,72,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,72,72,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'DIVIDE':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,73,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,73,73,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'MINOR':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,67,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'MINOR_EQUALS':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,68,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'EQUALS':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,69,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'PLUS':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,70,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,70,70,70,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'MINUS':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,71,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,71,71,71,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'THEN':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,78,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,105,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'LOOP':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,79,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,106,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'OF':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,85,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,111,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'ELSE':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,120,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,131,-47,-45,-50,-55,-44,-57,]),'POOL':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,121,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,132,-47,-45,-50,-55,-44,-57,]),'FI':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,139,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,142,-44,-57,]),'ESAC':([125,146,147,],[133,-51,-52,]),'RIGHT_ARROW':([140,],[143,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,29,]),'def_attr':([8,17,18,21,55,109,],[11,11,11,11,82,82,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'empty':([8,17,18,20,21,27,61,63,91,117,127,137,],[13,13,13,28,13,35,35,92,115,92,115,92,]),'param_list':([20,],[26,]),'param':([20,34,],[27,61,]),'param_list2':([27,61,],[33,88,]),'expr':([30,45,52,53,54,56,62,63,104,105,107,108,111,114,117,130,137,142,],[38,75,77,78,80,84,89,91,119,120,80,122,126,127,91,138,91,144,]),'bool':([30,40,45,52,53,54,56,62,63,94,104,105,107,108,111,114,117,130,137,142,],[39,64,39,39,39,39,39,39,39,116,39,39,39,39,39,39,39,39,39,39,]),'arith':([30,40,45,52,53,54,56,62,63,66,67,68,94,104,105,107,108,111,114,117,130,137,142,],[41,41,41,41,41,41,41,41,41,93,95,96,41,41,41,41,41,41,41,41,41,41,41,]),'term':([30,40,45,52,53,54,56,62,63,66,67,68,69,70,94,104,105,107,108,111,114,117,130,137,142,],[42,42,42,42,42,42,42,42,42,42,42,42,97,98,42,42,42,42,42,42,42,42,42,42,42,]),'factor':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[43,43,43,43,43,43,43,85,86,43,43,43,43,43,43,43,99,100,43,43,43,43,43,43,43,43,43,43,43,]),'atom':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'func_call':([30,40,45,52,53,54,56,57,58,62,63,66,67,68,69,70,71,72,94,104,105,107,108,111,114,117,130,137,142,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'expr_list':([54,107,],[79,121,]),'atr_decl_list':([55,109,],[81,123,]),'arg_list':([63,117,137,],[90,128,140,]),'arg_list2':([91,127,],[113,135,]),'case_list':([110,145,],[124,146,]),} +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,18,19,22,],[10,23,24,30,]),'def_attr':([8,18,19,22,56,110,],[11,11,11,11,83,83,]),'def_func':([8,18,19,22,],[12,12,12,12,]),'empty':([8,18,19,21,22,28,62,64,92,118,128,138,],[13,13,13,29,13,36,36,93,116,93,116,93,]),'type_inherit':([9,],[16,]),'param_list':([21,],[27,]),'param':([21,35,],[28,62,]),'param_list2':([28,62,],[34,89,]),'expr':([31,46,53,54,55,57,63,64,105,106,108,109,112,115,118,131,138,143,],[39,76,78,79,81,85,90,92,120,121,81,123,127,128,92,139,92,145,]),'bool':([31,41,46,53,54,55,57,63,64,95,105,106,108,109,112,115,118,131,138,143,],[40,65,40,40,40,40,40,40,40,117,40,40,40,40,40,40,40,40,40,40,]),'arith':([31,41,46,53,54,55,57,63,64,67,68,69,95,105,106,108,109,112,115,118,131,138,143,],[42,42,42,42,42,42,42,42,42,94,96,97,42,42,42,42,42,42,42,42,42,42,42,]),'term':([31,41,46,53,54,55,57,63,64,67,68,69,70,71,95,105,106,108,109,112,115,118,131,138,143,],[43,43,43,43,43,43,43,43,43,43,43,43,98,99,43,43,43,43,43,43,43,43,43,43,43,]),'factor':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[44,44,44,44,44,44,44,86,87,44,44,44,44,44,44,44,100,101,44,44,44,44,44,44,44,44,44,44,44,]),'atom':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'func_call':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'expr_list':([55,108,],[80,122,]),'atr_decl_list':([56,110,],[82,124,]),'arg_list':([64,118,138,],[91,129,141,]),'arg_list2':([92,128,],[114,136,]),'case_list':([111,146,],[125,147,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -31,60 +31,61 @@ ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','cool_parser.py',18), ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','cool_parser.py',19), ('def_class -> CLASS TYPE_ID LBRACE feature_list RBRACE','def_class',5,'p_def_class','cool_parser.py',27), - ('def_class -> CLASS TYPE_ID INHERITS TYPE_ID LBRACE feature_list RBRACE','def_class',7,'p_def_class','cool_parser.py',28), - ('empty -> ','empty',0,'p_empty','cool_parser.py',36), - ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',40), - ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',41), - ('feature_list -> empty','feature_list',1,'p_feature_list','cool_parser.py',42), - ('def_attr -> ID DOUBLE_DOT TYPE_ID','def_attr',3,'p_def_attr','cool_parser.py',50), - ('def_attr -> ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',51), - ('def_func -> ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE','def_func',9,'p_def_func','cool_parser.py',59), - ('param_list -> param param_list2','param_list',2,'p_param_list','cool_parser.py',65), - ('param_list -> empty','param_list',1,'p_param_list','cool_parser.py',66), - ('param_list2 -> COMMA param param_list2','param_list2',3,'p_param_list2','cool_parser.py',74), - ('param_list2 -> empty','param_list2',1,'p_param_list2','cool_parser.py',75), - ('param -> ID DOUBLE_DOT TYPE_ID','param',3,'p_param','cool_parser.py',83), - ('expr_list -> expr SEMICOLON','expr_list',2,'p_expr_list','cool_parser.py',88), - ('expr_list -> expr SEMICOLON expr_list','expr_list',3,'p_expr_list','cool_parser.py',89), - ('expr -> bool','expr',1,'p_expr','cool_parser.py',97), - ('bool -> NOT bool','bool',2,'p_bool','cool_parser.py',101), - ('bool -> arith MINOR arith','bool',3,'p_bool','cool_parser.py',102), - ('bool -> arith MINOR_EQUALS arith','bool',3,'p_bool','cool_parser.py',103), - ('bool -> arith EQUALS arith','bool',3,'p_bool','cool_parser.py',104), - ('bool -> arith','bool',1,'p_bool','cool_parser.py',105), - ('expr -> ID LEFT_ARROW expr','expr',3,'p_expr2','cool_parser.py',121), - ('arith -> term','arith',1,'p_arith','cool_parser.py',125), - ('arith -> NOT bool','arith',2,'p_arith','cool_parser.py',126), - ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',127), - ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',128), - ('term -> factor','term',1,'p_term','cool_parser.py',141), - ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',142), - ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',143), - ('factor -> atom','factor',1,'p_factor','cool_parser.py',154), - ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',155), - ('atom -> ID','atom',1,'p_atom1','cool_parser.py',164), - ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',168), - ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',172), - ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',176), - ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',181), - ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',186), - ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',187), - ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',199), - ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',203), - ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',207), - ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',211), - ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',215), - ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',216), - ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',225), - ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',229), - ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',230), - ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',238), - ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',248), - ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',252), - ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',257), - ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',262), - ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',269), - ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',270), - ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',278), - ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',279), + ('def_class -> CLASS TYPE_ID INHERITS type_inherit LBRACE feature_list RBRACE','def_class',7,'p_def_class','cool_parser.py',28), + ('type_inherit -> TYPE_ID','type_inherit',1,'p_type_inherit','cool_parser.py',39), + ('empty -> ','empty',0,'p_empty','cool_parser.py',46), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',50), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',51), + ('feature_list -> empty','feature_list',1,'p_feature_list','cool_parser.py',52), + ('def_attr -> ID DOUBLE_DOT TYPE_ID','def_attr',3,'p_def_attr','cool_parser.py',60), + ('def_attr -> ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',61), + ('def_func -> ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE','def_func',9,'p_def_func','cool_parser.py',70), + ('param_list -> param param_list2','param_list',2,'p_param_list','cool_parser.py',76), + ('param_list -> empty','param_list',1,'p_param_list','cool_parser.py',77), + ('param_list2 -> COMMA param param_list2','param_list2',3,'p_param_list2','cool_parser.py',85), + ('param_list2 -> empty','param_list2',1,'p_param_list2','cool_parser.py',86), + ('param -> ID DOUBLE_DOT TYPE_ID','param',3,'p_param','cool_parser.py',94), + ('expr_list -> expr SEMICOLON','expr_list',2,'p_expr_list','cool_parser.py',99), + ('expr_list -> expr SEMICOLON expr_list','expr_list',3,'p_expr_list','cool_parser.py',100), + ('expr -> bool','expr',1,'p_expr','cool_parser.py',108), + ('bool -> NOT bool','bool',2,'p_bool','cool_parser.py',112), + ('bool -> arith MINOR arith','bool',3,'p_bool','cool_parser.py',113), + ('bool -> arith MINOR_EQUALS arith','bool',3,'p_bool','cool_parser.py',114), + ('bool -> arith EQUALS arith','bool',3,'p_bool','cool_parser.py',115), + ('bool -> arith','bool',1,'p_bool','cool_parser.py',116), + ('expr -> ID LEFT_ARROW expr','expr',3,'p_expr2','cool_parser.py',133), + ('arith -> term','arith',1,'p_arith','cool_parser.py',138), + ('arith -> NOT bool','arith',2,'p_arith','cool_parser.py',139), + ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',140), + ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',141), + ('term -> factor','term',1,'p_term','cool_parser.py',155), + ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',156), + ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',157), + ('factor -> atom','factor',1,'p_factor','cool_parser.py',169), + ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',170), + ('atom -> ID','atom',1,'p_atom1','cool_parser.py',179), + ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',184), + ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',189), + ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',193), + ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',199), + ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',204), + ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',205), + ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',218), + ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',223), + ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',228), + ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',233), + ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',238), + ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',239), + ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',248), + ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',253), + ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',254), + ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',263), + ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',274), + ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',279), + ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',285), + ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',290), + ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',297), + ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',298), + ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',306), + ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',307), ] diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index 89b47119e..e94b31470 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -299,7 +299,7 @@ def visit(self, node:ArithmeticNode,scope:Scope): self.visit(node.left,scope.create_child()) self.visit(node.right,scope.create_child()) if node.left.type != self.context.get_type("Int", node.line) or node.right.type != self.context.get_type("Int", node.line): - self.errors.append("The static types of the two sub-expressions must be Int.") + self.errors.append(f"({node.line},{node.column}) - TypeError: static types of the two sub-expressions must be Int.") node.type = self.context.get_type("Int", node.line) diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py index df6435eb5..03b2f8fc4 100644 --- a/src/compiler_components/semantic/type_collector.py +++ b/src/compiler_components/semantic/type_collector.py @@ -28,7 +28,7 @@ def visit(self, node): try: if dec_node.parent is not None: if dec_node.parent in ["String","Int","Bool"]: - self.errors.append(SemanticError("Basic type as parent", dec_node.line)) + self.errors.append(f"({dec_node.line_father},{dec_node.column_father}) - SemanticError: Basic type as parent") self.context.get_type(dec_node.id, dec_node.line).set_parent(self.context.get_type(dec_node.parent,dec_node.line),node.line) except SemanticError as e: self.errors.append(e) diff --git a/src/program.txt b/src/program.txt index 93a371e1c..cf2b1cd2f 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,11 +1,9 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; +-- It is an error to inherit from or redefine Int. class Main inherits IO { main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; + +class A inherits Int { + is_prime(): Bool { false }; }; From fa604159552ae23fcc9e11daa8fb5a437c8b6e4a Mon Sep 17 00:00:00 2001 From: Carlos Date: Thu, 24 Feb 2022 21:34:01 -0300 Subject: [PATCH 39/60] working at semantic checker tester --- .../semantic/structures.py | 7 +++-- .../semantic/type_checker.py | 6 ++-- .../semantic/type_collector.py | 1 + src/program.txt | 28 +++++++++++++++---- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index 030ccae2e..d6baa743c 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -81,16 +81,16 @@ def define_attribute(self, name:str, typex, pos): else: raise SemanticError(f'Attribute "{name}" is already defined in {self.name}',pos) - def get_method(self, name:str,pos=0): + def get_method(self, name:str,line=0, col=0): try: return next(method for method in self.methods if method.name == name) except StopIteration: if self.parent is None: - raise AttributeError(f'Method "{name}" is not defined in {self.name}',pos) + raise AttributeError(f'{line},{col} - NameError: Undeclared identifier {name}') try: return self.parent.get_method(name) except SemanticError: - raise AttributeError(f'Method "{name}" is not defined in {self.name}',pos) + raise AttributeError(f'{line},{col} - NameError: Undeclared identifier {name}') def define_method(self, name:str, param_names:list, param_types:list, return_type, pos): try: @@ -103,6 +103,7 @@ def define_method(self, name:str, param_names:list, param_types:list, return_ty except AttributeError as e: method = Method(name, param_names, param_types, return_type) self.methods.append(method) + return method def all_attributes(self, clean=True): plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index e94b31470..f4ee39471 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -59,7 +59,7 @@ def visit(self, node:AttrDeclarationNode,scope:Scope): @visitor.when(FuncDeclarationNode) def visit(self, node:FuncDeclarationNode,scope:Scope): - method = self.current_type.get_method(node.id) + method = self.current_type.get_method(node.id, node.line, node.column) for i in range(len(method.param_names)): try: @@ -209,7 +209,7 @@ def visit(self, node:AssignNode,scope:Scope): at = [ at[0] for at in self.current_type.all_attributes() if at[0].name == node.id] var = at[0] except: - raise NameError(f"Variable {node.id} not defined",node.line) + raise NameError(f"({node.line}, {node.column}) - NameError: Undeclared identifier {node.id}") typex = self.current_type if isinstance(var.type , SELF_TYPE) else var.type @@ -371,7 +371,7 @@ def visit (self, node:VariableNode,scope:Scope): x = at[0] except: node.type = ErrorType() - self.errors.append(NameError(f"Variable {node.lex} not defined",node.line)) + self.errors.append(NameError(f"({node.line}, {node.column}) - NameError: Undeclared identifier {node.lex}")) return node.type = x.type if not isinstance(x.type , SELF_TYPE) else self.current_type diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py index 03b2f8fc4..eed65bb04 100644 --- a/src/compiler_components/semantic/type_collector.py +++ b/src/compiler_components/semantic/type_collector.py @@ -39,6 +39,7 @@ def visit(self, node): return for decl in classes: + self.current_type = self.context.get_type(decl.id) for feature in decl.features: self.visit(feature) diff --git a/src/program.txt b/src/program.txt index cf2b1cd2f..635a6fad7 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,9 +1,25 @@ --- It is an error to inherit from or redefine Int. +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class B inherits A { + b: Bool <- true; +}; +class C inherits B { + c: String <- "C"; +}; +class D inherits B { + d: IO <- new Main.main(); +}; class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Int { - is_prime(): Bool { false }; + main(): IO { out_string("Hello World!") }; }; From d9878f49a2d1a99ac47f26d869f8c0079f050d04 Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Thu, 24 Feb 2022 22:58:40 -0500 Subject: [PATCH 40/60] Fill some semantic errors --- .idea/misc.xml | 4 ++ .../semantic/type_checker.py | 56 +++++++++---------- .../semantic/type_collector.py | 22 ++++---- src/program.txt | 28 ++-------- 4 files changed, 48 insertions(+), 62 deletions(-) create mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..59e0b8397 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index f4ee39471..a415c509a 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -20,7 +20,7 @@ def visit(self, node:ProgramNode, scope=None): try: self.visit(dec,scope.create_child()) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) @visitor.when(ClassDeclarationNode) @@ -29,7 +29,7 @@ def visit(self, node:ClassDeclarationNode, scope:Scope): typex = self.context.get_type(node.id, node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) self.current_type = typex #for at in typex.all_attributes(): @@ -54,7 +54,7 @@ def visit(self, node:AttrDeclarationNode,scope:Scope): typex =self.current_type if node.type == "SELF_TYPE" else self.context.get_type(node.type,node.line) self.context.check_type(node.expr.type,typex,node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) @visitor.when(FuncDeclarationNode) def visit(self, node:FuncDeclarationNode,scope:Scope): @@ -68,14 +68,14 @@ def visit(self, node:FuncDeclarationNode,scope:Scope): scope.define_variable(method.param_names[i],method.param_types[i],node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) self.visit(node.body,scope.create_child()) try: typex = method.return_type if not isinstance(method.return_type,SELF_TYPE) else self.current_type self.context.check_type(node.body.type,typex,node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) @visitor.when(CaseNode) @@ -89,12 +89,12 @@ def visit(self, node:CaseNode, scope:Scope): for branches in node.list_case: tmpscope = scb.create_child() if branches.type in typesbr: - self.errors.append(SemanticError("Type in more than one branch",branches.expr.line)) + self.errors.append(f"({node.line},{node.column}) - SemanticError: Type in more than one branch") typesbr.add(branches.type) try : typex = self.context.get_type(branches.type,branches.expr.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) tmpscope.define_variable(branches.id,typex,node.line) self.visit(branches.expr,tmpscope) if common_type is None: @@ -122,7 +122,7 @@ def visit(self, node:DispatchNode, scope:Scope): temp = self.context.get_type(node.typex,node.line) self.context.check_type(node.expr.type,temp,node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) return else: if isinstance( node.expr.type , ErrorType): @@ -131,7 +131,7 @@ def visit(self, node:DispatchNode, scope:Scope): try: typex = self.context.get_type(node.typex,node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) return try : if isinstance( typex , ErrorType): @@ -146,9 +146,9 @@ def visit(self, node:DispatchNode, scope:Scope): try: self.context.check_type(node.params[i].type,method.param_types[i],node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) @visitor.when(CallNode) def visit(self, node:CallNode, scope:Scope): @@ -169,9 +169,9 @@ def visit(self, node:CallNode, scope:Scope): try: self.context.check_type(node.args[i].type,method.param_types[i],node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) @@ -182,7 +182,7 @@ def visit(self,node:IfNode,scope:Scope): try: self.context.check_type(node.if_c.type,self.context.get_type("Bool"),node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) self.visit(node.then_c,scope.create_child()) @@ -191,7 +191,7 @@ def visit(self,node:IfNode,scope:Scope): try: node.type = self.context.closest_common_antecesor(node.then_c.type, node.else_c.type) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) node.type = ErrorType() @@ -216,7 +216,7 @@ def visit(self, node:AssignNode,scope:Scope): self.context.check_type(node.expr.type, typex, node.line) node.type = node.expr.type except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) node.type = node.expr.type @@ -251,7 +251,7 @@ def visit(self, node:LetNode,scope:Scope): typey = self.context.get_type(init.type,node.line) if init.expr.type != "SELF_TYPE" else self.current_type self.context.check_type(typex,typey,node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) sc = sc.create_child() @@ -259,14 +259,14 @@ def visit(self, node:LetNode,scope:Scope): try: typex = self.context.get_type(init.type,node.line) if init.type != "SELF_TYPE" else self.current_type except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) typex = ErrorType() try: if init.id == "self": raise SemanticError('Trying to assign value to self' ,node.line) sc.define_variable(init.id,typex,node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) sc = sc.create_child() node.body_scope=sc @@ -282,7 +282,7 @@ def visit(self, node:InstantiateNode,scope:Scope): else: node.type = self.context.get_type(node.lex,node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) node.type = ErrorType() @@ -308,20 +308,20 @@ def visit(self, node:ArithmeticNode,scope:Scope): def visit(self, node:MinorNode,scope:Scope): self.visit(node.left,scope.create_child()) if node.left.type != self.context.get_type("Int", node.line): - self.errors.append("Expr must be Int not " + str(node.left.type)) + self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Int not " + str(node.left.type)) self.visit(node.right,scope.create_child()) if node.right.type != self.context.get_type("Int", node.line): - self.errors.append("Expr must be Int not " + str(node.right.type)) + self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Int not " + str(node.right.type)) node.type = self.context.get_type("Bool", node.line) @visitor.when(MinorEqualsNode) def visit(self, node:MinorEqualsNode, scope:Scope): self.visit(node.left,scope.create_child()) if node.left.type != self.context.get_type("Int", node.line): - self.errors.append("Expr must be Int not " + str(node.left.type)) + self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Int not " + str(node.left.type)) self.visit(node.right,scope.create_child()) if node.right.type != self.context.get_type("Int", node.line): - self.errors.append("Expr must be Int not " + str(node.right.type)) + self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Int not " + str(node.right.type)) node.type = self.context.get_type("Bool", node.line) @visitor.when(EqualsNode) @@ -331,21 +331,21 @@ def visit(self, node:EqualsNode, scope:Scope): if node.left.type != node.right.type: basic = ['Int', 'String', 'Bool'] if node.left.type.name in basic or node.right.type.name in basic: - self.errors.append(TypeError("Ilegal comparison with a basic type", node.line)) + self.errors.append(f"({node.line},{node.column}) - SemanticError: Ilegal comparison with a basic type") node.type = self.context.get_type("Bool", node.line) @visitor.when(NhanharaNode) def visit(self, node:NhanharaNode, scope:Scope): self.visit(node.expr, scope.create_child()) if node.expr.type != self.context.get_type("Int", node.line): - self.errors.append("Expr must be an int not " + str(node.expr.type)) + self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be an int not " + str(node.expr.type)) node.type = self.context.get_type("Int", node.line) @visitor.when(NotNode) def visit(self, node:NotNode, scope:Scope): self.visit(node.expr, scope.create_child()) if node.expr.type != self.context.get_type("Bool", node.line): - self.errors.append("Expr must be Bool not " + str(node.expr.type)) + self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Bool not " + str(node.expr.type)) node.type = self.context.get_type("Bool", node.line) @@ -371,7 +371,7 @@ def visit (self, node:VariableNode,scope:Scope): x = at[0] except: node.type = ErrorType() - self.errors.append(NameError(f"({node.line}, {node.column}) - NameError: Undeclared identifier {node.lex}")) + self.errors.append(f"({node.line}, {node.column}) - SemanticError: Undeclared identifier {node.lex}") return node.type = x.type if not isinstance(x.type , SELF_TYPE) else self.current_type diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py index eed65bb04..b5b54d216 100644 --- a/src/compiler_components/semantic/type_collector.py +++ b/src/compiler_components/semantic/type_collector.py @@ -31,11 +31,11 @@ def visit(self, node): self.errors.append(f"({dec_node.line_father},{dec_node.column_father}) - SemanticError: Basic type as parent") self.context.get_type(dec_node.id, dec_node.line).set_parent(self.context.get_type(dec_node.parent,dec_node.line),node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + e) cycles = self.context.circular_dependency() for cycle in cycles: - self.errors.append(SemanticError(f"Class {cycle[0][0]}, is involved in an inheritance cycle.",cycle[0][1])) + self.errors.append(f"({cycle[0][0].line},{cycle[0][0].column}) - SemanticError: Class {cycle[0][0]}, is involved in an inheritance cycle.") return for decl in classes: @@ -46,23 +46,21 @@ def visit(self, node): @visitor.when(ClassDeclarationNode) def visit(self, node): try: - self.current_type = self.context.create_type(node.id,node.line) + self.current_type = self.context.create_type(node.id, node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) return - #for feature in node.features: - #self.visit(feature) @visitor.when(AttrDeclarationNode) def visit(self, node): try: attr_type = SELF_TYPE() if node.type == "SELF_TYPE" else self.context.get_type(node.type,-1) #change -1 for line number if node.id == "self": - raise SemanticError('Trying to assign value to self' ,-1) #change -1 for line number - + self.errors.append(f"({node.line},{node.column}) - SemanticError: Trying to assign value to self") + raise SemanticError('', -1) #change -1 for line number self.current_type.define_attribute(node.id, attr_type, -1) #change -1 for line number except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) @visitor.when(FuncDeclarationNode) def visit(self, node): @@ -72,14 +70,14 @@ def visit(self, node): try: arg_types.append(self.context.get_type(param[1],node.line) ) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) arg_types.append(ErrorType()) try: ret_type = SELF_TYPE() if node.type =="SELF_TYPE" else self.context.get_type(node.type,node.line) except SemanticError as e: - self.errors.append(e) + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) ret_type = ErrorType() try: self.current_type.define_method(node.id, arg_names, arg_types, ret_type, node.line) except SemanticError as e: - self.errors.append(e) \ No newline at end of file + self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) \ No newline at end of file diff --git a/src/program.txt b/src/program.txt index 635a6fad7..8908366be 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,25 +1,9 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class B inherits A { - b: Bool <- true; -}; -class C inherits B { - c: String <- "C"; -}; -class D inherits B { - d: IO <- new Main.main(); -}; +-- It is an error to inherit from or redefine Bool. class Main inherits IO { - main(): IO { out_string("Hello World!") }; + main(): IO { out_string("Hello World!")}; }; + +class Bool { + xor(b: Bool): Bool { false }; +}; \ No newline at end of file From ebcac3d5b3f134818d00cdc58f043b012b874ea2 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 01:14:58 -0300 Subject: [PATCH 41/60] production added to get class type column --- src/compiler_components/ast.py | 4 +- src/compiler_components/cool_parser.py | 13 +- src/compiler_components/parsetab.py | 121 +++++++++--------- .../semantic/structures.py | 2 +- .../semantic/type_collector.py | 4 +- src/program.txt | 6 +- 6 files changed, 79 insertions(+), 71 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 8a1f55a52..2dc6756f2 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -37,7 +37,7 @@ def visit(self, tabs = 0): class ClassDeclarationNode(DeclarationNode): - def __init__(self, idx, features, parent=None, line = -1, column=-1, line_father = -1, column_father = -1): + def __init__(self, idx, features, parent=None, line = -1, column=-1, line_father = -1, column_father = -1, type_line = -1, type_column = -1): self.id = idx self.parent = parent self.features = features @@ -45,6 +45,8 @@ def __init__(self, idx, features, parent=None, line = -1, column=-1, line_father self.column = column self.line_father = line_father self.column_father = column_father + self.type_line = type_line + self.type_column = type_column def visit(self, tabs = 0): node = self diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 000c82422..8b21bc2f4 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -24,22 +24,27 @@ def p_class_list(p): p[0] = [p[1]] + p[3] def p_def_class(p): - '''def_class : CLASS TYPE_ID LBRACE feature_list RBRACE - | CLASS TYPE_ID INHERITS type_inherit LBRACE feature_list RBRACE + '''def_class : CLASS type_id LBRACE feature_list RBRACE + | CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE ''' line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 6: - p[0] = ClassDeclarationNode(p[2], p[4], line = line, column = column) + p[0] = ClassDeclarationNode(p[2]['value'], p[4], line = line, column = column, type_line = p[2]['line'], type_column = p[2]['column']) else: - p[0] = ClassDeclarationNode(p[2], p[6], p[4]['value'], line = line, column = column, line_father = p[4]['line'], column_father = p[4]['column']) + p[0] = ClassDeclarationNode(p[2]['value'], p[6], p[4]['value'], line = line, column = column, line_father = p[4]['line'], column_father = p[4]['column'], type_line = p[2]['line'], type_column = p[2]['column']) def p_type_inherit(p): 'type_inherit : TYPE_ID' line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] = {'value':p[1], 'line':line, 'column':column} +def p_type_id(p): + 'type_id : TYPE_ID' + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) + p[0] = {'value':p[1], 'line':line, 'column':column} + def p_empty(p): 'empty :' pass diff --git a/src/compiler_components/parsetab.py b/src/compiler_components/parsetab.py index bc50cb00c..0e3ed7ffd 100644 --- a/src/compiler_components/parsetab.py +++ b/src/compiler_components/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS TYPE_ID LBRACE feature_list RBRACE\n | CLASS TYPE_ID INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT TYPE_ID\n | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' +_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS type_id LBRACE feature_list RBRACE\n | CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDtype_id : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT TYPE_ID\n | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-2,-3,]),'SEMICOLON':([3,11,12,17,25,37,38,39,40,42,43,44,45,47,48,50,51,52,65,66,77,81,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,135,137,142,144,145,],[5,18,19,-4,-11,-5,-37,-12,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,108,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-13,-55,-44,-57,146,]),'TYPE_ID':([4,9,20,32,49,61,75,134,],[6,15,25,60,77,88,103,140,]),'LBRACE':([6,15,16,31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,88,95,105,106,108,109,112,115,118,131,138,143,],[8,-6,22,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,112,55,55,55,55,55,55,55,55,55,55,55,]),'INHERITS':([6,],[9,]),'ID':([8,18,19,21,22,31,35,41,46,53,54,55,56,57,58,59,63,64,67,68,69,70,71,72,73,74,95,105,106,108,109,110,111,112,115,118,119,131,138,143,146,],[14,14,14,26,14,38,26,66,38,38,38,38,84,38,66,66,38,38,66,66,66,66,66,66,66,102,66,38,38,38,38,84,126,38,38,38,130,38,38,38,126,]),'RBRACE':([8,10,13,18,19,22,23,24,30,38,40,42,43,44,45,47,48,50,51,52,65,66,77,80,86,87,90,94,96,97,98,99,100,101,104,107,108,113,117,122,123,127,132,133,137,142,144,],[-7,17,-10,-7,-7,-7,-8,-9,37,-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,107,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-19,-56,-29,-20,-47,135,-45,-50,-55,-44,-57,]),'DOUBLE_DOT':([14,26,33,84,126,],[20,32,61,20,134,]),'LPAREN':([14,31,38,41,46,53,54,55,57,58,59,63,64,66,67,68,69,70,71,72,73,95,102,105,106,108,109,112,115,118,130,131,138,143,],[21,46,64,46,46,46,46,46,46,46,46,46,46,64,46,46,46,46,46,46,46,46,118,46,46,46,46,46,46,46,138,46,46,46,]),'RPAREN':([21,27,28,29,34,36,38,40,42,43,44,45,47,48,50,51,52,60,62,64,65,66,76,77,86,87,89,90,91,92,93,94,96,97,98,99,100,101,104,107,113,114,116,117,118,123,128,129,132,133,136,137,138,141,142,144,],[-7,33,-7,-15,-14,-17,-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-18,-7,-7,-22,-37,104,-40,-53,-54,-16,-27,113,-7,-59,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-58,-61,-29,-7,-47,-7,137,-45,-50,-60,-55,-7,144,-44,-57,]),'COMMA':([25,28,38,39,40,42,43,44,45,47,48,50,51,52,60,62,65,66,77,83,86,87,90,92,94,96,97,98,99,100,101,104,107,113,117,123,128,132,133,137,142,144,],[-11,35,-37,-12,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-18,35,-22,-37,-40,110,-53,-54,-27,115,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,115,-45,-50,-55,-44,-57,]),'IN':([25,38,39,40,42,43,44,45,47,48,50,51,52,65,66,77,82,83,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,124,132,133,137,142,144,],[-11,-37,-12,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,109,-48,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-49,-45,-50,-55,-44,-57,]),'LEFT_ARROW':([25,38,],[31,63,]),'NOT':([31,41,46,53,54,55,57,63,64,67,68,69,95,105,106,108,109,112,115,118,131,138,143,],[41,41,41,41,41,41,41,41,41,95,95,95,41,41,41,41,41,41,41,41,41,41,41,]),'NUMBER':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'NEW':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'TRUE':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'FALSE':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'IF':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'WHILE':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'LET':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,]),'CASE':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'ISVOID':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'NHANHARA':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'DOT':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,103,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,74,-35,-38,-39,-41,-42,-43,-22,-37,-40,74,74,-27,-23,-24,-25,-30,-31,74,74,119,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'ARROBA':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,75,-35,-38,-39,-41,-42,-43,-22,-37,-40,75,75,-27,-23,-24,-25,-30,-31,75,75,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'TIMES':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,72,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,72,72,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'DIVIDE':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,73,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,73,73,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'MINOR':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,67,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'MINOR_EQUALS':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,68,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'EQUALS':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,69,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'PLUS':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,70,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,70,70,70,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'MINUS':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,71,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,71,71,71,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'THEN':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,78,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,105,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'LOOP':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,79,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,106,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'OF':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,85,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,111,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,-44,-57,]),'ELSE':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,120,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,131,-47,-45,-50,-55,-44,-57,]),'POOL':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,121,123,132,133,137,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,132,-47,-45,-50,-55,-44,-57,]),'FI':([38,40,42,43,44,45,47,48,50,51,52,65,66,77,86,87,90,94,96,97,98,99,100,101,104,107,113,117,123,132,133,137,139,142,144,],[-37,-21,-26,-28,-32,-35,-38,-39,-41,-42,-43,-22,-37,-40,-53,-54,-27,-23,-24,-25,-30,-31,-33,-34,-36,-46,-56,-29,-47,-45,-50,-55,142,-44,-57,]),'ESAC':([125,146,147,],[133,-51,-52,]),'RIGHT_ARROW':([140,],[143,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,8,],[0,-1,-2,-3,]),'SEMICOLON':([3,12,13,18,26,38,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,82,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,136,138,143,145,146,],[5,19,20,-4,-12,-5,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,109,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-14,-56,-45,-58,147,]),'TYPE_ID':([4,10,21,33,50,62,76,135,],[7,17,26,61,78,89,104,141,]),'LBRACE':([6,7,16,17,32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,89,96,106,107,109,110,113,116,119,132,139,144,],[9,-7,23,-6,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,113,56,56,56,56,56,56,56,56,56,56,56,]),'INHERITS':([6,7,],[10,-7,]),'ID':([9,19,20,22,23,32,36,42,47,54,55,56,57,58,59,60,64,65,68,69,70,71,72,73,74,75,96,106,107,109,110,111,112,113,116,119,120,132,139,144,147,],[15,15,15,27,15,39,27,67,39,39,39,39,85,39,67,67,39,39,67,67,67,67,67,67,67,103,67,39,39,39,39,85,127,39,39,39,131,39,39,39,127,]),'RBRACE':([9,11,14,19,20,23,24,25,31,39,41,43,44,45,46,48,49,51,52,53,66,67,78,81,87,88,91,95,97,98,99,100,101,102,105,108,109,114,118,123,124,128,133,134,138,143,145,],[-8,18,-11,-8,-8,-8,-9,-10,38,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,108,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-20,-57,-30,-21,-48,136,-46,-51,-56,-45,-58,]),'DOUBLE_DOT':([15,27,34,85,127,],[21,33,62,21,135,]),'LPAREN':([15,32,39,42,47,54,55,56,58,59,60,64,65,67,68,69,70,71,72,73,74,96,103,106,107,109,110,113,116,119,131,132,139,144,],[22,47,65,47,47,47,47,47,47,47,47,47,47,65,47,47,47,47,47,47,47,47,119,47,47,47,47,47,47,47,139,47,47,47,]),'RPAREN':([22,28,29,30,35,37,39,41,43,44,45,46,48,49,51,52,53,61,63,65,66,67,77,78,87,88,90,91,92,93,94,95,97,98,99,100,101,102,105,108,114,115,117,118,119,124,129,130,133,134,137,138,139,142,143,145,],[-8,34,-8,-16,-15,-18,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,-8,-8,-23,-38,105,-41,-54,-55,-17,-28,114,-8,-60,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-59,-62,-30,-8,-48,-8,138,-46,-51,-61,-56,-8,145,-45,-58,]),'COMMA':([26,29,39,40,41,43,44,45,46,48,49,51,52,53,61,63,66,67,78,84,87,88,91,93,95,97,98,99,100,101,102,105,108,114,118,124,129,133,134,138,143,145,],[-12,36,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,36,-23,-38,-41,111,-54,-55,-28,116,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,116,-46,-51,-56,-45,-58,]),'IN':([26,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,83,84,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,125,133,134,138,143,145,],[-12,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,110,-49,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-50,-46,-51,-56,-45,-58,]),'LEFT_ARROW':([26,39,],[32,64,]),'NOT':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,132,139,144,],[42,42,42,42,42,42,42,42,42,96,96,96,42,42,42,42,42,42,42,42,42,42,42,]),'NUMBER':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'NEW':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'TRUE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'FALSE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'IF':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'WHILE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'LET':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'CASE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'ISVOID':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'NHANHARA':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,]),'DOT':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,104,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,75,-36,-39,-40,-42,-43,-44,-23,-38,-41,75,75,-28,-24,-25,-26,-31,-32,75,75,120,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'ARROBA':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,76,-36,-39,-40,-42,-43,-44,-23,-38,-41,76,76,-28,-24,-25,-26,-31,-32,76,76,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'TIMES':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,73,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,73,73,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'DIVIDE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,74,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,74,74,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINOR':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,68,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINOR_EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,69,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,70,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'PLUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,71,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,71,71,71,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,72,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,72,72,72,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'THEN':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,79,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,106,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'LOOP':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,80,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,107,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'OF':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,86,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,112,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'ELSE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,121,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,132,-48,-46,-51,-56,-45,-58,]),'POOL':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,122,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,133,-48,-46,-51,-56,-45,-58,]),'FI':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,140,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,143,-45,-58,]),'ESAC':([126,147,148,],[134,-52,-53,]),'RIGHT_ARROW':([141,],[144,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,18,19,22,],[10,23,24,30,]),'def_attr':([8,18,19,22,56,110,],[11,11,11,11,83,83,]),'def_func':([8,18,19,22,],[12,12,12,12,]),'empty':([8,18,19,21,22,28,62,64,92,118,128,138,],[13,13,13,29,13,36,36,93,116,93,116,93,]),'type_inherit':([9,],[16,]),'param_list':([21,],[27,]),'param':([21,35,],[28,62,]),'param_list2':([28,62,],[34,89,]),'expr':([31,46,53,54,55,57,63,64,105,106,108,109,112,115,118,131,138,143,],[39,76,78,79,81,85,90,92,120,121,81,123,127,128,92,139,92,145,]),'bool':([31,41,46,53,54,55,57,63,64,95,105,106,108,109,112,115,118,131,138,143,],[40,65,40,40,40,40,40,40,40,117,40,40,40,40,40,40,40,40,40,40,]),'arith':([31,41,46,53,54,55,57,63,64,67,68,69,95,105,106,108,109,112,115,118,131,138,143,],[42,42,42,42,42,42,42,42,42,94,96,97,42,42,42,42,42,42,42,42,42,42,42,]),'term':([31,41,46,53,54,55,57,63,64,67,68,69,70,71,95,105,106,108,109,112,115,118,131,138,143,],[43,43,43,43,43,43,43,43,43,43,43,43,98,99,43,43,43,43,43,43,43,43,43,43,43,]),'factor':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[44,44,44,44,44,44,44,86,87,44,44,44,44,44,44,44,100,101,44,44,44,44,44,44,44,44,44,44,44,]),'atom':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'func_call':([31,41,46,53,54,55,57,58,59,63,64,67,68,69,70,71,72,73,95,105,106,108,109,112,115,118,131,138,143,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'expr_list':([55,108,],[80,122,]),'atr_decl_list':([56,110,],[82,124,]),'arg_list':([64,118,138,],[91,129,141,]),'arg_list2':([92,128,],[114,136,]),'case_list':([111,146,],[125,147,]),} +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,8,]),'def_class':([0,5,],[3,3,]),'type_id':([4,],[6,]),'feature_list':([9,19,20,23,],[11,24,25,31,]),'def_attr':([9,19,20,23,57,111,],[12,12,12,12,84,84,]),'def_func':([9,19,20,23,],[13,13,13,13,]),'empty':([9,19,20,22,23,29,63,65,93,119,129,139,],[14,14,14,30,14,37,37,94,117,94,117,94,]),'type_inherit':([10,],[16,]),'param_list':([22,],[28,]),'param':([22,36,],[29,63,]),'param_list2':([29,63,],[35,90,]),'expr':([32,47,54,55,56,58,64,65,106,107,109,110,113,116,119,132,139,144,],[40,77,79,80,82,86,91,93,121,122,82,124,128,129,93,140,93,146,]),'bool':([32,42,47,54,55,56,58,64,65,96,106,107,109,110,113,116,119,132,139,144,],[41,66,41,41,41,41,41,41,41,118,41,41,41,41,41,41,41,41,41,41,]),'arith':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,132,139,144,],[43,43,43,43,43,43,43,43,43,95,97,98,43,43,43,43,43,43,43,43,43,43,43,]),'term':([32,42,47,54,55,56,58,64,65,68,69,70,71,72,96,106,107,109,110,113,116,119,132,139,144,],[44,44,44,44,44,44,44,44,44,44,44,44,99,100,44,44,44,44,44,44,44,44,44,44,44,]),'factor':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[45,45,45,45,45,45,45,87,88,45,45,45,45,45,45,45,101,102,45,45,45,45,45,45,45,45,45,45,45,]),'atom':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'func_call':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'expr_list':([56,109,],[81,123,]),'atr_decl_list':([57,111,],[83,125,]),'arg_list':([65,119,139,],[92,130,142,]),'arg_list2':([93,129,],[115,137,]),'case_list':([112,147,],[126,148,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -30,62 +30,63 @@ ('program -> class_list','program',1,'p_program','cool_parser.py',14), ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','cool_parser.py',18), ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','cool_parser.py',19), - ('def_class -> CLASS TYPE_ID LBRACE feature_list RBRACE','def_class',5,'p_def_class','cool_parser.py',27), - ('def_class -> CLASS TYPE_ID INHERITS type_inherit LBRACE feature_list RBRACE','def_class',7,'p_def_class','cool_parser.py',28), + ('def_class -> CLASS type_id LBRACE feature_list RBRACE','def_class',5,'p_def_class','cool_parser.py',27), + ('def_class -> CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE','def_class',7,'p_def_class','cool_parser.py',28), ('type_inherit -> TYPE_ID','type_inherit',1,'p_type_inherit','cool_parser.py',39), - ('empty -> ','empty',0,'p_empty','cool_parser.py',46), - ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',50), - ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',51), - ('feature_list -> empty','feature_list',1,'p_feature_list','cool_parser.py',52), - ('def_attr -> ID DOUBLE_DOT TYPE_ID','def_attr',3,'p_def_attr','cool_parser.py',60), - ('def_attr -> ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',61), - ('def_func -> ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE','def_func',9,'p_def_func','cool_parser.py',70), - ('param_list -> param param_list2','param_list',2,'p_param_list','cool_parser.py',76), - ('param_list -> empty','param_list',1,'p_param_list','cool_parser.py',77), - ('param_list2 -> COMMA param param_list2','param_list2',3,'p_param_list2','cool_parser.py',85), - ('param_list2 -> empty','param_list2',1,'p_param_list2','cool_parser.py',86), - ('param -> ID DOUBLE_DOT TYPE_ID','param',3,'p_param','cool_parser.py',94), - ('expr_list -> expr SEMICOLON','expr_list',2,'p_expr_list','cool_parser.py',99), - ('expr_list -> expr SEMICOLON expr_list','expr_list',3,'p_expr_list','cool_parser.py',100), - ('expr -> bool','expr',1,'p_expr','cool_parser.py',108), - ('bool -> NOT bool','bool',2,'p_bool','cool_parser.py',112), - ('bool -> arith MINOR arith','bool',3,'p_bool','cool_parser.py',113), - ('bool -> arith MINOR_EQUALS arith','bool',3,'p_bool','cool_parser.py',114), - ('bool -> arith EQUALS arith','bool',3,'p_bool','cool_parser.py',115), - ('bool -> arith','bool',1,'p_bool','cool_parser.py',116), - ('expr -> ID LEFT_ARROW expr','expr',3,'p_expr2','cool_parser.py',133), - ('arith -> term','arith',1,'p_arith','cool_parser.py',138), - ('arith -> NOT bool','arith',2,'p_arith','cool_parser.py',139), - ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',140), - ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',141), - ('term -> factor','term',1,'p_term','cool_parser.py',155), - ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',156), - ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',157), - ('factor -> atom','factor',1,'p_factor','cool_parser.py',169), - ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',170), - ('atom -> ID','atom',1,'p_atom1','cool_parser.py',179), - ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',184), - ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',189), - ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',193), - ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',199), - ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',204), - ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',205), - ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',218), - ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',223), - ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',228), - ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',233), - ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',238), - ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',239), - ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',248), - ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',253), - ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',254), - ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',263), - ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',274), - ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',279), - ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',285), - ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',290), - ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',297), - ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',298), - ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',306), - ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',307), + ('type_id -> TYPE_ID','type_id',1,'p_type_id','cool_parser.py',44), + ('empty -> ','empty',0,'p_empty','cool_parser.py',49), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',53), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',54), + ('feature_list -> empty','feature_list',1,'p_feature_list','cool_parser.py',55), + ('def_attr -> ID DOUBLE_DOT TYPE_ID','def_attr',3,'p_def_attr','cool_parser.py',63), + ('def_attr -> ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',64), + ('def_func -> ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE','def_func',9,'p_def_func','cool_parser.py',73), + ('param_list -> param param_list2','param_list',2,'p_param_list','cool_parser.py',79), + ('param_list -> empty','param_list',1,'p_param_list','cool_parser.py',80), + ('param_list2 -> COMMA param param_list2','param_list2',3,'p_param_list2','cool_parser.py',88), + ('param_list2 -> empty','param_list2',1,'p_param_list2','cool_parser.py',89), + ('param -> ID DOUBLE_DOT TYPE_ID','param',3,'p_param','cool_parser.py',97), + ('expr_list -> expr SEMICOLON','expr_list',2,'p_expr_list','cool_parser.py',102), + ('expr_list -> expr SEMICOLON expr_list','expr_list',3,'p_expr_list','cool_parser.py',103), + ('expr -> bool','expr',1,'p_expr','cool_parser.py',111), + ('bool -> NOT bool','bool',2,'p_bool','cool_parser.py',115), + ('bool -> arith MINOR arith','bool',3,'p_bool','cool_parser.py',116), + ('bool -> arith MINOR_EQUALS arith','bool',3,'p_bool','cool_parser.py',117), + ('bool -> arith EQUALS arith','bool',3,'p_bool','cool_parser.py',118), + ('bool -> arith','bool',1,'p_bool','cool_parser.py',119), + ('expr -> ID LEFT_ARROW expr','expr',3,'p_expr2','cool_parser.py',136), + ('arith -> term','arith',1,'p_arith','cool_parser.py',141), + ('arith -> NOT bool','arith',2,'p_arith','cool_parser.py',142), + ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',143), + ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',144), + ('term -> factor','term',1,'p_term','cool_parser.py',158), + ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',159), + ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',160), + ('factor -> atom','factor',1,'p_factor','cool_parser.py',172), + ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',173), + ('atom -> ID','atom',1,'p_atom1','cool_parser.py',182), + ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',187), + ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',192), + ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',196), + ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',202), + ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',207), + ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',208), + ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',221), + ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',226), + ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',231), + ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',236), + ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',241), + ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',242), + ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',251), + ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',256), + ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',257), + ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',266), + ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',277), + ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',282), + ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',288), + ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',293), + ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',300), + ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',301), + ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',309), + ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',310), ] diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index d6baa743c..e58725a6c 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -207,7 +207,7 @@ def check_type(self,x:Type,y:Type,pos): def create_type(self, name:str,pos=0): if name in self.types: - raise SemanticError(f'Type with the same name ({name}) already in context.' , pos) + raise SemanticError(f'Type with the same name ({name}) already in context.') t = self.types[name] = Type(name,pos) return t diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py index b5b54d216..899c80cd7 100644 --- a/src/compiler_components/semantic/type_collector.py +++ b/src/compiler_components/semantic/type_collector.py @@ -46,9 +46,9 @@ def visit(self, node): @visitor.when(ClassDeclarationNode) def visit(self, node): try: - self.current_type = self.context.create_type(node.id, node.line) + self.current_type = self.context.create_type(node.id, node.type_line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.type_line},{node.type_column}) - SemanticError: " + str(e)) return @visitor.when(AttrDeclarationNode) diff --git a/src/program.txt b/src/program.txt index 8908366be..07e33bcc7 100644 --- a/src/program.txt +++ b/src/program.txt @@ -2,8 +2,8 @@ class Main inherits IO { main(): IO { out_string("Hello World!")}; -}; - +}; + class Bool { xor(b: Bool): Bool { false }; -}; \ No newline at end of file +}; From 0a19ee0bd1330bc7ff34cccf32b69f44aefa170f Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Fri, 25 Feb 2022 09:55:55 -0500 Subject: [PATCH 42/60] Fix some semantic errors --- src/compiler_components/ast.py | 4 +- src/compiler_components/code_gen.py | 6 ++- .../code_generator/converter.py | 2 +- .../code_generator/converter_utils.py | 26 ++++++---- src/compiler_components/cool_cil_converter.py | 10 ++-- .../semantic/structures.py | 17 +++---- .../semantic/type_checker.py | 47 +++++++++---------- .../semantic/type_collector.py | 10 ++-- src/compiler_components/semantic_checker.py | 13 +++-- src/program.txt | 39 ++++++++++++--- 10 files changed, 106 insertions(+), 68 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 2dc6756f2..a07e9b1b5 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -221,14 +221,14 @@ def visit(self, tabs = 0): class BlockNode(AtomicNode): - def __init__(self, expr_list, line = -1, column=-1): + def __init__(self, expr_list, line=-1, column=-1): self.expr_list = expr_list self.line = line self.column = column def visit(self, tabs = 0): ans = '\t'*tabs + " {; .... ;}\n" - exprs = '\n'.join(param.visit( tabs + 1) for param in self.expr_list) + exprs = '\n'.join(param.visit(tabs + 1) for param in self.expr_list) return ans+exprs diff --git a/src/compiler_components/code_gen.py b/src/compiler_components/code_gen.py index 5cade8caf..3fc1a88ca 100644 --- a/src/compiler_components/code_gen.py +++ b/src/compiler_components/code_gen.py @@ -9,14 +9,16 @@ class CodeGenerator(CompilerComponent): def __init__(self, semantic_checker: SemanticChecker) -> None: super().__init__() self.semantic_checker = semantic_checker - # TODO: connect to semantic checker self.context = None self.scope = None self.ast = None - self.mips_text = None def execute(self): + self.context = self.semantic_checker.context + self.scope = self.semantic_checker.scope + self.ast = self.semantic_checker.ast + cool_cil_converter = CoolToCilConverter(self.context) cil_tree = cool_cil_converter.visit(self.ast, self.scope) diff --git a/src/compiler_components/code_generator/converter.py b/src/compiler_components/code_generator/converter.py index 7758b2785..38930df69 100644 --- a/src/compiler_components/code_generator/converter.py +++ b/src/compiler_components/code_generator/converter.py @@ -4,7 +4,7 @@ class Converter: def __init__(self, context): self.dottypes = [] - self.dotdata = [cil.DataNode('_empty', '')] + self.dotdata = [CilDataNode('_empty', '')] self.dotcode = [] self.current_type = None self.current_method = None diff --git a/src/compiler_components/code_generator/converter_utils.py b/src/compiler_components/code_generator/converter_utils.py index de18c50e0..da634a47e 100644 --- a/src/compiler_components/code_generator/converter_utils.py +++ b/src/compiler_components/code_generator/converter_utils.py @@ -41,11 +41,11 @@ def get_method(converter, type_name, method_name): def box(converter, typeName, value): obj_internal = define_internal_local(converter) - converter.register_instruction(AllocateNode(typeName, obj_internal)) - converter.register_instruction(SetAttribNode(obj_internal, 0, value)) - converter.register_instruction(LoadNode(obj_internal, f'{typeName}_name')) - converter.register_instruction(LoadIntNode(obj_internal, f'{typeName}_size', 4)) - converter.register_instruction(LoadNode(obj_internal, f'__virtual_table__{typeName}', 8)) + register_instruction(converter, CilAllocateNode(typeName, obj_internal)) + register_instruction(converter, CilSetAttribNode(obj_internal, 0, value)) + register_instruction(converter, CilLoadNode(obj_internal, f'{typeName}_name')) + register_instruction(converter, CilLoadIntNode(obj_internal, f'{typeName}_size', 4)) + register_instruction(converter, CilLoadNode(obj_internal, f'__virtual_table__{typeName}', 8)) return obj_internal @@ -59,14 +59,14 @@ def to_attribute_name(attr_name): def register_param(converter, var_info): var_info.cilName = var_info.name - param_node = cil.ParamNode(var_info.cilName) + param_node = CilParamNode(var_info.cilName) converter.params.append(param_node) return var_info.cilName def register_local(converter, var_info): var_info.cilName = f'local_{converter.current_function.name[9:]}_{var_info.name}_{len(converter.localvars)}' - local_node = cil.LocalNode(var_info.cilName) + local_node = CilLocalNode(var_info.cilName) converter.localvars.append(local_node) return var_info.cilName @@ -83,13 +83,13 @@ def register_instruction(converter, instruction): def register_function(converter, function_name): - function_node = FunctionNode(function_name, [], [], [], []) + function_node = CilFunctionNode(function_name, [], [], [], []) converter.dotcode.append(function_node) return function_node def register_type(converter, name): - type_node = TypeNode(name) + type_node = CilTypeNode(name) converter.dottypes.append(type_node) return type_node @@ -100,7 +100,7 @@ def register_data(converter, value): return dataNode vname = f'data_{len(converter.dotdata)}' - data_node = DataNode(vname, value) + data_node = CilDataNode(vname, value) converter.dotdata.append(data_node) return data_node @@ -134,3 +134,9 @@ def basic_types(converter): cil_type = register_type(converter, basicType) for method, typeMethod in converter.context.get_type(basicType).all_methods(): cil_type.methods.append((method.name, to_function_name(method.name, typeMethod.name))) + + +class VariableInfo: + def __init__(self, name, typex): + self.name = name + self.type = typex diff --git a/src/compiler_components/cool_cil_converter.py b/src/compiler_components/cool_cil_converter.py index 2f4cc5e69..927538ff8 100644 --- a/src/compiler_components/cool_cil_converter.py +++ b/src/compiler_components/cool_cil_converter.py @@ -97,11 +97,11 @@ def visit(self, node, scope): @visitor.when(AttrDeclarationNode) def visit(self, node, scope): - if not node.expression is None: - value = self.visit(node.expression, scope.children[0]) + if not node.expr is None: + value = self.visit(node.expr, scope.children[0]) - if node.type == 'Object' and node.expression.type.name in ['Int', 'Bool', 'String']: - value = box(self, node.expression.type.name, value) + if node.type == 'Object' and node.expr.type.name in ['Int', 'Bool', 'String']: + value = box(self, node.expr.type.name, value) else: if node.type == 'String': @@ -316,7 +316,7 @@ def visit(self, node, scope): @visitor.when(ConstantStringNode) def visit(self, node, scope): - msg = register_data(self, node.token).name + msg = register_data(self, node.lex).name internal = define_internal_local(self) register_instruction(self, CilLoadAddressNode(internal, msg)) return internal diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index e58725a6c..823475c0d 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -5,7 +5,7 @@ class SemanticError(Exception): @property def text(self): - return str(self.args[1][0]) + return str(self.args[0]) class TypeError(SemanticError): pass class NameError(SemanticError): @@ -46,13 +46,14 @@ def __eq__(self, other): ############# Type ####################################### class Type: - def __init__(self, name:str,line=-1): + def __init__(self, name:str,line=-1, column=-1): self.name = name self.attributes = [] self.methods = [] self.parent = None self.sons = [] self.line = line + self.column = column def set_parent(self, parent, pos=0): if self.parent is not None: @@ -97,8 +98,8 @@ def define_method(self, name:str, param_names:list, param_types:list, return_ty method = self.get_method(name, pos) if method.return_type != return_type or method.param_types != param_types: raise SemanticError(f'Method "{name}" already defined in {self.name} with a different signature.', pos) - else: - raise SemanticError(f'Method "{name}" already defined in {self.name} ', pos) + #else: + # raise SemanticError(f'Method "{name}" already defined in {self.name} ', pos) except AttributeError as e: method = Method(name, param_names, param_types, return_type) @@ -205,10 +206,10 @@ def check_type(self,x:Type,y:Type,pos): if not x.conforms_to(y) : raise(TypeError(f"Expr type {x.name} is no subclass of {y.name} ",pos)) - def create_type(self, name:str,pos=0): + def create_type(self, name:str,line=0, column=0): if name in self.types: raise SemanticError(f'Type with the same name ({name}) already in context.') - t = self.types[name] = Type(name,pos) + t = self.types[name] = Type(name, line, column) return t def get_type(self, name:str,pos=0): @@ -253,10 +254,10 @@ def circular_dependency(self): break if temp.parent.name in ancestors: on_cycle[count] = [] - on_cycle[count].append((temp.name,temp.line)) + on_cycle[count].append((temp.name,temp.line, temp.column)) temp2 = temp.parent while temp != temp2: - on_cycle[count].append((temp2.name,temp2.line)) + on_cycle[count].append((temp2.name,temp2.line, temp2.column)) temp2 = temp2.parent on_cycle[count].sort(key= lambda x:x[1],reverse=True) count = count + 1 diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index a415c509a..216a5d831 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -29,7 +29,7 @@ def visit(self, node:ClassDeclarationNode, scope:Scope): typex = self.context.get_type(node.id, node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) self.current_type = typex #for at in typex.all_attributes(): @@ -54,7 +54,7 @@ def visit(self, node:AttrDeclarationNode,scope:Scope): typex =self.current_type if node.type == "SELF_TYPE" else self.context.get_type(node.type,node.line) self.context.check_type(node.expr.type,typex,node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) @visitor.when(FuncDeclarationNode) def visit(self, node:FuncDeclarationNode,scope:Scope): @@ -75,7 +75,7 @@ def visit(self, node:FuncDeclarationNode,scope:Scope): typex = method.return_type if not isinstance(method.return_type,SELF_TYPE) else self.current_type self.context.check_type(node.body.type,typex,node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column-4}) - TypeError: " + str(e)) @visitor.when(CaseNode) @@ -94,7 +94,7 @@ def visit(self, node:CaseNode, scope:Scope): try : typex = self.context.get_type(branches.type,branches.expr.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) tmpscope.define_variable(branches.id,typex,node.line) self.visit(branches.expr,tmpscope) if common_type is None: @@ -122,7 +122,7 @@ def visit(self, node:DispatchNode, scope:Scope): temp = self.context.get_type(node.typex,node.line) self.context.check_type(node.expr.type,temp,node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) return else: if isinstance( node.expr.type , ErrorType): @@ -131,7 +131,7 @@ def visit(self, node:DispatchNode, scope:Scope): try: typex = self.context.get_type(node.typex,node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) return try : if isinstance( typex , ErrorType): @@ -169,9 +169,9 @@ def visit(self, node:CallNode, scope:Scope): try: self.context.check_type(node.args[i].type,method.param_types[i],node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - Type: " + str(e)) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - AttributeError: " + str(e)) @@ -182,12 +182,11 @@ def visit(self,node:IfNode,scope:Scope): try: self.context.check_type(node.if_c.type,self.context.get_type("Bool"),node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.if_c.line},{node.if_c.column}) - TypeError: " + str(e)) self.visit(node.then_c,scope.create_child()) self.visit(node.else_c, scope.create_child()) - try: node.type = self.context.closest_common_antecesor(node.then_c.type, node.else_c.type) except SemanticError as e: @@ -224,9 +223,9 @@ def visit(self, node:AssignNode,scope:Scope): def visit(self , node:WhileNode, scope:Scope): self.visit(node.condition, scope.create_child()) if self.context.get_type("Bool",node.line) != node.condition.type: - self.errors.append(TypeError("Expr should be boolean", node.line)) + self.errors.append(f"({node.line},{node.column}) - TypeError: Expr should be boolean") self.visit(node.body, scope.create_child()) - node.type = self.context.get_type("Object",node.line) + node.type = self.context.get_type("Object", node.line) @visitor.when(BlockNode) @@ -251,7 +250,7 @@ def visit(self, node:LetNode,scope:Scope): typey = self.context.get_type(init.type,node.line) if init.expr.type != "SELF_TYPE" else self.current_type self.context.check_type(typex,typey,node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) sc = sc.create_child() @@ -259,7 +258,7 @@ def visit(self, node:LetNode,scope:Scope): try: typex = self.context.get_type(init.type,node.line) if init.type != "SELF_TYPE" else self.current_type except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) typex = ErrorType() try: if init.id == "self": @@ -282,7 +281,7 @@ def visit(self, node:InstantiateNode,scope:Scope): else: node.type = self.context.get_type(node.lex,node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) node.type = ErrorType() @@ -308,20 +307,20 @@ def visit(self, node:ArithmeticNode,scope:Scope): def visit(self, node:MinorNode,scope:Scope): self.visit(node.left,scope.create_child()) if node.left.type != self.context.get_type("Int", node.line): - self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Int not " + str(node.left.type)) + self.errors.append(f"({node.line},{node.column}) - TypeError: Expr must be Int not " + str(node.left.type)) self.visit(node.right,scope.create_child()) if node.right.type != self.context.get_type("Int", node.line): - self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Int not " + str(node.right.type)) + self.errors.append(f"({node.line},{node.column}) - TypeError: Expr must be Int not " + str(node.right.type)) node.type = self.context.get_type("Bool", node.line) @visitor.when(MinorEqualsNode) def visit(self, node:MinorEqualsNode, scope:Scope): self.visit(node.left,scope.create_child()) if node.left.type != self.context.get_type("Int", node.line): - self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Int not " + str(node.left.type)) + self.errors.append(f"({node.line},{node.column}) - TypeError: Expr must be Int not " + str(node.left.type)) self.visit(node.right,scope.create_child()) if node.right.type != self.context.get_type("Int", node.line): - self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Int not " + str(node.right.type)) + self.errors.append(f"({node.line},{node.column}) - TypeError: Expr must be Int not " + str(node.right.type)) node.type = self.context.get_type("Bool", node.line) @visitor.when(EqualsNode) @@ -331,21 +330,21 @@ def visit(self, node:EqualsNode, scope:Scope): if node.left.type != node.right.type: basic = ['Int', 'String', 'Bool'] if node.left.type.name in basic or node.right.type.name in basic: - self.errors.append(f"({node.line},{node.column}) - SemanticError: Ilegal comparison with a basic type") + self.errors.append(f"({node.line},{node.column}) - TypeError: Ilegal comparison with a basic type") node.type = self.context.get_type("Bool", node.line) @visitor.when(NhanharaNode) def visit(self, node:NhanharaNode, scope:Scope): self.visit(node.expr, scope.create_child()) if node.expr.type != self.context.get_type("Int", node.line): - self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be an int not " + str(node.expr.type)) + self.errors.append(f"({node.line},{node.column}) - TypeError: Expr must be an int not " + str(node.expr.type)) node.type = self.context.get_type("Int", node.line) @visitor.when(NotNode) def visit(self, node:NotNode, scope:Scope): self.visit(node.expr, scope.create_child()) if node.expr.type != self.context.get_type("Bool", node.line): - self.errors.append(f"({node.line},{node.column}) - SemanticError: Expr must be Bool not " + str(node.expr.type)) + self.errors.append(f"({node.line},{node.column}) - TypeError: Expr must be Bool not " + str(node.expr.type)) node.type = self.context.get_type("Bool", node.line) @@ -367,11 +366,11 @@ def visit (self, node:VariableNode,scope:Scope): x = scope.find_variable(node.lex) if x is None: try: - at = [ at[0] for at in self.current_type.all_attributes() if at[0].name == node.lex] + at = [at[0] for at in self.current_type.all_attributes() if at[0].name == node.lex] x = at[0] except: node.type = ErrorType() - self.errors.append(f"({node.line}, {node.column}) - SemanticError: Undeclared identifier {node.lex}") + self.errors.append(f"({node.line}, {node.column}) - NameError: Undeclared identifier {node.lex}") return node.type = x.type if not isinstance(x.type , SELF_TYPE) else self.current_type diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py index 899c80cd7..6ce53881c 100644 --- a/src/compiler_components/semantic/type_collector.py +++ b/src/compiler_components/semantic/type_collector.py @@ -31,11 +31,11 @@ def visit(self, node): self.errors.append(f"({dec_node.line_father},{dec_node.column_father}) - SemanticError: Basic type as parent") self.context.get_type(dec_node.id, dec_node.line).set_parent(self.context.get_type(dec_node.parent,dec_node.line),node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + e) + self.errors.append(f"({dec_node.line},{dec_node.column}) - TypeError: " + str(e)) cycles = self.context.circular_dependency() for cycle in cycles: - self.errors.append(f"({cycle[0][0].line},{cycle[0][0].column}) - SemanticError: Class {cycle[0][0]}, is involved in an inheritance cycle.") + self.errors.append(f"({cycle[0][1]},{cycle[0][2]+1}) - SemanticError: Class {cycle[0][0]}, is involved in an inheritance cycle.") return for decl in classes: @@ -46,7 +46,7 @@ def visit(self, node): @visitor.when(ClassDeclarationNode) def visit(self, node): try: - self.current_type = self.context.create_type(node.id, node.type_line) + self.current_type = self.context.create_type(node.id, node.type_line, node.type_column) except SemanticError as e: self.errors.append(f"({node.type_line},{node.type_column}) - SemanticError: " + str(e)) return @@ -70,12 +70,12 @@ def visit(self, node): try: arg_types.append(self.context.get_type(param[1],node.line) ) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) arg_types.append(ErrorType()) try: ret_type = SELF_TYPE() if node.type =="SELF_TYPE" else self.context.get_type(node.type,node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) ret_type = ErrorType() try: self.current_type.define_method(node.id, arg_names, arg_types, ret_type, node.line) diff --git a/src/compiler_components/semantic_checker.py b/src/compiler_components/semantic_checker.py index ffca3f33f..08868a55d 100644 --- a/src/compiler_components/semantic_checker.py +++ b/src/compiler_components/semantic_checker.py @@ -12,6 +12,9 @@ class SemanticChecker(CompilerComponent): def __init__(self, parser: Parser) -> None: super().__init__() self.parser = parser + self.context = None + self.scope = None + self.ast = None def execute(self): self.errors = [] @@ -20,18 +23,18 @@ def execute(self): tcollector.visit(self.ast) if(self.has_errors()): return - context = tcollector.context + self.context = tcollector.context - tbuilder = TypeBuilder(context,self.errors) + tbuilder = TypeBuilder(self.context, self.errors) tbuilder.visit(self.ast) if self.has_errors(): return - tchecking = TypeChecker(context,self.errors) - scope = Scope() + tchecking = TypeChecker(self.context,self.errors) + self.scope = Scope() - tchecking.visit(self.ast, scope) + tchecking.visit(self.ast, self.scope) def has_errors(self): return len(self.errors) > 0 diff --git a/src/program.txt b/src/program.txt index 07e33bcc7..46067db31 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,9 +1,36 @@ --- It is an error to inherit from or redefine Bool. +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +If f has return type B and B is a class name, then the static type of the dispatch is B. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; class Main inherits IO { main(): IO { out_string("Hello World!")}; -}; - -class Bool { - xor(b: Bool): Bool { false }; -}; + + test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); +}; \ No newline at end of file From ef6051685c363e50ac61b3ab405d8ab810596b72 Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Fri, 25 Feb 2022 14:03:47 -0500 Subject: [PATCH 43/60] Remove code generator bugs --- .../code_generator/mips_formatter.py | 1 + src/compiler_components/cool_cil_converter.py | 96 +- src/main.py | 5 - src/program.mips | 1507 +++++++++++++++++ src/program.txt | 87 +- 5 files changed, 1619 insertions(+), 77 deletions(-) create mode 100644 src/program.mips diff --git a/src/compiler_components/code_generator/mips_formatter.py b/src/compiler_components/code_generator/mips_formatter.py index 036844bf9..3e186d58e 100644 --- a/src/compiler_components/code_generator/mips_formatter.py +++ b/src/compiler_components/code_generator/mips_formatter.py @@ -1,4 +1,5 @@ from .mips_nodes import * +from . import visitor def get_formatter(): diff --git a/src/compiler_components/cool_cil_converter.py b/src/compiler_components/cool_cil_converter.py index 927538ff8..5fea70824 100644 --- a/src/compiler_components/cool_cil_converter.py +++ b/src/compiler_components/cool_cil_converter.py @@ -97,11 +97,11 @@ def visit(self, node, scope): @visitor.when(AttrDeclarationNode) def visit(self, node, scope): - if not node.expr is None: - value = self.visit(node.expr, scope.children[0]) + if not node.expr is None and len(scope.children) > 0: + value = self.visit(node.expr, scope.children[0]) - if node.type == 'Object' and node.expr.type.name in ['Int', 'Bool', 'String']: - value = box(self, node.expr.type.name, value) + if node.type == 'Object' and node.expr.type.name in ['Int', 'Bool', 'String']: + value = box(self, node.expr.type.name, value) else: if node.type == 'String': @@ -122,19 +122,18 @@ def visit(self, node, scope): def visit(self, node, scope): scope_open = scope.children[0] - for init in node.let_body: - if not init[2] is None: - value = self.visit(init[2], scope_open) - - if init[2].type.name in ['Int', 'Bool', 'String'] and init[1] == 'Object': - value = box(self, init[2].type.name, value) + for init in node.list_decl: + if not init.expr is None: + value = self.visit(init.expr, scope_open) + if init.expr.type.name in ['Int', 'Bool', 'String'] and init.type == 'Object': + value = box(self, init.expr.type.name, value) else: - if init[1] == 'String': + if init.type == 'String': internal = define_internal_local(self) register_instruction(self, CilLoadAddressNode(internal, "_empty")) value = internal - elif init[1] == 'Bool' or init[1] == 'Int': + elif init.type == 'Bool' or init.type == 'Int': value = 0 else: internal = define_internal_local(self) @@ -142,21 +141,24 @@ def visit(self, node, scope): value = internal scope_open = scope_open.children[-1] - var_info = scope_open.find_variable(init[0]) + var_info = scope_open.find_variable(init.id) vname = register_local(self, var_info) register_instruction(self, CilAssignNode(vname, value)) - return self.visit(node.in_body, scope_open.children[0]) + return self.visit(node.expr, scope_open.children[0]) @visitor.when(CaseNode) def visit(self, node, scope): result = define_internal_local(self) + if len(scope.children) == 0: + return result + internal_expression = define_internal_local(self) - value_expression = self.visit(node.expression, scope.children[0]) + value_expression = self.visit(node.expr, scope.children[0]) register_instruction(self, CilAssignNode(internal_expression, value_expression)) - types_ordered = sort_types([self.context.get_type(x[1]) for x in node.branches]) + types_ordered = sort_types([self.context.get_type(x.type) for x in node.list_case]) list_label = [] labels = dict() @@ -172,13 +174,13 @@ def visit(self, node, scope): register_instruction(self, CilCaseOption(value_expression, typex[1], typex[0])) label_end = register_label(self) - for branch, scopeBranch in zip(node.branches, scope.children[1].children): - var_info = scopeBranch.find_variable(branch[0]) + for branch, scopeBranch in zip(node.list_case, scope.children[1].children): + var_info = scopeBranch.find_variable(branch.id) xxx = register_local(self, var_info) - register_instruction(self, CilLabelNode(labels[branch[1]])) + register_instruction(self, CilLabelNode(labels[branch.type])) register_instruction(self, CilAssignNode(xxx, value_expression)) - value_branch = self.visit(branch[2], scopeBranch) + value_branch = self.visit(branch.expr, scopeBranch) register_instruction(self, CilAssignNode(result, value_branch)) register_instruction(self, CilGotoNode(label_end)) @@ -187,25 +189,25 @@ def visit(self, node, scope): @visitor.when(BlockNode) def visit(self, node, scope): - for expression, child in zip(node.expressions, scope.children): + for expression, child in zip(node.expr_list, scope.children): value = self.visit(expression, child) return value @visitor.when(IfNode) def visit(self, node, scope): - cond = self.visit(node.condition, scope.children[0]) + cond = self.visit(node.if_c, scope.children[0]) label_true = register_label(self) label_false = register_label(self) result = define_internal_local(self) register_instruction(self, CilGotoIfNode(label_true, cond)) - vfalse = self.visit(node.else_body, scope.children[2]) + vfalse = self.visit(node.else_c, scope.children[2]) register_instruction(self, CilAssignNode(result, vfalse)) register_instruction(self, CilGotoNode(label_false)) register_instruction(self, CilLabelNode(label_true)) - vtrue = self.visit(node.if_body, scope.children[1]) + vtrue = self.visit(node.then_c, scope.children[1]) register_instruction(self, CilAssignNode(result, vtrue)) register_instruction(self, CilLabelNode(label_false)) @@ -235,7 +237,7 @@ def visit(self, node, scope): @visitor.when(AssignNode) def visit(self, node, scope): vinfo = scope.find_variable(node.id) - value = self.visit(node.expression, scope.children[0]) + value = self.visit(node.expr, scope.children[0]) if vinfo is None: attrib = get_attr(self, self.current_type.name, node.id) @@ -248,19 +250,22 @@ def visit(self, node, scope): @visitor.when(DispatchNode) def visit(self, node, scope): result = define_internal_local(self) - obj = self.visit(node.obj, scope.children[0]) + if len(scope.children) == 0: + return result - if node.obj.type.name in ['Int', 'Bool', 'String']: + obj = self.visit(node.expr, scope.children[0]) + + if node.expr.type.name in ['Int', 'Bool', 'String']: if node.id in ['abort', 'type_name', 'copy']: - obj = self.box(node.obj.type.name, obj) + obj = box(self, node.expr.type.name, obj) valuesArgs = [] - for arg, child in zip(node.args, scope.children[1:]): + for arg, child in zip(node.params, scope.children[1:]): value = self.visit(arg, child) if arg.type.name in ['Int', 'Bool', 'String']: method = self.context.get_type(node.typex).get_method(node.id) - param_type = method.param_types[node.args.index(arg)] + param_type = method.param_types[node.params.index(arg)] if param_type.name == 'Object': valuesArgs.append(self.box(arg.type.name, value)) @@ -269,14 +274,14 @@ def visit(self, node, scope): valuesArgs.append(value) if node.typexa is None: - node.typex = node.obj.type.name + node.typex = node.expr.type.name register_instruction(self, CilArgsNode(list(reversed(valuesArgs)) + [obj])) - if node.obj.type.name == 'String' and node.id in ['length', 'concat', 'substr']: - register_instruction(self, CilJumpNode(self.to_function_name(node.id, 'String'), result)) + if node.expr.type.name == 'String' and node.id in ['length', 'concat', 'substr']: + register_instruction(self, CilJumpNode(to_function_name(node.id, 'String'), result)) else: - real_method = self.get_method(node.typex, node.id) + real_method = get_method(self, node.typex, node.id) register_instruction(self, CilDynamicCallNode(node.typexa, real_method, result, obj)) return result @@ -306,11 +311,11 @@ def visit(self, node, scope): @visitor.when(ConstantNumNode) def visit(self, node, scope): - return int(node.token) + return int(node.lex) @visitor.when(ConstantBooleanNode) def visit(self, node, scope): - if node.token: + if node.lex: return 1 return 0 @@ -323,19 +328,19 @@ def visit(self, node, scope): @visitor.when(VariableNode) def visit(self, node: VariableNode, scope): - if node.token == 'self': + if node.lex == 'self': return 'self' - vinfo = scope.find_variable(node.token) + vinfo = scope.find_variable(node.lex) if vinfo is None: result = define_internal_local(self) - attrib = get_attr(self, self.current_type.name, node.token) + attrib = get_attr(self, self.current_type.name, node.lex) register_instruction(self, CilGetAttribNode('self', attrib, result)) return result - return vinfo.cilName + return vinfo.name @visitor.when(InstantiateNode) def visit(self, node, scope): @@ -344,7 +349,7 @@ def visit(self, node, scope): result = define_internal_local(self) register_instruction(self, CilAllocateNode(node.type.name, instance)) register_instruction(self, CilArgsNode([instance])) - register_instruction(self, CilJumpNode(self.to_function_name('Ctr', node.type.name), result)) + register_instruction(self, CilJumpNode(to_function_name('Ctr', node.type.name), result)) return instance else: return 0 @@ -352,6 +357,9 @@ def visit(self, node, scope): @visitor.when(PlusNode) def visit(self, node, scope): result = define_internal_local(self) + if len(scope.children) < 2: + return result + left = self.visit(node.left, scope.children[0]) right = self.visit(node.right, scope.children[1]) register_instruction(self, CilPlusNode(result, left, right)) @@ -432,7 +440,7 @@ def visit(self, node, scope): @visitor.when(NotNode) def visit(self, node, scope): result = define_internal_local(self) - value = self.visit(node.expression, scope.children[0]) + value = self.visit(node.expr, scope.children[0]) label_true = register_label(self) label_end = register_label(self) @@ -449,7 +457,7 @@ def visit(self, node, scope): @visitor.when(NhanharaNode) def visit(self, node, scope): result = define_internal_local(self) - expression = self.visit(node.expression, scope.children[0]) + expression = self.visit(node.expr, scope.children[0]) register_instruction(self, CilComplementNode(expression, result)) return result @@ -457,7 +465,7 @@ def visit(self, node, scope): @visitor.when(IsVoidNode) def visit(self, node, scope): result = define_internal_local(self) - expression = self.visit(node.expression, scope.children[0]) + expression = self.visit(node.expr, scope.children[0]) label_end = register_label(self) diff --git a/src/main.py b/src/main.py index dd584547b..9fb33aa5a 100644 --- a/src/main.py +++ b/src/main.py @@ -22,15 +22,10 @@ def execute_compiler(cool_program : str, input_file): if component.has_errors(): component.print_errors() - # with errors - #print('with errors') return True - # TODO: write generated code to output file open(input_file.split(".")[0] + ".mips", 'w').write(code_generator.mips_text) - # without errors - #print('false') return False diff --git a/src/program.mips b/src/program.mips new file mode 100644 index 000000000..26c26daa5 --- /dev/null +++ b/src/program.mips @@ -0,0 +1,1507 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Foo_name: .asciiz "Foo" + Foo_size: .word 32 +__virtual_table__Foo: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_printh_at_Bazz + .word function_doh_at_Foo + Bar_name: .asciiz "Bar" + Bar_size: .word 48 +__virtual_table__Bar: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_printh_at_Bazz + .word function_doh_at_Foo + Razz_name: .asciiz "Razz" + Razz_size: .word 40 +__virtual_table__Razz: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_printh_at_Bazz + .word function_doh_at_Foo + Bazz_name: .asciiz "Bazz" + Bazz_size: .word 24 +__virtual_table__Bazz: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_printh_at_Bazz + .word function_doh_at_Bazz + Main_name: .asciiz "Main" + Main_size: .word 28 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_main_at_Main + _empty: .asciiz "" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_doh_at_Foo: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + lw $t1, -4($fp) + sw $t1, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $a0, 2 + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + li $a0, i + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Foo: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Foo_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Foo_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Foo + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Foo + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Foo: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -28 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Bazz + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 24($a0) + + #end set attribute + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -24($fp) + lw $t1, -20($fp) + lw $a0, -24($fp) + add $a0, $a0, $t1 + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -16($fp) + lw $a0, -28($fp) + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 28($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Bar: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Bar_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Bar_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Bar + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Bar + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Bar: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Razz + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 40($a0) + + #end set attribute + + la $t1, _void + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 44($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Razz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Razz_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Razz_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Razz + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Razz + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Razz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -36 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Foo + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 32($a0) + + #end set attribute + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, e + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + lw $a0, -28($fp) + add $a0, $a0, $t1 + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -32($fp) + lw $t1, -20($fp) + lw $a0, -32($fp) + add $a0, $a0, $t1 + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -16($fp) + lw $a0, -36($fp) + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 36($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 48 + lw $fp, 0($sp) + jr $ra +function_printh_at_Bazz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_doh_at_Bazz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + lw $t1, -4($fp) + sw $t1, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + li $a0, i + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Bazz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Bazz_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Bazz_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Bazz + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Bazz + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Bazz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 16($a0) + + #end set attribute + + la $t1, _void + sw $t1, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 20($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + la $t1, _empty + sw $t1, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _void + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 12($a0) + + #end set attribute + + la $t1, _void + sw $t1, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 16($a0) + + #end set attribute + + la $t1, _void + sw $t1, -16($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -16($fp) + sw $t1, 20($a0) + + #end set attribute + + la $t1, _void + sw $t1, -20($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -20($fp) + sw $t1, 24($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/src/program.txt b/src/program.txt index 46067db31..ec38a7766 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,36 +1,67 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -If f has return type B and B is a class name, then the static type of the dispatch is B. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; +(* hairy . . .*) + +class Foo inherits Bazz { + a : Razz <- case self of + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + b : Int <- a.doh() + g.doh() + doh() + printh(); + + doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; + }; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; + +class Bar inherits Razz { + + c : Int <- doh(); + + d : Object <- printh(); }; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; + + +class Razz inherits Foo { + + e : Bar <- case self of + n : Razz => (new Bar); + n : Bar => n; + esac; + + f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); + }; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - back(s: String): B { { - out_string(s); - self; - } }; +class Bazz inherits IO { - alphabet(a: A, b: B, c: C): D { self }; + h : Int <- 1; + + g : Foo <- case self of + n : Bazz => (new Foo); + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + i : Object <- printh(); + + printh() : Int { { out_int(h); 0; } }; + + doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; }; -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* scary . . . *) +class Main { + a : Bazz <- new Bazz; + b : Foo <- new Foo; + c : Razz <- new Razz; + d : Bar <- new Bar; + + main(): String { "do nothing" }; + +}; + + + + - test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); -}; \ No newline at end of file From 637f0ff05f37a9981ae80a9a47b235f0819e81ae Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 17:28:17 -0300 Subject: [PATCH 44/60] isvoid1 passed --- src/compiler_components/ast.py | 4 +- src/compiler_components/cool_parser.py | 8 +- src/compiler_components/parsetab.py | 10 +- .../semantic/type_checker.py | 3 +- src/program.txt | 93 ++++++------------- 5 files changed, 40 insertions(+), 78 deletions(-) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index a07e9b1b5..8e321dc66 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -75,12 +75,14 @@ def visit(self, tabs = 0): class AttrDeclarationNode(DeclarationNode): - def __init__(self, idx, typex, expr = None, line = -1, column=-1): + def __init__(self, idx, typex, expr = None, line = -1, column=-1, type_line = -1, type_column = -1): self.id = idx self.type = typex self.expr = expr self.line = line self.column = column + self.type_line = type_line + self.type_column = type_column def visit(self, tabs = 0): node = self diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 8b21bc2f4..1debd435a 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -60,14 +60,14 @@ def p_feature_list(p): p[0] = [p[1]] + p[3] def p_def_attr(p): - '''def_attr : ID DOUBLE_DOT TYPE_ID - | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr + '''def_attr : ID DOUBLE_DOT type_id + | ID DOUBLE_DOT type_id LEFT_ARROW expr ''' line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 4: - p[0] = AttrDeclarationNode(p[1], p[3], line = line, column = column) + p[0] = AttrDeclarationNode(p[1], p[3]['value'], line = line, column = column, type_line = p[3]['line'], type_column = p[3]['column']) else: - p[0] = AttrDeclarationNode(p[1], p[3], p[5], line = line, column = column) + p[0] = AttrDeclarationNode(p[1], p[3]['value'], p[5], line = line, column = column, type_line = p[3]['line'], type_column = p[3]['column']) def p_def_func(p): '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE diff --git a/src/compiler_components/parsetab.py b/src/compiler_components/parsetab.py index 0e3ed7ffd..4ca89b99f 100644 --- a/src/compiler_components/parsetab.py +++ b/src/compiler_components/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS type_id LBRACE feature_list RBRACE\n | CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDtype_id : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT TYPE_ID\n | ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' +_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS type_id LBRACE feature_list RBRACE\n | CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDtype_id : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT type_id\n | ID DOUBLE_DOT type_id LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,8,],[0,-1,-2,-3,]),'SEMICOLON':([3,12,13,18,26,38,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,82,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,136,138,143,145,146,],[5,19,20,-4,-12,-5,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,109,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-14,-56,-45,-58,147,]),'TYPE_ID':([4,10,21,33,50,62,76,135,],[7,17,26,61,78,89,104,141,]),'LBRACE':([6,7,16,17,32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,89,96,106,107,109,110,113,116,119,132,139,144,],[9,-7,23,-6,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,113,56,56,56,56,56,56,56,56,56,56,56,]),'INHERITS':([6,7,],[10,-7,]),'ID':([9,19,20,22,23,32,36,42,47,54,55,56,57,58,59,60,64,65,68,69,70,71,72,73,74,75,96,106,107,109,110,111,112,113,116,119,120,132,139,144,147,],[15,15,15,27,15,39,27,67,39,39,39,39,85,39,67,67,39,39,67,67,67,67,67,67,67,103,67,39,39,39,39,85,127,39,39,39,131,39,39,39,127,]),'RBRACE':([9,11,14,19,20,23,24,25,31,39,41,43,44,45,46,48,49,51,52,53,66,67,78,81,87,88,91,95,97,98,99,100,101,102,105,108,109,114,118,123,124,128,133,134,138,143,145,],[-8,18,-11,-8,-8,-8,-9,-10,38,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,108,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-20,-57,-30,-21,-48,136,-46,-51,-56,-45,-58,]),'DOUBLE_DOT':([15,27,34,85,127,],[21,33,62,21,135,]),'LPAREN':([15,32,39,42,47,54,55,56,58,59,60,64,65,67,68,69,70,71,72,73,74,96,103,106,107,109,110,113,116,119,131,132,139,144,],[22,47,65,47,47,47,47,47,47,47,47,47,47,65,47,47,47,47,47,47,47,47,119,47,47,47,47,47,47,47,139,47,47,47,]),'RPAREN':([22,28,29,30,35,37,39,41,43,44,45,46,48,49,51,52,53,61,63,65,66,67,77,78,87,88,90,91,92,93,94,95,97,98,99,100,101,102,105,108,114,115,117,118,119,124,129,130,133,134,137,138,139,142,143,145,],[-8,34,-8,-16,-15,-18,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,-8,-8,-23,-38,105,-41,-54,-55,-17,-28,114,-8,-60,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-59,-62,-30,-8,-48,-8,138,-46,-51,-61,-56,-8,145,-45,-58,]),'COMMA':([26,29,39,40,41,43,44,45,46,48,49,51,52,53,61,63,66,67,78,84,87,88,91,93,95,97,98,99,100,101,102,105,108,114,118,124,129,133,134,138,143,145,],[-12,36,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,36,-23,-38,-41,111,-54,-55,-28,116,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,116,-46,-51,-56,-45,-58,]),'IN':([26,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,83,84,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,125,133,134,138,143,145,],[-12,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,110,-49,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-50,-46,-51,-56,-45,-58,]),'LEFT_ARROW':([26,39,],[32,64,]),'NOT':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,132,139,144,],[42,42,42,42,42,42,42,42,42,96,96,96,42,42,42,42,42,42,42,42,42,42,42,]),'NUMBER':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'NEW':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'TRUE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'FALSE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'IF':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'WHILE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'LET':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'CASE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'ISVOID':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'NHANHARA':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,]),'DOT':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,104,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,75,-36,-39,-40,-42,-43,-44,-23,-38,-41,75,75,-28,-24,-25,-26,-31,-32,75,75,120,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'ARROBA':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,76,-36,-39,-40,-42,-43,-44,-23,-38,-41,76,76,-28,-24,-25,-26,-31,-32,76,76,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'TIMES':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,73,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,73,73,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'DIVIDE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,74,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,74,74,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINOR':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,68,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINOR_EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,69,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,70,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'PLUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,71,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,71,71,71,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,72,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,72,72,72,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'THEN':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,79,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,106,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'LOOP':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,80,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,107,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'OF':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,86,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,112,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'ELSE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,121,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,132,-48,-46,-51,-56,-45,-58,]),'POOL':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,122,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,133,-48,-46,-51,-56,-45,-58,]),'FI':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,140,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,143,-45,-58,]),'ESAC':([126,147,148,],[134,-52,-53,]),'RIGHT_ARROW':([141,],[144,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,8,],[0,-1,-2,-3,]),'SEMICOLON':([3,7,12,13,18,26,38,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,82,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,136,138,143,145,146,],[5,-7,19,20,-4,-12,-5,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,109,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-14,-56,-45,-58,147,]),'TYPE_ID':([4,10,21,33,50,62,76,135,],[7,17,7,61,78,89,104,141,]),'LBRACE':([6,7,16,17,32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,89,96,106,107,109,110,113,116,119,132,139,144,],[9,-7,23,-6,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,113,56,56,56,56,56,56,56,56,56,56,56,]),'INHERITS':([6,7,],[10,-7,]),'LEFT_ARROW':([7,26,39,],[-7,32,64,]),'COMMA':([7,26,29,39,40,41,43,44,45,46,48,49,51,52,53,61,63,66,67,78,84,87,88,91,93,95,97,98,99,100,101,102,105,108,114,118,124,129,133,134,138,143,145,],[-7,-12,36,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,36,-23,-38,-41,111,-54,-55,-28,116,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,116,-46,-51,-56,-45,-58,]),'IN':([7,26,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,83,84,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,125,133,134,138,143,145,],[-7,-12,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,110,-49,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-50,-46,-51,-56,-45,-58,]),'ID':([9,19,20,22,23,32,36,42,47,54,55,56,57,58,59,60,64,65,68,69,70,71,72,73,74,75,96,106,107,109,110,111,112,113,116,119,120,132,139,144,147,],[15,15,15,27,15,39,27,67,39,39,39,39,85,39,67,67,39,39,67,67,67,67,67,67,67,103,67,39,39,39,39,85,127,39,39,39,131,39,39,39,127,]),'RBRACE':([9,11,14,19,20,23,24,25,31,39,41,43,44,45,46,48,49,51,52,53,66,67,78,81,87,88,91,95,97,98,99,100,101,102,105,108,109,114,118,123,124,128,133,134,138,143,145,],[-8,18,-11,-8,-8,-8,-9,-10,38,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,108,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-20,-57,-30,-21,-48,136,-46,-51,-56,-45,-58,]),'DOUBLE_DOT':([15,27,34,85,127,],[21,33,62,21,135,]),'LPAREN':([15,32,39,42,47,54,55,56,58,59,60,64,65,67,68,69,70,71,72,73,74,96,103,106,107,109,110,113,116,119,131,132,139,144,],[22,47,65,47,47,47,47,47,47,47,47,47,47,65,47,47,47,47,47,47,47,47,119,47,47,47,47,47,47,47,139,47,47,47,]),'RPAREN':([22,28,29,30,35,37,39,41,43,44,45,46,48,49,51,52,53,61,63,65,66,67,77,78,87,88,90,91,92,93,94,95,97,98,99,100,101,102,105,108,114,115,117,118,119,124,129,130,133,134,137,138,139,142,143,145,],[-8,34,-8,-16,-15,-18,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,-8,-8,-23,-38,105,-41,-54,-55,-17,-28,114,-8,-60,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-59,-62,-30,-8,-48,-8,138,-46,-51,-61,-56,-8,145,-45,-58,]),'NOT':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,132,139,144,],[42,42,42,42,42,42,42,42,42,96,96,96,42,42,42,42,42,42,42,42,42,42,42,]),'NUMBER':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'NEW':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'TRUE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'FALSE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'IF':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'WHILE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'LET':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'CASE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'ISVOID':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'NHANHARA':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,]),'DOT':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,104,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,75,-36,-39,-40,-42,-43,-44,-23,-38,-41,75,75,-28,-24,-25,-26,-31,-32,75,75,120,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'ARROBA':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,76,-36,-39,-40,-42,-43,-44,-23,-38,-41,76,76,-28,-24,-25,-26,-31,-32,76,76,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'TIMES':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,73,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,73,73,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'DIVIDE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,74,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,74,74,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINOR':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,68,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINOR_EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,69,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,70,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'PLUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,71,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,71,71,71,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,72,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,72,72,72,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'THEN':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,79,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,106,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'LOOP':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,80,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,107,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'OF':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,86,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,112,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'ELSE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,121,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,132,-48,-46,-51,-56,-45,-58,]),'POOL':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,122,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,133,-48,-46,-51,-56,-45,-58,]),'FI':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,140,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,143,-45,-58,]),'ESAC':([126,147,148,],[134,-52,-53,]),'RIGHT_ARROW':([141,],[144,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,8,]),'def_class':([0,5,],[3,3,]),'type_id':([4,],[6,]),'feature_list':([9,19,20,23,],[11,24,25,31,]),'def_attr':([9,19,20,23,57,111,],[12,12,12,12,84,84,]),'def_func':([9,19,20,23,],[13,13,13,13,]),'empty':([9,19,20,22,23,29,63,65,93,119,129,139,],[14,14,14,30,14,37,37,94,117,94,117,94,]),'type_inherit':([10,],[16,]),'param_list':([22,],[28,]),'param':([22,36,],[29,63,]),'param_list2':([29,63,],[35,90,]),'expr':([32,47,54,55,56,58,64,65,106,107,109,110,113,116,119,132,139,144,],[40,77,79,80,82,86,91,93,121,122,82,124,128,129,93,140,93,146,]),'bool':([32,42,47,54,55,56,58,64,65,96,106,107,109,110,113,116,119,132,139,144,],[41,66,41,41,41,41,41,41,41,118,41,41,41,41,41,41,41,41,41,41,]),'arith':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,132,139,144,],[43,43,43,43,43,43,43,43,43,95,97,98,43,43,43,43,43,43,43,43,43,43,43,]),'term':([32,42,47,54,55,56,58,64,65,68,69,70,71,72,96,106,107,109,110,113,116,119,132,139,144,],[44,44,44,44,44,44,44,44,44,44,44,44,99,100,44,44,44,44,44,44,44,44,44,44,44,]),'factor':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[45,45,45,45,45,45,45,87,88,45,45,45,45,45,45,45,101,102,45,45,45,45,45,45,45,45,45,45,45,]),'atom':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'func_call':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'expr_list':([56,109,],[81,123,]),'atr_decl_list':([57,111,],[83,125,]),'arg_list':([65,119,139,],[92,130,142,]),'arg_list2':([93,129,],[115,137,]),'case_list':([112,147,],[126,148,]),} +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,8,]),'def_class':([0,5,],[3,3,]),'type_id':([4,21,],[6,26,]),'feature_list':([9,19,20,23,],[11,24,25,31,]),'def_attr':([9,19,20,23,57,111,],[12,12,12,12,84,84,]),'def_func':([9,19,20,23,],[13,13,13,13,]),'empty':([9,19,20,22,23,29,63,65,93,119,129,139,],[14,14,14,30,14,37,37,94,117,94,117,94,]),'type_inherit':([10,],[16,]),'param_list':([22,],[28,]),'param':([22,36,],[29,63,]),'param_list2':([29,63,],[35,90,]),'expr':([32,47,54,55,56,58,64,65,106,107,109,110,113,116,119,132,139,144,],[40,77,79,80,82,86,91,93,121,122,82,124,128,129,93,140,93,146,]),'bool':([32,42,47,54,55,56,58,64,65,96,106,107,109,110,113,116,119,132,139,144,],[41,66,41,41,41,41,41,41,41,118,41,41,41,41,41,41,41,41,41,41,]),'arith':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,132,139,144,],[43,43,43,43,43,43,43,43,43,95,97,98,43,43,43,43,43,43,43,43,43,43,43,]),'term':([32,42,47,54,55,56,58,64,65,68,69,70,71,72,96,106,107,109,110,113,116,119,132,139,144,],[44,44,44,44,44,44,44,44,44,44,44,44,99,100,44,44,44,44,44,44,44,44,44,44,44,]),'factor':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[45,45,45,45,45,45,45,87,88,45,45,45,45,45,45,45,101,102,45,45,45,45,45,45,45,45,45,45,45,]),'atom':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'func_call':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'expr_list':([56,109,],[81,123,]),'atr_decl_list':([57,111,],[83,125,]),'arg_list':([65,119,139,],[92,130,142,]),'arg_list2':([93,129,],[115,137,]),'case_list':([112,147,],[126,148,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -38,8 +38,8 @@ ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',53), ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',54), ('feature_list -> empty','feature_list',1,'p_feature_list','cool_parser.py',55), - ('def_attr -> ID DOUBLE_DOT TYPE_ID','def_attr',3,'p_def_attr','cool_parser.py',63), - ('def_attr -> ID DOUBLE_DOT TYPE_ID LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',64), + ('def_attr -> ID DOUBLE_DOT type_id','def_attr',3,'p_def_attr','cool_parser.py',63), + ('def_attr -> ID DOUBLE_DOT type_id LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',64), ('def_func -> ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE','def_func',9,'p_def_func','cool_parser.py',73), ('param_list -> param param_list2','param_list',2,'p_param_list','cool_parser.py',79), ('param_list -> empty','param_list',1,'p_param_list','cool_parser.py',80), diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index 216a5d831..3c92bb1e8 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -54,7 +54,7 @@ def visit(self, node:AttrDeclarationNode,scope:Scope): typex =self.current_type if node.type == "SELF_TYPE" else self.context.get_type(node.type,node.line) self.context.check_type(node.expr.type,typex,node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) + self.errors.append(f"({node.type_line},{node.type_column}) - TypeError: " + str(e)) @visitor.when(FuncDeclarationNode) def visit(self, node:FuncDeclarationNode,scope:Scope): @@ -73,6 +73,7 @@ def visit(self, node:FuncDeclarationNode,scope:Scope): self.visit(node.body,scope.create_child()) try: typex = method.return_type if not isinstance(method.return_type,SELF_TYPE) else self.current_type + self.context.check_type(node.body.type,typex,node.line) except SemanticError as e: self.errors.append(f"({node.line},{node.column-4}) - TypeError: " + str(e)) diff --git a/src/program.txt b/src/program.txt index ec38a7766..910e93a44 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,67 +1,26 @@ -(* hairy . . .*) - -class Foo inherits Bazz { - a : Razz <- case self of - n : Razz => (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - b : Int <- a.doh() + g.doh() + doh() + printh(); - - doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; - -}; - -class Bar inherits Razz { - - c : Int <- doh(); - - d : Object <- printh(); -}; - - -class Razz inherits Foo { - - e : Bar <- case self of - n : Razz => (new Bar); - n : Bar => n; - esac; - - f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); - -}; - -class Bazz inherits IO { - - h : Int <- 1; - - g : Foo <- case self of - n : Bazz => (new Foo); - n : Razz => (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - i : Object <- printh(); - - printh() : Int { { out_int(h); 0; } }; - - doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; -}; - -(* scary . . . *) -class Main { - a : Bazz <- new Bazz; - b : Foo <- new Foo; - c : Razz <- new Razz; - d : Bar <- new Bar; - - main(): String { "do nothing" }; - -}; - - - - - +--evaluates to true if expr is void and evaluates to false if expr is not void. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if isvoid new F then + new C + else + if false then new D + else new E fi + fi; + + test: B <- isvoid if isvoid new F then + new C + else + if false then new D + else new E fi + fi; +}; From bbaa64f6474c4c27500072d34d2aef5781e67976 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 17:36:51 -0300 Subject: [PATCH 45/60] redefine method of parent class alowed --- .../semantic/structures.py | 16 +++--- src/program.txt | 50 +++++++++++-------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index 823475c0d..91f47e9f0 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -82,25 +82,29 @@ def define_attribute(self, name:str, typex, pos): else: raise SemanticError(f'Attribute "{name}" is already defined in {self.name}',pos) - def get_method(self, name:str,line=0, col=0): + def get_method(self, name:str,line=0, col=0, own={'value':True}): try: return next(method for method in self.methods if method.name == name) except StopIteration: if self.parent is None: raise AttributeError(f'{line},{col} - NameError: Undeclared identifier {name}') try: - return self.parent.get_method(name) + own['value'] = False + return self.parent.get_method(name, own) except SemanticError: raise AttributeError(f'{line},{col} - NameError: Undeclared identifier {name}') def define_method(self, name:str, param_names:list, param_types:list, return_type, pos): try: - method = self.get_method(name, pos) + own ={'value':True} + method = self.get_method(name, pos, own = own) if method.return_type != return_type or method.param_types != param_types: raise SemanticError(f'Method "{name}" already defined in {self.name} with a different signature.', pos) - #else: - # raise SemanticError(f'Method "{name}" already defined in {self.name} ', pos) - + else: + if own['value']: + raise SemanticError(f'Method "{name}" already defined in {self.name} ', pos) + raise AttributeError() + except AttributeError as e: method = Method(name, param_names, param_types, return_type) self.methods.append(method) diff --git a/src/program.txt b/src/program.txt index 910e93a44..6c1b291fa 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,26 +1,34 @@ ---evaluates to true if expr is void and evaluates to false if expr is not void. +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the dispatch and the definition of f must have the same number of arguments +*) -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; class Main inherits IO { main(): IO { out_string("Hello World!")}; - b: B <- if isvoid new F then - new C - else - if false then new D - else new E fi - fi; - - test: B <- isvoid if isvoid new F then - new C - else - if false then new D - else new E fi - fi; -}; + test: Int <- new D.back("Hello ").g(2, 2); +}; From 859c6d6af8a7d6162a68153974fb02888228a4bb Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 17:46:58 -0300 Subject: [PATCH 46/60] dispathc undeclared method error printed --- src/compiler_components/semantic/type_checker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index 3c92bb1e8..cf28fee26 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -149,7 +149,7 @@ def visit(self, node:DispatchNode, scope:Scope): except SemanticError as e: self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - AttributeError: dispatch undeclared method {node.f}") @visitor.when(CallNode) def visit(self, node:CallNode, scope:Scope): @@ -209,7 +209,7 @@ def visit(self, node:AssignNode,scope:Scope): at = [ at[0] for at in self.current_type.all_attributes() if at[0].name == node.id] var = at[0] except: - raise NameError(f"({node.line}, {node.column}) - NameError: Undeclared identifier {node.id}") + raise SemanticError(f"({node.line}, {node.column}) - NameError: Undeclared identifier {node.id}") typex = self.current_type if isinstance(var.type , SELF_TYPE) else var.type From 7854a3f18d268985a5a8f330494c0000d076b979 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 17:55:35 -0300 Subject: [PATCH 47/60] dispatch method with incorrect number of params error printed correctly --- src/compiler_components/semantic/structures.py | 2 ++ src/compiler_components/semantic/type_checker.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index 91f47e9f0..050f27008 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -12,6 +12,8 @@ class NameError(SemanticError): pass class AttributeError(SemanticError): pass +class ParamError(Exception): + pass ############## End Semantic Errors ############################# ############ Class members ############################### diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index cf28fee26..aeac3887f 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -142,7 +142,7 @@ def visit(self, node:DispatchNode, scope:Scope): ret_type = method.return_type if not isinstance(method.return_type,SELF_TYPE) else typex node.type = ret_type if len(method.param_types) != len(node.params): - raise SemanticError (f'Method takes {len(method.param_types)} params but {len(node.params)} were given', node.line) + raise ParamError() for i in range(len(node.params)): try: self.context.check_type(node.params[i].type,method.param_types[i],node.line) @@ -150,6 +150,8 @@ def visit(self, node:DispatchNode, scope:Scope): self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) except SemanticError as e: self.errors.append(f"({node.line},{node.column}) - AttributeError: dispatch undeclared method {node.f}") + except ParamError as p: + self.errors.append(f'({node.line},{node.column}) - SemanticError: Method takes {len(method.param_types)} params but {len(node.params)} were given') @visitor.when(CallNode) def visit(self, node:CallNode, scope:Scope): From 86e186b564008086586d53105def506948219c49 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 18:02:21 -0300 Subject: [PATCH 48/60] it cant inherit from not declared type, (error printed correctly) --- .../semantic/type_collector.py | 2 +- src/program.txt | 41 ++++++------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py index 6ce53881c..29a872c5c 100644 --- a/src/compiler_components/semantic/type_collector.py +++ b/src/compiler_components/semantic/type_collector.py @@ -31,7 +31,7 @@ def visit(self, node): self.errors.append(f"({dec_node.line_father},{dec_node.column_father}) - SemanticError: Basic type as parent") self.context.get_type(dec_node.id, dec_node.line).set_parent(self.context.get_type(dec_node.parent,dec_node.line),node.line) except SemanticError as e: - self.errors.append(f"({dec_node.line},{dec_node.column}) - TypeError: " + str(e)) + self.errors.append(f"({dec_node.line_father},{dec_node.column_father}) - TypeError: " + str(e)) cycles = self.context.circular_dependency() for cycle in cycles: diff --git a/src/program.txt b/src/program.txt index 6c1b291fa..41a7e1e0b 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,34 +1,19 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the dispatch and the definition of f must have the same number of arguments -*) +--If C inherits from P, then P must have a class definition somewhere in the program. -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; +class Main inherits IO { + main(): IO { out_string("hi!") }; - back(s: String): B { { - out_string(s); - self; - } }; + main: IO <- out_string("bye!"); }; -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +class Alo { + x: Int <- 3; + + x(): String { "3" }; +}; - test: Int <- new D.back("Hello ").g(2, 2); +class B inherits A { + div(a: Int, b: Int): Int { a / b}; + + x: String <- "2"; }; From 489eaa50a2d88fbd2a333f7770d575ffa1289561 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 18:14:03 -0300 Subject: [PATCH 49/60] error multiple type in diferent branch correctly printed --- src/compiler_components/cool_parser.py | 15 ++++--- src/compiler_components/parsetab.py | 29 ++++++------- .../semantic/type_checker.py | 2 +- src/program.txt | 41 +++++++++++++------ 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index 1debd435a..de3770979 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -253,14 +253,19 @@ def p_atomCase(p): p[0] = CaseNode(p[2], p[4], line = line, column = column) def p_caseList(p): - '''case_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON - | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list + '''case_list : id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON + | id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list ''' - line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) + if len(p) == 7: - p[0] = [AttrDeclarationNode(p[1], p[3], p[5], line = line, column = column)] + p[0] = [AttrDeclarationNode(p[1]['value'], p[3], p[5], line = p[1]['line'], column = p[1]['column'])] else: - p[0] = [AttrDeclarationNode(p[1], p[3], p[5], line = line, column = column)] + p[7] + p[0] = [AttrDeclarationNode(p[1]['value'], p[3], p[5], line = p[1]['line'], column = p[1]['column'])] + p[7] + +def p_id_case(p): + 'id_case : ID' + line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) + p[0] ={'value':p[1], 'line':line, 'column':column} def p_atomIsVoid(p): 'atom : ISVOID factor' diff --git a/src/compiler_components/parsetab.py b/src/compiler_components/parsetab.py index 4ca89b99f..f1b2180ae 100644 --- a/src/compiler_components/parsetab.py +++ b/src/compiler_components/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS type_id LBRACE feature_list RBRACE\n | CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDtype_id : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT type_id\n | ID DOUBLE_DOT type_id LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n atom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' +_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS type_id LBRACE feature_list RBRACE\n | CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDtype_id : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT type_id\n | ID DOUBLE_DOT type_id LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n id_case : IDatom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,8,],[0,-1,-2,-3,]),'SEMICOLON':([3,7,12,13,18,26,38,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,82,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,136,138,143,145,146,],[5,-7,19,20,-4,-12,-5,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,109,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-14,-56,-45,-58,147,]),'TYPE_ID':([4,10,21,33,50,62,76,135,],[7,17,7,61,78,89,104,141,]),'LBRACE':([6,7,16,17,32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,89,96,106,107,109,110,113,116,119,132,139,144,],[9,-7,23,-6,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,113,56,56,56,56,56,56,56,56,56,56,56,]),'INHERITS':([6,7,],[10,-7,]),'LEFT_ARROW':([7,26,39,],[-7,32,64,]),'COMMA':([7,26,29,39,40,41,43,44,45,46,48,49,51,52,53,61,63,66,67,78,84,87,88,91,93,95,97,98,99,100,101,102,105,108,114,118,124,129,133,134,138,143,145,],[-7,-12,36,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,36,-23,-38,-41,111,-54,-55,-28,116,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,116,-46,-51,-56,-45,-58,]),'IN':([7,26,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,83,84,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,125,133,134,138,143,145,],[-7,-12,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,110,-49,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-50,-46,-51,-56,-45,-58,]),'ID':([9,19,20,22,23,32,36,42,47,54,55,56,57,58,59,60,64,65,68,69,70,71,72,73,74,75,96,106,107,109,110,111,112,113,116,119,120,132,139,144,147,],[15,15,15,27,15,39,27,67,39,39,39,39,85,39,67,67,39,39,67,67,67,67,67,67,67,103,67,39,39,39,39,85,127,39,39,39,131,39,39,39,127,]),'RBRACE':([9,11,14,19,20,23,24,25,31,39,41,43,44,45,46,48,49,51,52,53,66,67,78,81,87,88,91,95,97,98,99,100,101,102,105,108,109,114,118,123,124,128,133,134,138,143,145,],[-8,18,-11,-8,-8,-8,-9,-10,38,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,108,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-20,-57,-30,-21,-48,136,-46,-51,-56,-45,-58,]),'DOUBLE_DOT':([15,27,34,85,127,],[21,33,62,21,135,]),'LPAREN':([15,32,39,42,47,54,55,56,58,59,60,64,65,67,68,69,70,71,72,73,74,96,103,106,107,109,110,113,116,119,131,132,139,144,],[22,47,65,47,47,47,47,47,47,47,47,47,47,65,47,47,47,47,47,47,47,47,119,47,47,47,47,47,47,47,139,47,47,47,]),'RPAREN':([22,28,29,30,35,37,39,41,43,44,45,46,48,49,51,52,53,61,63,65,66,67,77,78,87,88,90,91,92,93,94,95,97,98,99,100,101,102,105,108,114,115,117,118,119,124,129,130,133,134,137,138,139,142,143,145,],[-8,34,-8,-16,-15,-18,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,-8,-8,-23,-38,105,-41,-54,-55,-17,-28,114,-8,-60,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-59,-62,-30,-8,-48,-8,138,-46,-51,-61,-56,-8,145,-45,-58,]),'NOT':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,132,139,144,],[42,42,42,42,42,42,42,42,42,96,96,96,42,42,42,42,42,42,42,42,42,42,42,]),'NUMBER':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'NEW':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'TRUE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'FALSE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'IF':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'WHILE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'LET':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'CASE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'ISVOID':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'NHANHARA':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,]),'DOT':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,104,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,75,-36,-39,-40,-42,-43,-44,-23,-38,-41,75,75,-28,-24,-25,-26,-31,-32,75,75,120,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'ARROBA':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,76,-36,-39,-40,-42,-43,-44,-23,-38,-41,76,76,-28,-24,-25,-26,-31,-32,76,76,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'TIMES':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,73,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,73,73,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'DIVIDE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,74,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,74,74,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINOR':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,68,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINOR_EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,69,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,70,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'PLUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,71,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,71,71,71,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'MINUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,72,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,72,72,72,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'THEN':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,79,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,106,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'LOOP':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,80,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,107,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'OF':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,86,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,112,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,-45,-58,]),'ELSE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,121,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,132,-48,-46,-51,-56,-45,-58,]),'POOL':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,122,124,133,134,138,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,133,-48,-46,-51,-56,-45,-58,]),'FI':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,133,134,138,140,143,145,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-54,-55,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-57,-30,-48,-46,-51,-56,143,-45,-58,]),'ESAC':([126,147,148,],[134,-52,-53,]),'RIGHT_ARROW':([141,],[144,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,8,],[0,-1,-2,-3,]),'SEMICOLON':([3,7,12,13,18,26,38,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,82,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,137,139,144,146,147,],[5,-7,19,20,-4,-12,-5,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,109,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-14,-57,-45,-59,148,]),'TYPE_ID':([4,10,21,33,50,62,76,136,],[7,17,7,61,78,89,104,142,]),'LBRACE':([6,7,16,17,32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,89,96,106,107,109,110,113,116,119,133,140,145,],[9,-7,23,-6,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,113,56,56,56,56,56,56,56,56,56,56,56,]),'INHERITS':([6,7,],[10,-7,]),'LEFT_ARROW':([7,26,39,],[-7,32,64,]),'COMMA':([7,26,29,39,40,41,43,44,45,46,48,49,51,52,53,61,63,66,67,78,84,87,88,91,93,95,97,98,99,100,101,102,105,108,114,118,124,130,134,135,139,144,146,],[-7,-12,36,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,36,-23,-38,-41,111,-55,-56,-28,116,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,116,-46,-51,-57,-45,-59,]),'IN':([7,26,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,83,84,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,125,134,135,139,144,146,],[-7,-12,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,110,-49,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-50,-46,-51,-57,-45,-59,]),'ID':([9,19,20,22,23,32,36,42,47,54,55,56,57,58,59,60,64,65,68,69,70,71,72,73,74,75,96,106,107,109,110,111,112,113,116,119,120,133,140,145,148,],[15,15,15,27,15,39,27,67,39,39,39,39,85,39,67,67,39,39,67,67,67,67,67,67,67,103,67,39,39,39,39,85,128,39,39,39,132,39,39,39,128,]),'RBRACE':([9,11,14,19,20,23,24,25,31,39,41,43,44,45,46,48,49,51,52,53,66,67,78,81,87,88,91,95,97,98,99,100,101,102,105,108,109,114,118,123,124,129,134,135,139,144,146,],[-8,18,-11,-8,-8,-8,-9,-10,38,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,108,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-20,-58,-30,-21,-48,137,-46,-51,-57,-45,-59,]),'DOUBLE_DOT':([15,27,34,85,127,128,],[21,33,62,21,136,-54,]),'LPAREN':([15,32,39,42,47,54,55,56,58,59,60,64,65,67,68,69,70,71,72,73,74,96,103,106,107,109,110,113,116,119,132,133,140,145,],[22,47,65,47,47,47,47,47,47,47,47,47,47,65,47,47,47,47,47,47,47,47,119,47,47,47,47,47,47,47,140,47,47,47,]),'RPAREN':([22,28,29,30,35,37,39,41,43,44,45,46,48,49,51,52,53,61,63,65,66,67,77,78,87,88,90,91,92,93,94,95,97,98,99,100,101,102,105,108,114,115,117,118,119,124,130,131,134,135,138,139,140,143,144,146,],[-8,34,-8,-16,-15,-18,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,-8,-8,-23,-38,105,-41,-55,-56,-17,-28,114,-8,-61,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-60,-63,-30,-8,-48,-8,139,-46,-51,-62,-57,-8,146,-45,-59,]),'NOT':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,133,140,145,],[42,42,42,42,42,42,42,42,42,96,96,96,42,42,42,42,42,42,42,42,42,42,42,]),'NUMBER':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'NEW':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'TRUE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'FALSE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'IF':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'WHILE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'LET':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'CASE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'ISVOID':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'NHANHARA':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,]),'DOT':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,104,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,75,-36,-39,-40,-42,-43,-44,-23,-38,-41,75,75,-28,-24,-25,-26,-31,-32,75,75,120,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'ARROBA':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,76,-36,-39,-40,-42,-43,-44,-23,-38,-41,76,76,-28,-24,-25,-26,-31,-32,76,76,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'TIMES':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,73,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,73,73,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'DIVIDE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,74,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,74,74,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINOR':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,68,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINOR_EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,69,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,70,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'PLUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,71,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,71,71,71,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,72,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,72,72,72,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'THEN':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,79,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,106,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'LOOP':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,80,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,107,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'OF':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,86,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,112,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'ELSE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,121,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,133,-48,-46,-51,-57,-45,-59,]),'POOL':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,122,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,134,-48,-46,-51,-57,-45,-59,]),'FI':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,141,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,144,-45,-59,]),'ESAC':([126,148,149,],[135,-52,-53,]),'RIGHT_ARROW':([142,],[145,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,8,]),'def_class':([0,5,],[3,3,]),'type_id':([4,21,],[6,26,]),'feature_list':([9,19,20,23,],[11,24,25,31,]),'def_attr':([9,19,20,23,57,111,],[12,12,12,12,84,84,]),'def_func':([9,19,20,23,],[13,13,13,13,]),'empty':([9,19,20,22,23,29,63,65,93,119,129,139,],[14,14,14,30,14,37,37,94,117,94,117,94,]),'type_inherit':([10,],[16,]),'param_list':([22,],[28,]),'param':([22,36,],[29,63,]),'param_list2':([29,63,],[35,90,]),'expr':([32,47,54,55,56,58,64,65,106,107,109,110,113,116,119,132,139,144,],[40,77,79,80,82,86,91,93,121,122,82,124,128,129,93,140,93,146,]),'bool':([32,42,47,54,55,56,58,64,65,96,106,107,109,110,113,116,119,132,139,144,],[41,66,41,41,41,41,41,41,41,118,41,41,41,41,41,41,41,41,41,41,]),'arith':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,132,139,144,],[43,43,43,43,43,43,43,43,43,95,97,98,43,43,43,43,43,43,43,43,43,43,43,]),'term':([32,42,47,54,55,56,58,64,65,68,69,70,71,72,96,106,107,109,110,113,116,119,132,139,144,],[44,44,44,44,44,44,44,44,44,44,44,44,99,100,44,44,44,44,44,44,44,44,44,44,44,]),'factor':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[45,45,45,45,45,45,45,87,88,45,45,45,45,45,45,45,101,102,45,45,45,45,45,45,45,45,45,45,45,]),'atom':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'func_call':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,132,139,144,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'expr_list':([56,109,],[81,123,]),'atr_decl_list':([57,111,],[83,125,]),'arg_list':([65,119,139,],[92,130,142,]),'arg_list2':([93,129,],[115,137,]),'case_list':([112,147,],[126,148,]),} +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,8,]),'def_class':([0,5,],[3,3,]),'type_id':([4,21,],[6,26,]),'feature_list':([9,19,20,23,],[11,24,25,31,]),'def_attr':([9,19,20,23,57,111,],[12,12,12,12,84,84,]),'def_func':([9,19,20,23,],[13,13,13,13,]),'empty':([9,19,20,22,23,29,63,65,93,119,130,140,],[14,14,14,30,14,37,37,94,117,94,117,94,]),'type_inherit':([10,],[16,]),'param_list':([22,],[28,]),'param':([22,36,],[29,63,]),'param_list2':([29,63,],[35,90,]),'expr':([32,47,54,55,56,58,64,65,106,107,109,110,113,116,119,133,140,145,],[40,77,79,80,82,86,91,93,121,122,82,124,129,130,93,141,93,147,]),'bool':([32,42,47,54,55,56,58,64,65,96,106,107,109,110,113,116,119,133,140,145,],[41,66,41,41,41,41,41,41,41,118,41,41,41,41,41,41,41,41,41,41,]),'arith':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,133,140,145,],[43,43,43,43,43,43,43,43,43,95,97,98,43,43,43,43,43,43,43,43,43,43,43,]),'term':([32,42,47,54,55,56,58,64,65,68,69,70,71,72,96,106,107,109,110,113,116,119,133,140,145,],[44,44,44,44,44,44,44,44,44,44,44,44,99,100,44,44,44,44,44,44,44,44,44,44,44,]),'factor':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[45,45,45,45,45,45,45,87,88,45,45,45,45,45,45,45,101,102,45,45,45,45,45,45,45,45,45,45,45,]),'atom':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'func_call':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'expr_list':([56,109,],[81,123,]),'atr_decl_list':([57,111,],[83,125,]),'arg_list':([65,119,140,],[92,131,143,]),'arg_list2':([93,130,],[115,138,]),'case_list':([112,148,],[126,149,]),'id_case':([112,148,],[127,127,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -78,15 +78,16 @@ ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',241), ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',242), ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',251), - ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',256), - ('case_list -> ID DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',257), - ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',266), - ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',277), - ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',282), - ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',288), - ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',293), - ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',300), - ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',301), - ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',309), - ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',310), + ('case_list -> id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',256), + ('case_list -> id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',257), + ('id_case -> ID','id_case',1,'p_id_case','cool_parser.py',266), + ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',271), + ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',282), + ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',287), + ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',293), + ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',298), + ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',305), + ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',306), + ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',314), + ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',315), ] diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index aeac3887f..f0dd61c44 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -90,7 +90,7 @@ def visit(self, node:CaseNode, scope:Scope): for branches in node.list_case: tmpscope = scb.create_child() if branches.type in typesbr: - self.errors.append(f"({node.line},{node.column}) - SemanticError: Type in more than one branch") + self.errors.append(f"({branches.line},{branches.column}) - SemanticError: Type in more than one branch") typesbr.add(branches.type) try : typex = self.context.get_type(branches.type,branches.expr.line) diff --git a/src/program.txt b/src/program.txt index 41a7e1e0b..66a0557e1 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,19 +1,36 @@ ---If C inherits from P, then P must have a class definition somewhere in the program. +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. +*) -class Main inherits IO { - main(): IO { out_string("hi!") }; - - main: IO <- out_string("bye!"); +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; }; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; -class Alo { - x: Int <- 3; + back(s: String): B { { + out_string(s); + self; + } }; - x(): String { "3" }; + alphabet(a: A, b: B, c: C): D { self }; }; -class B inherits A { - div(a: Int, b: Int): Int { a / b}; - - x: String <- "2"; +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); }; From dc2f2ab8a51fd48afe55529580ce1f4255c5e804 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 19:02:32 -0300 Subject: [PATCH 50/60] semantic ready --- src/compiler_components/cool_parser.py | 17 ++- src/compiler_components/parsetab.py | 110 +++++++++--------- .../semantic/structures.py | 22 ++-- .../semantic/type_checker.py | 6 +- .../semantic/type_collector.py | 2 +- 5 files changed, 83 insertions(+), 74 deletions(-) diff --git a/src/compiler_components/cool_parser.py b/src/compiler_components/cool_parser.py index de3770979..f00a5c769 100644 --- a/src/compiler_components/cool_parser.py +++ b/src/compiler_components/cool_parser.py @@ -60,14 +60,13 @@ def p_feature_list(p): p[0] = [p[1]] + p[3] def p_def_attr(p): - '''def_attr : ID DOUBLE_DOT type_id - | ID DOUBLE_DOT type_id LEFT_ARROW expr + '''def_attr : id DOUBLE_DOT type_id + | id DOUBLE_DOT type_id LEFT_ARROW expr ''' - line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) if len(p) == 4: - p[0] = AttrDeclarationNode(p[1], p[3]['value'], line = line, column = column, type_line = p[3]['line'], type_column = p[3]['column']) + p[0] = AttrDeclarationNode(p[1]['value'], p[3]['value'], line = p[1]['line'], column = p[1]['column'], type_line = p[3]['line'], type_column = p[3]['column']) else: - p[0] = AttrDeclarationNode(p[1], p[3]['value'], p[5], line = line, column = column, type_line = p[3]['line'], type_column = p[3]['column']) + p[0] = AttrDeclarationNode(p[1]['value'], p[3]['value'], p[5], line = p[1]['line'], column = p[1]['column'], type_line = p[3]['line'], type_column = p[3]['column']) def p_def_func(p): '''def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE @@ -253,8 +252,8 @@ def p_atomCase(p): p[0] = CaseNode(p[2], p[4], line = line, column = column) def p_caseList(p): - '''case_list : id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON - | id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list + '''case_list : id DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON + | id DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list ''' if len(p) == 7: @@ -262,8 +261,8 @@ def p_caseList(p): else: p[0] = [AttrDeclarationNode(p[1]['value'], p[3], p[5], line = p[1]['line'], column = p[1]['column'])] + p[7] -def p_id_case(p): - 'id_case : ID' +def p_id(p): + 'id : ID' line, column = calculate_position(p.lexer.lexdata, p.lexer.lexpos) p[0] ={'value':p[1], 'line':line, 'column':column} diff --git a/src/compiler_components/parsetab.py b/src/compiler_components/parsetab.py index f1b2180ae..2f4d2e0dc 100644 --- a/src/compiler_components/parsetab.py +++ b/src/compiler_components/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS type_id LBRACE feature_list RBRACE\n | CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDtype_id : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : ID DOUBLE_DOT type_id\n | ID DOUBLE_DOT type_id LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n id_case : IDatom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' +_lr_signature = 'ARROBA CASE CLASS COMMA DIVIDE DOT DOUBLE_DOT ELSE EQUALS ESAC FALSE FI ID IF IN INHERITS ISVOID LBRACE LEFT_ARROW LET LOOP LPAREN MINOR MINOR_EQUALS MINUS NEW NHANHARA NOT NUMBER OF PLUS POOL RBRACE RIGHT_ARROW RPAREN SEMICOLON STRING THEN TIMES TRUE TYPE_ID WHILEprogram : class_listclass_list : def_class SEMICOLON\n | def_class SEMICOLON class_list\n def_class : CLASS type_id LBRACE feature_list RBRACE\n | CLASS type_id INHERITS type_inherit LBRACE feature_list RBRACE\n type_inherit : TYPE_IDtype_id : TYPE_IDempty :feature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | empty\n def_attr : id DOUBLE_DOT type_id\n | id DOUBLE_DOT type_id LEFT_ARROW expr\n def_func : ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE\n param_list : param param_list2\n | empty\n param_list2 : COMMA param param_list2\n | empty\n param : ID DOUBLE_DOT TYPE_ID\n expr_list : expr SEMICOLON\n | expr SEMICOLON expr_list\n expr : boolbool : NOT bool\n | arith MINOR arith\n | arith MINOR_EQUALS arith\n | arith EQUALS arith\n | arith\n expr : ID LEFT_ARROW exprarith : term\n | NOT bool \n | arith PLUS term\n | arith MINUS term\n term : factor\n | term TIMES factor\n | term DIVIDE factor\n factor : atom\n | LPAREN expr RPAREN\n atom : IDatom : NUMBERatom : func_callatom : NEW TYPE_ID \n atom : STRINGatom : TRUE\n | FALSE\n atom : IF expr THEN expr ELSE expr FIatom : WHILE expr LOOP expr POOLatom : LBRACE expr_list RBRACEatom : LET atr_decl_list IN expratr_decl_list : def_attr\n | def_attr COMMA atr_decl_list \n \n atom : CASE expr OF case_list ESACcase_list : id DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON\n | id DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list\n id : IDatom : ISVOID factoratom : NHANHARA factorfunc_call : factor DOT ID LPAREN arg_list RPAREN\n func_call : ID LPAREN arg_list RPARENfunc_call : factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPARENarg_list : expr arg_list2\n | empty\n arg_list2 : COMMA expr arg_list2\n | empty\n ' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,8,],[0,-1,-2,-3,]),'SEMICOLON':([3,7,12,13,18,26,38,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,82,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,137,139,144,146,147,],[5,-7,19,20,-4,-12,-5,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,109,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-14,-57,-45,-59,148,]),'TYPE_ID':([4,10,21,33,50,62,76,136,],[7,17,7,61,78,89,104,142,]),'LBRACE':([6,7,16,17,32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,89,96,106,107,109,110,113,116,119,133,140,145,],[9,-7,23,-6,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,113,56,56,56,56,56,56,56,56,56,56,56,]),'INHERITS':([6,7,],[10,-7,]),'LEFT_ARROW':([7,26,39,],[-7,32,64,]),'COMMA':([7,26,29,39,40,41,43,44,45,46,48,49,51,52,53,61,63,66,67,78,84,87,88,91,93,95,97,98,99,100,101,102,105,108,114,118,124,130,134,135,139,144,146,],[-7,-12,36,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,36,-23,-38,-41,111,-55,-56,-28,116,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,116,-46,-51,-57,-45,-59,]),'IN':([7,26,39,40,41,43,44,45,46,48,49,51,52,53,66,67,78,83,84,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,125,134,135,139,144,146,],[-7,-12,-38,-13,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,110,-49,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-50,-46,-51,-57,-45,-59,]),'ID':([9,19,20,22,23,32,36,42,47,54,55,56,57,58,59,60,64,65,68,69,70,71,72,73,74,75,96,106,107,109,110,111,112,113,116,119,120,133,140,145,148,],[15,15,15,27,15,39,27,67,39,39,39,39,85,39,67,67,39,39,67,67,67,67,67,67,67,103,67,39,39,39,39,85,128,39,39,39,132,39,39,39,128,]),'RBRACE':([9,11,14,19,20,23,24,25,31,39,41,43,44,45,46,48,49,51,52,53,66,67,78,81,87,88,91,95,97,98,99,100,101,102,105,108,109,114,118,123,124,129,134,135,139,144,146,],[-8,18,-11,-8,-8,-8,-9,-10,38,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,108,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-20,-58,-30,-21,-48,137,-46,-51,-57,-45,-59,]),'DOUBLE_DOT':([15,27,34,85,127,128,],[21,33,62,21,136,-54,]),'LPAREN':([15,32,39,42,47,54,55,56,58,59,60,64,65,67,68,69,70,71,72,73,74,96,103,106,107,109,110,113,116,119,132,133,140,145,],[22,47,65,47,47,47,47,47,47,47,47,47,47,65,47,47,47,47,47,47,47,47,119,47,47,47,47,47,47,47,140,47,47,47,]),'RPAREN':([22,28,29,30,35,37,39,41,43,44,45,46,48,49,51,52,53,61,63,65,66,67,77,78,87,88,90,91,92,93,94,95,97,98,99,100,101,102,105,108,114,115,117,118,119,124,130,131,134,135,138,139,140,143,144,146,],[-8,34,-8,-16,-15,-18,-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,-8,-8,-23,-38,105,-41,-55,-56,-17,-28,114,-8,-61,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-60,-63,-30,-8,-48,-8,139,-46,-51,-62,-57,-8,146,-45,-59,]),'NOT':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,133,140,145,],[42,42,42,42,42,42,42,42,42,96,96,96,42,42,42,42,42,42,42,42,42,42,42,]),'NUMBER':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'NEW':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'TRUE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'FALSE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'IF':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'WHILE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'LET':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,]),'CASE':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'ISVOID':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'NHANHARA':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,]),'DOT':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,104,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,75,-36,-39,-40,-42,-43,-44,-23,-38,-41,75,75,-28,-24,-25,-26,-31,-32,75,75,120,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'ARROBA':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,76,-36,-39,-40,-42,-43,-44,-23,-38,-41,76,76,-28,-24,-25,-26,-31,-32,76,76,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'TIMES':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,73,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,73,73,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'DIVIDE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,74,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,74,74,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINOR':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,68,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINOR_EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,69,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'EQUALS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,70,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'PLUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,71,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,71,71,71,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINUS':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,72,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,72,72,72,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'THEN':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,79,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,106,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'LOOP':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,80,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,107,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'OF':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,86,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,112,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'ELSE':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,121,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,133,-48,-46,-51,-57,-45,-59,]),'POOL':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,122,124,134,135,139,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,134,-48,-46,-51,-57,-45,-59,]),'FI':([39,41,43,44,45,46,48,49,51,52,53,66,67,78,87,88,91,95,97,98,99,100,101,102,105,108,114,118,124,134,135,139,141,144,146,],[-38,-22,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,144,-45,-59,]),'ESAC':([126,148,149,],[135,-52,-53,]),'RIGHT_ARROW':([142,],[145,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,8,],[0,-1,-2,-3,]),'SEMICOLON':([3,7,12,13,19,27,39,40,41,42,44,45,46,47,49,50,52,53,54,67,68,79,83,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,137,139,144,146,147,],[5,-7,20,21,-4,-12,-5,-13,-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,110,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-14,-57,-45,-59,148,]),'TYPE_ID':([4,10,22,34,51,63,77,136,],[7,18,7,62,79,90,105,142,]),'LBRACE':([6,7,17,18,33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,90,97,107,108,110,111,114,117,120,133,140,145,],[9,-7,24,-6,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,57,114,57,57,57,57,57,57,57,57,57,57,57,]),'INHERITS':([6,7,],[10,-7,]),'LEFT_ARROW':([7,27,42,],[-7,33,65,]),'COMMA':([7,27,30,40,41,42,44,45,46,47,49,50,52,53,54,62,64,67,68,79,85,88,89,92,94,96,98,99,100,101,102,103,106,109,115,119,125,130,134,135,139,144,146,],[-7,-12,37,-13,-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,37,-23,-38,-41,112,-55,-56,-28,117,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,117,-46,-51,-57,-45,-59,]),'IN':([7,27,40,41,42,44,45,46,47,49,50,52,53,54,67,68,79,84,85,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,126,134,135,139,144,146,],[-7,-12,-13,-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,111,-49,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-50,-46,-51,-57,-45,-59,]),'ID':([9,20,21,23,24,33,37,43,48,55,56,57,58,59,60,61,65,66,69,70,71,72,73,74,75,76,97,107,108,110,111,112,113,114,117,120,121,133,140,145,148,],[16,16,16,28,16,42,28,68,42,42,42,42,86,42,68,68,42,42,68,68,68,68,68,68,68,104,68,42,42,42,42,86,86,42,42,42,132,42,42,42,86,]),'RBRACE':([9,11,14,20,21,24,25,26,32,41,42,44,45,46,47,49,50,52,53,54,67,68,79,82,88,89,92,96,98,99,100,101,102,103,106,109,110,115,119,124,125,129,134,135,139,144,146,],[-8,19,-11,-8,-8,-8,-9,-10,39,-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,109,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-20,-58,-30,-21,-48,137,-46,-51,-57,-45,-59,]),'DOUBLE_DOT':([15,16,28,35,86,128,],[22,-54,34,63,-54,136,]),'LPAREN':([16,33,42,43,48,55,56,57,59,60,61,65,66,68,69,70,71,72,73,74,75,97,104,107,108,110,111,114,117,120,132,133,140,145,],[23,48,66,48,48,48,48,48,48,48,48,48,48,66,48,48,48,48,48,48,48,48,120,48,48,48,48,48,48,48,140,48,48,48,]),'RPAREN':([23,29,30,31,36,38,41,42,44,45,46,47,49,50,52,53,54,62,64,66,67,68,78,79,88,89,91,92,93,94,95,96,98,99,100,101,102,103,106,109,115,116,118,119,120,125,130,131,134,135,138,139,140,143,144,146,],[-8,35,-8,-16,-15,-18,-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-19,-8,-8,-23,-38,106,-41,-55,-56,-17,-28,115,-8,-61,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-60,-63,-30,-8,-48,-8,139,-46,-51,-62,-57,-8,146,-45,-59,]),'NOT':([33,43,48,55,56,57,59,65,66,69,70,71,97,107,108,110,111,114,117,120,133,140,145,],[43,43,43,43,43,43,43,43,43,97,97,97,43,43,43,43,43,43,43,43,43,43,43,]),'NUMBER':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'NEW':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'STRING':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'TRUE':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'FALSE':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,]),'IF':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55,]),'WHILE':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,]),'LET':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,58,]),'CASE':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,]),'ISVOID':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,]),'NHANHARA':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,]),'THEN':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,80,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,107,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'LOOP':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,81,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,108,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'OF':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,87,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,113,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINOR':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,69,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINOR_EQUALS':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,70,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'EQUALS':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,71,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'PLUS':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,72,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,72,72,72,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'MINUS':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,73,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,73,73,73,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'ELSE':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,122,125,134,135,139,144,146,],[-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,133,-48,-46,-51,-57,-45,-59,]),'POOL':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,123,125,134,135,139,144,146,],[-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,134,-48,-46,-51,-57,-45,-59,]),'DOT':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,105,106,109,115,119,125,134,135,139,144,146,],[-22,-38,-27,-29,76,-36,-39,-40,-42,-43,-44,-23,-38,-41,76,76,-28,-24,-25,-26,-31,-32,76,76,121,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'ARROBA':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,-27,-29,77,-36,-39,-40,-42,-43,-44,-23,-38,-41,77,77,-28,-24,-25,-26,-31,-32,77,77,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'TIMES':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,-27,74,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,74,74,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'DIVIDE':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,144,146,],[-22,-38,-27,75,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,75,75,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,-45,-59,]),'FI':([41,42,44,45,46,47,49,50,52,53,54,67,68,79,88,89,92,96,98,99,100,101,102,103,106,109,115,119,125,134,135,139,141,144,146,],[-22,-38,-27,-29,-33,-36,-39,-40,-42,-43,-44,-23,-38,-41,-55,-56,-28,-24,-25,-26,-31,-32,-34,-35,-37,-47,-58,-30,-48,-46,-51,-57,144,-45,-59,]),'ESAC':([127,148,149,],[135,-52,-53,]),'RIGHT_ARROW':([142,],[145,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,8,]),'def_class':([0,5,],[3,3,]),'type_id':([4,21,],[6,26,]),'feature_list':([9,19,20,23,],[11,24,25,31,]),'def_attr':([9,19,20,23,57,111,],[12,12,12,12,84,84,]),'def_func':([9,19,20,23,],[13,13,13,13,]),'empty':([9,19,20,22,23,29,63,65,93,119,130,140,],[14,14,14,30,14,37,37,94,117,94,117,94,]),'type_inherit':([10,],[16,]),'param_list':([22,],[28,]),'param':([22,36,],[29,63,]),'param_list2':([29,63,],[35,90,]),'expr':([32,47,54,55,56,58,64,65,106,107,109,110,113,116,119,133,140,145,],[40,77,79,80,82,86,91,93,121,122,82,124,129,130,93,141,93,147,]),'bool':([32,42,47,54,55,56,58,64,65,96,106,107,109,110,113,116,119,133,140,145,],[41,66,41,41,41,41,41,41,41,118,41,41,41,41,41,41,41,41,41,41,]),'arith':([32,42,47,54,55,56,58,64,65,68,69,70,96,106,107,109,110,113,116,119,133,140,145,],[43,43,43,43,43,43,43,43,43,95,97,98,43,43,43,43,43,43,43,43,43,43,43,]),'term':([32,42,47,54,55,56,58,64,65,68,69,70,71,72,96,106,107,109,110,113,116,119,133,140,145,],[44,44,44,44,44,44,44,44,44,44,44,44,99,100,44,44,44,44,44,44,44,44,44,44,44,]),'factor':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[45,45,45,45,45,45,45,87,88,45,45,45,45,45,45,45,101,102,45,45,45,45,45,45,45,45,45,45,45,]),'atom':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'func_call':([32,42,47,54,55,56,58,59,60,64,65,68,69,70,71,72,73,74,96,106,107,109,110,113,116,119,133,140,145,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'expr_list':([56,109,],[81,123,]),'atr_decl_list':([57,111,],[83,125,]),'arg_list':([65,119,140,],[92,131,143,]),'arg_list2':([93,130,],[115,138,]),'case_list':([112,148,],[126,149,]),'id_case':([112,148,],[127,127,]),} +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,8,]),'def_class':([0,5,],[3,3,]),'type_id':([4,22,],[6,27,]),'feature_list':([9,20,21,24,],[11,25,26,32,]),'def_attr':([9,20,21,24,58,112,],[12,12,12,12,85,85,]),'def_func':([9,20,21,24,],[13,13,13,13,]),'empty':([9,20,21,23,24,30,64,66,94,120,130,140,],[14,14,14,31,14,38,38,95,118,95,118,95,]),'id':([9,20,21,24,58,112,113,148,],[15,15,15,15,15,15,128,128,]),'type_inherit':([10,],[17,]),'param_list':([23,],[29,]),'param':([23,37,],[30,64,]),'param_list2':([30,64,],[36,91,]),'expr':([33,48,55,56,57,59,65,66,107,108,110,111,114,117,120,133,140,145,],[40,78,80,81,83,87,92,94,122,123,83,125,129,130,94,141,94,147,]),'bool':([33,43,48,55,56,57,59,65,66,97,107,108,110,111,114,117,120,133,140,145,],[41,67,41,41,41,41,41,41,41,119,41,41,41,41,41,41,41,41,41,41,]),'arith':([33,43,48,55,56,57,59,65,66,69,70,71,97,107,108,110,111,114,117,120,133,140,145,],[44,44,44,44,44,44,44,44,44,96,98,99,44,44,44,44,44,44,44,44,44,44,44,]),'term':([33,43,48,55,56,57,59,65,66,69,70,71,72,73,97,107,108,110,111,114,117,120,133,140,145,],[45,45,45,45,45,45,45,45,45,45,45,45,100,101,45,45,45,45,45,45,45,45,45,45,45,]),'factor':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[46,46,46,46,46,46,46,88,89,46,46,46,46,46,46,46,102,103,46,46,46,46,46,46,46,46,46,46,46,]),'atom':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'func_call':([33,43,48,55,56,57,59,60,61,65,66,69,70,71,72,73,74,75,97,107,108,110,111,114,117,120,133,140,145,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'expr_list':([57,110,],[82,124,]),'atr_decl_list':([58,112,],[84,126,]),'arg_list':([66,120,140,],[93,131,143,]),'arg_list2':([94,130,],[116,138,]),'case_list':([113,148,],[127,149,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -38,56 +38,56 @@ ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',53), ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','cool_parser.py',54), ('feature_list -> empty','feature_list',1,'p_feature_list','cool_parser.py',55), - ('def_attr -> ID DOUBLE_DOT type_id','def_attr',3,'p_def_attr','cool_parser.py',63), - ('def_attr -> ID DOUBLE_DOT type_id LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',64), - ('def_func -> ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE','def_func',9,'p_def_func','cool_parser.py',73), - ('param_list -> param param_list2','param_list',2,'p_param_list','cool_parser.py',79), - ('param_list -> empty','param_list',1,'p_param_list','cool_parser.py',80), - ('param_list2 -> COMMA param param_list2','param_list2',3,'p_param_list2','cool_parser.py',88), - ('param_list2 -> empty','param_list2',1,'p_param_list2','cool_parser.py',89), - ('param -> ID DOUBLE_DOT TYPE_ID','param',3,'p_param','cool_parser.py',97), - ('expr_list -> expr SEMICOLON','expr_list',2,'p_expr_list','cool_parser.py',102), - ('expr_list -> expr SEMICOLON expr_list','expr_list',3,'p_expr_list','cool_parser.py',103), - ('expr -> bool','expr',1,'p_expr','cool_parser.py',111), - ('bool -> NOT bool','bool',2,'p_bool','cool_parser.py',115), - ('bool -> arith MINOR arith','bool',3,'p_bool','cool_parser.py',116), - ('bool -> arith MINOR_EQUALS arith','bool',3,'p_bool','cool_parser.py',117), - ('bool -> arith EQUALS arith','bool',3,'p_bool','cool_parser.py',118), - ('bool -> arith','bool',1,'p_bool','cool_parser.py',119), - ('expr -> ID LEFT_ARROW expr','expr',3,'p_expr2','cool_parser.py',136), - ('arith -> term','arith',1,'p_arith','cool_parser.py',141), - ('arith -> NOT bool','arith',2,'p_arith','cool_parser.py',142), - ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',143), - ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',144), - ('term -> factor','term',1,'p_term','cool_parser.py',158), - ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',159), - ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',160), - ('factor -> atom','factor',1,'p_factor','cool_parser.py',172), - ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',173), - ('atom -> ID','atom',1,'p_atom1','cool_parser.py',182), - ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',187), - ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',192), - ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',196), - ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',202), - ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',207), - ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',208), - ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',221), - ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',226), - ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',231), - ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',236), - ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',241), - ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',242), - ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',251), - ('case_list -> id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',256), - ('case_list -> id_case DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',257), - ('id_case -> ID','id_case',1,'p_id_case','cool_parser.py',266), - ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',271), - ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',282), - ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',287), - ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',293), - ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',298), - ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',305), - ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',306), - ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',314), - ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',315), + ('def_attr -> id DOUBLE_DOT type_id','def_attr',3,'p_def_attr','cool_parser.py',63), + ('def_attr -> id DOUBLE_DOT type_id LEFT_ARROW expr','def_attr',5,'p_def_attr','cool_parser.py',64), + ('def_func -> ID LPAREN param_list RPAREN DOUBLE_DOT TYPE_ID LBRACE expr RBRACE','def_func',9,'p_def_func','cool_parser.py',72), + ('param_list -> param param_list2','param_list',2,'p_param_list','cool_parser.py',78), + ('param_list -> empty','param_list',1,'p_param_list','cool_parser.py',79), + ('param_list2 -> COMMA param param_list2','param_list2',3,'p_param_list2','cool_parser.py',87), + ('param_list2 -> empty','param_list2',1,'p_param_list2','cool_parser.py',88), + ('param -> ID DOUBLE_DOT TYPE_ID','param',3,'p_param','cool_parser.py',96), + ('expr_list -> expr SEMICOLON','expr_list',2,'p_expr_list','cool_parser.py',101), + ('expr_list -> expr SEMICOLON expr_list','expr_list',3,'p_expr_list','cool_parser.py',102), + ('expr -> bool','expr',1,'p_expr','cool_parser.py',110), + ('bool -> NOT bool','bool',2,'p_bool','cool_parser.py',114), + ('bool -> arith MINOR arith','bool',3,'p_bool','cool_parser.py',115), + ('bool -> arith MINOR_EQUALS arith','bool',3,'p_bool','cool_parser.py',116), + ('bool -> arith EQUALS arith','bool',3,'p_bool','cool_parser.py',117), + ('bool -> arith','bool',1,'p_bool','cool_parser.py',118), + ('expr -> ID LEFT_ARROW expr','expr',3,'p_expr2','cool_parser.py',135), + ('arith -> term','arith',1,'p_arith','cool_parser.py',140), + ('arith -> NOT bool','arith',2,'p_arith','cool_parser.py',141), + ('arith -> arith PLUS term','arith',3,'p_arith','cool_parser.py',142), + ('arith -> arith MINUS term','arith',3,'p_arith','cool_parser.py',143), + ('term -> factor','term',1,'p_term','cool_parser.py',157), + ('term -> term TIMES factor','term',3,'p_term','cool_parser.py',158), + ('term -> term DIVIDE factor','term',3,'p_term','cool_parser.py',159), + ('factor -> atom','factor',1,'p_factor','cool_parser.py',171), + ('factor -> LPAREN expr RPAREN','factor',3,'p_factor','cool_parser.py',172), + ('atom -> ID','atom',1,'p_atom1','cool_parser.py',181), + ('atom -> NUMBER','atom',1,'p_atom2','cool_parser.py',186), + ('atom -> func_call','atom',1,'p_atom3','cool_parser.py',191), + ('atom -> NEW TYPE_ID','atom',2,'p_atom4','cool_parser.py',195), + ('atom -> STRING','atom',1,'p_atomString','cool_parser.py',201), + ('atom -> TRUE','atom',1,'p_atomBool','cool_parser.py',206), + ('atom -> FALSE','atom',1,'p_atomBool','cool_parser.py',207), + ('atom -> IF expr THEN expr ELSE expr FI','atom',7,'p_atomIF','cool_parser.py',220), + ('atom -> WHILE expr LOOP expr POOL','atom',5,'p_atomCicle','cool_parser.py',225), + ('atom -> LBRACE expr_list RBRACE','atom',3,'p_atomBlock','cool_parser.py',230), + ('atom -> LET atr_decl_list IN expr','atom',4,'p_atomLet','cool_parser.py',235), + ('atr_decl_list -> def_attr','atr_decl_list',1,'p_atr_decl_list','cool_parser.py',240), + ('atr_decl_list -> def_attr COMMA atr_decl_list','atr_decl_list',3,'p_atr_decl_list','cool_parser.py',241), + ('atom -> CASE expr OF case_list ESAC','atom',5,'p_atomCase','cool_parser.py',250), + ('case_list -> id DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON','case_list',6,'p_caseList','cool_parser.py',255), + ('case_list -> id DOUBLE_DOT TYPE_ID RIGHT_ARROW expr SEMICOLON case_list','case_list',7,'p_caseList','cool_parser.py',256), + ('id -> ID','id',1,'p_id','cool_parser.py',265), + ('atom -> ISVOID factor','atom',2,'p_atomIsVoid','cool_parser.py',270), + ('atom -> NHANHARA factor','atom',2,'p_atomNhanhara','cool_parser.py',281), + ('func_call -> factor DOT ID LPAREN arg_list RPAREN','func_call',6,'p_func_call','cool_parser.py',286), + ('func_call -> ID LPAREN arg_list RPAREN','func_call',4,'p_func_call2','cool_parser.py',292), + ('func_call -> factor ARROBA TYPE_ID DOT ID LPAREN arg_list RPAREN','func_call',8,'p_func_call3','cool_parser.py',297), + ('arg_list -> expr arg_list2','arg_list',2,'p_arg_list','cool_parser.py',304), + ('arg_list -> empty','arg_list',1,'p_arg_list','cool_parser.py',305), + ('arg_list2 -> COMMA expr arg_list2','arg_list2',3,'p_arg_list2','cool_parser.py',313), + ('arg_list2 -> empty','arg_list2',1,'p_arg_list2','cool_parser.py',314), ] diff --git a/src/compiler_components/semantic/structures.py b/src/compiler_components/semantic/structures.py index 050f27008..0441d1517 100644 --- a/src/compiler_components/semantic/structures.py +++ b/src/compiler_components/semantic/structures.py @@ -13,7 +13,9 @@ class NameError(SemanticError): class AttributeError(SemanticError): pass class ParamError(Exception): - pass + pass +class ParentError(Exception): + pass ############## End Semantic Errors ############################# ############ Class members ############################### @@ -63,27 +65,33 @@ def set_parent(self, parent, pos=0): self.parent = parent parent.sons.append(self) - def get_attribute(self, name:str,pos=0): + def get_attribute(self, name:str,pos=0, parent={'value':False}): try: return next(attr for attr in self.attributes if attr.name == name) except StopIteration: if self.parent is None: raise SemanticError(f'Attribute "{name}" is not defined in {self.name}',pos) try: - return self.parent.get_attribute(name) + parent['value'] = True + return self.parent.get_attribute(name, parent=parent) except SemanticError: raise SemanticError(f'Attribute "{name}" is not defined in {self.name}',pos) def define_attribute(self, name:str, typex, pos): try: - self.get_attribute(name) + parent = {} + parent['value'] = False + self.get_attribute(name, parent = parent) except SemanticError: a = Attribute(name, typex) self.attributes.append(a) return a else: - raise SemanticError(f'Attribute "{name}" is already defined in {self.name}',pos) - + if not parent['value']: + raise SemanticError(f'SemanticError:') + else: + raise SemanticError(f'SemanticError:') + def get_method(self, name:str,line=0, col=0, own={'value':True}): try: return next(method for method in self.methods if method.name == name) @@ -222,7 +230,7 @@ def get_type(self, name:str,pos=0): try: return self.types[name] except KeyError: - raise TypeError(f'Type "{name}" is not defined.' , pos) + raise TypeError(f'TypeError:') def closest_common_antecesor(self, type1:Type, type2:Type): antecesors = [] diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index f0dd61c44..3c725f4e0 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -77,6 +77,8 @@ def visit(self, node:FuncDeclarationNode,scope:Scope): self.context.check_type(node.body.type,typex,node.line) except SemanticError as e: self.errors.append(f"({node.line},{node.column-4}) - TypeError: " + str(e)) + except ParentError as p: + self.errors.append(f"({node.line},{node.column-4}) - SemanticError: " + str(e)) @visitor.when(CaseNode) @@ -95,7 +97,7 @@ def visit(self, node:CaseNode, scope:Scope): try : typex = self.context.get_type(branches.type,branches.expr.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) + self.errors.append(f"({branches.line},{branches.column}) - TypeError: {typex} is not defined") tmpscope.define_variable(branches.id,typex,node.line) self.visit(branches.expr,tmpscope) if common_type is None: @@ -147,7 +149,7 @@ def visit(self, node:DispatchNode, scope:Scope): try: self.context.check_type(node.params[i].type,method.param_types[i],node.line) except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - TypeError: " + str(e)) except SemanticError as e: self.errors.append(f"({node.line},{node.column}) - AttributeError: dispatch undeclared method {node.f}") except ParamError as p: diff --git a/src/compiler_components/semantic/type_collector.py b/src/compiler_components/semantic/type_collector.py index 29a872c5c..28f8b8ae9 100644 --- a/src/compiler_components/semantic/type_collector.py +++ b/src/compiler_components/semantic/type_collector.py @@ -60,7 +60,7 @@ def visit(self, node): raise SemanticError('', -1) #change -1 for line number self.current_type.define_attribute(node.id, attr_type, -1) #change -1 for line number except SemanticError as e: - self.errors.append(f"({node.line},{node.column}) - SemanticError: " + str(e)) + self.errors.append(f"({node.line},{node.column}) - {str(e)} {node.id} already defined" ) @visitor.when(FuncDeclarationNode) def visit(self, node): From 0c44c31ac074d266974332db42cfcf51761c1984 Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Fri, 25 Feb 2022 17:42:17 -0500 Subject: [PATCH 51/60] Add Informe Pending fill informe --- doc/Informe | 156 + src/program.mips | 897 ++-- src/program.txt | 55 +- tests/codegen/arith.mips | 7059 ++++++++++++++++++++++++++++++++ tests/codegen/atoi.mips | 2204 ++++++++++ tests/codegen/book_list.mips | 2487 +++++++++++ tests/codegen/cells.mips | 1685 ++++++++ tests/codegen/complex.mips | 1413 +++++++ tests/codegen/fib.mips | 859 ++++ tests/codegen/graph.mips | 4993 ++++++++++++++++++++++ tests/codegen/hairyscary.mips | 1507 +++++++ tests/codegen/hello_world.mips | 703 ++++ tests/codegen/io.mips | 1552 +++++++ tests/codegen/life.mips | 4673 +++++++++++++++++++++ tests/codegen/list.mips | 1647 ++++++++ tests/codegen/new_complex.mips | 1714 ++++++++ tests/codegen/palindrome.mips | 1076 +++++ tests/codegen/primes.mips | 733 ++++ tests/codegen/print-cool.mips | 914 +++++ tests/codegen/sort-list.mips | 2614 ++++++++++++ 20 files changed, 38244 insertions(+), 697 deletions(-) create mode 100644 doc/Informe create mode 100644 tests/codegen/arith.mips create mode 100644 tests/codegen/atoi.mips create mode 100644 tests/codegen/book_list.mips create mode 100644 tests/codegen/cells.mips create mode 100644 tests/codegen/complex.mips create mode 100644 tests/codegen/fib.mips create mode 100644 tests/codegen/graph.mips create mode 100644 tests/codegen/hairyscary.mips create mode 100644 tests/codegen/hello_world.mips create mode 100644 tests/codegen/io.mips create mode 100644 tests/codegen/life.mips create mode 100644 tests/codegen/list.mips create mode 100644 tests/codegen/new_complex.mips create mode 100644 tests/codegen/palindrome.mips create mode 100644 tests/codegen/primes.mips create mode 100644 tests/codegen/print-cool.mips create mode 100644 tests/codegen/sort-list.mips diff --git a/doc/Informe b/doc/Informe new file mode 100644 index 000000000..0a0879682 --- /dev/null +++ b/doc/Informe @@ -0,0 +1,156 @@ +# Informe de Complementos de Compilación +## Datos Generales +### Autores +- Luis Alejandro Lara Rojas +- Carlos Alejandro Arrieta Montes de Oca + + +## Ejecución +Para ejecutar el proyecto se necesita tener instalado `Python` y el conjunto de dependencias listado en [requirements.txt](https://github.com/Los-Mangotes-SA/cool-compiler-2021/blob/master/requirements.txt). + +Para instalar las dependencias desde la dirección `/src`, puede utilizar: +```bash +make install +``` +Una vez estén instaladas las dependencias, puede compilar y ejecutar cualquier archivo de código cool utilizando el comando: +```bash +make main .cl +``` + +### Sobre el proyecto +Para el diseño e implementación de este proyecto se toma como base los contenidos adquiridos durante tercer año de análisis lexicográfico, sintáctico y semántico de programas en lenguaje COOL. + +Este proyecto está basado en gran parte en las implementaciones hechas durante tercer año del Lexer, Parser y Semantic Checker. + + +## Estructura del proyecto +Como se puede ver en [main.py](https://github.com/Los-Mangotes-SA/cool-compiler-2021/blob/master/src/main.py) el proyecto está estructurado en 4 componentes principales: + +1. Lexer +2. Parser +3. Semantic Checker +4. Code Generator + +Cada una de estas componentes será explicada con mayor detenimiento a continuación. + +## Lexer + +Para esta componente se utilizó el paquete de Python PLY lex. + +# FILL # +Pon aquí majomeno como funciona el Lexer +# + +## Parser +Para el parser se ha utilizado el paquete de Python PLY yacc. + +# FILL # +Pon aqui majomeno como funciona el parser. +# + + +## Semantic Checker +Esta componente se ha dividido a su vez en 3 componentes principales: +- Type Collector: encargado de recolectar los tipos. +- Type Checker: encargado de hacer chequeo de tipos. +- Type Builder: encargado de construir los tipos. + +Cada una de estas sub-componentes serán explicadas a continuación. +### Type Collector +Durante la recolección de tipos se visitan todas las declaraciones de clases, se crean los tipos asociados a ellas y se valida la correctitud de las mismas. + +**Errores detectados**: +- Herencia cíclica +- Redefinición de clases +- Nombres de clase no válidos + + +### Type checker +En esta fase se evalúa la correctitud de todas las expresiones del lenguaje y se decide el tipo estático de cada una de ellas. + +**Errores detectados**: +- Incompatibilidad de tipos +- Uso de tipos no definidos +- Uso de variables, tipos y métodos no definidos +- mal usos de `self` y `SELF_TYPE` +- mal usos del `case` + + +### Type builder +A los tipos creados en la fase anterior se le añaden todos sus atributos y métodos. Además se verifica que se cumplan los requerimientos de un programa válido de Cool q son tener una clase `Main` con su método `main`. + +**Errores detectados**: +- Mal uso de herencia +- Uso de tipos no definidos +- Problemas de nombrado de atributos y métodos +- Redefinición de atributos +- Redefinición incorrecta de métodos +- No definición de la clase `Main` o su método `main` +- Incorrecta definición del método `main` + +## Code Generator +Esta componente a su vez está constituida por 2 sub-componentes: +- COOL-CIL Converter: encargado de convertir el código COOL a código CIL. +- CIL-MIPS Converter: encargado de convertir el código CIL a código MIPS. + +### COOL-CIL Converter +El lenguaje CIL utilizado es bastante parecido al estudiado en clases. +En esta etapa del proceso de compilación, requirió especial atención la generación de las expresiones *case*. Para ello se requiere ordenar las instrucciones de tal modo que se asegure el emparejamiento del tipo de la expresión principal con el tipo más específico declarado en las ramas del *case*. + +**Errores detectados**: +- Dispatch estático o dinámico desde un objeto void +- Ejecución de un *case* sin que ocurra algún emparejamiento con alguna rama. +- División por cero +- Substring fuera de rango + +> Aunque estos errores realmente se detectan en ejecución, es en esta fase que se genera el código que permite detectarlos. + +### CIL-MIPS Converter +Para esta fase se ejecuta un recorrido por los nodos de CIL, creando las instrucciones equivalentes en MIPS. Como apoyo a la hora de generar las instrucciones en MIPS, se utilizó + + +# FILL # +Aqui habría que sutituir esta explicación por la del proyecto de nosotros. +Ya lo que hay de aquí en adelante es la explicación de otro proyecto. +# +### Estructura de los objetos en memoria. +Determinar el modelo que seguirían los objetos en la memoria fue un paso fundamental para la toma de múltiples decisiones tanto en la generación de código `CIL` como `MIPS`. Los objetos en memoria siguen el siguiente modelo: + +```| Tipo | Tamaño | Tabla de dispatch | -- Atributos -- | Marca de objeto |``` + - Tipo: Esta sección tiene tamaño 1 `palabra`, el valor aquí encontrado se interpreta como un entero e indica el tipo del objeto. + - Tamaño: Esta sección tiene tamaño 1 `palabra`, el valor aquí encontrado se interpreta como un entero e indica el tamaño en `palabras` del objeto. + - Tabla de dispatch: Esta sección tiene tamaño 1 `palabra`, el valor aquí encontrado se interpreta como una dirección de memoria e indica el inicio de la tabla de dispatch del objeto. La tabla de dispatch del objeto es un segmento de la memoria donde interpretamos cada `palabra` como la dirección a uno de los métodos del objeto. + - Atributos: Esta sección tiene tamaño **N** `palabras` donde **N** es la cantidad de atributos que conforman el objeto, cada una de las `palabras` que conforman esta sección representa el valor de un atributo del objeto. + - Marca de objeto: Esta sección tiene tamaño 1 `palabra`, es un valor usado para marcar que esta zona de la memoria corresponde a un objeto, se añadió con el objetivo de hacer menos propenso a fallos la tarea de identificar objetos en memoria en el `Garbage Collector`. + +### Definición de tipos en memoria. +Un tipo está representado por tres estructuras en la memoria: + - Una dirección a una cadena alfanumérica que representa el nombre del tipo. + - Un prototipo que es una especie de plantilla que se utiliza en la creación de los objetos. Cuando se crea un objeto este prototipo es copiado al segmento de memoria asignado al objeto. Un prototipo es un objeto válido por lo que tiene exactamente la misma estructura explicada anteriormente. El prototipo es también la solución escogida para el problema de los valores por defecto de los objetos. + - Una tabla de dispatch que como se explicó anteriormente contiene las direcciones de los métodos del objeto. +Existe una tabla de prototipos (nombres) donde se puede encontrar el prototipo (nombre) de un tipo específico, utilizando como índice el valor que representa al tipo. + +### Elección de registros. +La elección de registros fue un proceso que se decidió optimizar para disminuir la utilización de las operaciones `lw` y `sw` en `MIPS` que como se sabe, añaden una demora considerable a nuestros programas por el tiempo que tarda en realizarse un operación de escritura o lectura en la memoria. +El proceso de elección de registros se realiza para cada función y consta de los siguientes pasos: + - Separación del código en bloques básicos: + + Para obtener los bloques básicos primero se hace un recorrido por las instrucciones de la función marcando los líderes. Son considerados líderes las instrucciones de tipo `Label` y las instrucciones que tengan como predecesor un instrucción de tipo `Goto` o `Goto if`. Luego de tener marcados los líderes, se obtienen los bloques que serán los conjuntos de instrucciones consecutivas que comienzan con un líder y terminan con la primera instrucción que sea predecesor de un líder (notar que un bloque puede estar formado por una sola instrucción). + + - Creación del grafo de flujo: + + Este es un grafo dirigido que indica los caminos posibles entre los bloques básicos su elaboración es bastante sencilla: si la última instrucción de un bloque es un `Goto`, entonces se añadirá una arista desde este bloque hacia el bloque iniciado por la instrucción `Label` a la que hace referencia el `Goto`; si la última instrucción es de tipo `Goto if`, entonces se añadirán dos aristas una hacia el bloque que comienza con la instrucción `Label` a la que se hace referencia, y otra hacia el bloque que comienza con la instrucción siguiente en la función; en el caso de que la última instrucción sea de cualquier otro tipo, se colocará una sola arista desde el bloque actual hacia el bloque que comienza con la instrucción siguiente en la función. + + - Análisis de vida de las variables: + + En este procedimiento se computan cinco conjuntos para cada instrucción **I**: `succ`, `gen`, `kill`, `in` y `out`. `succ` contiene las instrucciones que se pueden ejecutar inmediatamente después de la instrucción **I**; `gen` contiene las variables de las que se necesita el valor en la instrucción **I**; `kill` contiene las variables a las que se les asigna un valor en la instrucción **I**; `in` contiene las variables que pueden estar vivas al llegar a la instrucción **I**, y `out` contiene las variables que pueden estar vivas luego de ejecutada la instrucción **I**. + + - Creación del grafo de interferencia: + + Los vértices de este grafo serán las variables que se utilizan en la función y existirá una arista entre los vértices **x** y **y**, si las variables que representan esos nodos interfieren. Dos variables interfieren si existe alguna instrucción **I** tal que **x** pertenezca al `kill` de **I** y **y** pertenezca al `out` de **I**. + + - Asignación de registros: + + Contando con el grafo de interferencia, se asignan registros a las variables de forma tal que dos variables que interfieran no se les asigne el mismo registro, esto puede verse como el problema de colorear un grafo con **N** colores siendo **N** la cantidad de registros que se tienen. Es conocido que este problema es *NP* por lo que para asignar los registros se usa una heurística muy sencilla que consiste en lo siguiente: + + Primero se va eliminando del grafo y colocando en una pila cada nodo que tenga menos de N vecinos, se nota que todos estos elementos pueden ser coloreados sin problemas. Si en algún momento no existe algún nodo con menos de N vecinos, se tomará un nodo al azar; este proceso terminará cuando no queden nodos en el grafo. Luego se va sacando cada nodo de la pila y se le asigna un registro que no esté usado por alguno de los nodos que eran vecinos de este en el momento en que se eliminó del grafo, en el caso de que existan más de un nodo posible, se le asigna el menor, en caso de que no exista nodo posible la variable no tendrá registro y su valor permanecerá en la memoria. diff --git a/src/program.mips b/src/program.mips index 26c26daa5..955e13cc2 100644 --- a/src/program.mips +++ b/src/program.mips @@ -36,45 +36,9 @@ __virtual_table__IO: .word function_out_int_at_IO .word function_in_int_at_IO .word function_in_string_at_IO - Foo_name: .asciiz "Foo" - Foo_size: .word 32 -__virtual_table__Foo: - .word function_abort_at_Object - .word function_type_name_at_Object - .word function_copy_at_Object - .word function_out_string_at_IO - .word function_out_int_at_IO - .word function_in_int_at_IO - .word function_in_string_at_IO - .word function_printh_at_Bazz - .word function_doh_at_Foo - Bar_name: .asciiz "Bar" - Bar_size: .word 48 -__virtual_table__Bar: - .word function_abort_at_Object - .word function_type_name_at_Object - .word function_copy_at_Object - .word function_out_string_at_IO - .word function_out_int_at_IO - .word function_in_int_at_IO - .word function_in_string_at_IO - .word function_printh_at_Bazz - .word function_doh_at_Foo - Razz_name: .asciiz "Razz" - Razz_size: .word 40 -__virtual_table__Razz: - .word function_abort_at_Object - .word function_type_name_at_Object - .word function_copy_at_Object - .word function_out_string_at_IO - .word function_out_int_at_IO - .word function_in_int_at_IO - .word function_in_string_at_IO - .word function_printh_at_Bazz - .word function_doh_at_Foo - Bazz_name: .asciiz "Bazz" - Bazz_size: .word 24 -__virtual_table__Bazz: + Main_name: .asciiz "Main" + Main_size: .word 16 +__virtual_table__Main: .word function_abort_at_Object .word function_type_name_at_Object .word function_copy_at_Object @@ -82,16 +46,10 @@ __virtual_table__Bazz: .word function_out_int_at_IO .word function_in_int_at_IO .word function_in_string_at_IO - .word function_printh_at_Bazz - .word function_doh_at_Bazz - Main_name: .asciiz "Main" - Main_size: .word 28 -__virtual_table__Main: - .word function_abort_at_Object - .word function_type_name_at_Object - .word function_copy_at_Object + .word function_pal_at_Main .word function_main_at_Main _empty: .asciiz "" + data_1: .asciiz "n" _error1: .asciiz "Abort called from class " _salto_para_abort: .asciiz " " @@ -155,7 +113,7 @@ main: #comienzo llamada dinamica la $a0, __virtual_table__Main - lw $a0, 12($a0) + lw $a0, 32($a0) jalr $a0 sw $a0, -12($fp) @@ -172,7 +130,7 @@ main: addiu $sp, $sp, 20 lw $fp, 0($sp) jr $ra -function_doh_at_Foo: +function_pal_at_Main: #muevo el fp al sp, pongo en sp ra y avanzo la pila @@ -182,80 +140,106 @@ function_doh_at_Foo: #muevo la pila x las variables locales - addiu $sp, $sp, -16 + addiu $sp, $sp, -72 - #init get attribute + #guardando los parametros - lw $a0, 4($fp) - lw $a0, 12($a0) - sw $a0, -4($fp) - lw $t1, -4($fp) - sw $t1, -8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 - #init get attribute + # fin guardando los parametros - lw $a0, 4($fp) - lw $a0, 12($a0) - sw $a0, -16($fp) - lw $t1, -16($fp) - li $a0, 2 - add $a0, $a0, $t1 - sw $a0, -12($fp) - #init set attribute + #comienzo llamada al constructor - lw $a0, 4($fp) - lw $t1, -12($fp) - sw $t1, 12($a0) + jal function_length_at_String + sw $a0, -8($fp) - #end set attribute + #fin llamada dinamica + + lw $t1, -8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_pal_at_Main_0 + li $t1, 1 + sw $t1, -4($fp) + j label_pal_at_Main_1 +label_pal_at_Main_0: + li $t1, 0 + sw $t1, -4($fp) +label_pal_at_Main_1: + lw $a0, -4($fp) + bne $a0, $zero, label_pal_at_Main_2 + #guardando los parametros - #retornando el valor + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 - li $a0, i + # fin guardando los parametros - #return sp, fp, ra - lw $ra, 0($fp) - addiu $sp, $sp, 28 - lw $fp, 0($sp) - jr $ra -function_Ctr_at_Foo: + #comienzo llamada al constructor - #muevo el fp al sp, pongo en sp ra y avanzo la pila + jal function_length_at_String + sw $a0, -24($fp) - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 + #fin llamada dinamica - #muevo la pila x las variables locales + lw $t1, -24($fp) + li $a0, 1 + sub $a0, $t1, $a0 + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_pal_at_Main_4 + li $t1, 1 + sw $t1, -20($fp) + j label_pal_at_Main_5 +label_pal_at_Main_4: + li $t1, 0 + sw $t1, -20($fp) +label_pal_at_Main_5: + lw $a0, -20($fp) + bne $a0, $zero, label_pal_at_Main_6 + + #guardando los parametros + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) addiu $sp, $sp, -4 - #LOAD inicia + # fin guardando los parametros - la $t1, Foo_name - lw $t2, 4($fp) - sw $t1, 0($t2) - #LOAD inicia + #comienzo llamada al constructor - lw $t1, Foo_size - lw $t2, 4($fp) - sw $t1, 4($t2) + jal function_substr_at_String + sw $a0, -40($fp) - #LOAD inicia + #fin llamada dinamica - la $t1, __virtual_table__Foo - lw $t2, 4($fp) - sw $t1, 8($t2) #guardando los parametros sw $fp, 0($sp) addiu $sp, $sp, -4 - lw $a0, 4($fp) + lw $a0, 8($fp) sw $a0, 0($sp) addiu $sp, $sp, -4 @@ -264,39 +248,67 @@ function_Ctr_at_Foo: #comienzo llamada al constructor - jal function_Init_at_Foo - sw $a0, -4($fp) + jal function_length_at_String + sw $a0, -52($fp) #fin llamada dinamica + lw $t1, -52($fp) + li $a0, 1 + blt $t1, $a0, label_pal_at_Main_8 + li $a0, 0 + j label_pal_at_Main_9 +label_pal_at_Main_8: + li $a0, 1 +label_pal_at_Main_9: + sw $a0, -48($fp) - #retornando el valor + #guardando los parametros - lw $a0, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 - #return sp, fp, ra + # fin guardando los parametros - lw $ra, 0($fp) - addiu $sp, $sp, 16 - lw $fp, 0($sp) - jr $ra -function_Init_at_Foo: - #muevo el fp al sp, pongo en sp ra y avanzo la pila + #comienzo llamada al constructor - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 + jal function_substr_at_String + sw $a0, -44($fp) - #muevo la pila x las variables locales + #fin llamada dinamica - addiu $sp, $sp, -28 + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_pal_at_Main_10 + li $t1, 0 + sw $t1, -56($fp) + j label_pal_at_Main_11 +label_pal_at_Main_10: #guardando los parametros sw $fp, 0($sp) addiu $sp, $sp, -4 - lw $a0, 4($fp) + lw $a0, 8($fp) sw $a0, 0($sp) addiu $sp, $sp, -4 @@ -305,45 +317,53 @@ function_Init_at_Foo: #comienzo llamada al constructor - jal function_Init_at_Bazz - sw $a0, -4($fp) + jal function_length_at_String + sw $a0, -72($fp) #fin llamada dinamica - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -8($fp) - sw $t1, 24($a0) - - #end set attribute - + lw $t1, -72($fp) + li $a0, 2 + blt $t1, $a0, label_pal_at_Main_12 + li $a0, 0 + j label_pal_at_Main_13 +label_pal_at_Main_12: + li $a0, 1 +label_pal_at_Main_13: + sw $a0, -68($fp) #guardando los parametros sw $fp, 0($sp) addiu $sp, $sp, -4 - lw $a0, 4($fp) + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) sw $a0, 0($sp) addiu $sp, $sp, -4 # fin guardando los parametros - lw $a0, 4($fp) - lw $a0, 8($a0) - lw $a0, 32($a0) - jalr $a0 - sw $a0, -24($fp) - lw $t1, -20($fp) - lw $a0, -24($fp) - add $a0, $a0, $t1 - sw $a0, -16($fp) + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -64($fp) + + #fin llamada dinamica + #guardando los parametros sw $fp, 0($sp) addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 lw $a0, 4($fp) sw $a0, 0($sp) addiu $sp, $sp, -4 @@ -354,32 +374,36 @@ function_Init_at_Foo: lw $a0, 8($a0) lw $a0, 28($a0) jalr $a0 - sw $a0, -28($fp) - lw $t1, -16($fp) - lw $a0, -28($fp) - add $a0, $a0, $t1 - sw $a0, -12($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -12($fp) - sw $t1, 28($a0) - - #end set attribute - + sw $a0, -60($fp) + lw $t1, -60($fp) + sw $t1, -56($fp) +label_pal_at_Main_11: + lw $t1, -56($fp) + sw $t1, -32($fp) + j label_pal_at_Main_7 +label_pal_at_Main_6: + li $t1, 1 + sw $t1, -32($fp) +label_pal_at_Main_7: + lw $t1, -32($fp) + sw $t1, -16($fp) + j label_pal_at_Main_3 +label_pal_at_Main_2: + li $t1, 1 + sw $t1, -16($fp) +label_pal_at_Main_3: #retornando el valor - lw $a0, 4($fp) + lw $a0, -16($fp) #return sp, fp, ra lw $ra, 0($fp) - addiu $sp, $sp, 40 + addiu $sp, $sp, 88 lw $fp, 0($sp) jr $ra -function_Ctr_at_Bar: +function_main_at_Main: #muevo el fp al sp, pongo en sp ra y avanzo la pila @@ -389,264 +413,87 @@ function_Ctr_at_Bar: #muevo la pila x las variables locales - addiu $sp, $sp, -4 - - #LOAD inicia - - la $t1, Bar_name - lw $t2, 4($fp) - sw $t1, 0($t2) + addiu $sp, $sp, -40 + li $t1, 1 + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -4($fp) - #LOAD inicia + #init set attribute - lw $t1, Bar_size - lw $t2, 4($fp) - sw $t1, 4($t2) + lw $a0, 4($fp) + lw $t1, -4($fp) + sw $t1, 12($a0) - #LOAD inicia + #end set attribute - la $t1, __virtual_table__Bar - lw $t2, 4($fp) - sw $t1, 8($t2) + la $t1, data_1 + sw $t1, -12($fp) #guardando los parametros sw $fp, 0($sp) addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 lw $a0, 4($fp) sw $a0, 0($sp) addiu $sp, $sp, -4 # fin guardando los parametros - - #comienzo llamada al constructor - - jal function_Init_at_Bar - sw $a0, -4($fp) - - #fin llamada dinamica - - - #retornando el valor - lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -8($fp) - #return sp, fp, ra - - lw $ra, 0($fp) - addiu $sp, $sp, 16 - lw $fp, 0($sp) - jr $ra -function_Init_at_Bar: - - #muevo el fp al sp, pongo en sp ra y avanzo la pila + #guardando los parametros - move $fp, $sp - sw $ra, 0($sp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) addiu $sp, $sp, -4 - #muevo la pila x las variables locales + # fin guardando los parametros - addiu $sp, $sp, -8 + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -20($fp) #guardando los parametros sw $fp, 0($sp) addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 lw $a0, 4($fp) sw $a0, 0($sp) addiu $sp, $sp, -4 # fin guardando los parametros - - #comienzo llamada al constructor - - jal function_Init_at_Razz - sw $a0, -4($fp) - - #fin llamada dinamica - - - #init set attribute - - lw $a0, 4($fp) - li $t1, 0 - sw $t1, 40($a0) - - #end set attribute - - la $t1, _void - sw $t1, -8($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -8($fp) - sw $t1, 44($a0) - - #end set attribute - - - #retornando el valor - - lw $a0, 4($fp) - - #return sp, fp, ra - - lw $ra, 0($fp) - addiu $sp, $sp, 20 - lw $fp, 0($sp) - jr $ra -function_Ctr_at_Razz: - - #muevo el fp al sp, pongo en sp ra y avanzo la pila - - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 - - #muevo la pila x las variables locales - - addiu $sp, $sp, -4 - - #LOAD inicia - - la $t1, Razz_name - lw $t2, 4($fp) - sw $t1, 0($t2) - - #LOAD inicia - - lw $t1, Razz_size - lw $t2, 4($fp) - sw $t1, 4($t2) - - #LOAD inicia - - la $t1, __virtual_table__Razz - lw $t2, 4($fp) - sw $t1, 8($t2) - - #guardando los parametros - - sw $fp, 0($sp) - addiu $sp, $sp, -4 - lw $a0, 4($fp) - sw $a0, 0($sp) - addiu $sp, $sp, -4 - - # fin guardando los parametros - - - #comienzo llamada al constructor - - jal function_Init_at_Razz - sw $a0, -4($fp) - - #fin llamada dinamica - - - #retornando el valor - - lw $a0, 4($fp) - - #return sp, fp, ra - - lw $ra, 0($fp) - addiu $sp, $sp, 16 - lw $fp, 0($sp) - jr $ra -function_Init_at_Razz: - - #muevo el fp al sp, pongo en sp ra y avanzo la pila - - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 - - #muevo la pila x las variables locales - - addiu $sp, $sp, -36 - - #guardando los parametros - - sw $fp, 0($sp) - addiu $sp, $sp, -4 - lw $a0, 4($fp) - sw $a0, 0($sp) - addiu $sp, $sp, -4 - - # fin guardando los parametros - - - #comienzo llamada al constructor - - jal function_Init_at_Foo - sw $a0, -4($fp) - - #fin llamada dinamica - - - #init set attribute - lw $a0, 4($fp) - lw $t1, -8($fp) - sw $t1, 32($a0) - - #end set attribute - - - #guardando los parametros - - sw $fp, 0($sp) - addiu $sp, $sp, -4 - li $a0, e - sw $a0, 0($sp) - addiu $sp, $sp, -4 - - # fin guardando los parametros - - - #comienzo llamada dinamica - - lw $a0, None lw $a0, 8($a0) - lw $a0, 32($a0) + lw $a0, 28($a0) jalr $a0 - sw $a0, -28($fp) - - #fin llamada dinamica - - lw $t1, -24($fp) - lw $a0, -28($fp) - add $a0, $a0, $t1 - sw $a0, -20($fp) + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_main_at_Main_0 + la $t1, data_1 + sw $t1, -32($fp) #guardando los parametros sw $fp, 0($sp) addiu $sp, $sp, -4 - lw $a0, 4($fp) - sw $a0, 0($sp) - addiu $sp, $sp, -4 - - # fin guardando los parametros - - lw $a0, 4($fp) - lw $a0, 8($a0) - lw $a0, 32($a0) - jalr $a0 - sw $a0, -32($fp) - lw $t1, -20($fp) lw $a0, -32($fp) - add $a0, $a0, $t1 - sw $a0, -16($fp) - - #guardando los parametros - - sw $fp, 0($sp) + sw $a0, 0($sp) addiu $sp, $sp, -4 lw $a0, 4($fp) sw $a0, 0($sp) @@ -656,56 +503,21 @@ function_Init_at_Razz: lw $a0, 4($fp) lw $a0, 8($a0) - lw $a0, 28($a0) - jalr $a0 - sw $a0, -36($fp) - lw $t1, -16($fp) - lw $a0, -36($fp) - add $a0, $a0, $t1 - sw $a0, -12($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -12($fp) - sw $t1, 36($a0) - - #end set attribute - - - #retornando el valor - - lw $a0, 4($fp) - - #return sp, fp, ra - - lw $ra, 0($fp) - addiu $sp, $sp, 48 - lw $fp, 0($sp) - jr $ra -function_printh_at_Bazz: - - #muevo el fp al sp, pongo en sp ra y avanzo la pila - - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 - - #muevo la pila x las variables locales - - addiu $sp, $sp, -8 - - #init get attribute - - lw $a0, 4($fp) lw $a0, 12($a0) - sw $a0, -8($fp) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -28($fp) + sw $t1, -24($fp) + j label_main_at_Main_1 +label_main_at_Main_0: + la $t1, data_1 + sw $t1, -40($fp) #guardando los parametros sw $fp, 0($sp) addiu $sp, $sp, -4 - lw $a0, -8($fp) + lw $a0, -40($fp) sw $a0, 0($sp) addiu $sp, $sp, -4 lw $a0, 4($fp) @@ -716,220 +528,21 @@ function_printh_at_Bazz: lw $a0, 4($fp) lw $a0, 8($a0) - lw $a0, 16($a0) - jalr $a0 - sw $a0, -4($fp) - - #retornando el valor - - li $a0, 0 - - #return sp, fp, ra - - lw $ra, 0($fp) - addiu $sp, $sp, 20 - lw $fp, 0($sp) - jr $ra -function_doh_at_Bazz: - - #muevo el fp al sp, pongo en sp ra y avanzo la pila - - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 - - #muevo la pila x las variables locales - - addiu $sp, $sp, -16 - - #init get attribute - - lw $a0, 4($fp) lw $a0, 12($a0) - sw $a0, -4($fp) - lw $t1, -4($fp) - sw $t1, -8($fp) - - #init get attribute - - lw $a0, 4($fp) - lw $a0, 12($a0) - sw $a0, -16($fp) - lw $t1, -16($fp) - li $a0, 1 - add $a0, $a0, $t1 - sw $a0, -12($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -12($fp) - sw $t1, 12($a0) - - #end set attribute - - - #retornando el valor - - li $a0, i - - #return sp, fp, ra - - lw $ra, 0($fp) - addiu $sp, $sp, 28 - lw $fp, 0($sp) - jr $ra -function_Ctr_at_Bazz: - - #muevo el fp al sp, pongo en sp ra y avanzo la pila - - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 - - #muevo la pila x las variables locales - - addiu $sp, $sp, -4 - - #LOAD inicia - - la $t1, Bazz_name - lw $t2, 4($fp) - sw $t1, 0($t2) - - #LOAD inicia - - lw $t1, Bazz_size - lw $t2, 4($fp) - sw $t1, 4($t2) - - #LOAD inicia - - la $t1, __virtual_table__Bazz - lw $t2, 4($fp) - sw $t1, 8($t2) - - #guardando los parametros - - sw $fp, 0($sp) - addiu $sp, $sp, -4 - lw $a0, 4($fp) - sw $a0, 0($sp) - addiu $sp, $sp, -4 - - # fin guardando los parametros - - - #comienzo llamada al constructor - - jal function_Init_at_Bazz - sw $a0, -4($fp) - - #fin llamada dinamica - - - #retornando el valor - - lw $a0, 4($fp) - - #return sp, fp, ra - - lw $ra, 0($fp) - addiu $sp, $sp, 16 - lw $fp, 0($sp) - jr $ra -function_Init_at_Bazz: - - #muevo el fp al sp, pongo en sp ra y avanzo la pila - - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 - - #muevo la pila x las variables locales - - addiu $sp, $sp, -12 - - #guardando los parametros - - sw $fp, 0($sp) - addiu $sp, $sp, -4 - lw $a0, 4($fp) - sw $a0, 0($sp) - addiu $sp, $sp, -4 - - # fin guardando los parametros - - - #comienzo llamada al constructor - - jal function_Init_at_IO - sw $a0, -4($fp) - - #fin llamada dinamica - - - #init set attribute - - lw $a0, 4($fp) - li $t1, 0 - sw $t1, 12($a0) - - #end set attribute - - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -8($fp) - sw $t1, 16($a0) - - #end set attribute - - la $t1, _void - sw $t1, -12($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -12($fp) - sw $t1, 20($a0) - - #end set attribute - - - #retornando el valor - - lw $a0, 4($fp) - - #return sp, fp, ra - - lw $ra, 0($fp) - addiu $sp, $sp, 24 - lw $fp, 0($sp) - jr $ra -function_main_at_Main: - - #muevo el fp al sp, pongo en sp ra y avanzo la pila - - move $fp, $sp - sw $ra, 0($sp) - addiu $sp, $sp, -4 - - #muevo la pila x las variables locales - - addiu $sp, $sp, -4 - la $t1, _empty - sw $t1, -4($fp) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -24($fp) +label_main_at_Main_1: #retornando el valor - lw $a0, -4($fp) + lw $a0, -24($fp) #return sp, fp, ra lw $ra, 0($fp) - addiu $sp, $sp, 16 + addiu $sp, $sp, 52 lw $fp, 0($sp) jr $ra function_Ctr_at_Main: @@ -1001,7 +614,7 @@ function_Init_at_Main: #muevo la pila x las variables locales - addiu $sp, $sp, -20 + addiu $sp, $sp, -4 #guardando los parametros @@ -1016,55 +629,11 @@ function_Init_at_Main: #comienzo llamada al constructor - jal function_Init_at_Object + jal function_Init_at_IO sw $a0, -4($fp) #fin llamada dinamica - la $t1, _void - sw $t1, -8($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -8($fp) - sw $t1, 12($a0) - - #end set attribute - - la $t1, _void - sw $t1, -12($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -12($fp) - sw $t1, 16($a0) - - #end set attribute - - la $t1, _void - sw $t1, -16($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -16($fp) - sw $t1, 20($a0) - - #end set attribute - - la $t1, _void - sw $t1, -20($fp) - - #init set attribute - - lw $a0, 4($fp) - lw $t1, -20($fp) - sw $t1, 24($a0) - - #end set attribute - #retornando el valor @@ -1073,7 +642,7 @@ function_Init_at_Main: #return sp, fp, ra lw $ra, 0($fp) - addiu $sp, $sp, 32 + addiu $sp, $sp, 16 lw $fp, 0($sp) jr $ra diff --git a/src/program.txt b/src/program.txt index 66a0557e1..7f24789f9 100644 --- a/src/program.txt +++ b/src/program.txt @@ -1,36 +1,25 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - class Main inherits IO { - main(): IO { out_string("Hello World!")}; + pal(s : String) : Bool { + if s.length() = 0 + then true + else if s.length() = 1 + then true + else if s.substr(0, 1) = s.substr(s.length() - 1, 1) + then pal(s.substr(1, s.length() -2)) + else false + fi fi fi + }; + + i : Int; - test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); + main() : IO { + { + i <- ~1; + out_string("enter a string\n"); + if pal(in_string()) + then out_string("that was a palindrome\n") + else out_string("that was not a palindrome\n") + fi; + } + }; }; diff --git a/tests/codegen/arith.mips b/tests/codegen/arith.mips new file mode 100644 index 000000000..ade506513 --- /dev/null +++ b/tests/codegen/arith.mips @@ -0,0 +1,7059 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + A_name: .asciiz "A" + A_size: .word 16 +__virtual_table__A: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_value_at_A + .word function_set_var_at_A + .word function_method1_at_A + .word function_method2_at_A + .word function_method3_at_A + .word function_method4_at_A + .word function_method5_at_A + B_name: .asciiz "B" + B_size: .word 16 +__virtual_table__B: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_value_at_A + .word function_set_var_at_A + .word function_method1_at_A + .word function_method2_at_A + .word function_method3_at_A + .word function_method4_at_A + .word function_method5_at_B + C_name: .asciiz "C" + C_size: .word 16 +__virtual_table__C: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_value_at_A + .word function_set_var_at_A + .word function_method1_at_A + .word function_method2_at_A + .word function_method3_at_A + .word function_method4_at_A + .word function_method5_at_C + .word function_method6_at_C + D_name: .asciiz "D" + D_size: .word 16 +__virtual_table__D: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_value_at_A + .word function_set_var_at_A + .word function_method1_at_A + .word function_method2_at_A + .word function_method3_at_A + .word function_method4_at_A + .word function_method5_at_B + .word function_method7_at_D + E_name: .asciiz "E" + E_size: .word 16 +__virtual_table__E: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_value_at_A + .word function_set_var_at_A + .word function_method1_at_A + .word function_method2_at_A + .word function_method3_at_A + .word function_method4_at_A + .word function_method5_at_B + .word function_method7_at_D + .word function_method6_at_E + A2I_name: .asciiz "A2I" + A2I_size: .word 12 +__virtual_table__A2I: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_c2i_at_A2I + .word function_i2c_at_A2I + .word function_a2i_at_A2I + .word function_a2i_aux_at_A2I + .word function_i2a_at_A2I + .word function_i2a_aux_at_A2I + Main_name: .asciiz "Main" + Main_size: .word 28 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_menu_at_Main + .word function_prompt_at_Main + .word function_get_int_at_Main + .word function_is_even_at_Main + .word function_class_type_at_Main + .word function_print_at_Main + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n " + data_2: .asciiz "n" + data_3: .asciiz " " + data_4: .asciiz " n" + data_5: .asciiz " nn" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 52($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_value_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_set_var_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_method1_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_method2_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + li $t1, 0 + sw $t1, -4($fp) + lw $t1, 8($fp) + lw $a0, 12($fp) + add $a0, $a0, $t1 + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, B_size + syscall + sw $v0, -16($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_B + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_method3_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + li $t1, 0 + sw $t1, -4($fp) + lw $t1, 8($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -8($fp) + lw $t1, -8($fp) + sw $t1, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, C_size + syscall + sw $v0, -16($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_C + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_method4_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -44 + li $a0, [] + bne $a0, $zero, label_method4_at_A_0 + li $t1, 0 + sw $t1, -8($fp) + lw $t1, 12($fp) + lw $a0, 8($fp) + blt $t1, $a0, label_method4_at_A_2 + li $a0, 0 + j label_method4_at_A_3 +label_method4_at_A_2: + li $a0, 1 +label_method4_at_A_3: + sw $a0, -12($fp) + lw $t1, -12($fp) + sw $t1, -8($fp) + + #init allocate + + li $v0, 9 + lw $a0, D_size + syscall + sw $v0, -20($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_D + sw $a0, -24($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + lw $t1, -16($fp) + sw $t1, -4($fp) + j label_method4_at_A_1 +label_method4_at_A_0: + li $t1, 0 + sw $t1, -28($fp) + lw $t1, 8($fp) + lw $a0, 12($fp) + blt $t1, $a0, label_method4_at_A_4 + li $a0, 0 + j label_method4_at_A_5 +label_method4_at_A_4: + li $a0, 1 +label_method4_at_A_5: + sw $a0, -32($fp) + lw $t1, -32($fp) + sw $t1, -28($fp) + + #init allocate + + li $v0, 9 + lw $a0, D_size + syscall + sw $v0, -40($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_D + sw $a0, -44($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -40($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -36($fp) + + #fin llamada dinamica + + lw $t1, -36($fp) + sw $t1, -4($fp) +label_method4_at_A_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 64 + lw $fp, 0($sp) + jr $ra +function_method5_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -36 + li $t1, 1 + sw $t1, -4($fp) + li $t1, 1 + sw $t1, -8($fp) +label_method5_at_A_0: + li $t1, y + lw $a0, 8($fp) + ble $t1, $a0, label_method5_at_A_3 + li $a0, 0 + j label_method5_at_A_4 +label_method5_at_A_3: + li $a0, 1 +label_method5_at_A_4: + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_method5_at_A_1 + j label_method5_at_A_2 +label_method5_at_A_1: + li $t1, x + li $a0, y + mul $a0 $t1 $a0 + sw $a0, -16($fp) + lw $t1, -16($fp) + sw $t1, -4($fp) + li $t1, y + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -20($fp) + lw $t1, -20($fp) + sw $t1, -8($fp) + j label_method5_at_A_0 +label_method5_at_A_2: + la $t1, _void + sw $t1, -24($fp) + + #init allocate + + li $v0, 9 + lw $a0, E_size + syscall + sw $v0, -32($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_E + sw $a0, -36($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -32($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -28($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 52 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, A_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, A_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__A + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_A + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_method5_at_B: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + li $t1, 0 + sw $t1, -4($fp) + lw $t1, 8($fp) + lw $a0, 8($fp) + mul $a0 $t1 $a0 + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, E_size + syscall + sw $v0, -16($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_E + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_B: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, B_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, B_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__B + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_B + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_B: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_A + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_method6_at_C: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + li $t1, 0 + sw $t1, -4($fp) + lw $t1, 8($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -8($fp) + lw $t1, -8($fp) + sw $t1, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, A_size + syscall + sw $v0, -16($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_method5_at_C: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -24 + li $t1, 0 + sw $t1, -4($fp) + lw $t1, 8($fp) + lw $a0, 8($fp) + mul $a0 $t1 $a0 + sw $a0, -12($fp) + lw $t1, -12($fp) + lw $a0, 8($fp) + mul $a0 $t1 $a0 + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, E_size + syscall + sw $v0, -20($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_E + sw $a0, -24($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_C: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, C_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, C_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__C + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_C + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_C: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_B + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_method7_at_D: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -60 + lw $t1, 8($fp) + sw $t1, -4($fp) + li $a0, [] + bne $a0, $zero, label_method7_at_D_0 + li $t1, 0 + li $a0, x + sub $a0, $t1, $a0 + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_method7_at_D_2 + li $t1, 1 + sw $t1, -12($fp) + j label_method7_at_D_3 +label_method7_at_D_2: + li $t1, 0 + sw $t1, -12($fp) +label_method7_at_D_3: + lw $a0, -12($fp) + bne $a0, $zero, label_method7_at_D_4 + li $t1, 1 + li $a0, x + sub $a0, $t1, $a0 + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_method7_at_D_6 + li $t1, 1 + sw $t1, -24($fp) + j label_method7_at_D_7 +label_method7_at_D_6: + li $t1, 0 + sw $t1, -24($fp) +label_method7_at_D_7: + lw $a0, -24($fp) + bne $a0, $zero, label_method7_at_D_8 + li $t1, 2 + li $a0, x + sub $a0, $t1, $a0 + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_method7_at_D_10 + li $t1, 1 + sw $t1, -36($fp) + j label_method7_at_D_11 +label_method7_at_D_10: + li $t1, 0 + sw $t1, -36($fp) +label_method7_at_D_11: + lw $a0, -36($fp) + bne $a0, $zero, label_method7_at_D_12 + li $t1, x + li $a0, 3 + blt $t1, $a0, label_method7_at_D_14 + li $a0, 0 + j label_method7_at_D_15 +label_method7_at_D_14: + li $a0, 1 +label_method7_at_D_15: + sw $a0, -52($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -52($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -48($fp) + lw $t1, -48($fp) + sw $t1, -44($fp) + j label_method7_at_D_13 +label_method7_at_D_12: + li $t1, 0 + sw $t1, -44($fp) +label_method7_at_D_13: + lw $t1, -44($fp) + sw $t1, -32($fp) + j label_method7_at_D_9 +label_method7_at_D_8: + li $t1, 0 + sw $t1, -32($fp) +label_method7_at_D_9: + lw $t1, -32($fp) + sw $t1, -20($fp) + j label_method7_at_D_5 +label_method7_at_D_4: + li $t1, 1 + sw $t1, -20($fp) +label_method7_at_D_5: + lw $t1, -20($fp) + sw $t1, -8($fp) + j label_method7_at_D_1 +label_method7_at_D_0: + li $t1, x + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -60($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -56($fp) + lw $t1, -56($fp) + sw $t1, -8($fp) +label_method7_at_D_1: + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 76 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_D: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, D_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, D_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__D + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_D + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_D: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_B + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_method6_at_E: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + li $t1, 0 + sw $t1, -4($fp) + lw $t1, 8($fp) + li $a0, 8 + div $a0, $t1, $a0 + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, A_size + syscall + sw $v0, -16($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_E: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, E_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, E_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__E + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_E + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_E: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_D + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_c2i_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -124 + la $t1, _empty + sw $t1, -8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -4($fp) + lw $a0, -4($fp) + bne $a0, $zero, label_c2i_at_A2I_0 + la $t1, _empty + sw $t1, -20($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_c2i_at_A2I_2 + la $t1, _empty + sw $t1, -32($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_c2i_at_A2I_4 + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_c2i_at_A2I_6 + la $t1, _empty + sw $t1, -56($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -52($fp) + lw $a0, -52($fp) + bne $a0, $zero, label_c2i_at_A2I_8 + la $t1, _empty + sw $t1, -68($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -64($fp) + lw $a0, -64($fp) + bne $a0, $zero, label_c2i_at_A2I_10 + la $t1, _empty + sw $t1, -80($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -76($fp) + lw $a0, -76($fp) + bne $a0, $zero, label_c2i_at_A2I_12 + la $t1, _empty + sw $t1, -92($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -92($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -88($fp) + lw $a0, -88($fp) + bne $a0, $zero, label_c2i_at_A2I_14 + la $t1, _empty + sw $t1, -104($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -104($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -100($fp) + lw $a0, -100($fp) + bne $a0, $zero, label_c2i_at_A2I_16 + la $t1, _empty + sw $t1, -116($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -116($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -112($fp) + lw $a0, -112($fp) + bne $a0, $zero, label_c2i_at_A2I_18 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -124($fp) + li $t1, 0 + sw $t1, -120($fp) + j label_c2i_at_A2I_19 +label_c2i_at_A2I_18: + li $t1, 9 + sw $t1, -120($fp) +label_c2i_at_A2I_19: + lw $t1, -120($fp) + sw $t1, -108($fp) + j label_c2i_at_A2I_17 +label_c2i_at_A2I_16: + li $t1, 8 + sw $t1, -108($fp) +label_c2i_at_A2I_17: + lw $t1, -108($fp) + sw $t1, -96($fp) + j label_c2i_at_A2I_15 +label_c2i_at_A2I_14: + li $t1, 7 + sw $t1, -96($fp) +label_c2i_at_A2I_15: + lw $t1, -96($fp) + sw $t1, -84($fp) + j label_c2i_at_A2I_13 +label_c2i_at_A2I_12: + li $t1, 6 + sw $t1, -84($fp) +label_c2i_at_A2I_13: + lw $t1, -84($fp) + sw $t1, -72($fp) + j label_c2i_at_A2I_11 +label_c2i_at_A2I_10: + li $t1, 5 + sw $t1, -72($fp) +label_c2i_at_A2I_11: + lw $t1, -72($fp) + sw $t1, -60($fp) + j label_c2i_at_A2I_9 +label_c2i_at_A2I_8: + li $t1, 4 + sw $t1, -60($fp) +label_c2i_at_A2I_9: + lw $t1, -60($fp) + sw $t1, -48($fp) + j label_c2i_at_A2I_7 +label_c2i_at_A2I_6: + li $t1, 3 + sw $t1, -48($fp) +label_c2i_at_A2I_7: + lw $t1, -48($fp) + sw $t1, -36($fp) + j label_c2i_at_A2I_5 +label_c2i_at_A2I_4: + li $t1, 2 + sw $t1, -36($fp) +label_c2i_at_A2I_5: + lw $t1, -36($fp) + sw $t1, -24($fp) + j label_c2i_at_A2I_3 +label_c2i_at_A2I_2: + li $t1, 1 + sw $t1, -24($fp) +label_c2i_at_A2I_3: + lw $t1, -24($fp) + sw $t1, -12($fp) + j label_c2i_at_A2I_1 +label_c2i_at_A2I_0: + li $t1, 0 + sw $t1, -12($fp) +label_c2i_at_A2I_1: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 140 + lw $fp, 0($sp) + jr $ra +function_i2c_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -168 + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -8($fp) + lw $a0, -8($fp) + bne $a0, $zero, label_i2c_at_A2I_0 + li $t1, 1 + sw $t1, -4($fp) + j label_i2c_at_A2I_1 +label_i2c_at_A2I_0: + li $t1, 0 + sw $t1, -4($fp) +label_i2c_at_A2I_1: + lw $a0, -4($fp) + bne $a0, $zero, label_i2c_at_A2I_2 + lw $t1, 8($fp) + li $a0, 1 + sub $a0, $t1, $a0 + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_i2c_at_A2I_4 + li $t1, 1 + sw $t1, -16($fp) + j label_i2c_at_A2I_5 +label_i2c_at_A2I_4: + li $t1, 0 + sw $t1, -16($fp) +label_i2c_at_A2I_5: + lw $a0, -16($fp) + bne $a0, $zero, label_i2c_at_A2I_6 + lw $t1, 8($fp) + li $a0, 2 + sub $a0, $t1, $a0 + sw $a0, -32($fp) + lw $a0, -32($fp) + bne $a0, $zero, label_i2c_at_A2I_8 + li $t1, 1 + sw $t1, -28($fp) + j label_i2c_at_A2I_9 +label_i2c_at_A2I_8: + li $t1, 0 + sw $t1, -28($fp) +label_i2c_at_A2I_9: + lw $a0, -28($fp) + bne $a0, $zero, label_i2c_at_A2I_10 + lw $t1, 8($fp) + li $a0, 3 + sub $a0, $t1, $a0 + sw $a0, -44($fp) + lw $a0, -44($fp) + bne $a0, $zero, label_i2c_at_A2I_12 + li $t1, 1 + sw $t1, -40($fp) + j label_i2c_at_A2I_13 +label_i2c_at_A2I_12: + li $t1, 0 + sw $t1, -40($fp) +label_i2c_at_A2I_13: + lw $a0, -40($fp) + bne $a0, $zero, label_i2c_at_A2I_14 + lw $t1, 8($fp) + li $a0, 4 + sub $a0, $t1, $a0 + sw $a0, -56($fp) + lw $a0, -56($fp) + bne $a0, $zero, label_i2c_at_A2I_16 + li $t1, 1 + sw $t1, -52($fp) + j label_i2c_at_A2I_17 +label_i2c_at_A2I_16: + li $t1, 0 + sw $t1, -52($fp) +label_i2c_at_A2I_17: + lw $a0, -52($fp) + bne $a0, $zero, label_i2c_at_A2I_18 + lw $t1, 8($fp) + li $a0, 5 + sub $a0, $t1, $a0 + sw $a0, -68($fp) + lw $a0, -68($fp) + bne $a0, $zero, label_i2c_at_A2I_20 + li $t1, 1 + sw $t1, -64($fp) + j label_i2c_at_A2I_21 +label_i2c_at_A2I_20: + li $t1, 0 + sw $t1, -64($fp) +label_i2c_at_A2I_21: + lw $a0, -64($fp) + bne $a0, $zero, label_i2c_at_A2I_22 + lw $t1, 8($fp) + li $a0, 6 + sub $a0, $t1, $a0 + sw $a0, -80($fp) + lw $a0, -80($fp) + bne $a0, $zero, label_i2c_at_A2I_24 + li $t1, 1 + sw $t1, -76($fp) + j label_i2c_at_A2I_25 +label_i2c_at_A2I_24: + li $t1, 0 + sw $t1, -76($fp) +label_i2c_at_A2I_25: + lw $a0, -76($fp) + bne $a0, $zero, label_i2c_at_A2I_26 + lw $t1, 8($fp) + li $a0, 7 + sub $a0, $t1, $a0 + sw $a0, -92($fp) + lw $a0, -92($fp) + bne $a0, $zero, label_i2c_at_A2I_28 + li $t1, 1 + sw $t1, -88($fp) + j label_i2c_at_A2I_29 +label_i2c_at_A2I_28: + li $t1, 0 + sw $t1, -88($fp) +label_i2c_at_A2I_29: + lw $a0, -88($fp) + bne $a0, $zero, label_i2c_at_A2I_30 + lw $t1, 8($fp) + li $a0, 8 + sub $a0, $t1, $a0 + sw $a0, -104($fp) + lw $a0, -104($fp) + bne $a0, $zero, label_i2c_at_A2I_32 + li $t1, 1 + sw $t1, -100($fp) + j label_i2c_at_A2I_33 +label_i2c_at_A2I_32: + li $t1, 0 + sw $t1, -100($fp) +label_i2c_at_A2I_33: + lw $a0, -100($fp) + bne $a0, $zero, label_i2c_at_A2I_34 + lw $t1, 8($fp) + li $a0, 9 + sub $a0, $t1, $a0 + sw $a0, -116($fp) + lw $a0, -116($fp) + bne $a0, $zero, label_i2c_at_A2I_36 + li $t1, 1 + sw $t1, -112($fp) + j label_i2c_at_A2I_37 +label_i2c_at_A2I_36: + li $t1, 0 + sw $t1, -112($fp) +label_i2c_at_A2I_37: + lw $a0, -112($fp) + bne $a0, $zero, label_i2c_at_A2I_38 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -124($fp) + la $t1, _empty + sw $t1, -128($fp) + lw $t1, -128($fp) + sw $t1, -120($fp) + j label_i2c_at_A2I_39 +label_i2c_at_A2I_38: + la $t1, _empty + sw $t1, -132($fp) + lw $t1, -132($fp) + sw $t1, -120($fp) +label_i2c_at_A2I_39: + lw $t1, -120($fp) + sw $t1, -108($fp) + j label_i2c_at_A2I_35 +label_i2c_at_A2I_34: + la $t1, _empty + sw $t1, -136($fp) + lw $t1, -136($fp) + sw $t1, -108($fp) +label_i2c_at_A2I_35: + lw $t1, -108($fp) + sw $t1, -96($fp) + j label_i2c_at_A2I_31 +label_i2c_at_A2I_30: + la $t1, _empty + sw $t1, -140($fp) + lw $t1, -140($fp) + sw $t1, -96($fp) +label_i2c_at_A2I_31: + lw $t1, -96($fp) + sw $t1, -84($fp) + j label_i2c_at_A2I_27 +label_i2c_at_A2I_26: + la $t1, _empty + sw $t1, -144($fp) + lw $t1, -144($fp) + sw $t1, -84($fp) +label_i2c_at_A2I_27: + lw $t1, -84($fp) + sw $t1, -72($fp) + j label_i2c_at_A2I_23 +label_i2c_at_A2I_22: + la $t1, _empty + sw $t1, -148($fp) + lw $t1, -148($fp) + sw $t1, -72($fp) +label_i2c_at_A2I_23: + lw $t1, -72($fp) + sw $t1, -60($fp) + j label_i2c_at_A2I_19 +label_i2c_at_A2I_18: + la $t1, _empty + sw $t1, -152($fp) + lw $t1, -152($fp) + sw $t1, -60($fp) +label_i2c_at_A2I_19: + lw $t1, -60($fp) + sw $t1, -48($fp) + j label_i2c_at_A2I_15 +label_i2c_at_A2I_14: + la $t1, _empty + sw $t1, -156($fp) + lw $t1, -156($fp) + sw $t1, -48($fp) +label_i2c_at_A2I_15: + lw $t1, -48($fp) + sw $t1, -36($fp) + j label_i2c_at_A2I_11 +label_i2c_at_A2I_10: + la $t1, _empty + sw $t1, -160($fp) + lw $t1, -160($fp) + sw $t1, -36($fp) +label_i2c_at_A2I_11: + lw $t1, -36($fp) + sw $t1, -24($fp) + j label_i2c_at_A2I_7 +label_i2c_at_A2I_6: + la $t1, _empty + sw $t1, -164($fp) + lw $t1, -164($fp) + sw $t1, -24($fp) +label_i2c_at_A2I_7: + lw $t1, -24($fp) + sw $t1, -12($fp) + j label_i2c_at_A2I_3 +label_i2c_at_A2I_2: + la $t1, _empty + sw $t1, -168($fp) + lw $t1, -168($fp) + sw $t1, -12($fp) +label_i2c_at_A2I_3: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 184 + lw $fp, 0($sp) + jr $ra +function_a2i_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -88 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_a2i_at_A2I_0 + li $t1, 1 + sw $t1, -4($fp) + j label_a2i_at_A2I_1 +label_a2i_at_A2I_0: + li $t1, 0 + sw $t1, -4($fp) +label_a2i_at_A2I_1: + lw $a0, -4($fp) + bne $a0, $zero, label_a2i_at_A2I_2 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -24($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -28($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_a2i_at_A2I_4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -40($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_a2i_at_A2I_6 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -52($fp) + lw $t1, -52($fp) + sw $t1, -48($fp) + j label_a2i_at_A2I_7 +label_a2i_at_A2I_6: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -68($fp) + + #fin llamada dinamica + + lw $t1, -68($fp) + li $a0, 1 + blt $t1, $a0, label_a2i_at_A2I_8 + li $a0, 0 + j label_a2i_at_A2I_9 +label_a2i_at_A2I_8: + li $a0, 1 +label_a2i_at_A2I_9: + sw $a0, -64($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -60($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -56($fp) + lw $t1, -56($fp) + sw $t1, -48($fp) +label_a2i_at_A2I_7: + lw $t1, -48($fp) + sw $t1, -32($fp) + j label_a2i_at_A2I_5 +label_a2i_at_A2I_4: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -88($fp) + + #fin llamada dinamica + + lw $t1, -88($fp) + li $a0, 1 + blt $t1, $a0, label_a2i_at_A2I_10 + li $a0, 0 + j label_a2i_at_A2I_11 +label_a2i_at_A2I_10: + li $a0, 1 +label_a2i_at_A2I_11: + sw $a0, -84($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -84($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -80($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -76($fp) + lw $t1, -76($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -72($fp) + lw $t1, -72($fp) + sw $t1, -32($fp) +label_a2i_at_A2I_5: + lw $t1, -32($fp) + sw $t1, -16($fp) + j label_a2i_at_A2I_3 +label_a2i_at_A2I_2: + li $t1, 0 + sw $t1, -16($fp) +label_a2i_at_A2I_3: + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 104 + lw $fp, 0($sp) + jr $ra +function_a2i_aux_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + li $t1, 0 + sw $t1, -4($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + sw $t1, -12($fp) + li $t1, 0 + sw $t1, -16($fp) +label_a2i_aux_at_A2I_0: + li $a0, [] + bne $a0, $zero, label_a2i_aux_at_A2I_1 + j label_a2i_aux_at_A2I_2 +label_a2i_aux_at_A2I_1: + li $t1, int + li $a0, 10 + mul $a0 $t1 $a0 + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, i + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -32($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -24($fp) + lw $a0, -28($fp) + add $a0, $a0, $t1 + sw $a0, -20($fp) + lw $t1, -20($fp) + sw $t1, -4($fp) + li $t1, i + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -16($fp) + j label_a2i_aux_at_A2I_0 +label_a2i_aux_at_A2I_2: + la $t1, _void + sw $t1, -40($fp) + + #retornando el valor + + li $a0, int + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 56 + lw $fp, 0($sp) + jr $ra +function_i2a_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -44 + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -8($fp) + lw $a0, -8($fp) + bne $a0, $zero, label_i2a_at_A2I_0 + li $t1, 1 + sw $t1, -4($fp) + j label_i2a_at_A2I_1 +label_i2a_at_A2I_0: + li $t1, 0 + sw $t1, -4($fp) +label_i2a_at_A2I_1: + lw $a0, -4($fp) + bne $a0, $zero, label_i2a_at_A2I_2 + li $a0, [] + bne $a0, $zero, label_i2a_at_A2I_4 + la $t1, _empty + sw $t1, -24($fp) + li $t1, 1 + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -36($fp) + lw $t1, 8($fp) + lw $a0, -36($fp) + mul $a0 $t1 $a0 + sw $a0, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_concat_at_String + sw $a0, -20($fp) + + #fin llamada dinamica + + lw $t1, -20($fp) + sw $t1, -16($fp) + j label_i2a_at_A2I_5 +label_i2a_at_A2I_4: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -40($fp) + lw $t1, -40($fp) + sw $t1, -16($fp) +label_i2a_at_A2I_5: + lw $t1, -16($fp) + sw $t1, -12($fp) + j label_i2a_at_A2I_3 +label_i2a_at_A2I_2: + la $t1, _empty + sw $t1, -44($fp) + lw $t1, -44($fp) + sw $t1, -12($fp) +label_i2a_at_A2I_3: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_i2a_aux_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -44 + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -8($fp) + lw $a0, -8($fp) + bne $a0, $zero, label_i2a_aux_at_A2I_0 + li $t1, 1 + sw $t1, -4($fp) + j label_i2a_aux_at_A2I_1 +label_i2a_aux_at_A2I_0: + li $t1, 0 + sw $t1, -4($fp) +label_i2a_aux_at_A2I_1: + lw $a0, -4($fp) + bne $a0, $zero, label_i2a_aux_at_A2I_2 + lw $t1, 8($fp) + li $a0, 10 + div $a0, $t1, $a0 + sw $a0, -16($fp) + lw $t1, -16($fp) + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, next + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -28($fp) + li $t1, next + li $a0, 10 + mul $a0 $t1 $a0 + sw $a0, -40($fp) + lw $t1, 8($fp) + lw $a0, -40($fp) + blt $t1, $a0, label_i2a_aux_at_A2I_4 + li $a0, 0 + j label_i2a_aux_at_A2I_5 +label_i2a_aux_at_A2I_4: + li $a0, 1 +label_i2a_aux_at_A2I_5: + sw $a0, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_concat_at_String + sw $a0, -24($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + sw $t1, -12($fp) + j label_i2a_aux_at_A2I_3 +label_i2a_aux_at_A2I_2: + la $t1, _empty + sw $t1, -44($fp) + lw $t1, -44($fp) + sw $t1, -12($fp) +label_i2a_aux_at_A2I_3: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, A2I_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, A2I_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__A2I + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_A2I + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_menu_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -212 + la $t1, data_1 + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -12($fp) + la $t1, data_2 + sw $t1, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -20($fp) + la $t1, data_3 + sw $t1, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -36($fp) + la $t1, data_2 + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -44($fp) + la $t1, data_3 + sw $t1, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -52($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -64($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -60($fp) + la $t1, data_2 + sw $t1, -72($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -72($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -68($fp) + la $t1, data_3 + sw $t1, -80($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -76($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -88($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -88($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -84($fp) + la $t1, data_2 + sw $t1, -96($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -96($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -92($fp) + la $t1, data_3 + sw $t1, -104($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -104($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -100($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -112($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -112($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -108($fp) + la $t1, data_2 + sw $t1, -120($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -120($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -116($fp) + la $t1, data_3 + sw $t1, -128($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -128($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -124($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -136($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -136($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -132($fp) + la $t1, data_2 + sw $t1, -144($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -144($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -140($fp) + la $t1, data_3 + sw $t1, -152($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -152($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -148($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -160($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -160($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -156($fp) + la $t1, data_2 + sw $t1, -168($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -168($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -164($fp) + la $t1, data_3 + sw $t1, -176($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -176($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -172($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -184($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -184($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -180($fp) + la $t1, data_2 + sw $t1, -192($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -192($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -188($fp) + la $t1, data_4 + sw $t1, -200($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -200($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -196($fp) + la $t1, data_5 + sw $t1, -208($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -208($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -204($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -212($fp) + + #retornando el valor + + lw $a0, -212($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 224 + lw $fp, 0($sp) + jr $ra +function_prompt_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + la $t1, data_2 + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + la $t1, _empty + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -20($fp) + + #retornando el valor + + lw $a0, -20($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra +function_get_int_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -24 + + #init allocate + + li $v0, 9 + lw $a0, A2I_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A2I + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -16($fp) + lw $t1, -16($fp) + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, s + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, z + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -24($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_is_even_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + lw $t1, 8($fp) + sw $t1, -4($fp) + li $a0, [] + bne $a0, $zero, label_is_even_at_Main_0 + li $t1, 0 + li $a0, x + sub $a0, $t1, $a0 + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_is_even_at_Main_2 + li $t1, 1 + sw $t1, -12($fp) + j label_is_even_at_Main_3 +label_is_even_at_Main_2: + li $t1, 0 + sw $t1, -12($fp) +label_is_even_at_Main_3: + lw $a0, -12($fp) + bne $a0, $zero, label_is_even_at_Main_4 + li $t1, 1 + li $a0, x + sub $a0, $t1, $a0 + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_is_even_at_Main_6 + li $t1, 1 + sw $t1, -24($fp) + j label_is_even_at_Main_7 +label_is_even_at_Main_6: + li $t1, 0 + sw $t1, -24($fp) +label_is_even_at_Main_7: + lw $a0, -24($fp) + bne $a0, $zero, label_is_even_at_Main_8 + li $t1, x + li $a0, 2 + blt $t1, $a0, label_is_even_at_Main_10 + li $a0, 0 + j label_is_even_at_Main_11 +label_is_even_at_Main_10: + li $a0, 1 +label_is_even_at_Main_11: + sw $a0, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -32($fp) + j label_is_even_at_Main_9 +label_is_even_at_Main_8: + li $t1, 0 + sw $t1, -32($fp) +label_is_even_at_Main_9: + lw $t1, -32($fp) + sw $t1, -20($fp) + j label_is_even_at_Main_5 +label_is_even_at_Main_4: + li $t1, 1 + sw $t1, -20($fp) +label_is_even_at_Main_5: + lw $t1, -20($fp) + sw $t1, -8($fp) + j label_is_even_at_Main_1 +label_is_even_at_Main_0: + li $t1, x + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -44($fp) + lw $t1, -44($fp) + sw $t1, -8($fp) +label_is_even_at_Main_1: + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 64 + lw $fp, 0($sp) + jr $ra +function_class_type_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -80 + lw $t1, 8($fp) + sw $t1, -8($fp) + la $a0, E_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_0 + la $a0, D_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_1 + la $a0, C_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_2 + la $a0, B_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_3 + la $a0, A_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_4 + la $a0, Bool_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_5 + la $a0, Int_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_5 + la $a0, String_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_5 + la $a0, Main_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_5 + la $a0, IO_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_5 + la $a0, A2I_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_5 + la $a0, Object_name + lw $t1, 8($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_class_type_at_Main_5 +label_class_type_at_Main_4: + lw $t1, 8($fp) + sw $t1, -12($fp) + la $t1, data_2 + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -16($fp) + lw $t1, -16($fp) + sw $t1, -4($fp) + j label_class_type_at_Main_6 +label_class_type_at_Main_3: + lw $t1, 8($fp) + sw $t1, -24($fp) + la $t1, data_2 + sw $t1, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -28($fp) + sw $t1, -4($fp) + j label_class_type_at_Main_6 +label_class_type_at_Main_2: + lw $t1, 8($fp) + sw $t1, -36($fp) + la $t1, data_2 + sw $t1, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -40($fp) + lw $t1, -40($fp) + sw $t1, -4($fp) + j label_class_type_at_Main_6 +label_class_type_at_Main_1: + lw $t1, 8($fp) + sw $t1, -48($fp) + la $t1, data_2 + sw $t1, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -52($fp) + lw $t1, -52($fp) + sw $t1, -4($fp) + j label_class_type_at_Main_6 +label_class_type_at_Main_0: + lw $t1, 8($fp) + sw $t1, -60($fp) + la $t1, data_2 + sw $t1, -68($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -64($fp) + lw $t1, -64($fp) + sw $t1, -4($fp) + j label_class_type_at_Main_6 +label_class_type_at_Main_5: + lw $t1, 8($fp) + sw $t1, -72($fp) + la $t1, data_2 + sw $t1, -80($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -76($fp) + lw $t1, -76($fp) + sw $t1, -4($fp) + j label_class_type_at_Main_6 +label_class_type_at_Main_6: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 96 + lw $fp, 0($sp) + jr $ra +function_print_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -32 + + #init allocate + + li $v0, 9 + lw $a0, A2I_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A2I + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, 8($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, z + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -16($fp) + la $t1, _empty + sw $t1, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + + #retornando el valor + + lw $a0, -28($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 48 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -652 + + #init allocate + + li $v0, 9 + lw $a0, A_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A + sw $a0, -8($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -4($fp) + sw $t1, 16($a0) + + #end set attribute + +label_main_at_Main_0: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 24($a0) + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_main_at_Main_1 + j label_main_at_Main_2 +label_main_at_Main_1: + la $t1, _empty + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -16($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -24($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -40($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -36($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -32($fp) + lw $a0, -32($fp) + bne $a0, $zero, label_main_at_Main_3 + la $t1, data_2 + sw $t1, -52($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -52($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -48($fp) + lw $t1, -48($fp) + sw $t1, -44($fp) + j label_main_at_Main_4 +label_main_at_Main_3: + la $t1, data_2 + sw $t1, -60($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -56($fp) + lw $t1, -56($fp) + sw $t1, -44($fp) +label_main_at_Main_4: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -68($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -64($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -72($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -72($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -80($fp) + la $t1, _empty + sw $t1, -84($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -84($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -76($fp) + lw $a0, -76($fp) + bne $a0, $zero, label_main_at_Main_5 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -96($fp) + la $t1, _empty + sw $t1, -100($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -96($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -100($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -92($fp) + lw $a0, -92($fp) + bne $a0, $zero, label_main_at_Main_7 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -112($fp) + la $t1, _empty + sw $t1, -116($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -112($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -116($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -108($fp) + lw $a0, -108($fp) + bne $a0, $zero, label_main_at_Main_9 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -128($fp) + la $t1, _empty + sw $t1, -132($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -128($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -132($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -124($fp) + lw $a0, -124($fp) + bne $a0, $zero, label_main_at_Main_11 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -144($fp) + la $t1, _empty + sw $t1, -148($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -144($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -148($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -140($fp) + lw $a0, -140($fp) + bne $a0, $zero, label_main_at_Main_13 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -160($fp) + la $t1, _empty + sw $t1, -164($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -160($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -164($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -156($fp) + lw $a0, -156($fp) + bne $a0, $zero, label_main_at_Main_15 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -176($fp) + la $t1, _empty + sw $t1, -180($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -176($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -180($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -172($fp) + lw $a0, -172($fp) + bne $a0, $zero, label_main_at_Main_17 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -192($fp) + la $t1, _empty + sw $t1, -196($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -192($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -196($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -188($fp) + lw $a0, -188($fp) + bne $a0, $zero, label_main_at_Main_19 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -208($fp) + la $t1, _empty + sw $t1, -212($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -208($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -212($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -204($fp) + lw $a0, -204($fp) + bne $a0, $zero, label_main_at_Main_21 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -224($fp) + la $t1, _empty + sw $t1, -228($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -224($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -228($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -220($fp) + lw $a0, -220($fp) + bne $a0, $zero, label_main_at_Main_23 + + #init allocate + + li $v0, 9 + lw $a0, A_size + syscall + sw $v0, -240($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -240($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A + sw $a0, -244($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -252($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -252($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -252($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -248($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -248($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -240($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -240($fp) + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -236($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -236($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -236($fp) + sw $t1, -232($fp) + j label_main_at_Main_24 +label_main_at_Main_23: + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 24($a0) + + #end set attribute + + li $t1, 0 + sw $t1, -232($fp) +label_main_at_Main_24: + lw $t1, -232($fp) + sw $t1, -216($fp) + j label_main_at_Main_22 +label_main_at_Main_21: + + #init allocate + + li $v0, 9 + lw $a0, A_size + syscall + sw $v0, -256($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -256($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A + sw $a0, -260($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -256($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -256($fp) + sw $t1, -216($fp) +label_main_at_Main_22: + lw $t1, -216($fp) + sw $t1, -200($fp) + j label_main_at_Main_20 +label_main_at_Main_19: + la $t1, _void + sw $t1, -264($fp) + lw $t1, -264($fp) + sw $t1, -268($fp) + + #init allocate + + li $v0, 9 + lw $a0, E_size + syscall + sw $v0, -276($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -276($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_E + sw $a0, -280($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -288($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -288($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -288($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -284($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -284($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -276($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -276($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -272($fp) + + #fin llamada dinamica + + lw $t1, -272($fp) + sw $t1, -268($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -300($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -300($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -300($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -296($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -308($fp) + + #fin llamada dinamica + + lw $t1, -308($fp) + li $a0, 8 + mul $a0 $t1 $a0 + sw $a0, -304($fp) + lw $t1, -296($fp) + lw $a0, -304($fp) + blt $t1, $a0, label_main_at_Main_25 + li $a0, 0 + j label_main_at_Main_26 +label_main_at_Main_25: + li $a0, 1 +label_main_at_Main_26: + sw $a0, -292($fp) + lw $t1, -292($fp) + sw $t1, -312($fp) + la $t1, _empty + sw $t1, -320($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -320($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -316($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -328($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -328($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -324($fp) + la $t1, _empty + sw $t1, -336($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -336($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -332($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, x + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -340($fp) + la $t1, _empty + sw $t1, -348($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -348($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -344($fp) + + #init allocate + + li $v0, 9 + lw $a0, A2I_size + syscall + sw $v0, -352($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -352($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A2I + sw $a0, -356($fp) + + #fin llamada dinamica + + lw $t1, -352($fp) + sw $t1, -360($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, r + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, a + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -368($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -368($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -364($fp) + la $t1, data_2 + sw $t1, -376($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -376($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -372($fp) + + #init set attribute + + lw $a0, 4($fp) + li $t1, x + sw $t1, 16($a0) + + #end set attribute + + li $t1, x + sw $t1, -200($fp) +label_main_at_Main_20: + lw $t1, -200($fp) + sw $t1, -184($fp) + j label_main_at_Main_18 +label_main_at_Main_17: + + #init allocate + + li $v0, 9 + lw $a0, D_size + syscall + sw $v0, -384($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -384($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_D + sw $a0, -388($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -396($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -396($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -396($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -392($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -392($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -384($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -384($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -380($fp) + + #fin llamada dinamica + + lw $a0, -380($fp) + bne $a0, $zero, label_main_at_Main_27 + la $t1, _empty + sw $t1, -408($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -408($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -404($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -416($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -416($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -412($fp) + la $t1, data_2 + sw $t1, -424($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -424($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -420($fp) + lw $t1, -420($fp) + sw $t1, -400($fp) + j label_main_at_Main_28 +label_main_at_Main_27: + la $t1, _empty + sw $t1, -432($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -432($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -428($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -440($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -440($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -436($fp) + la $t1, data_2 + sw $t1, -448($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -448($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -444($fp) + lw $t1, -444($fp) + sw $t1, -400($fp) +label_main_at_Main_28: + lw $t1, -400($fp) + sw $t1, -184($fp) +label_main_at_Main_18: + lw $t1, -184($fp) + sw $t1, -168($fp) + j label_main_at_Main_16 +label_main_at_Main_15: + + #init allocate + + li $v0, 9 + lw $a0, C_size + syscall + sw $v0, -456($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -456($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_C + sw $a0, -460($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -468($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -468($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -468($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -464($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -464($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -456($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__C + lw $a0, 36($a0) + jalr $a0 + sw $a0, -452($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -452($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -452($fp) + sw $t1, -168($fp) +label_main_at_Main_16: + lw $t1, -168($fp) + sw $t1, -152($fp) + j label_main_at_Main_14 +label_main_at_Main_13: + + #init allocate + + li $v0, 9 + lw $a0, C_size + syscall + sw $v0, -476($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -476($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_C + sw $a0, -480($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -488($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -488($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -488($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -484($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -484($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -476($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__B + lw $a0, 36($a0) + jalr $a0 + sw $a0, -472($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -472($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -472($fp) + sw $t1, -152($fp) +label_main_at_Main_14: + lw $t1, -152($fp) + sw $t1, -136($fp) + j label_main_at_Main_12 +label_main_at_Main_11: + + #init allocate + + li $v0, 9 + lw $a0, C_size + syscall + sw $v0, -496($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -496($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_C + sw $a0, -500($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -508($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -508($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -508($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -504($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -504($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -496($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__A + lw $a0, 36($a0) + jalr $a0 + sw $a0, -492($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -492($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -492($fp) + sw $t1, -136($fp) +label_main_at_Main_12: + lw $t1, -136($fp) + sw $t1, -120($fp) + j label_main_at_Main_10 +label_main_at_Main_9: + + #init allocate + + li $v0, 9 + lw $a0, A_size + syscall + sw $v0, -516($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -516($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A + sw $a0, -520($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -524($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -524($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -516($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -516($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -512($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -512($fp) + sw $t1, 20($a0) + + #end set attribute + + + #init allocate + + li $v0, 9 + lw $a0, D_size + syscall + sw $v0, -532($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -532($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_D + sw $a0, -536($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -544($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -544($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -544($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -540($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 20($a0) + sw $a0, -552($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -552($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -552($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -548($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -548($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -540($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -532($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -532($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -528($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -528($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -528($fp) + sw $t1, -120($fp) +label_main_at_Main_10: + lw $t1, -120($fp) + sw $t1, -104($fp) + j label_main_at_Main_8 +label_main_at_Main_7: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -564($fp) + lw $t1, -564($fp) + sw $t1, -560($fp) + la $a0, C_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_29 + la $a0, E_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_30 + la $a0, D_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_30 + la $a0, B_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_30 + la $a0, A_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_30 + la $a0, Bool_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_31 + la $a0, Int_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_31 + la $a0, String_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_31 + la $a0, Main_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_31 + la $a0, IO_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_31 + la $a0, A2I_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_31 + la $a0, Object_name + lw $t1, -564($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_main_at_Main_31 +label_main_at_Main_29: + lw $t1, -564($fp) + sw $t1, -568($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, c + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -576($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -576($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, c + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -572($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -572($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -572($fp) + sw $t1, -556($fp) + j label_main_at_Main_32 +label_main_at_Main_30: + lw $t1, -564($fp) + sw $t1, -580($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, a + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -588($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -588($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, a + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -584($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -584($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -584($fp) + sw $t1, -556($fp) + j label_main_at_Main_32 +label_main_at_Main_31: + lw $t1, -564($fp) + sw $t1, -592($fp) + la $t1, data_2 + sw $t1, -600($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -600($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -596($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -604($fp) + li $t1, 0 + sw $t1, -556($fp) + j label_main_at_Main_32 +label_main_at_Main_32: + lw $t1, -556($fp) + sw $t1, -104($fp) +label_main_at_Main_8: + lw $t1, -104($fp) + sw $t1, -88($fp) + j label_main_at_Main_6 +label_main_at_Main_5: + + #init allocate + + li $v0, 9 + lw $a0, A_size + syscall + sw $v0, -612($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -612($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A + sw $a0, -616($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -620($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -620($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -612($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -612($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -608($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -608($fp) + sw $t1, 20($a0) + + #end set attribute + + + #init allocate + + li $v0, 9 + lw $a0, B_size + syscall + sw $v0, -628($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -628($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_B + sw $a0, -632($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -640($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -640($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -640($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -636($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 20($a0) + sw $a0, -648($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -648($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -648($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -644($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -644($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -636($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -628($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -628($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -624($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -624($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -624($fp) + sw $t1, -88($fp) +label_main_at_Main_6: + j label_main_at_Main_0 +label_main_at_Main_2: + la $t1, _void + sw $t1, -652($fp) + + #retornando el valor + + lw $a0, -652($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 664 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/atoi.mips b/tests/codegen/atoi.mips new file mode 100644 index 000000000..f8dd438a5 --- /dev/null +++ b/tests/codegen/atoi.mips @@ -0,0 +1,2204 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + A2I_name: .asciiz "A2I" + A2I_size: .word 12 +__virtual_table__A2I: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_c2i_at_A2I + .word function_i2c_at_A2I + .word function_a2i_at_A2I + .word function_a2i_aux_at_A2I + .word function_i2a_at_A2I + .word function_i2a_aux_at_A2I + Main_name: .asciiz "Main" + Main_size: .word 12 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 28($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_c2i_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -124 + la $t1, _empty + sw $t1, -8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -4($fp) + lw $a0, -4($fp) + bne $a0, $zero, label_c2i_at_A2I_0 + la $t1, _empty + sw $t1, -20($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_c2i_at_A2I_2 + la $t1, _empty + sw $t1, -32($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_c2i_at_A2I_4 + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_c2i_at_A2I_6 + la $t1, _empty + sw $t1, -56($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -52($fp) + lw $a0, -52($fp) + bne $a0, $zero, label_c2i_at_A2I_8 + la $t1, _empty + sw $t1, -68($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -64($fp) + lw $a0, -64($fp) + bne $a0, $zero, label_c2i_at_A2I_10 + la $t1, _empty + sw $t1, -80($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -76($fp) + lw $a0, -76($fp) + bne $a0, $zero, label_c2i_at_A2I_12 + la $t1, _empty + sw $t1, -92($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -92($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -88($fp) + lw $a0, -88($fp) + bne $a0, $zero, label_c2i_at_A2I_14 + la $t1, _empty + sw $t1, -104($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -104($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -100($fp) + lw $a0, -100($fp) + bne $a0, $zero, label_c2i_at_A2I_16 + la $t1, _empty + sw $t1, -116($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -116($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -112($fp) + lw $a0, -112($fp) + bne $a0, $zero, label_c2i_at_A2I_18 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -124($fp) + li $t1, 0 + sw $t1, -120($fp) + j label_c2i_at_A2I_19 +label_c2i_at_A2I_18: + li $t1, 9 + sw $t1, -120($fp) +label_c2i_at_A2I_19: + lw $t1, -120($fp) + sw $t1, -108($fp) + j label_c2i_at_A2I_17 +label_c2i_at_A2I_16: + li $t1, 8 + sw $t1, -108($fp) +label_c2i_at_A2I_17: + lw $t1, -108($fp) + sw $t1, -96($fp) + j label_c2i_at_A2I_15 +label_c2i_at_A2I_14: + li $t1, 7 + sw $t1, -96($fp) +label_c2i_at_A2I_15: + lw $t1, -96($fp) + sw $t1, -84($fp) + j label_c2i_at_A2I_13 +label_c2i_at_A2I_12: + li $t1, 6 + sw $t1, -84($fp) +label_c2i_at_A2I_13: + lw $t1, -84($fp) + sw $t1, -72($fp) + j label_c2i_at_A2I_11 +label_c2i_at_A2I_10: + li $t1, 5 + sw $t1, -72($fp) +label_c2i_at_A2I_11: + lw $t1, -72($fp) + sw $t1, -60($fp) + j label_c2i_at_A2I_9 +label_c2i_at_A2I_8: + li $t1, 4 + sw $t1, -60($fp) +label_c2i_at_A2I_9: + lw $t1, -60($fp) + sw $t1, -48($fp) + j label_c2i_at_A2I_7 +label_c2i_at_A2I_6: + li $t1, 3 + sw $t1, -48($fp) +label_c2i_at_A2I_7: + lw $t1, -48($fp) + sw $t1, -36($fp) + j label_c2i_at_A2I_5 +label_c2i_at_A2I_4: + li $t1, 2 + sw $t1, -36($fp) +label_c2i_at_A2I_5: + lw $t1, -36($fp) + sw $t1, -24($fp) + j label_c2i_at_A2I_3 +label_c2i_at_A2I_2: + li $t1, 1 + sw $t1, -24($fp) +label_c2i_at_A2I_3: + lw $t1, -24($fp) + sw $t1, -12($fp) + j label_c2i_at_A2I_1 +label_c2i_at_A2I_0: + li $t1, 0 + sw $t1, -12($fp) +label_c2i_at_A2I_1: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 140 + lw $fp, 0($sp) + jr $ra +function_i2c_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -168 + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -8($fp) + lw $a0, -8($fp) + bne $a0, $zero, label_i2c_at_A2I_0 + li $t1, 1 + sw $t1, -4($fp) + j label_i2c_at_A2I_1 +label_i2c_at_A2I_0: + li $t1, 0 + sw $t1, -4($fp) +label_i2c_at_A2I_1: + lw $a0, -4($fp) + bne $a0, $zero, label_i2c_at_A2I_2 + lw $t1, 8($fp) + li $a0, 1 + sub $a0, $t1, $a0 + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_i2c_at_A2I_4 + li $t1, 1 + sw $t1, -16($fp) + j label_i2c_at_A2I_5 +label_i2c_at_A2I_4: + li $t1, 0 + sw $t1, -16($fp) +label_i2c_at_A2I_5: + lw $a0, -16($fp) + bne $a0, $zero, label_i2c_at_A2I_6 + lw $t1, 8($fp) + li $a0, 2 + sub $a0, $t1, $a0 + sw $a0, -32($fp) + lw $a0, -32($fp) + bne $a0, $zero, label_i2c_at_A2I_8 + li $t1, 1 + sw $t1, -28($fp) + j label_i2c_at_A2I_9 +label_i2c_at_A2I_8: + li $t1, 0 + sw $t1, -28($fp) +label_i2c_at_A2I_9: + lw $a0, -28($fp) + bne $a0, $zero, label_i2c_at_A2I_10 + lw $t1, 8($fp) + li $a0, 3 + sub $a0, $t1, $a0 + sw $a0, -44($fp) + lw $a0, -44($fp) + bne $a0, $zero, label_i2c_at_A2I_12 + li $t1, 1 + sw $t1, -40($fp) + j label_i2c_at_A2I_13 +label_i2c_at_A2I_12: + li $t1, 0 + sw $t1, -40($fp) +label_i2c_at_A2I_13: + lw $a0, -40($fp) + bne $a0, $zero, label_i2c_at_A2I_14 + lw $t1, 8($fp) + li $a0, 4 + sub $a0, $t1, $a0 + sw $a0, -56($fp) + lw $a0, -56($fp) + bne $a0, $zero, label_i2c_at_A2I_16 + li $t1, 1 + sw $t1, -52($fp) + j label_i2c_at_A2I_17 +label_i2c_at_A2I_16: + li $t1, 0 + sw $t1, -52($fp) +label_i2c_at_A2I_17: + lw $a0, -52($fp) + bne $a0, $zero, label_i2c_at_A2I_18 + lw $t1, 8($fp) + li $a0, 5 + sub $a0, $t1, $a0 + sw $a0, -68($fp) + lw $a0, -68($fp) + bne $a0, $zero, label_i2c_at_A2I_20 + li $t1, 1 + sw $t1, -64($fp) + j label_i2c_at_A2I_21 +label_i2c_at_A2I_20: + li $t1, 0 + sw $t1, -64($fp) +label_i2c_at_A2I_21: + lw $a0, -64($fp) + bne $a0, $zero, label_i2c_at_A2I_22 + lw $t1, 8($fp) + li $a0, 6 + sub $a0, $t1, $a0 + sw $a0, -80($fp) + lw $a0, -80($fp) + bne $a0, $zero, label_i2c_at_A2I_24 + li $t1, 1 + sw $t1, -76($fp) + j label_i2c_at_A2I_25 +label_i2c_at_A2I_24: + li $t1, 0 + sw $t1, -76($fp) +label_i2c_at_A2I_25: + lw $a0, -76($fp) + bne $a0, $zero, label_i2c_at_A2I_26 + lw $t1, 8($fp) + li $a0, 7 + sub $a0, $t1, $a0 + sw $a0, -92($fp) + lw $a0, -92($fp) + bne $a0, $zero, label_i2c_at_A2I_28 + li $t1, 1 + sw $t1, -88($fp) + j label_i2c_at_A2I_29 +label_i2c_at_A2I_28: + li $t1, 0 + sw $t1, -88($fp) +label_i2c_at_A2I_29: + lw $a0, -88($fp) + bne $a0, $zero, label_i2c_at_A2I_30 + lw $t1, 8($fp) + li $a0, 8 + sub $a0, $t1, $a0 + sw $a0, -104($fp) + lw $a0, -104($fp) + bne $a0, $zero, label_i2c_at_A2I_32 + li $t1, 1 + sw $t1, -100($fp) + j label_i2c_at_A2I_33 +label_i2c_at_A2I_32: + li $t1, 0 + sw $t1, -100($fp) +label_i2c_at_A2I_33: + lw $a0, -100($fp) + bne $a0, $zero, label_i2c_at_A2I_34 + lw $t1, 8($fp) + li $a0, 9 + sub $a0, $t1, $a0 + sw $a0, -116($fp) + lw $a0, -116($fp) + bne $a0, $zero, label_i2c_at_A2I_36 + li $t1, 1 + sw $t1, -112($fp) + j label_i2c_at_A2I_37 +label_i2c_at_A2I_36: + li $t1, 0 + sw $t1, -112($fp) +label_i2c_at_A2I_37: + lw $a0, -112($fp) + bne $a0, $zero, label_i2c_at_A2I_38 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -124($fp) + la $t1, _empty + sw $t1, -128($fp) + lw $t1, -128($fp) + sw $t1, -120($fp) + j label_i2c_at_A2I_39 +label_i2c_at_A2I_38: + la $t1, _empty + sw $t1, -132($fp) + lw $t1, -132($fp) + sw $t1, -120($fp) +label_i2c_at_A2I_39: + lw $t1, -120($fp) + sw $t1, -108($fp) + j label_i2c_at_A2I_35 +label_i2c_at_A2I_34: + la $t1, _empty + sw $t1, -136($fp) + lw $t1, -136($fp) + sw $t1, -108($fp) +label_i2c_at_A2I_35: + lw $t1, -108($fp) + sw $t1, -96($fp) + j label_i2c_at_A2I_31 +label_i2c_at_A2I_30: + la $t1, _empty + sw $t1, -140($fp) + lw $t1, -140($fp) + sw $t1, -96($fp) +label_i2c_at_A2I_31: + lw $t1, -96($fp) + sw $t1, -84($fp) + j label_i2c_at_A2I_27 +label_i2c_at_A2I_26: + la $t1, _empty + sw $t1, -144($fp) + lw $t1, -144($fp) + sw $t1, -84($fp) +label_i2c_at_A2I_27: + lw $t1, -84($fp) + sw $t1, -72($fp) + j label_i2c_at_A2I_23 +label_i2c_at_A2I_22: + la $t1, _empty + sw $t1, -148($fp) + lw $t1, -148($fp) + sw $t1, -72($fp) +label_i2c_at_A2I_23: + lw $t1, -72($fp) + sw $t1, -60($fp) + j label_i2c_at_A2I_19 +label_i2c_at_A2I_18: + la $t1, _empty + sw $t1, -152($fp) + lw $t1, -152($fp) + sw $t1, -60($fp) +label_i2c_at_A2I_19: + lw $t1, -60($fp) + sw $t1, -48($fp) + j label_i2c_at_A2I_15 +label_i2c_at_A2I_14: + la $t1, _empty + sw $t1, -156($fp) + lw $t1, -156($fp) + sw $t1, -48($fp) +label_i2c_at_A2I_15: + lw $t1, -48($fp) + sw $t1, -36($fp) + j label_i2c_at_A2I_11 +label_i2c_at_A2I_10: + la $t1, _empty + sw $t1, -160($fp) + lw $t1, -160($fp) + sw $t1, -36($fp) +label_i2c_at_A2I_11: + lw $t1, -36($fp) + sw $t1, -24($fp) + j label_i2c_at_A2I_7 +label_i2c_at_A2I_6: + la $t1, _empty + sw $t1, -164($fp) + lw $t1, -164($fp) + sw $t1, -24($fp) +label_i2c_at_A2I_7: + lw $t1, -24($fp) + sw $t1, -12($fp) + j label_i2c_at_A2I_3 +label_i2c_at_A2I_2: + la $t1, _empty + sw $t1, -168($fp) + lw $t1, -168($fp) + sw $t1, -12($fp) +label_i2c_at_A2I_3: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 184 + lw $fp, 0($sp) + jr $ra +function_a2i_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -88 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_a2i_at_A2I_0 + li $t1, 1 + sw $t1, -4($fp) + j label_a2i_at_A2I_1 +label_a2i_at_A2I_0: + li $t1, 0 + sw $t1, -4($fp) +label_a2i_at_A2I_1: + lw $a0, -4($fp) + bne $a0, $zero, label_a2i_at_A2I_2 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -24($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -28($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_a2i_at_A2I_4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -40($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_a2i_at_A2I_6 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -52($fp) + lw $t1, -52($fp) + sw $t1, -48($fp) + j label_a2i_at_A2I_7 +label_a2i_at_A2I_6: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -68($fp) + + #fin llamada dinamica + + lw $t1, -68($fp) + li $a0, 1 + blt $t1, $a0, label_a2i_at_A2I_8 + li $a0, 0 + j label_a2i_at_A2I_9 +label_a2i_at_A2I_8: + li $a0, 1 +label_a2i_at_A2I_9: + sw $a0, -64($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -60($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -56($fp) + lw $t1, -56($fp) + sw $t1, -48($fp) +label_a2i_at_A2I_7: + lw $t1, -48($fp) + sw $t1, -32($fp) + j label_a2i_at_A2I_5 +label_a2i_at_A2I_4: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -88($fp) + + #fin llamada dinamica + + lw $t1, -88($fp) + li $a0, 1 + blt $t1, $a0, label_a2i_at_A2I_10 + li $a0, 0 + j label_a2i_at_A2I_11 +label_a2i_at_A2I_10: + li $a0, 1 +label_a2i_at_A2I_11: + sw $a0, -84($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -84($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -80($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -76($fp) + lw $t1, -76($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -72($fp) + lw $t1, -72($fp) + sw $t1, -32($fp) +label_a2i_at_A2I_5: + lw $t1, -32($fp) + sw $t1, -16($fp) + j label_a2i_at_A2I_3 +label_a2i_at_A2I_2: + li $t1, 0 + sw $t1, -16($fp) +label_a2i_at_A2I_3: + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 104 + lw $fp, 0($sp) + jr $ra +function_a2i_aux_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + li $t1, 0 + sw $t1, -4($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + sw $t1, -12($fp) + li $t1, 0 + sw $t1, -16($fp) +label_a2i_aux_at_A2I_0: + li $a0, [] + bne $a0, $zero, label_a2i_aux_at_A2I_1 + j label_a2i_aux_at_A2I_2 +label_a2i_aux_at_A2I_1: + li $t1, int + li $a0, 10 + mul $a0 $t1 $a0 + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, i + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -32($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -24($fp) + lw $a0, -28($fp) + add $a0, $a0, $t1 + sw $a0, -20($fp) + lw $t1, -20($fp) + sw $t1, -4($fp) + li $t1, i + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -16($fp) + j label_a2i_aux_at_A2I_0 +label_a2i_aux_at_A2I_2: + la $t1, _void + sw $t1, -40($fp) + + #retornando el valor + + li $a0, int + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 56 + lw $fp, 0($sp) + jr $ra +function_i2a_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -44 + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -8($fp) + lw $a0, -8($fp) + bne $a0, $zero, label_i2a_at_A2I_0 + li $t1, 1 + sw $t1, -4($fp) + j label_i2a_at_A2I_1 +label_i2a_at_A2I_0: + li $t1, 0 + sw $t1, -4($fp) +label_i2a_at_A2I_1: + lw $a0, -4($fp) + bne $a0, $zero, label_i2a_at_A2I_2 + li $a0, [] + bne $a0, $zero, label_i2a_at_A2I_4 + la $t1, _empty + sw $t1, -24($fp) + li $t1, 1 + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -36($fp) + lw $t1, 8($fp) + lw $a0, -36($fp) + mul $a0 $t1 $a0 + sw $a0, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_concat_at_String + sw $a0, -20($fp) + + #fin llamada dinamica + + lw $t1, -20($fp) + sw $t1, -16($fp) + j label_i2a_at_A2I_5 +label_i2a_at_A2I_4: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -40($fp) + lw $t1, -40($fp) + sw $t1, -16($fp) +label_i2a_at_A2I_5: + lw $t1, -16($fp) + sw $t1, -12($fp) + j label_i2a_at_A2I_3 +label_i2a_at_A2I_2: + la $t1, _empty + sw $t1, -44($fp) + lw $t1, -44($fp) + sw $t1, -12($fp) +label_i2a_at_A2I_3: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_i2a_aux_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -44 + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -8($fp) + lw $a0, -8($fp) + bne $a0, $zero, label_i2a_aux_at_A2I_0 + li $t1, 1 + sw $t1, -4($fp) + j label_i2a_aux_at_A2I_1 +label_i2a_aux_at_A2I_0: + li $t1, 0 + sw $t1, -4($fp) +label_i2a_aux_at_A2I_1: + lw $a0, -4($fp) + bne $a0, $zero, label_i2a_aux_at_A2I_2 + lw $t1, 8($fp) + li $a0, 10 + div $a0, $t1, $a0 + sw $a0, -16($fp) + lw $t1, -16($fp) + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, next + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -28($fp) + li $t1, next + li $a0, 10 + mul $a0 $t1 $a0 + sw $a0, -40($fp) + lw $t1, 8($fp) + lw $a0, -40($fp) + blt $t1, $a0, label_i2a_aux_at_A2I_4 + li $a0, 0 + j label_i2a_aux_at_A2I_5 +label_i2a_aux_at_A2I_4: + li $a0, 1 +label_i2a_aux_at_A2I_5: + sw $a0, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_concat_at_String + sw $a0, -24($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + sw $t1, -12($fp) + j label_i2a_aux_at_A2I_3 +label_i2a_aux_at_A2I_2: + la $t1, _empty + sw $t1, -44($fp) + lw $t1, -44($fp) + sw $t1, -12($fp) +label_i2a_aux_at_A2I_3: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, A2I_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, A2I_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__A2I + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_A2I + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_A2I: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -60 + + #init allocate + + li $v0, 9 + lw $a0, A2I_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A2I + sw $a0, -12($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -20($fp) + + #init allocate + + li $v0, 9 + lw $a0, A2I_size + syscall + sw $v0, -28($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A2I + sw $a0, -32($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 678987 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -28($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + sw $t1, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, a + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -40($fp) + la $t1, _empty + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, b + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -52($fp) + la $t1, data_1 + sw $t1, -60($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -56($fp) + + #retornando el valor + + lw $a0, -56($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 72 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/book_list.mips b/tests/codegen/book_list.mips new file mode 100644 index 000000000..c509548d6 --- /dev/null +++ b/tests/codegen/book_list.mips @@ -0,0 +1,2487 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Book_name: .asciiz "Book" + Book_size: .word 20 +__virtual_table__Book: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_initBook_at_Book + .word function_print_at_Book + Article_name: .asciiz "Article" + Article_size: .word 24 +__virtual_table__Article: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_initBook_at_Book + .word function_print_at_Article + .word function_initArticle_at_Article + BookList_name: .asciiz "BookList" + BookList_size: .word 12 +__virtual_table__BookList: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_BookList + .word function_cons_at_BookList + .word function_car_at_BookList + .word function_cdr_at_BookList + .word function_print_list_at_BookList + Cons_name: .asciiz "Cons" + Cons_size: .word 20 +__virtual_table__Cons: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_Cons + .word function_cons_at_BookList + .word function_car_at_Cons + .word function_cdr_at_Cons + .word function_print_list_at_Cons + .word function_init_at_Cons + Nil_name: .asciiz "Nil" + Nil_size: .word 12 +__virtual_table__Nil: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_Nil + .word function_cons_at_BookList + .word function_car_at_BookList + .word function_cdr_at_BookList + .word function_print_list_at_Nil + Main_name: .asciiz "Main" + Main_size: .word 16 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_initBook_at_Book: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 12($fp) + sw $t1, 16($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_print_at_Book: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + la $t1, _empty + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -12($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -8($fp) + + #fin llamada dinamica + + la $t1, data_1 + sw $t1, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -36($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -36($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -32($fp) + + #fin llamada dinamica + + la $t1, data_1 + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -32($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Book: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Book_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Book_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Book + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Book + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Book: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_initArticle_at_Article: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -4($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 16($fp) + sw $t1, 20($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_print_at_Article: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -28 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Book + lw $a0, 32($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -16($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 20($a0) + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + la $t1, data_1 + sw $t1, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -12($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -8($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Article: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Article_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Article_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Article + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Article + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Article: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Book + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_BookList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_cons_at_BookList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init allocate + + li $v0, 9 + lw $a0, Cons_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Cons + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, new_cell + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra +function_car_at_BookList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, Book_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Book + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_cdr_at_BookList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, BookList_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_BookList + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_print_list_at_BookList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_BookList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, BookList_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, BookList_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__BookList + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_BookList + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_BookList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_init_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 12($fp) + sw $t1, 16($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_car_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_cdr_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_print_list_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + lw $t1, -12($fp) + sw $t1, -8($fp) + la $a0, Article_name + lw $t1, -12($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_print_list_at_Cons_0 + la $a0, Book_name + lw $t1, -12($fp) + lw $t1, 0($t1) + beq $t1, $a0, label_print_list_at_Cons_1 +label_print_list_at_Cons_1: + lw $t1, -12($fp) + sw $t1, -20($fp) + la $t1, data_1 + sw $t1, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -24($fp) + lw $t1, -24($fp) + sw $t1, -4($fp) + j label_print_list_at_Cons_2 +label_print_list_at_Cons_0: + lw $t1, -12($fp) + sw $t1, -32($fp) + la $t1, data_1 + sw $t1, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -4($fp) + j label_print_list_at_Cons_2 +label_print_list_at_Cons_2: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -48($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -44($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -44($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Cons_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Cons_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Cons + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Cons + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_BookList + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_print_list_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Nil_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Nil_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Nil + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Nil + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_BookList + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -76 + + #init allocate + + li $v0, 9 + lw $a0, Book_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Book + sw $a0, -12($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -16($fp) + la $t1, _empty + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -24($fp) + + #init allocate + + li $v0, 9 + lw $a0, Article_size + syscall + sw $v0, -32($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Article + sw $a0, -36($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -40($fp) + la $t1, _empty + sw $t1, -44($fp) + la $t1, _empty + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -32($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + lw $t1, -28($fp) + sw $t1, -52($fp) + + #init allocate + + li $v0, 9 + lw $a0, Nil_size + syscall + sw $v0, -64($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Nil + sw $a0, -68($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, a_book + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -64($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -60($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, an_article + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -60($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -56($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -56($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -76($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -76($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -76($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -72($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -72($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 88 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/cells.mips b/tests/codegen/cells.mips new file mode 100644 index 000000000..be1d9467c --- /dev/null +++ b/tests/codegen/cells.mips @@ -0,0 +1,1685 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + CellularAutomaton_name: .asciiz "CellularAutomaton" + CellularAutomaton_size: .word 16 +__virtual_table__CellularAutomaton: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_init_at_CellularAutomaton + .word function_print_at_CellularAutomaton + .word function_num_cells_at_CellularAutomaton + .word function_cell_at_CellularAutomaton + .word function_cell_left_neighbor_at_CellularAutomaton + .word function_cell_right_neighbor_at_CellularAutomaton + .word function_cell_at_next_evolution_at_CellularAutomaton + .word function_evolve_at_CellularAutomaton + Main_name: .asciiz "Main" + Main_size: .word 16 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_init_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_print_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -12($fp) + la $t1, data_1 + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_concat_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_num_cells_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_cell_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_cell_left_neighbor_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -32 + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -8($fp) + lw $a0, -8($fp) + bne $a0, $zero, label_cell_left_neighbor_at_CellularAutomaton_0 + li $t1, 1 + sw $t1, -4($fp) + j label_cell_left_neighbor_at_CellularAutomaton_1 +label_cell_left_neighbor_at_CellularAutomaton_0: + li $t1, 0 + sw $t1, -4($fp) +label_cell_left_neighbor_at_CellularAutomaton_1: + lw $a0, -4($fp) + bne $a0, $zero, label_cell_left_neighbor_at_CellularAutomaton_2 + lw $t1, 8($fp) + li $a0, 1 + blt $t1, $a0, label_cell_left_neighbor_at_CellularAutomaton_4 + li $a0, 0 + j label_cell_left_neighbor_at_CellularAutomaton_5 +label_cell_left_neighbor_at_CellularAutomaton_4: + li $a0, 1 +label_cell_left_neighbor_at_CellularAutomaton_5: + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -16($fp) + lw $t1, -16($fp) + sw $t1, -12($fp) + j label_cell_left_neighbor_at_CellularAutomaton_3 +label_cell_left_neighbor_at_CellularAutomaton_2: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -32($fp) + lw $t1, -32($fp) + li $a0, 1 + blt $t1, $a0, label_cell_left_neighbor_at_CellularAutomaton_6 + li $a0, 0 + j label_cell_left_neighbor_at_CellularAutomaton_7 +label_cell_left_neighbor_at_CellularAutomaton_6: + li $a0, 1 +label_cell_left_neighbor_at_CellularAutomaton_7: + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -24($fp) + lw $t1, -24($fp) + sw $t1, -12($fp) +label_cell_left_neighbor_at_CellularAutomaton_3: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 48 + lw $fp, 0($sp) + jr $ra +function_cell_right_neighbor_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -32 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -12($fp) + lw $t1, -12($fp) + li $a0, 1 + blt $t1, $a0, label_cell_right_neighbor_at_CellularAutomaton_0 + li $a0, 0 + j label_cell_right_neighbor_at_CellularAutomaton_1 +label_cell_right_neighbor_at_CellularAutomaton_0: + li $a0, 1 +label_cell_right_neighbor_at_CellularAutomaton_1: + sw $a0, -8($fp) + lw $t1, 8($fp) + lw $a0, -8($fp) + sub $a0, $t1, $a0 + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_cell_right_neighbor_at_CellularAutomaton_2 + li $t1, 1 + sw $t1, -4($fp) + j label_cell_right_neighbor_at_CellularAutomaton_3 +label_cell_right_neighbor_at_CellularAutomaton_2: + li $t1, 0 + sw $t1, -4($fp) +label_cell_right_neighbor_at_CellularAutomaton_3: + lw $a0, -4($fp) + bne $a0, $zero, label_cell_right_neighbor_at_CellularAutomaton_4 + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -24($fp) + lw $t1, -24($fp) + sw $t1, -20($fp) + j label_cell_right_neighbor_at_CellularAutomaton_5 +label_cell_right_neighbor_at_CellularAutomaton_4: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -32($fp) + lw $t1, -32($fp) + sw $t1, -20($fp) +label_cell_right_neighbor_at_CellularAutomaton_5: + + #retornando el valor + + lw $a0, -20($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 48 + lw $fp, 0($sp) + jr $ra +function_cell_at_next_evolution_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -76 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -20($fp) + la $t1, _empty + sw $t1, -24($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_0 + li $t1, 0 + sw $t1, -28($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_1 +label_cell_at_next_evolution_at_CellularAutomaton_0: + li $t1, 1 + sw $t1, -28($fp) +label_cell_at_next_evolution_at_CellularAutomaton_1: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -36($fp) + la $t1, _empty + sw $t1, -40($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -32($fp) + lw $a0, -32($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_2 + li $t1, 0 + sw $t1, -44($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_3 +label_cell_at_next_evolution_at_CellularAutomaton_2: + li $t1, 1 + sw $t1, -44($fp) +label_cell_at_next_evolution_at_CellularAutomaton_3: + lw $t1, -28($fp) + lw $a0, -44($fp) + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -52($fp) + la $t1, _empty + sw $t1, -56($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -52($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -48($fp) + lw $a0, -48($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_4 + li $t1, 0 + sw $t1, -60($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_5 +label_cell_at_next_evolution_at_CellularAutomaton_4: + li $t1, 1 + sw $t1, -60($fp) +label_cell_at_next_evolution_at_CellularAutomaton_5: + lw $t1, -12($fp) + lw $a0, -60($fp) + add $a0, $a0, $t1 + sw $a0, -8($fp) + lw $t1, -8($fp) + li $a0, 1 + sub $a0, $t1, $a0 + sw $a0, -64($fp) + lw $a0, -64($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_6 + li $t1, 1 + sw $t1, -4($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_7 +label_cell_at_next_evolution_at_CellularAutomaton_6: + li $t1, 0 + sw $t1, -4($fp) +label_cell_at_next_evolution_at_CellularAutomaton_7: + lw $a0, -4($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_8 + la $t1, _empty + sw $t1, -72($fp) + lw $t1, -72($fp) + sw $t1, -68($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_9 +label_cell_at_next_evolution_at_CellularAutomaton_8: + la $t1, _empty + sw $t1, -76($fp) + lw $t1, -76($fp) + sw $t1, -68($fp) +label_cell_at_next_evolution_at_CellularAutomaton_9: + + #retornando el valor + + lw $a0, -68($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 92 + lw $fp, 0($sp) + jr $ra +function_evolve_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -36 + li $t1, 0 + sw $t1, -4($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -12($fp) + la $t1, _empty + sw $t1, -16($fp) + lw $t1, -16($fp) + sw $t1, -20($fp) +label_evolve_at_CellularAutomaton_0: + li $a0, [] + bne $a0, $zero, label_evolve_at_CellularAutomaton_1 + j label_evolve_at_CellularAutomaton_2 +label_evolve_at_CellularAutomaton_1: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, position + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 52($a0) + jalr $a0 + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, temp + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_concat_at_String + sw $a0, -24($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + sw $t1, -20($fp) + li $t1, position + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -32($fp) + lw $t1, -32($fp) + sw $t1, -4($fp) + j label_evolve_at_CellularAutomaton_0 +label_evolve_at_CellularAutomaton_2: + la $t1, _void + sw $t1, -36($fp) + + #init set attribute + + lw $a0, 4($fp) + li $t1, temp + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 48 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, CellularAutomaton_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, CellularAutomaton_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__CellularAutomaton + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_CellularAutomaton + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -52 + + #init allocate + + li $v0, 9 + lw $a0, CellularAutomaton_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_CellularAutomaton + sw $a0, -12($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -4($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -24($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -20($fp) + + #fin llamada dinamica + + li $t1, 20 + sw $t1, -28($fp) +label_main_at_Main_0: + li $a0, [] + bne $a0, $zero, label_main_at_Main_1 + j label_main_at_Main_2 +label_main_at_Main_1: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -36($fp) + lw $a0, 8($a0) + lw $a0, 56($a0) + jalr $a0 + sw $a0, -32($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -44($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -40($fp) + + #fin llamada dinamica + + li $t1, countdown + li $a0, 1 + blt $t1, $a0, label_main_at_Main_3 + li $a0, 0 + j label_main_at_Main_4 +label_main_at_Main_3: + li $a0, 1 +label_main_at_Main_4: + sw $a0, -48($fp) + lw $t1, -48($fp) + sw $t1, -28($fp) + j label_main_at_Main_0 +label_main_at_Main_2: + la $t1, _void + sw $t1, -52($fp) + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 64 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/complex.mips b/tests/codegen/complex.mips new file mode 100644 index 000000000..a208e60e7 --- /dev/null +++ b/tests/codegen/complex.mips @@ -0,0 +1,1413 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Main_name: .asciiz "Main" + Main_size: .word 12 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_main_at_Main + Complex_name: .asciiz "Complex" + Complex_size: .word 20 +__virtual_table__Complex: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_init_at_Complex + .word function_print_at_Complex + .word function_reflect_0_at_Complex + .word function_reflect_X_at_Complex + .word function_reflect_Y_at_Complex + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 28($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -56 + + #init allocate + + li $v0, 9 + lw $a0, Complex_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Complex + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, c + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -28($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, c + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -32($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + lw $a0, -32($fp) + sub $a0, $t1, $a0 + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_main_at_Main_0 + li $t1, 1 + sw $t1, -20($fp) + j label_main_at_Main_1 +label_main_at_Main_0: + li $t1, 0 + sw $t1, -20($fp) +label_main_at_Main_1: + lw $a0, -20($fp) + bne $a0, $zero, label_main_at_Main_2 + la $t1, data_1 + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -44($fp) + lw $t1, -44($fp) + sw $t1, -40($fp) + j label_main_at_Main_3 +label_main_at_Main_2: + la $t1, data_1 + sw $t1, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -52($fp) + lw $t1, -52($fp) + sw $t1, -40($fp) +label_main_at_Main_3: + + #retornando el valor + + lw $a0, -40($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 68 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_init_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -24 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + lw $t1, -8($fp) + lw $a0, 8($fp) + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_init_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_init_at_Complex_1 +label_init_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_init_at_Complex_1: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -20($fp) + lw $t1, -20($fp) + lw $a0, 12($fp) + sub $a0, $t1, $a0 + sw $a0, -24($fp) + lw $a0, -24($fp) + bne $a0, $zero, label_init_at_Complex_2 + li $t1, 1 + sw $t1, -16($fp) + j label_init_at_Complex_3 +label_init_at_Complex_2: + li $t1, 0 + sw $t1, -16($fp) +label_init_at_Complex_3: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 44 + lw $fp, 0($sp) + jr $ra +function_print_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -56 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -8($fp) + lw $t1, -8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_print_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_print_at_Complex_1 +label_print_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_print_at_Complex_1: + lw $a0, -4($fp) + bne $a0, $zero, label_print_at_Complex_2 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -32($fp) + la $t1, _empty + sw $t1, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -32($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -28($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -24($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -20($fp) + + #fin llamada dinamica + + lw $t1, -20($fp) + sw $t1, -16($fp) + j label_print_at_Complex_3 +label_print_at_Complex_2: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -52($fp) + lw $t1, -52($fp) + sw $t1, -16($fp) +label_print_at_Complex_3: + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 68 + lw $fp, 0($sp) + jr $ra +function_reflect_0_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -12($fp) + lw $t1, -8($fp) + lw $a0, -12($fp) + sub $a0, $t1, $a0 + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_reflect_0_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_reflect_0_at_Complex_1 +label_reflect_0_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_reflect_0_at_Complex_1: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -28($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -36($fp) + lw $t1, -36($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -32($fp) + lw $t1, -28($fp) + lw $a0, -32($fp) + sub $a0, $t1, $a0 + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_reflect_0_at_Complex_2 + li $t1, 1 + sw $t1, -24($fp) + j label_reflect_0_at_Complex_3 +label_reflect_0_at_Complex_2: + li $t1, 0 + sw $t1, -24($fp) +label_reflect_0_at_Complex_3: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 52 + lw $fp, 0($sp) + jr $ra +function_reflect_X_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -12($fp) + lw $t1, -8($fp) + lw $a0, -12($fp) + sub $a0, $t1, $a0 + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_reflect_X_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_reflect_X_at_Complex_1 +label_reflect_X_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_reflect_X_at_Complex_1: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra +function_reflect_Y_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -12($fp) + lw $t1, -8($fp) + lw $a0, -12($fp) + sub $a0, $t1, $a0 + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_reflect_Y_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_reflect_Y_at_Complex_1 +label_reflect_Y_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_reflect_Y_at_Complex_1: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Complex_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Complex_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Complex + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Complex + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/fib.mips b/tests/codegen/fib.mips new file mode 100644 index 000000000..0e2815e03 --- /dev/null +++ b/tests/codegen/fib.mips @@ -0,0 +1,859 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Main_name: .asciiz "Main" + Main_size: .word 12 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_main_at_Main + .word function_fib_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 28($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -28 + la $t1, data_1 + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + la $t1, data_1 + sw $t1, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -24($fp) + + #retornando el valor + + lw $a0, -24($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_fib_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -36 + li $t1, 1 + sw $t1, -4($fp) + li $t1, 0 + sw $t1, -8($fp) + li $t1, 0 + sw $t1, -12($fp) +label_fib_at_Main_0: + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -24($fp) + lw $a0, -24($fp) + bne $a0, $zero, label_fib_at_Main_3 + li $t1, 1 + sw $t1, -20($fp) + j label_fib_at_Main_4 +label_fib_at_Main_3: + li $t1, 0 + sw $t1, -20($fp) +label_fib_at_Main_4: + lw $a0, -20($fp) + bne $a0, $zero, label_fib_at_Main_5 + li $t1, 1 + sw $t1, -16($fp) + j label_fib_at_Main_6 +label_fib_at_Main_5: + li $t1, 0 + sw $t1, -16($fp) +label_fib_at_Main_6: + lw $a0, -16($fp) + bne $a0, $zero, label_fib_at_Main_1 + j label_fib_at_Main_2 +label_fib_at_Main_1: + li $t1, a + li $a0, b + add $a0, $a0, $t1 + sw $a0, -28($fp) + lw $t1, -28($fp) + sw $t1, -12($fp) + lw $t1, 8($fp) + li $a0, 1 + blt $t1, $a0, label_fib_at_Main_7 + li $a0, 0 + j label_fib_at_Main_8 +label_fib_at_Main_7: + li $a0, 1 +label_fib_at_Main_8: + sw $a0, -32($fp) + lw $t1, -32($fp) + sw $t1, 8($fp) + li $t1, a + sw $t1, -8($fp) + li $t1, c + sw $t1, -4($fp) + j label_fib_at_Main_0 +label_fib_at_Main_2: + la $t1, _void + sw $t1, -36($fp) + + #retornando el valor + + li $a0, c + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 52 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/graph.mips b/tests/codegen/graph.mips new file mode 100644 index 000000000..54a974dc2 --- /dev/null +++ b/tests/codegen/graph.mips @@ -0,0 +1,4993 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Graph_name: .asciiz "Graph" + Graph_size: .word 20 +__virtual_table__Graph: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_add_vertice_at_Graph + .word function_print_E_at_Graph + .word function_print_V_at_Graph + Vertice_name: .asciiz "Vertice" + Vertice_size: .word 20 +__virtual_table__Vertice: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_outgoing_at_Vertice + .word function_number_at_Vertice + .word function_init_at_Vertice + .word function_add_out_at_Vertice + .word function_print_at_Vertice + Edge_name: .asciiz "Edge" + Edge_size: .word 24 +__virtual_table__Edge: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_init_at_Edge + .word function_print_at_Edge + EList_name: .asciiz "EList" + EList_size: .word 16 +__virtual_table__EList: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_EList + .word function_head_at_EList + .word function_tail_at_EList + .word function_cons_at_EList + .word function_append_at_EList + .word function_print_at_EList + ECons_name: .asciiz "ECons" + ECons_size: .word 20 +__virtual_table__ECons: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_ECons + .word function_head_at_ECons + .word function_tail_at_ECons + .word function_cons_at_EList + .word function_append_at_EList + .word function_print_at_ECons + .word function_init_at_ECons + VList_name: .asciiz "VList" + VList_size: .word 16 +__virtual_table__VList: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_VList + .word function_head_at_VList + .word function_tail_at_VList + .word function_cons_at_VList + .word function_print_at_VList + VCons_name: .asciiz "VCons" + VCons_size: .word 20 +__virtual_table__VCons: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_VCons + .word function_head_at_VCons + .word function_tail_at_VCons + .word function_cons_at_VList + .word function_print_at_VCons + .word function_init_at_VCons + Parse_name: .asciiz "Parse" + Parse_size: .word 20 +__virtual_table__Parse: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_read_input_at_Parse + .word function_parse_line_at_Parse + .word function_c2i_at_Parse + .word function_a2i_at_Parse + .word function_a2i_aux_at_Parse + Main_name: .asciiz "Main" + Main_size: .word 24 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_read_input_at_Parse + .word function_parse_line_at_Parse + .word function_c2i_at_Parse + .word function_a2i_at_Parse + .word function_a2i_aux_at_Parse + .word function_main_at_Main + BoolOp_name: .asciiz "BoolOp" + BoolOp_size: .word 12 +__virtual_table__BoolOp: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_and_at_BoolOp + .word function_or_at_BoolOp + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 48($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_add_vertice_at_Graph: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, 8($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -8($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -4($fp) + sw $t1, 16($a0) + + #end set attribute + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -16($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_print_E_at_Graph: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_print_V_at_Graph: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Graph: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Graph_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Graph_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Graph + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Graph + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Graph: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _void + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 12($a0) + + #end set attribute + + la $t1, _void + sw $t1, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 16($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_outgoing_at_Vertice: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_number_at_Vertice: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_init_at_Vertice: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_add_out_at_Vertice: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -4($fp) + sw $t1, 16($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_print_at_Vertice: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -4($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Vertice: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Vertice_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Vertice_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Vertice + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Vertice + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Vertice: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_init_at_Edge: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 12($fp) + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 16($fp) + sw $t1, 20($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_print_at_Edge: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + la $t1, _empty + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + la $t1, _empty + sw $t1, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -20($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -28($fp) + la $t1, _empty + sw $t1, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -36($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 20($a0) + sw $a0, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -44($fp) + + #retornando el valor + + lw $a0, -44($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Edge: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Edge_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Edge_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Edge + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Edge + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Edge: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_EList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_head_at_EList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_tail_at_EList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_cons_at_EList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, ECons_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_ECons + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 52($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_append_at_EList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -24 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + lw $a0, -4($fp) + bne $a0, $zero, label_append_at_EList_0 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + lw $t1, -12($fp) + sw $t1, -8($fp) + j label_append_at_EList_1 +label_append_at_EList_0: + lw $t1, 8($fp) + sw $t1, -8($fp) +label_append_at_EList_1: + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_print_at_EList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + la $t1, data_1 + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_EList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, EList_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, EList_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__EList + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_EList + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_EList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_ECons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_head_at_ECons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_tail_at_ECons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_init_at_ECons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 12($fp) + sw $t1, 16($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_print_at_ECons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_ECons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, ECons_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, ECons_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__ECons + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_ECons + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_ECons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_EList + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_VList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_head_at_VList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_tail_at_VList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_cons_at_VList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, VCons_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_VCons + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_print_at_VList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + la $t1, data_1 + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_VList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, VList_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, VList_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__VList + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_VList + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_VList: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_VCons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_head_at_VCons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_tail_at_VCons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_init_at_VCons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 12($fp) + sw $t1, 16($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_print_at_VCons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_VCons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, VCons_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, VCons_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__VCons + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_VCons + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_VCons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_VList + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_read_input_at_Parse: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -68 + + #init allocate + + li $v0, 9 + lw $a0, Graph_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Graph + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -16($fp) + lw $t1, -16($fp) + sw $t1, -20($fp) +label_read_input_at_Parse_0: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -28($fp) + la $t1, data_1 + sw $t1, -40($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, None + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_read_input_at_Parse_3 + li $t1, 1 + sw $t1, -32($fp) + j label_read_input_at_Parse_4 +label_read_input_at_Parse_3: + li $t1, 0 + sw $t1, -32($fp) +label_read_input_at_Parse_4: + la $t1, _empty + sw $t1, -52($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, None + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -52($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -48($fp) + lw $a0, -48($fp) + bne $a0, $zero, label_read_input_at_Parse_5 + li $t1, 1 + sw $t1, -44($fp) + j label_read_input_at_Parse_6 +label_read_input_at_Parse_5: + li $t1, 0 + sw $t1, -44($fp) +label_read_input_at_Parse_6: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -28($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + lw $a0, -24($fp) + bne $a0, $zero, label_read_input_at_Parse_1 + j label_read_input_at_Parse_2 +label_read_input_at_Parse_1: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, line + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -60($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, g + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -56($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -64($fp) + lw $t1, -64($fp) + sw $t1, -20($fp) + j label_read_input_at_Parse_0 +label_read_input_at_Parse_2: + la $t1, _void + sw $t1, -68($fp) + + #retornando el valor + + li $a0, g + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 80 + lw $fp, 0($sp) + jr $ra +function_parse_line_at_Parse: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -88 + + #init allocate + + li $v0, 9 + lw $a0, Vertice_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Vertice + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -20($fp) +label_parse_line_at_Parse_0: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -32($fp) + + #fin llamada dinamica + + lw $t1, -32($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_parse_line_at_Parse_3 + li $t1, 1 + sw $t1, -28($fp) + j label_parse_line_at_Parse_4 +label_parse_line_at_Parse_3: + li $t1, 0 + sw $t1, -28($fp) +label_parse_line_at_Parse_4: + lw $a0, -28($fp) + bne $a0, $zero, label_parse_line_at_Parse_5 + li $t1, 1 + sw $t1, -24($fp) + j label_parse_line_at_Parse_6 +label_parse_line_at_Parse_5: + li $t1, 0 + sw $t1, -24($fp) +label_parse_line_at_Parse_6: + lw $a0, -24($fp) + bne $a0, $zero, label_parse_line_at_Parse_1 + j label_parse_line_at_Parse_2 +label_parse_line_at_Parse_1: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -44($fp) + lw $t1, -44($fp) + sw $t1, -52($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -60($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -56($fp) + lw $t1, -56($fp) + sw $t1, -64($fp) + + #init allocate + + li $v0, 9 + lw $a0, Edge_size + syscall + sw $v0, -76($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -76($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Edge + sw $a0, -80($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, v + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -84($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, weight + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, succ + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -84($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -76($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -76($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -72($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -72($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, v + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -68($fp) + + #fin llamada dinamica + + j label_parse_line_at_Parse_0 +label_parse_line_at_Parse_2: + la $t1, _void + sw $t1, -88($fp) + + #retornando el valor + + li $a0, v + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 104 + lw $fp, 0($sp) + jr $ra +function_c2i_at_Parse: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -124 + la $t1, _empty + sw $t1, -8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -4($fp) + lw $a0, -4($fp) + bne $a0, $zero, label_c2i_at_Parse_0 + la $t1, _empty + sw $t1, -20($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_c2i_at_Parse_2 + la $t1, _empty + sw $t1, -32($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_c2i_at_Parse_4 + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_c2i_at_Parse_6 + la $t1, _empty + sw $t1, -56($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -52($fp) + lw $a0, -52($fp) + bne $a0, $zero, label_c2i_at_Parse_8 + la $t1, _empty + sw $t1, -68($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -64($fp) + lw $a0, -64($fp) + bne $a0, $zero, label_c2i_at_Parse_10 + la $t1, _empty + sw $t1, -80($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -76($fp) + lw $a0, -76($fp) + bne $a0, $zero, label_c2i_at_Parse_12 + la $t1, _empty + sw $t1, -92($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -92($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -88($fp) + lw $a0, -88($fp) + bne $a0, $zero, label_c2i_at_Parse_14 + la $t1, _empty + sw $t1, -104($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -104($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -100($fp) + lw $a0, -100($fp) + bne $a0, $zero, label_c2i_at_Parse_16 + la $t1, _empty + sw $t1, -116($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -116($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -112($fp) + lw $a0, -112($fp) + bne $a0, $zero, label_c2i_at_Parse_18 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -124($fp) + li $t1, 0 + sw $t1, -120($fp) + j label_c2i_at_Parse_19 +label_c2i_at_Parse_18: + li $t1, 9 + sw $t1, -120($fp) +label_c2i_at_Parse_19: + lw $t1, -120($fp) + sw $t1, -108($fp) + j label_c2i_at_Parse_17 +label_c2i_at_Parse_16: + li $t1, 8 + sw $t1, -108($fp) +label_c2i_at_Parse_17: + lw $t1, -108($fp) + sw $t1, -96($fp) + j label_c2i_at_Parse_15 +label_c2i_at_Parse_14: + li $t1, 7 + sw $t1, -96($fp) +label_c2i_at_Parse_15: + lw $t1, -96($fp) + sw $t1, -84($fp) + j label_c2i_at_Parse_13 +label_c2i_at_Parse_12: + li $t1, 6 + sw $t1, -84($fp) +label_c2i_at_Parse_13: + lw $t1, -84($fp) + sw $t1, -72($fp) + j label_c2i_at_Parse_11 +label_c2i_at_Parse_10: + li $t1, 5 + sw $t1, -72($fp) +label_c2i_at_Parse_11: + lw $t1, -72($fp) + sw $t1, -60($fp) + j label_c2i_at_Parse_9 +label_c2i_at_Parse_8: + li $t1, 4 + sw $t1, -60($fp) +label_c2i_at_Parse_9: + lw $t1, -60($fp) + sw $t1, -48($fp) + j label_c2i_at_Parse_7 +label_c2i_at_Parse_6: + li $t1, 3 + sw $t1, -48($fp) +label_c2i_at_Parse_7: + lw $t1, -48($fp) + sw $t1, -36($fp) + j label_c2i_at_Parse_5 +label_c2i_at_Parse_4: + li $t1, 2 + sw $t1, -36($fp) +label_c2i_at_Parse_5: + lw $t1, -36($fp) + sw $t1, -24($fp) + j label_c2i_at_Parse_3 +label_c2i_at_Parse_2: + li $t1, 1 + sw $t1, -24($fp) +label_c2i_at_Parse_3: + lw $t1, -24($fp) + sw $t1, -12($fp) + j label_c2i_at_Parse_1 +label_c2i_at_Parse_0: + li $t1, 0 + sw $t1, -12($fp) +label_c2i_at_Parse_1: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 140 + lw $fp, 0($sp) + jr $ra +function_a2i_at_Parse: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -88 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_a2i_at_Parse_0 + li $t1, 1 + sw $t1, -4($fp) + j label_a2i_at_Parse_1 +label_a2i_at_Parse_0: + li $t1, 0 + sw $t1, -4($fp) +label_a2i_at_Parse_1: + lw $a0, -4($fp) + bne $a0, $zero, label_a2i_at_Parse_2 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -24($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -28($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_a2i_at_Parse_4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -40($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_a2i_at_Parse_6 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -52($fp) + lw $t1, -52($fp) + sw $t1, -48($fp) + j label_a2i_at_Parse_7 +label_a2i_at_Parse_6: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -68($fp) + + #fin llamada dinamica + + lw $t1, -68($fp) + li $a0, 1 + blt $t1, $a0, label_a2i_at_Parse_8 + li $a0, 0 + j label_a2i_at_Parse_9 +label_a2i_at_Parse_8: + li $a0, 1 +label_a2i_at_Parse_9: + sw $a0, -64($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -60($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -56($fp) + lw $t1, -56($fp) + sw $t1, -48($fp) +label_a2i_at_Parse_7: + lw $t1, -48($fp) + sw $t1, -32($fp) + j label_a2i_at_Parse_5 +label_a2i_at_Parse_4: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -88($fp) + + #fin llamada dinamica + + lw $t1, -88($fp) + li $a0, 1 + blt $t1, $a0, label_a2i_at_Parse_10 + li $a0, 0 + j label_a2i_at_Parse_11 +label_a2i_at_Parse_10: + li $a0, 1 +label_a2i_at_Parse_11: + sw $a0, -84($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -84($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -80($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -76($fp) + lw $t1, -76($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -72($fp) + lw $t1, -72($fp) + sw $t1, -32($fp) +label_a2i_at_Parse_5: + lw $t1, -32($fp) + sw $t1, -16($fp) + j label_a2i_at_Parse_3 +label_a2i_at_Parse_2: + li $t1, 0 + sw $t1, -16($fp) +label_a2i_at_Parse_3: + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 104 + lw $fp, 0($sp) + jr $ra +function_a2i_aux_at_Parse: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -132 + li $t1, 0 + sw $t1, -4($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + sw $t1, -12($fp) + li $t1, 0 + sw $t1, -16($fp) +label_a2i_aux_at_Parse_0: + li $a0, [] + bne $a0, $zero, label_a2i_aux_at_Parse_1 + j label_a2i_aux_at_Parse_2 +label_a2i_aux_at_Parse_1: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, i + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -20($fp) + + #fin llamada dinamica + + lw $t1, -20($fp) + sw $t1, -24($fp) + la $t1, _empty + sw $t1, -32($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, None + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_a2i_aux_at_Parse_3 + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, None + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_a2i_aux_at_Parse_5 + li $t1, int + li $a0, 10 + mul $a0 $t1 $a0 + sw $a0, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, i + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -64($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -60($fp) + lw $t1, -56($fp) + lw $a0, -60($fp) + add $a0, $a0, $t1 + sw $a0, -52($fp) + lw $t1, -52($fp) + sw $t1, -4($fp) + li $t1, i + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -68($fp) + lw $t1, -68($fp) + sw $t1, -16($fp) + li $t1, i + li $a0, j + sub $a0, $t1, $a0 + sw $a0, -76($fp) + lw $a0, -76($fp) + bne $a0, $zero, label_a2i_aux_at_Parse_7 + li $t1, 1 + sw $t1, -72($fp) + j label_a2i_aux_at_Parse_8 +label_a2i_aux_at_Parse_7: + li $t1, 0 + sw $t1, -72($fp) +label_a2i_aux_at_Parse_8: + lw $a0, -72($fp) + bne $a0, $zero, label_a2i_aux_at_Parse_9 + la $t1, _empty + sw $t1, -84($fp) + lw $t1, -84($fp) + sw $t1, -80($fp) + j label_a2i_aux_at_Parse_10 +label_a2i_aux_at_Parse_9: + la $t1, _empty + sw $t1, -88($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -88($fp) + sw $t1, 16($a0) + + #end set attribute + + lw $t1, -88($fp) + sw $t1, -80($fp) +label_a2i_aux_at_Parse_10: + lw $t1, -80($fp) + sw $t1, -48($fp) + j label_a2i_aux_at_Parse_6 +label_a2i_aux_at_Parse_5: + li $t1, i + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -96($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -108($fp) + + #fin llamada dinamica + + lw $t1, -108($fp) + li $a0, i + blt $t1, $a0, label_a2i_aux_at_Parse_11 + li $a0, 0 + j label_a2i_aux_at_Parse_12 +label_a2i_aux_at_Parse_11: + li $a0, 1 +label_a2i_aux_at_Parse_12: + sw $a0, -104($fp) + lw $t1, -104($fp) + li $a0, 1 + blt $t1, $a0, label_a2i_aux_at_Parse_13 + li $a0, 0 + j label_a2i_aux_at_Parse_14 +label_a2i_aux_at_Parse_13: + li $a0, 1 +label_a2i_aux_at_Parse_14: + sw $a0, -100($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -100($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -96($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -92($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -92($fp) + sw $t1, 16($a0) + + #end set attribute + + li $t1, j + sw $t1, -16($fp) + li $t1, j + sw $t1, -48($fp) +label_a2i_aux_at_Parse_6: + lw $t1, -48($fp) + sw $t1, -36($fp) + j label_a2i_aux_at_Parse_4 +label_a2i_aux_at_Parse_3: + li $t1, i + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -116($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -128($fp) + + #fin llamada dinamica + + lw $t1, -128($fp) + li $a0, i + blt $t1, $a0, label_a2i_aux_at_Parse_15 + li $a0, 0 + j label_a2i_aux_at_Parse_16 +label_a2i_aux_at_Parse_15: + li $a0, 1 +label_a2i_aux_at_Parse_16: + sw $a0, -124($fp) + lw $t1, -124($fp) + li $a0, 1 + blt $t1, $a0, label_a2i_aux_at_Parse_17 + li $a0, 0 + j label_a2i_aux_at_Parse_18 +label_a2i_aux_at_Parse_17: + li $a0, 1 +label_a2i_aux_at_Parse_18: + sw $a0, -120($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -120($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -116($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -112($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -112($fp) + sw $t1, 16($a0) + + #end set attribute + + li $t1, j + sw $t1, -16($fp) + li $t1, j + sw $t1, -36($fp) +label_a2i_aux_at_Parse_4: + j label_a2i_aux_at_Parse_0 +label_a2i_aux_at_Parse_2: + la $t1, _void + sw $t1, -132($fp) + + #retornando el valor + + li $a0, int + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 148 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Parse: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Parse_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Parse_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Parse + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Parse + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Parse: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _void + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 20($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 20($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Parse + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _void + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 20($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_and_at_BoolOp: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + lw $a0, 8($fp) + bne $a0, $zero, label_and_at_BoolOp_0 + li $t1, 0 + sw $t1, -4($fp) + j label_and_at_BoolOp_1 +label_and_at_BoolOp_0: + lw $t1, 12($fp) + sw $t1, -4($fp) +label_and_at_BoolOp_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_or_at_BoolOp: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + lw $a0, 8($fp) + bne $a0, $zero, label_or_at_BoolOp_0 + lw $t1, 12($fp) + sw $t1, -4($fp) + j label_or_at_BoolOp_1 +label_or_at_BoolOp_0: + li $t1, 1 + sw $t1, -4($fp) +label_or_at_BoolOp_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_BoolOp: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, BoolOp_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, BoolOp_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__BoolOp + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_BoolOp + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_BoolOp: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/hairyscary.mips b/tests/codegen/hairyscary.mips new file mode 100644 index 000000000..26c26daa5 --- /dev/null +++ b/tests/codegen/hairyscary.mips @@ -0,0 +1,1507 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Foo_name: .asciiz "Foo" + Foo_size: .word 32 +__virtual_table__Foo: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_printh_at_Bazz + .word function_doh_at_Foo + Bar_name: .asciiz "Bar" + Bar_size: .word 48 +__virtual_table__Bar: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_printh_at_Bazz + .word function_doh_at_Foo + Razz_name: .asciiz "Razz" + Razz_size: .word 40 +__virtual_table__Razz: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_printh_at_Bazz + .word function_doh_at_Foo + Bazz_name: .asciiz "Bazz" + Bazz_size: .word 24 +__virtual_table__Bazz: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_printh_at_Bazz + .word function_doh_at_Bazz + Main_name: .asciiz "Main" + Main_size: .word 28 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_main_at_Main + _empty: .asciiz "" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_doh_at_Foo: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + lw $t1, -4($fp) + sw $t1, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $a0, 2 + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + li $a0, i + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Foo: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Foo_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Foo_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Foo + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Foo + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Foo: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -28 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Bazz + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 24($a0) + + #end set attribute + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -24($fp) + lw $t1, -20($fp) + lw $a0, -24($fp) + add $a0, $a0, $t1 + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -16($fp) + lw $a0, -28($fp) + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 28($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Bar: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Bar_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Bar_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Bar + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Bar + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Bar: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Razz + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 40($a0) + + #end set attribute + + la $t1, _void + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 44($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Razz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Razz_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Razz_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Razz + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Razz + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Razz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -36 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Foo + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 32($a0) + + #end set attribute + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, e + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + lw $a0, -28($fp) + add $a0, $a0, $t1 + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -32($fp) + lw $t1, -20($fp) + lw $a0, -32($fp) + add $a0, $a0, $t1 + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -16($fp) + lw $a0, -36($fp) + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 36($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 48 + lw $fp, 0($sp) + jr $ra +function_printh_at_Bazz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_doh_at_Bazz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + lw $t1, -4($fp) + sw $t1, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + li $a0, i + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Bazz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Bazz_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Bazz_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Bazz + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Bazz + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Bazz: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 16($a0) + + #end set attribute + + la $t1, _void + sw $t1, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 20($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + la $t1, _empty + sw $t1, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _void + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 12($a0) + + #end set attribute + + la $t1, _void + sw $t1, -12($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -12($fp) + sw $t1, 16($a0) + + #end set attribute + + la $t1, _void + sw $t1, -16($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -16($fp) + sw $t1, 20($a0) + + #end set attribute + + la $t1, _void + sw $t1, -20($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -20($fp) + sw $t1, 24($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/hello_world.mips b/tests/codegen/hello_world.mips new file mode 100644 index 000000000..a205ae8c1 --- /dev/null +++ b/tests/codegen/hello_world.mips @@ -0,0 +1,703 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Main_name: .asciiz "Main" + Main_size: .word 12 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 28($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + la $t1, data_1 + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/io.mips b/tests/codegen/io.mips new file mode 100644 index 000000000..187646bcf --- /dev/null +++ b/tests/codegen/io.mips @@ -0,0 +1,1552 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + A_name: .asciiz "A" + A_size: .word 16 +__virtual_table__A: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_a_at_A + B_name: .asciiz "B" + B_size: .word 16 +__virtual_table__B: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_a_at_A + .word function_out_b_at_B + C_name: .asciiz "C" + C_size: .word 12 +__virtual_table__C: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_out_c_at_C + D_name: .asciiz "D" + D_size: .word 12 +__virtual_table__D: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_out_c_at_C + .word function_out_d_at_D + Main_name: .asciiz "Main" + Main_size: .word 12 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 28($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_out_a_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + la $t1, data_1 + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, A_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, A_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__A + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_A + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_A: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, _void + sw $t1, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_out_b_at_B: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + la $t1, data_1 + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_B: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, B_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, B_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__B + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_B + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_B: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_A + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_out_c_at_C: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + la $t1, data_1 + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_C: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, C_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, C_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__C + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_C + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_C: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_out_d_at_D: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + la $t1, data_1 + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_D: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, D_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, D_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__D + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_D + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_D: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_C + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -56 + + #init allocate + + li $v0, 9 + lw $a0, A_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_A + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init allocate + + li $v0, 9 + lw $a0, B_size + syscall + sw $v0, -20($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_B + sw $a0, -24($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #init allocate + + li $v0, 9 + lw $a0, C_size + syscall + sw $v0, -32($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_C + sw $a0, -36($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -32($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + + #init allocate + + li $v0, 9 + lw $a0, D_size + syscall + sw $v0, -44($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_D + sw $a0, -48($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -44($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -40($fp) + + #fin llamada dinamica + + la $t1, data_1 + sw $t1, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -52($fp) + + #retornando el valor + + lw $a0, -52($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 68 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/life.mips b/tests/codegen/life.mips new file mode 100644 index 000000000..f738f9597 --- /dev/null +++ b/tests/codegen/life.mips @@ -0,0 +1,4673 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Board_name: .asciiz "Board" + Board_size: .word 24 +__virtual_table__Board: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_size_of_board_at_Board + .word function_board_init_at_Board + CellularAutomaton_name: .asciiz "CellularAutomaton" + CellularAutomaton_size: .word 28 +__virtual_table__CellularAutomaton: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_size_of_board_at_Board + .word function_board_init_at_Board + .word function_init_at_CellularAutomaton + .word function_print_at_CellularAutomaton + .word function_num_cells_at_CellularAutomaton + .word function_cell_at_CellularAutomaton + .word function_north_at_CellularAutomaton + .word function_south_at_CellularAutomaton + .word function_east_at_CellularAutomaton + .word function_west_at_CellularAutomaton + .word function_northwest_at_CellularAutomaton + .word function_northeast_at_CellularAutomaton + .word function_southeast_at_CellularAutomaton + .word function_southwest_at_CellularAutomaton + .word function_neighbors_at_CellularAutomaton + .word function_cell_at_next_evolution_at_CellularAutomaton + .word function_evolve_at_CellularAutomaton + .word function_option_at_CellularAutomaton + .word function_prompt_at_CellularAutomaton + .word function_prompt2_at_CellularAutomaton + Main_name: .asciiz "Main" + Main_size: .word 32 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_size_of_board_at_Board + .word function_board_init_at_Board + .word function_init_at_CellularAutomaton + .word function_print_at_CellularAutomaton + .word function_num_cells_at_CellularAutomaton + .word function_cell_at_CellularAutomaton + .word function_north_at_CellularAutomaton + .word function_south_at_CellularAutomaton + .word function_east_at_CellularAutomaton + .word function_west_at_CellularAutomaton + .word function_northwest_at_CellularAutomaton + .word function_northeast_at_CellularAutomaton + .word function_southeast_at_CellularAutomaton + .word function_southwest_at_CellularAutomaton + .word function_neighbors_at_CellularAutomaton + .word function_cell_at_next_evolution_at_CellularAutomaton + .word function_evolve_at_CellularAutomaton + .word function_option_at_CellularAutomaton + .word function_prompt_at_CellularAutomaton + .word function_prompt2_at_CellularAutomaton + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + data_2: .asciiz "nn" + data_3: .asciiz " n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 108($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_size_of_board_at_Board: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_board_init_at_Board: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -80 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -4($fp) + lw $t1, -4($fp) + sw $t1, -8($fp) + li $t1, size + li $a0, 15 + sub $a0, $t1, $a0 + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_board_init_at_Board_0 + li $t1, 1 + sw $t1, -12($fp) + j label_board_init_at_Board_1 +label_board_init_at_Board_0: + li $t1, 0 + sw $t1, -12($fp) +label_board_init_at_Board_1: + lw $a0, -12($fp) + bne $a0, $zero, label_board_init_at_Board_2 + li $t1, size + li $a0, 16 + sub $a0, $t1, $a0 + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_board_init_at_Board_4 + li $t1, 1 + sw $t1, -24($fp) + j label_board_init_at_Board_5 +label_board_init_at_Board_4: + li $t1, 0 + sw $t1, -24($fp) +label_board_init_at_Board_5: + lw $a0, -24($fp) + bne $a0, $zero, label_board_init_at_Board_6 + li $t1, size + li $a0, 20 + sub $a0, $t1, $a0 + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_board_init_at_Board_8 + li $t1, 1 + sw $t1, -36($fp) + j label_board_init_at_Board_9 +label_board_init_at_Board_8: + li $t1, 0 + sw $t1, -36($fp) +label_board_init_at_Board_9: + lw $a0, -36($fp) + bne $a0, $zero, label_board_init_at_Board_10 + li $t1, size + li $a0, 21 + sub $a0, $t1, $a0 + sw $a0, -52($fp) + lw $a0, -52($fp) + bne $a0, $zero, label_board_init_at_Board_12 + li $t1, 1 + sw $t1, -48($fp) + j label_board_init_at_Board_13 +label_board_init_at_Board_12: + li $t1, 0 + sw $t1, -48($fp) +label_board_init_at_Board_13: + lw $a0, -48($fp) + bne $a0, $zero, label_board_init_at_Board_14 + li $t1, size + li $a0, 25 + sub $a0, $t1, $a0 + sw $a0, -64($fp) + lw $a0, -64($fp) + bne $a0, $zero, label_board_init_at_Board_16 + li $t1, 1 + sw $t1, -60($fp) + j label_board_init_at_Board_17 +label_board_init_at_Board_16: + li $t1, 0 + sw $t1, -60($fp) +label_board_init_at_Board_17: + lw $a0, -60($fp) + bne $a0, $zero, label_board_init_at_Board_18 + li $t1, size + li $a0, 28 + sub $a0, $t1, $a0 + sw $a0, -76($fp) + lw $a0, -76($fp) + bne $a0, $zero, label_board_init_at_Board_20 + li $t1, 1 + sw $t1, -72($fp) + j label_board_init_at_Board_21 +label_board_init_at_Board_20: + li $t1, 0 + sw $t1, -72($fp) +label_board_init_at_Board_21: + lw $a0, -72($fp) + bne $a0, $zero, label_board_init_at_Board_22 + + #init set attribute + + lw $a0, 4($fp) + li $t1, 5 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 5 + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, size + sw $t1, 20($a0) + + #end set attribute + + li $t1, size + sw $t1, -80($fp) + j label_board_init_at_Board_23 +label_board_init_at_Board_22: + + #init set attribute + + lw $a0, 4($fp) + li $t1, 7 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 4 + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, size + sw $t1, 20($a0) + + #end set attribute + + li $t1, size + sw $t1, -80($fp) +label_board_init_at_Board_23: + lw $t1, -80($fp) + sw $t1, -68($fp) + j label_board_init_at_Board_19 +label_board_init_at_Board_18: + + #init set attribute + + lw $a0, 4($fp) + li $t1, 5 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 5 + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, size + sw $t1, 20($a0) + + #end set attribute + + li $t1, size + sw $t1, -68($fp) +label_board_init_at_Board_19: + lw $t1, -68($fp) + sw $t1, -56($fp) + j label_board_init_at_Board_15 +label_board_init_at_Board_14: + + #init set attribute + + lw $a0, 4($fp) + li $t1, 3 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 7 + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, size + sw $t1, 20($a0) + + #end set attribute + + li $t1, size + sw $t1, -56($fp) +label_board_init_at_Board_15: + lw $t1, -56($fp) + sw $t1, -44($fp) + j label_board_init_at_Board_11 +label_board_init_at_Board_10: + + #init set attribute + + lw $a0, 4($fp) + li $t1, 4 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 5 + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, size + sw $t1, 20($a0) + + #end set attribute + + li $t1, size + sw $t1, -44($fp) +label_board_init_at_Board_11: + lw $t1, -44($fp) + sw $t1, -32($fp) + j label_board_init_at_Board_7 +label_board_init_at_Board_6: + + #init set attribute + + lw $a0, 4($fp) + li $t1, 4 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 4 + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, size + sw $t1, 20($a0) + + #end set attribute + + li $t1, size + sw $t1, -32($fp) +label_board_init_at_Board_7: + lw $t1, -32($fp) + sw $t1, -20($fp) + j label_board_init_at_Board_3 +label_board_init_at_Board_2: + + #init set attribute + + lw $a0, 4($fp) + li $t1, 3 + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 5 + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, size + sw $t1, 20($a0) + + #end set attribute + + li $t1, size + sw $t1, -20($fp) +label_board_init_at_Board_3: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 96 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Board: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Board_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Board_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Board + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Board + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Board: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_init_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 24($a0) + + #end set attribute + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 32($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_print_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -64 + li $t1, 0 + sw $t1, -4($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 20($a0) + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -12($fp) + la $t1, data_1 + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -16($fp) +label_print_at_CellularAutomaton_0: + li $a0, [] + bne $a0, $zero, label_print_at_CellularAutomaton_1 + j label_print_at_CellularAutomaton_2 +label_print_at_CellularAutomaton_1: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 24($a0) + sw $a0, -32($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, i + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -28($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -24($fp) + la $t1, data_1 + sw $t1, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -40($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -52($fp) + li $t1, i + lw $a0, -52($fp) + add $a0, $a0, $t1 + sw $a0, -48($fp) + lw $t1, -48($fp) + sw $t1, -4($fp) + j label_print_at_CellularAutomaton_0 +label_print_at_CellularAutomaton_2: + la $t1, _void + sw $t1, -56($fp) + la $t1, data_1 + sw $t1, -64($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -60($fp) + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 76 + lw $fp, 0($sp) + jr $ra +function_num_cells_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 24($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_cell_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + li $a0, [] + bne $a0, $zero, label_cell_at_CellularAutomaton_0 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 24($a0) + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + sw $t1, -4($fp) + j label_cell_at_CellularAutomaton_1 +label_cell_at_CellularAutomaton_0: + la $t1, _empty + sw $t1, -16($fp) + lw $t1, -16($fp) + sw $t1, -4($fp) +label_cell_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra +function_north_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + li $a0, [] + bne $a0, $zero, label_north_at_CellularAutomaton_0 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -16($fp) + lw $t1, 8($fp) + lw $a0, -16($fp) + blt $t1, $a0, label_north_at_CellularAutomaton_2 + li $a0, 0 + j label_north_at_CellularAutomaton_3 +label_north_at_CellularAutomaton_2: + li $a0, 1 +label_north_at_CellularAutomaton_3: + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -4($fp) + j label_north_at_CellularAutomaton_1 +label_north_at_CellularAutomaton_0: + la $t1, _empty + sw $t1, -20($fp) + lw $t1, -20($fp) + sw $t1, -4($fp) +label_north_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_south_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + li $a0, [] + bne $a0, $zero, label_south_at_CellularAutomaton_0 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -16($fp) + lw $t1, 8($fp) + lw $a0, -16($fp) + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -4($fp) + j label_south_at_CellularAutomaton_1 +label_south_at_CellularAutomaton_0: + la $t1, _empty + sw $t1, -20($fp) + lw $t1, -20($fp) + sw $t1, -4($fp) +label_south_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_east_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -16($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -20($fp) + lw $t1, -16($fp) + lw $a0, -20($fp) + div $a0, $t1, $a0 + sw $a0, -12($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -24($fp) + lw $t1, -12($fp) + lw $a0, -24($fp) + mul $a0 $t1 $a0 + sw $a0, -8($fp) + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -28($fp) + lw $t1, -8($fp) + lw $a0, -28($fp) + sub $a0, $t1, $a0 + sw $a0, -32($fp) + lw $a0, -32($fp) + bne $a0, $zero, label_east_at_CellularAutomaton_0 + li $t1, 1 + sw $t1, -4($fp) + j label_east_at_CellularAutomaton_1 +label_east_at_CellularAutomaton_0: + li $t1, 0 + sw $t1, -4($fp) +label_east_at_CellularAutomaton_1: + lw $a0, -4($fp) + bne $a0, $zero, label_east_at_CellularAutomaton_2 + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -40($fp) + lw $t1, -40($fp) + sw $t1, -36($fp) + j label_east_at_CellularAutomaton_3 +label_east_at_CellularAutomaton_2: + la $t1, _empty + sw $t1, -48($fp) + lw $t1, -48($fp) + sw $t1, -36($fp) +label_east_at_CellularAutomaton_3: + + #retornando el valor + + lw $a0, -36($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 64 + lw $fp, 0($sp) + jr $ra +function_west_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -56 + lw $t1, 8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -8($fp) + lw $a0, -8($fp) + bne $a0, $zero, label_west_at_CellularAutomaton_0 + li $t1, 1 + sw $t1, -4($fp) + j label_west_at_CellularAutomaton_1 +label_west_at_CellularAutomaton_0: + li $t1, 0 + sw $t1, -4($fp) +label_west_at_CellularAutomaton_1: + lw $a0, -4($fp) + bne $a0, $zero, label_west_at_CellularAutomaton_2 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -28($fp) + lw $t1, 8($fp) + lw $a0, -28($fp) + div $a0, $t1, $a0 + sw $a0, -24($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -32($fp) + lw $t1, -24($fp) + lw $a0, -32($fp) + mul $a0 $t1 $a0 + sw $a0, -20($fp) + lw $t1, -20($fp) + lw $a0, 8($fp) + sub $a0, $t1, $a0 + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_west_at_CellularAutomaton_4 + li $t1, 1 + sw $t1, -16($fp) + j label_west_at_CellularAutomaton_5 +label_west_at_CellularAutomaton_4: + li $t1, 0 + sw $t1, -16($fp) +label_west_at_CellularAutomaton_5: + lw $a0, -16($fp) + bne $a0, $zero, label_west_at_CellularAutomaton_6 + lw $t1, 8($fp) + li $a0, 1 + blt $t1, $a0, label_west_at_CellularAutomaton_8 + li $a0, 0 + j label_west_at_CellularAutomaton_9 +label_west_at_CellularAutomaton_8: + li $a0, 1 +label_west_at_CellularAutomaton_9: + sw $a0, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -44($fp) + lw $t1, -44($fp) + sw $t1, -40($fp) + j label_west_at_CellularAutomaton_7 +label_west_at_CellularAutomaton_6: + la $t1, _empty + sw $t1, -52($fp) + lw $t1, -52($fp) + sw $t1, -40($fp) +label_west_at_CellularAutomaton_7: + lw $t1, -40($fp) + sw $t1, -12($fp) + j label_west_at_CellularAutomaton_3 +label_west_at_CellularAutomaton_2: + la $t1, _empty + sw $t1, -56($fp) + lw $t1, -56($fp) + sw $t1, -12($fp) +label_west_at_CellularAutomaton_3: + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 72 + lw $fp, 0($sp) + jr $ra +function_northwest_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + li $a0, [] + bne $a0, $zero, label_northwest_at_CellularAutomaton_0 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -20($fp) + lw $t1, 8($fp) + lw $a0, -20($fp) + div $a0, $t1, $a0 + sw $a0, -16($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -24($fp) + lw $t1, -16($fp) + lw $a0, -24($fp) + mul $a0 $t1 $a0 + sw $a0, -12($fp) + lw $t1, -12($fp) + lw $a0, 8($fp) + sub $a0, $t1, $a0 + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_northwest_at_CellularAutomaton_2 + li $t1, 1 + sw $t1, -8($fp) + j label_northwest_at_CellularAutomaton_3 +label_northwest_at_CellularAutomaton_2: + li $t1, 0 + sw $t1, -8($fp) +label_northwest_at_CellularAutomaton_3: + lw $a0, -8($fp) + bne $a0, $zero, label_northwest_at_CellularAutomaton_4 + lw $t1, 8($fp) + li $a0, 1 + blt $t1, $a0, label_northwest_at_CellularAutomaton_6 + li $a0, 0 + j label_northwest_at_CellularAutomaton_7 +label_northwest_at_CellularAutomaton_6: + li $a0, 1 +label_northwest_at_CellularAutomaton_7: + sw $a0, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 52($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -32($fp) + j label_northwest_at_CellularAutomaton_5 +label_northwest_at_CellularAutomaton_4: + la $t1, _empty + sw $t1, -44($fp) + lw $t1, -44($fp) + sw $t1, -32($fp) +label_northwest_at_CellularAutomaton_5: + lw $t1, -32($fp) + sw $t1, -4($fp) + j label_northwest_at_CellularAutomaton_1 +label_northwest_at_CellularAutomaton_0: + la $t1, _empty + sw $t1, -48($fp) + lw $t1, -48($fp) + sw $t1, -4($fp) +label_northwest_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 64 + lw $fp, 0($sp) + jr $ra +function_northeast_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -56 + li $a0, [] + bne $a0, $zero, label_northeast_at_CellularAutomaton_0 + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -20($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -24($fp) + lw $t1, -20($fp) + lw $a0, -24($fp) + div $a0, $t1, $a0 + sw $a0, -16($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -28($fp) + lw $t1, -16($fp) + lw $a0, -28($fp) + mul $a0 $t1 $a0 + sw $a0, -12($fp) + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -32($fp) + lw $t1, -12($fp) + lw $a0, -32($fp) + sub $a0, $t1, $a0 + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_northeast_at_CellularAutomaton_2 + li $t1, 1 + sw $t1, -8($fp) + j label_northeast_at_CellularAutomaton_3 +label_northeast_at_CellularAutomaton_2: + li $t1, 0 + sw $t1, -8($fp) +label_northeast_at_CellularAutomaton_3: + lw $a0, -8($fp) + bne $a0, $zero, label_northeast_at_CellularAutomaton_4 + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 52($a0) + jalr $a0 + sw $a0, -44($fp) + lw $t1, -44($fp) + sw $t1, -40($fp) + j label_northeast_at_CellularAutomaton_5 +label_northeast_at_CellularAutomaton_4: + la $t1, _empty + sw $t1, -52($fp) + lw $t1, -52($fp) + sw $t1, -40($fp) +label_northeast_at_CellularAutomaton_5: + lw $t1, -40($fp) + sw $t1, -4($fp) + j label_northeast_at_CellularAutomaton_1 +label_northeast_at_CellularAutomaton_0: + la $t1, _empty + sw $t1, -56($fp) + lw $t1, -56($fp) + sw $t1, -4($fp) +label_northeast_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 72 + lw $fp, 0($sp) + jr $ra +function_southeast_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -56 + li $a0, [] + bne $a0, $zero, label_southeast_at_CellularAutomaton_0 + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -20($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -24($fp) + lw $t1, -20($fp) + lw $a0, -24($fp) + div $a0, $t1, $a0 + sw $a0, -16($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -28($fp) + lw $t1, -16($fp) + lw $a0, -28($fp) + mul $a0 $t1 $a0 + sw $a0, -12($fp) + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -32($fp) + lw $t1, -12($fp) + lw $a0, -32($fp) + sub $a0, $t1, $a0 + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_southeast_at_CellularAutomaton_2 + li $t1, 1 + sw $t1, -8($fp) + j label_southeast_at_CellularAutomaton_3 +label_southeast_at_CellularAutomaton_2: + li $t1, 0 + sw $t1, -8($fp) +label_southeast_at_CellularAutomaton_3: + lw $a0, -8($fp) + bne $a0, $zero, label_southeast_at_CellularAutomaton_4 + lw $t1, 8($fp) + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 56($a0) + jalr $a0 + sw $a0, -44($fp) + lw $t1, -44($fp) + sw $t1, -40($fp) + j label_southeast_at_CellularAutomaton_5 +label_southeast_at_CellularAutomaton_4: + la $t1, _empty + sw $t1, -52($fp) + lw $t1, -52($fp) + sw $t1, -40($fp) +label_southeast_at_CellularAutomaton_5: + lw $t1, -40($fp) + sw $t1, -4($fp) + j label_southeast_at_CellularAutomaton_1 +label_southeast_at_CellularAutomaton_0: + la $t1, _empty + sw $t1, -56($fp) + lw $t1, -56($fp) + sw $t1, -4($fp) +label_southeast_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 72 + lw $fp, 0($sp) + jr $ra +function_southwest_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + li $a0, [] + bne $a0, $zero, label_southwest_at_CellularAutomaton_0 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -20($fp) + lw $t1, 8($fp) + lw $a0, -20($fp) + div $a0, $t1, $a0 + sw $a0, -16($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -24($fp) + lw $t1, -16($fp) + lw $a0, -24($fp) + mul $a0 $t1 $a0 + sw $a0, -12($fp) + lw $t1, -12($fp) + lw $a0, 8($fp) + sub $a0, $t1, $a0 + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_southwest_at_CellularAutomaton_2 + li $t1, 1 + sw $t1, -8($fp) + j label_southwest_at_CellularAutomaton_3 +label_southwest_at_CellularAutomaton_2: + li $t1, 0 + sw $t1, -8($fp) +label_southwest_at_CellularAutomaton_3: + lw $a0, -8($fp) + bne $a0, $zero, label_southwest_at_CellularAutomaton_4 + lw $t1, 8($fp) + li $a0, 1 + blt $t1, $a0, label_southwest_at_CellularAutomaton_6 + li $a0, 0 + j label_southwest_at_CellularAutomaton_7 +label_southwest_at_CellularAutomaton_6: + li $a0, 1 +label_southwest_at_CellularAutomaton_7: + sw $a0, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 56($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -32($fp) + j label_southwest_at_CellularAutomaton_5 +label_southwest_at_CellularAutomaton_4: + la $t1, _empty + sw $t1, -44($fp) + lw $t1, -44($fp) + sw $t1, -32($fp) +label_southwest_at_CellularAutomaton_5: + lw $t1, -32($fp) + sw $t1, -4($fp) + j label_southwest_at_CellularAutomaton_1 +label_southwest_at_CellularAutomaton_0: + la $t1, _empty + sw $t1, -48($fp) + lw $t1, -48($fp) + sw $t1, -4($fp) +label_southwest_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 64 + lw $fp, 0($sp) + jr $ra +function_neighbors_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -156 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 52($a0) + jalr $a0 + sw $a0, -36($fp) + la $t1, _empty + sw $t1, -40($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -32($fp) + lw $a0, -32($fp) + bne $a0, $zero, label_neighbors_at_CellularAutomaton_0 + li $t1, 0 + sw $t1, -44($fp) + j label_neighbors_at_CellularAutomaton_1 +label_neighbors_at_CellularAutomaton_0: + li $t1, 1 + sw $t1, -44($fp) +label_neighbors_at_CellularAutomaton_1: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 56($a0) + jalr $a0 + sw $a0, -52($fp) + la $t1, _empty + sw $t1, -56($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -52($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -48($fp) + lw $a0, -48($fp) + bne $a0, $zero, label_neighbors_at_CellularAutomaton_2 + li $t1, 0 + sw $t1, -60($fp) + j label_neighbors_at_CellularAutomaton_3 +label_neighbors_at_CellularAutomaton_2: + li $t1, 1 + sw $t1, -60($fp) +label_neighbors_at_CellularAutomaton_3: + lw $t1, -44($fp) + lw $a0, -60($fp) + add $a0, $a0, $t1 + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 60($a0) + jalr $a0 + sw $a0, -68($fp) + la $t1, _empty + sw $t1, -72($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -72($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -64($fp) + lw $a0, -64($fp) + bne $a0, $zero, label_neighbors_at_CellularAutomaton_4 + li $t1, 0 + sw $t1, -76($fp) + j label_neighbors_at_CellularAutomaton_5 +label_neighbors_at_CellularAutomaton_4: + li $t1, 1 + sw $t1, -76($fp) +label_neighbors_at_CellularAutomaton_5: + lw $t1, -28($fp) + lw $a0, -76($fp) + add $a0, $a0, $t1 + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 64($a0) + jalr $a0 + sw $a0, -84($fp) + la $t1, _empty + sw $t1, -88($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -84($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -88($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -80($fp) + lw $a0, -80($fp) + bne $a0, $zero, label_neighbors_at_CellularAutomaton_6 + li $t1, 0 + sw $t1, -92($fp) + j label_neighbors_at_CellularAutomaton_7 +label_neighbors_at_CellularAutomaton_6: + li $t1, 1 + sw $t1, -92($fp) +label_neighbors_at_CellularAutomaton_7: + lw $t1, -24($fp) + lw $a0, -92($fp) + add $a0, $a0, $t1 + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 72($a0) + jalr $a0 + sw $a0, -100($fp) + la $t1, _empty + sw $t1, -104($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -100($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -104($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -96($fp) + lw $a0, -96($fp) + bne $a0, $zero, label_neighbors_at_CellularAutomaton_8 + li $t1, 0 + sw $t1, -108($fp) + j label_neighbors_at_CellularAutomaton_9 +label_neighbors_at_CellularAutomaton_8: + li $t1, 1 + sw $t1, -108($fp) +label_neighbors_at_CellularAutomaton_9: + lw $t1, -20($fp) + lw $a0, -108($fp) + add $a0, $a0, $t1 + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 68($a0) + jalr $a0 + sw $a0, -116($fp) + la $t1, _empty + sw $t1, -120($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -116($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -120($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -112($fp) + lw $a0, -112($fp) + bne $a0, $zero, label_neighbors_at_CellularAutomaton_10 + li $t1, 0 + sw $t1, -124($fp) + j label_neighbors_at_CellularAutomaton_11 +label_neighbors_at_CellularAutomaton_10: + li $t1, 1 + sw $t1, -124($fp) +label_neighbors_at_CellularAutomaton_11: + lw $t1, -16($fp) + lw $a0, -124($fp) + add $a0, $a0, $t1 + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 76($a0) + jalr $a0 + sw $a0, -132($fp) + la $t1, _empty + sw $t1, -136($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -132($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -136($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -128($fp) + lw $a0, -128($fp) + bne $a0, $zero, label_neighbors_at_CellularAutomaton_12 + li $t1, 0 + sw $t1, -140($fp) + j label_neighbors_at_CellularAutomaton_13 +label_neighbors_at_CellularAutomaton_12: + li $t1, 1 + sw $t1, -140($fp) +label_neighbors_at_CellularAutomaton_13: + lw $t1, -12($fp) + lw $a0, -140($fp) + add $a0, $a0, $t1 + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 80($a0) + jalr $a0 + sw $a0, -148($fp) + la $t1, _empty + sw $t1, -152($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -148($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -152($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -144($fp) + lw $a0, -144($fp) + bne $a0, $zero, label_neighbors_at_CellularAutomaton_14 + li $t1, 0 + sw $t1, -156($fp) + j label_neighbors_at_CellularAutomaton_15 +label_neighbors_at_CellularAutomaton_14: + li $t1, 1 + sw $t1, -156($fp) +label_neighbors_at_CellularAutomaton_15: + lw $t1, -8($fp) + lw $a0, -156($fp) + add $a0, $a0, $t1 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 172 + lw $fp, 0($sp) + jr $ra +function_cell_at_next_evolution_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -64 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 84($a0) + jalr $a0 + sw $a0, -8($fp) + lw $t1, -8($fp) + li $a0, 3 + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_0 + li $t1, 1 + sw $t1, -4($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_1 +label_cell_at_next_evolution_at_CellularAutomaton_0: + li $t1, 0 + sw $t1, -4($fp) +label_cell_at_next_evolution_at_CellularAutomaton_1: + lw $a0, -4($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_2 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 84($a0) + jalr $a0 + sw $a0, -24($fp) + lw $t1, -24($fp) + li $a0, 2 + sub $a0, $t1, $a0 + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_4 + li $t1, 1 + sw $t1, -20($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_5 +label_cell_at_next_evolution_at_CellularAutomaton_4: + li $t1, 0 + sw $t1, -20($fp) +label_cell_at_next_evolution_at_CellularAutomaton_5: + lw $a0, -20($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_6 + la $t1, _empty + sw $t1, -36($fp) + lw $t1, -36($fp) + sw $t1, -32($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_7 +label_cell_at_next_evolution_at_CellularAutomaton_6: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -44($fp) + la $t1, _empty + sw $t1, -48($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_cell_at_next_evolution_at_CellularAutomaton_8 + la $t1, _empty + sw $t1, -56($fp) + lw $t1, -56($fp) + sw $t1, -52($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_9 +label_cell_at_next_evolution_at_CellularAutomaton_8: + la $t1, _empty + sw $t1, -60($fp) + lw $t1, -60($fp) + sw $t1, -52($fp) +label_cell_at_next_evolution_at_CellularAutomaton_9: + lw $t1, -52($fp) + sw $t1, -32($fp) +label_cell_at_next_evolution_at_CellularAutomaton_7: + lw $t1, -32($fp) + sw $t1, -16($fp) + j label_cell_at_next_evolution_at_CellularAutomaton_3 +label_cell_at_next_evolution_at_CellularAutomaton_2: + la $t1, _empty + sw $t1, -64($fp) + lw $t1, -64($fp) + sw $t1, -16($fp) +label_cell_at_next_evolution_at_CellularAutomaton_3: + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 80 + lw $fp, 0($sp) + jr $ra +function_evolve_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -36 + li $t1, 0 + sw $t1, -4($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -8($fp) + lw $t1, -8($fp) + sw $t1, -12($fp) + la $t1, _empty + sw $t1, -16($fp) + lw $t1, -16($fp) + sw $t1, -20($fp) +label_evolve_at_CellularAutomaton_0: + li $a0, [] + bne $a0, $zero, label_evolve_at_CellularAutomaton_1 + j label_evolve_at_CellularAutomaton_2 +label_evolve_at_CellularAutomaton_1: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, position + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 88($a0) + jalr $a0 + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, temp + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_concat_at_String + sw $a0, -24($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + sw $t1, -20($fp) + li $t1, position + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -32($fp) + lw $t1, -32($fp) + sw $t1, -4($fp) + j label_evolve_at_CellularAutomaton_0 +label_evolve_at_CellularAutomaton_2: + la $t1, _void + sw $t1, -36($fp) + + #init set attribute + + lw $a0, 4($fp) + li $t1, temp + sw $t1, 24($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 48 + lw $fp, 0($sp) + jr $ra +function_option_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -540 + li $t1, 0 + sw $t1, -4($fp) + la $t1, data_2 + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -8($fp) + la $t1, data_3 + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -16($fp) + la $t1, data_3 + sw $t1, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -24($fp) + la $t1, data_3 + sw $t1, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -32($fp) + la $t1, data_3 + sw $t1, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -40($fp) + la $t1, data_3 + sw $t1, -52($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -52($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -48($fp) + la $t1, data_3 + sw $t1, -60($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -56($fp) + la $t1, data_3 + sw $t1, -68($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -64($fp) + la $t1, data_3 + sw $t1, -76($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -76($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -72($fp) + la $t1, data_3 + sw $t1, -84($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -84($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -80($fp) + la $t1, data_3 + sw $t1, -92($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -92($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -88($fp) + la $t1, data_3 + sw $t1, -100($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -100($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -96($fp) + la $t1, data_3 + sw $t1, -108($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -108($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -104($fp) + la $t1, data_3 + sw $t1, -116($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -116($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -112($fp) + la $t1, data_3 + sw $t1, -124($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -124($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -120($fp) + la $t1, data_3 + sw $t1, -132($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -132($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -128($fp) + la $t1, data_3 + sw $t1, -140($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -140($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -136($fp) + la $t1, data_3 + sw $t1, -148($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -148($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -144($fp) + la $t1, data_3 + sw $t1, -156($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -156($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -152($fp) + la $t1, data_3 + sw $t1, -164($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -164($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -160($fp) + la $t1, data_3 + sw $t1, -172($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -172($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -168($fp) + la $t1, data_3 + sw $t1, -180($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -180($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -176($fp) + la $t1, _empty + sw $t1, -188($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -188($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -184($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -192($fp) + lw $t1, -192($fp) + sw $t1, -4($fp) + la $t1, data_1 + sw $t1, -200($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -200($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -196($fp) + li $t1, num + li $a0, 1 + sub $a0, $t1, $a0 + sw $a0, -208($fp) + lw $a0, -208($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_0 + li $t1, 1 + sw $t1, -204($fp) + j label_option_at_CellularAutomaton_1 +label_option_at_CellularAutomaton_0: + li $t1, 0 + sw $t1, -204($fp) +label_option_at_CellularAutomaton_1: + lw $a0, -204($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_2 + li $t1, num + li $a0, 2 + sub $a0, $t1, $a0 + sw $a0, -220($fp) + lw $a0, -220($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_4 + li $t1, 1 + sw $t1, -216($fp) + j label_option_at_CellularAutomaton_5 +label_option_at_CellularAutomaton_4: + li $t1, 0 + sw $t1, -216($fp) +label_option_at_CellularAutomaton_5: + lw $a0, -216($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_6 + li $t1, num + li $a0, 3 + sub $a0, $t1, $a0 + sw $a0, -232($fp) + lw $a0, -232($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_8 + li $t1, 1 + sw $t1, -228($fp) + j label_option_at_CellularAutomaton_9 +label_option_at_CellularAutomaton_8: + li $t1, 0 + sw $t1, -228($fp) +label_option_at_CellularAutomaton_9: + lw $a0, -228($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_10 + li $t1, num + li $a0, 4 + sub $a0, $t1, $a0 + sw $a0, -244($fp) + lw $a0, -244($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_12 + li $t1, 1 + sw $t1, -240($fp) + j label_option_at_CellularAutomaton_13 +label_option_at_CellularAutomaton_12: + li $t1, 0 + sw $t1, -240($fp) +label_option_at_CellularAutomaton_13: + lw $a0, -240($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_14 + li $t1, num + li $a0, 5 + sub $a0, $t1, $a0 + sw $a0, -256($fp) + lw $a0, -256($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_16 + li $t1, 1 + sw $t1, -252($fp) + j label_option_at_CellularAutomaton_17 +label_option_at_CellularAutomaton_16: + li $t1, 0 + sw $t1, -252($fp) +label_option_at_CellularAutomaton_17: + lw $a0, -252($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_18 + li $t1, num + li $a0, 6 + sub $a0, $t1, $a0 + sw $a0, -268($fp) + lw $a0, -268($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_20 + li $t1, 1 + sw $t1, -264($fp) + j label_option_at_CellularAutomaton_21 +label_option_at_CellularAutomaton_20: + li $t1, 0 + sw $t1, -264($fp) +label_option_at_CellularAutomaton_21: + lw $a0, -264($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_22 + li $t1, num + li $a0, 7 + sub $a0, $t1, $a0 + sw $a0, -280($fp) + lw $a0, -280($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_24 + li $t1, 1 + sw $t1, -276($fp) + j label_option_at_CellularAutomaton_25 +label_option_at_CellularAutomaton_24: + li $t1, 0 + sw $t1, -276($fp) +label_option_at_CellularAutomaton_25: + lw $a0, -276($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_26 + li $t1, num + li $a0, 8 + sub $a0, $t1, $a0 + sw $a0, -292($fp) + lw $a0, -292($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_28 + li $t1, 1 + sw $t1, -288($fp) + j label_option_at_CellularAutomaton_29 +label_option_at_CellularAutomaton_28: + li $t1, 0 + sw $t1, -288($fp) +label_option_at_CellularAutomaton_29: + lw $a0, -288($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_30 + li $t1, num + li $a0, 9 + sub $a0, $t1, $a0 + sw $a0, -304($fp) + lw $a0, -304($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_32 + li $t1, 1 + sw $t1, -300($fp) + j label_option_at_CellularAutomaton_33 +label_option_at_CellularAutomaton_32: + li $t1, 0 + sw $t1, -300($fp) +label_option_at_CellularAutomaton_33: + lw $a0, -300($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_34 + li $t1, num + li $a0, 10 + sub $a0, $t1, $a0 + sw $a0, -316($fp) + lw $a0, -316($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_36 + li $t1, 1 + sw $t1, -312($fp) + j label_option_at_CellularAutomaton_37 +label_option_at_CellularAutomaton_36: + li $t1, 0 + sw $t1, -312($fp) +label_option_at_CellularAutomaton_37: + lw $a0, -312($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_38 + li $t1, num + li $a0, 11 + sub $a0, $t1, $a0 + sw $a0, -328($fp) + lw $a0, -328($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_40 + li $t1, 1 + sw $t1, -324($fp) + j label_option_at_CellularAutomaton_41 +label_option_at_CellularAutomaton_40: + li $t1, 0 + sw $t1, -324($fp) +label_option_at_CellularAutomaton_41: + lw $a0, -324($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_42 + li $t1, num + li $a0, 12 + sub $a0, $t1, $a0 + sw $a0, -340($fp) + lw $a0, -340($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_44 + li $t1, 1 + sw $t1, -336($fp) + j label_option_at_CellularAutomaton_45 +label_option_at_CellularAutomaton_44: + li $t1, 0 + sw $t1, -336($fp) +label_option_at_CellularAutomaton_45: + lw $a0, -336($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_46 + li $t1, num + li $a0, 13 + sub $a0, $t1, $a0 + sw $a0, -352($fp) + lw $a0, -352($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_48 + li $t1, 1 + sw $t1, -348($fp) + j label_option_at_CellularAutomaton_49 +label_option_at_CellularAutomaton_48: + li $t1, 0 + sw $t1, -348($fp) +label_option_at_CellularAutomaton_49: + lw $a0, -348($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_50 + li $t1, num + li $a0, 14 + sub $a0, $t1, $a0 + sw $a0, -364($fp) + lw $a0, -364($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_52 + li $t1, 1 + sw $t1, -360($fp) + j label_option_at_CellularAutomaton_53 +label_option_at_CellularAutomaton_52: + li $t1, 0 + sw $t1, -360($fp) +label_option_at_CellularAutomaton_53: + lw $a0, -360($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_54 + li $t1, num + li $a0, 15 + sub $a0, $t1, $a0 + sw $a0, -376($fp) + lw $a0, -376($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_56 + li $t1, 1 + sw $t1, -372($fp) + j label_option_at_CellularAutomaton_57 +label_option_at_CellularAutomaton_56: + li $t1, 0 + sw $t1, -372($fp) +label_option_at_CellularAutomaton_57: + lw $a0, -372($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_58 + li $t1, num + li $a0, 16 + sub $a0, $t1, $a0 + sw $a0, -388($fp) + lw $a0, -388($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_60 + li $t1, 1 + sw $t1, -384($fp) + j label_option_at_CellularAutomaton_61 +label_option_at_CellularAutomaton_60: + li $t1, 0 + sw $t1, -384($fp) +label_option_at_CellularAutomaton_61: + lw $a0, -384($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_62 + li $t1, num + li $a0, 17 + sub $a0, $t1, $a0 + sw $a0, -400($fp) + lw $a0, -400($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_64 + li $t1, 1 + sw $t1, -396($fp) + j label_option_at_CellularAutomaton_65 +label_option_at_CellularAutomaton_64: + li $t1, 0 + sw $t1, -396($fp) +label_option_at_CellularAutomaton_65: + lw $a0, -396($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_66 + li $t1, num + li $a0, 18 + sub $a0, $t1, $a0 + sw $a0, -412($fp) + lw $a0, -412($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_68 + li $t1, 1 + sw $t1, -408($fp) + j label_option_at_CellularAutomaton_69 +label_option_at_CellularAutomaton_68: + li $t1, 0 + sw $t1, -408($fp) +label_option_at_CellularAutomaton_69: + lw $a0, -408($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_70 + li $t1, num + li $a0, 19 + sub $a0, $t1, $a0 + sw $a0, -424($fp) + lw $a0, -424($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_72 + li $t1, 1 + sw $t1, -420($fp) + j label_option_at_CellularAutomaton_73 +label_option_at_CellularAutomaton_72: + li $t1, 0 + sw $t1, -420($fp) +label_option_at_CellularAutomaton_73: + lw $a0, -420($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_74 + li $t1, num + li $a0, 20 + sub $a0, $t1, $a0 + sw $a0, -436($fp) + lw $a0, -436($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_76 + li $t1, 1 + sw $t1, -432($fp) + j label_option_at_CellularAutomaton_77 +label_option_at_CellularAutomaton_76: + li $t1, 0 + sw $t1, -432($fp) +label_option_at_CellularAutomaton_77: + lw $a0, -432($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_78 + li $t1, num + li $a0, 21 + sub $a0, $t1, $a0 + sw $a0, -448($fp) + lw $a0, -448($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_80 + li $t1, 1 + sw $t1, -444($fp) + j label_option_at_CellularAutomaton_81 +label_option_at_CellularAutomaton_80: + li $t1, 0 + sw $t1, -444($fp) +label_option_at_CellularAutomaton_81: + lw $a0, -444($fp) + bne $a0, $zero, label_option_at_CellularAutomaton_82 + la $t1, _empty + sw $t1, -456($fp) + lw $t1, -456($fp) + sw $t1, -452($fp) + j label_option_at_CellularAutomaton_83 +label_option_at_CellularAutomaton_82: + la $t1, _empty + sw $t1, -460($fp) + lw $t1, -460($fp) + sw $t1, -452($fp) +label_option_at_CellularAutomaton_83: + lw $t1, -452($fp) + sw $t1, -440($fp) + j label_option_at_CellularAutomaton_79 +label_option_at_CellularAutomaton_78: + la $t1, _empty + sw $t1, -464($fp) + lw $t1, -464($fp) + sw $t1, -440($fp) +label_option_at_CellularAutomaton_79: + lw $t1, -440($fp) + sw $t1, -428($fp) + j label_option_at_CellularAutomaton_75 +label_option_at_CellularAutomaton_74: + la $t1, _empty + sw $t1, -468($fp) + lw $t1, -468($fp) + sw $t1, -428($fp) +label_option_at_CellularAutomaton_75: + lw $t1, -428($fp) + sw $t1, -416($fp) + j label_option_at_CellularAutomaton_71 +label_option_at_CellularAutomaton_70: + la $t1, _empty + sw $t1, -472($fp) + lw $t1, -472($fp) + sw $t1, -416($fp) +label_option_at_CellularAutomaton_71: + lw $t1, -416($fp) + sw $t1, -404($fp) + j label_option_at_CellularAutomaton_67 +label_option_at_CellularAutomaton_66: + la $t1, _empty + sw $t1, -476($fp) + lw $t1, -476($fp) + sw $t1, -404($fp) +label_option_at_CellularAutomaton_67: + lw $t1, -404($fp) + sw $t1, -392($fp) + j label_option_at_CellularAutomaton_63 +label_option_at_CellularAutomaton_62: + la $t1, _empty + sw $t1, -480($fp) + lw $t1, -480($fp) + sw $t1, -392($fp) +label_option_at_CellularAutomaton_63: + lw $t1, -392($fp) + sw $t1, -380($fp) + j label_option_at_CellularAutomaton_59 +label_option_at_CellularAutomaton_58: + la $t1, _empty + sw $t1, -484($fp) + lw $t1, -484($fp) + sw $t1, -380($fp) +label_option_at_CellularAutomaton_59: + lw $t1, -380($fp) + sw $t1, -368($fp) + j label_option_at_CellularAutomaton_55 +label_option_at_CellularAutomaton_54: + la $t1, _empty + sw $t1, -488($fp) + lw $t1, -488($fp) + sw $t1, -368($fp) +label_option_at_CellularAutomaton_55: + lw $t1, -368($fp) + sw $t1, -356($fp) + j label_option_at_CellularAutomaton_51 +label_option_at_CellularAutomaton_50: + la $t1, _empty + sw $t1, -492($fp) + lw $t1, -492($fp) + sw $t1, -356($fp) +label_option_at_CellularAutomaton_51: + lw $t1, -356($fp) + sw $t1, -344($fp) + j label_option_at_CellularAutomaton_47 +label_option_at_CellularAutomaton_46: + la $t1, _empty + sw $t1, -496($fp) + lw $t1, -496($fp) + sw $t1, -344($fp) +label_option_at_CellularAutomaton_47: + lw $t1, -344($fp) + sw $t1, -332($fp) + j label_option_at_CellularAutomaton_43 +label_option_at_CellularAutomaton_42: + la $t1, _empty + sw $t1, -500($fp) + lw $t1, -500($fp) + sw $t1, -332($fp) +label_option_at_CellularAutomaton_43: + lw $t1, -332($fp) + sw $t1, -320($fp) + j label_option_at_CellularAutomaton_39 +label_option_at_CellularAutomaton_38: + la $t1, _empty + sw $t1, -504($fp) + lw $t1, -504($fp) + sw $t1, -320($fp) +label_option_at_CellularAutomaton_39: + lw $t1, -320($fp) + sw $t1, -308($fp) + j label_option_at_CellularAutomaton_35 +label_option_at_CellularAutomaton_34: + la $t1, _empty + sw $t1, -508($fp) + lw $t1, -508($fp) + sw $t1, -308($fp) +label_option_at_CellularAutomaton_35: + lw $t1, -308($fp) + sw $t1, -296($fp) + j label_option_at_CellularAutomaton_31 +label_option_at_CellularAutomaton_30: + la $t1, _empty + sw $t1, -512($fp) + lw $t1, -512($fp) + sw $t1, -296($fp) +label_option_at_CellularAutomaton_31: + lw $t1, -296($fp) + sw $t1, -284($fp) + j label_option_at_CellularAutomaton_27 +label_option_at_CellularAutomaton_26: + la $t1, _empty + sw $t1, -516($fp) + lw $t1, -516($fp) + sw $t1, -284($fp) +label_option_at_CellularAutomaton_27: + lw $t1, -284($fp) + sw $t1, -272($fp) + j label_option_at_CellularAutomaton_23 +label_option_at_CellularAutomaton_22: + la $t1, _empty + sw $t1, -520($fp) + lw $t1, -520($fp) + sw $t1, -272($fp) +label_option_at_CellularAutomaton_23: + lw $t1, -272($fp) + sw $t1, -260($fp) + j label_option_at_CellularAutomaton_19 +label_option_at_CellularAutomaton_18: + la $t1, _empty + sw $t1, -524($fp) + lw $t1, -524($fp) + sw $t1, -260($fp) +label_option_at_CellularAutomaton_19: + lw $t1, -260($fp) + sw $t1, -248($fp) + j label_option_at_CellularAutomaton_15 +label_option_at_CellularAutomaton_14: + la $t1, _empty + sw $t1, -528($fp) + lw $t1, -528($fp) + sw $t1, -248($fp) +label_option_at_CellularAutomaton_15: + lw $t1, -248($fp) + sw $t1, -236($fp) + j label_option_at_CellularAutomaton_11 +label_option_at_CellularAutomaton_10: + la $t1, _empty + sw $t1, -532($fp) + lw $t1, -532($fp) + sw $t1, -236($fp) +label_option_at_CellularAutomaton_11: + lw $t1, -236($fp) + sw $t1, -224($fp) + j label_option_at_CellularAutomaton_7 +label_option_at_CellularAutomaton_6: + la $t1, _empty + sw $t1, -536($fp) + lw $t1, -536($fp) + sw $t1, -224($fp) +label_option_at_CellularAutomaton_7: + lw $t1, -224($fp) + sw $t1, -212($fp) + j label_option_at_CellularAutomaton_3 +label_option_at_CellularAutomaton_2: + la $t1, _empty + sw $t1, -540($fp) + lw $t1, -540($fp) + sw $t1, -212($fp) +label_option_at_CellularAutomaton_3: + + #retornando el valor + + lw $a0, -212($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 552 + lw $fp, 0($sp) + jr $ra +function_prompt_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + la $t1, _empty + sw $t1, -4($fp) + lw $t1, -4($fp) + sw $t1, -8($fp) + la $t1, data_1 + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + la $t1, _empty + sw $t1, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -28($fp) + sw $t1, -8($fp) + la $t1, data_1 + sw $t1, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -32($fp) + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, None + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_prompt_at_CellularAutomaton_0 + li $t1, 1 + sw $t1, -48($fp) + j label_prompt_at_CellularAutomaton_1 +label_prompt_at_CellularAutomaton_0: + li $t1, 0 + sw $t1, -48($fp) +label_prompt_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -48($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_prompt2_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + la $t1, _empty + sw $t1, -4($fp) + lw $t1, -4($fp) + sw $t1, -8($fp) + la $t1, data_2 + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + la $t1, data_1 + sw $t1, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -20($fp) + la $t1, _empty + sw $t1, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -8($fp) + la $t1, _empty + sw $t1, -44($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, None + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_prompt2_at_CellularAutomaton_0 + li $t1, 0 + sw $t1, -48($fp) + j label_prompt2_at_CellularAutomaton_1 +label_prompt2_at_CellularAutomaton_0: + li $t1, 1 + sw $t1, -48($fp) +label_prompt2_at_CellularAutomaton_1: + + #retornando el valor + + lw $a0, -48($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, CellularAutomaton_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, CellularAutomaton_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__CellularAutomaton + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_CellularAutomaton + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_CellularAutomaton: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Board + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -88 + li $t1, 0 + sw $t1, -4($fp) + la $t1, _empty + sw $t1, -8($fp) + lw $t1, -8($fp) + sw $t1, -12($fp) + la $t1, data_1 + sw $t1, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -16($fp) + la $t1, data_1 + sw $t1, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -24($fp) +label_main_at_Main_0: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 104($a0) + jalr $a0 + sw $a0, -32($fp) + lw $a0, -32($fp) + bne $a0, $zero, label_main_at_Main_1 + j label_main_at_Main_2 +label_main_at_Main_1: + li $t1, 1 + sw $t1, -4($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 96($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -12($fp) + + #init allocate + + li $v0, 9 + lw $a0, CellularAutomaton_size + syscall + sw $v0, -44($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_CellularAutomaton + sw $a0, -48($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, choice + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -44($fp) + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -40($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -40($fp) + sw $t1, 28($a0) + + #end set attribute + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 28($a0) + sw $a0, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -56($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -52($fp) + + #fin llamada dinamica + +label_main_at_Main_3: + li $a0, continue + bne $a0, $zero, label_main_at_Main_4 + j label_main_at_Main_5 +label_main_at_Main_4: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 100($a0) + jalr $a0 + sw $a0, -60($fp) + lw $a0, -60($fp) + bne $a0, $zero, label_main_at_Main_6 + li $t1, 0 + sw $t1, -4($fp) + li $t1, 0 + sw $t1, -64($fp) + j label_main_at_Main_7 +label_main_at_Main_6: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 28($a0) + sw $a0, -72($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -72($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -72($fp) + lw $a0, 8($a0) + lw $a0, 92($a0) + jalr $a0 + sw $a0, -68($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 28($a0) + sw $a0, -80($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -80($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -76($fp) + + #fin llamada dinamica + + lw $t1, -76($fp) + sw $t1, -64($fp) +label_main_at_Main_7: + j label_main_at_Main_3 +label_main_at_Main_5: + la $t1, _void + sw $t1, -84($fp) + j label_main_at_Main_0 +label_main_at_Main_2: + la $t1, _void + sw $t1, -88($fp) + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 100 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_CellularAutomaton + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/list.mips b/tests/codegen/list.mips new file mode 100644 index 000000000..afb919b26 --- /dev/null +++ b/tests/codegen/list.mips @@ -0,0 +1,1647 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + List_name: .asciiz "List" + List_size: .word 12 +__virtual_table__List: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_isNil_at_List + .word function_head_at_List + .word function_tail_at_List + .word function_cons_at_List + Cons_name: .asciiz "Cons" + Cons_size: .word 20 +__virtual_table__Cons: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_isNil_at_Cons + .word function_head_at_Cons + .word function_tail_at_Cons + .word function_cons_at_List + .word function_init_at_Cons + Main_name: .asciiz "Main" + Main_size: .word 16 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_print_list_at_Main + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 32($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_isNil_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_head_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_tail_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_cons_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Cons_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Cons + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, List_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, List_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__List + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_List + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Object + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_head_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_tail_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_init_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 12($fp) + sw $t1, 16($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Cons_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Cons_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Cons + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Cons + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_List + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_print_list_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, 8($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + lw $a0, -4($fp) + bne $a0, $zero, label_print_list_at_Main_0 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, 8($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -12($fp) + la $t1, _empty + sw $t1, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, 8($fp) + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -32($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -28($fp) + sw $t1, -8($fp) + j label_print_list_at_Main_1 +label_print_list_at_Main_0: + la $t1, data_1 + sw $t1, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -8($fp) +label_print_list_at_Main_1: + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 56 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -60 + + #init allocate + + li $v0, 9 + lw $a0, List_size + syscall + sw $v0, -24($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_List + sw $a0, -28($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -24($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 2 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 3 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -12($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 5 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -4($fp) + sw $t1, 12($a0) + + #end set attribute + +label_main_at_Main_0: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -40($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -36($fp) + + #fin llamada dinamica + + lw $a0, -36($fp) + bne $a0, $zero, label_main_at_Main_3 + li $t1, 1 + sw $t1, -32($fp) + j label_main_at_Main_4 +label_main_at_Main_3: + li $t1, 0 + sw $t1, -32($fp) +label_main_at_Main_4: + lw $a0, -32($fp) + bne $a0, $zero, label_main_at_Main_1 + j label_main_at_Main_2 +label_main_at_Main_1: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -44($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -56($fp) + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -52($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -52($fp) + sw $t1, 12($a0) + + #end set attribute + + j label_main_at_Main_0 +label_main_at_Main_2: + la $t1, _void + sw $t1, -60($fp) + + #retornando el valor + + lw $a0, -60($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 72 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/new_complex.mips b/tests/codegen/new_complex.mips new file mode 100644 index 000000000..f25261c3f --- /dev/null +++ b/tests/codegen/new_complex.mips @@ -0,0 +1,1714 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Main_name: .asciiz "Main" + Main_size: .word 12 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_main_at_Main + Complex_name: .asciiz "Complex" + Complex_size: .word 20 +__virtual_table__Complex: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_init_at_Complex + .word function_print_at_Complex + .word function_reflect_0_at_Complex + .word function_reflect_X_at_Complex + .word function_reflect_Y_at_Complex + .word function_equal_at_Complex + .word function_x_value_at_Complex + .word function_y_value_at_Complex + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 28($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -88 + + #init allocate + + li $v0, 9 + lw $a0, Complex_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Complex + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, c + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, c + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + lw $a0, -28($fp) + sub $a0, $t1, $a0 + sw $a0, -32($fp) + lw $a0, -32($fp) + bne $a0, $zero, label_main_at_Main_0 + li $t1, 1 + sw $t1, -20($fp) + j label_main_at_Main_1 +label_main_at_Main_0: + li $t1, 0 + sw $t1, -20($fp) +label_main_at_Main_1: + lw $a0, -20($fp) + bne $a0, $zero, label_main_at_Main_2 + la $t1, data_1 + sw $t1, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -40($fp) + lw $t1, -40($fp) + sw $t1, -36($fp) + j label_main_at_Main_3 +label_main_at_Main_2: + la $t1, data_1 + sw $t1, -52($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -52($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -48($fp) + lw $t1, -48($fp) + sw $t1, -36($fp) +label_main_at_Main_3: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, c + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -64($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -64($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -60($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, c + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 36($a0) + jalr $a0 + sw $a0, -68($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -60($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -60($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -56($fp) + + #fin llamada dinamica + + lw $a0, -56($fp) + bne $a0, $zero, label_main_at_Main_4 + la $t1, data_1 + sw $t1, -80($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -80($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -76($fp) + lw $t1, -76($fp) + sw $t1, -72($fp) + j label_main_at_Main_5 +label_main_at_Main_4: + la $t1, data_1 + sw $t1, -88($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -88($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -84($fp) + lw $t1, -84($fp) + sw $t1, -72($fp) +label_main_at_Main_5: + + #retornando el valor + + lw $a0, -72($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 100 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_init_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -24 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + lw $t1, -8($fp) + lw $a0, 8($fp) + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_init_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_init_at_Complex_1 +label_init_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_init_at_Complex_1: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -20($fp) + lw $t1, -20($fp) + lw $a0, 12($fp) + sub $a0, $t1, $a0 + sw $a0, -24($fp) + lw $a0, -24($fp) + bne $a0, $zero, label_init_at_Complex_2 + li $t1, 1 + sw $t1, -16($fp) + j label_init_at_Complex_3 +label_init_at_Complex_2: + li $t1, 0 + sw $t1, -16($fp) +label_init_at_Complex_3: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 44 + lw $fp, 0($sp) + jr $ra +function_print_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -56 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -8($fp) + lw $t1, -8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_print_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_print_at_Complex_1 +label_print_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_print_at_Complex_1: + lw $a0, -4($fp) + bne $a0, $zero, label_print_at_Complex_2 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -36($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -32($fp) + la $t1, _empty + sw $t1, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -32($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -44($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -28($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + la $t1, _empty + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -24($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -20($fp) + + #fin llamada dinamica + + lw $t1, -20($fp) + sw $t1, -16($fp) + j label_print_at_Complex_3 +label_print_at_Complex_2: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -56($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -56($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -52($fp) + lw $t1, -52($fp) + sw $t1, -16($fp) +label_print_at_Complex_3: + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 68 + lw $fp, 0($sp) + jr $ra +function_reflect_0_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -12($fp) + lw $t1, -8($fp) + lw $a0, -12($fp) + sub $a0, $t1, $a0 + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_reflect_0_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_reflect_0_at_Complex_1 +label_reflect_0_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_reflect_0_at_Complex_1: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -28($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -36($fp) + lw $t1, -36($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -32($fp) + lw $t1, -28($fp) + lw $a0, -32($fp) + sub $a0, $t1, $a0 + sw $a0, -40($fp) + lw $a0, -40($fp) + bne $a0, $zero, label_reflect_0_at_Complex_2 + li $t1, 1 + sw $t1, -24($fp) + j label_reflect_0_at_Complex_3 +label_reflect_0_at_Complex_2: + li $t1, 0 + sw $t1, -24($fp) +label_reflect_0_at_Complex_3: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 52 + lw $fp, 0($sp) + jr $ra +function_reflect_X_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -12($fp) + lw $t1, -8($fp) + lw $a0, -12($fp) + sub $a0, $t1, $a0 + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_reflect_X_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_reflect_X_at_Complex_1 +label_reflect_X_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_reflect_X_at_Complex_1: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra +function_reflect_Y_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -20 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + lw $t1, -16($fp) + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -12($fp) + lw $t1, -8($fp) + lw $a0, -12($fp) + sub $a0, $t1, $a0 + sw $a0, -20($fp) + lw $a0, -20($fp) + bne $a0, $zero, label_reflect_Y_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_reflect_Y_at_Complex_1 +label_reflect_Y_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_reflect_Y_at_Complex_1: + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra +function_equal_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, 8($fp) + lw $a0, 8($a0) + lw $a0, 52($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + lw $a0, -12($fp) + sub $a0, $t1, $a0 + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_equal_at_Complex_0 + li $t1, 1 + sw $t1, -4($fp) + j label_equal_at_Complex_1 +label_equal_at_Complex_0: + li $t1, 0 + sw $t1, -4($fp) +label_equal_at_Complex_1: + lw $a0, -4($fp) + bne $a0, $zero, label_equal_at_Complex_2 + li $t1, 0 + sw $t1, -20($fp) + j label_equal_at_Complex_3 +label_equal_at_Complex_2: + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, 8($fp) + lw $a0, 8($a0) + lw $a0, 56($a0) + jalr $a0 + sw $a0, -32($fp) + + #fin llamada dinamica + + lw $t1, -28($fp) + lw $a0, -32($fp) + sub $a0, $t1, $a0 + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_equal_at_Complex_4 + li $t1, 1 + sw $t1, -24($fp) + j label_equal_at_Complex_5 +label_equal_at_Complex_4: + li $t1, 0 + sw $t1, -24($fp) +label_equal_at_Complex_5: + lw $a0, -24($fp) + bne $a0, $zero, label_equal_at_Complex_6 + li $t1, 0 + sw $t1, -40($fp) + j label_equal_at_Complex_7 +label_equal_at_Complex_6: + li $t1, 1 + sw $t1, -40($fp) +label_equal_at_Complex_7: + lw $t1, -40($fp) + sw $t1, -20($fp) +label_equal_at_Complex_3: + + #retornando el valor + + lw $a0, -20($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 56 + lw $fp, 0($sp) + jr $ra +function_x_value_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_y_value_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Complex_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Complex_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Complex + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Complex + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Complex: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/palindrome.mips b/tests/codegen/palindrome.mips new file mode 100644 index 000000000..955e13cc2 --- /dev/null +++ b/tests/codegen/palindrome.mips @@ -0,0 +1,1076 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Main_name: .asciiz "Main" + Main_size: .word 16 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_pal_at_Main + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 32($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_pal_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -72 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + li $a0, 0 + sub $a0, $t1, $a0 + sw $a0, -12($fp) + lw $a0, -12($fp) + bne $a0, $zero, label_pal_at_Main_0 + li $t1, 1 + sw $t1, -4($fp) + j label_pal_at_Main_1 +label_pal_at_Main_0: + li $t1, 0 + sw $t1, -4($fp) +label_pal_at_Main_1: + lw $a0, -4($fp) + bne $a0, $zero, label_pal_at_Main_2 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -24($fp) + + #fin llamada dinamica + + lw $t1, -24($fp) + li $a0, 1 + sub $a0, $t1, $a0 + sw $a0, -28($fp) + lw $a0, -28($fp) + bne $a0, $zero, label_pal_at_Main_4 + li $t1, 1 + sw $t1, -20($fp) + j label_pal_at_Main_5 +label_pal_at_Main_4: + li $t1, 0 + sw $t1, -20($fp) +label_pal_at_Main_5: + lw $a0, -20($fp) + bne $a0, $zero, label_pal_at_Main_6 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 0 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -40($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -52($fp) + + #fin llamada dinamica + + lw $t1, -52($fp) + li $a0, 1 + blt $t1, $a0, label_pal_at_Main_8 + li $a0, 0 + j label_pal_at_Main_9 +label_pal_at_Main_8: + li $a0, 1 +label_pal_at_Main_9: + sw $a0, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -44($fp) + + #fin llamada dinamica + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -44($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_comparer_string + sw $a0, -36($fp) + lw $a0, -36($fp) + bne $a0, $zero, label_pal_at_Main_10 + li $t1, 0 + sw $t1, -56($fp) + j label_pal_at_Main_11 +label_pal_at_Main_10: + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_length_at_String + sw $a0, -72($fp) + + #fin llamada dinamica + + lw $t1, -72($fp) + li $a0, 2 + blt $t1, $a0, label_pal_at_Main_12 + li $a0, 0 + j label_pal_at_Main_13 +label_pal_at_Main_12: + li $a0, 1 +label_pal_at_Main_13: + sw $a0, -68($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -68($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -64($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -64($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -60($fp) + lw $t1, -60($fp) + sw $t1, -56($fp) +label_pal_at_Main_11: + lw $t1, -56($fp) + sw $t1, -32($fp) + j label_pal_at_Main_7 +label_pal_at_Main_6: + li $t1, 1 + sw $t1, -32($fp) +label_pal_at_Main_7: + lw $t1, -32($fp) + sw $t1, -16($fp) + j label_pal_at_Main_3 +label_pal_at_Main_2: + li $t1, 1 + sw $t1, -16($fp) +label_pal_at_Main_3: + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 88 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + li $t1, 1 + li $t2, -1 + mul $t1 $t1 $t2 + sw $t1, -4($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -4($fp) + sw $t1, 12($a0) + + #end set attribute + + la $t1, data_1 + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 24($a0) + jalr $a0 + sw $a0, -20($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -16($fp) + lw $a0, -16($fp) + bne $a0, $zero, label_main_at_Main_0 + la $t1, data_1 + sw $t1, -32($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -28($fp) + lw $t1, -28($fp) + sw $t1, -24($fp) + j label_main_at_Main_1 +label_main_at_Main_0: + la $t1, data_1 + sw $t1, -40($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -36($fp) + lw $t1, -36($fp) + sw $t1, -24($fp) +label_main_at_Main_1: + + #retornando el valor + + lw $a0, -24($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 52 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/primes.mips b/tests/codegen/primes.mips new file mode 100644 index 000000000..7b989c7eb --- /dev/null +++ b/tests/codegen/primes.mips @@ -0,0 +1,733 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Main_name: .asciiz "Main" + Main_size: .word 32 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_main_at_Main + _empty: .asciiz "" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 28($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -8 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -8($fp) + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 16($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 0 + sw $t1, 20($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + li $t1, 500 + sw $t1, 24($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/print-cool.mips b/tests/codegen/print-cool.mips new file mode 100644 index 000000000..9c7626a73 --- /dev/null +++ b/tests/codegen/print-cool.mips @@ -0,0 +1,914 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + Main_name: .asciiz "Main" + Main_size: .word 12 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 28($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -48 + + #init allocate + + li $v0, 9 + lw $a0, Object_size + syscall + sw $v0, -20($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Object + sw $a0, -24($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 4($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -8($fp) + lw $t1, 4($fp) + li $a0, 1 + la $t2, _void + bne $t1, $t2, label_main_at_Main_0 + li $a0, 0 +label_main_at_Main_0: + sw $a0, -36($fp) + + #init allocate + + li $v0, 9 + lw $a0, Bool_size + syscall + sw $v0, -40($fp) + + #end allocate + + + #init set attribute + + lw $a0, -40($fp) + lw $t1, -36($fp) + sw $t1, 12($a0) + + #end set attribute + + + #LOAD inicia + + la $t1, Bool_name + lw $t2, -40($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Bool_size + lw $t2, -40($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Bool + lw $t2, -40($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -40($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -40($fp) + lw $a0, 8($a0) + lw $a0, 4($a0) + jalr $a0 + sw $a0, -32($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + li $a0, 3 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, 1 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -32($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_substr_at_String + sw $a0, -28($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + la $t1, data_1 + sw $t1, -48($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -48($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -44($fp) + + #retornando el valor + + lw $a0, -44($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 60 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file diff --git a/tests/codegen/sort-list.mips b/tests/codegen/sort-list.mips new file mode 100644 index 000000000..746de2712 --- /dev/null +++ b/tests/codegen/sort-list.mips @@ -0,0 +1,2614 @@ +.data + Int_name: .asciiz "Int" + Int_size: .word 16 +__virtual_table__Int: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + String_name: .asciiz "String" + String_size: .word 16 +__virtual_table__String: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_length_at_String + .word function_concat_at_String + .word function_substr_at_String + Bool_name: .asciiz "Bool" + Bool_size: .word 16 +__virtual_table__Bool: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + Object_name: .asciiz "Object" + Object_size: .word 12 +__virtual_table__Object: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + IO_name: .asciiz "IO" + IO_size: .word 12 +__virtual_table__IO: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + List_name: .asciiz "List" + List_size: .word 12 +__virtual_table__List: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_List + .word function_cons_at_List + .word function_car_at_List + .word function_cdr_at_List + .word function_rev_at_List + .word function_sort_at_List + .word function_insert_at_List + .word function_rcons_at_List + .word function_print_list_at_List + Cons_name: .asciiz "Cons" + Cons_size: .word 20 +__virtual_table__Cons: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_Cons + .word function_cons_at_List + .word function_car_at_Cons + .word function_cdr_at_Cons + .word function_rev_at_Cons + .word function_sort_at_Cons + .word function_insert_at_Cons + .word function_rcons_at_Cons + .word function_print_list_at_Cons + .word function_init_at_Cons + Nil_name: .asciiz "Nil" + Nil_size: .word 12 +__virtual_table__Nil: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_isNil_at_Nil + .word function_cons_at_List + .word function_car_at_List + .word function_cdr_at_List + .word function_rev_at_Nil + .word function_sort_at_Nil + .word function_insert_at_Nil + .word function_rcons_at_Nil + .word function_print_list_at_Nil + Main_name: .asciiz "Main" + Main_size: .word 16 +__virtual_table__Main: + .word function_abort_at_Object + .word function_type_name_at_Object + .word function_copy_at_Object + .word function_out_string_at_IO + .word function_out_int_at_IO + .word function_in_int_at_IO + .word function_in_string_at_IO + .word function_iota_at_Main + .word function_main_at_Main + _empty: .asciiz "" + data_1: .asciiz "n" + _error1: .asciiz "Abort called from class " + _salto_para_abort: .asciiz " +" + _buffer: .space 2048 + _void: .asciiz "" + + +.text +main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Main_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Main + sw $a0, -8($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + la $a0, __virtual_table__Main + lw $a0, 32($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_isNil_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_cons_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init allocate + + li $v0, 9 + lw $a0, Cons_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Cons + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -4($fp) + sw $t1, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, new_cell + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, None + lw $a0, 8($a0) + lw $a0, 64($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -16($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 32 + lw $fp, 0($sp) + jr $ra +function_car_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_cdr_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #init allocate + + li $v0, 9 + lw $a0, List_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_List + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -8($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 24 + lw $fp, 0($sp) + jr $ra +function_rev_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_sort_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_insert_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_rcons_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 40($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_print_list_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 0($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, List_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, List_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__List + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_List + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_List: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 0 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_init_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 8($fp) + sw $t1, 12($a0) + + #end set attribute + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, 12($fp) + sw $t1, 16($a0) + + #end set attribute + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_car_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_cdr_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_rev_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -12($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -8($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 56($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_sort_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -16 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -12($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -12($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -8($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 52($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_insert_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + li $a0, [] + bne $a0, $zero, label_insert_at_Cons_0 + + #init allocate + + li $v0, 9 + lw $a0, Cons_size + syscall + sw $v0, -12($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Cons + sw $a0, -16($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -20($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -28($fp) + lw $a0, 8($a0) + lw $a0, 52($a0) + jalr $a0 + sw $a0, -24($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -12($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -12($fp) + lw $a0, 8($a0) + lw $a0, 64($a0) + jalr $a0 + sw $a0, -8($fp) + + #fin llamada dinamica + + lw $t1, -8($fp) + sw $t1, -4($fp) + j label_insert_at_Cons_1 +label_insert_at_Cons_0: + + #init allocate + + li $v0, 9 + lw $a0, Cons_size + syscall + sw $v0, -36($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Cons + sw $a0, -40($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -36($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -36($fp) + lw $a0, 8($a0) + lw $a0, 64($a0) + jalr $a0 + sw $a0, -32($fp) + + #fin llamada dinamica + + lw $t1, -32($fp) + sw $t1, -4($fp) +label_insert_at_Cons_1: + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 56 + lw $fp, 0($sp) + jr $ra +function_rcons_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -24 + + #init allocate + + li $v0, 9 + lw $a0, Cons_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Cons + sw $a0, -12($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -16($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -24($fp) + lw $a0, 8($a0) + lw $a0, 56($a0) + jalr $a0 + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 64($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_print_list_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -24 + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 16($a0) + jalr $a0 + sw $a0, -4($fp) + la $t1, data_1 + sw $t1, -16($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -12($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 16($a0) + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -24($fp) + lw $a0, 8($a0) + lw $a0, 60($a0) + jalr $a0 + sw $a0, -20($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -20($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 36 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Cons_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Cons_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Cons + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Cons + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Cons: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_List + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_isNil_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_rev_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_sort_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_insert_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 56($a0) + jalr $a0 + sw $a0, -4($fp) + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra +function_rcons_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -12 + + #init allocate + + li $v0, 9 + lw $a0, Cons_size + syscall + sw $v0, -8($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Cons + sw $a0, -12($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -8($fp) + lw $a0, 8($a0) + lw $a0, 64($a0) + jalr $a0 + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 28 + lw $fp, 0($sp) + jr $ra +function_print_list_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -0 + + #retornando el valor + + li $a0, 1 + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Nil_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Nil_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Nil + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Nil + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Nil: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_List + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_iota_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -40 + + #init allocate + + li $v0, 9 + lw $a0, Nil_size + syscall + sw $v0, -4($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Nil + sw $a0, -8($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -4($fp) + sw $t1, 12($a0) + + #end set attribute + + li $t1, 0 + sw $t1, -12($fp) +label_iota_at_Main_0: + li $a0, [] + bne $a0, $zero, label_iota_at_Main_1 + j label_iota_at_Main_2 +label_iota_at_Main_1: + + #init allocate + + li $v0, 9 + lw $a0, Cons_size + syscall + sw $v0, -20($fp) + + #end allocate + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Ctr_at_Cons + sw $a0, -24($fp) + + #fin llamada dinamica + + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + li $a0, j + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 64($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #init set attribute + + lw $a0, 4($fp) + lw $t1, -16($fp) + sw $t1, 12($a0) + + #end set attribute + + li $t1, j + li $a0, 1 + add $a0, $a0, $t1 + sw $a0, -32($fp) + lw $t1, -32($fp) + sw $t1, -12($fp) + j label_iota_at_Main_0 +label_iota_at_Main_2: + la $t1, _void + sw $t1, -36($fp) + + #init get attribute + + lw $a0, 4($fp) + lw $a0, 12($a0) + sw $a0, -40($fp) + + #retornando el valor + + lw $a0, -40($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 56 + lw $fp, 0($sp) + jr $ra +function_main_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -28 + la $t1, _empty + sw $t1, -8($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -8($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 12($a0) + jalr $a0 + sw $a0, -4($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 20($a0) + jalr $a0 + sw $a0, -28($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -28($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + lw $a0, 4($fp) + lw $a0, 8($a0) + lw $a0, 28($a0) + jalr $a0 + sw $a0, -24($fp) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -24($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -24($fp) + lw $a0, 8($a0) + lw $a0, 44($a0) + jalr $a0 + sw $a0, -20($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -20($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -20($fp) + lw $a0, 8($a0) + lw $a0, 48($a0) + jalr $a0 + sw $a0, -16($fp) + + #fin llamada dinamica + + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, -16($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada dinamica + + lw $a0, -16($fp) + lw $a0, 8($a0) + lw $a0, 60($a0) + jalr $a0 + sw $a0, -12($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, -12($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 40 + lw $fp, 0($sp) + jr $ra +function_Ctr_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #LOAD inicia + + la $t1, Main_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + #LOAD inicia + + lw $t1, Main_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + #LOAD inicia + + la $t1, __virtual_table__Main + lw $t2, 4($fp) + sw $t1, 8($t2) + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_Main + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra +function_Init_at_Main: + + #muevo el fp al sp, pongo en sp ra y avanzo la pila + + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + #muevo la pila x las variables locales + + addiu $sp, $sp, -4 + + #guardando los parametros + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + # fin guardando los parametros + + + #comienzo llamada al constructor + + jal function_Init_at_IO + sw $a0, -4($fp) + + #fin llamada dinamica + + + #retornando el valor + + lw $a0, 4($fp) + + #return sp, fp, ra + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_Ctr_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, Object_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, Object_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__Object + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Ctr_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $t1, IO_name + lw $t2, 4($fp) + sw $t1, 0($t2) + + lw $t1, IO_size + lw $t2, 4($fp) + sw $t1, 4($t2) + + la $t1, __virtual_table__IO + lw $t2, 4($fp) + sw $t1, 8($t2) + + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_Init_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_type_name_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + lw $a0, 4($fp) + lw $a0 0($a0) + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_abort_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + la $a0, _error1 + li $v0, 4 + syscall + lw $a0 4($fp) + lw $a0 ($a0) + li $v0, 4 + syscall + la $a0, _salto_para_abort + li $v0, 4 + syscall + li $v0, 10 + syscall + +function_copy_at_Object: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Int_name + + bne $a0, $t0, not_int + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_int: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, Bool_name + + bne $a0, $t0, not_bool + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_bool: + lw $a0, 4($fp) + lw $a0, 0($a0) + la $t0, String_name + + bne $a0, $t0, not_string + lw $a0, 4($fp) + lw $a0, 8($a0) + j end + + not_string: + lw $a0, 4($fp) + move $t2, $a0 + lw $a0, 4($a0) + move $t1, $a0 + + li $v0, 9 + syscall + + move $a0, $v0 + + copy: + lw $t0, 0($t2) + sw $t0, 0($a0) + addiu $a0, $a0, 4 + addiu $t2, $t2, 4 + addiu $t1, $t1, -4 + bne $t1, $zero, copy + + move $a0, $v0 + + end: + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_length_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s0, 4($fp) + li $a0, -1 + + length: + lb $t0, ($s0) + addiu $a0, $a0, 1 + addiu $s0, $s0, 1 + bne $t0, $zero, length + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_concat_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + move $t6, $a0 + add $a0, $t7, $t6 + addiu $a0, $a0, 1 + + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + copy_self: + lb $t5, ($s1) + beq $t5, $zero, end_copy_self + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + j copy_self + + end_copy_self: + lw $s1, 8($fp) + + copy_given: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + bne $t5, $zero, copy_given + + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + +function_substr_at_String: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 12($fp) + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + + lw $s1, 4($fp) + lw $t1, 8($fp) + add $s1, $s1, $t1 + + lw $t1, 12($fp) + + substr: + lb $t5, ($s1) + sb $t5, ($t0) + addiu $s1, $s1, 1 + addiu $t0, $t0, 1 + addiu $t1, $t1, -1 + bne $t1, $zero, substr + + sb $zero, ($t0) + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 20 + lw $fp, 0($sp) + jr $ra + + +function_comparer_string: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 4($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + sw $a0, 0($sp) + addiu $sp, $sp, -4 + + lw $s1, 8($fp) + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $s1, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + lw $t7, 4($sp) + addiu $sp, $sp, 4 + + bne $t7, $a0, not_equals_strings + + lw $t7, 4($fp) + lw $a0, 8($fp) + + equal_chart: + lb $t1, ($t7) + lb $t2, ($a0) + addiu $t7, $t7, 1 + addiu $a0, $a0, 1 + bne $t1, $t2, not_equals_strings + beq $t1, $zero, equals_strings + j equal_chart + + not_equals_strings: + li $a0, 0 + j end_equal_string + + equals_strings: + li $a0, 1 + + end_equal_string: + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + + + +function_out_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 4 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_out_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 8($fp) + li $v0, 1 + syscall + + lw $a0, 4($fp) + + lw $ra, 0($fp) + addiu $sp, $sp, 16 + lw $fp, 0($sp) + jr $ra + +function_in_int_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + lw $a0, 4($fp) + li $v0, 5 + syscall + + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + +function_in_string_at_IO: + move $fp, $sp + sw $ra, 0($sp) + addiu $sp, $sp, -4 + + la $a0, _buffer + li $a1, 1024 + + li $v0, 8 + syscall + + sw $fp, 0($sp) + addiu $sp, $sp, -4 + sw $a0, 0($sp) + addiu $sp, $sp, -4 + jal function_length_at_String + + addiu $a0, $a0, 1 + li $v0, 9 + syscall + + move $t0, $v0 + la $a0, _buffer + + IO_copy: + lb $t1, ($a0) + sb $t1, ($t0) + addiu $a0, $a0, 1 + addiu $t0, $t0, 1 + bne $t1, $zero, IO_copy + + addiu $t0, $t0, -2 + li $t1 10 + lb $t2, ($t0) + bne $t1 , $t2 not_slash + sb $zero, ($t0) + + not_slash: + move $a0, $v0 + + lw $ra, 0($fp) + addiu $sp, $sp, 12 + lw $fp, 0($sp) + jr $ra + + \ No newline at end of file From 98d14e88518109eab2cdaf1f16369fef4a716b13 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 21:17:49 -0300 Subject: [PATCH 52/60] fix litle problems --- src/compiler_components/cool_cil_converter.py | 12 ++++++++++++ src/compiler_components/lexer.py | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/compiler_components/cool_cil_converter.py b/src/compiler_components/cool_cil_converter.py index 5fea70824..225b3bf64 100644 --- a/src/compiler_components/cool_cil_converter.py +++ b/src/compiler_components/cool_cil_converter.py @@ -366,6 +366,18 @@ def visit(self, node, scope): return result @visitor.when(MinusNode) + def visit(self, node, scope): + result = define_internal_local(self) + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + + labelTrue = register_label(self) + labelEnd = register_label(self) + + register_instruction(self, CilLessNode(result, left, right, labelTrue, labelEnd)) + return result + + @visitor.when(MinorNode) def visit(self, node, scope): result = define_internal_local(self) left = self.visit(node.left, scope.children[0]) diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index de762c71b..9c9775b87 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -126,12 +126,14 @@ def t_STRING(self, t): s+='\t' elif rest_data[index] == 'f': s+='\f' - elif rest_data[index] == '\n': + elif rest_data[index] == '\n' or rest_data[index] == 'n': s+='\n' t.lexer.lineno += 1 else: s+= rest_data[index] - + else: + s+= rest_data[index] + t.lexer.skip(1) index+=1 From 1669a0bf80f11cc980291f0f9c25ef00374ed814 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 21:22:56 -0300 Subject: [PATCH 53/60] delete code gen folder --- tests/codegen/arith.cl | 430 --------------- tests/codegen/arith_input.txt | 13 - tests/codegen/arith_output.txt | 158 ------ tests/codegen/atoi.cl | 121 ----- tests/codegen/atoi_input.txt | 0 tests/codegen/atoi_output.txt | 1 - tests/codegen/book_list.cl | 132 ----- tests/codegen/book_list_input.txt | 0 tests/codegen/book_list_output.txt | 7 - tests/codegen/cells.cl | 97 ---- tests/codegen/cells_input.txt | 0 tests/codegen/cells_output.txt | 21 - tests/codegen/complex.cl | 52 -- tests/codegen/complex_input.txt | 0 tests/codegen/complex_output.txt | 1 - tests/codegen/fib.cl | 29 - tests/codegen/fib_input.txt | 1 - tests/codegen/fib_output.txt | 2 - tests/codegen/graph.cl | 381 ------------- tests/codegen/graph_input.txt | 5 - tests/codegen/graph_output.txt | 7 - tests/codegen/hairyscary.cl | 67 --- tests/codegen/hairyscary_input.txt | 0 tests/codegen/hairyscary_output.txt | 1 - tests/codegen/hello_world.cl | 5 - tests/codegen/hello_world_input.txt | 0 tests/codegen/hello_world_output.txt | 1 - tests/codegen/io.cl | 103 ---- tests/codegen/io_input.txt | 0 tests/codegen/io_output.txt | 5 - tests/codegen/life.cl | 436 --------------- tests/codegen/life_input.txt | 66 --- tests/codegen/life_output.txt | 778 --------------------------- tests/codegen/list.cl | 141 ----- tests/codegen/list_input.txt | 0 tests/codegen/list_output.txt | 5 - tests/codegen/new_complex.cl | 79 --- tests/codegen/new_complex_input.txt | 0 tests/codegen/new_complex_output.txt | 2 - tests/codegen/palindrome.cl | 25 - tests/codegen/palindrome_input.txt | 1 - tests/codegen/palindrome_output.txt | 2 - tests/codegen/primes.cl | 84 --- tests/codegen/primes_input.txt | 0 tests/codegen/primes_output.txt | 96 ---- tests/codegen/print-cool.cl | 9 - tests/codegen/print-cool_input.txt | 0 tests/codegen/print-cool_output.txt | 1 - tests/codegen/sort-list.cl | 146 ----- tests/codegen/sort-list_input.txt | 1 - tests/codegen/sort-list_output.txt | 10 - 51 files changed, 3522 deletions(-) delete mode 100755 tests/codegen/arith.cl delete mode 100644 tests/codegen/arith_input.txt delete mode 100644 tests/codegen/arith_output.txt delete mode 100644 tests/codegen/atoi.cl delete mode 100644 tests/codegen/atoi_input.txt delete mode 100644 tests/codegen/atoi_output.txt delete mode 100755 tests/codegen/book_list.cl delete mode 100644 tests/codegen/book_list_input.txt delete mode 100644 tests/codegen/book_list_output.txt delete mode 100755 tests/codegen/cells.cl delete mode 100644 tests/codegen/cells_input.txt delete mode 100644 tests/codegen/cells_output.txt delete mode 100755 tests/codegen/complex.cl delete mode 100644 tests/codegen/complex_input.txt delete mode 100644 tests/codegen/complex_output.txt delete mode 100644 tests/codegen/fib.cl delete mode 100644 tests/codegen/fib_input.txt delete mode 100644 tests/codegen/fib_output.txt delete mode 100755 tests/codegen/graph.cl delete mode 100644 tests/codegen/graph_input.txt delete mode 100644 tests/codegen/graph_output.txt delete mode 100755 tests/codegen/hairyscary.cl delete mode 100644 tests/codegen/hairyscary_input.txt delete mode 100644 tests/codegen/hairyscary_output.txt delete mode 100755 tests/codegen/hello_world.cl delete mode 100644 tests/codegen/hello_world_input.txt delete mode 100644 tests/codegen/hello_world_output.txt delete mode 100755 tests/codegen/io.cl delete mode 100644 tests/codegen/io_input.txt delete mode 100644 tests/codegen/io_output.txt delete mode 100755 tests/codegen/life.cl delete mode 100644 tests/codegen/life_input.txt delete mode 100644 tests/codegen/life_output.txt delete mode 100644 tests/codegen/list.cl delete mode 100644 tests/codegen/list_input.txt delete mode 100644 tests/codegen/list_output.txt delete mode 100755 tests/codegen/new_complex.cl delete mode 100644 tests/codegen/new_complex_input.txt delete mode 100644 tests/codegen/new_complex_output.txt delete mode 100755 tests/codegen/palindrome.cl delete mode 100644 tests/codegen/palindrome_input.txt delete mode 100644 tests/codegen/palindrome_output.txt delete mode 100644 tests/codegen/primes.cl delete mode 100644 tests/codegen/primes_input.txt delete mode 100644 tests/codegen/primes_output.txt delete mode 100644 tests/codegen/print-cool.cl delete mode 100644 tests/codegen/print-cool_input.txt delete mode 100644 tests/codegen/print-cool_output.txt delete mode 100644 tests/codegen/sort-list.cl delete mode 100644 tests/codegen/sort-list_input.txt delete mode 100644 tests/codegen/sort-list_output.txt diff --git a/tests/codegen/arith.cl b/tests/codegen/arith.cl deleted file mode 100755 index af5951cf7..000000000 --- a/tests/codegen/arith.cl +++ /dev/null @@ -1,430 +0,0 @@ -(* - * A contribution from Anne Sheets (sheets@cory) - * - * Tests the arithmetic operations and various other things - *) - -class A { - - var : Int <- 0; - - value() : Int { var }; - - set_var(num : Int) : A{ - { - var <- num; - self; - } - }; - - method1(num : Int) : A { -- same - self - }; - - method2(num1 : Int, num2 : Int) : A { -- plus - (let x : Int in - { - x <- num1 + num2; - (new B).set_var(x); - } - ) - }; - - method3(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new C).set_var(x); - } - ) - }; - - method4(num1 : Int, num2 : Int) : A { -- diff - if num2 < num1 then - (let x : Int in - { - x <- num1 - num2; - (new D).set_var(x); - } - ) - else - (let x : Int in - { - x <- num2 - num1; - (new D).set_var(x); - } - ) - fi - }; - - method5(num : Int) : A { -- factorial - (let x : Int <- 1 in - { - (let y : Int <- 1 in - while y <= num loop - { - x <- x * y; - y <- y + 1; - } - pool - ); - (new E).set_var(x); - } - ) - }; - -}; - -class B inherits A { -- B is a number squared - - method5(num : Int) : A { -- square - (let x : Int in - { - x <- num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class C inherits B { - - method6(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new A).set_var(x); - } - ) - }; - - method5(num : Int) : A { -- cube - (let x : Int in - { - x <- num * num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class D inherits B { - - method7(num : Int) : Bool { -- divisible by 3 - (let x : Int <- num in - if x < 0 then method7(~x) else - if 0 = x then true else - if 1 = x then false else - if 2 = x then false else - method7(x - 3) - fi fi fi fi - ) - }; - -}; - -class E inherits D { - - method6(num : Int) : A { -- division - (let x : Int in - { - x <- num / 8; - (new A).set_var(x); - } - ) - }; - -}; - -(* The following code is from atoi.cl in ~cs164/examples *) - -(* - The class A2I provides integer-to-string and string-to-integer -conversion routines. To use these routines, either inherit them -in the class where needed, have a dummy variable bound to -something of type A2I, or simpl write (new A2I).method(argument). -*) - - -(* - c2i Converts a 1-character string to an integer. Aborts - if the string is not "0" through "9" -*) -class A2I { - - c2i(char : String) : Int { - if char = "0" then 0 else - if char = "1" then 1 else - if char = "2" then 2 else - if char = "3" then 3 else - if char = "4" then 4 else - if char = "5" then 5 else - if char = "6" then 6 else - if char = "7" then 7 else - if char = "8" then 8 else - if char = "9" then 9 else - { abort(); 0; } (* the 0 is needed to satisfy the - typchecker *) - fi fi fi fi fi fi fi fi fi fi - }; - -(* - i2c is the inverse of c2i. -*) - i2c(i : Int) : String { - if i = 0 then "0" else - if i = 1 then "1" else - if i = 2 then "2" else - if i = 3 then "3" else - if i = 4 then "4" else - if i = 5 then "5" else - if i = 6 then "6" else - if i = 7 then "7" else - if i = 8 then "8" else - if i = 9 then "9" else - { abort(); ""; } -- the "" is needed to satisfy the typchecker - fi fi fi fi fi fi fi fi fi fi - }; - -(* - a2i converts an ASCII string into an integer. The empty string -is converted to 0. Signed and unsigned strings are handled. The -method aborts if the string does not represent an integer. Very -long strings of digits produce strange answers because of arithmetic -overflow. - -*) - a2i(s : String) : Int { - if s.length() = 0 then 0 else - if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else - if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else - a2i_aux(s) - fi fi fi - }; - -(* a2i_aux converts the usigned portion of the string. As a - programming example, this method is written iteratively. *) - - - a2i_aux(s : String) : Int { - (let int : Int <- 0 in - { - (let j : Int <- s.length() in - (let i : Int <- 0 in - while i < j loop - { - int <- int * 10 + c2i(s.substr(i,1)); - i <- i + 1; - } - pool - ) - ); - int; - } - ) - }; - -(* i2a converts an integer to a string. Positive and negative - numbers are handled correctly. *) - - i2a(i : Int) : String { - if i = 0 then "0" else - if 0 < i then i2a_aux(i) else - "-".concat(i2a_aux(i * ~1)) - fi fi - }; - -(* i2a_aux is an example using recursion. *) - - i2a_aux(i : Int) : String { - if i = 0 then "" else - (let next : Int <- i / 10 in - i2a_aux(next).concat(i2c(i - next * 10)) - ) - fi - }; - -}; - -class Main inherits IO { - - char : String; - avar : A; - a_var : A; - flag : Bool <- true; - - - menu() : String { - { - out_string("\n\tTo add a number to "); - print(avar); - out_string("...enter a:\n"); - out_string("\tTo negate "); - print(avar); - out_string("...enter b:\n"); - out_string("\tTo find the difference between "); - print(avar); - out_string("and another number...enter c:\n"); - out_string("\tTo find the factorial of "); - print(avar); - out_string("...enter d:\n"); - out_string("\tTo square "); - print(avar); - out_string("...enter e:\n"); - out_string("\tTo cube "); - print(avar); - out_string("...enter f:\n"); - out_string("\tTo find out if "); - print(avar); - out_string("is a multiple of 3...enter g:\n"); - out_string("\tTo divide "); - print(avar); - out_string("by 8...enter h:\n"); - out_string("\tTo get a new number...enter j:\n"); - out_string("\tTo quit...enter q:\n\n"); - in_string(); - } - }; - - prompt() : String { - { - out_string("\n"); - out_string("Please enter a number... "); - in_string(); - } - }; - - get_int() : Int { - { - (let z : A2I <- new A2I in - (let s : String <- prompt() in - z.a2i(s) - ) - ); - } - }; - - is_even(num : Int) : Bool { - (let x : Int <- num in - if x < 0 then is_even(~x) else - if 0 = x then true else - if 1 = x then false else - is_even(x - 2) - fi fi fi - ) - }; - - class_type(var : A) : IO { - case var of - a : A => out_string("Class type is now A\n"); - b : B => out_string("Class type is now B\n"); - c : C => out_string("Class type is now C\n"); - d : D => out_string("Class type is now D\n"); - e : E => out_string("Class type is now E\n"); - o : Object => out_string("Oooops\n"); - esac - }; - - print(var : A) : IO { - (let z : A2I <- new A2I in - { - out_string(z.i2a(var.value())); - out_string(" "); - } - ) - }; - - main() : Object { - { - avar <- (new A); - while flag loop - { - -- avar <- (new A).set_var(get_int()); - out_string("number "); - print(avar); - if is_even(avar.value()) then - out_string("is even!\n") - else - out_string("is odd!\n") - fi; - -- print(avar); -- prints out answer - class_type(avar); - char <- menu(); - if char = "a" then -- add - { - a_var <- (new A).set_var(get_int()); - avar <- (new B).method2(avar.value(), a_var.value()); - } else - if char = "b" then -- negate - case avar of - c : C => avar <- c.method6(c.value()); - a : A => avar <- a.method3(a.value()); - o : Object => { - out_string("Oooops\n"); - abort(); 0; - }; - esac else - if char = "c" then -- diff - { - a_var <- (new A).set_var(get_int()); - avar <- (new D).method4(avar.value(), a_var.value()); - } else - if char = "d" then avar <- (new C)@A.method5(avar.value()) else - -- factorial - if char = "e" then avar <- (new C)@B.method5(avar.value()) else - -- square - if char = "f" then avar <- (new C)@C.method5(avar.value()) else - -- cube - if char = "g" then -- multiple of 3? - if ((new D).method7(avar.value())) - then -- avar <- (new A).method1(avar.value()) - { - out_string("number "); - print(avar); - out_string("is divisible by 3.\n"); - } - else -- avar <- (new A).set_var(0) - { - out_string("number "); - print(avar); - out_string("is not divisible by 3.\n"); - } - fi else - if char = "h" then - (let x : A in - { - x <- (new E).method6(avar.value()); - (let r : Int <- (avar.value() - (x.value() * 8)) in - { - out_string("number "); - print(avar); - out_string("is equal to "); - print(x); - out_string("times 8 with a remainder of "); - (let a : A2I <- new A2I in - { - out_string(a.i2a(r)); - out_string("\n"); - } - ); -- end let a: - } - ); -- end let r: - avar <- x; - } - ) -- end let x: - else - if char = "j" then avar <- (new A) - else - if char = "q" then flag <- false - else - avar <- (new A).method1(avar.value()) -- divide/8 - fi fi fi fi fi fi fi fi fi fi; - } - pool; - } - }; - -}; - diff --git a/tests/codegen/arith_input.txt b/tests/codegen/arith_input.txt deleted file mode 100644 index 83e05b1ea..000000000 --- a/tests/codegen/arith_input.txt +++ /dev/null @@ -1,13 +0,0 @@ -a -1 -b -c -0 -d -e -f -g -h -j -5 -q diff --git a/tests/codegen/arith_output.txt b/tests/codegen/arith_output.txt deleted file mode 100644 index 44b4ce73e..000000000 --- a/tests/codegen/arith_output.txt +++ /dev/null @@ -1,158 +0,0 @@ -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now B - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number -1 is odd! -Class type is now C - - To add a number to -1 ...enter a: - To negate -1 ...enter b: - To find the difference between -1 and another number...enter c: - To find the factorial of -1 ...enter d: - To square -1 ...enter e: - To cube -1 ...enter f: - To find out if -1 is a multiple of 3...enter g: - To divide -1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now D - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is not divisible by 3. -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is equal to 0 times 8 with a remainder of 1 -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - diff --git a/tests/codegen/atoi.cl b/tests/codegen/atoi.cl deleted file mode 100644 index fd8b2ea42..000000000 --- a/tests/codegen/atoi.cl +++ /dev/null @@ -1,121 +0,0 @@ -(* - The class A2I provides integer-to-string and string-to-integer -conversion routines. To use these routines, either inherit them -in the class where needed, have a dummy variable bound to -something of type A2I, or simpl write (new A2I).method(argument). -*) - - -(* - c2i Converts a 1-character string to an integer. Aborts - if the string is not "0" through "9" -*) -class A2I { - - c2i(char : String) : Int { - if char = "0" then 0 else - if char = "1" then 1 else - if char = "2" then 2 else - if char = "3" then 3 else - if char = "4" then 4 else - if char = "5" then 5 else - if char = "6" then 6 else - if char = "7" then 7 else - if char = "8" then 8 else - if char = "9" then 9 else - { abort(); 0; } -- the 0 is needed to satisfy the typchecker - fi fi fi fi fi fi fi fi fi fi - }; - -(* - i2c is the inverse of c2i. -*) - i2c(i : Int) : String { - if i = 0 then "0" else - if i = 1 then "1" else - if i = 2 then "2" else - if i = 3 then "3" else - if i = 4 then "4" else - if i = 5 then "5" else - if i = 6 then "6" else - if i = 7 then "7" else - if i = 8 then "8" else - if i = 9 then "9" else - { abort(); ""; } -- the "" is needed to satisfy the typchecker - fi fi fi fi fi fi fi fi fi fi - }; - -(* - a2i converts an ASCII string into an integer. The empty string -is converted to 0. Signed and unsigned strings are handled. The -method aborts if the string does not represent an integer. Very -long strings of digits produce strange answers because of arithmetic -overflow. - -*) - a2i(s : String) : Int { - if s.length() = 0 then 0 else - if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else - if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else - a2i_aux(s) - fi fi fi - }; - -(* - a2i_aux converts the usigned portion of the string. As a programming -example, this method is written iteratively. -*) - a2i_aux(s : String) : Int { - (let int : Int <- 0 in - { - (let j : Int <- s.length() in - (let i : Int <- 0 in - while i < j loop - { - int <- int * 10 + c2i(s.substr(i,1)); - i <- i + 1; - } - pool - ) - ); - int; - } - ) - }; - -(* - i2a converts an integer to a string. Positive and negative -numbers are handled correctly. -*) - i2a(i : Int) : String { - if i = 0 then "0" else - if 0 < i then i2a_aux(i) else - "-".concat(i2a_aux(i * ~1)) - fi fi - }; - -(* - i2a_aux is an example using recursion. -*) - i2a_aux(i : Int) : String { - if i = 0 then "" else - (let next : Int <- i / 10 in - i2a_aux(next).concat(i2c(i - next * 10)) - ) - fi - }; - -}; - -class Main inherits IO { - main () : Object { - let a : Int <- (new A2I).a2i("678987"), - b : String <- (new A2I).i2a(678987) in - { - out_int(a) ; - out_string(" == ") ; - out_string(b) ; - out_string("\n"); - } - } ; -} ; diff --git a/tests/codegen/atoi_input.txt b/tests/codegen/atoi_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/atoi_output.txt b/tests/codegen/atoi_output.txt deleted file mode 100644 index 51b815a48..000000000 --- a/tests/codegen/atoi_output.txt +++ /dev/null @@ -1 +0,0 @@ -678987 == 678987 diff --git a/tests/codegen/book_list.cl b/tests/codegen/book_list.cl deleted file mode 100755 index 025ea1695..000000000 --- a/tests/codegen/book_list.cl +++ /dev/null @@ -1,132 +0,0 @@ --- example of static and dynamic type differing for a dispatch - -Class Book inherits IO { - title : String; - author : String; - - initBook(title_p : String, author_p : String) : Book { - { - title <- title_p; - author <- author_p; - self; - } - }; - - print() : Book { - { - out_string("title: ").out_string(title).out_string("\n"); - out_string("author: ").out_string(author).out_string("\n"); - self; - } - }; -}; - -Class Article inherits Book { - per_title : String; - - initArticle(title_p : String, author_p : String, - per_title_p : String) : Article { - { - initBook(title_p, author_p); - per_title <- per_title_p; - self; - } - }; - - print() : Book { - { - self@Book.print(); - out_string("periodical: ").out_string(per_title).out_string("\n"); - self; - } - }; -}; - -Class BookList inherits IO { - (* Since abort "returns" type Object, we have to add - an expression of type Bool here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - isNil() : Bool { { abort(); true; } }; - - cons(hd : Book) : Cons { - (let new_cell : Cons <- new Cons in - new_cell.init(hd,self) - ) - }; - - (* Since abort "returns" type Object, we have to add - an expression of type Book here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - car() : Book { { abort(); new Book; } }; - - (* Since abort "returns" type Object, we have to add - an expression of type BookList here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - cdr() : BookList { { abort(); new BookList; } }; - - print_list() : Object { abort() }; -}; - -Class Cons inherits BookList { - xcar : Book; -- We keep the car and cdr in attributes. - xcdr : BookList; -- Because methods and features must have different names, - -- we use xcar and xcdr for the attributes and reserve - -- car and cdr for the features. - - isNil() : Bool { false }; - - init(hd : Book, tl : BookList) : Cons { - { - xcar <- hd; - xcdr <- tl; - self; - } - }; - - car() : Book { xcar }; - - cdr() : BookList { xcdr }; - - print_list() : Object { - { - case xcar.print() of - dummy : Book => out_string("- dynamic type was Book -\n"); - dummy : Article => out_string("- dynamic type was Article -\n"); - esac; - xcdr.print_list(); - } - }; -}; - -Class Nil inherits BookList { - isNil() : Bool { true }; - - print_list() : Object { true }; -}; - - -Class Main { - - books : BookList; - - main() : Object { - (let a_book : Book <- - (new Book).initBook("Compilers, Principles, Techniques, and Tools", - "Aho, Sethi, and Ullman") - in - (let an_article : Article <- - (new Article).initArticle("The Top 100 CD_ROMs", - "Ulanoff", - "PC Magazine") - in - { - books <- (new Nil).cons(a_book).cons(an_article); - books.print_list(); - } - ) -- end let an_article - ) -- end let a_book - }; -}; diff --git a/tests/codegen/book_list_input.txt b/tests/codegen/book_list_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/book_list_output.txt b/tests/codegen/book_list_output.txt deleted file mode 100644 index 3408320b2..000000000 --- a/tests/codegen/book_list_output.txt +++ /dev/null @@ -1,7 +0,0 @@ -title: The Top 100 CD_ROMs -author: Ulanoff -periodical: PC Magazine -- dynamic type was Article - -title: Compilers, Principles, Techniques, and Tools -author: Aho, Sethi, and Ullman -- dynamic type was Book - diff --git a/tests/codegen/cells.cl b/tests/codegen/cells.cl deleted file mode 100755 index 9fd6741bb..000000000 --- a/tests/codegen/cells.cl +++ /dev/null @@ -1,97 +0,0 @@ -(* models one-dimensional cellular automaton on a circle of finite radius - arrays are faked as Strings, - X's respresent live cells, dots represent dead cells, - no error checking is done *) -class CellularAutomaton inherits IO { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - self; - } - }; - - print() : CellularAutomaton { - { - out_string(population_map.concat("\n")); - self; - } - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - population_map.substr(position, 1) - }; - - cell_left_neighbor(position : Int) : String { - if position = 0 then - cell(num_cells() - 1) - else - cell(position - 1) - fi - }; - - cell_right_neighbor(position : Int) : String { - if position = num_cells() - 1 then - cell(0) - else - cell(position + 1) - fi - }; - - (* a cell will live if exactly 1 of itself and it's immediate - neighbors are alive *) - cell_at_next_evolution(position : Int) : String { - if (if cell(position) = "X" then 1 else 0 fi - + if cell_left_neighbor(position) = "X" then 1 else 0 fi - + if cell_right_neighbor(position) = "X" then 1 else 0 fi - = 1) - then - "X" - else - "." - fi - }; - - evolve() : CellularAutomaton { - (let position : Int in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; -}; - -class Main { - cells : CellularAutomaton; - - main() : Main { - { - cells <- (new CellularAutomaton).init(" X "); - cells.print(); - (let countdown : Int <- 20 in - while 0 < countdown loop - { - cells.evolve(); - cells.print(); - countdown <- countdown - 1; - } - pool - ); - self; - } - }; -}; diff --git a/tests/codegen/cells_input.txt b/tests/codegen/cells_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/cells_output.txt b/tests/codegen/cells_output.txt deleted file mode 100644 index 6304902cc..000000000 --- a/tests/codegen/cells_output.txt +++ /dev/null @@ -1,21 +0,0 @@ - X -........XXX........ -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. -XXX.............XXX -...X...........X... -..XXX.........XXX.. -.X...X.......X...X. -XXX.XXX.....XXX.XXX -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. diff --git a/tests/codegen/complex.cl b/tests/codegen/complex.cl deleted file mode 100755 index 0b7aa44e9..000000000 --- a/tests/codegen/complex.cl +++ /dev/null @@ -1,52 +0,0 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - if c.reflect_X().reflect_Y() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; -}; diff --git a/tests/codegen/complex_input.txt b/tests/codegen/complex_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/complex_output.txt b/tests/codegen/complex_output.txt deleted file mode 100644 index 18b77c1fc..000000000 --- a/tests/codegen/complex_output.txt +++ /dev/null @@ -1 +0,0 @@ -=) diff --git a/tests/codegen/fib.cl b/tests/codegen/fib.cl deleted file mode 100644 index 08ceaede8..000000000 --- a/tests/codegen/fib.cl +++ /dev/null @@ -1,29 +0,0 @@ -class Main inherits IO { - -- the class has features. Only methods in this case. - main(): Object { - { - out_string("Enter n to find nth fibonacci number!\n"); - out_int(fib(in_int())); - out_string("\n"); - } - }; - - fib(i : Int) : Int { -- list of formals. And the return type of the method. - let a : Int <- 1, - b : Int <- 0, - c : Int <- 0 - in - { - while (not (i = 0)) loop -- expressions are nested. - { - c <- a + b; - i <- i - 1; - b <- a; - a <- c; - } - pool; - c; - } - }; - -}; diff --git a/tests/codegen/fib_input.txt b/tests/codegen/fib_input.txt deleted file mode 100644 index f599e28b8..000000000 --- a/tests/codegen/fib_input.txt +++ /dev/null @@ -1 +0,0 @@ -10 diff --git a/tests/codegen/fib_output.txt b/tests/codegen/fib_output.txt deleted file mode 100644 index d402da6af..000000000 --- a/tests/codegen/fib_output.txt +++ /dev/null @@ -1,2 +0,0 @@ -Enter n to find nth fibonacci number! -89 diff --git a/tests/codegen/graph.cl b/tests/codegen/graph.cl deleted file mode 100755 index 8e511358c..000000000 --- a/tests/codegen/graph.cl +++ /dev/null @@ -1,381 +0,0 @@ -(* - * Cool program reading descriptions of weighted directed graphs - * from stdin. It builds up a graph objects with a list of vertices - * and a list of edges. Every vertice has a list of outgoing edges. - * - * INPUT FORMAT - * Every line has the form vertice successor* - * Where vertice is an int, and successor is vertice,weight - * - * An empty line or EOF terminates the input. - * - * The list of vertices and the edge list is printed out by the Main - * class. - * - * TEST - * Once compiled, the file g1.graph can be fed to the program. - * The output should look like this: - -nautilus.CS.Berkeley.EDU 53# spim -file graph.s (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - b : Int <- a.doh() + g.doh() + doh() + printh(); - - doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; - -}; - -class Bar inherits Razz { - - c : Int <- doh(); - - d : Object <- printh(); -}; - - -class Razz inherits Foo { - - e : Bar <- case self of - n : Razz => (new Bar); - n : Bar => n; - esac; - - f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); - -}; - -class Bazz inherits IO { - - h : Int <- 1; - - g : Foo <- case self of - n : Bazz => (new Foo); - n : Razz => (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - i : Object <- printh(); - - printh() : Int { { out_int(h); 0; } }; - - doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; -}; - -(* scary . . . *) -class Main { - a : Bazz <- new Bazz; - b : Foo <- new Foo; - c : Razz <- new Razz; - d : Bar <- new Bar; - - main(): String { "do nothing" }; - -}; - - - - - diff --git a/tests/codegen/hairyscary_input.txt b/tests/codegen/hairyscary_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/hairyscary_output.txt b/tests/codegen/hairyscary_output.txt deleted file mode 100644 index 8985c22f2..000000000 --- a/tests/codegen/hairyscary_output.txt +++ /dev/null @@ -1 +0,0 @@ -17141611714163171416511714161171416317141653117141611714163171416511714161171416317141653171416117141631714165171416 \ No newline at end of file diff --git a/tests/codegen/hello_world.cl b/tests/codegen/hello_world.cl deleted file mode 100755 index 0c818f908..000000000 --- a/tests/codegen/hello_world.cl +++ /dev/null @@ -1,5 +0,0 @@ -class Main inherits IO { - main(): IO { - out_string("Hello, World.\n") - }; -}; diff --git a/tests/codegen/hello_world_input.txt b/tests/codegen/hello_world_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/hello_world_output.txt b/tests/codegen/hello_world_output.txt deleted file mode 100644 index 349db2bfe..000000000 --- a/tests/codegen/hello_world_output.txt +++ /dev/null @@ -1 +0,0 @@ -Hello, World. diff --git a/tests/codegen/io.cl b/tests/codegen/io.cl deleted file mode 100755 index 7f0de869e..000000000 --- a/tests/codegen/io.cl +++ /dev/null @@ -1,103 +0,0 @@ -(* - * The IO class is predefined and has 4 methods: - * - * out_string(s : String) : SELF_TYPE - * out_int(i : Int) : SELF_TYPE - * in_string() : String - * in_int() : Int - * - * The out operations print their argument to the terminal. The - * in_string method reads an entire line from the terminal and returns a - * string not containing the new line. The in_int method also reads - * an entire line from the terminal and returns the integer - * corresponding to the first non blank word on the line. If that - * word is not an integer, it returns 0. - * - * - * Because our language is object oriented, we need an object of type - * IO in order to call any of these methods. - * - * There are basically two ways of getting access to IO in a class C. - * - * 1) Define C to Inherit from IO. This way the IO methods become - * methods of C, and they can be called using the abbreviated - * dispatch, i.e. - * - * class C inherits IO is - * ... - * out_string("Hello world\n") - * ... - * end; - * - * 2) If your class C does not directly or indirectly inherit from - * IO, the best way to access IO is through an initialized - * attribute of type IO. - * - * class C inherits Foo is - * io : IO <- new IO; - * ... - * io.out_string("Hello world\n"); - * ... - * end; - * - * Approach 1) is most often used, in particular when you need IO - * functions in the Main class. - * - *) - - -class A { - - -- Let's assume that we don't want A to not inherit from IO. - - io : IO <- new IO; - - out_a() : Object { io.out_string("A: Hello world\n") }; - -}; - - -class B inherits A { - - -- B does not have to an extra attribute, since it inherits io from A. - - out_b() : Object { io.out_string("B: Hello world\n") }; - -}; - - -class C inherits IO { - - -- Now the IO methods are part of C. - - out_c() : Object { out_string("C: Hello world\n") }; - - -- Note that out_string(...) is just a shorthand for self.out_string(...) - -}; - - -class D inherits C { - - -- Inherits IO methods from C. - - out_d() : Object { out_string("D: Hello world\n") }; - -}; - - -class Main inherits IO { - - -- Same case as class C. - - main() : Object { - { - (new A).out_a(); - (new B).out_b(); - (new C).out_c(); - (new D).out_d(); - out_string("Done.\n"); - } - }; - -}; diff --git a/tests/codegen/io_input.txt b/tests/codegen/io_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/io_output.txt b/tests/codegen/io_output.txt deleted file mode 100644 index f846f596d..000000000 --- a/tests/codegen/io_output.txt +++ /dev/null @@ -1,5 +0,0 @@ -A: Hello world -B: Hello world -C: Hello world -D: Hello world -Done. diff --git a/tests/codegen/life.cl b/tests/codegen/life.cl deleted file mode 100755 index b83d97957..000000000 --- a/tests/codegen/life.cl +++ /dev/null @@ -1,436 +0,0 @@ -(* The Game of Life - Tendo Kayiira, Summer '95 - With code taken from /private/cool/class/examples/cells.cl - - This introduction was taken off the internet. It gives a brief - description of the Game Of Life. It also gives the rules by which - this particular game follows. - - Introduction - - John Conway's Game of Life is a mathematical amusement, but it - is also much more: an insight into how a system of simple - cellualar automata can create complex, odd, and often aesthetically - pleasing patterns. It is played on a cartesian grid of cells - which are either 'on' or 'off' The game gets it's name from the - similarity between the behaviour of these cells and the behaviour - of living organisms. - - The Rules - - The playfield is a cartesian grid of arbitrary size. Each cell in - this grid can be in an 'on' state or an 'off' state. On each 'turn' - (called a generation,) the state of each cell changes simultaneously - depending on it's state and the state of all cells adjacent to it. - - For 'on' cells, - If the cell has 0 or 1 neighbours which are 'on', the cell turns - 'off'. ('dies of loneliness') - If the cell has 2 or 3 neighbours which are 'on', the cell stays - 'on'. (nothing happens to that cell) - If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', - the cell turns 'off'. ('dies of overcrowding') - - For 'off' cells, - If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which - are 'on', the cell stays 'off'. (nothing happens to that cell) - If the cell has 3 neighbours which are 'on', the cell turns - 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) - - Repeat for as many generations as desired. - - *) - - -class Board inherits IO { - - rows : Int; - columns : Int; - board_size : Int; - - size_of_board(initial : String) : Int { - initial.length() - }; - - board_init(start : String) : Board { - (let size :Int <- size_of_board(start) in - { - if size = 15 then - { - rows <- 3; - columns <- 5; - board_size <- size; - } - else if size = 16 then - { - rows <- 4; - columns <- 4; - board_size <- size; - } - else if size = 20 then - { - rows <- 4; - columns <- 5; - board_size <- size; - } - else if size = 21 then - { - rows <- 3; - columns <- 7; - board_size <- size; - } - else if size = 25 then - { - rows <- 5; - columns <- 5; - board_size <- size; - } - else if size = 28 then - { - rows <- 7; - columns <- 4; - board_size <- size; - } - else -- If none of the above fit, then just give - { -- the configuration of the most common board - rows <- 5; - columns <- 5; - board_size <- size; - } - fi fi fi fi fi fi; - self; - } - ) - }; - -}; - - - -class CellularAutomaton inherits Board { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - board_init(map); - self; - } - }; - - - - - print() : CellularAutomaton { - - (let i : Int <- 0 in - (let num : Int <- board_size in - { - out_string("\n"); - while i < num loop - { - out_string(population_map.substr(i,columns)); - out_string("\n"); - i <- i + columns; - } - pool; - out_string("\n"); - self; - } - ) ) - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - if board_size - 1 < position then - " " - else - population_map.substr(position, 1) - fi - }; - - north(position : Int): String { - if (position - columns) < 0 then - " " - else - cell(position - columns) - fi - }; - - south(position : Int): String { - if board_size < (position + columns) then - " " - else - cell(position + columns) - fi - }; - - east(position : Int): String { - if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - cell(position + 1) - fi - }; - - west(position : Int): String { - if position = 0 then - " " - else - if ((position / columns) * columns) = position then - " " - else - cell(position - 1) - fi fi - }; - - northwest(position : Int): String { - if (position - columns) < 0 then - " " - else if ((position / columns) * columns) = position then - " " - else - north(position - 1) - fi fi - }; - - northeast(position : Int): String { - if (position - columns) < 0 then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - north(position + 1) - fi fi - }; - - southeast(position : Int): String { - if board_size < (position + columns) then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - south(position + 1) - fi fi - }; - - southwest(position : Int): String { - if board_size < (position + columns) then - " " - else if ((position / columns) * columns) = position then - " " - else - south(position - 1) - fi fi - }; - - neighbors(position: Int): Int { - { - if north(position) = "X" then 1 else 0 fi - + if south(position) = "X" then 1 else 0 fi - + if east(position) = "X" then 1 else 0 fi - + if west(position) = "X" then 1 else 0 fi - + if northeast(position) = "X" then 1 else 0 fi - + if northwest(position) = "X" then 1 else 0 fi - + if southeast(position) = "X" then 1 else 0 fi - + if southwest(position) = "X" then 1 else 0 fi; - } - }; - - -(* A cell will live if 2 or 3 of it's neighbors are alive. It dies - otherwise. A cell is born if only 3 of it's neighbors are alive. *) - - cell_at_next_evolution(position : Int) : String { - - if neighbors(position) = 3 then - "X" - else - if neighbors(position) = 2 then - if cell(position) = "X" then - "X" - else - "-" - fi - else - "-" - fi fi - }; - - - evolve() : CellularAutomaton { - (let position : Int <- 0 in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; - -(* This is where the background pattern is detremined by the user. More - patterns can be added as long as whoever adds keeps the board either - 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) - option(): String { - { - (let num : Int in - { - out_string("\nPlease chose a number:\n"); - out_string("\t1: A cross\n"); - out_string("\t2: A slash from the upper left to lower right\n"); - out_string("\t3: A slash from the upper right to lower left\n"); - out_string("\t4: An X\n"); - out_string("\t5: A greater than sign \n"); - out_string("\t6: A less than sign\n"); - out_string("\t7: Two greater than signs\n"); - out_string("\t8: Two less than signs\n"); - out_string("\t9: A 'V'\n"); - out_string("\t10: An inverse 'V'\n"); - out_string("\t11: Numbers 9 and 10 combined\n"); - out_string("\t12: A full grid\n"); - out_string("\t13: A 'T'\n"); - out_string("\t14: A plus '+'\n"); - out_string("\t15: A 'W'\n"); - out_string("\t16: An 'M'\n"); - out_string("\t17: An 'E'\n"); - out_string("\t18: A '3'\n"); - out_string("\t19: An 'O'\n"); - out_string("\t20: An '8'\n"); - out_string("\t21: An 'S'\n"); - out_string("Your choice => "); - num <- in_int(); - out_string("\n"); - if num = 1 then - " XX XXXX XXXX XX " - else if num = 2 then - " X X X X X " - else if num = 3 then - "X X X X X" - else if num = 4 then - "X X X X X X X X X" - else if num = 5 then - "X X X X X " - else if num = 6 then - " X X X X X" - else if num = 7 then - "X X X XX X " - else if num = 8 then - " X XX X X X " - else if num = 9 then - "X X X X X " - else if num = 10 then - " X X X X X" - else if num = 11 then - "X X X X X X X X" - else if num = 12 then - "XXXXXXXXXXXXXXXXXXXXXXXXX" - else if num = 13 then - "XXXXX X X X X " - else if num = 14 then - " X X XXXXX X X " - else if num = 15 then - "X X X X X X X " - else if num = 16 then - " X X X X X X X" - else if num = 17 then - "XXXXX X XXXXX X XXXX" - else if num = 18 then - "XXX X X X X XXXX " - else if num = 19 then - " XX X XX X XX " - else if num = 20 then - " XX X XX X XX X XX X XX " - else if num = 21 then - " XXXX X XX X XXXX " - else - " " - fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; - } - ); - } - }; - - - - - prompt() : Bool { - { - (let ans : String in - { - out_string("Would you like to continue with the next generation? \n"); - out_string("Please use lowercase y or n for your answer [y]: "); - ans <- in_string(); - out_string("\n"); - if ans = "n" then - false - else - true - fi; - } - ); - } - }; - - - prompt2() : Bool { - (let ans : String in - { - out_string("\n\n"); - out_string("Would you like to choose a background pattern? \n"); - out_string("Please use lowercase y or n for your answer [n]: "); - ans <- in_string(); - if ans = "y" then - true - else - false - fi; - } - ) - }; - - -}; - -class Main inherits CellularAutomaton { - cells : CellularAutomaton; - - main() : Main { - { - (let continue : Bool in - (let choice : String in - { - out_string("Welcome to the Game of Life.\n"); - out_string("There are many initial states to choose from. \n"); - while prompt2() loop - { - continue <- true; - choice <- option(); - cells <- (new CellularAutomaton).init(choice); - cells.print(); - while continue loop - if prompt() then - { - cells.evolve(); - cells.print(); - } - else - continue <- false - fi - pool; - } - pool; - self; - } ) ); } - }; -}; - diff --git a/tests/codegen/life_input.txt b/tests/codegen/life_input.txt deleted file mode 100644 index 07e016726..000000000 --- a/tests/codegen/life_input.txt +++ /dev/null @@ -1,66 +0,0 @@ -y -1 -n -y -2 -n -y -3 -n -y -4 -n -y -5 -n -y -6 -n -y -7 -n -y -8 -n -y -9 -n -y -10 -n -y -11 -n -y -12 -n -y -13 -n -y -14 -n -y -15 -n -y -16 -n -y -17 -n -y -18 -n -y -19 -n -y -20 -n -y -21 -y -y -n -n \ No newline at end of file diff --git a/tests/codegen/life_output.txt b/tests/codegen/life_output.txt deleted file mode 100644 index 5a9b9f73d..000000000 --- a/tests/codegen/life_output.txt +++ /dev/null @@ -1,778 +0,0 @@ -Welcome to the Game of Life. -There are many initial states to choose from. - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -XXXX -XXXX - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X -X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X -X X - X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X X - X X -X X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX -XXXXX -XXXXX -XXXXX -XXXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X -XXXXX - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X X - X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X - X X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXX -X -X -XXXX -X -X -XXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXX - X - X - X - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XXX -X -X - XX - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X--- --XX- ----X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X-X- --XX- --X-X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: \ No newline at end of file diff --git a/tests/codegen/list.cl b/tests/codegen/list.cl deleted file mode 100644 index b384dac62..000000000 --- a/tests/codegen/list.cl +++ /dev/null @@ -1,141 +0,0 @@ -(* - * This file shows how to implement a list data type for lists of integers. - * It makes use of INHERITANCE and DYNAMIC DISPATCH. - * - * The List class has 4 operations defined on List objects. If 'l' is - * a list, then the methods dispatched on 'l' have the following effects: - * - * isNil() : Bool Returns true if 'l' is empty, false otherwise. - * head() : Int Returns the integer at the head of 'l'. - * If 'l' is empty, execution aborts. - * tail() : List Returns the remainder of the 'l', - * i.e. without the first element. - * cons(i : Int) : List Return a new list containing i as the - * first element, followed by the - * elements in 'l'. - * - * There are 2 kinds of lists, the empty list and a non-empty - * list. We can think of the non-empty list as a specialization of - * the empty list. - * The class List defines the operations on empty list. The class - * Cons inherits from List and redefines things to handle non-empty - * lists. - *) - - -class List { - -- Define operations on empty lists. - - isNil() : Bool { true }; - - -- Since abort() has return type Object and head() has return type - -- Int, we need to have an Int as the result of the method body, - -- even though abort() never returns. - - head() : Int { { abort(); 0; } }; - - -- As for head(), the self is just to make sure the return type of - -- tail() is correct. - - tail() : List { { abort(); self; } }; - - -- When we cons and element onto the empty list we get a non-empty - -- list. The (new Cons) expression creates a new list cell of class - -- Cons, which is initialized by a dispatch to init(). - -- The result of init() is an element of class Cons, but it - -- conforms to the return type List, because Cons is a subclass of - -- List. - - cons(i : Int) : List { - (new Cons).init(i, self) - }; - -}; - - -(* - * Cons inherits all operations from List. We can reuse only the cons - * method though, because adding an element to the front of an emtpy - * list is the same as adding it to the front of a non empty - * list. All other methods have to be redefined, since the behaviour - * for them is different from the empty list. - * - * Cons needs two attributes to hold the integer of this list - * cell and to hold the rest of the list. - * - * The init() method is used by the cons() method to initialize the - * cell. - *) - -class Cons inherits List { - - car : Int; -- The element in this list cell - - cdr : List; -- The rest of the list - - isNil() : Bool { false }; - - head() : Int { car }; - - tail() : List { cdr }; - - init(i : Int, rest : List) : List { - { - car <- i; - cdr <- rest; - self; - } - }; - -}; - - - -(* - * The Main class shows how to use the List class. It creates a small - * list and then repeatedly prints out its elements and takes off the - * first element of the list. - *) - -class Main inherits IO { - - mylist : List; - - -- Print all elements of the list. Calls itself recursively with - -- the tail of the list, until the end of the list is reached. - - print_list(l : List) : Object { - if l.isNil() then out_string("\n") - else { - out_int(l.head()); - out_string(" "); - print_list(l.tail()); - } - fi - }; - - -- Note how the dynamic dispatch mechanism is responsible to end - -- the while loop. As long as mylist is bound to an object of - -- dynamic type Cons, the dispatch to isNil calls the isNil method of - -- the Cons class, which returns false. However when we reach the - -- end of the list, mylist gets bound to the object that was - -- created by the (new List) expression. This object is of dynamic type - -- List, and thus the method isNil in the List class is called and - -- returns true. - - main() : Object { - { - mylist <- new List.cons(1).cons(2).cons(3).cons(4).cons(5); - while (not mylist.isNil()) loop - { - print_list(mylist); - mylist <- mylist.tail(); - } - pool; - } - }; - -}; - - - diff --git a/tests/codegen/list_input.txt b/tests/codegen/list_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/list_output.txt b/tests/codegen/list_output.txt deleted file mode 100644 index fca724903..000000000 --- a/tests/codegen/list_output.txt +++ /dev/null @@ -1,5 +0,0 @@ -5 4 3 2 1 -4 3 2 1 -3 2 1 -2 1 -1 diff --git a/tests/codegen/new_complex.cl b/tests/codegen/new_complex.cl deleted file mode 100755 index a4fe714ce..000000000 --- a/tests/codegen/new_complex.cl +++ /dev/null @@ -1,79 +0,0 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - { - -- trivially equal (see CoolAid) - if c.reflect_X() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi; - -- equal - if c.reflect_X().reflect_Y().equal(c.reflect_0()) - then out_string("=)\n") - else out_string("=(\n") - fi; - } - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; - - equal(d : Complex) : Bool { - if x = d.x_value() - then - if y = d.y_value() - then true - else false - fi - else false - fi - }; - - x_value() : Int { - x - }; - - y_value() : Int { - y - }; -}; diff --git a/tests/codegen/new_complex_input.txt b/tests/codegen/new_complex_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/new_complex_output.txt b/tests/codegen/new_complex_output.txt deleted file mode 100644 index 0e8da112c..000000000 --- a/tests/codegen/new_complex_output.txt +++ /dev/null @@ -1,2 +0,0 @@ -=) -=) diff --git a/tests/codegen/palindrome.cl b/tests/codegen/palindrome.cl deleted file mode 100755 index 7f24789f9..000000000 --- a/tests/codegen/palindrome.cl +++ /dev/null @@ -1,25 +0,0 @@ -class Main inherits IO { - pal(s : String) : Bool { - if s.length() = 0 - then true - else if s.length() = 1 - then true - else if s.substr(0, 1) = s.substr(s.length() - 1, 1) - then pal(s.substr(1, s.length() -2)) - else false - fi fi fi - }; - - i : Int; - - main() : IO { - { - i <- ~1; - out_string("enter a string\n"); - if pal(in_string()) - then out_string("that was a palindrome\n") - else out_string("that was not a palindrome\n") - fi; - } - }; -}; diff --git a/tests/codegen/palindrome_input.txt b/tests/codegen/palindrome_input.txt deleted file mode 100644 index 8e1b64142..000000000 --- a/tests/codegen/palindrome_input.txt +++ /dev/null @@ -1 +0,0 @@ -anitalabalatina diff --git a/tests/codegen/palindrome_output.txt b/tests/codegen/palindrome_output.txt deleted file mode 100644 index 7a0095959..000000000 --- a/tests/codegen/palindrome_output.txt +++ /dev/null @@ -1,2 +0,0 @@ -enter a string -that was a palindrome diff --git a/tests/codegen/primes.cl b/tests/codegen/primes.cl deleted file mode 100644 index 8b9254d58..000000000 --- a/tests/codegen/primes.cl +++ /dev/null @@ -1,84 +0,0 @@ - -(* - * methodless-primes.cl - * - * Designed by Jesse H. Willett, jhw@cory, 11103234, with - * Istvan Siposs, isiposs@cory, 12342921. - * - * This program generates primes in order without using any methods. - * Actually, it does use three methods: those of IO to print out each - * prime, and abort() to halt the program. These methods are incidental, - * however, to the information-processing functionality of the program. We - * could regard the attribute 'out's sequential values as our output, and - * the string "halt" as our terminate signal. - * - * Naturally, using Cool this way is a real waste, basically reducing it - * to assembly without the benefit of compilation. - * - * There could even be a subroutine-like construction, in that different - * code could be in the assign fields of attributes of other classes, - * and it could be executed by calling 'new Sub', but no parameters - * could be passed to the subroutine, and it could only return itself. - * but returning itself would be useless since we couldn't call methods - * and the only operators we have are for Int and Bool, which do nothing - * interesting when we initialize them! - *) - -class Main inherits IO { - - main() : Int { -- main() is an atrophied method so we can parse. - 0 - }; - - out : Int <- -- out is our 'output'. Its values are the primes. - { - out_string("2 is trivially prime.\n"); - 2; - }; - - testee : Int <- out; -- testee is a number to be tested for primeness. - - divisor : Int; -- divisor is a number which may factor testee. - - stop : Int <- 500; -- stop is an arbitrary value limiting testee. - - m : Object <- -- m supplants the main method. - while true loop - { - - testee <- testee + 1; - divisor <- 2; - - while - if testee < divisor * divisor - then false -- can stop if divisor > sqrt(testee). - else if testee - divisor*(testee/divisor) = 0 - then false -- can stop if divisor divides testee. - else true - fi fi - loop - divisor <- divisor + 1 - pool; - - if testee < divisor * divisor -- which reason did we stop for? - then -- testee has no factors less than sqrt(testee). - { - out <- testee; -- we could think of out itself as the output. - out_int(out); - out_string(" is prime.\n"); - } - else -- the loop halted on testee/divisor = 0, testee isn't prime. - 0 -- testee isn't prime, do nothing. - fi; - - if stop <= testee then - "halt".abort() -- we could think of "halt" as SIGTERM. - else - "continue" - fi; - - } - pool; - -}; (* end of Main *) - diff --git a/tests/codegen/primes_input.txt b/tests/codegen/primes_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/primes_output.txt b/tests/codegen/primes_output.txt deleted file mode 100644 index a4d0fcb3f..000000000 --- a/tests/codegen/primes_output.txt +++ /dev/null @@ -1,96 +0,0 @@ -2 is trivially prime. -3 is prime. -5 is prime. -7 is prime. -11 is prime. -13 is prime. -17 is prime. -19 is prime. -23 is prime. -29 is prime. -31 is prime. -37 is prime. -41 is prime. -43 is prime. -47 is prime. -53 is prime. -59 is prime. -61 is prime. -67 is prime. -71 is prime. -73 is prime. -79 is prime. -83 is prime. -89 is prime. -97 is prime. -101 is prime. -103 is prime. -107 is prime. -109 is prime. -113 is prime. -127 is prime. -131 is prime. -137 is prime. -139 is prime. -149 is prime. -151 is prime. -157 is prime. -163 is prime. -167 is prime. -173 is prime. -179 is prime. -181 is prime. -191 is prime. -193 is prime. -197 is prime. -199 is prime. -211 is prime. -223 is prime. -227 is prime. -229 is prime. -233 is prime. -239 is prime. -241 is prime. -251 is prime. -257 is prime. -263 is prime. -269 is prime. -271 is prime. -277 is prime. -281 is prime. -283 is prime. -293 is prime. -307 is prime. -311 is prime. -313 is prime. -317 is prime. -331 is prime. -337 is prime. -347 is prime. -349 is prime. -353 is prime. -359 is prime. -367 is prime. -373 is prime. -379 is prime. -383 is prime. -389 is prime. -397 is prime. -401 is prime. -409 is prime. -419 is prime. -421 is prime. -431 is prime. -433 is prime. -439 is prime. -443 is prime. -449 is prime. -457 is prime. -461 is prime. -463 is prime. -467 is prime. -479 is prime. -487 is prime. -491 is prime. -499 is prime. -Abort called from class String diff --git a/tests/codegen/print-cool.cl b/tests/codegen/print-cool.cl deleted file mode 100644 index 76194e966..000000000 --- a/tests/codegen/print-cool.cl +++ /dev/null @@ -1,9 +0,0 @@ -class Main inherits IO { - main() : IO { - { - out_string((new Object).type_name().substr(4,1)). - out_string((isvoid self).type_name().substr(1,3)); -- demonstrates the dispatch rules. - out_string("\n"); - } - }; -}; diff --git a/tests/codegen/print-cool_input.txt b/tests/codegen/print-cool_input.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/codegen/print-cool_output.txt b/tests/codegen/print-cool_output.txt deleted file mode 100644 index 2b58f8985..000000000 --- a/tests/codegen/print-cool_output.txt +++ /dev/null @@ -1 +0,0 @@ -cool diff --git a/tests/codegen/sort-list.cl b/tests/codegen/sort-list.cl deleted file mode 100644 index 7cf7b20a3..000000000 --- a/tests/codegen/sort-list.cl +++ /dev/null @@ -1,146 +0,0 @@ -(* - This file presents a fairly large example of Cool programming. The -class List defines the names of standard list operations ala Scheme: -car, cdr, cons, isNil, rev, sort, rcons (add an element to the end of -the list), and print_list. In the List class most of these functions -are just stubs that abort if ever called. The classes Nil and Cons -inherit from List and define the same operations, but now as -appropriate to the empty list (for the Nil class) and for cons cells (for -the Cons class). - -The Main class puts all of this code through the following silly -test exercise: - - 1. prompt for a number N - 2. generate a list of numbers 0..N-1 - 3. reverse the list - 4. sort the list - 5. print the sorted list - -Because the sort used is a quadratic space insertion sort, sorting -moderately large lists can be quite slow. -*) - -Class List inherits IO { - (* Since abort() returns Object, we need something of - type Bool at the end of the block to satisfy the typechecker. - This code is unreachable, since abort() halts the program. *) - isNil() : Bool { { abort(); true; } }; - - cons(hd : Int) : Cons { - (let new_cell : Cons <- new Cons in - new_cell.init(hd,self) - ) - }; - - (* - Since abort "returns" type Object, we have to add - an expression of type Int here to satisfy the typechecker. - This code is, of course, unreachable. - *) - car() : Int { { abort(); new Int; } }; - - cdr() : List { { abort(); new List; } }; - - rev() : List { cdr() }; - - sort() : List { cdr() }; - - insert(i : Int) : List { cdr() }; - - rcons(i : Int) : List { cdr() }; - - print_list() : Object { abort() }; -}; - -Class Cons inherits List { - xcar : Int; -- We keep the car in cdr in attributes. - xcdr : List; - - isNil() : Bool { false }; - - init(hd : Int, tl : List) : Cons { - { - xcar <- hd; - xcdr <- tl; - self; - } - }; - - car() : Int { xcar }; - - cdr() : List { xcdr }; - - rev() : List { (xcdr.rev()).rcons(xcar) }; - - sort() : List { (xcdr.sort()).insert(xcar) }; - - insert(i : Int) : List { - if i < xcar then - (new Cons).init(i,self) - else - (new Cons).init(xcar,xcdr.insert(i)) - fi - }; - - - rcons(i : Int) : List { (new Cons).init(xcar, xcdr.rcons(i)) }; - - print_list() : Object { - { - out_int(xcar); - out_string("\n"); - xcdr.print_list(); - } - }; -}; - -Class Nil inherits List { - isNil() : Bool { true }; - - rev() : List { self }; - - sort() : List { self }; - - insert(i : Int) : List { rcons(i) }; - - rcons(i : Int) : List { (new Cons).init(i,self) }; - - print_list() : Object { true }; - -}; - - -Class Main inherits IO { - - l : List; - - (* iota maps its integer argument n into the list 0..n-1 *) - iota(i : Int) : List { - { - l <- new Nil; - (let j : Int <- 0 in - while j < i - loop - { - l <- (new Cons).init(j,l); - j <- j + 1; - } - pool - ); - l; - } - }; - - main() : Object { - { - out_string("How many numbers to sort? "); - iota(in_int()).rev().sort().print_list(); - } - }; -}; - - - - - diff --git a/tests/codegen/sort-list_input.txt b/tests/codegen/sort-list_input.txt deleted file mode 100644 index f599e28b8..000000000 --- a/tests/codegen/sort-list_input.txt +++ /dev/null @@ -1 +0,0 @@ -10 diff --git a/tests/codegen/sort-list_output.txt b/tests/codegen/sort-list_output.txt deleted file mode 100644 index 9878d57ea..000000000 --- a/tests/codegen/sort-list_output.txt +++ /dev/null @@ -1,10 +0,0 @@ -How many numbers to sort? 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 From 80ac6b7201ef60a82ca635674841d9023618a110 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 25 Feb 2022 21:24:43 -0300 Subject: [PATCH 54/60] reverse --- tests/codegen/arith.cl | 430 +++++++++++++++ tests/codegen/arith_input.txt | 13 + tests/codegen/arith_output.txt | 158 ++++++ tests/codegen/atoi.cl | 121 +++++ tests/codegen/atoi_input.txt | 0 tests/codegen/atoi_output.txt | 1 + tests/codegen/book_list.cl | 132 +++++ tests/codegen/book_list_input.txt | 0 tests/codegen/book_list_output.txt | 7 + tests/codegen/cells.cl | 97 ++++ tests/codegen/cells_input.txt | 0 tests/codegen/cells_output.txt | 21 + tests/codegen/complex.cl | 52 ++ tests/codegen/complex_input.txt | 0 tests/codegen/complex_output.txt | 1 + tests/codegen/fib.cl | 29 + tests/codegen/fib_input.txt | 1 + tests/codegen/fib_output.txt | 2 + tests/codegen/graph.cl | 381 +++++++++++++ tests/codegen/graph_input.txt | 5 + tests/codegen/graph_output.txt | 7 + tests/codegen/hairyscary.cl | 67 +++ tests/codegen/hairyscary_input.txt | 0 tests/codegen/hairyscary_output.txt | 1 + tests/codegen/hello_world.cl | 5 + tests/codegen/hello_world_input.txt | 0 tests/codegen/hello_world_output.txt | 1 + tests/codegen/io.cl | 103 ++++ tests/codegen/io_input.txt | 0 tests/codegen/io_output.txt | 5 + tests/codegen/life.cl | 436 +++++++++++++++ tests/codegen/life_input.txt | 66 +++ tests/codegen/life_output.txt | 778 +++++++++++++++++++++++++++ tests/codegen/list.cl | 141 +++++ tests/codegen/list_input.txt | 0 tests/codegen/list_output.txt | 5 + tests/codegen/new_complex.cl | 79 +++ tests/codegen/new_complex_input.txt | 0 tests/codegen/new_complex_output.txt | 2 + tests/codegen/palindrome.cl | 25 + tests/codegen/palindrome_input.txt | 1 + tests/codegen/palindrome_output.txt | 2 + tests/codegen/primes.cl | 84 +++ tests/codegen/primes_input.txt | 0 tests/codegen/primes_output.txt | 96 ++++ tests/codegen/print-cool.cl | 9 + tests/codegen/print-cool_input.txt | 0 tests/codegen/print-cool_output.txt | 1 + tests/codegen/sort-list.cl | 146 +++++ tests/codegen/sort-list_input.txt | 1 + tests/codegen/sort-list_output.txt | 10 + 51 files changed, 3522 insertions(+) create mode 100755 tests/codegen/arith.cl create mode 100644 tests/codegen/arith_input.txt create mode 100644 tests/codegen/arith_output.txt create mode 100644 tests/codegen/atoi.cl create mode 100644 tests/codegen/atoi_input.txt create mode 100644 tests/codegen/atoi_output.txt create mode 100755 tests/codegen/book_list.cl create mode 100644 tests/codegen/book_list_input.txt create mode 100644 tests/codegen/book_list_output.txt create mode 100755 tests/codegen/cells.cl create mode 100644 tests/codegen/cells_input.txt create mode 100644 tests/codegen/cells_output.txt create mode 100755 tests/codegen/complex.cl create mode 100644 tests/codegen/complex_input.txt create mode 100644 tests/codegen/complex_output.txt create mode 100644 tests/codegen/fib.cl create mode 100644 tests/codegen/fib_input.txt create mode 100644 tests/codegen/fib_output.txt create mode 100755 tests/codegen/graph.cl create mode 100644 tests/codegen/graph_input.txt create mode 100644 tests/codegen/graph_output.txt create mode 100755 tests/codegen/hairyscary.cl create mode 100644 tests/codegen/hairyscary_input.txt create mode 100644 tests/codegen/hairyscary_output.txt create mode 100755 tests/codegen/hello_world.cl create mode 100644 tests/codegen/hello_world_input.txt create mode 100644 tests/codegen/hello_world_output.txt create mode 100755 tests/codegen/io.cl create mode 100644 tests/codegen/io_input.txt create mode 100644 tests/codegen/io_output.txt create mode 100755 tests/codegen/life.cl create mode 100644 tests/codegen/life_input.txt create mode 100644 tests/codegen/life_output.txt create mode 100644 tests/codegen/list.cl create mode 100644 tests/codegen/list_input.txt create mode 100644 tests/codegen/list_output.txt create mode 100755 tests/codegen/new_complex.cl create mode 100644 tests/codegen/new_complex_input.txt create mode 100644 tests/codegen/new_complex_output.txt create mode 100755 tests/codegen/palindrome.cl create mode 100644 tests/codegen/palindrome_input.txt create mode 100644 tests/codegen/palindrome_output.txt create mode 100644 tests/codegen/primes.cl create mode 100644 tests/codegen/primes_input.txt create mode 100644 tests/codegen/primes_output.txt create mode 100644 tests/codegen/print-cool.cl create mode 100644 tests/codegen/print-cool_input.txt create mode 100644 tests/codegen/print-cool_output.txt create mode 100644 tests/codegen/sort-list.cl create mode 100644 tests/codegen/sort-list_input.txt create mode 100644 tests/codegen/sort-list_output.txt diff --git a/tests/codegen/arith.cl b/tests/codegen/arith.cl new file mode 100755 index 000000000..af5951cf7 --- /dev/null +++ b/tests/codegen/arith.cl @@ -0,0 +1,430 @@ +(* + * A contribution from Anne Sheets (sheets@cory) + * + * Tests the arithmetic operations and various other things + *) + +class A { + + var : Int <- 0; + + value() : Int { var }; + + set_var(num : Int) : A{ + { + var <- num; + self; + } + }; + + method1(num : Int) : A { -- same + self + }; + + method2(num1 : Int, num2 : Int) : A { -- plus + (let x : Int in + { + x <- num1 + num2; + (new B).set_var(x); + } + ) + }; + + method3(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new C).set_var(x); + } + ) + }; + + method4(num1 : Int, num2 : Int) : A { -- diff + if num2 < num1 then + (let x : Int in + { + x <- num1 - num2; + (new D).set_var(x); + } + ) + else + (let x : Int in + { + x <- num2 - num1; + (new D).set_var(x); + } + ) + fi + }; + + method5(num : Int) : A { -- factorial + (let x : Int <- 1 in + { + (let y : Int <- 1 in + while y <= num loop + { + x <- x * y; + y <- y + 1; + } + pool + ); + (new E).set_var(x); + } + ) + }; + +}; + +class B inherits A { -- B is a number squared + + method5(num : Int) : A { -- square + (let x : Int in + { + x <- num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class C inherits B { + + method6(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new A).set_var(x); + } + ) + }; + + method5(num : Int) : A { -- cube + (let x : Int in + { + x <- num * num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class D inherits B { + + method7(num : Int) : Bool { -- divisible by 3 + (let x : Int <- num in + if x < 0 then method7(~x) else + if 0 = x then true else + if 1 = x then false else + if 2 = x then false else + method7(x - 3) + fi fi fi fi + ) + }; + +}; + +class E inherits D { + + method6(num : Int) : A { -- division + (let x : Int in + { + x <- num / 8; + (new A).set_var(x); + } + ) + }; + +}; + +(* The following code is from atoi.cl in ~cs164/examples *) + +(* + The class A2I provides integer-to-string and string-to-integer +conversion routines. To use these routines, either inherit them +in the class where needed, have a dummy variable bound to +something of type A2I, or simpl write (new A2I).method(argument). +*) + + +(* + c2i Converts a 1-character string to an integer. Aborts + if the string is not "0" through "9" +*) +class A2I { + + c2i(char : String) : Int { + if char = "0" then 0 else + if char = "1" then 1 else + if char = "2" then 2 else + if char = "3" then 3 else + if char = "4" then 4 else + if char = "5" then 5 else + if char = "6" then 6 else + if char = "7" then 7 else + if char = "8" then 8 else + if char = "9" then 9 else + { abort(); 0; } (* the 0 is needed to satisfy the + typchecker *) + fi fi fi fi fi fi fi fi fi fi + }; + +(* + i2c is the inverse of c2i. +*) + i2c(i : Int) : String { + if i = 0 then "0" else + if i = 1 then "1" else + if i = 2 then "2" else + if i = 3 then "3" else + if i = 4 then "4" else + if i = 5 then "5" else + if i = 6 then "6" else + if i = 7 then "7" else + if i = 8 then "8" else + if i = 9 then "9" else + { abort(); ""; } -- the "" is needed to satisfy the typchecker + fi fi fi fi fi fi fi fi fi fi + }; + +(* + a2i converts an ASCII string into an integer. The empty string +is converted to 0. Signed and unsigned strings are handled. The +method aborts if the string does not represent an integer. Very +long strings of digits produce strange answers because of arithmetic +overflow. + +*) + a2i(s : String) : Int { + if s.length() = 0 then 0 else + if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else + if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else + a2i_aux(s) + fi fi fi + }; + +(* a2i_aux converts the usigned portion of the string. As a + programming example, this method is written iteratively. *) + + + a2i_aux(s : String) : Int { + (let int : Int <- 0 in + { + (let j : Int <- s.length() in + (let i : Int <- 0 in + while i < j loop + { + int <- int * 10 + c2i(s.substr(i,1)); + i <- i + 1; + } + pool + ) + ); + int; + } + ) + }; + +(* i2a converts an integer to a string. Positive and negative + numbers are handled correctly. *) + + i2a(i : Int) : String { + if i = 0 then "0" else + if 0 < i then i2a_aux(i) else + "-".concat(i2a_aux(i * ~1)) + fi fi + }; + +(* i2a_aux is an example using recursion. *) + + i2a_aux(i : Int) : String { + if i = 0 then "" else + (let next : Int <- i / 10 in + i2a_aux(next).concat(i2c(i - next * 10)) + ) + fi + }; + +}; + +class Main inherits IO { + + char : String; + avar : A; + a_var : A; + flag : Bool <- true; + + + menu() : String { + { + out_string("\n\tTo add a number to "); + print(avar); + out_string("...enter a:\n"); + out_string("\tTo negate "); + print(avar); + out_string("...enter b:\n"); + out_string("\tTo find the difference between "); + print(avar); + out_string("and another number...enter c:\n"); + out_string("\tTo find the factorial of "); + print(avar); + out_string("...enter d:\n"); + out_string("\tTo square "); + print(avar); + out_string("...enter e:\n"); + out_string("\tTo cube "); + print(avar); + out_string("...enter f:\n"); + out_string("\tTo find out if "); + print(avar); + out_string("is a multiple of 3...enter g:\n"); + out_string("\tTo divide "); + print(avar); + out_string("by 8...enter h:\n"); + out_string("\tTo get a new number...enter j:\n"); + out_string("\tTo quit...enter q:\n\n"); + in_string(); + } + }; + + prompt() : String { + { + out_string("\n"); + out_string("Please enter a number... "); + in_string(); + } + }; + + get_int() : Int { + { + (let z : A2I <- new A2I in + (let s : String <- prompt() in + z.a2i(s) + ) + ); + } + }; + + is_even(num : Int) : Bool { + (let x : Int <- num in + if x < 0 then is_even(~x) else + if 0 = x then true else + if 1 = x then false else + is_even(x - 2) + fi fi fi + ) + }; + + class_type(var : A) : IO { + case var of + a : A => out_string("Class type is now A\n"); + b : B => out_string("Class type is now B\n"); + c : C => out_string("Class type is now C\n"); + d : D => out_string("Class type is now D\n"); + e : E => out_string("Class type is now E\n"); + o : Object => out_string("Oooops\n"); + esac + }; + + print(var : A) : IO { + (let z : A2I <- new A2I in + { + out_string(z.i2a(var.value())); + out_string(" "); + } + ) + }; + + main() : Object { + { + avar <- (new A); + while flag loop + { + -- avar <- (new A).set_var(get_int()); + out_string("number "); + print(avar); + if is_even(avar.value()) then + out_string("is even!\n") + else + out_string("is odd!\n") + fi; + -- print(avar); -- prints out answer + class_type(avar); + char <- menu(); + if char = "a" then -- add + { + a_var <- (new A).set_var(get_int()); + avar <- (new B).method2(avar.value(), a_var.value()); + } else + if char = "b" then -- negate + case avar of + c : C => avar <- c.method6(c.value()); + a : A => avar <- a.method3(a.value()); + o : Object => { + out_string("Oooops\n"); + abort(); 0; + }; + esac else + if char = "c" then -- diff + { + a_var <- (new A).set_var(get_int()); + avar <- (new D).method4(avar.value(), a_var.value()); + } else + if char = "d" then avar <- (new C)@A.method5(avar.value()) else + -- factorial + if char = "e" then avar <- (new C)@B.method5(avar.value()) else + -- square + if char = "f" then avar <- (new C)@C.method5(avar.value()) else + -- cube + if char = "g" then -- multiple of 3? + if ((new D).method7(avar.value())) + then -- avar <- (new A).method1(avar.value()) + { + out_string("number "); + print(avar); + out_string("is divisible by 3.\n"); + } + else -- avar <- (new A).set_var(0) + { + out_string("number "); + print(avar); + out_string("is not divisible by 3.\n"); + } + fi else + if char = "h" then + (let x : A in + { + x <- (new E).method6(avar.value()); + (let r : Int <- (avar.value() - (x.value() * 8)) in + { + out_string("number "); + print(avar); + out_string("is equal to "); + print(x); + out_string("times 8 with a remainder of "); + (let a : A2I <- new A2I in + { + out_string(a.i2a(r)); + out_string("\n"); + } + ); -- end let a: + } + ); -- end let r: + avar <- x; + } + ) -- end let x: + else + if char = "j" then avar <- (new A) + else + if char = "q" then flag <- false + else + avar <- (new A).method1(avar.value()) -- divide/8 + fi fi fi fi fi fi fi fi fi fi; + } + pool; + } + }; + +}; + diff --git a/tests/codegen/arith_input.txt b/tests/codegen/arith_input.txt new file mode 100644 index 000000000..83e05b1ea --- /dev/null +++ b/tests/codegen/arith_input.txt @@ -0,0 +1,13 @@ +a +1 +b +c +0 +d +e +f +g +h +j +5 +q diff --git a/tests/codegen/arith_output.txt b/tests/codegen/arith_output.txt new file mode 100644 index 000000000..44b4ce73e --- /dev/null +++ b/tests/codegen/arith_output.txt @@ -0,0 +1,158 @@ +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now B + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number -1 is odd! +Class type is now C + + To add a number to -1 ...enter a: + To negate -1 ...enter b: + To find the difference between -1 and another number...enter c: + To find the factorial of -1 ...enter d: + To square -1 ...enter e: + To cube -1 ...enter f: + To find out if -1 is a multiple of 3...enter g: + To divide -1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now D + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is not divisible by 3. +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is equal to 0 times 8 with a remainder of 1 +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + diff --git a/tests/codegen/atoi.cl b/tests/codegen/atoi.cl new file mode 100644 index 000000000..fd8b2ea42 --- /dev/null +++ b/tests/codegen/atoi.cl @@ -0,0 +1,121 @@ +(* + The class A2I provides integer-to-string and string-to-integer +conversion routines. To use these routines, either inherit them +in the class where needed, have a dummy variable bound to +something of type A2I, or simpl write (new A2I).method(argument). +*) + + +(* + c2i Converts a 1-character string to an integer. Aborts + if the string is not "0" through "9" +*) +class A2I { + + c2i(char : String) : Int { + if char = "0" then 0 else + if char = "1" then 1 else + if char = "2" then 2 else + if char = "3" then 3 else + if char = "4" then 4 else + if char = "5" then 5 else + if char = "6" then 6 else + if char = "7" then 7 else + if char = "8" then 8 else + if char = "9" then 9 else + { abort(); 0; } -- the 0 is needed to satisfy the typchecker + fi fi fi fi fi fi fi fi fi fi + }; + +(* + i2c is the inverse of c2i. +*) + i2c(i : Int) : String { + if i = 0 then "0" else + if i = 1 then "1" else + if i = 2 then "2" else + if i = 3 then "3" else + if i = 4 then "4" else + if i = 5 then "5" else + if i = 6 then "6" else + if i = 7 then "7" else + if i = 8 then "8" else + if i = 9 then "9" else + { abort(); ""; } -- the "" is needed to satisfy the typchecker + fi fi fi fi fi fi fi fi fi fi + }; + +(* + a2i converts an ASCII string into an integer. The empty string +is converted to 0. Signed and unsigned strings are handled. The +method aborts if the string does not represent an integer. Very +long strings of digits produce strange answers because of arithmetic +overflow. + +*) + a2i(s : String) : Int { + if s.length() = 0 then 0 else + if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else + if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else + a2i_aux(s) + fi fi fi + }; + +(* + a2i_aux converts the usigned portion of the string. As a programming +example, this method is written iteratively. +*) + a2i_aux(s : String) : Int { + (let int : Int <- 0 in + { + (let j : Int <- s.length() in + (let i : Int <- 0 in + while i < j loop + { + int <- int * 10 + c2i(s.substr(i,1)); + i <- i + 1; + } + pool + ) + ); + int; + } + ) + }; + +(* + i2a converts an integer to a string. Positive and negative +numbers are handled correctly. +*) + i2a(i : Int) : String { + if i = 0 then "0" else + if 0 < i then i2a_aux(i) else + "-".concat(i2a_aux(i * ~1)) + fi fi + }; + +(* + i2a_aux is an example using recursion. +*) + i2a_aux(i : Int) : String { + if i = 0 then "" else + (let next : Int <- i / 10 in + i2a_aux(next).concat(i2c(i - next * 10)) + ) + fi + }; + +}; + +class Main inherits IO { + main () : Object { + let a : Int <- (new A2I).a2i("678987"), + b : String <- (new A2I).i2a(678987) in + { + out_int(a) ; + out_string(" == ") ; + out_string(b) ; + out_string("\n"); + } + } ; +} ; diff --git a/tests/codegen/atoi_input.txt b/tests/codegen/atoi_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/atoi_output.txt b/tests/codegen/atoi_output.txt new file mode 100644 index 000000000..51b815a48 --- /dev/null +++ b/tests/codegen/atoi_output.txt @@ -0,0 +1 @@ +678987 == 678987 diff --git a/tests/codegen/book_list.cl b/tests/codegen/book_list.cl new file mode 100755 index 000000000..025ea1695 --- /dev/null +++ b/tests/codegen/book_list.cl @@ -0,0 +1,132 @@ +-- example of static and dynamic type differing for a dispatch + +Class Book inherits IO { + title : String; + author : String; + + initBook(title_p : String, author_p : String) : Book { + { + title <- title_p; + author <- author_p; + self; + } + }; + + print() : Book { + { + out_string("title: ").out_string(title).out_string("\n"); + out_string("author: ").out_string(author).out_string("\n"); + self; + } + }; +}; + +Class Article inherits Book { + per_title : String; + + initArticle(title_p : String, author_p : String, + per_title_p : String) : Article { + { + initBook(title_p, author_p); + per_title <- per_title_p; + self; + } + }; + + print() : Book { + { + self@Book.print(); + out_string("periodical: ").out_string(per_title).out_string("\n"); + self; + } + }; +}; + +Class BookList inherits IO { + (* Since abort "returns" type Object, we have to add + an expression of type Bool here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + isNil() : Bool { { abort(); true; } }; + + cons(hd : Book) : Cons { + (let new_cell : Cons <- new Cons in + new_cell.init(hd,self) + ) + }; + + (* Since abort "returns" type Object, we have to add + an expression of type Book here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + car() : Book { { abort(); new Book; } }; + + (* Since abort "returns" type Object, we have to add + an expression of type BookList here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + cdr() : BookList { { abort(); new BookList; } }; + + print_list() : Object { abort() }; +}; + +Class Cons inherits BookList { + xcar : Book; -- We keep the car and cdr in attributes. + xcdr : BookList; -- Because methods and features must have different names, + -- we use xcar and xcdr for the attributes and reserve + -- car and cdr for the features. + + isNil() : Bool { false }; + + init(hd : Book, tl : BookList) : Cons { + { + xcar <- hd; + xcdr <- tl; + self; + } + }; + + car() : Book { xcar }; + + cdr() : BookList { xcdr }; + + print_list() : Object { + { + case xcar.print() of + dummy : Book => out_string("- dynamic type was Book -\n"); + dummy : Article => out_string("- dynamic type was Article -\n"); + esac; + xcdr.print_list(); + } + }; +}; + +Class Nil inherits BookList { + isNil() : Bool { true }; + + print_list() : Object { true }; +}; + + +Class Main { + + books : BookList; + + main() : Object { + (let a_book : Book <- + (new Book).initBook("Compilers, Principles, Techniques, and Tools", + "Aho, Sethi, and Ullman") + in + (let an_article : Article <- + (new Article).initArticle("The Top 100 CD_ROMs", + "Ulanoff", + "PC Magazine") + in + { + books <- (new Nil).cons(a_book).cons(an_article); + books.print_list(); + } + ) -- end let an_article + ) -- end let a_book + }; +}; diff --git a/tests/codegen/book_list_input.txt b/tests/codegen/book_list_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/book_list_output.txt b/tests/codegen/book_list_output.txt new file mode 100644 index 000000000..3408320b2 --- /dev/null +++ b/tests/codegen/book_list_output.txt @@ -0,0 +1,7 @@ +title: The Top 100 CD_ROMs +author: Ulanoff +periodical: PC Magazine +- dynamic type was Article - +title: Compilers, Principles, Techniques, and Tools +author: Aho, Sethi, and Ullman +- dynamic type was Book - diff --git a/tests/codegen/cells.cl b/tests/codegen/cells.cl new file mode 100755 index 000000000..9fd6741bb --- /dev/null +++ b/tests/codegen/cells.cl @@ -0,0 +1,97 @@ +(* models one-dimensional cellular automaton on a circle of finite radius + arrays are faked as Strings, + X's respresent live cells, dots represent dead cells, + no error checking is done *) +class CellularAutomaton inherits IO { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + self; + } + }; + + print() : CellularAutomaton { + { + out_string(population_map.concat("\n")); + self; + } + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + population_map.substr(position, 1) + }; + + cell_left_neighbor(position : Int) : String { + if position = 0 then + cell(num_cells() - 1) + else + cell(position - 1) + fi + }; + + cell_right_neighbor(position : Int) : String { + if position = num_cells() - 1 then + cell(0) + else + cell(position + 1) + fi + }; + + (* a cell will live if exactly 1 of itself and it's immediate + neighbors are alive *) + cell_at_next_evolution(position : Int) : String { + if (if cell(position) = "X" then 1 else 0 fi + + if cell_left_neighbor(position) = "X" then 1 else 0 fi + + if cell_right_neighbor(position) = "X" then 1 else 0 fi + = 1) + then + "X" + else + "." + fi + }; + + evolve() : CellularAutomaton { + (let position : Int in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; +}; + +class Main { + cells : CellularAutomaton; + + main() : Main { + { + cells <- (new CellularAutomaton).init(" X "); + cells.print(); + (let countdown : Int <- 20 in + while 0 < countdown loop + { + cells.evolve(); + cells.print(); + countdown <- countdown - 1; + } + pool + ); + self; + } + }; +}; diff --git a/tests/codegen/cells_input.txt b/tests/codegen/cells_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/cells_output.txt b/tests/codegen/cells_output.txt new file mode 100644 index 000000000..6304902cc --- /dev/null +++ b/tests/codegen/cells_output.txt @@ -0,0 +1,21 @@ + X +........XXX........ +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. +XXX.............XXX +...X...........X... +..XXX.........XXX.. +.X...X.......X...X. +XXX.XXX.....XXX.XXX +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. diff --git a/tests/codegen/complex.cl b/tests/codegen/complex.cl new file mode 100755 index 000000000..0b7aa44e9 --- /dev/null +++ b/tests/codegen/complex.cl @@ -0,0 +1,52 @@ +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + if c.reflect_X().reflect_Y() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; +}; diff --git a/tests/codegen/complex_input.txt b/tests/codegen/complex_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/complex_output.txt b/tests/codegen/complex_output.txt new file mode 100644 index 000000000..18b77c1fc --- /dev/null +++ b/tests/codegen/complex_output.txt @@ -0,0 +1 @@ +=) diff --git a/tests/codegen/fib.cl b/tests/codegen/fib.cl new file mode 100644 index 000000000..08ceaede8 --- /dev/null +++ b/tests/codegen/fib.cl @@ -0,0 +1,29 @@ +class Main inherits IO { + -- the class has features. Only methods in this case. + main(): Object { + { + out_string("Enter n to find nth fibonacci number!\n"); + out_int(fib(in_int())); + out_string("\n"); + } + }; + + fib(i : Int) : Int { -- list of formals. And the return type of the method. + let a : Int <- 1, + b : Int <- 0, + c : Int <- 0 + in + { + while (not (i = 0)) loop -- expressions are nested. + { + c <- a + b; + i <- i - 1; + b <- a; + a <- c; + } + pool; + c; + } + }; + +}; diff --git a/tests/codegen/fib_input.txt b/tests/codegen/fib_input.txt new file mode 100644 index 000000000..f599e28b8 --- /dev/null +++ b/tests/codegen/fib_input.txt @@ -0,0 +1 @@ +10 diff --git a/tests/codegen/fib_output.txt b/tests/codegen/fib_output.txt new file mode 100644 index 000000000..d402da6af --- /dev/null +++ b/tests/codegen/fib_output.txt @@ -0,0 +1,2 @@ +Enter n to find nth fibonacci number! +89 diff --git a/tests/codegen/graph.cl b/tests/codegen/graph.cl new file mode 100755 index 000000000..8e511358c --- /dev/null +++ b/tests/codegen/graph.cl @@ -0,0 +1,381 @@ +(* + * Cool program reading descriptions of weighted directed graphs + * from stdin. It builds up a graph objects with a list of vertices + * and a list of edges. Every vertice has a list of outgoing edges. + * + * INPUT FORMAT + * Every line has the form vertice successor* + * Where vertice is an int, and successor is vertice,weight + * + * An empty line or EOF terminates the input. + * + * The list of vertices and the edge list is printed out by the Main + * class. + * + * TEST + * Once compiled, the file g1.graph can be fed to the program. + * The output should look like this: + +nautilus.CS.Berkeley.EDU 53# spim -file graph.s (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + b : Int <- a.doh() + g.doh() + doh() + printh(); + + doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; + +}; + +class Bar inherits Razz { + + c : Int <- doh(); + + d : Object <- printh(); +}; + + +class Razz inherits Foo { + + e : Bar <- case self of + n : Razz => (new Bar); + n : Bar => n; + esac; + + f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); + +}; + +class Bazz inherits IO { + + h : Int <- 1; + + g : Foo <- case self of + n : Bazz => (new Foo); + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + i : Object <- printh(); + + printh() : Int { { out_int(h); 0; } }; + + doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; +}; + +(* scary . . . *) +class Main { + a : Bazz <- new Bazz; + b : Foo <- new Foo; + c : Razz <- new Razz; + d : Bar <- new Bar; + + main(): String { "do nothing" }; + +}; + + + + + diff --git a/tests/codegen/hairyscary_input.txt b/tests/codegen/hairyscary_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/hairyscary_output.txt b/tests/codegen/hairyscary_output.txt new file mode 100644 index 000000000..8985c22f2 --- /dev/null +++ b/tests/codegen/hairyscary_output.txt @@ -0,0 +1 @@ +17141611714163171416511714161171416317141653117141611714163171416511714161171416317141653171416117141631714165171416 \ No newline at end of file diff --git a/tests/codegen/hello_world.cl b/tests/codegen/hello_world.cl new file mode 100755 index 000000000..0c818f908 --- /dev/null +++ b/tests/codegen/hello_world.cl @@ -0,0 +1,5 @@ +class Main inherits IO { + main(): IO { + out_string("Hello, World.\n") + }; +}; diff --git a/tests/codegen/hello_world_input.txt b/tests/codegen/hello_world_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/hello_world_output.txt b/tests/codegen/hello_world_output.txt new file mode 100644 index 000000000..349db2bfe --- /dev/null +++ b/tests/codegen/hello_world_output.txt @@ -0,0 +1 @@ +Hello, World. diff --git a/tests/codegen/io.cl b/tests/codegen/io.cl new file mode 100755 index 000000000..7f0de869e --- /dev/null +++ b/tests/codegen/io.cl @@ -0,0 +1,103 @@ +(* + * The IO class is predefined and has 4 methods: + * + * out_string(s : String) : SELF_TYPE + * out_int(i : Int) : SELF_TYPE + * in_string() : String + * in_int() : Int + * + * The out operations print their argument to the terminal. The + * in_string method reads an entire line from the terminal and returns a + * string not containing the new line. The in_int method also reads + * an entire line from the terminal and returns the integer + * corresponding to the first non blank word on the line. If that + * word is not an integer, it returns 0. + * + * + * Because our language is object oriented, we need an object of type + * IO in order to call any of these methods. + * + * There are basically two ways of getting access to IO in a class C. + * + * 1) Define C to Inherit from IO. This way the IO methods become + * methods of C, and they can be called using the abbreviated + * dispatch, i.e. + * + * class C inherits IO is + * ... + * out_string("Hello world\n") + * ... + * end; + * + * 2) If your class C does not directly or indirectly inherit from + * IO, the best way to access IO is through an initialized + * attribute of type IO. + * + * class C inherits Foo is + * io : IO <- new IO; + * ... + * io.out_string("Hello world\n"); + * ... + * end; + * + * Approach 1) is most often used, in particular when you need IO + * functions in the Main class. + * + *) + + +class A { + + -- Let's assume that we don't want A to not inherit from IO. + + io : IO <- new IO; + + out_a() : Object { io.out_string("A: Hello world\n") }; + +}; + + +class B inherits A { + + -- B does not have to an extra attribute, since it inherits io from A. + + out_b() : Object { io.out_string("B: Hello world\n") }; + +}; + + +class C inherits IO { + + -- Now the IO methods are part of C. + + out_c() : Object { out_string("C: Hello world\n") }; + + -- Note that out_string(...) is just a shorthand for self.out_string(...) + +}; + + +class D inherits C { + + -- Inherits IO methods from C. + + out_d() : Object { out_string("D: Hello world\n") }; + +}; + + +class Main inherits IO { + + -- Same case as class C. + + main() : Object { + { + (new A).out_a(); + (new B).out_b(); + (new C).out_c(); + (new D).out_d(); + out_string("Done.\n"); + } + }; + +}; diff --git a/tests/codegen/io_input.txt b/tests/codegen/io_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/io_output.txt b/tests/codegen/io_output.txt new file mode 100644 index 000000000..f846f596d --- /dev/null +++ b/tests/codegen/io_output.txt @@ -0,0 +1,5 @@ +A: Hello world +B: Hello world +C: Hello world +D: Hello world +Done. diff --git a/tests/codegen/life.cl b/tests/codegen/life.cl new file mode 100755 index 000000000..b83d97957 --- /dev/null +++ b/tests/codegen/life.cl @@ -0,0 +1,436 @@ +(* The Game of Life + Tendo Kayiira, Summer '95 + With code taken from /private/cool/class/examples/cells.cl + + This introduction was taken off the internet. It gives a brief + description of the Game Of Life. It also gives the rules by which + this particular game follows. + + Introduction + + John Conway's Game of Life is a mathematical amusement, but it + is also much more: an insight into how a system of simple + cellualar automata can create complex, odd, and often aesthetically + pleasing patterns. It is played on a cartesian grid of cells + which are either 'on' or 'off' The game gets it's name from the + similarity between the behaviour of these cells and the behaviour + of living organisms. + + The Rules + + The playfield is a cartesian grid of arbitrary size. Each cell in + this grid can be in an 'on' state or an 'off' state. On each 'turn' + (called a generation,) the state of each cell changes simultaneously + depending on it's state and the state of all cells adjacent to it. + + For 'on' cells, + If the cell has 0 or 1 neighbours which are 'on', the cell turns + 'off'. ('dies of loneliness') + If the cell has 2 or 3 neighbours which are 'on', the cell stays + 'on'. (nothing happens to that cell) + If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', + the cell turns 'off'. ('dies of overcrowding') + + For 'off' cells, + If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which + are 'on', the cell stays 'off'. (nothing happens to that cell) + If the cell has 3 neighbours which are 'on', the cell turns + 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) + + Repeat for as many generations as desired. + + *) + + +class Board inherits IO { + + rows : Int; + columns : Int; + board_size : Int; + + size_of_board(initial : String) : Int { + initial.length() + }; + + board_init(start : String) : Board { + (let size :Int <- size_of_board(start) in + { + if size = 15 then + { + rows <- 3; + columns <- 5; + board_size <- size; + } + else if size = 16 then + { + rows <- 4; + columns <- 4; + board_size <- size; + } + else if size = 20 then + { + rows <- 4; + columns <- 5; + board_size <- size; + } + else if size = 21 then + { + rows <- 3; + columns <- 7; + board_size <- size; + } + else if size = 25 then + { + rows <- 5; + columns <- 5; + board_size <- size; + } + else if size = 28 then + { + rows <- 7; + columns <- 4; + board_size <- size; + } + else -- If none of the above fit, then just give + { -- the configuration of the most common board + rows <- 5; + columns <- 5; + board_size <- size; + } + fi fi fi fi fi fi; + self; + } + ) + }; + +}; + + + +class CellularAutomaton inherits Board { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + board_init(map); + self; + } + }; + + + + + print() : CellularAutomaton { + + (let i : Int <- 0 in + (let num : Int <- board_size in + { + out_string("\n"); + while i < num loop + { + out_string(population_map.substr(i,columns)); + out_string("\n"); + i <- i + columns; + } + pool; + out_string("\n"); + self; + } + ) ) + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + if board_size - 1 < position then + " " + else + population_map.substr(position, 1) + fi + }; + + north(position : Int): String { + if (position - columns) < 0 then + " " + else + cell(position - columns) + fi + }; + + south(position : Int): String { + if board_size < (position + columns) then + " " + else + cell(position + columns) + fi + }; + + east(position : Int): String { + if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + cell(position + 1) + fi + }; + + west(position : Int): String { + if position = 0 then + " " + else + if ((position / columns) * columns) = position then + " " + else + cell(position - 1) + fi fi + }; + + northwest(position : Int): String { + if (position - columns) < 0 then + " " + else if ((position / columns) * columns) = position then + " " + else + north(position - 1) + fi fi + }; + + northeast(position : Int): String { + if (position - columns) < 0 then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + north(position + 1) + fi fi + }; + + southeast(position : Int): String { + if board_size < (position + columns) then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + south(position + 1) + fi fi + }; + + southwest(position : Int): String { + if board_size < (position + columns) then + " " + else if ((position / columns) * columns) = position then + " " + else + south(position - 1) + fi fi + }; + + neighbors(position: Int): Int { + { + if north(position) = "X" then 1 else 0 fi + + if south(position) = "X" then 1 else 0 fi + + if east(position) = "X" then 1 else 0 fi + + if west(position) = "X" then 1 else 0 fi + + if northeast(position) = "X" then 1 else 0 fi + + if northwest(position) = "X" then 1 else 0 fi + + if southeast(position) = "X" then 1 else 0 fi + + if southwest(position) = "X" then 1 else 0 fi; + } + }; + + +(* A cell will live if 2 or 3 of it's neighbors are alive. It dies + otherwise. A cell is born if only 3 of it's neighbors are alive. *) + + cell_at_next_evolution(position : Int) : String { + + if neighbors(position) = 3 then + "X" + else + if neighbors(position) = 2 then + if cell(position) = "X" then + "X" + else + "-" + fi + else + "-" + fi fi + }; + + + evolve() : CellularAutomaton { + (let position : Int <- 0 in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; + +(* This is where the background pattern is detremined by the user. More + patterns can be added as long as whoever adds keeps the board either + 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) + option(): String { + { + (let num : Int in + { + out_string("\nPlease chose a number:\n"); + out_string("\t1: A cross\n"); + out_string("\t2: A slash from the upper left to lower right\n"); + out_string("\t3: A slash from the upper right to lower left\n"); + out_string("\t4: An X\n"); + out_string("\t5: A greater than sign \n"); + out_string("\t6: A less than sign\n"); + out_string("\t7: Two greater than signs\n"); + out_string("\t8: Two less than signs\n"); + out_string("\t9: A 'V'\n"); + out_string("\t10: An inverse 'V'\n"); + out_string("\t11: Numbers 9 and 10 combined\n"); + out_string("\t12: A full grid\n"); + out_string("\t13: A 'T'\n"); + out_string("\t14: A plus '+'\n"); + out_string("\t15: A 'W'\n"); + out_string("\t16: An 'M'\n"); + out_string("\t17: An 'E'\n"); + out_string("\t18: A '3'\n"); + out_string("\t19: An 'O'\n"); + out_string("\t20: An '8'\n"); + out_string("\t21: An 'S'\n"); + out_string("Your choice => "); + num <- in_int(); + out_string("\n"); + if num = 1 then + " XX XXXX XXXX XX " + else if num = 2 then + " X X X X X " + else if num = 3 then + "X X X X X" + else if num = 4 then + "X X X X X X X X X" + else if num = 5 then + "X X X X X " + else if num = 6 then + " X X X X X" + else if num = 7 then + "X X X XX X " + else if num = 8 then + " X XX X X X " + else if num = 9 then + "X X X X X " + else if num = 10 then + " X X X X X" + else if num = 11 then + "X X X X X X X X" + else if num = 12 then + "XXXXXXXXXXXXXXXXXXXXXXXXX" + else if num = 13 then + "XXXXX X X X X " + else if num = 14 then + " X X XXXXX X X " + else if num = 15 then + "X X X X X X X " + else if num = 16 then + " X X X X X X X" + else if num = 17 then + "XXXXX X XXXXX X XXXX" + else if num = 18 then + "XXX X X X X XXXX " + else if num = 19 then + " XX X XX X XX " + else if num = 20 then + " XX X XX X XX X XX X XX " + else if num = 21 then + " XXXX X XX X XXXX " + else + " " + fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; + } + ); + } + }; + + + + + prompt() : Bool { + { + (let ans : String in + { + out_string("Would you like to continue with the next generation? \n"); + out_string("Please use lowercase y or n for your answer [y]: "); + ans <- in_string(); + out_string("\n"); + if ans = "n" then + false + else + true + fi; + } + ); + } + }; + + + prompt2() : Bool { + (let ans : String in + { + out_string("\n\n"); + out_string("Would you like to choose a background pattern? \n"); + out_string("Please use lowercase y or n for your answer [n]: "); + ans <- in_string(); + if ans = "y" then + true + else + false + fi; + } + ) + }; + + +}; + +class Main inherits CellularAutomaton { + cells : CellularAutomaton; + + main() : Main { + { + (let continue : Bool in + (let choice : String in + { + out_string("Welcome to the Game of Life.\n"); + out_string("There are many initial states to choose from. \n"); + while prompt2() loop + { + continue <- true; + choice <- option(); + cells <- (new CellularAutomaton).init(choice); + cells.print(); + while continue loop + if prompt() then + { + cells.evolve(); + cells.print(); + } + else + continue <- false + fi + pool; + } + pool; + self; + } ) ); } + }; +}; + diff --git a/tests/codegen/life_input.txt b/tests/codegen/life_input.txt new file mode 100644 index 000000000..07e016726 --- /dev/null +++ b/tests/codegen/life_input.txt @@ -0,0 +1,66 @@ +y +1 +n +y +2 +n +y +3 +n +y +4 +n +y +5 +n +y +6 +n +y +7 +n +y +8 +n +y +9 +n +y +10 +n +y +11 +n +y +12 +n +y +13 +n +y +14 +n +y +15 +n +y +16 +n +y +17 +n +y +18 +n +y +19 +n +y +20 +n +y +21 +y +y +n +n \ No newline at end of file diff --git a/tests/codegen/life_output.txt b/tests/codegen/life_output.txt new file mode 100644 index 000000000..5a9b9f73d --- /dev/null +++ b/tests/codegen/life_output.txt @@ -0,0 +1,778 @@ +Welcome to the Game of Life. +There are many initial states to choose from. + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +XXXX +XXXX + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X +X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X +X X + X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X X + X X +X X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX +XXXXX +XXXXX +XXXXX +XXXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X +XXXXX + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X X + X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X + X X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXX +X +X +XXXX +X +X +XXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXX + X + X + X + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XXX +X +X + XX + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X--- +-XX- +---X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X-X- +-XX- +-X-X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: \ No newline at end of file diff --git a/tests/codegen/list.cl b/tests/codegen/list.cl new file mode 100644 index 000000000..b384dac62 --- /dev/null +++ b/tests/codegen/list.cl @@ -0,0 +1,141 @@ +(* + * This file shows how to implement a list data type for lists of integers. + * It makes use of INHERITANCE and DYNAMIC DISPATCH. + * + * The List class has 4 operations defined on List objects. If 'l' is + * a list, then the methods dispatched on 'l' have the following effects: + * + * isNil() : Bool Returns true if 'l' is empty, false otherwise. + * head() : Int Returns the integer at the head of 'l'. + * If 'l' is empty, execution aborts. + * tail() : List Returns the remainder of the 'l', + * i.e. without the first element. + * cons(i : Int) : List Return a new list containing i as the + * first element, followed by the + * elements in 'l'. + * + * There are 2 kinds of lists, the empty list and a non-empty + * list. We can think of the non-empty list as a specialization of + * the empty list. + * The class List defines the operations on empty list. The class + * Cons inherits from List and redefines things to handle non-empty + * lists. + *) + + +class List { + -- Define operations on empty lists. + + isNil() : Bool { true }; + + -- Since abort() has return type Object and head() has return type + -- Int, we need to have an Int as the result of the method body, + -- even though abort() never returns. + + head() : Int { { abort(); 0; } }; + + -- As for head(), the self is just to make sure the return type of + -- tail() is correct. + + tail() : List { { abort(); self; } }; + + -- When we cons and element onto the empty list we get a non-empty + -- list. The (new Cons) expression creates a new list cell of class + -- Cons, which is initialized by a dispatch to init(). + -- The result of init() is an element of class Cons, but it + -- conforms to the return type List, because Cons is a subclass of + -- List. + + cons(i : Int) : List { + (new Cons).init(i, self) + }; + +}; + + +(* + * Cons inherits all operations from List. We can reuse only the cons + * method though, because adding an element to the front of an emtpy + * list is the same as adding it to the front of a non empty + * list. All other methods have to be redefined, since the behaviour + * for them is different from the empty list. + * + * Cons needs two attributes to hold the integer of this list + * cell and to hold the rest of the list. + * + * The init() method is used by the cons() method to initialize the + * cell. + *) + +class Cons inherits List { + + car : Int; -- The element in this list cell + + cdr : List; -- The rest of the list + + isNil() : Bool { false }; + + head() : Int { car }; + + tail() : List { cdr }; + + init(i : Int, rest : List) : List { + { + car <- i; + cdr <- rest; + self; + } + }; + +}; + + + +(* + * The Main class shows how to use the List class. It creates a small + * list and then repeatedly prints out its elements and takes off the + * first element of the list. + *) + +class Main inherits IO { + + mylist : List; + + -- Print all elements of the list. Calls itself recursively with + -- the tail of the list, until the end of the list is reached. + + print_list(l : List) : Object { + if l.isNil() then out_string("\n") + else { + out_int(l.head()); + out_string(" "); + print_list(l.tail()); + } + fi + }; + + -- Note how the dynamic dispatch mechanism is responsible to end + -- the while loop. As long as mylist is bound to an object of + -- dynamic type Cons, the dispatch to isNil calls the isNil method of + -- the Cons class, which returns false. However when we reach the + -- end of the list, mylist gets bound to the object that was + -- created by the (new List) expression. This object is of dynamic type + -- List, and thus the method isNil in the List class is called and + -- returns true. + + main() : Object { + { + mylist <- new List.cons(1).cons(2).cons(3).cons(4).cons(5); + while (not mylist.isNil()) loop + { + print_list(mylist); + mylist <- mylist.tail(); + } + pool; + } + }; + +}; + + + diff --git a/tests/codegen/list_input.txt b/tests/codegen/list_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/list_output.txt b/tests/codegen/list_output.txt new file mode 100644 index 000000000..fca724903 --- /dev/null +++ b/tests/codegen/list_output.txt @@ -0,0 +1,5 @@ +5 4 3 2 1 +4 3 2 1 +3 2 1 +2 1 +1 diff --git a/tests/codegen/new_complex.cl b/tests/codegen/new_complex.cl new file mode 100755 index 000000000..a4fe714ce --- /dev/null +++ b/tests/codegen/new_complex.cl @@ -0,0 +1,79 @@ +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + { + -- trivially equal (see CoolAid) + if c.reflect_X() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi; + -- equal + if c.reflect_X().reflect_Y().equal(c.reflect_0()) + then out_string("=)\n") + else out_string("=(\n") + fi; + } + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; + + equal(d : Complex) : Bool { + if x = d.x_value() + then + if y = d.y_value() + then true + else false + fi + else false + fi + }; + + x_value() : Int { + x + }; + + y_value() : Int { + y + }; +}; diff --git a/tests/codegen/new_complex_input.txt b/tests/codegen/new_complex_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/new_complex_output.txt b/tests/codegen/new_complex_output.txt new file mode 100644 index 000000000..0e8da112c --- /dev/null +++ b/tests/codegen/new_complex_output.txt @@ -0,0 +1,2 @@ +=) +=) diff --git a/tests/codegen/palindrome.cl b/tests/codegen/palindrome.cl new file mode 100755 index 000000000..7f24789f9 --- /dev/null +++ b/tests/codegen/palindrome.cl @@ -0,0 +1,25 @@ +class Main inherits IO { + pal(s : String) : Bool { + if s.length() = 0 + then true + else if s.length() = 1 + then true + else if s.substr(0, 1) = s.substr(s.length() - 1, 1) + then pal(s.substr(1, s.length() -2)) + else false + fi fi fi + }; + + i : Int; + + main() : IO { + { + i <- ~1; + out_string("enter a string\n"); + if pal(in_string()) + then out_string("that was a palindrome\n") + else out_string("that was not a palindrome\n") + fi; + } + }; +}; diff --git a/tests/codegen/palindrome_input.txt b/tests/codegen/palindrome_input.txt new file mode 100644 index 000000000..8e1b64142 --- /dev/null +++ b/tests/codegen/palindrome_input.txt @@ -0,0 +1 @@ +anitalabalatina diff --git a/tests/codegen/palindrome_output.txt b/tests/codegen/palindrome_output.txt new file mode 100644 index 000000000..7a0095959 --- /dev/null +++ b/tests/codegen/palindrome_output.txt @@ -0,0 +1,2 @@ +enter a string +that was a palindrome diff --git a/tests/codegen/primes.cl b/tests/codegen/primes.cl new file mode 100644 index 000000000..8b9254d58 --- /dev/null +++ b/tests/codegen/primes.cl @@ -0,0 +1,84 @@ + +(* + * methodless-primes.cl + * + * Designed by Jesse H. Willett, jhw@cory, 11103234, with + * Istvan Siposs, isiposs@cory, 12342921. + * + * This program generates primes in order without using any methods. + * Actually, it does use three methods: those of IO to print out each + * prime, and abort() to halt the program. These methods are incidental, + * however, to the information-processing functionality of the program. We + * could regard the attribute 'out's sequential values as our output, and + * the string "halt" as our terminate signal. + * + * Naturally, using Cool this way is a real waste, basically reducing it + * to assembly without the benefit of compilation. + * + * There could even be a subroutine-like construction, in that different + * code could be in the assign fields of attributes of other classes, + * and it could be executed by calling 'new Sub', but no parameters + * could be passed to the subroutine, and it could only return itself. + * but returning itself would be useless since we couldn't call methods + * and the only operators we have are for Int and Bool, which do nothing + * interesting when we initialize them! + *) + +class Main inherits IO { + + main() : Int { -- main() is an atrophied method so we can parse. + 0 + }; + + out : Int <- -- out is our 'output'. Its values are the primes. + { + out_string("2 is trivially prime.\n"); + 2; + }; + + testee : Int <- out; -- testee is a number to be tested for primeness. + + divisor : Int; -- divisor is a number which may factor testee. + + stop : Int <- 500; -- stop is an arbitrary value limiting testee. + + m : Object <- -- m supplants the main method. + while true loop + { + + testee <- testee + 1; + divisor <- 2; + + while + if testee < divisor * divisor + then false -- can stop if divisor > sqrt(testee). + else if testee - divisor*(testee/divisor) = 0 + then false -- can stop if divisor divides testee. + else true + fi fi + loop + divisor <- divisor + 1 + pool; + + if testee < divisor * divisor -- which reason did we stop for? + then -- testee has no factors less than sqrt(testee). + { + out <- testee; -- we could think of out itself as the output. + out_int(out); + out_string(" is prime.\n"); + } + else -- the loop halted on testee/divisor = 0, testee isn't prime. + 0 -- testee isn't prime, do nothing. + fi; + + if stop <= testee then + "halt".abort() -- we could think of "halt" as SIGTERM. + else + "continue" + fi; + + } + pool; + +}; (* end of Main *) + diff --git a/tests/codegen/primes_input.txt b/tests/codegen/primes_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/primes_output.txt b/tests/codegen/primes_output.txt new file mode 100644 index 000000000..a4d0fcb3f --- /dev/null +++ b/tests/codegen/primes_output.txt @@ -0,0 +1,96 @@ +2 is trivially prime. +3 is prime. +5 is prime. +7 is prime. +11 is prime. +13 is prime. +17 is prime. +19 is prime. +23 is prime. +29 is prime. +31 is prime. +37 is prime. +41 is prime. +43 is prime. +47 is prime. +53 is prime. +59 is prime. +61 is prime. +67 is prime. +71 is prime. +73 is prime. +79 is prime. +83 is prime. +89 is prime. +97 is prime. +101 is prime. +103 is prime. +107 is prime. +109 is prime. +113 is prime. +127 is prime. +131 is prime. +137 is prime. +139 is prime. +149 is prime. +151 is prime. +157 is prime. +163 is prime. +167 is prime. +173 is prime. +179 is prime. +181 is prime. +191 is prime. +193 is prime. +197 is prime. +199 is prime. +211 is prime. +223 is prime. +227 is prime. +229 is prime. +233 is prime. +239 is prime. +241 is prime. +251 is prime. +257 is prime. +263 is prime. +269 is prime. +271 is prime. +277 is prime. +281 is prime. +283 is prime. +293 is prime. +307 is prime. +311 is prime. +313 is prime. +317 is prime. +331 is prime. +337 is prime. +347 is prime. +349 is prime. +353 is prime. +359 is prime. +367 is prime. +373 is prime. +379 is prime. +383 is prime. +389 is prime. +397 is prime. +401 is prime. +409 is prime. +419 is prime. +421 is prime. +431 is prime. +433 is prime. +439 is prime. +443 is prime. +449 is prime. +457 is prime. +461 is prime. +463 is prime. +467 is prime. +479 is prime. +487 is prime. +491 is prime. +499 is prime. +Abort called from class String diff --git a/tests/codegen/print-cool.cl b/tests/codegen/print-cool.cl new file mode 100644 index 000000000..76194e966 --- /dev/null +++ b/tests/codegen/print-cool.cl @@ -0,0 +1,9 @@ +class Main inherits IO { + main() : IO { + { + out_string((new Object).type_name().substr(4,1)). + out_string((isvoid self).type_name().substr(1,3)); -- demonstrates the dispatch rules. + out_string("\n"); + } + }; +}; diff --git a/tests/codegen/print-cool_input.txt b/tests/codegen/print-cool_input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/codegen/print-cool_output.txt b/tests/codegen/print-cool_output.txt new file mode 100644 index 000000000..2b58f8985 --- /dev/null +++ b/tests/codegen/print-cool_output.txt @@ -0,0 +1 @@ +cool diff --git a/tests/codegen/sort-list.cl b/tests/codegen/sort-list.cl new file mode 100644 index 000000000..7cf7b20a3 --- /dev/null +++ b/tests/codegen/sort-list.cl @@ -0,0 +1,146 @@ +(* + This file presents a fairly large example of Cool programming. The +class List defines the names of standard list operations ala Scheme: +car, cdr, cons, isNil, rev, sort, rcons (add an element to the end of +the list), and print_list. In the List class most of these functions +are just stubs that abort if ever called. The classes Nil and Cons +inherit from List and define the same operations, but now as +appropriate to the empty list (for the Nil class) and for cons cells (for +the Cons class). + +The Main class puts all of this code through the following silly +test exercise: + + 1. prompt for a number N + 2. generate a list of numbers 0..N-1 + 3. reverse the list + 4. sort the list + 5. print the sorted list + +Because the sort used is a quadratic space insertion sort, sorting +moderately large lists can be quite slow. +*) + +Class List inherits IO { + (* Since abort() returns Object, we need something of + type Bool at the end of the block to satisfy the typechecker. + This code is unreachable, since abort() halts the program. *) + isNil() : Bool { { abort(); true; } }; + + cons(hd : Int) : Cons { + (let new_cell : Cons <- new Cons in + new_cell.init(hd,self) + ) + }; + + (* + Since abort "returns" type Object, we have to add + an expression of type Int here to satisfy the typechecker. + This code is, of course, unreachable. + *) + car() : Int { { abort(); new Int; } }; + + cdr() : List { { abort(); new List; } }; + + rev() : List { cdr() }; + + sort() : List { cdr() }; + + insert(i : Int) : List { cdr() }; + + rcons(i : Int) : List { cdr() }; + + print_list() : Object { abort() }; +}; + +Class Cons inherits List { + xcar : Int; -- We keep the car in cdr in attributes. + xcdr : List; + + isNil() : Bool { false }; + + init(hd : Int, tl : List) : Cons { + { + xcar <- hd; + xcdr <- tl; + self; + } + }; + + car() : Int { xcar }; + + cdr() : List { xcdr }; + + rev() : List { (xcdr.rev()).rcons(xcar) }; + + sort() : List { (xcdr.sort()).insert(xcar) }; + + insert(i : Int) : List { + if i < xcar then + (new Cons).init(i,self) + else + (new Cons).init(xcar,xcdr.insert(i)) + fi + }; + + + rcons(i : Int) : List { (new Cons).init(xcar, xcdr.rcons(i)) }; + + print_list() : Object { + { + out_int(xcar); + out_string("\n"); + xcdr.print_list(); + } + }; +}; + +Class Nil inherits List { + isNil() : Bool { true }; + + rev() : List { self }; + + sort() : List { self }; + + insert(i : Int) : List { rcons(i) }; + + rcons(i : Int) : List { (new Cons).init(i,self) }; + + print_list() : Object { true }; + +}; + + +Class Main inherits IO { + + l : List; + + (* iota maps its integer argument n into the list 0..n-1 *) + iota(i : Int) : List { + { + l <- new Nil; + (let j : Int <- 0 in + while j < i + loop + { + l <- (new Cons).init(j,l); + j <- j + 1; + } + pool + ); + l; + } + }; + + main() : Object { + { + out_string("How many numbers to sort? "); + iota(in_int()).rev().sort().print_list(); + } + }; +}; + + + + + diff --git a/tests/codegen/sort-list_input.txt b/tests/codegen/sort-list_input.txt new file mode 100644 index 000000000..f599e28b8 --- /dev/null +++ b/tests/codegen/sort-list_input.txt @@ -0,0 +1 @@ +10 diff --git a/tests/codegen/sort-list_output.txt b/tests/codegen/sort-list_output.txt new file mode 100644 index 000000000..9878d57ea --- /dev/null +++ b/tests/codegen/sort-list_output.txt @@ -0,0 +1,10 @@ +How many numbers to sort? 0 +1 +2 +3 +4 +5 +6 +7 +8 +9 From 2002b30c5ecc5594ee370b62adb725127557cc6c Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 7 Mar 2022 17:25:31 -0300 Subject: [PATCH 55/60] all test passed --- src/compiler_components/ast.py | 10 +- src/compiler_components/base_to_cil.py | 158 ++++++ src/compiler_components/cil.py | 353 +++++++++++++ src/compiler_components/cil_mips_converter.py | 6 +- .../{code_generator => }/cil_nodes.py | 0 src/compiler_components/cil_to_mips.py | 463 ++++++++++++++++ src/compiler_components/code_gen.py | 21 +- .../code_generator/__init__.py | 0 .../code_generator/converter.py | 29 - .../code_generator/converter_utils.py | 142 ----- .../code_generator/mips_nodes.py | 149 ------ src/compiler_components/cool_cil_converter.py | 2 + src/compiler_components/cool_to_cil.py | 500 ++++++++++++++++++ src/compiler_components/lexer.py | 7 +- .../mips_formatter.py => mips.py} | 166 +++++- .../semantic/type_checker.py | 7 +- .../{code_generator => }/visitor.py | 0 17 files changed, 1657 insertions(+), 356 deletions(-) create mode 100644 src/compiler_components/base_to_cil.py create mode 100644 src/compiler_components/cil.py rename src/compiler_components/{code_generator => }/cil_nodes.py (100%) create mode 100644 src/compiler_components/cil_to_mips.py delete mode 100644 src/compiler_components/code_generator/__init__.py delete mode 100644 src/compiler_components/code_generator/converter.py delete mode 100644 src/compiler_components/code_generator/converter_utils.py delete mode 100644 src/compiler_components/code_generator/mips_nodes.py create mode 100644 src/compiler_components/cool_to_cil.py rename src/compiler_components/{code_generator/mips_formatter.py => mips.py} (81%) rename src/compiler_components/{code_generator => }/visitor.py (100%) diff --git a/src/compiler_components/ast.py b/src/compiler_components/ast.py index 8e321dc66..0d4b37917 100644 --- a/src/compiler_components/ast.py +++ b/src/compiler_components/ast.py @@ -280,6 +280,8 @@ def visit(self, tabs = 0): class ArithmeticNode(BinaryNode): pass +class MathNode(ArithmeticNode): + pass class ConstantNumNode(AtomicNode): pass @@ -331,19 +333,19 @@ def visit(self, tabs): return '\t' * tabs + f'\\__ InstantiateNode: new {node.lex}()' -class PlusNode(ArithmeticNode): +class PlusNode(MathNode): pass -class MinusNode(ArithmeticNode): +class MinusNode(MathNode): pass -class StarNode(ArithmeticNode): +class StarNode(MathNode): pass -class DivNode(ArithmeticNode): +class DivNode(MathNode): pass diff --git a/src/compiler_components/base_to_cil.py b/src/compiler_components/base_to_cil.py new file mode 100644 index 000000000..a60fca574 --- /dev/null +++ b/src/compiler_components/base_to_cil.py @@ -0,0 +1,158 @@ +from . import cil +import sys +sys.path.append('./semantic') +from .semantic.structures import * +import queue + +class BaseToCil: + def __init__(self, context): + self.dottypes = [] + self.dotdata = [ cil.DataNode('_empty', '')] + self.dotcode = [] + self.current_type = None + self.current_method = None + self.current_function = None + self.context = context + self.basic_types() + + @property + def params(self): + return self.current_function.params + + @property + def localvars(self): + return self.current_function.localvars + + @property + def instructions(self): + return self.current_function.instructions + + @property + def labels(self): + return self.current_function.labels + + def basic_types(self): + for basicType in ['Int', 'String', 'Bool']: + cil_type = self.register_type(basicType) + cil_type.attributes.append(self.to_attribute_name('value', basicType)) + + for method , typeMethod in self.context.get_type(basicType).all_methods(): + cil_type.methods.append((method.name, self.to_function_name(method.name, typeMethod.name))) + + for basicType in ['Object', 'IO']: + cil_type = self.register_type(basicType) + for method , typeMethod in self.context.get_type(basicType).all_methods(): + cil_type.methods.append((method.name, self.to_function_name(method.name, typeMethod.name))) + + + def register_param(self, vinfo): + vinfo.cilName = vinfo.name # f'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' + param_node = cil.ParamNode(vinfo.cilName) + self.params.append(param_node) + return vinfo.cilName + + def register_local(self, vinfo): + vinfo.cilName = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' + local_node = cil.LocalNode(vinfo.cilName) + self.localvars.append(local_node) + return vinfo.cilName + + def register_label(self): + name = f'label_{self.current_function.name[9:]}_{len(self.labels)}' + self.labels.append(name) + return name + + def define_internal_local(self): + vinfo = VariableInfo('internal', None) + return self.register_local(vinfo) + + def register_instruction(self, instruction): + self.instructions.append(instruction) + return instruction + + def to_function_name(self, method_name, type_name): + return f'function_{method_name}_at_{type_name}' + + def to_attribute_name(self, attr_name, attr_type): + return f'attribute_{attr_name}' + + def register_function(self, function_name): + function_node = cil.FunctionNode(function_name, [], [], [], []) + self.dotcode.append(function_node) + return function_node + + def register_type(self, name): + type_node = cil.TypeNode(name) + self.dottypes.append(type_node) + return type_node + + def register_data(self, value): + for dataNode in self.dotdata: + if dataNode.value == value: + return dataNode + + vname = f'data_{len(self.dotdata)}' + data_node = cil.DataNode(vname, value) + self.dotdata.append(data_node) + return data_node + + + def get_attr(self, function_name, attribute): + for dottype in self.dottypes: + if dottype.name == function_name: + break + + + # for attrib in dottype.attributes: + # if self.to_attribute_name(attribute, None) == attrib: + # break + + return dottype.attributes.index(self.to_attribute_name(attribute,None)) + + def get_method(self, type_name, method_name): + for typeContext in self.context.types: + if typeContext == type_name: + break + + methods = list(self.context.types[typeContext].all_methods()) + + for m in methods: + if m[0].name == method_name: + break + + return methods.index(m) + + def sort_types(self, types): + q = queue.deque() + lst = [] + for tp1 in types: + if not any ([x for x in types if x!= tp1 and tp1.conforms_to(x) ]): + q.append(tp1) + + while len(q) != 0: + tp = q.popleft() + if tp in types: + lst.append(tp) + for s in tp.sons: + q.append(s) + lst = list(reversed(lst)) + return lst + + def get_preordenTypes(self, typex): + ret_lis = [] + + for son in typex.sons: + ret_lis.extend(self.get_preordenTypes(son)) + + ret_lis.append(typex) + return ret_lis + + + def box(self, typeName, value): + obj_internal = self.define_internal_local() + self.register_instruction(cil.AllocateNode(typeName, obj_internal)) + self.register_instruction(cil.SetAttribNode(obj_internal, 0, value)) + self.register_instruction(cil.LoadNode(obj_internal, f'{typeName}_name')) + self.register_instruction(cil.LoadIntNode(obj_internal, f'{typeName}_size', 4)) + self.register_instruction(cil.LoadNode(obj_internal, f'__virtual_table__{typeName}', 8)) + return obj_internal \ No newline at end of file diff --git a/src/compiler_components/cil.py b/src/compiler_components/cil.py new file mode 100644 index 000000000..0795ace17 --- /dev/null +++ b/src/compiler_components/cil.py @@ -0,0 +1,353 @@ +from . import visitor + + +class Node: + pass + +class ProgramNode(Node): + def __init__(self, dottypes, dotdata, dotcode): + self.dottypes = dottypes + self.dotdata = dotdata + self.dotcode = dotcode + +class TypeNode(Node): + def __init__(self, name): + self.name = name + self.attributes = [] + self.methods = [] + +class DataNode(Node): + def __init__(self, vname, value): + self.name = vname + self.value = value + +class FunctionNode(Node): + def __init__(self, fname, params, localvars, instructions, labels): + self.name = fname + self.params = params + self.localvars = localvars + self.instructions = instructions + self.labels = labels + +class ParamNode(Node): + def __init__(self, name): + self.name = name + +class LocalNode(Node): + def __init__(self, name): + self.name = name + +class InstructionNode(Node): + pass + +class AssignNode(InstructionNode): + def __init__(self, dest, source): + self.dest = dest + self.source = source + +class ArithmeticNode(InstructionNode): + def __init__(self, dest, left, right): + self.dest = dest + self.left = left + self.right = right + +class ComplementNode(InstructionNode): + def __init__(self, expression, dest): + self.expression = expression + self.dest = dest + +class PlusNode(ArithmeticNode): + pass + +class MinusNode(ArithmeticNode): + pass + +class StarNode(ArithmeticNode): + pass + +class DivNode(ArithmeticNode): + pass + +class LessNode(InstructionNode): + def __init__(self, result, left, right, labelTrue, labelEnd): + self.result = result + self.left = left + self.right =right + self.labelTrue = labelTrue + self.labelEnd = labelEnd + +class LessEqualNode(ArithmeticNode): + def __init__(self, result, left, right, labelTrue, labelEnd): + self.result = result + self.left = left + self.right =right + self.labelTrue = labelTrue + self.labelEnd = labelEnd + +class GetAttribNode(InstructionNode): + def __init__(self, ins,att,dest): + self.ins = ins + self.att = att + self.dest = dest + +class SetAttribNode(InstructionNode): + def __init__(self, ins,att, value): + self.ins = ins + self.att = att + self.value = value + +class GetIndexNode(InstructionNode): + pass + +class SetIndexNode(InstructionNode): + pass + +class AllocateNode(InstructionNode): + def __init__(self, itype, dest): + self.type = itype + self.dest = dest + +class JumpNode(InstructionNode): + def __init__(self, method, dest): + self.method = method + self.dest = dest + +class ArrayNode(InstructionNode): + pass + +class TypeOfNode(InstructionNode): + def __init__(self, obj, dest): + self.obj = obj + self.dest = dest + +class IsVoidNode(InstructionNode): + def __init__(self, obj, dest, label): + self.obj = obj + self.dest = dest + self.label = label + +class CaseOption(InstructionNode): + def __init__(self, expression, label, typex): + self.expression = expression + self.label = label + self.typex = typex + +class LabelNode(InstructionNode): + def __init__(self, name): + self.name = name + +class GotoNode(InstructionNode): + def __init__(self, name): + self.name = name + +class GotoIfNode(InstructionNode): + def __init__(self, name, condition): + self.name = name + self.condition = condition + +class StaticCallNode(InstructionNode): + def __init__(self, function, dest): + self.function = function + self.dest = dest + +class DynamicCallNode(InstructionNode): + def __init__(self, xtype, method, dest,ins): + self.type = xtype + self.method = method + self.dest = dest + self.ins = ins + +class ArgsNode(InstructionNode): + def __init__(self, names): + self.names = names + +class ReturnNode(InstructionNode): + def __init__(self, value=None): + self.value = value + +class LoadNode(InstructionNode): + def __init__(self, dest, msg, desp=0): + self.dest = dest + self.msg = msg + self.desp = desp + +class LoadAddressNode(LoadNode): + pass + +class LoadIntNode(InstructionNode): + def __init__(self, dest, msg, desp): + self.dest = dest + self.msg = msg + self.desp = desp + +class LengthNode(InstructionNode): + pass + +class ConcatNode(InstructionNode): + pass + +class PrefixNode(InstructionNode): + pass + +class SubstringNode(InstructionNode): + pass + +class StringComparer(InstructionNode): + def __init__(self, result, left, right): + self.result = result + self.left = left + self.right = right + +class ToStrNode(InstructionNode): + def __init__(self, dest, ivalue): + self.dest = dest + self.ivalue = ivalue + +class ReadNode(InstructionNode): + def __init__(self, dest): + self.dest = dest + +class PrintNode(InstructionNode): + def __init__(self, str_addr): + self.str_addr = str_addr + +def get_formatter(): + + class PrintVisitor(object): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node): + dottypes = '\n'.join(self.visit(t) for t in node.dottypes) + dotdata = '\n'.join(self.visit(t) for t in node.dotdata) + dotcode = '\n'.join(self.visit(t) for t in node.dotcode) + + return f'.TYPES\n{dottypes}\n\n.DATA\n{dotdata}\n\n.CODE\n{dotcode}' + + @visitor.when(DataNode) + def visit(self, node): + return f'{node.name}: "{node.value}"' + + @visitor.when(TypeNode) + def visit(self, node): + attributes = '\n\t'.join(f'attribute {x}' for x in node.attributes) + methods = '\n\t'.join(f'method {x}: {y}' for x,y in node.methods) + + return f'type {node.name} {{\n\t{attributes}\n\n\t{methods}\n}}' + + @visitor.when(FunctionNode) + def visit(self, node): + params = '\n\t'.join(self.visit(x) for x in node.params) + localvars = '\n\t'.join(self.visit(x) for x in node.localvars) + instructions = '\n\t'.join(self.visit(x) for x in node.instructions) + + return f'function {node.name} {{\n\t{params}\n\n\t{localvars}\n\n\t{instructions}\n}}' + + # @visitor.when(Node) + # def visit(self, node): + # return f'----------------------------------{node.__class__.__name__}' + + @visitor.when(ParamNode) + def visit(self, node): + return f'PARAM {node.name}' + + @visitor.when(LocalNode) + def visit(self, node): + return f'LOCAL {node.name}' + + @visitor.when(AssignNode) + def visit(self, node:AssignNode): + return f'{node.dest} = {node.source}' + + @visitor.when(GetAttribNode) + def visit(self, node:GetAttribNode): + return f'{node.dest} = GETATTR {node.ins} {node.att}' + + @visitor.when(SetAttribNode) + def visit(self, node:SetAttribNode): + return f'SETATTR {node.ins} {node.att} {node.value}' + + @visitor.when(PlusNode) + def visit(self, node): + return f'{node.dest} = {node.left} + {node.right}' + + @visitor.when(MinusNode) + def visit(self, node): + return f'{node.dest} = {node.left} - {node.right}' + + @visitor.when(StarNode) + def visit(self, node): + return f'{node.dest} = {node.left} * {node.right}' + + @visitor.when(DivNode) + def visit(self, node): + return f'{node.dest} = {node.left} / {node.right}' + + @visitor.when(LessEqualNode) + def visit(self, node): + return f'{node.dest} = {node.left} <= {node.right}' + + @visitor.when(LessNode) + def visit(self, node): + return f'{node.result} = {node.left} < {node.right}' + + @visitor.when(AllocateNode) + def visit(self, node): + return f'{node.dest} = ALLOCATE {node.type}' + + @visitor.when(LabelNode) + def visit(self, node): + return f'LABEL {node.name}' + + @visitor.when(JumpNode) + def visit(self, node): + return f'JUMP {node.method}' + + @visitor.when(GotoNode) + def visit(self, node): + return f'GOTO {node.name}' + + @visitor.when(GotoIfNode) + def visit(self, node): + return f'IF {node.condition} GOTO {node.name}' + + @visitor.when(TypeOfNode) + def visit(self, node): + return f'{node.dest} = TYPEOF {node.type}' + + @visitor.when(StaticCallNode) + def visit(self, node): + return f'{node.dest} = CALL {node.function}' + + @visitor.when(DynamicCallNode) + def visit(self, node): + return f'{node.dest} = VCALL {node.type} {node.method}' + + @visitor.when(ArgsNode) + def visit(self, node): + return '\n\t'.join(f'ARG {x}' for x in node.names) + + @visitor.when(ReturnNode) + def visit(self, node): + return f'RETURN {node.value if node.value is not None else ""}' + + @visitor.when(LoadNode) + def visit(self, node): + return f'LOAD {node.dest} {node.msg} {node.desp}' + + @visitor.when(LoadAddressNode) + def visit(self, node): + return f'LOAD_ADDRESS {node.dest} {node.msg} {node.desp}' + + @visitor.when(LoadIntNode) + def visit(self, node): + return f'LOAD_INT {node.dest} {node.msg} {node.desp}' + + @visitor.when(StringComparer) + def visit(self,node): + return f'STRCOMP {node.result}, {node.left}, {node.right}' + + printer = PrintVisitor() + return (lambda ast: printer.visit(ast)) \ No newline at end of file diff --git a/src/compiler_components/cil_mips_converter.py b/src/compiler_components/cil_mips_converter.py index 2bf13de2b..e7b3fa084 100644 --- a/src/compiler_components/cil_mips_converter.py +++ b/src/compiler_components/cil_mips_converter.py @@ -1,6 +1,6 @@ -from .code_generator import visitor -from .code_generator.cil_nodes import * -from .code_generator.mips_nodes import * +from . import visitor +from .cil_nodes import * +from .mips import * class CilToMipsConverter: diff --git a/src/compiler_components/code_generator/cil_nodes.py b/src/compiler_components/cil_nodes.py similarity index 100% rename from src/compiler_components/code_generator/cil_nodes.py rename to src/compiler_components/cil_nodes.py diff --git a/src/compiler_components/cil_to_mips.py b/src/compiler_components/cil_to_mips.py new file mode 100644 index 000000000..30c29a340 --- /dev/null +++ b/src/compiler_components/cil_to_mips.py @@ -0,0 +1,463 @@ +from . import visitor +from . import cil +from .mips import * +from .cil import * + +class CilToMips: + def __init__(self): + self.data = [] + self.text = [] + self.function = None + self.types = None + + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node): + self.types = node.dottypes + + for typePN in node.dottypes: + self.visit(typePN) + + for dataNode in node.dotdata: + self.visit(dataNode) + + for instructionNode in node.dotcode: + self.visit(instructionNode) + + return MipsProgramNode(self.data, self.text) + + + @visitor.when(TypeNode) + def visit(self, node:TypeNode): + self.data.append(MipsStringNode(f'{node.name}_name', node.name)) + self.data.append(MipsWordNode(f'{node.name}_size', 4*(len(node.attributes) + 3))) + self.data.append(MipsTableNode(node.name , [ met[1] for met in node.methods])) + + + @visitor.when(DataNode) + def visit(self, node): + self.data.append(MipsStringNode(node.name, node.value)) + + @visitor.when(JumpNode) + def visit(self, node:DynamicCallNode): + self.register_instruction(MipsCommentNode('comienzo llamada al constructor')) + self.register_instruction(MipsJumpAtAddressNode(node.method)) + + num = int(node.dest.split('_')[-1]) + self.register_instruction(MipsSWNode('$a0', f'-{(num+1) * 4}($fp)')) + self.register_instruction(MipsCommentNode('fin llamada dinamica')) + + + @visitor.when(FunctionNode) + def visit(self, node:FunctionNode): + self.function = node + self.register_instruction(MipsLabelNode(node.name)) + + self.register_instruction(MipsCommentNode('muevo el fp al sp, pongo en sp ra y avanzo la pila')) + self.register_instruction(MipsMoveNode('$fp', '$sp')) + self.register_instruction(MipsSWNode('$ra', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + + self.register_instruction(MipsCommentNode('muevo la pila x las variables locales')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', f'-{len(node.localvars) * 4}')) + + for ins in node.instructions: + self.visit(ins) + + self.register_instruction(MipsCommentNode('return sp, fp, ra')) + self.register_instruction(MipsLWNode('$ra', '0($fp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', f'{len(node.localvars) * 4 + 8 + len(node.params) * 4}')) + self.register_instruction(MipsLWNode('$fp', '0($sp)')) + self.register_instruction(MipsJRNode('$ra')) + + + @visitor.when(ArgsNode) + def visit(self, node): + self.register_instruction(MipsCommentNode('guardando los parametros')) + self.register_instruction(MipsSWNode('$fp', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp' ,'-4')) + + for name in node.names: + pos = self.request_pos(name) + if not pos is None: + self.register_instruction(MipsLWNode('$a0', pos)) + else: + self.register_instruction(MipsLINode('$a0', name)) + + self.register_instruction(MipsSWNode('$a0', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + self.register_instruction(MipsCommentNode(' fin guardando los parametros')) + + + + + @visitor.when(ReturnNode) + def visit(self, node:ReturnNode): + self.register_instruction(MipsCommentNode('retornando el valor')) + pos = self.request_pos(node.value) + + if not pos is None: + self.register_instruction(MipsLWNode('$a0', pos)) + else: + self.register_instruction(MipsLINode('$a0', node.value)) + + @visitor.when(AllocateNode) + def visit(self, node:AllocateNode): + self.register_instruction(MipsCommentNode('init allocate')) + self.register_instruction(MipsLINode('$v0', '9')) + self.register_instruction(MipsLWNode('$a0', f'{node.type}_size')) + self.register_instruction(MipsSyscallNode()) + + num = int(node.dest.split('_')[-1]) + self.register_instruction(MipsSWNode('$v0', f'-{(num+1) * 4}($fp)')) + self.register_instruction(MipsCommentNode('end allocate')) + + + + @visitor.when(StaticCallNode) + def visit(self, node:StaticCallNode): + self.register_instruction(MipsLWNode('$a0', '4($fp)')) + self.register_instruction(MipsLWNode('$a0', '8($a0)')) + self.register_instruction(MipsLWNode('$a0', f'{node.function * 4}($a0)')) + self.register_instruction(MipsJALRNode('$a0')) + + num = int(node.dest.split('_')[-1]) + self.register_instruction(MipsSWNode('$a0', f'-{(num+1) * 4}($fp)')) + + @visitor.when(DynamicCallNode) + def visit(self, node:DynamicCallNode): + self.register_instruction(MipsCommentNode('comienzo llamada dinamica')) + + if node.type is None: + pos = self.request_pos(node.ins) + self.register_instruction(MipsLWNode('$a0', pos)) + self.register_instruction(MipsLWNode('$a0', '8($a0)')) + else: + self.register_instruction(MipsLANode('$a0', f'__virtual_table__{node.type}')) + + self.register_instruction(MipsLWNode('$a0', f'{node.method * 4}($a0)')) + self.register_instruction(MipsJALRNode('$a0')) + + num = int(node.dest.split('_')[-1]) + self.register_instruction(MipsSWNode('$a0', f'-{(num+1) * 4}($fp)')) + self.register_instruction(MipsCommentNode('fin llamada dinamica')) + + + + @visitor.when(SetAttribNode) + def visit(self, node:SetAttribNode): + self.register_instruction(MipsCommentNode('init set attribute')) + + pos = self.request_pos(node.ins) + self.register_instruction(MipsLWNode('$a0', pos)) + + # nameType = node.att.split('_')[1] + # num = -1 + + # for typeAct in self.types: + # if typeAct.name == nameType: + # num = typeAct.attributes.index(node.att) + # break + + + pos = self.request_pos(node.value) + if not pos is None: + self.register_instruction(MipsLWNode('$t1', pos)) + else: + self.register_instruction(MipsLINode('$t1', node.value)) + + self.register_instruction(MipsSWNode('$t1', f'{node.att * 4 + 12}($a0)')) + self.register_instruction(MipsCommentNode('end set attribute')) + + @visitor.when(GetAttribNode) + def visit(self, node:GetAttribNode): + self.register_instruction(MipsCommentNode('init get attribute')) + + pos_result = self.request_pos(node.dest) + pos = self.request_pos(node.ins) + self.register_instruction(MipsLWNode('$a0', pos)) + + # nameType = node.att.split('_')[1] + # num = -1 + + # for typeAct in self.types: + # if typeAct.name == nameType: + # num = typeAct.attributes.index(node.att) + # break + + + self.register_instruction(MipsLWNode('$a0', f'{node.att * 4 + 12}($a0)')) + self.register_instruction(MipsSWNode('$a0', pos_result)) + + + + @visitor.when(LoadNode) + def visit(self, node): + self.register_instruction(MipsCommentNode('LOAD inicia')) + self.register_instruction(MipsLANode('$t1', node.msg)) + dest = self.request_pos(node.dest) + self.register_instruction(MipsLWNode("$t2",dest)) + self.register_instruction(MipsSWNode('$t1', f"{node.desp}($t2)")) + + @visitor.when(LoadAddressNode) + def visit(self, node): + pos = self.request_pos(node.dest) + self.register_instruction(MipsLANode('$t1', node.msg)) + self.register_instruction(MipsSWNode('$t1', pos)) + + @visitor.when(LoadIntNode) + def visit(self, node): + self.register_instruction(MipsCommentNode('LOAD inicia')) + self.register_instruction(MipsLWNode('$t1', node.msg)) + dest = self.request_pos(node.dest) + self.register_instruction(MipsLWNode("$t2",dest)) + self.register_instruction(MipsSWNode('$t1', f"{node.desp}($t2)")) + + + + @visitor.when(AssignNode) + def visit(self, node:AssignNode): + pos_dest = self.request_pos(node.dest) + pos_src = self.request_pos(node.source) + + if not pos_src is None: + self.register_instruction(MipsLWNode('$t1', pos_src)) + else: + self.register_instruction(MipsLINode('$t1', node.source)) + + self.register_instruction(MipsSWNode('$t1', pos_dest)) + + @visitor.when(GotoNode) + def visit(self, node): + self.register_instruction(MipsJumpNode(node.name)) + + @visitor.when(GotoIfNode) + def visit(self, node): + pos = self.request_pos(node.condition) + + if not pos is None: + self.register_instruction(MipsLWNode('$a0', pos)) + else: + self.register_instruction(MipsLINode('$a0', node.condition)) + + self.register_instruction(MipsBNENode('$a0', '$zero', node.name)) + + @visitor.when(LabelNode) + def visit(self, node): + self.register_instruction(MipsLabelNode(node.name)) + + + + @visitor.when(PlusNode) + def visit(self, node:PlusNode): + pos_dest = self.request_pos(node.dest) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsAddNode('$a0', '$a0', '$t1')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(MinusNode) + def visit(self, node): + pos_dest = self.request_pos(node.dest) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsMinusNode('$a0', '$t1', '$a0')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + + @visitor.when(StarNode) + def visit(self, node): + pos_dest = self.request_pos(node.dest) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsStarNode('$a0', '$t1', '$a0')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(DivNode) + def visit(self, node): + pos_dest = self.request_pos(node.dest) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsDivNode('$a0', '$t1', '$a0')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(ComplementNode) + def visit(self, node): + pos_dest = self.request_pos(node.dest) + pos_expression = self.request_pos(node.expression) + + if not pos_expression is None: + self.register_instruction(MipsLWNode('$t1', pos_expression)) + else: + self.register_instruction(MipsLINode('$t1', node.expression)) + + self.register_instruction(MipsLINode('$t2', -1)) + self.register_instruction(MipsStarNode('$t1','$t1' ,'$t2')) + self.register_instruction(MipsSWNode('$t1', pos_dest)) + + @visitor.when(IsVoidNode) + def visit(self, node): + pos_obj = self.request_pos(node.obj) + pos_dest = self.request_pos(node.dest) + + if not pos_obj is None: + self.register_instruction(MipsLWNode('$t1', pos_obj)) + else: + self.register_instruction(MipsLINode('$a0', 1)) + self.register_instruction(MipsJumpNode(node.label)) + + self.register_instruction(MipsLINode('$a0', 1)) + self.register_instruction(MipsLANode('$t2', '_void')) + self.register_instruction(MipsBNENode('$t1', '$t2', node.label)) + self.register_instruction(MipsLINode('$a0', 0)) + self.register_instruction(MipsLabelNode(node.label)) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(LessNode) + def visit(self, node): + pos_dest = self.request_pos(node.result) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsBLTNode('$t1', '$a0', node.labelTrue)) + self.register_instruction(MipsLINode('$a0', 0)) + self.register_instruction(MipsJumpNode(node.labelEnd)) + self.register_instruction(MipsLabelNode(node.labelTrue)) + self.register_instruction(MipsLINode('$a0', 1)) + self.register_instruction(MipsLabelNode(node.labelEnd)) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(LessEqualNode) + def visit(self, node): + pos_dest = self.request_pos(node.result) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + if not pos_left is None: + self.register_instruction(MipsLWNode('$t1', pos_left)) + else: + self.register_instruction(MipsLINode('$t1', node.left)) + + if not pos_right is None: + self.register_instruction(MipsLWNode('$a0', pos_right)) + else: + self.register_instruction(MipsLINode('$a0', node.right)) + + self.register_instruction(MipsBLENode('$t1', '$a0', node.labelTrue)) + self.register_instruction(MipsLINode('$a0', 0)) + self.register_instruction(MipsJumpNode(node.labelEnd)) + self.register_instruction(MipsLabelNode(node.labelTrue)) + self.register_instruction(MipsLINode('$a0', 1)) + self.register_instruction(MipsLabelNode(node.labelEnd)) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + @visitor.when(StringComparer) + def visit(self, node): + pos_dest = self.request_pos(node.result) + pos_left = self.request_pos(node.left) + pos_right = self.request_pos(node.right) + + self.register_instruction(MipsSWNode('$fp', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp' ,'-4')) + + self.register_instruction(MipsLWNode('$a0', pos_left)) + self.register_instruction(MipsSWNode('$a0', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + + self.register_instruction(MipsLWNode('$a0', pos_right)) + self.register_instruction(MipsSWNode('$a0', '0($sp)')) + self.register_instruction(MipsAddiuNode('$sp', '$sp', '-4')) + + self.register_instruction(MipsJumpAtAddressNode('function_comparer_string')) + self.register_instruction(MipsSWNode('$a0', pos_dest)) + + + @visitor.when(CaseOption) + def visit(self, node): + pos_expression = self.request_pos(node.expression) + + if not pos_expression is None: + self.register_instruction(MipsLANode('$a0', f'{node.typex.name}_name')) + self.register_instruction(MipsLWNode('$t1', pos_expression)) + self.register_instruction(MipsLWNode('$t1', '0($t1)')) + self.register_instruction(MipsBEQNode('$t1', '$a0', node.label)) + else: + pass + + # registers + def register_data(self, instruction): + self.data.append(instruction) + + def register_instruction(self, instruction): + self.text.append(instruction) + + + + + # utils + def request_pos(self, name): + if name in [x.name for x in self.function.localvars]: + numb = int( name.split('_')[-1]) + return f'-{(numb+1) * 4}($fp)' + elif name in [x.name for x in self.function.params]: + numb = [param.name for param in self.function.params].index(name) + return f'{(numb + 1) * 4}($fp)' + else: + return None \ No newline at end of file diff --git a/src/compiler_components/code_gen.py b/src/compiler_components/code_gen.py index 3fc1a88ca..fe9795b87 100644 --- a/src/compiler_components/code_gen.py +++ b/src/compiler_components/code_gen.py @@ -1,8 +1,11 @@ from .compiler_component import CompilerComponent from .semantic_checker import SemanticChecker -from .cool_cil_converter import CoolToCilConverter +from .cool_to_cil import CoolToCil from .cil_mips_converter import CilToMipsConverter -from .code_generator.mips_formatter import get_formatter +from . import cil +from .cil_to_mips import CilToMips +from .cil import get_formatter +from . import mips class CodeGenerator(CompilerComponent): @@ -19,14 +22,16 @@ def execute(self): self.scope = self.semantic_checker.scope self.ast = self.semantic_checker.ast - cool_cil_converter = CoolToCilConverter(self.context) - cil_tree = cool_cil_converter.visit(self.ast, self.scope) + cool2cil = CoolToCil(self.context) + f = cil.get_formatter() + c = cool2cil.visit(self.ast, self.scope) + # print(f(c)) - cil_mips_converter = CilToMipsConverter() - mips_tree = cil_mips_converter.visit(cil_tree) - mips_formatter = get_formatter() + cil2mips = CilToMips() + d = cil2mips.visit(c) + e = mips.get_formatter() - self.mips_text = mips_formatter(mips_tree) + self.mips_text = e(d) def has_errors(self): return False diff --git a/src/compiler_components/code_generator/__init__.py b/src/compiler_components/code_generator/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/compiler_components/code_generator/converter.py b/src/compiler_components/code_generator/converter.py deleted file mode 100644 index 38930df69..000000000 --- a/src/compiler_components/code_generator/converter.py +++ /dev/null @@ -1,29 +0,0 @@ -from .converter_utils import * - - -class Converter: - def __init__(self, context): - self.dottypes = [] - self.dotdata = [CilDataNode('_empty', '')] - self.dotcode = [] - self.current_type = None - self.current_method = None - self.current_function = None - self.context = context - basic_types(self) - - @property - def params(self): - return self.current_function.params - - @property - def localvars(self): - return self.current_function.localvars - - @property - def instructions(self): - return self.current_function.instructions - - @property - def labels(self): - return self.current_function.labels diff --git a/src/compiler_components/code_generator/converter_utils.py b/src/compiler_components/code_generator/converter_utils.py deleted file mode 100644 index da634a47e..000000000 --- a/src/compiler_components/code_generator/converter_utils.py +++ /dev/null @@ -1,142 +0,0 @@ -from .cil_nodes import * -import queue - - -def define_internal_local(converter): - var_info = VariableInfo('internal', None) - return register_local(converter, var_info) - - -def get_preorder_types(converter, typex): - ret_lis = [] - - for son in typex.sons: - ret_lis.extend(get_preorder_types(converter, son)) - - ret_lis.append(typex) - return ret_lis - - -def get_attr(converter, function_name, attribute): - for dottype in converter.dottypes: - if dottype.name == function_name: - break - - return dottype.attributes.index(to_attribute_name(attribute)) - - -def get_method(converter, type_name, method_name): - for typeContext in converter.context.types: - if typeContext == type_name: - break - - methods = list(converter.context.types[typeContext].all_methods()) - - for m in methods: - if m[0].name == method_name: - break - - return methods.index(m) - - -def box(converter, typeName, value): - obj_internal = define_internal_local(converter) - register_instruction(converter, CilAllocateNode(typeName, obj_internal)) - register_instruction(converter, CilSetAttribNode(obj_internal, 0, value)) - register_instruction(converter, CilLoadNode(obj_internal, f'{typeName}_name')) - register_instruction(converter, CilLoadIntNode(obj_internal, f'{typeName}_size', 4)) - register_instruction(converter, CilLoadNode(obj_internal, f'__virtual_table__{typeName}', 8)) - return obj_internal - - -def to_function_name(method_name, type_name): - return f'function_{method_name}_at_{type_name}' - - -def to_attribute_name(attr_name): - return f'attribute_{attr_name}' - - -def register_param(converter, var_info): - var_info.cilName = var_info.name - param_node = CilParamNode(var_info.cilName) - converter.params.append(param_node) - return var_info.cilName - - -def register_local(converter, var_info): - var_info.cilName = f'local_{converter.current_function.name[9:]}_{var_info.name}_{len(converter.localvars)}' - local_node = CilLocalNode(var_info.cilName) - converter.localvars.append(local_node) - return var_info.cilName - - -def register_label(converter): - name = f'label_{converter.current_function.name[9:]}_{len(converter.labels)}' - converter.labels.append(name) - return name - - -def register_instruction(converter, instruction): - converter.instructions.append(instruction) - return instruction - - -def register_function(converter, function_name): - function_node = CilFunctionNode(function_name, [], [], [], []) - converter.dotcode.append(function_node) - return function_node - - -def register_type(converter, name): - type_node = CilTypeNode(name) - converter.dottypes.append(type_node) - return type_node - - -def register_data(converter, value): - for dataNode in converter.dotdata: - if dataNode.value == value: - return dataNode - - vname = f'data_{len(converter.dotdata)}' - data_node = CilDataNode(vname, value) - converter.dotdata.append(data_node) - return data_node - - -def sort_types(types): - q = queue.deque() - lst = [] - for tp1 in types: - if not any([x for x in types if x != tp1 and tp1.conforms_to(x)]): - q.append(tp1) - - while len(q) != 0: - tp = q.popleft() - if tp in types: - lst.append(tp) - for s in tp.sons: - q.append(s) - lst = list(reversed(lst)) - return lst - - -def basic_types(converter): - for basicType in ['Int', 'String', 'Bool']: - cil_type = register_type(converter, basicType) - cil_type.attributes.append(to_attribute_name('value')) - - for method, typeMethod in converter.context.get_type(basicType).all_methods(): - cil_type.methods.append((method.name, to_function_name(method.name, typeMethod.name))) - - for basicType in ['Object', 'IO']: - cil_type = register_type(converter, basicType) - for method, typeMethod in converter.context.get_type(basicType).all_methods(): - cil_type.methods.append((method.name, to_function_name(method.name, typeMethod.name))) - - -class VariableInfo: - def __init__(self, name, typex): - self.name = name - self.type = typex diff --git a/src/compiler_components/code_generator/mips_nodes.py b/src/compiler_components/code_generator/mips_nodes.py deleted file mode 100644 index a66ba3e8d..000000000 --- a/src/compiler_components/code_generator/mips_nodes.py +++ /dev/null @@ -1,149 +0,0 @@ -class MipsNode: - pass - - -class MipsProgramNode(MipsNode): - def __init__(self, dotdata, dotcode): - self.dotdata = dotdata - self.dotcode = dotcode - - -# string -class MipsStringNode(MipsNode): - def __init__(self, name, value): - self.name = name - self.value = value - - -class MipsWordNode(MipsNode): - def __init__(self, name, value): - self.name = name - self.value = value - - -class MipsTableNode(MipsNode): - def __init__(self , type_name,methods): - self.type_name = type_name - self.methods = methods - - -# jumps -class MipsJumpNode(MipsNode): - def __init__(self, label): - self.label = label - - -class MipsJumpAtAddressNode(MipsJumpNode): - pass - - -class MipsJRNode(MipsJumpNode): - pass - - -class MipsJALRNode(MipsJumpNode): - pass - - -# stack -class MipsLWNode(MipsNode): - def __init__(self, dest, src): - self.src = src - self.dest = dest - - -class MipsLINode(MipsNode): - def __init__(self, dest, src): - self.src = src - self.dest = dest - - -class MipsLANode(MipsNode): - def __init__(self, dest, src): - self.src = src - self.dest = dest - - -class MipsSWNode(MipsNode): - def __init__(self, src, dest): - self.src = src - self.dest = dest - - -# syscall -class MipsSyscallNode(MipsNode): - pass - - -# move -class MipsMoveNode(MipsNode): - def __init__(self, dest, src): - self.src = src - self.dest = dest - - -# arithmetic -class MipsArithmeticNode: - def __init__(self, param1, param2, param3): - self.param1 = param1 - self.param2 = param2 - self.param3 = param3 - - -class MipsAddNode(MipsArithmeticNode): - pass - - -class MipsAddiuNode(MipsArithmeticNode): - pass - - -class MipsMinusNode(MipsArithmeticNode): - pass - - -class MipsStarNode(MipsArithmeticNode): - pass - - -class MipsDivNode(MipsArithmeticNode): - pass - - -class MipsNEGNode(MipsNode): - def __init__(self, dest, src): - self.dest = dest - self.src = src - - -class MipsComparerNode(MipsNode): - def __init__(self, param1, param2, label): - self.param1 = param1 - self.param2 = param2 - self.label = label - - -class MipsBEQNode(MipsComparerNode): - pass - - -class MipsBNENode(MipsComparerNode): - pass - - -class MipsBLTNode(MipsComparerNode): - pass - - -class MipsBLENode(MipsComparerNode): - pass - - -class MipsLabelNode(MipsNode): - def __init__(self, name): - self.name = name - - -class MipsCommentNode(MipsNode): - def __init__(self, comment): - self.comment = '\n #' + comment + '\n' diff --git a/src/compiler_components/cool_cil_converter.py b/src/compiler_components/cool_cil_converter.py index 225b3bf64..8a5ec4de2 100644 --- a/src/compiler_components/cool_cil_converter.py +++ b/src/compiler_components/cool_cil_converter.py @@ -189,8 +189,10 @@ def visit(self, node, scope): @visitor.when(BlockNode) def visit(self, node, scope): + for expression, child in zip(node.expr_list, scope.children): value = self.visit(expression, child) + return value diff --git a/src/compiler_components/cool_to_cil.py b/src/compiler_components/cool_to_cil.py new file mode 100644 index 000000000..b12202fbe --- /dev/null +++ b/src/compiler_components/cool_to_cil.py @@ -0,0 +1,500 @@ +from . import cil +import sys +from .base_to_cil import BaseToCil +from .ast import * +sys.path.append('./semantic') +from .semantic.structures import * +from . import visitor + +class CoolToCil(BaseToCil): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node, scope): + self.current_function = self.register_function('main') + instance = self.define_internal_local() + result = self.define_internal_local() + result2 = self.define_internal_local() + + self.register_instruction(cil.AllocateNode('Main', instance)) + self.register_instruction(cil.ArgsNode([instance])) + + self.register_instruction(cil.JumpNode(self.to_function_name('Ctr', 'Main'), result)) + self.register_instruction(cil.ArgsNode([result])) + + realMethod = self.get_method(self.context.get_type('Main').name, 'main') + self.register_instruction(cil.DynamicCallNode('Main', realMethod , result2, result)) + self.register_instruction(cil.ReturnNode(0)) + self.current_function = None + + for declaration, child_scope in zip(node.declarations, scope.children): + self.visit(declaration, child_scope) + + return cil.ProgramNode(self.dottypes, self.dotdata, self.dotcode) + + @visitor.when(ClassDeclarationNode) + def visit(self, node, scope): + self.current_type = self.context.get_type(node.id) + + cil_type = self.register_type(node.id) + + for attr, type_attr in self.current_type.all_attributes(): + cil_type.attributes.append(self.to_attribute_name(attr.name, type_attr.name)) + + for func, type_func in self.current_type.all_methods(): + cil_type.methods.append((func.name, self.to_function_name(func.name, type_func.name))) + + nodeFunctions = [x for x in node.features if isinstance(x, FuncDeclarationNode)] + for feature, child_scope in zip(nodeFunctions, scope.children[0].children): + self.visit(feature, child_scope) + + #ctr + name = self.to_function_name("Ctr", self.current_type.name) + self.current_function = self.register_function(name) + self.register_param(VariableInfo('self', self.current_type)) + + self.register_instruction(cil.LoadNode('self', f'{self.current_type.name}_name')) + self.register_instruction(cil.LoadIntNode('self', f'{self.current_type.name}_size', 4)) + self.register_instruction(cil.LoadNode('self', f'__virtual_table__{self.current_type.name}', 8)) + + initResult = self.define_internal_local() + self.register_instruction(cil.ArgsNode(['self'])) + self.register_instruction(cil.JumpNode(self.to_function_name('Init', self.current_type.name), initResult)) + self.register_instruction(cil.ReturnNode('self')) + + + #init + name = self.to_function_name('Init', self.current_type.name) + self.current_function = self.register_function(name) + self.register_param(VariableInfo('self', self.current_type)) + + parentResult = self.define_internal_local() + self.register_instruction(cil.ArgsNode(['self'])) + self.register_instruction(cil.JumpNode(self.to_function_name('Init', self.current_type.parent.name), parentResult)) + + nodeatt = [x for x in node.features if isinstance(x, AttrDeclarationNode)] + for feature, child_scope in zip(nodeatt, scope.children[1].children): + self.visit(feature, child_scope) + + self.register_instruction(cil.ReturnNode('self')) + + self.current_type = None + + @visitor.when(FuncDeclarationNode) + def visit(self, node, scope): + self.current_method = self.current_type.get_method(node.id) + + name = self.to_function_name(node.id, self.current_type.name) + self.current_function = self.register_function(name) + + self.register_param(VariableInfo('self', self.current_type)) + for param in scope.locals: + self.register_param(param) + + value = self.visit(node.body, scope.children[0]) + + self.register_instruction(cil.ReturnNode(value)) + self.current_method = None + + + @visitor.when(AttrDeclarationNode) + def visit(self, node, scope): + if not node.expr is None: + value = self.visit(node.expr, scope.children[0]) + + if node.type == 'Object' and node.expr.type.name in ['Int', 'Bool', 'String']: + value = self.box(node.expr.type.name, value) + + else: + if node.type == 'String': + internal = self.define_internal_local() + self.register_instruction(cil.LoadAddressNode(internal, "_empty")) + value = internal + elif node.type == 'Bool' or node.type == 'Int': + value = 0 + else: + internal = self.define_internal_local() + self.register_instruction(cil.LoadAddressNode(internal, "_void")) + value = internal + + attrib = self.get_attr(self.current_type.name, node.id) + self.register_instruction(cil.SetAttribNode('self', attrib, value)) + + @visitor.when(LetNode) + def visit(self, node, scope): + scopeOpen = scope.children[0] + + value = None + for init in node.list_decl: + if not init.expr is None: + value = self.visit(init.expr, scopeOpen) + + if init.expr.type.name in ['Int', 'Bool', 'String'] and init.type == 'Object': + value = self.box(init.expr.type.name, value) + + else: + if init.type == 'String': + internal = self.define_internal_local() + self.register_instruction(cil.LoadAddressNode(internal, "_empty")) + value = internal + elif init.type == 'Bool' or init.type == 'Int': + value = 0 + else: + internal = self.define_internal_local() + self.register_instruction(cil.LoadAddressNode(internal, "_void")) + value = internal + + scopeOpen = scopeOpen.children[-1] + vinfo = scopeOpen.find_variable(init.id) + vname = self.register_local(vinfo) + self.register_instruction(cil.AssignNode(vname, value)) + + return self.visit(node.expr, scopeOpen.children[0]) + + @visitor.when(CaseNode) + def visit(self, node, scope): + result = self.define_internal_local() + + internal_expression = self.define_internal_local() + value_expression = self.visit(node.expr, scope.children[0]) + self.register_instruction(cil.AssignNode(internal_expression, value_expression)) + + types_ordered = self.sort_types([self.context.get_type(x.type) for x in node.list_case]) + list_label = [] + labels = dict() + + for typex in types_ordered: + labelTypex = self.register_label() + labels[typex.name] = labelTypex + pre = self.get_preordenTypes(typex) + for typex2 in pre: + if not typex2 in [x[0] for x in list_label]: + list_label.append((typex2, labelTypex)) + + for typex in list_label: + self.register_instruction(cil.CaseOption(value_expression, typex[1], typex[0])) + #error + + labelEnd = self.register_label() + for branch, scopeBranch in zip(node.list_case, scope.children[1].children): + vinfo = scopeBranch.find_variable(branch.id) + xxx = self.register_local(vinfo) + self.register_instruction(cil.LabelNode(labels[branch.type])) + self.register_instruction(cil.AssignNode(xxx, value_expression)) + + valueBranch = self.visit(branch.expr, scopeBranch) + self.register_instruction(cil.AssignNode(result, valueBranch)) + self.register_instruction(cil.GotoNode(labelEnd)) + + self.register_instruction(cil.LabelNode(labelEnd)) + return result + + + @visitor.when(BlockNode) + def visit(self, node, scope): + for expression, child in zip(node.expr_list, scope.children): + value = self.visit(expression, child) + + return value + + @visitor.when(IfNode) + def visit(self, node, scope): + cond = self.visit(node.if_c, scope.children[0]) + + labelTrue = self.register_label() + labelFalse = self.register_label() + result = self.define_internal_local() + + self.register_instruction(cil.GotoIfNode(labelTrue, cond)) + vfalse = self.visit(node.else_c, scope.children[2]) + self.register_instruction(cil.AssignNode(result, vfalse)) + self.register_instruction(cil.GotoNode(labelFalse)) + self.register_instruction(cil.LabelNode(labelTrue)) + vtrue = self.visit(node.then_c, scope.children[1]) + self.register_instruction(cil.AssignNode(result, vtrue)) + self.register_instruction(cil.LabelNode(labelFalse)) + + return result + + @visitor.when(WhileNode) + def visit(self, node, scope): + labelWhileStart = self.register_label() + labelWhileContinue = self.register_label() + labelWhileBreak = self.register_label() + + self.register_instruction(cil.LabelNode(labelWhileStart)) + + cond = self.visit(node.condition, scope.children[0]) + + self.register_instruction(cil.GotoIfNode(labelWhileContinue, cond)) + self.register_instruction(cil.GotoNode(labelWhileBreak)) + self.register_instruction(cil.LabelNode(labelWhileContinue)) + self.visit(node.body, scope.children[1]) + self.register_instruction(cil.GotoNode(labelWhileStart)) + self.register_instruction(cil.LabelNode(labelWhileBreak)) + + result = self.define_internal_local() + self.register_instruction(cil.LoadAddressNode(result, "_void")) + return result + + @visitor.when(AssignNode) + def visit(self, node, scope): + vinfo = scope.find_variable(node.id) + value = self.visit(node.expr, scope.children[0]) + + if vinfo is None: + attrib = self.get_attr(self.current_type.name, node.id) + self.register_instruction(cil.SetAttribNode('self', attrib, value)) + else: + self.register_instruction(cil.AssignNode(vinfo.cilName, value)) + + return value + + @visitor.when(DispatchNode) + def visit(self, node, scope): + result = self.define_internal_local() + obj = self.visit(node.expr, scope.children[0]) + + if node.expr.type.name in ['Int', 'Bool', 'String']: + if node.id in ['abort', 'type_name', 'copy']: + obj = self.box(node.expr.type.name, obj) + + valuesArgs = [] + for arg, child in zip(node.params, scope.children[1:]): + value = self.visit(arg, child) + + if arg.type.name in ['Int', 'Bool', 'String']: + method = self.context.get_type(node.typex).get_method(node.id) + param_type = method.param_types[node.params.index(arg)] + + if param_type.name == 'Object': + valuesArgs.append(self.box(arg.type.name, value)) + continue + + valuesArgs.append(value) + + if node.typexa is None: + node.typex = node.expr.type.name + + self.register_instruction(cil.ArgsNode( list(reversed(valuesArgs)) + [obj])) + + if node.expr.type.name == 'String' and node.id in ['length', 'concat', 'substr']: + self.register_instruction(cil.JumpNode(self.to_function_name(node.id, 'String'), result)) + else: + realMethod = self.get_method(node.typex, node.id) + self.register_instruction(cil.DynamicCallNode(node.typexa, realMethod, result, obj)) + return result + + @visitor.when(CallNode) + def visit(self, node, scope): + result = self.define_internal_local() + + valuesArgs = [] + for arg, child in zip(node.args, scope.children): + value = self.visit(arg, child) + + if arg.type.name in ['Int', 'Bool', 'String']: + method = self.current_type.get_method(node.id) + param_type = method.param_types[node.args.index(arg)] + + if param_type.name == 'Object': + valuesArgs.append(self.box(arg.type.name, value)) + continue + + valuesArgs.append(value) + + self.register_instruction(cil.ArgsNode( list(reversed(valuesArgs)) + ['self'])) + + realMethod = self.get_method(self.current_type.name, node.id) + self.register_instruction(cil.StaticCallNode(realMethod, result)) + return result + + @visitor.when(ConstantNumNode) + def visit(self, node, scope): + return int(node.lex) + + + @visitor.when(ConstantBooleanNode) + def visit(self, node, scope): + if node.lex: + return 1 + return 0 + + + @visitor.when(ConstantStringNode) + def visit(self, node, scope): + msg = self.register_data(node.lex).name + internal = self.define_internal_local() + self.register_instruction(cil.LoadAddressNode(internal, msg)) + return internal + + + @visitor.when(VariableNode) + def visit(self, node, scope): + if node.lex == 'self': + return 'self' + + vinfo = scope.find_variable(node.lex) + + if vinfo is None: + result = self.define_internal_local() + attrib = self.get_attr(self.current_type.name, node.lex) + + self.register_instruction(cil.GetAttribNode('self', attrib, result)) + return result + + return vinfo.cilName + + + @visitor.when(InstantiateNode) + def visit(self, node, scope): + if not node.type.name == "Int": + instance = self.define_internal_local() + result = self.define_internal_local() + self.register_instruction(cil.AllocateNode(node.type.name, instance)) + self.register_instruction(cil.ArgsNode([instance])) + self.register_instruction(cil.JumpNode(self.to_function_name('Ctr', node.type.name), result)) + return instance + else: + return 0 + + + + @visitor.when(PlusNode) + def visit(self, node, scope): + result = self.define_internal_local() + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + self.register_instruction(cil.PlusNode(result, left, right)) + return result + + + @visitor.when(MinusNode) + def visit(self, node, scope): + result = self.define_internal_local() + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + self.register_instruction(cil.MinusNode(result, left, right)) + return result + + + @visitor.when(StarNode) + def visit(self, node, scope): + result = self.define_internal_local() + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + self.register_instruction(cil.StarNode(result, left, right)) + return result + + @visitor.when(DivNode) + def visit(self, node, scope): + result = self.define_internal_local() + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + self.register_instruction(cil.DivNode(result, left, right)) + return result + + @visitor.when(EqualsNode) + def visit(self, node, scope): + result = self.define_internal_local() + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + + if node.left.type.name == 'String': + self.register_instruction(cil.StringComparer(result, left, right)) + else: + labelEquals = self.register_label() + labelsEnd = self.register_label() + + resultComparer = self.define_internal_local() + self.register_instruction(cil.MinusNode(resultComparer, left, right)) + + self.register_instruction(cil.GotoIfNode(labelEquals, resultComparer)) + self.register_instruction(cil.AssignNode(result, 1)) + self.register_instruction(cil.GotoNode(labelsEnd)) + self.register_instruction(cil.LabelNode(labelEquals)) + self.register_instruction(cil.AssignNode(result, 0)) + self.register_instruction(cil.LabelNode(labelsEnd)) + + return result + + @visitor.when(MinusNode) + def visit(self, node, scope): + result = self.define_internal_local() + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + self.register_instruction(cil.MinusNode(result, left, right)) + return result + + @visitor.when(MinorNode) + def visit(self, node, scope): + result = self.define_internal_local() + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + + labelTrue = self.register_label() + labelEnd = self.register_label() + + self.register_instruction(cil.LessNode(result, left, right, labelTrue, labelEnd)) + return result + + @visitor.when(MinorEqualsNode) + def visit(self, node, scope): + result = self.define_internal_local() + left = self.visit(node.left, scope.children[0]) + right = self.visit(node.right, scope.children[1]) + + labelTrue = self.register_label() + labelEnd = self.register_label() + + self.register_instruction(cil.LessEqualNode(result, left, right, labelTrue,labelEnd)) + return result + + @visitor.when(NotNode) + def visit(self, node, scope): + result = self.define_internal_local() + value = self.visit(node.expr, scope.children[0]) + + labelTrue = self.register_label() + labelEnd = self.register_label() + + self.register_instruction(cil.GotoIfNode(labelTrue, value)) + self.register_instruction(cil.AssignNode(result, 1)) + self.register_instruction(cil.GotoNode(labelEnd)) + self.register_instruction(cil.LabelNode(labelTrue)) + self.register_instruction(cil.AssignNode(result, 0)) + self.register_instruction(cil.LabelNode(labelEnd)) + + return result + + @visitor.when(NhanharaNode) + def visit(self, node, scope): + result = self.define_internal_local() + expression = self.visit(node.expr, scope.children[0]) + + self.register_instruction(cil.ComplementNode(expression, result)) + return result + + @visitor.when(IsVoidNode) + def visit(self, node, scope): + result = self.define_internal_local() + expression = self.visit(node.expr, scope.children[0]) + + labelEnd = self.register_label() + + self.register_instruction(cil.IsVoidNode(expression, result, labelEnd)) + return result + + + # utils + def request_pos(self, name): + if name in [x.name for x in self.current_function.localvars]: + numb = int( name.split('_')[-1]) + return f'-{(numb+1) * 4}($fp)' + elif name in [x.name for x in self.current_function.params]: + numb = [param.name for param in self.function.params].index(name) + return f'{(numb + 1) * 4}($fp)' + else: + return None diff --git a/src/compiler_components/lexer.py b/src/compiler_components/lexer.py index 9c9775b87..3e9e6643b 100644 --- a/src/compiler_components/lexer.py +++ b/src/compiler_components/lexer.py @@ -92,7 +92,7 @@ def t_STRING(self, t): s += rest_data[index] break - if rest_data[index] == '\n' or rest_data[index] == '\000': + if rest_data[index] == '\n' or rest_data[index] == "\0": s = t.lexer.lexdata.split('\n') count = 0 for i in range(t.lexer.lineno - 1): @@ -101,7 +101,7 @@ def t_STRING(self, t): posAtLine = t.lexer.lexpos - count - t.lexer.lineno + 2 if rest_data[index] == '\n': self.errors.append("(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ") - LexicographicError: Unterminated string constant") - if rest_data[index] == '\000': + if rest_data[index] == '\0': self.errors.append("(" + str(t.lexer.lineno) + ", " + str(posAtLine) + ") - LexicographicError: String contains null character") t.lexer.lineno+=1 return @@ -128,7 +128,8 @@ def t_STRING(self, t): s+='\f' elif rest_data[index] == '\n' or rest_data[index] == 'n': s+='\n' - t.lexer.lineno += 1 + if rest_data[index] == '\n': + t.lexer.lineno += 1 else: s+= rest_data[index] else: diff --git a/src/compiler_components/code_generator/mips_formatter.py b/src/compiler_components/mips.py similarity index 81% rename from src/compiler_components/code_generator/mips_formatter.py rename to src/compiler_components/mips.py index 3e186d58e..fbc207c5a 100644 --- a/src/compiler_components/code_generator/mips_formatter.py +++ b/src/compiler_components/mips.py @@ -1,8 +1,138 @@ -from .mips_nodes import * from . import visitor +from .ast import * +class MipsNode: + pass + +class MipsProgramNode(MipsNode): + def __init__(self, dotdata, dotcode): + self.dotdata = dotdata + self.dotcode = dotcode + +# string +class MipsStringNode(MipsNode): + def __init__(self, name, value): + self.name = name + self.value = value + +class MipsWordNode(MipsNode): + def __init__(self, name, value): + self.name = name + self.value = value + +class MipsTableNode(MipsNode): + def __init__(self , type_name,methods): + self.type_name = type_name + self.methods = methods + +# jumps +class MipsJumpNode(MipsNode): + def __init__(self, label): + self.label = label + +class MipsJumpAtAddressNode(MipsJumpNode): + pass + +class MipsJRNode(MipsJumpNode): + pass + +class MipsJALRNode(MipsJumpNode): + pass + + +# stack +class MipsLWNode(MipsNode): + def __init__(self, dest, src): + self.src = src + self.dest = dest + +class MipsLINode(MipsNode): + def __init__(self, dest, src): + self.src = src + self.dest = dest + +class MipsLANode(MipsNode): + def __init__(self, dest, src): + self.src = src + self.dest = dest + +class MipsSWNode(MipsNode): + def __init__(self, src, dest): + self.src = src + self.dest = dest + + +# syscall +class MipsSyscallNode(MipsNode): + pass + + +# move +class MipsMoveNode(MipsNode): + def __init__(self, dest, src): + self.src = src + self.dest = dest + + +# arithmetic +class MipsArithmeticNode: + def __init__(self, param1, param2, param3): + self.param1 = param1 + self.param2 = param2 + self.param3 = param3 + +class MipsAddNode(MipsArithmeticNode): + pass + +class MipsAddiuNode(MipsArithmeticNode): + pass + +class MipsMinusNode(MipsArithmeticNode): + pass + +class MipsStarNode(MipsArithmeticNode): + pass + +class MipsDivNode(MipsArithmeticNode): + pass + +class MipsNEGNode(MipsNode): + def __init__(self, dest, src): + self.dest = dest + self.src = src + +# comp +class MipsComparerNode(MipsNode): + def __init__(self, param1, param2, label): + self.param1 = param1 + self.param2 = param2 + self.label = label + +class MipsBEQNode(MipsComparerNode): + pass + +class MipsBNENode(MipsComparerNode): + pass + +class MipsBLTNode(MipsComparerNode): + pass + +class MipsBLENode(MipsComparerNode): + pass + + + +# label +class MipsLabelNode(MipsNode): + def __init__(self, name): + self.name = name + +class MipsCommentNode(MipsNode): + def __init__(self, comment): + self.comment = '\n #' + comment + '\n' def get_formatter(): + class PrintVisitor(object): @visitor.on('node') def visit(self, node): @@ -16,8 +146,8 @@ def visit(self, node): _salto_para_abort: .asciiz "\n" _buffer: .space 2048 _void: .asciiz "" - ''' - + ''' + dotcode = '\n'.join(self.visit(t) for t in node.dotcode) dotcode += '''\n @@ -25,7 +155,7 @@ def visit(self, node): move $fp, $sp sw $ra, 0($sp) addiu $sp, $sp, -4 - + la $t1, Object_name lw $t2, 4($fp) sw $t1, 0($t2) @@ -50,7 +180,7 @@ def visit(self, node): move $fp, $sp sw $ra, 0($sp) addiu $sp, $sp, -4 - + lw $a0, 4($fp) lw $ra, 0($fp) @@ -156,7 +286,7 @@ def visit(self, node): lw $a0, 4($fp) lw $a0, 8($a0) j end - + not_string: lw $a0, 4($fp) move $t2, $a0 @@ -175,7 +305,7 @@ def visit(self, node): addiu $t2, $t2, 4 addiu $t1, $t1, -4 bne $t1, $zero, copy - + move $a0, $v0 end: @@ -197,7 +327,7 @@ def visit(self, node): addiu $a0, $a0, 1 addiu $s0, $s0, 1 bne $t0, $zero, length - + lw $ra, 0($fp) addiu $sp, $sp, 12 lw $fp, 0($sp) @@ -214,7 +344,7 @@ def visit(self, node): sw $s1, 0($sp) addiu $sp, $sp, -4 jal function_length_at_String - + sw $a0, 0($sp) addiu $sp, $sp, -4 @@ -311,7 +441,7 @@ def visit(self, node): sw $s1, 0($sp) addiu $sp, $sp, -4 jal function_length_at_String - + sw $a0, 0($sp) addiu $sp, $sp, -4 @@ -460,9 +590,9 @@ def visit(self, node): return f'\t\t\t{node.name}: .word {node.value}' @visitor.when(MipsTableNode) - def visit(self, node: MipsTableNode): - return f'__virtual_table__{node.type_name}:\n' + '\n'.join(f"\t\t\t .word {m}" for m in node.methods) - + def visit(self , node:MipsTableNode): + return f'__virtual_table__{node.type_name}:\n' + '\n'.join( f"\t\t\t .word {m}" for m in node.methods) + # jumps @visitor.when(MipsJumpNode) def visit(self, node): @@ -497,16 +627,20 @@ def visit(self, node): def visit(self, node): return f'\t\t\tsw {node.src}, {node.dest}' + # syscall @visitor.when(MipsSyscallNode) def visit(self, node): return '\t\t\tsyscall' + # move @visitor.when(MipsMoveNode) def visit(self, node): return f'\t\t\tmove {node.dest}, {node.src}' + + # arithmetic @visitor.when(MipsAddNode) def visit(self, node): @@ -549,14 +683,16 @@ def visit(self, node): def visit(self, node): return f'\t\t\tble {node.param1}, {node.param2}, {node.label}' + + # label @visitor.when(MipsLabelNode) def visit(self, node): return f'{node.name}:' - + @visitor.when(MipsCommentNode) def visit(self, node): return node.comment printer = PrintVisitor() - return lambda ast: printer.visit(ast) + return (lambda ast: printer.visit(ast)) \ No newline at end of file diff --git a/src/compiler_components/semantic/type_checker.py b/src/compiler_components/semantic/type_checker.py index 3c725f4e0..ff9567876 100644 --- a/src/compiler_components/semantic/type_checker.py +++ b/src/compiler_components/semantic/type_checker.py @@ -41,7 +41,7 @@ def visit(self, node:ClassDeclarationNode, scope:Scope): if isinstance(feat, FuncDeclarationNode): self.visit(feat,mscope.create_child()) else: - self.visit(feat, ascope) + self.visit(feat, ascope.create_child()) @visitor.when(AttrDeclarationNode) def visit(self, node:AttrDeclarationNode,scope:Scope): @@ -298,8 +298,8 @@ def visit(self, node:IsVoidNode, scope:Scope): node.type = self.context.get_type("Bool", node.line) - @visitor.when(ArithmeticNode) - def visit(self, node:ArithmeticNode,scope:Scope): + @visitor.when(MathNode) + def visit(self, node:MathNode,scope:Scope): self.visit(node.left,scope.create_child()) self.visit(node.right,scope.create_child()) if node.left.type != self.context.get_type("Int", node.line) or node.right.type != self.context.get_type("Int", node.line): @@ -307,6 +307,7 @@ def visit(self, node:ArithmeticNode,scope:Scope): node.type = self.context.get_type("Int", node.line) + @visitor.when(MinorNode) def visit(self, node:MinorNode,scope:Scope): diff --git a/src/compiler_components/code_generator/visitor.py b/src/compiler_components/visitor.py similarity index 100% rename from src/compiler_components/code_generator/visitor.py rename to src/compiler_components/visitor.py From 000cb2aaffb19e5674eee11820ff0b48f4b2625d Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 7 Mar 2022 19:38:45 -0300 Subject: [PATCH 56/60] some changes at informe --- doc/Informe | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/doc/Informe b/doc/Informe index 0a0879682..f7eaa6eae 100644 --- a/doc/Informe +++ b/doc/Informe @@ -37,23 +37,21 @@ Cada una de estas componentes será explicada con mayor detenimiento a continuac Para esta componente se utilizó el paquete de Python PLY lex. -# FILL # -Pon aquí majomeno como funciona el Lexer -# +Basicamente nos auxiliamos de todo el poder que nos brinda PLY y las expresiones regulares, lo que nos causó mayor problema +fueron los comentarios y los strings, en cuyos casos se utilizaron expresiones regulares para detectar el comienzo, y se usaron algoritmos +creados por nosotros para formar el string o ignorar el comentario hasta su fin, siempre manteniendo actualizado el número de línea +para poder brindar mejores mensajes de error y poder pasar los tests ## Parser Para el parser se ha utilizado el paquete de Python PLY yacc. -# FILL # -Pon aqui majomeno como funciona el parser. -# - +Usamos la facilidad que nos brinda esta biblioteca, y usando una gramática generamos un ast de Cool ## Semantic Checker Esta componente se ha dividido a su vez en 3 componentes principales: - Type Collector: encargado de recolectar los tipos. -- Type Checker: encargado de hacer chequeo de tipos. - Type Builder: encargado de construir los tipos. +- Type Checker: encargado de hacer chequeo de tipos. Cada una de estas sub-componentes serán explicadas a continuación. ### Type Collector @@ -63,7 +61,16 @@ Durante la recolección de tipos se visitan todas las declaraciones de clases, s - Herencia cíclica - Redefinición de clases - Nombres de clase no válidos - + +### Type builder +A los tipos creados en la fase anterior se le añaden todos sus atributos y métodos. + +**Errores detectados**: +- Mal uso de herencia +- Uso de tipos no definidos +- Problemas de nombrado de atributos y métodos +- Redefinición de atributos +- Redefinición incorrecta de métodos ### Type checker En esta fase se evalúa la correctitud de todas las expresiones del lenguaje y se decide el tipo estático de cada una de ellas. @@ -75,26 +82,12 @@ En esta fase se evalúa la correctitud de todas las expresiones del lenguaje y s - mal usos de `self` y `SELF_TYPE` - mal usos del `case` - -### Type builder -A los tipos creados en la fase anterior se le añaden todos sus atributos y métodos. Además se verifica que se cumplan los requerimientos de un programa válido de Cool q son tener una clase `Main` con su método `main`. - -**Errores detectados**: -- Mal uso de herencia -- Uso de tipos no definidos -- Problemas de nombrado de atributos y métodos -- Redefinición de atributos -- Redefinición incorrecta de métodos -- No definición de la clase `Main` o su método `main` -- Incorrecta definición del método `main` - ## Code Generator Esta componente a su vez está constituida por 2 sub-componentes: -- COOL-CIL Converter: encargado de convertir el código COOL a código CIL. -- CIL-MIPS Converter: encargado de convertir el código CIL a código MIPS. +- COOL-CIL Converter: encargado de convertir el ast de Cool a un ast de CIL +- CIL-MIPS Converter: encargado de convertir ast de CIL ast de MIPS. ### COOL-CIL Converter -El lenguaje CIL utilizado es bastante parecido al estudiado en clases. En esta etapa del proceso de compilación, requirió especial atención la generación de las expresiones *case*. Para ello se requiere ordenar las instrucciones de tal modo que se asegure el emparejamiento del tipo de la expresión principal con el tipo más específico declarado en las ramas del *case*. **Errores detectados**: From bf0c3a661136a95740292407d45b35e1be7a54fe Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Thu, 10 Mar 2022 15:22:58 -0500 Subject: [PATCH 57/60] Minor fix --- doc/Informe | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/doc/Informe b/doc/Informe index f7eaa6eae..7ab093610 100644 --- a/doc/Informe +++ b/doc/Informe @@ -101,49 +101,3 @@ En esta etapa del proceso de compilación, requirió especial atención la gener ### CIL-MIPS Converter Para esta fase se ejecuta un recorrido por los nodos de CIL, creando las instrucciones equivalentes en MIPS. Como apoyo a la hora de generar las instrucciones en MIPS, se utilizó - -# FILL # -Aqui habría que sutituir esta explicación por la del proyecto de nosotros. -Ya lo que hay de aquí en adelante es la explicación de otro proyecto. -# -### Estructura de los objetos en memoria. -Determinar el modelo que seguirían los objetos en la memoria fue un paso fundamental para la toma de múltiples decisiones tanto en la generación de código `CIL` como `MIPS`. Los objetos en memoria siguen el siguiente modelo: - -```| Tipo | Tamaño | Tabla de dispatch | -- Atributos -- | Marca de objeto |``` - - Tipo: Esta sección tiene tamaño 1 `palabra`, el valor aquí encontrado se interpreta como un entero e indica el tipo del objeto. - - Tamaño: Esta sección tiene tamaño 1 `palabra`, el valor aquí encontrado se interpreta como un entero e indica el tamaño en `palabras` del objeto. - - Tabla de dispatch: Esta sección tiene tamaño 1 `palabra`, el valor aquí encontrado se interpreta como una dirección de memoria e indica el inicio de la tabla de dispatch del objeto. La tabla de dispatch del objeto es un segmento de la memoria donde interpretamos cada `palabra` como la dirección a uno de los métodos del objeto. - - Atributos: Esta sección tiene tamaño **N** `palabras` donde **N** es la cantidad de atributos que conforman el objeto, cada una de las `palabras` que conforman esta sección representa el valor de un atributo del objeto. - - Marca de objeto: Esta sección tiene tamaño 1 `palabra`, es un valor usado para marcar que esta zona de la memoria corresponde a un objeto, se añadió con el objetivo de hacer menos propenso a fallos la tarea de identificar objetos en memoria en el `Garbage Collector`. - -### Definición de tipos en memoria. -Un tipo está representado por tres estructuras en la memoria: - - Una dirección a una cadena alfanumérica que representa el nombre del tipo. - - Un prototipo que es una especie de plantilla que se utiliza en la creación de los objetos. Cuando se crea un objeto este prototipo es copiado al segmento de memoria asignado al objeto. Un prototipo es un objeto válido por lo que tiene exactamente la misma estructura explicada anteriormente. El prototipo es también la solución escogida para el problema de los valores por defecto de los objetos. - - Una tabla de dispatch que como se explicó anteriormente contiene las direcciones de los métodos del objeto. -Existe una tabla de prototipos (nombres) donde se puede encontrar el prototipo (nombre) de un tipo específico, utilizando como índice el valor que representa al tipo. - -### Elección de registros. -La elección de registros fue un proceso que se decidió optimizar para disminuir la utilización de las operaciones `lw` y `sw` en `MIPS` que como se sabe, añaden una demora considerable a nuestros programas por el tiempo que tarda en realizarse un operación de escritura o lectura en la memoria. -El proceso de elección de registros se realiza para cada función y consta de los siguientes pasos: - - Separación del código en bloques básicos: - - Para obtener los bloques básicos primero se hace un recorrido por las instrucciones de la función marcando los líderes. Son considerados líderes las instrucciones de tipo `Label` y las instrucciones que tengan como predecesor un instrucción de tipo `Goto` o `Goto if`. Luego de tener marcados los líderes, se obtienen los bloques que serán los conjuntos de instrucciones consecutivas que comienzan con un líder y terminan con la primera instrucción que sea predecesor de un líder (notar que un bloque puede estar formado por una sola instrucción). - - - Creación del grafo de flujo: - - Este es un grafo dirigido que indica los caminos posibles entre los bloques básicos su elaboración es bastante sencilla: si la última instrucción de un bloque es un `Goto`, entonces se añadirá una arista desde este bloque hacia el bloque iniciado por la instrucción `Label` a la que hace referencia el `Goto`; si la última instrucción es de tipo `Goto if`, entonces se añadirán dos aristas una hacia el bloque que comienza con la instrucción `Label` a la que se hace referencia, y otra hacia el bloque que comienza con la instrucción siguiente en la función; en el caso de que la última instrucción sea de cualquier otro tipo, se colocará una sola arista desde el bloque actual hacia el bloque que comienza con la instrucción siguiente en la función. - - - Análisis de vida de las variables: - - En este procedimiento se computan cinco conjuntos para cada instrucción **I**: `succ`, `gen`, `kill`, `in` y `out`. `succ` contiene las instrucciones que se pueden ejecutar inmediatamente después de la instrucción **I**; `gen` contiene las variables de las que se necesita el valor en la instrucción **I**; `kill` contiene las variables a las que se les asigna un valor en la instrucción **I**; `in` contiene las variables que pueden estar vivas al llegar a la instrucción **I**, y `out` contiene las variables que pueden estar vivas luego de ejecutada la instrucción **I**. - - - Creación del grafo de interferencia: - - Los vértices de este grafo serán las variables que se utilizan en la función y existirá una arista entre los vértices **x** y **y**, si las variables que representan esos nodos interfieren. Dos variables interfieren si existe alguna instrucción **I** tal que **x** pertenezca al `kill` de **I** y **y** pertenezca al `out` de **I**. - - - Asignación de registros: - - Contando con el grafo de interferencia, se asignan registros a las variables de forma tal que dos variables que interfieran no se les asigne el mismo registro, esto puede verse como el problema de colorear un grafo con **N** colores siendo **N** la cantidad de registros que se tienen. Es conocido que este problema es *NP* por lo que para asignar los registros se usa una heurística muy sencilla que consiste en lo siguiente: - - Primero se va eliminando del grafo y colocando en una pila cada nodo que tenga menos de N vecinos, se nota que todos estos elementos pueden ser coloreados sin problemas. Si en algún momento no existe algún nodo con menos de N vecinos, se tomará un nodo al azar; este proceso terminará cuando no queden nodos en el grafo. Luego se va sacando cada nodo de la pila y se le asigna un registro que no esté usado por alguno de los nodos que eran vecinos de este en el momento en que se eliminó del grafo, en el caso de que existan más de un nodo posible, se le asigna el menor, en caso de que no exista nodo posible la variable no tendrá registro y su valor permanecerá en la memoria. From dafaede6d496cc5c34ecb5850e369e2ac3dfe67b Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Thu, 10 Mar 2022 15:59:45 -0500 Subject: [PATCH 58/60] Add informe --- .DS_Store | Bin 0 -> 6148 bytes .vscode/extensions.json | 5 +++++ doc/{Informe => Informe.md} | 24 ++++++++++++++++++++++++ doc/Informe.pdf | Bin 0 -> 29065 bytes 4 files changed, 29 insertions(+) create mode 100644 .DS_Store create mode 100644 .vscode/extensions.json rename doc/{Informe => Informe.md} (68%) create mode 100644 doc/Informe.pdf diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7cbe275046a42350e05301fa3e51caa9dcc81710 GIT binary patch literal 6148 zcmeH~Jr2S!425ml0g0s}V-^m;4I%_5-~tFbB6UFQIXcfj3xyd~=vlJA*s0a_4NWZ~ zdU%d|kwHY(aHH%j%uJDYGRh>k@o~Ffr|E7bw^h;#@Ihw#xlK?3DnJFO02QDD3sN8t z^7Upx&%{Te0#slb3fT9dz>PK8g8u11@DTv)QFg=HX9=)a0j$XuLtMpWxr-|5*!DDnJGPOabkW z=i>n{m1pb6>skGhRa-YW=$9kB{RAMfqj(EBO6k$3{W&s5BqBR1fJ_`%TF(n3(j4nQEt z0cHV%Ss<(|U=|n~7@|&x$-{$*w9r3A3i%zevlSA=EaYS-qF@K~#AH_B1KHWwpMH@7 zu`scKF`4yrK&(tG0A#-NE1#GG$Uw);_KZfy))d4nZE1o0#UA>dy#}+aj-4IS#sb7F zh;%U4L&}TrYyH5$_JfE8#H^~O4uU{HAWSw^2osFu^gj@YI2nSJqDSXkNtCS|W{cXlsn zY+;JYERWQ)18G3uz|_NG(4W%@1^y~oZ z2V{VlmE^@RPyc}K8rj)d*>W&58yedg+3PatS(-CTTG}#7=~x(A+97Qj75JF-EG^9# zfd^K`W=I=GVAZfP>zY~WGMnqz0=CO+gS56cwn3UBE$nQW?40b**3mCp2mdg*-+=rV zV`XK5{~Q_=0{y9IRtW2NO@ctsU)K8nX2`ZSdcf$7EtssF|1sJhhWKl+vO0!<8<5qp z0rUepT_o~=pRlyBJ5?75e7eGb26?2drM-jvn%C`eg+atU%uxoqql0Yyc<!5(*bMNJl=FUBp92nM%GieYC1&OLX3jk-1O!?I7LB{@cRt7xI&uZ^b#{rrA3w zY5Tj#VUX7C`!}Uu?NvDKRUT@)es&vm!~V8<0$+6>Q`2diMbvv0Jor?Q_Q_t&Wm3zi z;KPFivTv1#lS1o^c7sxH?$x|5DUGsjH#9CT@G3~?Y%Trlf1k8=S-V66%ThTb=N?^@ zqHbO6`YwyDijf@KO#|7Z!?`hLot>Mc9c{S{-UZW6%SO`hl&Pz=`%Cv`GFY}Ba@~9s zGkhx@D@#kQPuu7ArRysB*T;#bdUl>Hw#EpH=b+b>rQHj1l!w>tWOP;TICPn0gNxbe z{hw(KTbQe9qBceP+X<>fMd3izZ!8?)=HWfvCLR{}oKdRGp|@CE!(>mL z3+Z@4iK~9N&%N|%r{Pg8_HaZWEhQ<)o_HKjN8@PYA`Q`OO+|O3y3vL8r z=-e5DqLT@_l*TeD2|EHMFORv@+#NCBi@!RcyY}ug^6G&2ynGce!o3_LV&@&H9WVL(bLUiWhjNY%5DlwFvRP5N3&_s2tc5w_o6+3*0 zN3(oIislR(&d$TaWafsQhOZI$c%dA)t9|~9K{SLJekH(_fsi(UPlgUIFPb?hN*Pq9G)DKhJZw-^OQNJ$JrJZGvwGWpy;4WP2=>vKG5{9#-hli; zQS(^wNT&do`9d*V(mpWa4jVezMmsg_iZoF>A2EqduOuq z+tJ?4X6LuVBB$d_r_IcA7e_L#?_XlicVY53BRfKzgC-(TaW%u0^+b%OgB_6a? z*K&6f#?`CY#mir4*9d}aJ~LQLCh&zI^hh(R9PbY2-ZcRu^|f2D?VjBnazLa?$vF_) zRi_IYFBuUZkX&=N(669{7n0cM>L_RW@_@Z;?G# zd$9^7P2G{%QvwV3SYR*@4Gt7kRo!eMn5AeK+{8BJ&$A<`_nkb`P+NGmyk^(k(zjDi{&0E<<90Lh=P(P zc!B*P&dn2Sgk?`YI&+rWgXP(hgTdL7%4LZVxaD`W83@aQT)~{T(GI!VAbm*Dm{IsR zoU3%w_*U0cmyD5*WIdy}8O#ksm(0>7Y0_@KOBFN+FCu+HVE9@pM4(}U$%Ij^TP)dk zFoDW!j-0cahL#J7Au+_fUR&lN3>O%!oJCVe-K2uD4!Q&e_CfUO0FRlK4{xe|2oLhV4Aj2Ua;`fBa9q}3k#?ycF${g8=fRz zz>!0$27&5u&?kMKk8QQWgCeLT*SVI6-t>?z8XX5;kXdPA-E zkBR!n{qa;nu*aJoKlXg*GXA`1sVmll5u7g46|d$<$uw34exAdX5Uf-dceAHUT`2SuiF9>#_ojYV=B_Fz}a&BZs~1q$@STaWbL5&`wCEZ-{| z)%;!J6j_)%@<+roL9T|v_yYX`*!*yO3M9H+K@2Etp%G zw5=X72kg8?NxrBil4MUbDf4xrI2ntC1Vx+Ik4$hhcs0B@*@i?n?=5H9KBr}8ut@Og zLIguRKgvkTE|mvD@k_rhZde5$ar7>6G^`(+qlR*lW^8{kt{aaKPc<&}>H*aSw%cLH zoQ+ydn--p+qab%rG*PXWFRzDp4xFpG zVV7CZMo>PdrlJ}@&9%}C{>Z;YA}^7Ude7@{%Bso?6Se21s6M<*HHgHE@gs{}BOC86 zM$1s>7vbkZH?PQ1mE&D;OH`vv(vOqg6TeRmaWibe*R^}>J8XQvN3^yb_1&_^M9ng9 zo2Mk<;SH)-4s=xQ(jXQoG^{P{iLs!#M${tN5!b0uOX3afH?!I)emod^urZB%4Y33n z!_5V*dVwb!%%ON_Phejl6Wnq>OEZ#Xx%!3|eIZU1mc2X$jCi*=KOR*!I0z{=afLjx zEb;fTrnFraZSjp0_q5aEudFAN=kz3gwt|z*Dyl5J=Q>|sTY<~0)O(f=1Wk=~zUZ0=k`us60x_I>|&#Q|M+n1!& zi&Sa@Fp5lE{dD#dS*o=^%`9qBxMEyI4HY3`zr%O5Z8!UZs-C~&G`AxV256<$A4U3vA36pq+nYO3;~E5>`FyM`XhGVx^ua`&L)V+H-H;+0JmE1@XdPJd*pHrU-2= zrA$GwbIbF@)X=9MFcvG}nlvS_R}zI8xr)$bDhZ~7$<9Z@g`VQlqL#VqB(j&eLI==V zH{LFiYS?OG`he1bf4gd4DCQT1ZAmxx7*^9b^2%rhEPuU`6_?);Zf( zIbycREbeO2ipSWc`L}MduT-j6_GD{m6qdlIH`U%ewig!c$;8#7#$}mIbp%rj%mm#K z%wBBQ^lh;VQ?g$*vrj3ll$lF5*GgOIQF}?!D*Um^({jB2P14Sb1Ap&-q>P5LoG zA~sXdE8iJalCWvigl)+i>Hms!&Q@cAH`J6#o8#*G#-~Z1;-m5Ew9!2sCb@D~%o^BD zX8k;tu=dJf%q}f4UWsd8ctszKQKttv1T(icuDFrSY*1a~S%HhJXd$*Q2z^x)S;?wf z-dleGPYkvV$R5*I$pKp=MkI&Y25e1>!<^@|rrE+nFE`DiqrWU3Q|$9eCZ1P=b_uHX zvs|MjaZj%;m7H> zY_NA2<9H+dK%2)3$~h>X*1}#WR;Rl9!bL}(ywzILq`MNgjd&q_ksCK0(|$4?tY$y{ zJkFG^B0Qh5fSKumC0b0fj5Vf(z7<5ji<6AG0V+6yu@%nPTIcPXz>$-BnV|m_NK^`4 z@hS%yvu?+%_~j=LHHrsIMMgKEv!O{H@pz;j^Y)eI14}$Qvz(S+5TORYB{P9e;4(|Cg>zi2_mL`_f$-2r|jqqe;}Q=jBa28#_^8Hw>LESsyr&xo6gGlgEz)KwE}3L`4C)0Q4QU_ zPWU|Oebr6XDPkL;S0HDi)Z+$qk1%-1^TsdL1gPvO={S6i`>}rG8;M-6vU?DS7zmBI z@|2Cc|InMTckQ8k(Gky3YobRw?~^NHVJ2L zY~H)V(Sqrb&dA6etq1=3B1F-#CaPqPWC5#(DXyoHDD?32NEF3Y^?yd9^4PI(N?)@I z-;}Q^%&y55?6IE_pUh+BF~`$WtcA*}!}e;-*-C$p7!jcka(<5(h2kj>9M<+YJb>$5 zYrVeUn?F2vQ9&sT2*n(*sCK3vOGF%Xt1n2(LLzo5d!t@=utfy387-yVUk-C)L`u;)Jbz4j@=t09h?(iWSm%^FD>cc&~b?e>7j0zb9 zr^%b|QONJ9q_dFaX&4g*hC+VicECTA5Ujr?cM$9>KV#g#k~`p^Nr*pa0lvRwfWSYq z55E(^VSh{2fPZ8kG=8Ur!GGl!ehG*C9=(6?Kt+O2T0m4r{s9JrTEY^%?$bai@2x2{r=l@A*3}XEr=l+e-6vTQS^8Q^P<{;K{oWG*p&|m8OEfdOz zVt)Z`AjrAWfLmc>8vxMCW^%$LjJQJ*nSuCQxE5M0^G{lARSIqwcqFMyIRhT7-`n|xk3L#f3D%*;QjDcf6SUB z0K^IS*!&L_hy1JP^JVi>^tm2?6aB;a{UKWRtaQNke<9rPuforl=TG71YWO7_daB2N z8IB@gmsWsi5Q+d`qh@D|=*&w0p^2Z&|7EA9e***knPU6Cl+POe3+cLmNf-mtPYvSF zIrz_#&HpO-=ZZQr-m_7kCGUO!Ieq?L0MP?VGfo$(>Hh+VzP1+-RV;)AlD8Qkk}%BJjFcwabgQP`>FW5-vIww z4L{`km&Fj!bHDXlF$C=N=Mo_Idocv;T#^5MF~nKFbH8y~Z1MknF~r%xPVs8|Dt|cB z#*Z<4FMoiZTLLi2|6TdRNbpEAzT1Gx8v7HN**H-BuoP$g1m(&@rzdWgHy%1!sxA?6 z4&j7%;!!(vioTGR;JBxZpw53&3gxCs80)hyP;h*Fd_=v!5Hh`Tvbox#a=3atr&O8W zR{V{5=*YR~@M*5vNT-;d%^~~#!N^y3XKgoix34Ge+S>zewckW`7wW{KkMa(`#Z0Gs z`|7?|bDYu6d{mk(RWm;NHgas>fn!~K@vD9%)8WiRXO5%F{h1V%&&SmJrOv~ZVm%CP zMWbdZRo{-=J2J+gA(G3^Gs=`&WtsW@9E=I=bGZz|y~TaAw%WU&!|&I+Ym9B@IIVES zH(obShDz;PwA4LTJs#vf+U}OpiZmX1u|I38fE)ozED};m)XI2bxGPOssbnfg25BF2 z?2V1J!ZLP94DWQ2;qh#`-No?KgcbZxrlZz!Xm%Qy$mS%f$=Vt3{n_8+qoGfj@o zeXetr7_XID8Gn4ddH;dC+ri}H$269osaMCT$w*fa60_4og}sJM+f$!cF)*YR(26r$ z%3PYR3ol*}dh)DAM|sCcMDlTqz9eVa#rN7apT^ckZwWKIAe^N7u_A4%ZIcl-A{Xy7 zr@l3GxWMzQVuVWxH^j!9uGZ5KH^83plCa|KROxhv8rIHtFS`eO24@?p+^kF=;!1cH z-R*{$N?JNSW(hGg07>{+$=v2xrYE+n7iJSU|nR<+A~13*(f4m8I_b+t531h z+aSWa-D<4msvq!$- zbGdZ}rkoiX=?0isS+2>bXN*`X*P}6j1GzyD0lfkD9eCTsxn%m{H6DCUw&Sld9M(?Y^7LXH^28)mpoCsJ@7vR3u3i4!(V}GIKuO2CgTCo)EZZLAuh( z=Jwh-Y^X}BCF>=z(0Wt$%?<=-$FnT|E2?tAH+&jQhLn%TN(oy*kFz_IO$yr$6Tl^6 zx;E^Rebi!-_Q|xFEXLu6VvYlY8?h!2&HJ27ER(8=blny)_Lhtqd#&^hnVAyq7ZP&T z4<>xObfl4_`?d0A?8=Qna|6482K#e}DJDvtV!os!d$%cP7iVsBoznvRW(H%B)xm{>3lbZJVSig(4a zQ_$q;OUu^z{aMcf^_#R$U*vm-mf3t3f}%^y#& z6VYzJ#F*$KFM?yW1w=1*4<MskJPZ1?OI!eUgER(Z0nKj_f-_)EgjTpIBHQ83Jrhh`QNgJ_`RZv&k*BySb3Pxv( z{rMqEP~mOaVFSh<58AAaP1qbNKW=|WD)J+^iI z-dBZ33#>gt@ON__yiNAG9>_}GifX#{P^2*Iv5`1S2y(=*YMHM=DvF(a6e{x&pJKCb zlQ`3W#?_e{6^U{~G~`pu(hgUY5e*BkBB%4iE56}JF4WI}65i0)Z625h_&!cfq-h3<%vSvCZ?9abx-qb? z-R+=l#~f>6o=h?pWlczmIuO^zt=``^ew4>aabMQlYaeXq!h$QWgOl)tFm;Ph?a7O^ zVXP?&fO+6zc#^AjdVor zB)pz!uMRQ$e8rQ%+fBW22CWQL+uvH)O77XK6rr}Ncohqa^t)6Z*aW1ieGpWi2CzHY zklj7uv}a{xarSy&m(sHpWy)rQtC_ocmn#Qr$MSE$5Dy-jXV>g6zMWB?xq>4^nApoc z@j^QsUL5+aFVq85bA`Ufs1GMzdn_BTcU>kZ>uqSF>?;Ht*D8 zKQWlxnX0_Dy5Iie|#^t(aW>}qsbRd^B$Bs9=o2+$odtIBjUP40~0w*$<^5C z9<6ACzDgdt3iLQd2xC=yx*BV#_TH0WR_5kj>DmLYqNW##_%BmTYETvtx4rHT2{N>P zZKRuwt+aZqFT5Bkg%X9c4YAehe}r*7QG#7IZ&AZoKIY2QLyBCR??`VwhfI-uM`n~Zk$z{#>ApSW#}XKVF_dysYHW?N}uzNoT~vb z7zCOInacW&FAr-fC`x54WvL9am)x_=CG|77Br-urkYxX{&(DPAaje2bk(5_zaCVyY z?EJNTJJKXiYqgfv17~r=>NH8}F)^vi0<5c9?#n0?{t8dmtv*WVp`)zZ&$HuMSWqUV z)@d9Lqv`T4mOYKM70c{7bNYN2BEE8re9mFRdTl9uOjxU7rJz{;G{CGDcM7bV<{l^@ zRr>zx^={JC@SV%*%O)ikf^RuTS>1w(q(jqA?UrT@z{E9yaD@h$!1A-jD~Ws0#}L$ny(ruD|>L^ zTgbZ^FOdQ4RT+?HX#Ms2HFGr*S$bo+-X?#T`w-D38dgdJr>}7r1zBOAum!(xyY~2| zu1lK2lykz9wlY=mbd)36x8ITPab-;lW(VYo$TC_hT#9^27nnd9$a%S~Z{z}MWXab! zBg%AVKjHS+dph@8sS?U*u`c*K1{*IobS2312|DFhG#?4gcB;%OjEiR;<`afTzoL~b zm29VsTN^E2>(dVt5qxvk%VRD|T#~Ds>;s1PHpx(8>%SNESE69p1ZEIR$)SLVw7KG59Nsu_y)ohN<+#@3K~ zbt2KiSIDlWh`P@C?W@ULI^B*SOQr%gO4F zKO4!S#p%qpAD&uy>j8w^xKGvZC@NZY+m`My0h%J!P+_P`mb0 zeD!^yOj;#PDl)afMrishf*4{=Hvw^_&SaRZ|Gug7p{=9) zhg)i@4~~3iqwkks@G5C4+~W&=AhMBA2*I^lWKKx?l$ZIR$F3I%;j& zS}c5#5;{yBX_n+WJ7!;k7dHc!+P*4HLM{u^Pu_JCfq&^JUXR+IWvP0*7D`u`l)1yA z-%dRoMEEIM+1t7C)u3Vug)lB_9KI9I^JI{w<69?NUrk2LXDT_*$hd+?54HPupVYLl z5xi495!dpJtgc2b^n3DQMdiJX5PGF6J>waA>nW+EB0p;qjP8CM!^zbmtVtLJ^pEA-uDlE3iwI);g@J(WwxYnmd=Pgi`c*koUEwkA-c6g&8q#&G@EMhI| z6}gE>Am!IEI!UHbv(I{JT zK^d8QkH}4_O?8_b@s+JnBwGRo8}Z@r@-dBwe)LJ0dQ$*{8&48n~sq=Jg;`I zScXB4cuR#n-o5xx!SIe=zWy+;_mK)&PDSi+M0aG<=YZD_xySJ`F^!VJDJ=vPxu}yC zU4;ZH%ANiGYW@_kSAFY@&H^TtWHVV&QL;t3vaN@^#sdpR7KPmRJyV1kLs&BK-!ILC z490*vnNV35>k4Z{BS!4+^jx?`uA9c9YQX3I#I}dq^5Eg;UV<-TRYCZ#V~MqnhEi?3wsNSG6#MFD-OmyNsPlVGo|c9)&Pe z#X^D$!j@T?Oncb!C?zo1s|%H?B^dFWU=1Q-`U^qqFV*+=>*IPQ8Lg~7%l3|5IvhMy zuz7Wj_-RGM)|mfLS++NaNMocoYxyn4m`T4q_Qno55|ZMzk<0fz3G<1NSQ{i4P#q$! z_iNP~7LQ9W^ICCA4f!0)bHfvZk-VFX*IC6Ax+%gG>^JO zDc><#($#E~=!N>Oao(!^Ae)tQ$@>u<5&i?4+s)iKDQ&M6`Nh&(HE+)bt0(#_*h(xV z(y9|`?)LBxZ!8gSCaM`6OfVTqFl9SFW~qg)jD2XVy5i1joWxdjLC;wv(1ET^AgzM{ zD|vrz^1Aws&B7>U{3e>-T)3uyXC9s0<4>1}270yq3YBN?Z}u{BxzG=1IQ!`Y^dy+^ zJPW@;R#X}8SC*` z7y`Q+SpZgiwtA-e+BMTkUdC8ZqIvBmQdn#YbRC)=Ge%PA6ycpuZ zs^}f;d81@%LsM8IkE533Yp=Di2;(&PTg4R;kt9TIj8()S#a3|w3gi%u6cNX+4SJ*7b69;W_lK?#s`h-15V7ZZdrb;V%nr= zY`IhLEvGy!-#EE#dD|(8|MJ?*hofp+H5TMb4DWQGGs3>zCFALK^EEkv3-{0s5jCR-u)pVrAu@3cuOHZKs;h| zuRu=o>8oB$Mrd%*QM%)z6OU6+Sm?iZJQ(4wAVn{YG*@a+<(D!k#lnqC( z-&of9A}}0+)owuIR&j#My|+&-ldylal>gR&uKZWt#LM0HdO7l#WXWDQ+J!r3%SA^# z?dQuYKbcP-8fu`YG(WzGIKX(jy*QfwEKp|J?1JhbJsx&z4m&i-19uF%$xi0W!G0Bw ze z78;GY5T`}5u%HMjcTusk`}V|n+>O)WLnHs=Z^cKFLe#hDnU4EaFWiV~{DL+7Y_X#O zOQyuAj?nGPyx?K=QD*@(X%fzzW;+?&^6+gSzF95S?4*X4muSKoW5zt6+mmYwF=YpG z=G%JDKYZ!9D%K!DmT?J*g!0#ZMDyU|^iNMS7s*cv;BSK4zq{7r?hYzWi0Nq=?wVL@ zrm#gJ`9}Qk;Q?e8DPCyEGk4;X!>CgmCfa=?EoG=O7!xBZJtDmyzaa6&TV>@1S&VqQ zl5_~gsOp>Dpo2$6@t@0U>6tn1y{;5+D&t@k)x@NUVAXM`nd+egkD*BiF`p& zn}gJT<7ZQ%7_H2Wq2j-6BqQ_h&X?LjLDpnaCyRK zK5@)@j#QlxtP805$|hVlI68-*R`MFh{`(J0q8~TyPfXtNbe>?NYAh{DJ}Is;U4K8K z(BmQ{M7^((QhgsXc8Te6rQXX0x-LhVaY$%%<;$5687kT`$5Ae;^qe~cUpiP8E4?+x zZ@AH`V?-+!O`~k)C!yO0A-&T{2d1@Bvk$%qMj4B0!}c|$Zp6xtwruq_sVjtMeW@C+ zN*y}No7Tc!=uWSfI?+_4BZkOqqeR|F_x5E9^>9zj`+yxG*2)mm>BdepX;H<~9Q|!Y+0rEsXe*o9KW?FSH%}3ZBgKKm}5`(ZMBP z^_uB*6$GNUFaKot;HCNo&cVZLWOuX_s_zku64XRjRy<^7S@1 zUFDqKd~xR0F5i!oad%LZ_cAkP4KT(oOe|ABBHL#8@X8iDAXbG<#&k??2yz$~!{pHx z4oV6rDhgmS^1~v#XfZC1KxCAK(7VS*+7ur^iie->rC*l`Qe-Sq%@g7+j19a3)nJvL ze~5wSL&;GRj$|%VB>#Lka?M9~uxPOeLY}I$FPEc(#{YD4lSrghoGQ6KF?U*jTdO|( z31aNi@WV}?l?e8s+ZCzrCJKVY#KgC>afjIPE^oT@GjmN$UE4juQaic8K~*keG?A=T?%(b{-xxalToxH*p&yoQ~xc?NJzw zPEd>MYfbA1xWCNRG0(WUcZBg@kDY!udg2K8pPOPMaA!SA9CF0VN6 zG;1w}FAPVfb9dITI+yIL#9CO2NxwA29^KU4S;Yu`nfX+|TT#VuPVz&U)-v(t2D~wt zK33>so4myMgo?;EANHN3UPW&QI^q|~0ypj@`PYSa4Lf{o3GQg5LQ8kIIx4SHV9&hC zvp1%Us;CkaU7+#unsm2!I#ONh(N}I%=4H=vTf?|}&xb#=3J}$?yP^>?l z$7pr&+K7d%t5RC^nogXG1!Bhsm5J>WCtq>($;<|A^t4MG%;&NUB)94t^((7@% zqU};Iyg2`xOpF``s3uB8k1vcy=bWgyMkWf9XgAIf7B+igrYazB(4%75T?k+Z@bM4E zY`8g@ZaJ(D*aiPA(w5o?*C4ZDxR+;AD_-AS-lj79pgq`=|FP|==7Ac&>*h(hs>vJq zcz^njBKs)wH@!&?qPNxAE~rej?&<}g?WTJUT-8l3RiTRU z{rez(xpnVNA!_2ts90f4EOw5qoe95UyJpEdT<#Uq+t+ptkuMC#9luCn7FQJ&9VQem zJbjj$E)^T3fqf4yvUMvU(aCDyBgxiRJ08d0C4oB&S2m#^tYz0q`|+kMY#FsKCM_9R z7k&`%HUUTWyn3!5IPQ?H_tEtBQ3wKLPi23qu=3I&VwSOQE~2)(O}PJ{LtMGV;sHsUO6q! zwwI;y-*OE|_GH>j`KXdAayQ+il~_vCYnMED>#$OKLKq!nZX|Q5j%eBXFiXhc zex=2s3fAOfMC{>qr_=L0>(;l5n!;vq1vGC9i26W_e4Fulv|RFy>bRUPC%3n9tn(_P zi%QE>eRH>La)}KD<%YZ$ zl9pnbZB>htKh>o z#m(g+4CjBfrt(pZv3x#nw@FkzIULToOdhQ%xI-^m^6;>6ys(ior;@`{P^@jHyM=#^)$diroaz?o6N zk$#Y;P0l(%5At%oH9r1LoACbYER&=C_@|hr4?jvoe#T^~q2TE0<<4F~MweR6blDkx`cmg@14eE(*}ZHE|?U zzD;3>oDsMv+V$;O$yc?gqtCAvXGPR%j&v_#g{w>S5x-r5+_X;$(7v%K_>Kro`B*fm zB@%Cu=Q{kI#^WcJrC0Lg!AU)rFY(7#LPZzp#dk;{Q-0B^?|q zVYFNBj2FmRpK{chL!wo<*PN2+pSkXzmSgNY_4r zz|&nBXX_w`+kzN;(UF7#IkoStP!y{jIM8b$k6eUA1|0Imz!#wzs5?{%?@e}x>TQa{ zjbX+1%UTg^MT|5ZXjP6pyW#?FPJ+fgN%R*SmfdGI^0_Jf{5W^XO{i(fmcLwlXs?L# zi1S|N*Ef~%{;dHOiwLG&%{rYqHV5~jJ<{{9P#QLR{W0SLsEvqRe}`I9epqA_<4cMhg33q|UKc@MWX ze{7S!tD5_^3aDOQvj{;5B*^bch0IN__iJ?ai+b9P#}uDwHyr34 z-zV{WDuw|KN+z!MnS4_9j>TOzuDMvZXgTa`N6{yYgWhm9dm@7nj~wY}2c3*Tt2=9NSuwMQjRF{MEI_Zr#3;v%0j})~Z^1-O+0ewr5DCQp?b(SRPa4_%LTp?x`Rte!wr zFJQD)62o+V$H~>cVfV9V%0`K;AufrgN)pS_AbpG+*ulExj;PwzNv@?^DLRoKI;7iZ zt4#<#xOlG`iWab}_a^jkLp0}m(QdLGgUP_hgmd1jx=VX)%5X~$p`Di*d7;PnkEWLI zW1`lNku`97?g&^gZ^I7b#}-ItCAQoSICScqr@E^r0v$U%Ut131P24}3VCs+<_F}(? zjgd#@Dx%EvymUi6QI5`>fcki?$bXUMQtz|GISDa@n}^r>vlg01(ROWYpWZ)+!yj09JY$sk|$Z8p!Kbr#?JS{=*XJp z6a~A*FQv!$zKo=7qvi_0rf@`SpAaULK5sM3PnP+3>SDR@ip~m0 z=lY5(%7eGNYje(gU#Kb+DU;2-4 zPz`VxtdkZ8(^2%QEygw+GOIOl1sA9_5$IxIkbFvzy`a0^*|hbTsyY zezm&-UfWG_3_P$e$2PiebDZS;Sl8co->X&#p6k`H?DJPa=ei@SjC#WSHjb)QwIna| z#jA4Z+Y@uE1%WW4fL5H=y;j!;Guaz9$a^k|Ig+qmA`>F)OMCqH^2=_7aBzucTj#t9 zPLk8a&uXIHlw}ixUGIyT>pL20xo-8C2)?`FBM0ETVTB^nt8uaGS0ENBaq^#KADEk(ox zrF4KZiGK9QWL7yn?HsKuOJvut_XobK`=NRsH=yA*x>8{12}Lp5*!4Bv4h}e zR|Ig+3W5N~CBcAwAgAA9Kz|r;w9sikI8a~*M*vrV*C{_35VHkC5Fj|PyM*oZIU5jC zg+oDbfG_lvKkyw4X9Ypo!NBQ6u(K-|;0Fh4vY~7MZ-5T=T`r6bpoe|udn%I!a(;i> z_T$42$N)BjoXQ3RMZ#bNfD_=2U;&Ow0zPMSa4;}Fc3`Y95CZtXfek)dn7<$K1p8G_ z3DmWoABY5mhEFy8eaq3QM#U_Qft@12QFwX^NIQ^$v4y_P_rs+?y1?{VU;;h#je!%H z&hO6t>Y3|UolVF8V!o9G6#hNcAbq3(zzCSo^N9PInK1sCT1KGHFN(9uQveIlgY_KD z=`l{Wr>9og0H=>3F}Y5Ux#IzG2?PI~ZE*R=bMSdDU4uW#zxO)3obg}04|dKI z`n~(PSfTSVfX^?m?;;Da<-OcI=25IqXmV4nOMPW?57zm2n(1AaG<9dEjVyY=b_-T46?`hS$s%2Rc*(&&r3Kc~%Yrsm#UNTm@yL*Ew8@PFDn z%c!WjwvQ_yAW}+qOA5mf!ywWkEirU=cY}bGbcf{7j(~)ObSWSmiqat|9fLIT4$AY~ zw{SmeJzt)0@A<-7|8?!N_c`Y}n_1_#_x}Tx)w=4&1KROL-3r6#Gy z`@+=XeqOz7z1Sy1#Zb@Cv8mUub*|NbV$=HLNukNg`1Mz81 znw>Tii~0Qaqkm-3WqfpNhI=<}G1EohvIy&mv5BI=v?lBx?yu>6=m#0Fm576qTuOzu z`FcxfA%@xnhm!6_yKaDU{QWvrgWT`1URLx(R0Ex6()caGWu8WqHM+7UA(o({*zaw0 zW%mU>8l6tvUU=+;o(R_OYd=cf{&;r2`ocv>^i@E}7qT2?V@KDYJJo5v!xEfas}VmL8q7-H)cHXGOTX@jPx=ut)d&Zmm-c;hGyHyow~CgW ztr&Km2pru)TEEY~KhhjDY2cXBY5$hMlfq-tvzlXgdh8oK?&HQLX4S--g}3_2>JXMp zdGOZ0t6S_7Wk(y1hnYiwk^aOKKDF0Q(f4y?pjGORnxaY!s`VzDIfhM3dz;klN{0!E zBTViqdlYo(4-@HYXMsp%^T$^Qra!Ct3g&1Wp9;Y1lRB0(U)Ii@R(*c(aP64>@8}|6w!?-opqS} z@*tpjPi@ARknwP0nNi{li-Q9CbN>zzRa%-sv%~k6Y(JW4j)}bDccYpCC;L5&A3p-O zp2|{39GAOUT8IY@E5dx=BJN?4X70i?Iq*;@1*uEO@9pC>8<|OpS?y^ z@v`ax`kNJ+`>)|159LbaUlvR(l-J1e|1jKloEhBS?)eyHBGjUicDPl6Tw^z)(+Y*Q z#wqFCgk~IZ8l4iBn0Ni0)6%&Abx0+P%kSQIBCCd7`BDF#!4jmf6js)$IX1i1!)7&Ltk#b<#U7qt zwjC8j)GB&sHLTxxHt5t#;5Z))e|ee0W||4Bw>oVp**vb>1*XfvW$?TN z1lL_7G2!8ii}?=^WDf;K7b!_Kv>SX42E?thK80mydzo9$y)&vms6;7FOm=!9I&Y*E zq9_*wHeMS~nnVggtggJF>n=VsJSt4%>ApI9-_{a3f1{BkZoU5jr0!;O#b{nEV98REB3kdxXv@W z`Yq=nrq_@B(#l&7;_e$if9hJZy&d7^Juut6g(+`FG^(-zh6JEWy7r)De=hXIxs4Y> zp59}9B<`WxDbH_J?2q%o68^%KZ)^Q}M86G(W zw@wF^zujMsW{2{-HdN0jB10!fxE|smx^#6J;q!SfI_Fwl6}^wDxi(3liuHM+xKfKU zB^9yQ3C21|B&cq{*1B1@6Pw@e)#SLm(={a*$*y)j+j}}ZTEgxd&}Uh7bUIaUZY_XX zyL#`0WOsS7FuhV-RR)?&|GGZZXFWf3D*i;UVGDo%YjiY)R?S+=;pkxJ=;4C9ov%z* zx6jGs(bRly0Oi9@ht*-2mCR{d;0SV)ip!7*OK~|`03Mzb2f0qmC`1C!>84M>qy9We zn~yO}WAiDn6pho4czV^Gk@IkGg53<{7>T9R2IR5+jUK1q&9L+y-0W}EOC@9!ntUv` zw2&VNc|xiWI@dop5cTyCVt5AAdE zme}lKeyrmOi(e30AL!|^szvq9sw#d|Ccx$8?qh4aUxa)X6k{%$;TCbQcSOcY^GXw0 z84cuVmnHysR9kITS&(1%s#D$gwL{=IY#9x$f$}x-Vn(D~m5ZvD1#=~SP!Iu8h_7ER z&X`RSMn$`lO-YI4$Sq{L$PJr5IUZ~skrle798odFlrc>W9h<6@V$(ZW8*hs2EN?bO zi<)xzPshaRyo#crv2dKRw5orGD`uB?FFrJ~TvI1IyQWvk6sYw^r7HSEU5mQ5s;(&# zo?0DyI`ivtweccL3TQz`hjiK(#l=D!&y?DGuU(Q}iufA8apk`Cg6jZS>RhWsuz1T8 zoybe3XS26){fplE?#X)M?DLvj<<;#I%R-rOhy9HRw1yp@vgsmj91-FAXC9C1$gJ@( z6npLx@WaJnK9+`Vq>-i^UvpESP@QB7;=N-zfLd9Gb}WQ#G@3U><$HUTCu+RA#ry0b5;r+qVjLet~*!>T2rKRF9m-x=P7KiuFP? z1J$S^KiffnThf%ONn6{n$hr2cpCx$AklV2I1owwTSr|^k7vW!$ZNuJirDW3@+vUG5mGWw=_lSCVwwsm`_&hT$D4y5-ubG;nUX)|+RxJ@UVQR{zV zeo#lZ>Gp0?Ha^^GoQ(c&mojxe{GWI=!9p`ncwDX zoFQ!$3a<|ie>aKx0_g3ucHk1J##R*5l%l(N-aWG#X6cy^lry7kJM9oNFEi@VQT6JB zexo(6fHT49T1=y0E@E^Ad%y;1QnvS6nuhS@H_RNo4aF12&^$DS)#x5yX?gPG2 zA)o*sE+#*PyOc$nwR#baN|$}Xt6`Kv6}2OQ4GO{N&muW~PQ1K(&Q!!?B%9{*mKu=~ zFpfdJGJjYwziFL-E(|YZy(+!gLoNDKc-cTp=?mIzEK4(!vH|15WE^0#u_f0QFk^f* zxSWx)8yo3t%kSrdtP!PST!p4Y=9Al>(VF$-?`i7=!{zv3P$MNBzp36+GUd3VEuv&M z9#{o@rt1`wX?DcSRih&Pj9x95yC+i!b8WFAaDdHSg+yV6nQB!&wS2v6xq@*l(?Z_Y zN6G29J`h>q0WyKqblcn3Vw)-APISY`(c<2GP8CJ5?e4-muCs zx1>MMf)LtW7J?Kb$crXeKS`FSZbn6C_)n<}D+LmEg=I}h=+vq<+KJbfTFR-&TQ0iK zNlAkFImF4Gv@^&mgHxPV8_@emDIv=e!|KMW%k8~x;ikhLx5JY5b78a977sCUc=7$m zeCTrk(zLhp_1Wl1_B-^GQ0n8KQo4#Kw=3R|mr%f`#HM)BNKlDk#$0!AR_n$p&tb$3 z2G1}noOeMrXNG*t`FSQOWbtvgnY(&&@Nw+vhM3&cwKWozCk<#A=tlz48@MD&X$-}` zjpJKO?j+zZ8c5ixi&%KZ1m>5;MePD=HI8*vev%Q}gbwxCz)$1WObdX_Dh}8_sHivI z;F6Fl3G6gna8hioqx6S&&hBoNfe2WU7B8z7#0 zYH*skrGLvi^z`I8cX|2UyEGk)PwhVe8A~xdP&K5aS5U^VW!|Dt5d}eJRo#7JL0MX< zgxTKIhQvGy`Dfd%fh?85y9u*4l^hhdv&uf~wDw+carC|8*w!6~A|B+)E=Hy-jP9{-6b3F5zjBfrQ3q+Bl=^Y$Ropm zY56ib=kBzIRZZs9kU16!lUy(xoJ(XWd$g30tj-q&!DQ{J}QrKav=D{6BLG(rWp*Itg^` z38sAFPz)~_dQz7jpCjwj}(Lk-FIBk9gd&6`Y`us$Cs_@Vq z0{M{AP$_0gyg7yNBlp1gENS}MvSdsc0#if>2jN#^Yav16lks0F-4>J`Yd3i>kcj(! zt{nYG8sU#^mdu3@K!}uWq8^@km(&iYpB53_t|b={!Bg~f{7Cy<2~qW@VS(i-;X8~W zY&n>2ZzPpaMkNi^vw)1xMZ@5VER#z73>`rb3`*Tt?!10&iok0$((^7L?0U{EYB{Zcw}@>7>$8&3D}H3H5-StjbxL(i{wi~ zc~fHVzB#MXw>)ZLUuOVKTl5Xl$?}#Si$VNe!l+l-#{S%_dmHqVWQ-N={P*dP%nPGs z{94t5B)N!UjZ(93%b0V>{_J zH69-GjVBCJD|8{12G31yW2Q&p9p&3R?0P0mSd))s8~M~0_hu-LHC%TtJ}kF5z&9qz zD6vBmiL_eP{p$)|R@G^T1bvq2d)2D(#Z@09KI<0tg8YdwqT+7Hoa!nUZ|_IAJuWOa z%fwjSDILz+Rwb;|UlC3+i$(PS``$^VwmVfXAI1^AJj%~=_Xj-w?wa~7(X&2w1lFnL z;Zy&P`B7BdUBk+fh26|JG)D&^KhvxX(ykuETD<)CkIjo1>|Dgw_DTT7e${nq4UgGp z`V~NG+6<-iOh^tqJ zn_!%mr@50?nJy_-i~Ch_@n)(DP3ma&;JIG;xICnIxQ6~qo`o1*R!QdbcXI>M2HbvC z5`iXy6p6^sSZ;2eQRUDAPyXTi>c4C&xWRmXE#UvlCgkrQI{yn?_1EXl{~f6M?f>$h zK$W-}g6QyE@Rv)c9Nxd|z5Y#TF1}bIBL1Jy`~`IW1EIM9Ef<953f=fk26!(i#cvLB zNpH9=A;%>S`3)T|`3diD)^UknF4@B+#JMCiT$k+O68>D0k4yOT2lDtA1G*$Mzxl}} zaJeKVmuTh^;&A^C;rV^)OXP6@NB*Y-Co#{%`E! zuPr%$w|zli2^kAxCu$5Wj9;t+#oUmpu67lNx_Yl|rRbwvY%F3ceR>;qAC>{?r1#Q&VDaUewLx9b{${a-mBh!b$F z4=~RKefqOsFc;{W2D(^>a3v1G&aUMK2n@Q`2cp>9wP(o(ym;OI?3WLOSSN8s0|PG% zE&q%IAqr<*(|E5x4?ZrwYxkLt=fa8e&-3x|UYHbJ(ZC3LctryP_^ywS_oB4bA8k1i zaQu{war|12gLoJh&R9xz jb_kozi+TT-^Olpdfur-UX%PrQEF!^RV0ipg0^|PxO;g#4 literal 0 HcmV?d00001 From 2fa4bb0d6fec9941babea52781002093dcf58a6d Mon Sep 17 00:00:00 2001 From: Luis Lara Date: Fri, 11 Mar 2022 10:06:10 -0500 Subject: [PATCH 59/60] Update coolc.sh --- src/coolc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coolc.sh b/src/coolc.sh index 593ab2245..8b82c925b 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -8,4 +8,4 @@ echo "Cool Compiler v0.1" echo "Copyright (c) 2022: Luis Lara, Carlos Arrieta" # Llamar al compilador -python3 main.py ${INPUT_FILE} +python main.py $INPUT_FILE From 95adb8dded501dfc8883f9454b678bee8d776491 Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 11 Mar 2022 16:39:42 -0300 Subject: [PATCH 60/60] update requirenmets --- requirements.txt | 1 + src/coolc.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9eb0cad1a..cba16ee2f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pytest pytest-ordering +ply diff --git a/src/coolc.sh b/src/coolc.sh index 8b82c925b..89bb3e933 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -8,4 +8,4 @@ echo "Cool Compiler v0.1" echo "Copyright (c) 2022: Luis Lara, Carlos Arrieta" # Llamar al compilador -python main.py $INPUT_FILE +python3 main.py $INPUT_FILE