├── .github └── workflows │ ├── concourse-notify-pull-request.yml │ └── concourse-notify-push.yml ├── .gitignore ├── ChangeLog.txt ├── License.txt ├── README.md ├── bin └── Note.txt ├── build-stanza.proj ├── ci ├── bootstrap-stanza.sh ├── build-stanza-version.txt ├── build-stanza.sh ├── calc-stanza-version-bump.sh ├── calc-stanza-version.sh └── install-stanza.sh ├── compiler ├── algorithms.stanza ├── arg-parser.stanza ├── asm-emitter.stanza ├── asm-ir-utils.stanza ├── asm-ir.stanza ├── asmjit.stanza ├── ast-lang.stanza ├── ast-lang2.stanza ├── ast-printer-lang.stanza ├── auto-doc.stanza ├── aux-file-errors.stanza ├── aux-file-serializer.stanza ├── aux-file-utils.stanza ├── aux-file.stanza ├── backend-regs.stanza ├── backend.stanza ├── basic-blocks.stanza ├── basic-ops.stanza ├── binary-tree.stanza ├── bindings-errors.stanza ├── bindings-extractor.stanza ├── bindings.stanza ├── branch-table.stanza ├── built-in-package-managers.stanza ├── c-extern-trampoline.stanza ├── c-trampoline.stanza ├── call-records.stanza ├── check-lang-engine.stanza ├── check-lang.stanza ├── check-set-equal.stanza ├── code-emitter.stanza ├── code-reader.stanza ├── code-table.stanza ├── code-template-table.stanza ├── codegen.stanza ├── comments-tests.stanza ├── comments.stanza ├── compiler-build-settings.stanza ├── compiler-linking.stanza ├── compiler-main.stanza ├── compiler-result.stanza ├── compiler.stanza ├── compiler.txt ├── conan-package-manager.stanza ├── config.stanza ├── const-pool.stanza ├── conversion-utils.stanza ├── core-macros.stanza ├── cvm-code-table.stanza ├── cvm-encoder.stanza ├── cvm.c ├── cycles.stanza ├── data-pool.stanza ├── defs-db-ir.stanza ├── defs-db-serializer.stanza ├── defs-db.stanza ├── dependencies.stanza ├── dir-utils.stanza ├── dispatch-dag.stanza ├── dl-ir.stanza ├── dl.stanza ├── driver.stanza ├── dump-to-log.stanza ├── dyn-bi-table.stanza ├── dyn-tree.stanza ├── dynamic-graph.stanza ├── ehier.stanza ├── el-basic-blocks.stanza ├── el-freevars.stanza ├── el-infer-engine.stanza ├── el-infer.stanza ├── el-ir.stanza ├── el-reordering.stanza ├── el-to-vm.stanza ├── el-unique-ids.stanza ├── el-utils.stanza ├── el-var-table.stanza ├── el.stanza ├── example-package-manager.stanza ├── exec-alloc.c ├── extern-defn-table.stanza ├── extern-intrinsics.stanza ├── external-dependencies.stanza ├── fastio-buffer.stanza ├── fastio-code-transforms.stanza ├── fastio-codegen.stanza ├── fastio-deftable.stanza ├── fastio-errors.stanza ├── fastio-runtime.stanza ├── fastio-serializer-lang-checks.stanza ├── fastio-serializer-lang-parser.stanza ├── fastio-serializer-lang.stanza ├── fastio-serializer-macros.stanza ├── fastio-size.stanza ├── fastio-to-codegen-ir.stanza ├── fastio.txt ├── file-stamps.stanza ├── foreign-package-files.stanza ├── foreign-package-manager.stanza ├── front-end.stanza ├── graphviz.stanza ├── hash.stanza ├── ids.stanza ├── il-ir.stanza ├── il-to-tl.stanza ├── infer.stanza ├── input.stanza ├── jit-code-table.stanza ├── jit-encoder.stanza ├── keyed-set.stanza ├── line-noise-prompter.stanza ├── linking-errors.stanza ├── loaded-dynamic-libraries.stanza ├── macro-handshake.c ├── macro-master.stanza ├── macro-plugin.stanza ├── macrobuilder.stanza ├── macroexpander.stanza ├── main.stanza ├── message-lang.stanza ├── mincore.stanza ├── mocker.stanza ├── namemap.stanza ├── optimistic-file-analysis.stanza ├── overlap-table.stanza ├── package-manager-system.stanza ├── package-stamps.stanza ├── packed-class-table.stanza ├── padder.stanza ├── params.stanza ├── pkg-errors.stanza ├── pkg-ir.stanza ├── pkg-serializer.stanza ├── pkg.stanza ├── plugin-interface.stanza ├── plugin-result.stanza ├── plugin-utils.stanza ├── preparsed-template.stanza ├── primitives.stanza ├── printing-utils.stanza ├── proj-conversion.stanza ├── proj-env.stanza ├── proj-errors.stanza ├── proj-field-types.stanza ├── proj-flattening.stanza ├── proj-ir.stanza ├── proj-isolate-package-manager-params.stanza ├── proj-manager.stanza ├── proj-normalization.stanza ├── proj-post-checks.stanza ├── proj-reader.stanza ├── proj-special-dirs.stanza ├── proj-stage0.stanza ├── proj-traverse-includes.stanza ├── proj-utils.stanza ├── proj-value-types.stanza ├── proj-variable-substitution.stanza ├── proj-wellformedness.stanza ├── proj.stanza ├── read-lang-engine.stanza ├── reader-lang.stanza ├── reg-alloc.stanza ├── renamer-lang.stanza ├── renamer.stanza ├── repl.stanza ├── resolver-lang.stanza ├── resolver.stanza ├── serializer-primitives.spec ├── set-simplifier.stanza ├── set-utils.stanza ├── sexp-checker.stanza ├── sexp-errors.stanza ├── sexp-serializer.stanza ├── shuffle.stanza ├── stable-arrays.stanza ├── standard-proj-env.stanza ├── stanza.proj ├── stitcher.stanza ├── system-dependencies.stanza ├── terminal-style.stanza ├── test-c-extern-driver.c ├── test-c-extern-trampoline.stanza ├── test-code-template-table.stanza ├── test-dispatch-dag.stanza ├── test-driver.stanza ├── test-dyn-graph.stanza ├── test-dyn-tree.stanza ├── test-extern-table.stanza ├── test-fastio-buffer.stanza ├── test-fastio-code-transforms.stanza ├── test-fastio-codegen.stanza ├── test-fastio-deftable.stanza ├── test-fastio-pkg.stanza ├── test-fastio-rw.stanza ├── test-fastio-serializer-lang-parser.stanza ├── test-fastio-to-codegen-ir.stanza ├── test-framework.stanza ├── test-lang.stanza ├── test-overlap-table.stanza ├── test-timing-log-commands.stanza ├── timing-log-api.stanza ├── timing-log-commands.stanza ├── timing-log-env.stanza ├── timing-log-options.stanza ├── timing-log-overlap-analysis.stanza ├── timing-log-reader.stanza ├── timing-log.stanza ├── tl-formatter.stanza ├── tl-guards.stanza ├── tl-ir.stanza ├── tl-struct-table.stanza ├── tl-to-dl.stanza ├── tl-to-el.stanza ├── trie-table.stanza ├── type-calculus.stanza ├── type-capside.stanza ├── type-equation-solver.stanza ├── type-equations.stanza ├── type-error-formatter.stanza ├── type-errors.stanza ├── type-fargs.stanza ├── type-fill.stanza ├── type-fnarities.stanza ├── type-formatter.stanza ├── type-gen-equations.stanza ├── type-hierarchy.stanza ├── type-instantiation.stanza ├── type-instfns.stanza ├── type-locs.stanza ├── type-match.stanza ├── type-solver.stanza ├── type-utils.stanza ├── type-variance.stanza ├── type.stanza ├── types.stanza ├── types.txt ├── typeset.stanza ├── uitree.stanza ├── utils.stanza ├── var-length-ints.stanza ├── verbose.stanza ├── visibility.stanza ├── vm-analyze.stanza ├── vm-ids.stanza ├── vm-ir.stanza ├── vm-load-unit.stanza ├── vm-normalize.stanza ├── vm-opcodes.stanza ├── vm-structures.stanza ├── vm-table.stanza └── vm.stanza ├── core ├── arg-parser.stanza ├── collections.stanza ├── core.stanza ├── core.txt ├── dynamic-library.c ├── dynamic-library.stanza ├── line-prompter.stanza ├── line-wrap.stanza ├── macro-utils.stanza ├── meta-utils.stanza ├── parsed-path.stanza ├── parser │ ├── binding-analysis.stanza │ ├── context.stanza │ ├── core-macroexpander.stanza │ ├── engine-frames.stanza │ ├── engine-lang.stanza │ ├── engine-value-stack.stanza │ ├── engine.stanza │ ├── errors.stanza │ ├── eval-value.stanza │ ├── lookahead-tokens.stanza │ ├── macro-compiler.stanza │ ├── macro-runtime.stanza │ ├── macro-syntax.stanza │ ├── macroexpander.stanza │ ├── merged-syntax-package.stanza │ ├── op-compiler.stanza │ ├── ops.stanza │ ├── pattern-parser.stanza │ ├── patterns.stanza │ ├── postprocessing.stanza │ ├── syntax-package-compiler.stanza │ ├── syntax-package-merger.stanza │ ├── syntax-package-registry.stanza │ ├── syntax-packages.stanza │ ├── timers.stanza │ └── translate.stanza ├── reader.stanza ├── sha256.c ├── sha256.stanza ├── stack-trace.stanza ├── stanza.proj ├── threaded-reader.stanza └── threadedreader.c ├── docs ├── build-system.md ├── check-docs.md ├── mocking-utility.md ├── test-framework.md └── usage-docs.md ├── examples ├── argparsing.stanza ├── calculus.stanza ├── cffi.stanza ├── closure.stanza ├── csum.c ├── dispatch.stanza ├── enums.stanza ├── examples.txt ├── generate-numbers │ ├── gen-numbers.c │ ├── gen-numbers.stanza │ ├── instructions.txt │ └── stanza.proj ├── helloworld.stanza ├── simplemock.stanza ├── simpletests.stanza ├── sort.stanza ├── stanza.proj ├── string.stanza ├── triforce.stanza └── wrapping-and-indenting.stanza ├── include ├── stanza.h └── stanza │ ├── platform.h │ └── types.h ├── libs └── asmjit │ ├── CMakeLists.txt │ ├── LICENSE.md │ ├── README.md │ ├── src │ ├── asmjit.natvis │ ├── asmjit │ │ ├── a64.h │ │ ├── arm.h │ │ ├── arm │ │ │ ├── a64archtraits_p.h │ │ │ ├── a64assembler.cpp │ │ │ ├── a64assembler.h │ │ │ ├── a64builder.cpp │ │ │ ├── a64builder.h │ │ │ ├── a64compiler.cpp │ │ │ ├── a64compiler.h │ │ │ ├── a64emithelper.cpp │ │ │ ├── a64emithelper_p.h │ │ │ ├── a64emitter.h │ │ │ ├── a64formatter.cpp │ │ │ ├── a64formatter_p.h │ │ │ ├── a64func.cpp │ │ │ ├── a64func_p.h │ │ │ ├── a64globals.h │ │ │ ├── a64instapi.cpp │ │ │ ├── a64instapi_p.h │ │ │ ├── a64instdb.cpp │ │ │ ├── a64instdb.h │ │ │ ├── a64instdb_p.h │ │ │ ├── a64operand.cpp │ │ │ ├── a64operand.h │ │ │ ├── a64rapass.cpp │ │ │ ├── a64rapass_p.h │ │ │ ├── a64utils.h │ │ │ ├── armformatter.cpp │ │ │ ├── armformatter_p.h │ │ │ ├── armglobals.h │ │ │ └── armoperand.h │ │ ├── asmjit-scope-begin.h │ │ ├── asmjit-scope-end.h │ │ ├── asmjit.h │ │ ├── core.h │ │ ├── core │ │ │ ├── api-build_p.h │ │ │ ├── api-config.h │ │ │ ├── archcommons.h │ │ │ ├── archtraits.cpp │ │ │ ├── archtraits.h │ │ │ ├── assembler.cpp │ │ │ ├── assembler.h │ │ │ ├── builder.cpp │ │ │ ├── builder.h │ │ │ ├── codebuffer.h │ │ │ ├── codeholder.cpp │ │ │ ├── codeholder.h │ │ │ ├── codewriter.cpp │ │ │ ├── codewriter_p.h │ │ │ ├── compiler.cpp │ │ │ ├── compiler.h │ │ │ ├── compilerdefs.h │ │ │ ├── constpool.cpp │ │ │ ├── constpool.h │ │ │ ├── cpuinfo.cpp │ │ │ ├── cpuinfo.h │ │ │ ├── emithelper.cpp │ │ │ ├── emithelper_p.h │ │ │ ├── emitter.cpp │ │ │ ├── emitter.h │ │ │ ├── emitterutils.cpp │ │ │ ├── emitterutils_p.h │ │ │ ├── environment.cpp │ │ │ ├── environment.h │ │ │ ├── errorhandler.cpp │ │ │ ├── errorhandler.h │ │ │ ├── formatter.cpp │ │ │ ├── formatter.h │ │ │ ├── formatter_p.h │ │ │ ├── func.cpp │ │ │ ├── func.h │ │ │ ├── funcargscontext.cpp │ │ │ ├── funcargscontext_p.h │ │ │ ├── globals.cpp │ │ │ ├── globals.h │ │ │ ├── inst.cpp │ │ │ ├── inst.h │ │ │ ├── jitallocator.cpp │ │ │ ├── jitallocator.h │ │ │ ├── jitruntime.cpp │ │ │ ├── jitruntime.h │ │ │ ├── logger.cpp │ │ │ ├── logger.h │ │ │ ├── misc_p.h │ │ │ ├── operand.cpp │ │ │ ├── operand.h │ │ │ ├── osutils.cpp │ │ │ ├── osutils.h │ │ │ ├── osutils_p.h │ │ │ ├── raassignment_p.h │ │ │ ├── rabuilders_p.h │ │ │ ├── radefs_p.h │ │ │ ├── ralocal.cpp │ │ │ ├── ralocal_p.h │ │ │ ├── rapass.cpp │ │ │ ├── rapass_p.h │ │ │ ├── rastack.cpp │ │ │ ├── rastack_p.h │ │ │ ├── string.cpp │ │ │ ├── string.h │ │ │ ├── support.cpp │ │ │ ├── support.h │ │ │ ├── target.cpp │ │ │ ├── target.h │ │ │ ├── type.cpp │ │ │ ├── type.h │ │ │ ├── virtmem.cpp │ │ │ ├── virtmem.h │ │ │ ├── zone.cpp │ │ │ ├── zone.h │ │ │ ├── zonehash.cpp │ │ │ ├── zonehash.h │ │ │ ├── zonelist.cpp │ │ │ ├── zonelist.h │ │ │ ├── zonestack.cpp │ │ │ ├── zonestack.h │ │ │ ├── zonestring.h │ │ │ ├── zonetree.cpp │ │ │ ├── zonetree.h │ │ │ ├── zonevector.cpp │ │ │ └── zonevector.h │ │ ├── x86.h │ │ └── x86 │ │ │ ├── x86archtraits_p.h │ │ │ ├── x86assembler.cpp │ │ │ ├── x86assembler.h │ │ │ ├── x86builder.cpp │ │ │ ├── x86builder.h │ │ │ ├── x86compiler.cpp │ │ │ ├── x86compiler.h │ │ │ ├── x86emithelper.cpp │ │ │ ├── x86emithelper_p.h │ │ │ ├── x86emitter.h │ │ │ ├── x86formatter.cpp │ │ │ ├── x86formatter_p.h │ │ │ ├── x86func.cpp │ │ │ ├── x86func_p.h │ │ │ ├── x86globals.h │ │ │ ├── x86instapi.cpp │ │ │ ├── x86instapi_p.h │ │ │ ├── x86instdb.cpp │ │ │ ├── x86instdb.h │ │ │ ├── x86instdb_p.h │ │ │ ├── x86opcode_p.h │ │ │ ├── x86operand.cpp │ │ │ ├── x86operand.h │ │ │ ├── x86rapass.cpp │ │ │ └── x86rapass_p.h │ └── bindings │ │ ├── stz-asmjit.cpp │ │ └── stz-asmjit.h │ ├── test │ ├── asmjit_test_assembler.cpp │ ├── asmjit_test_assembler.h │ ├── asmjit_test_assembler_a64.cpp │ ├── asmjit_test_assembler_x64.cpp │ ├── asmjit_test_assembler_x86.cpp │ ├── asmjit_test_compiler.cpp │ ├── asmjit_test_compiler.h │ ├── asmjit_test_compiler_a64.cpp │ ├── asmjit_test_compiler_x86.cpp │ ├── asmjit_test_emitters.cpp │ ├── asmjit_test_instinfo.cpp │ ├── asmjit_test_misc.h │ ├── asmjit_test_perf.cpp │ ├── asmjit_test_perf.h │ ├── asmjit_test_perf_a64.cpp │ ├── asmjit_test_perf_x86.cpp │ ├── asmjit_test_unit.cpp │ ├── asmjit_test_x86_sections.cpp │ ├── asmjitutils.h │ ├── broken.cpp │ ├── broken.h │ ├── cmdline.h │ └── performancetimer.h │ └── tools │ ├── configure-makefiles.sh │ ├── configure-ninja.sh │ ├── configure-sanitizers.sh │ ├── configure-vs2019-x64.bat │ ├── configure-vs2019-x86.bat │ ├── configure-vs2022-x64.bat │ ├── configure-vs2022-x86.bat │ ├── configure-xcode.sh │ ├── enumgen.js │ ├── enumgen.sh │ ├── tablegen-arm.js │ ├── tablegen-arm.sh │ ├── tablegen-x86.js │ ├── tablegen-x86.sh │ ├── tablegen.js │ └── tablegen.sh ├── notes.doc ├── notes ├── KForm Passes.graffle ├── Stacks.graffle ├── Stacks.pdf ├── asm.txt ├── dev.txt ├── docs.txt ├── emitter.txt ├── encoder.txt ├── fine-grained-tco.txt ├── gchooks.txt ├── index.txt ├── input.txt ├── install.txt ├── kform-dev.txt ├── reentrancy.txt ├── regalloc.txt ├── todo.txt ├── type.txt ├── ui.txt └── vm.txt ├── oldtests ├── buffered-input-stream.stanza ├── callc.asm ├── callc.c ├── dist-graph.stanza ├── driver.c ├── dup.c ├── elinfer.txt ├── freelist.stanza ├── graph.txt ├── mincore.stanza ├── parser.txt ├── process.stanza ├── read-pkg.stanza ├── serializer.stanza ├── test-macros.stanza ├── test-serialize.txt ├── test-tests.stanza ├── testdb.stanza ├── testdb2.stanza ├── tests.stanza ├── tests2.stanza ├── verify-reader.stanza ├── vmcore.stanza └── vmcore2.stanza ├── runtime ├── driver.c ├── linenoise.c ├── linenoise.h ├── process-win32.c └── process.h ├── scripts ├── copy-to-site.sh ├── export.sh ├── finish.sh ├── lfinish.sh ├── make-all-platforms.sh ├── make-asmjit.bat ├── make-asmjit.sh ├── make-bootstrap.sh ├── make-compiler-dev.sh ├── make-compiler.sh ├── make-extended.sh ├── make-linux-compiler.sh ├── make-main.sh ├── make-read-pkg.sh ├── make-reader.sh ├── make-serialize-lang.sh ├── make-test-asm.sh ├── make-test-full.sh ├── make-test-input.sh ├── make-test-kl-lowered.sh ├── make-test-kl.sh ├── make-test-macros.sh ├── make-test-regalloc.sh ├── make-test-tgt.sh ├── make-test-type-kl.sh ├── make-test-type.sh ├── make-test.sh ├── make-tgt-compiler.sh ├── make.sh ├── run-postcompile-tests.sh ├── run-tests.sh ├── test-boot-prog.sh ├── test-boot.sh ├── test-compiler.sh ├── test-main.sh ├── wfinish.bat └── wfinish.sh ├── stanza.proj └── tests ├── build-dev-tools.stanza ├── call-trampoline.c ├── conantest02 ├── Makefile ├── README.md ├── asmjit-app.stanza ├── stanza-asmjit │ ├── stz-asmjit.cpp │ ├── stz-asmjit.h │ └── stz-asmjit.stanza └── stanza.proj ├── data ├── ex1.proj ├── ex2.proj ├── ex3.proj ├── ex4.proj ├── ex5.proj ├── ex5a.proj ├── ex5c.proj ├── ex6.proj ├── ex6a.proj ├── ex6b.proj ├── ex6b.stanza ├── ex7.proj ├── ex8.proj ├── tl1.stanza └── type1.txt ├── dev-linker.stanza ├── dev-package-manager.stanza ├── dev-proj.stanza ├── dev-tl.stanza ├── dev-types.stanza ├── exampletest01 ├── alib.stanza ├── blib.stanza ├── main.stanza └── stanza.proj ├── extern_c_callbacks.c ├── gen-trampoline.stanza ├── indexing-data ├── stanza.proj ├── test-package.stanza └── test-unresolved-symbol.stanza ├── macros ├── macro-a.stanza ├── macro-b.stanza ├── macro-c.stanza ├── stanza.proj ├── test-macros.stanza └── test-macros2.stanza ├── repl-type-decl ├── animals.stanza ├── base.stanza ├── child.stanza └── side.stanza ├── run.stanza ├── stanza-postcompile-compiler-only-tests.stanza ├── stanza-postcompile-tests.stanza ├── stanza-tests.stanza ├── stanza.proj ├── test-asmjit.stanza ├── test-bitset-intrinsics.stanza ├── test-constant-fold-gen.stanza ├── test-constants.stanza ├── test-core.stanza ├── test-coroutines.stanza ├── test-cycles.stanza ├── test-definitions-database.stanza ├── test-dispatch-dag.stanza ├── test-externs.stanza ├── test-heap.stanza ├── test-infer.stanza ├── test-inline-targ.stanza ├── test-linker.stanza ├── test-lostanza.stanza ├── test-macro-plugins.stanza ├── test-match-syntax.stanza ├── test-meta-utils.stanza ├── test-multis.stanza ├── test-nan.stanza ├── test-package-manager.stanza ├── test-packed-class-table.stanza ├── test-paths.stanza ├── test-process-api.stanza ├── test-proj.stanza ├── test-shuffle.stanza ├── test-tools.stanza ├── test-trampoline.stanza ├── test-utils.stanza ├── type-reader.stanza └── type-test-ir.stanza /.github/workflows/concourse-notify-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Trigger Concourse on Pull Request 2 | on: [ pull_request, workflow_dispatch ] 3 | env: 4 | HOST: https://ci.jitx.com 5 | TEAM: main 6 | PIPELINE: lbstanza 7 | INSTVARS: vars.branch="${{ github.base_ref }}" 8 | TOKEN: ${{ secrets.CONCOURSE_WEBHOOK_TOKEN }} 9 | jobs: 10 | trigger-pr: 11 | runs-on: ubuntu-latest 12 | env: 13 | RESOURCE: github--lbstanza--pr 14 | steps: 15 | - name: Trigger Concourse Pull Request 16 | run: | 17 | URL="${HOST}/api/v1/teams/${TEAM}/pipelines/${PIPELINE}/resources/${RESOURCE}/check/webhook?webhook_token=${TOKEN}&${INSTVARS}" 18 | echo Triggering: "${URL}" 19 | curl --silent --fail --show-error --location --request "POST" --url "${URL}" 20 | -------------------------------------------------------------------------------- /.github/workflows/concourse-notify-push.yml: -------------------------------------------------------------------------------- 1 | name: Trigger Concourse on Push 2 | on: [ push, workflow_dispatch ] 3 | env: 4 | HOST: https://ci.jitx.com 5 | TEAM: main 6 | PIPELINE: lbstanza 7 | INSTVARS: vars.branch="${{ github.ref_name }}" 8 | TOKEN: ${{ secrets.CONCOURSE_WEBHOOK_TOKEN }} 9 | jobs: 10 | trigger-push: 11 | runs-on: ubuntu-latest 12 | env: 13 | RESOURCE: git--lbstanza 14 | steps: 15 | - name: Trigger Concourse resource check 16 | run: | 17 | URL="${HOST}/api/v1/teams/${TEAM}/pipelines/${PIPELINE}/resources/${RESOURCE}/check/webhook?webhook_token=${TOKEN}&${INSTVARS}" 18 | echo Triggering: "${URL}" 19 | # ignore 404 errors if the branch pipeline doesn't exist in Concourse 20 | curl --silent --fail --show-error --location --request "POST" --url "${URL}" || true 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | logs 3 | build 4 | scratch 5 | bin 6 | pkgs 7 | lpkgs 8 | wpkgs 9 | .#* 10 | *.*~ 11 | *.swp 12 | *.swo 13 | 14 | build 15 | *.s 16 | *.pkg 17 | *.fpkg 18 | *.o 19 | *.exe 20 | stanza.aux 21 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Patrick Shaobai Li, The Regents of the University 2 | of California. All Rights Reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 1. Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | 3. Neither the names of the copyright holders nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE TO ANY PARTY FOR 16 | DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, 17 | INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND 18 | ITS DOCUMENTATION, EVEN IF THE COPYRIGHT HOLDERS HAS BEEN ADVISED OF 19 | THE POSSIBILITY OF SUCH DAMAGE. 20 | 21 | THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIMS ANY WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND 24 | ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS 25 | IS". THE COPYRIGHT HOLDERS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, 26 | SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CAUTION # 2 | 3 | This Repo has been cleaned up and a new version of the repo has been created called 'lbstanza'. This is the old non-cleaned-up version. 4 | 5 | # L.B. Stanza Programming Language 6 | 7 | L.B. Stanza (or Stanza for short) is a new optionally-typed general purpose programming language designed to help programmers tackle the complexity of architecting large programs and significantly increase the productivity of application programmers across the entire software development life cycle. 8 | 9 | Visit www.lbstanza.org for details. 10 | -------------------------------------------------------------------------------- /bin/Note.txt: -------------------------------------------------------------------------------- 1 | Compiled binaries go into this folder. 2 | -------------------------------------------------------------------------------- /build-stanza.proj: -------------------------------------------------------------------------------- 1 | include "core/stanza.proj" 2 | include "compiler/stanza.proj" 3 | 4 | build main : 5 | inputs: 6 | stz/driver 7 | pkg: "pkgs" 8 | s: "stanza.s" 9 | o: "stanza" 10 | 11 | build core-macros : 12 | inputs: 13 | stz/check-lang 14 | stz/reader-lang 15 | stz/ast-lang 16 | stz/renamer-lang 17 | stz/resolver-lang 18 | stz/fastio-serializer-lang 19 | stz/ast-printer-lang 20 | stz/core-macros 21 | stz/macro-plugin 22 | o: "../build/core-macros" 23 | pkg: "../pkgs" -------------------------------------------------------------------------------- /ci/build-stanza-version.txt: -------------------------------------------------------------------------------- 1 | # build-stanza-version.txt 2 | # The existing version of stanza to be used to compile 3 | # this repo/branch's new version of stanza 4 | # - Comment lines begin with a '#' character 5 | # - The first non-comment line will be used as the version 6 | # - The line should be formated as a a version number by itself 7 | # like 1.23.45 8 | # 9 | # Use version 0.17.56 to compile 0.18.0 10 | 0.17.56 11 | -------------------------------------------------------------------------------- /compiler/aux-file-errors.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/aux-file-errors : 2 | import core 3 | import collections 4 | 5 | public defstruct CorruptedAuxFile <: Exception : 6 | filename: String 7 | 8 | defmethod print (o:OutputStream, f:CorruptedAuxFile) : 9 | print(o, "Auxiliary file %~ is corrupted." % [filename(f)]) 10 | 11 | public defstruct WrongAuxFileVersion <: Exception : 12 | filename: String|False with: (updater => sub-filename) 13 | version: Tuple 14 | current-version: Tuple 15 | 16 | defmethod print (o:OutputStream, e:WrongAuxFileVersion) : 17 | val version-str = string-join(version(e), ".") 18 | val current-version-str = string-join(current-version(e), ".") 19 | print(o, "Auxiliary file %~ is out-of-date. It was generated by Stanza %_ \ 20 | but the currently-running Stanza is on version %_." % [ 21 | filename(e), version-str, current-version-str]) 22 | -------------------------------------------------------------------------------- /compiler/aux-file-utils.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/aux-file-utils : 2 | import core 3 | import collections 4 | import stz/aux-file 5 | import stz/compiler-build-settings 6 | 7 | ;Create a BuildRecordSettings object (an AuxFile IR structure) from 8 | ;a compiler BuildSettings structure. 9 | public defn BuildRecordSettings (settings:BuildSettings) -> BuildRecordSettings : 10 | BuildRecordSettings( 11 | build-inputs!(settings) ;inputs 12 | vm-packages(settings) ;vm-packages 13 | platform(settings) ;platform 14 | original-asm(settings) ;assembly 15 | output(settings) ;output 16 | external-dependencies(settings) ;external-dependencies 17 | pkg-dir(settings) ;pkg-dir 18 | optimize?(settings) ;optimize? 19 | ccfiles(settings) ;ccfiles 20 | ccflags(settings) ;ccflags 21 | flags(settings)) ;flags 22 | -------------------------------------------------------------------------------- /compiler/backend-regs.stanza: -------------------------------------------------------------------------------- 1 | ;Utilities for finding free registers given a backend. 2 | 3 | defpackage stz/backend-regs : 4 | import core 5 | import collections 6 | import stz/backend 7 | import stz/asm-ir 8 | import stz/asm-ir-utils 9 | 10 | ;Helper: Retrieve free registers. 11 | public defn free-regs (used:Tuple, backend:Backend) -> Tuple : 12 | val regset = IntSet() 13 | add-all(regset, 0 to num-regs(backend)) 14 | for r in used do : 15 | match(r) : 16 | (r:Reg) : remove(regset, n(r)) 17 | (r:CallCArgRegs) : do(remove{regset, _}, callc-regs(backend)) 18 | (r:CallCPreservedRegs) : do(remove{regset, _}, c-preserved-regs(backend)) 19 | (r) : fatal("Illegal argument: %_" % [r]) 20 | to-tuple(seq(R, regset)) 21 | 22 | ;Helper: Retrieve free float registers. 23 | public defn free-fregs (used:Tuple, backend:Backend) -> Tuple : 24 | val regset = IntSet() 25 | add-all(regset, 0 to num-fregs(backend)) 26 | for r in used do : 27 | match(r) : 28 | (r:FReg) : remove(regset, n(r)) 29 | (r:CallCArgFRegs) : do(remove{regset, _}, callc-fregs(backend)) 30 | (r:CallCPreservedFRegs) : do(remove{regset, _}, c-preserved-fregs(backend)) 31 | (r) : fatal("Illegal argument: %_" % [r]) 32 | to-tuple(seq(F, regset)) 33 | 34 | ;Used to quickly represent a register class for use 35 | ;by 'free-registers' utility. 36 | public defenum RegClass : 37 | CallCArgRegs 38 | CallCArgFRegs 39 | CallCPreservedRegs 40 | CallCPreservedFRegs -------------------------------------------------------------------------------- /compiler/binary-tree.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/binary-tree : 2 | import core 3 | import collections 4 | 5 | ;======================================================= 6 | ;=================== Output Datastructure =================== 7 | ;============================================================ 8 | 9 | For inner nodes, left node values are guaranteed to be smaller or 10 | equal to the node value. 11 | 12 | ;============================================================ 13 | ;======================================================= 14 | 15 | public deftype BinaryNode 16 | 17 | public defstruct InnerNode <: BinaryNode : 18 | value: Int 19 | left: BinaryNode 20 | right: BinaryNode 21 | with: 22 | printer => true 23 | 24 | public defstruct LeafNode <: BinaryNode : 25 | entries: Tuple> 26 | with: 27 | printer => true 28 | 29 | ;============================================================ 30 | ;======================= Algorithm ========================== 31 | ;============================================================ 32 | 33 | public defn BinaryNode (input-entries:Seqable>, max-leaf-entries:Int) -> BinaryNode : 34 | fatal("Max-leaf-entries must be 2 or greater.") when max-leaf-entries < 2 35 | val entries = to-vector>(input-entries) 36 | qsort!(key, entries) 37 | defn node (start:Int, num:Int) : 38 | if num <= max-leaf-entries : 39 | LeafNode(to-tuple(entries[start to start + num])) 40 | else : 41 | val half1 = num / 2 42 | val half2 = num - half1 43 | val value = key(entries[start + half1 - 1]) 44 | InnerNode(value, 45 | node(start, half1) 46 | node(start + half1, half2)) 47 | node(0, length(entries)) 48 | 49 | public defn BinaryNode (input-entries:Seqable>) : 50 | BinaryNode(input-entries, 3) -------------------------------------------------------------------------------- /compiler/bindings-errors.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/bindings-errors : 2 | import core 3 | 4 | ;Represents any error related to Bindings. 5 | public deftype BindingException <: Exception 6 | 7 | ;Generic error. 8 | public defn BindingException (msg) : 9 | val msg-str = to-string(msg) 10 | new BindingException : 11 | defmethod print (o:OutputStream, this) : 12 | print(o, msg-str) 13 | 14 | ;Wrap up multiple errors. 15 | public defn BindingErrors (errors:Collection) : 16 | BindingException("%n" % [errors]) 17 | 18 | ;Occurs when a user declares: "extern myfunc", and also "extern defn myfunc ()". 19 | public defn LblUsedForExtern (lbl:Symbol) : 20 | BindingException $ "Label '%~' is used as both an extern and extern defn binding." % [lbl] 21 | -------------------------------------------------------------------------------- /compiler/bindings.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/bindings : 2 | import core 3 | import collections 4 | import stz/vm-ir 5 | import stz/printing-utils 6 | 7 | ;============================================================ 8 | ;=================== Bindings Structure ===================== 9 | ;============================================================ 10 | 11 | ;Represents the set of all bindings collected from the 12 | ;Stanza '-supported-vm-packages' option. 13 | ;- externs: The labels of all the externs pointing to foreign-declared 14 | ; code. 15 | ;- extern-defns: The *public* 'extern defn' functions. We create a 16 | ; global static label for these functions so that the compiler 17 | ; can be statically linked against foreign-declared code. 18 | public defstruct Bindings : 19 | externs: Tuple 20 | extern-defns: Tuple 21 | 22 | ;Represents an 'extern defn' label. 23 | public defstruct ExternDefnBinding : 24 | lbl: Symbol 25 | 26 | ;Represents an 'extern' label. 27 | public defstruct ExternBinding : 28 | lbl: Symbol 29 | 30 | ;============================================================ 31 | ;======================= Printers =========================== 32 | ;============================================================ 33 | 34 | defmethod print (o:OutputStream, b:Bindings) : 35 | val items = cat(externs(b), extern-defns(b)) 36 | print(o, "Bindings%_" % [colon-field-list(items)]) 37 | 38 | defmethod print (o:OutputStream, e:ExternBinding) : 39 | print(o, "extern %~" % [lbl(e)]) 40 | 41 | defmethod print (o:OutputStream, e:ExternDefnBinding) : 42 | print(o, "extern defn %~" % [lbl(e)]) -------------------------------------------------------------------------------- /compiler/built-in-package-managers.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/built-in-package-managers : 2 | import core 3 | import collections 4 | import stz/foreign-package-manager 5 | 6 | ;Register all of the built-in package managers. 7 | ;register-foreign-package-manager $ 8 | ; stz/example-package-manager/ExamplePackageManager() 9 | 10 | register-foreign-package-manager $ 11 | stz/conan-package-manager/ConanPackageManager() 12 | -------------------------------------------------------------------------------- /compiler/check-set-equal.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/check-set-equal : 2 | import core 3 | import collections 4 | import stz/utils 5 | 6 | ;List the three types of set differences. 7 | public deftype SetDifference 8 | public defstruct UnsupportedItem <: SetDifference : (name:Symbol) 9 | public defstruct DuplicateItem <: SetDifference : (name:Symbol) 10 | public defstruct MissingItem <: SetDifference : (name:Symbol) 11 | 12 | ;Used to represent the expected items in the set. 13 | public defstruct Item : 14 | name:Symbol 15 | optional?:True|False 16 | 17 | ;Utility: Scan through xs and check whether it satisfies the expected 18 | ;items given in ys. Returns a tuple of all differences. 19 | public defn check-set-equal (xs:Tuple, ys:Tuple) -> Tuple : 20 | val diffs = Vector() 21 | val ys-set = to-hashset(seq(name ys)) 22 | val xs-set = HashTable(0) 23 | 24 | ;Check for unsupported or duplicate items. 25 | for x in xs do : 26 | val num-x = update(xs-set, {_ + 1}, x) 27 | if num-x == 1 : 28 | if not ys-set[x] : 29 | add(diffs, UnsupportedItem(x)) 30 | else if num-x == 2 : 31 | add(diffs, DuplicateItem(x)) 32 | 33 | ;Check for missing required items. 34 | for y in ys do : 35 | if not optional?(y) : 36 | if not key?(xs-set,name(y)) : 37 | add(diffs, MissingItem(name(y))) 38 | 39 | to-tuple(diffs) -------------------------------------------------------------------------------- /compiler/code-emitter.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/code-emitter : 2 | import core 3 | import collections 4 | import stz/asm-ir 5 | 6 | ;======================================================= 7 | ;================= Code Emitter Interface =================== 8 | ;============================================================ 9 | 10 | The code emitter is an abstract interface that acts as the 11 | output stream for assembly instructions. 12 | 13 | ;============================================================ 14 | ;======================================================= 15 | 16 | public deftype CodeEmitter 17 | 18 | ;Emit an assembly instruction. 19 | public defmulti emit (e:CodeEmitter, i:Ins) -> False 20 | 21 | ;Generate a unique identifier for use as a label. 22 | public defmulti unique-label (e:CodeEmitter) -> Int -------------------------------------------------------------------------------- /compiler/comments-tests.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/comments-tests : 2 | import core 3 | import collections 4 | import stz/comments 5 | 6 | let : 7 | val filename = "testfile2.txt" 8 | val full-path = resolve-path!(filename) 9 | val stream = StringInputStream(slurp(filename), filename) 10 | val params = DocParams("+", "/", "@") 11 | val doc = parse-comment-doc(stream, filename, full-path, params) as CommentDoc 12 | println("===== INPUT DOCUMENT =====") 13 | println(doc) 14 | val result = compute-implicit-ends(doc) 15 | println("===== RESULT =====") 16 | println(result) 17 | -------------------------------------------------------------------------------- /compiler/compiler-result.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/compiler-result : 2 | import core 3 | import collections 4 | import stz/package-stamps 5 | import stz/file-stamps 6 | 7 | ;Represents the output of a compilation run. 8 | ;- compiled-packages: The names of all the Stanza packages. 9 | ;- binding-packages: The names of all the Stanza binding packages used by the REPL. 10 | ;- package-stamps: The originating information about the input Stanza packages. 11 | ;- output-pkgs: The filestamps of any new pkgs that were produced during compilation. 12 | public defstruct CompilationResult : 13 | compiled-packages: Tuple 14 | binding-packages: Tuple 15 | package-stamps: Tuple 16 | output-pkgs: Tuple 17 | with: 18 | printer => true -------------------------------------------------------------------------------- /compiler/conversion-utils.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/conversion-utils : 2 | import core 3 | import collections 4 | import stz/set-utils 5 | import stz/dispatch-dag 6 | import stz/el-ir 7 | import stz/typeset 8 | import stz/dyn-tree 9 | 10 | public defn etype-to-arg (ct:DynTree, t:EType, include-abstract?:True|False) -> Arg : 11 | let to-arg (t:EType = t) : 12 | match(t) : 13 | (t:EAnd) : intersect([to-arg(a(t)), to-arg(b(t))]) 14 | (t:EOr) : union([to-arg(a(t)), to-arg(b(t))]) 15 | (t:ETVar|ETop) : Top() 16 | (t:EOf) : 17 | Nums $ 18 | if include-abstract? : all-children(ct, n(t)) 19 | else : all-leaves(ct, n(t)) 20 | 21 | public defn to-arg (t:TypeSet, set-representation:Int -> Tuple) -> Arg : 22 | let to-arg (t:TypeSet = t) : 23 | match(t) : 24 | (t:AndType) : intersect(map(to-arg, types(t))) 25 | (t:OrType) : union(map(to-arg, types(t))) 26 | (t:TopType) : Top() 27 | (t:SingleType) : Nums(set-representation(type(t))) 28 | 29 | public defn to-branches (bs:Seqable>, set-representation:Int -> Tuple) -> Tuple : 30 | to-tuple $ for b in bs seq : 31 | Branch(to-tuple(seq(to-arg{_, set-representation}, b))) -------------------------------------------------------------------------------- /compiler/cycles.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/cycles : 2 | import core 3 | import collections 4 | import stz/utils 5 | 6 | ;============================================================ 7 | ;=============== Cycle Detection Utility ==================== 8 | ;============================================================ 9 | 10 | public defstruct Edge : 11 | id 12 | src:Int 13 | dst:Int 14 | with: 15 | printer => true 16 | 17 | defenum CycleState : 18 | OnStack 19 | Visited 20 | NotVisited 21 | 22 | public defn detect-cycles (vertices:Tuple, 23 | get-edges:Int -> Seqable) -> Vector> : 24 | val state = IntTable(NotVisited) 25 | val stack = Vector() 26 | val cycles = Vector>() 27 | defn* loop (v:Int) : 28 | switch(state[v]) : 29 | NotVisited : 30 | state[v] = OnStack 31 | do(loop, get-edges(v)) 32 | state[v] = Visited 33 | OnStack : 34 | add(cycles, cycle-on-stack()) 35 | Visited : 36 | false 37 | defn* loop (e:Edge) : 38 | add(stack, e) 39 | loop(dst(e)) 40 | pop(stack) 41 | defn cycle-on-stack () -> Tuple : 42 | val v = dst(peek(stack)) 43 | val start-index = for i in reverse(0 to length(stack)) find! : 44 | src(stack[i]) == v 45 | to-tuple(stack[start-index to false]) 46 | do(loop, vertices) 47 | cycles 48 | 49 | ;Simple API for convenience. 50 | public defn detect-cycles (vertices:Tuple, edges:Tuple) -> Vector> : 51 | val edge-table = group-by(src, edges) 52 | detect-cycles(vertices, {edge-table[_]}) -------------------------------------------------------------------------------- /compiler/data-pool.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/data-pool : 2 | import core 3 | import collections 4 | import stz/vm-ir 5 | 6 | public deftype DataPool 7 | public defmulti intern (p:DataPool, v:ByteArray) -> Int 8 | public defmulti datas (p:DataPool) -> Vector 9 | 10 | public defn DataPool () : 11 | val datas = Vector() 12 | val data-table = HashTable(content-hash, content-equal?) 13 | new DataPool : 14 | defmethod intern (this, v:ByteArray) : 15 | match(get?(data-table, v)) : 16 | (i:Int) : 17 | i 18 | (_:False) : 19 | val i = length(datas) 20 | add(datas, v) 21 | data-table[v] = i 22 | i 23 | defmethod datas (this) : 24 | datas 25 | 26 | defn content-hash (b:ByteArray) : 27 | var h:Int = length(b) 28 | for x in b do : h = (7 * h) + to-int(x) 29 | h 30 | 31 | defn content-equal? (a:ByteArray, b:ByteArray) : 32 | length(a) == length(b) and 33 | all?(equal?, a, b) -------------------------------------------------------------------------------- /compiler/dir-utils.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/dir-utils : 2 | import core 3 | import collections 4 | import core/parsed-path 5 | 6 | ;This function attempts to ensure that the given path exists as a directory. 7 | ;If it doesn't exist already, then it attempts to create the directory. 8 | ;If it does exist, then it throws an error if it is not a directory. 9 | public defn ensure-directory-exists (dirpath:String) -> False : 10 | if not file-exists?(dirpath) : 11 | create-dir-recursive(dirpath) 12 | 13 | ;This function attempts to ensure that the directory that contains the 14 | ;given file exists. It is meant to be used when generating output files 15 | ;at a specific path. 16 | public defn ensure-containing-directory-exists (filepath:String) -> False : 17 | ensure-directory-exists(to-string(enclosing-dir(filepath))) -------------------------------------------------------------------------------- /compiler/driver.stanza: -------------------------------------------------------------------------------- 1 | ;See License.txt for details about licensing. 2 | 3 | defpackage stz/driver : 4 | import core 5 | import stz/main 6 | 7 | ;Imports that are not strictly needed to implement the compiler, 8 | ;but that we would like to be automatically included with the REPL. 9 | import core/threaded-reader 10 | import stz/optimistic-file-analysis 11 | 12 | stanza-main() -------------------------------------------------------------------------------- /compiler/dump-to-log.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/dump-to-log : 2 | import core 3 | import collections 4 | import stz/utils 5 | 6 | ;Represents the name of this object to use when creating the filename. 7 | public defmulti object-log-name (object) -> Symbol 8 | 9 | ;Represents the extension to use for this object when creating the filename. 10 | public defmulti object-extension (object) -> String 11 | 12 | ;Dump the object to the given path with the given suffix. 13 | public defn dump (object, path:String, suffix:String|False) -> False : 14 | val suffix-str = "" when suffix is False else ".%_" % [suffix] 15 | val filename = norm-path("%_/%_.%_%_" % [path, 16 | mangle-as-filename(object-log-name(object)), 17 | object-extension(object), 18 | suffix-str]) 19 | spit(filename, object) 20 | 21 | ;Default suffix is false. 22 | public defn dump (object, path:String) -> False : 23 | dump(object, path, false) -------------------------------------------------------------------------------- /compiler/el-freevars.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/el-freevars : 2 | import core 3 | import collections 4 | import stz/el-ir 5 | import stz/el-var-table 6 | 7 | ;============================================================ 8 | ;=================== Freevar Analysis ======================= 9 | ;============================================================ 10 | 11 | public defn analyze-freevars (el:ELBigItem&?T, vt:VarTable) -> T : 12 | defn analyze-usages (e:EFn) -> EFn : 13 | ;Gather all uses in the function 14 | val var-uses = IntSet() 15 | val tvar-uses = IntSet() 16 | 17 | defn loop (e:ELItem) : 18 | match(e) : 19 | (e:EVar|EVarLoc) : 20 | add(var-uses, n(e)) 21 | (e:ETVar|ETVarLoc) : 22 | add(tvar-uses, n(e)) 23 | (e:EFn) : 24 | val free = free(e) 25 | add-all(var-uses, vars(free)) 26 | add-all(tvar-uses, tvars(free)) 27 | (e) : 28 | do(loop, e) 29 | do(loop,e) 30 | 31 | ;Remove all locally defined quantities 32 | defn remove-all (xs:IntSet, ys:Seqable) : do(remove{xs, _}, ys) 33 | remove-all(tvar-uses, targs(e)) 34 | remove-all(tvar-uses, seq(n, localtypes(body(e)))) 35 | remove-all(var-uses, args(e)) 36 | remove-all(var-uses, seq(n, locals(body(e)))) 37 | remove-all(var-uses, seq(n, localfns(body(e)))) 38 | 39 | ;Record free 40 | defn local? (x:Int) : not global?(vt,x) 41 | defn local? (xs:Seqable) : to-tuple(filter(local?,xs)) 42 | sub-free(e, Free(local?(var-uses), to-tuple(tvar-uses))) 43 | 44 | ;Recursively analyze usages 45 | defn analyze (e:ELBigItem) : 46 | match(map(analyze, e)) : 47 | (e:EFn) : analyze-usages(e) 48 | (e) : e 49 | analyze(el) as ELBigItem&T -------------------------------------------------------------------------------- /compiler/exec-alloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifdef PLATFORM_WINDOWS 6 | #include 7 | #else 8 | #include 9 | #endif 10 | 11 | //Print a message and halt immediately. 12 | void allocate_exec_error () { 13 | printf("Could not allocate executable memory.\n"); 14 | exit(-1); 15 | } 16 | 17 | //Return some executable memory of the given size. 18 | char* allocate_exec_memory (uint64_t size){ 19 | #ifdef PLATFORM_WINDOWS 20 | // Reserve the max size with no access 21 | char* code = VirtualAlloc(NULL, (SIZE_T)size, MEM_RESERVE, PAGE_NOACCESS); 22 | if(!code) allocate_exec_error(); 23 | 24 | // Commit the min size with RWX access. 25 | code = VirtualAlloc(code, (SIZE_T)size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); 26 | if(!code) allocate_exec_error(); 27 | 28 | return code; 29 | 30 | #else 31 | char* code = mmap(0, size, 32 | PROT_READ|PROT_WRITE|PROT_EXEC, 33 | MAP_PRIVATE|MAP_ANON, -1, 0); 34 | if(!code) allocate_exec_error(); 35 | 36 | return code; 37 | 38 | #endif 39 | } 40 | -------------------------------------------------------------------------------- /compiler/extern-intrinsics.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/extern-intrinsics : 2 | import core 3 | 4 | protected extern defn lowest_zero_bit_count (x:long) -> long : 5 | return call-prim lowest-zero-bit-count(x) 6 | -------------------------------------------------------------------------------- /compiler/fastio-serializer-macros.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/fastio-serializer-macros : 2 | import core 3 | import collections 4 | import macro-utils 5 | import stz/core-macros 6 | import stz/fastio-serializer-lang 7 | import stz/fastio-serializer-lang-parser 8 | import stz/fastio-serializer-lang-checks 9 | import stz/fastio-code-transforms 10 | import stz/fastio-to-codegen-ir 11 | import stz/fastio-codegen 12 | 13 | defsyntax fastio-serializer : 14 | import exp4 from core 15 | import defserializer from fastio-serializer-lang 16 | 17 | defrule exp4 = (?s:#defserializer) : 18 | check-errors(s) 19 | val transformed = lift-combinators(s) 20 | val code-ir = to-codegen-ir(transformed) 21 | val form = to-sexp(code-ir) 22 | parse-syntax[core / #exp](List(form)) -------------------------------------------------------------------------------- /compiler/fastio-size.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/fastio-size : 2 | import core 3 | import collections 4 | 5 | ;============================================================ 6 | ;=========== Different Representations of Size ============== 7 | ;============================================================ 8 | 9 | ;Size is known and constant. 10 | public defstruct ConstantSize : 11 | size:Int 12 | with: 13 | printer => true 14 | 15 | ;Size is known for all instances of this specification, but requires 16 | ;computation to calculate. 17 | public defstruct ComputableSize : 18 | exp 19 | with: 20 | printer => true 21 | 22 | ;Size is not calculated directly, and skipping is implemented 23 | ;directly. 24 | public defstruct SkipExp : 25 | exp 26 | with: 27 | printer => true 28 | 29 | ;Size is known and computable from child specifications. 30 | public defstruct ComputeFromChildren 31 | 32 | ;Size is not calculated directly, and skipping is implemented 33 | ;by calls to the skip expression from children. 34 | public defstruct SkipChildren 35 | 36 | ;============================================================ 37 | ;===================== Contexts ============================= 38 | ;============================================================ 39 | 40 | ;Abstract type for all sizes. 41 | public deftype SizeSpec : 42 | AtomSize <: SizeSpec 43 | StructSize <: SizeSpec 44 | UnionSize <: SizeSpec 45 | 46 | ;Size specification for DefAtom definitions. 47 | public deftype AtomSize : 48 | ConstantSize <: AtomSize 49 | ComputableSize <: AtomSize 50 | SkipExp <: AtomSize 51 | 52 | ;Size specification for Struct definitions. 53 | public deftype StructSize : 54 | ConstantSize <: StructSize 55 | ComputeFromChildren <: StructSize 56 | SkipChildren <: StructSize 57 | 58 | ;Size specification for Union definitions. 59 | public deftype UnionSize : 60 | ConstantSize <: UnionSize 61 | SkipChildren <: UnionSize 62 | 63 | -------------------------------------------------------------------------------- /compiler/fastio.txt: -------------------------------------------------------------------------------- 1 | ## Testing ## 2 | 3 | @[file:test-fastio-serializer-lang-parser.stanza] 4 | Test out the parsing of S-expressions into IR. 5 | 6 | @[file:test-fastio-deftable.stanza] 7 | Test out whether the DefTable is working. 8 | 9 | @[file:test-fastio-code-transforms.stanza] 10 | Test out the parsing of S-expressions into IR. 11 | 12 | @[file:test-fastio-to-codegen-ir.stanza] 13 | Test out conversion of input IR to CodeGen IR. 14 | 15 | @[file:test-fastio-codegen.stanza] 16 | Test out the code generation from CodeIR into 17 | S-expressions. 18 | 19 | ## Serialization Language ## 20 | 21 | @[file:fastio-serializer-lang.stanza] 22 | Definition of the IR 23 | Examples of the surface syntax 24 | 25 | @[file:fastio-serializer-lang-parser.stanza] 26 | Parse S-expressions into the IR 27 | 28 | @[file:fastio-serializer-lang-checks.stanza] 29 | Issue errors for improperly formed IR. 30 | 31 | @[file:fastio-deftable.stanza] 32 | Utility table for looking up types of definitions 33 | in a DefSerializer 34 | 35 | @[file:fastio-size.stanza] 36 | Representation of the size of various definitions. 37 | 38 | @[file:fastio-code-transforms.stanza] 39 | Transform the input IR for preparation for output to CodeGen IR. 40 | 41 | @[file:fastio-to-codegen-ir.stanza] 42 | Transform the transformed input IR into 43 | the CodeGen IR. 44 | 45 | @[file:fastio-codegen.stanza] 46 | Generate the final s-expressions for 47 | implementing the serializer. 48 | 49 | @[file:fastio-runtime] 50 | Defines 'FastIOSerializer' 51 | Defines 'write-to-file', 'read-from-file' utilities. 52 | 53 | ## System Connection ## 54 | 55 | @[file:fastio-serializer-macros.stanza] 56 | Macro connection to Stanza 57 | 58 | ## Basic Buffer ## 59 | 60 | @[file:fastio-buffer.stanza] 61 | Definition of FastIOBuffer 62 | Reading and Writing Primitives 63 | 64 | ## Errors ## 65 | 66 | @[file:fastio-errors.stanza] 67 | All errors related to FastIO 68 | -------------------------------------------------------------------------------- /compiler/foreign-package-files.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/foreign-package-files : 2 | import core 3 | import collections 4 | 5 | ;Example: 6 | ; foreign-packages(conan) : 7 | ; "goodzip/2.11.3" 8 | public defstruct ForeignPackageFiles <: Equalable : 9 | package-manager:Symbol 10 | files: Tuple 11 | with: 12 | equalable => true -------------------------------------------------------------------------------- /compiler/graphviz.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/graphviz : 2 | import core 3 | import collections 4 | 5 | public defstruct DigraphViz : 6 | name: String 7 | entries: Tuple> 8 | 9 | defmethod print (o:OutputStream, v:DigraphViz) : 10 | print(o, "digraph %~ {" % [name(v)]) 11 | val o2 = IndentedStream(o) 12 | for e in entries(v) do : 13 | lnprint(o2, "%~ -> %~" % [key(e), value(e)]) 14 | lnprint(o, "}") -------------------------------------------------------------------------------- /compiler/ids.stanza: -------------------------------------------------------------------------------- 1 | ;See License.txt for details about licensing. 2 | 3 | defpackage stz/ids : 4 | import core 5 | import collections 6 | import stz/params 7 | import stz/utils 8 | 9 | 10 | ; Id Generation 11 | ; ============= 12 | 13 | val ID-COUNTER = to-seq(1000000 to false) 14 | public defn fresh-id () : next(ID-COUNTER) 15 | -------------------------------------------------------------------------------- /compiler/line-noise-prompter.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/line-noise-prompter : 2 | import core 3 | import collections 4 | import reader 5 | 6 | extern linenoiseSetMultiLine : int -> int 7 | extern linenoise : ptr -> ptr 8 | extern linenoiseHistoryAdd : ptr -> int 9 | 10 | lostanza defn set-multi-line (x:ref) -> ref : 11 | if x == true : call-c linenoiseSetMultiLine(1) 12 | else : call-c linenoiseSetMultiLine(0) 13 | return false 14 | set-multi-line(true) 15 | 16 | lostanza defn line-noise (prompt:ref) -> ref : 17 | val s = call-c linenoise(addr!(prompt.chars)) 18 | if s == 0L as ptr : 19 | return false 20 | else : 21 | val str = String(s) 22 | call-c clib/free(s) 23 | return str 24 | 25 | lostanza defn add-history (str:ref) -> ref : 26 | call-c linenoiseHistoryAdd(addr!(str.chars)) 27 | return false 28 | 29 | public defn LineNoisePrompter (prompt:String, continue:String) : 30 | var line-counter = to-seq(0 to false) 31 | new Prompter : 32 | defmethod get-line (this) : 33 | val msg = prompt when next(line-counter) == 0 34 | else continue 35 | val l = line-noise(msg) 36 | match(l:String) : 37 | add-history(l) 38 | l -------------------------------------------------------------------------------- /compiler/macro-handshake.c: -------------------------------------------------------------------------------- 1 | #include 2 | //Simple sanity-check function to test successful connection to macro plugin. 3 | STANZA_API_FUNC uint32_t handshake () { 4 | return 0xcafebabe; 5 | } 6 | -------------------------------------------------------------------------------- /compiler/macrobuilder.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/macrobuilder : 2 | import core 3 | import collections 4 | import stz/macroexpander 5 | import stz/params 6 | 7 | ;This is a small utility for calling the Stanza compiler to build a macro target. 8 | ; 9 | ;The StanzaMacroexpander uses this utility when it encounters a macro plugin that may not 10 | ;have been built yet. 11 | 12 | public defn MacroBuilder () -> MacroSystem : 13 | new MacroSystem : 14 | defmethod compile-build-target (this, target:Symbol) : 15 | val exe = system-filepath(StanzaCompiler) 16 | val code = call-system $ [exe, "build", to-string(target)] 17 | if code != 0 : 18 | throw(MacroBuildError(target)) 19 | 20 | ;Occurs when the compilation fails. 21 | public defstruct MacroBuildError <: Exception : 22 | target:Symbol 23 | 24 | defmethod print (o:OutputStream, e:MacroBuildError) : 25 | print(o, "Errors occurred during compilation of build target '%~'." % [target(e)]) -------------------------------------------------------------------------------- /compiler/padder.stanza: -------------------------------------------------------------------------------- 1 | ;See License.txt for details about licensing. 2 | 3 | defpackage stz/padder : 4 | import core 5 | import collections 6 | 7 | public defstruct Padding : 8 | size: Int 9 | 10 | public defn pad (alignment:T -> Int, 11 | size:T -> Int, 12 | xs:Collection, 13 | min-aln:Int) -> 14 | [Seq, Int] : 15 | val aln = maximum(min-aln, seq(alignment, xs)) 16 | val xs* = generate : 17 | var accum = 0 18 | defn align-accum (a:Int) : 19 | val over = accum % a 20 | if over > 0 : 21 | yield(Padding(a - over)) 22 | accum = accum + a - over 23 | for x in xs do : 24 | align-accum(alignment(x)) 25 | yield(x) 26 | accum = accum + size(x) 27 | align-accum(aln) 28 | [xs*, aln] 29 | 30 | -------------------------------------------------------------------------------- /compiler/proj-env.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/proj-env : 2 | import core 3 | import collections 4 | import stz/proj-ir 5 | import stz/proj-value-types 6 | import stz/printing-utils 7 | 8 | ;Represents the environment in which to read the proj files. 9 | public deftype ProjEnv 10 | 11 | ;Retrieve the current working directory. This is used to resolve 12 | ;{WORKDIR} and to also compute absolute paths for everything. 13 | public defmulti workdir (env:ProjEnv) -> String 14 | 15 | ;Retrieve the parameter names and types for the given package manager. 16 | public defmulti foreign-package-managers (env:ProjEnv) -> Tuple : 17 | [] 18 | 19 | ;Retrieve the additional build variables computed by the foreign package managers. 20 | ;A returned value must satisfy: 21 | ; value = Symbol 22 | ; | String 23 | ; | List 24 | ;and it will be translated over to a ProjValue before substitution. 25 | public defmulti package-manager-variables (env:ProjEnv, 26 | params:ForeignPackageParamsStmt, 27 | platform:Symbol) 28 | -> Tuple> : 29 | [] 30 | 31 | ;Contains the information about a foreign package manager. 32 | ;- name: The name of the package manager. e.g. `conan 33 | ;- params: The list of parameters that the package manager can 34 | ; be configured with. 35 | public defstruct ForeignPackageManagerInfo : 36 | name:Symbol 37 | params:Tuple 38 | -------------------------------------------------------------------------------- /compiler/sexp-checker.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/sexp-checker : 2 | import core 3 | import collections 4 | import stz/sexp-errors 5 | 6 | ;Scan through the given s-expression and ensure it is valid. 7 | ;If it is not, throw a InvalidSExp error. 8 | 9 | public defn check-valid-sexp (sexp, 10 | allow-rich-quotes?:True|False) -> False : 11 | 12 | ;Track the most recent information seen. 13 | var closest-info:FileInfo|False = false 14 | defn update-info (info:FileInfo|False) : 15 | if info is FileInfo : 16 | closest-info = info 17 | 18 | ;Accumulate all errors into this buffer 19 | val error-buffer = Vector() 20 | 21 | ;Throw errors if error-buffer is not empty. 22 | defn throw-errors? () : 23 | if not empty?(error-buffer) : 24 | throw(InvalidSExp(to-tuple(error-buffer))) 25 | 26 | ;Scan through the s-expression and collect 27 | ;errors. 28 | let loop (sexp = sexp) : 29 | match(sexp) : 30 | (sexp:Token) : 31 | update-info(info(sexp)) 32 | loop(item(sexp)) 33 | (sexp:List) : 34 | if quote-form?(sexp) : 35 | if not allow-rich-quotes? : 36 | do(loop, sexp) 37 | else : 38 | do(loop, sexp) 39 | (sexp:Char 40 | |Byte|Int|Long 41 | |Float|Double 42 | |String|Symbol 43 | |True|False) : 44 | false 45 | (sexp) : 46 | val err = NotAnSExp(closest-info, object-type(sexp)) 47 | add(error-buffer, err) 48 | 49 | ;Issue errors 50 | throw-errors?() 51 | 52 | ;By default, allow-rich-quotes? is false. 53 | public defn check-valid-sexp (sexp) -> False : 54 | check-valid-sexp(sexp, false) 55 | 56 | ;Helper: Return true if it's a ($quote ...) form. 57 | defn quote-form? (x:List) -> True|False : 58 | not empty?(x) and 59 | unwrap-token(head(x)) == `$quote -------------------------------------------------------------------------------- /compiler/sexp-errors.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/sexp-errors : 2 | import core 3 | import collections 4 | 5 | ;General error type for s-expressions. 6 | public deftype SExpError <: Exception 7 | 8 | ;Occurs when we detect an object that is not a valid 9 | ;s-expression type. 10 | public defstruct NotAnSExp <: SExpError : 11 | info:FileInfo|False 12 | type:String 13 | defmethod print (o:OutputStream, e:NotAnSExp) : 14 | print(o, "%_Object of type %_ is not a valid s-expression." % [ 15 | info-str(info(e)), type(e)]) 16 | 17 | ;Occurs when we detect that an s-expression is not valid. 18 | public defstruct InvalidSExp <: SExpError : 19 | errors:Tuple 20 | defmethod print (o:OutputStream, e:InvalidSExp) : 21 | val err-str = Indented("%n" % [errors(e)]) 22 | print(o, "The s-expression is invalid:\n%_" % [err-str]) 23 | 24 | ;Helper: Format file information 25 | defn info-str (info:FileInfo|False) : 26 | "" when info is False else "%_: " % [info] -------------------------------------------------------------------------------- /compiler/stanza.proj: -------------------------------------------------------------------------------- 1 | packages stz/* defined-in "." -------------------------------------------------------------------------------- /compiler/system-dependencies.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/system-dependencies : 2 | import core 3 | import collections 4 | import stz/external-dependencies 5 | import stz/params 6 | 7 | ;Compute the set of external dependencies required by the 8 | ;system. 9 | public defn system-dependencies (platform:Symbol) -> ProjDependencies : 10 | val ccfiles = Vector() 11 | val ccflags = Vector() 12 | 13 | ;C Standard 14 | add(ccflags, "-std=gnu11") 15 | 16 | ;Use static linking on windows 17 | if platform == `windows : 18 | add(ccflags, "-Wl,-Bstatic") 19 | 20 | ;Math library 21 | add(ccflags, "-lm") 22 | 23 | ;PThread library 24 | if platform == `windows or platform == `linux : 25 | add(ccflags, "-lpthread") 26 | 27 | ;Position independence flag 28 | if platform == `linux : 29 | add(ccflags, "-ldl") 30 | add(ccflags, "-fPIC") 31 | 32 | ;Driver Platform flag 33 | add(ccflags, "-D") 34 | switch(platform) : 35 | `os-x : add(ccflags, "PLATFORM_OS_X") 36 | `linux : add(ccflags, "PLATFORM_LINUX") 37 | `windows : add(ccflags, "PLATFORM_WINDOWS") 38 | 39 | ;Pulling in GNU extensions for Linux 40 | if platform == `linux : 41 | add(ccflags, "-D_GNU_SOURCE") 42 | 43 | ;Include standard C++ library. 44 | switch(platform) : 45 | `os-x : add(ccflags, "-lc++") 46 | `linux : add(ccflags, "-lstdc++") 47 | `windows : add(ccflags, "-lstdc++") 48 | 49 | ;Stanza include dir 50 | add(ccflags, to-string("-I%_" % [system-filepath(StanzaIncludeDir)])) 51 | 52 | ;Driver file 53 | add(ccfiles, system-filepath(StanzaRuntimeDriver)) 54 | 55 | ;Return ccfiles and ccflags 56 | ProjDependencies( 57 | to-tuple(ccfiles), 58 | to-tuple(ccflags), 59 | []) -------------------------------------------------------------------------------- /compiler/terminal-style.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/terminal-style : 2 | import core 3 | 4 | ;- SimpleTerminal: Directly reads from standard input. 5 | ;- EditTerminal: Provides some basic editing features, e.g. backspace. 6 | public defenum TerminalStyle : 7 | SimpleTerminal 8 | EditTerminal 9 | 10 | ;Returns the default terminal style for the current 11 | ;platform. 12 | public defn default-terminal-style () -> TerminalStyle : 13 | #if-defined(PLATFORM-WINDOWS) : 14 | SimpleTerminal 15 | #else : 16 | EditTerminal 17 | 18 | ;Parse the given string and return the corresponding terminal style. 19 | public defn parse-terminal-style (str:String) -> TerminalStyle|False : 20 | switch(str) : 21 | "simple" : SimpleTerminal 22 | "edit" : EditTerminal 23 | else : false -------------------------------------------------------------------------------- /compiler/test-c-extern-trampoline.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-c-extern-trampoline : 2 | import core 3 | import collections 4 | import stz/c-extern-trampoline 5 | import stz/code-emitter 6 | import stz/asm-emitter 7 | import stz/backend 8 | import stz/asm-ir 9 | 10 | ;Return an appropriate backend for the current platform. 11 | defn current-backend () -> Backend : 12 | switch(CURRENT-PLATFORM) : 13 | Windows: W64Backend() 14 | OS-X: X64Backend() 15 | Linux: L64Backend() 16 | 17 | ;Return a new asm emitter that saves its instructions 18 | ;to a file. 19 | defn asm-emitter (body:CodeEmitter -> ?, filename:String, backend:Backend) -> False : 20 | val stream = FileOutputStream(filename) 21 | try : 22 | val label-counter = to-seq(0 to false) 23 | val emitter = new CodeEmitter : 24 | defmethod unique-label (this) : 25 | next(label-counter) 26 | defmethod emit (this, e:Ins) : 27 | emit-asm(current-output-stream(), e, backend) 28 | emit-asm(stream, e, backend) 29 | body(emitter) 30 | finally : 31 | close(stream) 32 | 33 | ;Main testing function. 34 | defn main () : 35 | val backend = current-backend() 36 | within emitter = asm-emitter("c-extern-code.s", backend) : 37 | compile-c-extern-dynamic-code-template(backend, emitter) 38 | compile-c-extern-trampoline-stub(backend, emitter) 39 | 40 | ;Launch! 41 | main() -------------------------------------------------------------------------------- /compiler/test-driver.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-driver 2 | stz/test-framework/print-test-report(true) -------------------------------------------------------------------------------- /compiler/test-dyn-graph.stanza: -------------------------------------------------------------------------------- 1 | defpackage test-dyn-graph : 2 | import core 3 | import collections 4 | import stz/dynamic-graph 5 | 6 | defn parse-edge-sets (forms) : 7 | match-syntax(forms) : 8 | ((edgeset ?ids:_ : ((?srcs => ?dsts) @...)) @...) : 9 | to-tuple $ for (id in ids, src in srcs, dst in dsts) seq : 10 | val edges = to-tuple(seq(Edge, src, dst)) 11 | EdgeSet(id as Int, edges) 12 | 13 | defn main () : 14 | val g = DynamicGraph() 15 | defn test (edges, nodes:Tuple) : 16 | defn make-node (n:Int) : 17 | new Node : 18 | defmethod id (this) : n 19 | defmethod compute-value (this, v0:Maybe) : 20 | println("Compute value of node %_ from inputs %," % [n, inputs(g,n)]) 21 | false 22 | val update = update(g, GraphChange(map(make-node,nodes), parse-edge-sets(edges))) 23 | println(g) 24 | 25 | test( 26 | `(edgeset 1 : 27 | 2 => 1 28 | 3 => 1 29 | 4 => 1 30 | edgeset 2 : () 31 | edgeset 3 : 32 | 5 => 3 33 | 6 => 3 34 | edgeset 4 : () 35 | edgeset 5 : () 36 | edgeset 6 : () 37 | edgeset 7 : 38 | 7 => 5 39 | 7 => 6) 40 | [1,2,3,4,5,6,7]) 41 | 42 | test( 43 | `(edgeset 7 : 44 | 7 => 4 45 | 7 => 5 46 | edgeset 1 : 47 | 3 => 1 48 | 4 => 1 49 | edgeset 2 : 50 | 2 => 3) 51 | []) 52 | 53 | 54 | 55 | main() -------------------------------------------------------------------------------- /compiler/test-dyn-tree.stanza: -------------------------------------------------------------------------------- 1 | defpackage test-dyn-tree : 2 | import core 3 | import collections 4 | import stz/dyn-tree 5 | 6 | defn main () : 7 | val t = DynTree() 8 | 9 | add{t, _} $ new TreeListener : 10 | defmethod node-changed (this, n:Int) : 11 | println("Node %_ changed:" % [n]) 12 | println(" Leaves = %_" % [all-leaves(t,n)]) 13 | println(" Children = %_" % [all-children(t,n)]) 14 | 15 | defn print-state (name) : 16 | println(name) 17 | println(t) 18 | for i in 1 through 7 do : 19 | println("All children of %_ = %," % [i, all-children(t,i)]) 20 | println("All leaves of %_ = %," % [i, all-leaves(t,i)]) 21 | 22 | add(t, [ 23 | NodeState(1, [], [2, 3, 4], false) 24 | NodeState(2, [], [], true) 25 | NodeState(3, [], [5,6], false) 26 | NodeState(4, [], [], false) 27 | NodeState(5, [], [], false) 28 | NodeState(6, [], [], false) 29 | NodeState(7, [5,6], [], true) 30 | ]) 31 | print-state("Initial Tree") 32 | 33 | add(t, [ 34 | NodeState(7, [4,5], [], true) 35 | NodeState(1, [], [3,4], false) 36 | NodeState(2, [3], [], true) 37 | ]) 38 | print-state("After Moving") 39 | 40 | add(t, [ 41 | NodeState(2, [4], [], true) 42 | ]) 43 | print-state("Done") 44 | 45 | main() -------------------------------------------------------------------------------- /compiler/test-fastio-buffer.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-fastio-buffer : 2 | import core 3 | import collections 4 | import stz/fastio-buffer 5 | 6 | defn flush (b:FastIOBuffer) : 7 | false 8 | 9 | lostanza defn write (b:ref, x:ref) -> ref : 10 | return write-int(b, x.value) 11 | 12 | lostanza defn read-Int (b:ref) -> ref : 13 | return new Int{read-int(b)} 14 | 15 | defn main () : 16 | val buffer = FastIOBuffer(4 * 1024) 17 | val num-iters = 100 18 | val num-i = 1000000 19 | val t0 = current-time-us() 20 | for iter in 0 to num-iters do : 21 | for i in 0 to num-i do : 22 | write(buffer, i) 23 | val t1 = current-time-us() 24 | println("Time: %_ us" % [t1 - t0]) 25 | println("Elements per Microsecond: %_" % [to-long(num-iters * num-i) / (t1 - t0)]) 26 | 27 | val readbuf = read-from(buffer) 28 | for iter in 0 to num-iters do : 29 | for i in 0 to num-i do : 30 | println(read-Int(readbuf)) 31 | 32 | main() -------------------------------------------------------------------------------- /compiler/test-fastio-code-transforms.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-fastio-code-transforms : 2 | import core 3 | import collections 4 | import stz/fastio-serializer-lang-parser 5 | import stz/fastio-serializer-lang 6 | import stz/fastio-code-transforms 7 | 8 | defn main () : 9 | val filename = command-line-arguments()[1] 10 | val forms = reader/read-file(filename) 11 | val parsed = parse-syntax[fastio-serializer-lang / #defserializer](forms) 12 | println("##### PARSED #####\n%_" % [Indented(parsed)]) 13 | val transformed = lift-combinators(parsed) 14 | println("##### LIFTED COMBINATORS #####\n%_" % [Indented(transformed)]) 15 | 16 | set-command-line-arguments(["parse" "testdata/serializer-lang-ir.txt"]) 17 | main() -------------------------------------------------------------------------------- /compiler/test-fastio-deftable.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-fastio-deftable : 2 | import core 3 | import collections 4 | import stz/fastio-serializer-lang-parser 5 | import stz/fastio-serializer-lang 6 | import stz/fastio-deftable 7 | 8 | defn parse-file (filename:String) : 9 | val forms = reader/read-file(filename) 10 | parse-syntax[fastio-serializer-lang / #defserializer](forms) 11 | 12 | var table:DefTable 13 | 14 | defn main () : 15 | val filename = command-line-arguments()[1] 16 | val parsed = parse-file(filename) 17 | table = DefTable(parsed) 18 | 19 | val lit = NamedSpec(`lit) 20 | val tuple-lit = CombinatorSpec(`tuple, [lit]) 21 | val optional-lit = CombinatorSpec(`optional, [lit]) 22 | val tuple-optional-lit = CombinatorSpec(`tuple, [optional-lit]) 23 | 24 | defn print-type (s:IOSpec) : 25 | println("Type of %_: %_" % [s, type(table,s)]) 26 | 27 | defn print-size (name:Symbol) : 28 | println("Size of %_: %_" % [name, size(table,name)]) 29 | 30 | print-type(lit) 31 | print-type(tuple-lit) 32 | print-type(optional-lit) 33 | print-type(tuple-optional-lit) 34 | 35 | print-size(`int) 36 | print-size(`int2) 37 | print-size(`int3) 38 | print-size(`byte) 39 | print-size(`lit) 40 | print-size(`myunion) 41 | print-size(`myunion2) 42 | print-size(`mystruct) 43 | print-size(`mystruct3) 44 | 45 | set-command-line-arguments(["parse" "testdata/serializer-lang-ir.txt"]) 46 | main() -------------------------------------------------------------------------------- /compiler/test-fastio-serializer-lang-parser.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-fastio-serializer-lang-parser : 2 | import core 3 | import collections 4 | import stz/fastio-serializer-lang-parser 5 | import stz/fastio-serializer-lang 6 | 7 | defn main () : 8 | val filename = command-line-arguments()[1] 9 | val forms = reader/read-file(filename) 10 | val parsed = parse-syntax[fastio-serializer-lang / #defserializer](forms) 11 | println(parsed) 12 | 13 | set-command-line-arguments(["parse" "testdata/serializer-lang-ir.txt"]) 14 | main() -------------------------------------------------------------------------------- /compiler/test-fastio-to-codegen-ir.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-fastio-to-codegen-ir : 2 | import core 3 | import collections 4 | import stz/fastio-serializer-lang-parser 5 | import stz/fastio-code-transforms 6 | import stz/fastio-to-codegen-ir 7 | import stz/fastio-codegen 8 | 9 | ;DEBUGGING 10 | within (package,sig) = set-stack-trace-filter() : 11 | package != `core 12 | 13 | defn main () : 14 | val filename = command-line-arguments()[1] 15 | val forms = reader/read-file(filename) 16 | val parsed = parse-syntax[fastio-serializer-lang / #defserializer](forms) 17 | val transformed = lift-combinators(parsed) 18 | val code-ir = to-codegen-ir(transformed) 19 | val form = wrap-sexp-in-defpackage(to-sexp(code-ir)) 20 | spit("build/test-program.stanza", form) 21 | call-system("stanza", ["stanza", "run", "compiler/stanza.proj", "build/test-program.stanza"]) 22 | 23 | defn wrap-sexp-in-defpackage (form) : 24 | qquote( 25 | defpackage test-program : 26 | import core 27 | import collections 28 | 29 | ~ form) 30 | 31 | set-command-line-arguments(["parse" "testdata/serializer-lang-ir.txt"]) 32 | main() -------------------------------------------------------------------------------- /compiler/test-overlap-table.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-overlap-table : 2 | import core 3 | import collections 4 | import stz/overlap-table 5 | 6 | defn main () : 7 | val table = OverlapTable(10, 2) 8 | add-group(table, 0, `(0 1 2 3)) 9 | add-group(table, 0, `(4 5 6 7)) 10 | add-group(table, 1, `(2 3 4 5)) 11 | add-group(table, 1, `(6 7 8 9)) 12 | add-pairwise(table, 1, 1, 2) 13 | within (x,y) = all-overlaps(table) : 14 | println("Overlap %_,%_" % [x,y]) 15 | 16 | main() -------------------------------------------------------------------------------- /compiler/test-timing-log-commands.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/test-timing-log-commands : 2 | import core 3 | import collections 4 | import stz/timing-log-commands 5 | 6 | defn main () : 7 | let loop () : 8 | match(read-command()) : 9 | (c:QuitCommand) : 10 | false 11 | (c:Command) : 12 | println(c) 13 | loop() 14 | (e:CommandException) : 15 | println(e) 16 | loop() 17 | 18 | main() 19 | 20 | -------------------------------------------------------------------------------- /compiler/timing-log-options.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/timing-log-options : 2 | import core 3 | import collections 4 | 5 | public defstruct ViewOptions <: Equalable&Hashable : 6 | sorting:SortOrder with: (updater => sub-sorting) 7 | grouping:GroupType with: (updater => sub-grouping) 8 | with: 9 | equalable => true 10 | hashable => true 11 | 12 | public defenum SortOrder : 13 | SortByTime 14 | SortByDuration 15 | 16 | public deftype GroupType <: Equalable&Hashable 17 | 18 | public defstruct NoGrouping <: GroupType 19 | with: 20 | equalable => true 21 | hashable => true 22 | 23 | public defstruct GroupById <: GroupType 24 | with: 25 | equalable => true 26 | hashable => true 27 | 28 | public defstruct GroupByParents <: GroupType : 29 | parents:Tuple 30 | with: 31 | equalable => true 32 | hashable => true 33 | 34 | public defstruct GroupAllByParents <: GroupType : 35 | parents:Tuple 36 | with: 37 | equalable => true 38 | hashable => true -------------------------------------------------------------------------------- /compiler/type-capside.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/type-capside : 2 | import core 3 | 4 | ;Represents the side that the capturing variable is on. 5 | public defenum CapSide : 6 | CapLeft 7 | CapRight 8 | 9 | ;Flip the direction. 10 | public defn opp (s:CapSide) -> CapSide : 11 | CapRight when s == CapLeft else CapLeft -------------------------------------------------------------------------------- /compiler/type-locs.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/type-locs : 2 | import core 3 | 4 | ;Inference Locations: 5 | ;- TupleLoc: A specific element within a tuple. 6 | ;- ArgLoc: A specific argument within a lambda. 7 | ;- ReturnLoc: The return value of a lambda. 8 | public deftype InferLoc 9 | 10 | public defstruct TupleLoc <: InferLoc : 11 | arity:Int 12 | index:Int 13 | 14 | public defstruct ArgLoc <: InferLoc : 15 | arity:Int 16 | index:Int 17 | 18 | public defstruct ReturnLoc <: InferLoc : 19 | arity:Int 20 | 21 | defmethod print (o:OutputStream, l:TupleLoc) : 22 | print(o, "tuple-slot(%_ of %_)" % [index(l), arity(l)]) 23 | 24 | defmethod print (o:OutputStream, l:ArgLoc) : 25 | print(o, "arg(%_ of %_)" % [index(l), arity(l)]) 26 | 27 | defmethod print (o:OutputStream, l:ReturnLoc) : 28 | print(o, "ret(%_)" % [arity(l)]) 29 | -------------------------------------------------------------------------------- /compiler/type-match.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/type-match : 2 | import core 3 | 4 | ;Used to represent that an overloaded match partially matches 5 | ;due to the usage of gradual expansion. 6 | public defstruct PartialMatch <: Equalable 7 | with: (equalable => true) 8 | 9 | -------------------------------------------------------------------------------- /compiler/type-variance.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/type-variance : 2 | import core 3 | import collections 4 | import stz/types 5 | 6 | ;A covariance/contravariance selector. 7 | public defenum Variance : 8 | Covariant 9 | Contravariant 10 | 11 | ;Flip the variance. 12 | public defn flip (v:Variance) -> Variance : 13 | Contravariant when v == Covariant else Covariant 14 | 15 | ;Indicate that a type appears in both variance positions. 16 | public defstruct Bivariant 17 | 18 | ;Detect all the variances in the given types. 19 | public defn variances (ts:Seqable, initial-v:Variance) -> IntTable : 20 | ;Collect all the variances here. 21 | val table = IntTable() 22 | 23 | ;Record the variance of the given variable. 24 | defn record (n:Int, v:Variance) -> False : 25 | val new-v = match(get?(table,n)) : 26 | (old-v:Bivariant) : 27 | old-v 28 | (old-v:Variance) : 29 | if v == old-v : v 30 | else : Bivariant() 31 | (f:False) : 32 | v 33 | table[n] = new-v 34 | 35 | ;Scan the given type assuming it appears in variance position v. 36 | defn scan (t:Type|LSType|False, v:Variance) -> False : 37 | match(t) : 38 | (t:TCap) : 39 | record(n(t), v) 40 | (t:TArrow) : 41 | val inv-v = flip(v) 42 | do(scan{_, inv-v}, a1(t)) 43 | scan(a2(t), v) 44 | (t:FnT) : 45 | val inv-v = flip(v) 46 | do(scan{_, inv-v}, a(t)) 47 | scan(r(t), inv-v) 48 | scan(b(t), v) 49 | (t:Type|LSType): 50 | do(scan{_ as Type|LSType, v}, t) 51 | (f:False) : 52 | false 53 | 54 | ;Launch! 55 | do(scan{_, initial-v}, ts) 56 | table -------------------------------------------------------------------------------- /compiler/verbose.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/verbose : 2 | import core 3 | import collections 4 | 5 | ;Represents the program verbosity level. 6 | var VERBOSE-LEVEL:Int = 0 7 | 8 | ;Return true if verbose is on. 9 | public defn verbose-setting? () -> True|False : 10 | VERBOSE-LEVEL > 0 11 | 12 | ;Run the given body with the given verbosity setting. 13 | public defn run-with-verbose-level (body:() -> ?T, level:Int) -> T : 14 | let-var VERBOSE-LEVEL = level : 15 | body() 16 | 17 | ;Main functions for testing the verbosity level 18 | ;and then printing. 19 | 20 | #for (vprintf in [vprint vprintln vlnprint] 21 | printf in [print println lnprint]) : 22 | 23 | public defn vprintf (o:OutputStream, level:Int, x) : 24 | if VERBOSE-LEVEL >= level : 25 | printf(o, x) 26 | 27 | public defn vprintf (o:OutputStream, x) : 28 | vprintf(o, 1, x) 29 | 30 | public defn vprintf (level:Int, x) : 31 | vprintf(current-output-stream(), level, x) 32 | 33 | public defn vprintf (x) : 34 | vprintf(current-output-stream(), 1, x) -------------------------------------------------------------------------------- /compiler/visibility.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/visibility : 2 | import core 3 | 4 | public defenum Visibility : 5 | Private 6 | Protected 7 | Public -------------------------------------------------------------------------------- /core/core.txt: -------------------------------------------------------------------------------- 1 | Description of the Core Libraries 2 | 3 | @[file:macro-utils.stanza] 4 | @[file:sha256.stanza] 5 | @[file:reader.stanza] 6 | @[file:collections.stanza] 7 | @[file:parser.stanza] 8 | @[file:stanza.proj] 9 | @[file:core.stanza] 10 | @[file:sha256.c] 11 | -------------------------------------------------------------------------------- /core/dynamic-library.c: -------------------------------------------------------------------------------- 1 | #if defined(PLATFORM_WINDOWS) 2 | #include 3 | #include 4 | 5 | void* load_library(const stz_byte* name) { 6 | return (void*)LoadLibrary((LPCSTR)name); 7 | } 8 | 9 | stz_int free_library(void* handle) { 10 | if (!FreeLibrary((HMODULE)handle)) { 11 | return -1; 12 | } 13 | return 0; 14 | } 15 | 16 | void* get_proc_address(void* handle, const stz_byte* name) { 17 | return (void*)GetProcAddress((HMODULE)handle, (LPCSTR)name); 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /core/line-prompter.stanza: -------------------------------------------------------------------------------- 1 | defpackage core/line-prompter : 2 | import core 3 | import reader 4 | 5 | public defn LinePrompter (prompt:String, continue:String) -> Prompter: 6 | 7 | val buffer = StringBuffer() 8 | defn read-line (s:InputStream) -> String|False: 9 | clear(buffer) 10 | defn* loop () -> String|False : 11 | val c = get-char(s) 12 | match(c:Char): 13 | if c == '\n': 14 | to-string(buffer) 15 | else: 16 | add(buffer, c) 17 | loop() 18 | loop() 19 | 20 | val line-counter = to-seq(0 to false) 21 | new Prompter : 22 | defmethod get-line (this) -> String|False : 23 | val msg = prompt when next(line-counter) == 0 24 | else continue 25 | print(STANDARD-OUTPUT-STREAM, msg) 26 | flush(STANDARD-OUTPUT-STREAM as FileOutputStream) 27 | read-line(STANDARD-INPUT-STREAM) 28 | -------------------------------------------------------------------------------- /core/meta-utils.stanza: -------------------------------------------------------------------------------- 1 | defpackage core/meta-utils : 2 | import core 3 | 4 | ;============================================================ 5 | ;=================== MetaUtils Type ========================= 6 | ;============================================================ 7 | 8 | public deftype HasMetaUtils 9 | 10 | public defmulti field-values (x:HasMetaUtils) -> Tuple 11 | 12 | public defmulti field-names (x:HasMetaUtils) -> Tuple 13 | 14 | public defmulti field-accessors (x:HasMetaUtils) -> Tuple<(HasMetaUtils -> ?)> 15 | 16 | public defmulti field-entries (x:HasMetaUtils) -> Tuple> -------------------------------------------------------------------------------- /core/parser/context.stanza: -------------------------------------------------------------------------------- 1 | defpackage parser/context : 2 | import core 3 | 4 | public deftype Context 5 | public defmulti get-all (c:Context) -> ? 6 | public defmulti get (c:Context, i:Int) -> ? 7 | public defmulti info (c:Context) -> FileInfo|False 8 | 9 | public defn closest-info (form) -> FileInfo|False : 10 | match(form) : 11 | (form:Token) : info(form) 12 | (form:List) : find-by(seq(closest-info, form)) 13 | (form) : false 14 | 15 | public defn info (c:Context, form) -> FileInfo|False : 16 | match(closest-info(form)) : 17 | (i:FileInfo) : i 18 | (f:False) : info(c) -------------------------------------------------------------------------------- /core/parser/core-macroexpander.stanza: -------------------------------------------------------------------------------- 1 | defpackage parser/core-macroexpander : 2 | import core 3 | import collections 4 | import parser/macroexpander 5 | 6 | ;Use this late-bound macroexpander to handle: 7 | ; #use-added-syntax, #use-syntax, #with-added-syntax, #with-syntax 8 | ;macros. 9 | var CORE-MACROEXPANDER:Macroexpander = SimpleMacroexpander() 10 | 11 | ;Retrieve the core macroexpander. 12 | public defn core-macroexpander () : 13 | CORE-MACROEXPANDER 14 | 15 | ;Temporarily set the core macroexpander. 16 | public defn with-core-macroexpander (body:() -> ?T, expander:Macroexpander) : 17 | let-var CORE-MACROEXPANDER = expander : 18 | body() -------------------------------------------------------------------------------- /core/parser/macro-runtime.stanza: -------------------------------------------------------------------------------- 1 | defpackage parser/macro-runtime : 2 | import core 3 | import collections 4 | 5 | ;============================================================ 6 | ;================== Type Builders =========================== 7 | ;============================================================ 8 | 9 | protected defn list-type (f: () -> ?T) -> (() -> List) : 10 | f as ? as () -> List 11 | 12 | protected defn union-type (g: () -> ?T, h: () -> ?S) -> (() -> T|S) : 13 | g as ? as () -> T|S -------------------------------------------------------------------------------- /core/parser/macroexpander.stanza: -------------------------------------------------------------------------------- 1 | defpackage parser/macroexpander : 2 | import core 3 | import collections 4 | import parser/syntax-package-registry 5 | 6 | ;============================================================ 7 | ;====================== API ================================= 8 | ;============================================================ 9 | 10 | ;Utility type that can expand macros. 11 | public deftype Macroexpander 12 | 13 | ;Expand the given form using the given overlays. 14 | public defmulti macroexpand (e:Macroexpander, form, overlays:List) -> ? 15 | 16 | ;============================================================ 17 | ;====================== Convenience ========================= 18 | ;============================================================ 19 | 20 | ;Default overlays is empty. 21 | public defn macroexpand (e:Macroexpander, form) -> ? : 22 | macroexpand(e, form, List()) 23 | 24 | ;============================================================ 25 | ;================== SimpleMacroexpander ===================== 26 | ;============================================================ 27 | 28 | ;Return the default SimpleMacroexpander. 29 | ;Simply calls syntax-parse. 30 | public defn SimpleMacroexpander () : 31 | new Macroexpander : 32 | defmethod macroexpand (this, form, overlay-specifiers:List) : 33 | syntax-parse(`core, overlay-specifiers, List(form), `exp, false) -------------------------------------------------------------------------------- /core/parser/merged-syntax-package.stanza: -------------------------------------------------------------------------------- 1 | defpackage parser/merged-syntax-package : 2 | import core 3 | import collections 4 | import parser/patterns 5 | 6 | ;============================================================ 7 | ;=============== Datastructure Definition =================== 8 | ;============================================================ 9 | 10 | public defstruct MergedSyntaxPackage : 11 | base: Symbol 12 | productions: Tuple 13 | 14 | public defstruct MergedProduction : 15 | public?: True|False 16 | id:Int 17 | package: Symbol 18 | name: Symbol 19 | patterns: Tuple 20 | 21 | ;============================================================ 22 | ;==================== Printer =============================== 23 | ;============================================================ 24 | 25 | defmethod print (o:OutputStream, p:MergedProduction) : 26 | val items = [ 27 | "package: %_" % [package(p)] 28 | "name: %_" % [name(p)] 29 | "patterns:\n%_" % [indented-items(patterns(p))]] 30 | val public-str = "public " when public?(p) else "" 31 | print(o, "%_prod %_\n%_" % [public-str, id(p), indented-items(items)]) 32 | 33 | defmethod print (o:OutputStream, p:MergedSyntaxPackage) : 34 | val items = cat-all $ [ 35 | ["base: %_" % [base(p)]] 36 | productions(p)] 37 | print(o, "merged-syntax-package:\n%_" % [indented-items(items)]) 38 | 39 | defn indented-items (xs:Seqable) : 40 | Indented("%n" % [xs]) -------------------------------------------------------------------------------- /core/parser/syntax-packages.stanza: -------------------------------------------------------------------------------- 1 | defpackage parser/syntax-packages : 2 | import core 3 | import collections 4 | import parser/patterns 5 | 6 | ;============================================================ 7 | ;=================== API Definition ========================= 8 | ;============================================================ 9 | 10 | public defstruct SyntaxPackage : 11 | name: Symbol 12 | imports: List 13 | productions: List 14 | import-rules: List 15 | rules: List 16 | 17 | public defstruct DefImport : 18 | names: List 19 | package: Symbol 20 | public?: True|False 21 | 22 | public defstruct ImportRules : 23 | name: Symbol 24 | new-name: Symbol 25 | 26 | public defstruct DefProduction : 27 | name: Symbol 28 | public?: True|False 29 | 30 | public defstruct DefRule : 31 | name: Symbol 32 | pattern: Pattern 33 | 34 | ;============================================================ 35 | ;=================== Printers =============================== 36 | ;============================================================ 37 | 38 | defmethod print (o:OutputStream, p:SyntaxPackage) : 39 | println(o, "defsyntax %_ :" % [name(p)]) 40 | for io in o do-indented : 41 | do(println{io, _}, imports(p)) 42 | do(println{io, _}, productions(p)) 43 | do(println{io, _}, import-rules(p)) 44 | do(println{io, _}, rules(p)) 45 | 46 | defmethod print (o:OutputStream, i:ImportRules) : 47 | print(o, "import %_ rules as %_" % [name(i), new-name(i)]) 48 | 49 | defmethod print (o:OutputStream, i:DefImport) : 50 | val public-str = "public " when public?(i) else "" 51 | print(o, "%_import %, from %_" % [public-str, names(i), package(i)]) 52 | 53 | defmethod print (o:OutputStream, p:DefProduction) : 54 | print(o, "%_defproduction %_" % [ 55 | "public " when public?(p) else "" 56 | name(p)]) 57 | 58 | defmethod print (o:OutputStream, r:DefRule) : 59 | print(o, "defrule %_ = %_" % [name(r), pattern(r)]) -------------------------------------------------------------------------------- /core/parser/timers.stanza: -------------------------------------------------------------------------------- 1 | defpackage parser/timers : 2 | import core 3 | import stz/timing-log-api 4 | 5 | public val PARSER-ENGINE = TimerLabel("Parser engine") 6 | public val PARSER-INTERPRET = TimerLabel(PARSER-ENGINE, suffix("Interpret")) 7 | public val PARSER-EVAL = TimerLabel(PARSER-ENGINE, suffix("Eval")) 8 | public val PARSER-PARSE-VALUE-STACK = TimerLabel(PARSER-ENGINE, suffix("Parse Value Stack")) -------------------------------------------------------------------------------- /core/sha256.stanza: -------------------------------------------------------------------------------- 1 | defpackage core/sha256 : 2 | import core 3 | import collections 4 | 5 | ;============================================================ 6 | ;======================== Driver ============================ 7 | ;============================================================ 8 | 9 | public lostanza defn sha256-hash (bytes:ref) -> ref : 10 | val out = ByteArray(new Int{32}) 11 | call-c calc_sha_256(addr!(out.data), addr!(bytes.data), bytes.length) 12 | return out 13 | 14 | public defn sha256-hash-file (filename:String) -> ByteArray : 15 | sha256-hash(read-bytes(filename)) 16 | 17 | ;============================================================ 18 | ;=================== External Function ====================== 19 | ;============================================================ 20 | extern calc_sha_256: (ptr, ptr, long) -> int 21 | 22 | defn read-bytes (filename:String) : 23 | val file = RandomAccessFile(filename, false) 24 | try : 25 | val len = truncate-filesize(length(file)) 26 | val bytes = ByteArray(len) 27 | fill(bytes, file) 28 | bytes 29 | finally : 30 | close(file) 31 | 32 | defn truncate-filesize (x:Long) : 33 | val max = to-long(INT-MAX) 34 | fatal("File is too big for current implementation.") when x > max 35 | to-int(x) -------------------------------------------------------------------------------- /core/stanza.proj: -------------------------------------------------------------------------------- 1 | package collections defined-in "collections.stanza" 2 | package clib defined-in "core.stanza" 3 | package core defined-in "core.stanza" 4 | package math defined-in "core.stanza" 5 | package macro-utils defined-in "macro-utils.stanza" 6 | packages parser/* defined-in "parser" 7 | package reader defined-in "reader.stanza" 8 | package arg-parser defined-in "arg-parser.stanza" 9 | package line-wrap defined-in "line-wrap.stanza" 10 | packages core/* defined-in "." -------------------------------------------------------------------------------- /docs/usage-docs.md: -------------------------------------------------------------------------------- 1 | # Usage Documentation # 2 | 3 | These documents explain how to use parts of the Stanza system. 4 | 5 | @[file:build-system.md] Explains how to use `.proj` files and Stanza's automatic build system. 6 | @[file:test-framework.md] Explains how to use Stanza's automatic test facility. 7 | @[file:mocking-utility.md] Explains how to use Stanza's mocking utility. 8 | @[file:check-docs.md] Explains how to use Stanza's document consistency checker. 9 | -------------------------------------------------------------------------------- /examples/cffi.stanza: -------------------------------------------------------------------------------- 1 | defpackage cffi : 2 | import core 3 | import collections 4 | 5 | extern c_sum: (int, int) -> int 6 | 7 | lostanza defn sum (a:ref, b:ref) -> ref : 8 | val result = call-c c_sum(a.value, b.value) 9 | return new Int{result} 10 | 11 | defn main () : 12 | println("The sum from 10 to 41 is %_." % [sum(10, 41)]) 13 | 14 | main() -------------------------------------------------------------------------------- /examples/closure.stanza: -------------------------------------------------------------------------------- 1 | defpackage closure : 2 | import core 3 | import collections 4 | import stz/algorithms 5 | 6 | defn main () : 7 | defn E (k:String, vs:Tuple) : k => to-list(vs) 8 | val closure = strong-components $ [ 9 | E("A", ["B" "C" "F"]) 10 | E("B", ["D"]) 11 | E("D", ["C", "F"]) 12 | E("C", ["B"]) 13 | E("F", ["H"]) 14 | E("H", ["I", "E"]) 15 | E("I", ["G"]) 16 | E("G", ["F"]) 17 | E("E", [])] 18 | do(println, closure) 19 | 20 | main() 21 | -------------------------------------------------------------------------------- /examples/csum.c: -------------------------------------------------------------------------------- 1 | int c_sum (int start, int end){ 2 | int accum = 0; 3 | for(int i=start; i>(List()) 20 | defn put-table (d:Direction, x:Int) : 21 | update(table, cons{x, _}, d) 22 | 23 | put-table(N, 0) 24 | put-table(E, 1) 25 | put-table(S, 5) 26 | put-table(W, 11) 27 | put-table(E, 13) 28 | put-table(W, 3) 29 | put-table(S, 7) 30 | put-table(S, 0) 31 | put-table(W, 13) 32 | put-table(N, 11) 33 | put-table(N, 18) 34 | put-table(E, 19) 35 | put-table(W, 20) 36 | put-table(E, 21) 37 | put-table(N, 1) 38 | 39 | for entry in table do : 40 | val dir = key(entry) 41 | val nums = value(entry) 42 | println("The entries corresponding to direction %_ are %,." % [dir, nums]) 43 | 44 | deftest enums-as-types : 45 | defn test (d:Direction) : 46 | match(d) : 47 | (d:N|E) : println("%_ is either N or E." % [d]) 48 | (d:S|W) : println("%_ is either S or W." % [d]) 49 | match(d) : 50 | (d:N|W) : println("%_ is either N or W." % [d]) 51 | (d:S|E) : println("%_ is either S or E." % [d]) 52 | 53 | test(N) 54 | test(S) 55 | test(E) 56 | test(W) 57 | 58 | -------------------------------------------------------------------------------- /examples/examples.txt: -------------------------------------------------------------------------------- 1 | Example Programs 2 | 3 | @[file:stanza.proj] Standard Stanza file listing. 4 | @[file:simpletests.stanza] Example of simple tests using the test framework. 5 | @[file:simplemock.stanza] Example of using the mocking utility to write a test. 6 | @[file:cffi.stanza] Example of Using the FFI to Call a C function 7 | @[file:csum.c] C function to call 8 | @[file:helloworld.stanza] Simple hello world 9 | @[file:string.stanza] String handling example 10 | @[file:triforce.stanza] Print out the Triforce 11 | @[file:dispatch.stanza] Calculating a compiler dispatch table 12 | @[file:sort.stanza] Simple selection sort 13 | @[file:enums.stanza] Examples of using enums 14 | @[file:calculus.stanza] Example of automatic differentiation 15 | @[file:closure.stanza] Example of computing strongly connected-components 16 | 17 | -------------------------------------------------------------------------------- /examples/generate-numbers/gen-numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void generate_integers (void (*callback)(int32_t), int32_t low, int32_t high){ 6 | printf("Generating integers between %d and %d.\n", low, high); 7 | for (int32_t i=low; i<=high; i++) 8 | callback(i); 9 | printf("Finished generation.\n"); 10 | } 11 | 12 | void generate_floats (void (*callback)(double), double low, double high, int n){ 13 | printf("Generating %d floats between %g and %g.\n", n, low, high); 14 | for (int i=0; i load gen-numbers 18 | -------------------------------------------------------------------------------- /examples/generate-numbers/stanza.proj: -------------------------------------------------------------------------------- 1 | package gen-numbers defined-in "gen-numbers.stanza" 2 | 3 | package gen-numbers requires : 4 | dynamic-library: 5 | on-platform: 6 | windows: "mylib.dll" 7 | else: "mylib.so" 8 | 9 | dynamic-library-dirs: 10 | "." -------------------------------------------------------------------------------- /examples/helloworld.stanza: -------------------------------------------------------------------------------- 1 | defpackage helloworld : 2 | import core 3 | 4 | println("Hello World") -------------------------------------------------------------------------------- /examples/simpletests.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage simple-tests : 3 | import core 4 | import collections 5 | 6 | ;Correct implementation of sum 7 | defn compute-sum (a:Int, b:Int, c:Int) : 8 | a + b + c 9 | 10 | ;Incorrect implementation of sum 11 | defn bad-compute-sum (a:Int, b:Int, c:Int): 12 | a + b * c 13 | 14 | ;Correct implementation of product 15 | defn compute-product (a:Int, b:Int) : 16 | a * b 17 | 18 | ;Test sum function with one set of inputs. 19 | deftest sum1 : 20 | #ASSERT(compute-sum(1,2,3) == 6) 21 | 22 | ;Test sum function with another set of inputs. 23 | deftest sum2 : 24 | println("Compute bad sum") 25 | #ASSERT(bad-compute-sum(1,2,3) == 6) 26 | 27 | ;Test product function with three sets of inputs. 28 | ;Use a generated name to name the test. 29 | for a in [2 3 4] do : 30 | deftest(product-tests) (to-string("product: a = %_" % [a])) : 31 | #ASSERT(compute-product(a, 10) == a * 10) 32 | 33 | ;Tag a given test as 'flaky'. 34 | deftest(flaky) bad-test : 35 | #ASSERT(rand(10) < 8) 36 | 37 | ;Using expect instead of assert 38 | deftest test-expect : 39 | val counter = to-seq(0 to false) 40 | #EXPECT(next(counter) == 0) 41 | #EXPECT(next(counter) == 1) 42 | #EXPECT(next(counter) == 2) 43 | #EXPECT(next(counter) == 2) 44 | #EXPECT(next(counter) == 2) 45 | 46 | ;Using and/or expressions in assertions 47 | deftest test-and-or : 48 | val x = 3 49 | val y = 4 50 | val z = 5 51 | val w = 6 52 | #EXPECT(x == 2 or x == 5) 53 | #EXPECT(x == 3 and y == 6) 54 | #EXPECT(x == 3 and y == 4 and z == 6 and w == 7) -------------------------------------------------------------------------------- /examples/sort.stanza: -------------------------------------------------------------------------------- 1 | defpackage sort : 2 | import core 3 | import collections 4 | 5 | ; Simple Selection Sort 6 | ; ===================== 7 | 8 | defn selection-sort (xs:Array) : 9 | val n = length(xs) 10 | for i in 0 to (n - 1) do : 11 | var min-idx = i 12 | var min-val = xs[i] 13 | for j in (i + 1) to n do : 14 | if xs[j] < min-val : 15 | min-idx = j 16 | min-val = xs[j] 17 | if i != min-idx : 18 | xs[min-idx] = xs[i] 19 | xs[i] = min-val 20 | 21 | val xs = to-array([1, 3, 2, 5, -1, -7, 3, 8, 11, 9]) 22 | println("Before Sorting: %_" % [xs]) 23 | selection-sort(xs) 24 | println("After Sorting: %_" % [xs]) -------------------------------------------------------------------------------- /examples/stanza.proj: -------------------------------------------------------------------------------- 1 | package triforce defined-in "triforce.stanza" 2 | package calculus defined-in "calculus.stanza" 3 | package helloworld defined-in "helloworld.stanza" 4 | package closure defined-in "closure.stanza" 5 | package sort defined-in "sort.stanza" 6 | package string-handling defined-in "string.stanza" 7 | package dispatch defined-in "dispatch.stanza" 8 | package cffi defined-in "cffi.stanza" 9 | package cffi requires : 10 | ccfiles: "csum.c" 11 | package simple-tests defined-in "simpletests.stanza" -------------------------------------------------------------------------------- /examples/string.stanza: -------------------------------------------------------------------------------- 1 | defpackage string-handling : 2 | import core 3 | import collections 4 | 5 | defn main () : 6 | val string = "Hello world 17 ah ha!" 7 | val i = index-of-chars(string, "world") 8 | println("The substring 'world' is at index %_." % [i]) 9 | 10 | val j = index-of-chars(string, (i as Int) to false, "ah") 11 | println("The first occurrence of 'ah' after 'world' is at index %_." % [j]) 12 | 13 | val num-start = (i as Int) + length("world") 14 | val num-str = string[num-start to (j as Int)] 15 | val num = to-int(trim(num-str)) 16 | println("The parsed number between 'world' and 'ah' is %_." % [num]) 17 | 18 | main() -------------------------------------------------------------------------------- /examples/triforce.stanza: -------------------------------------------------------------------------------- 1 | defpackage triforce : 2 | import core 3 | import collections 4 | 5 | ; Using Sequences to Make Ascii Art 6 | ; ================================= 7 | 8 | ;Returns a sequence of functions, that when called in order 9 | ;draws a triangle. 10 | defn triangle (n:Int) : 11 | for i in 0 to n seq : 12 | fn () : 13 | val m = i * 2 + 1 14 | do(print{' '}, 0 to (n - i - 1)) 15 | do(print{'*'}, 0 to m) 16 | do(print{' '}, 0 to (n - i - 1)) 17 | 18 | ;Takes a sequence of functions and returns a new sequence of 19 | ;functions that draws the original shape padded with left 20 | ;leading spaces and right trailing spaces. 21 | defn pad (xs:Seqable<(() -> False)>, left:Int, right:Int) : 22 | for x in xs seq : 23 | fn () : 24 | do(print{' '}, 0 to left) 25 | x() 26 | do(print{' '}, 0 to right) 27 | 28 | ;Takes two shapes represented as sequences of functions, and 29 | ;returns a new sequence of functions that will draw the 30 | ;first shape to the left of the second shape. 31 | defn beside (xs:Seqable<(() -> False)>, ys:Seqable<(() -> False)>) : 32 | for (x in xs, y in ys) seq : 33 | fn () : 34 | x() 35 | y() 36 | 37 | ;Draw a shape represented as a sequence of functions. 38 | defn display (xs:Seqable<(() -> False)>) : 39 | for x in xs do : 40 | x() 41 | print('\n') 42 | 43 | ;Triforce shape. 44 | defn triforce (n:Int) : 45 | val top = pad(triangle(n), n, n) 46 | val bottom = beside(triangle(n), pad(triangle(n), 1, 0)) 47 | cat(top, bottom) 48 | 49 | ;Big triforce shape. 50 | defn big-triforce (n:Int) : 51 | val top = pad(triforce(n), n * 2, n * 2) 52 | val bottom = beside(triforce(n), pad(triforce(n), 1, 0)) 53 | cat(top, bottom) 54 | 55 | ;Draw a big triforce 56 | display(big-triforce(5)) -------------------------------------------------------------------------------- /include/stanza.h: -------------------------------------------------------------------------------- 1 | #ifndef STANZA_STANZA_H 2 | #define STANZA_STANZA_H 3 | 4 | #include "stanza/platform.h" 5 | #include "stanza/types.h" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /include/stanza/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef STANZA_PLATFORM_H 2 | #define STANZA_PLATFORM_H 3 | 4 | #ifdef PLATFORM_WINDOWS 5 | #define STANZA_EXPORTED_SYMBOL __declspec(dllexport) 6 | #else 7 | #define STANZA_EXPORTED_SYMBOL 8 | #endif 9 | 10 | #define STANZA_API_FUNC STANZA_EXPORTED_SYMBOL 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /include/stanza/types.h: -------------------------------------------------------------------------------- 1 | #ifndef STANZA_TYPES_H 2 | #define STANZA_TYPES_H 3 | #include 4 | 5 | // These types match the size/signedness of the corresponding Stanza type, 6 | // whereas the size/signedness of the corresponding bare C type (e.g. `char`, 7 | // `int`) may be platform-specific. We use these at the interface between 8 | // Stanza and the runtime to prevent size/signedness mismatch. 9 | typedef int64_t stz_long; 10 | typedef int32_t stz_int; 11 | typedef uint8_t stz_byte; 12 | typedef double stz_double; 13 | typedef float stz_float; 14 | 15 | // Conversion macros between Stanza-strings (stz_byte*) and C-strings (char*) 16 | // These are necessary because `char` may be signed, but `stz_byte` is unsigned 17 | // It also helps us identify exactly where conversions are occurring 18 | #define C_STR(x) ((char*)(x)) 19 | #define C_CSTR(x) ((const char*)(x)) 20 | #define STZ_STR(x) ((stz_byte*)(x)) 21 | #define STZ_CSTR(x) ((const stz_byte*)(x)) 22 | 23 | // Macro to create an integer literal of size `stz_long`. Using LL is probably 24 | // always OK but using an explicit macro helps keep definition/declarations in 25 | // sync. (compare `stz_long i = 4LL` to `stz_long i = STZ_LONG(4)`) 26 | #ifdef PLATFORM_WINDOWS 27 | #define STZ_LONG(N) ((stz_long)N##LL) 28 | #else 29 | #define STZ_LONG(N) ((stz_long)N##L) 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /libs/asmjit/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2020 The AsmJit Authors 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/a64builder.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include "../core/api-build_p.h" 7 | #if !defined(ASMJIT_NO_AARCH64) && !defined(ASMJIT_NO_BUILDER) 8 | 9 | #include "../arm/a64assembler.h" 10 | #include "../arm/a64builder.h" 11 | #include "../arm/a64emithelper_p.h" 12 | 13 | ASMJIT_BEGIN_SUB_NAMESPACE(a64) 14 | 15 | // a64::Builder - Construction & Destruction 16 | // ========================================= 17 | 18 | Builder::Builder(CodeHolder* code) noexcept : BaseBuilder() { 19 | _archMask = uint64_t(1) << uint32_t(Arch::kAArch64); 20 | assignEmitterFuncs(this); 21 | 22 | if (code) 23 | code->attach(this); 24 | } 25 | Builder::~Builder() noexcept {} 26 | 27 | // a64::Builder - Events 28 | // ===================== 29 | 30 | Error Builder::onAttach(CodeHolder* code) noexcept { 31 | return Base::onAttach(code); 32 | } 33 | 34 | Error Builder::onDetach(CodeHolder* code) noexcept { 35 | return Base::onDetach(code); 36 | } 37 | 38 | // a64::Builder - Finalize 39 | // ======================= 40 | 41 | Error Builder::finalize() { 42 | ASMJIT_PROPAGATE(runPasses()); 43 | Assembler a(_code); 44 | a.addEncodingOptions(encodingOptions()); 45 | a.addDiagnosticOptions(diagnosticOptions()); 46 | return serializeTo(&a); 47 | } 48 | 49 | ASMJIT_END_SUB_NAMESPACE 50 | 51 | #endif // !ASMJIT_NO_AARCH64 && !ASMJIT_NO_BUILDER 52 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/a64builder.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_ARM_A64BUILDER_H_INCLUDED 7 | #define ASMJIT_ARM_A64BUILDER_H_INCLUDED 8 | 9 | #include "../core/api-config.h" 10 | #ifndef ASMJIT_NO_BUILDER 11 | 12 | #include "../core/builder.h" 13 | #include "../arm/a64emitter.h" 14 | 15 | ASMJIT_BEGIN_SUB_NAMESPACE(a64) 16 | 17 | //! \addtogroup asmjit_a64 18 | //! \{ 19 | 20 | //! AArch64 builder implementation. 21 | class ASMJIT_VIRTAPI Builder 22 | : public BaseBuilder, 23 | public EmitterExplicitT { 24 | public: 25 | ASMJIT_NONCOPYABLE(Builder) 26 | typedef BaseBuilder Base; 27 | 28 | //! \name Construction & Destruction 29 | //! \{ 30 | 31 | ASMJIT_API explicit Builder(CodeHolder* code = nullptr) noexcept; 32 | ASMJIT_API virtual ~Builder() noexcept; 33 | 34 | //! \} 35 | 36 | //! \name Events 37 | //! \{ 38 | 39 | ASMJIT_API Error onAttach(CodeHolder* code) noexcept override; 40 | ASMJIT_API Error onDetach(CodeHolder* code) noexcept override; 41 | 42 | //! \} 43 | 44 | //! \name Finalize 45 | //! \{ 46 | 47 | ASMJIT_API Error finalize() override; 48 | 49 | //! \} 50 | }; 51 | 52 | //! \} 53 | 54 | ASMJIT_END_SUB_NAMESPACE 55 | 56 | #endif // !ASMJIT_NO_BUILDER 57 | #endif // ASMJIT_ARM_A64BUILDER_H_INCLUDED 58 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/a64compiler.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include "../core/api-build_p.h" 7 | #if !defined(ASMJIT_NO_AARCH64) && !defined(ASMJIT_NO_COMPILER) 8 | 9 | #include "../arm/a64assembler.h" 10 | #include "../arm/a64compiler.h" 11 | #include "../arm/a64emithelper_p.h" 12 | #include "../arm/a64rapass_p.h" 13 | 14 | ASMJIT_BEGIN_SUB_NAMESPACE(a64) 15 | 16 | // a64::Compiler - Construction & Destruction 17 | // ========================================== 18 | 19 | Compiler::Compiler(CodeHolder* code) noexcept : BaseCompiler() { 20 | _archMask = uint64_t(1) << uint32_t(Arch::kAArch64); 21 | assignEmitterFuncs(this); 22 | 23 | if (code) 24 | code->attach(this); 25 | } 26 | Compiler::~Compiler() noexcept {} 27 | 28 | // a64::Compiler - Events 29 | // ====================== 30 | 31 | Error Compiler::onAttach(CodeHolder* code) noexcept { 32 | ASMJIT_PROPAGATE(Base::onAttach(code)); 33 | Error err = addPassT(); 34 | 35 | if (ASMJIT_UNLIKELY(err)) { 36 | onDetach(code); 37 | return err; 38 | } 39 | 40 | return kErrorOk; 41 | } 42 | 43 | Error Compiler::onDetach(CodeHolder* code) noexcept { 44 | return Base::onDetach(code); 45 | } 46 | 47 | // a64::Compiler - Finalize 48 | // ======================== 49 | 50 | Error Compiler::finalize() { 51 | ASMJIT_PROPAGATE(runPasses()); 52 | Assembler a(_code); 53 | a.addEncodingOptions(encodingOptions()); 54 | a.addDiagnosticOptions(diagnosticOptions()); 55 | return serializeTo(&a); 56 | } 57 | 58 | ASMJIT_END_SUB_NAMESPACE 59 | 60 | #endif // !ASMJIT_NO_AARCH64 && !ASMJIT_NO_COMPILER 61 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/a64emithelper_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_ARM_ARMEMITHELPER_P_H_INCLUDED 7 | #define ASMJIT_ARM_ARMEMITHELPER_P_H_INCLUDED 8 | 9 | #include "../core/api-config.h" 10 | 11 | #include "../core/emithelper_p.h" 12 | #include "../core/func.h" 13 | #include "../arm/a64emitter.h" 14 | #include "../arm/a64operand.h" 15 | 16 | ASMJIT_BEGIN_SUB_NAMESPACE(a64) 17 | 18 | //! \cond INTERNAL 19 | //! \addtogroup asmjit_a64 20 | //! \{ 21 | 22 | class EmitHelper : public BaseEmitHelper { 23 | public: 24 | inline explicit EmitHelper(BaseEmitter* emitter = nullptr) noexcept 25 | : BaseEmitHelper(emitter) {} 26 | 27 | Error emitRegMove( 28 | const Operand_& dst_, 29 | const Operand_& src_, TypeId typeId, const char* comment = nullptr) override; 30 | 31 | Error emitRegSwap( 32 | const BaseReg& a, 33 | const BaseReg& b, const char* comment = nullptr) override; 34 | 35 | Error emitArgMove( 36 | const BaseReg& dst_, TypeId dstTypeId, 37 | const Operand_& src_, TypeId srcTypeId, const char* comment = nullptr) override; 38 | 39 | Error emitProlog(const FuncFrame& frame); 40 | Error emitEpilog(const FuncFrame& frame); 41 | }; 42 | 43 | void assignEmitterFuncs(BaseEmitter* emitter); 44 | 45 | //! \} 46 | //! \endcond 47 | 48 | ASMJIT_END_SUB_NAMESPACE 49 | 50 | #endif // ASMJIT_ARM_ARMEMITHELPER_P_H_INCLUDED 51 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/a64formatter_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_ARM_A64FORMATTER_P_H_INCLUDED 7 | #define ASMJIT_ARM_A64FORMATTER_P_H_INCLUDED 8 | 9 | #include "../core/api-config.h" 10 | #ifndef ASMJIT_NO_LOGGING 11 | 12 | #include "../core/formatter.h" 13 | #include "../core/string.h" 14 | #include "../arm/armformatter_p.h" 15 | #include "../arm/a64globals.h" 16 | 17 | ASMJIT_BEGIN_SUB_NAMESPACE(a64) 18 | 19 | //! \cond INTERNAL 20 | //! \addtogroup asmjit_a64 21 | //! \{ 22 | 23 | namespace FormatterInternal { 24 | 25 | using namespace arm::FormatterInternal; 26 | 27 | Error ASMJIT_CDECL formatRegister( 28 | String& sb, 29 | FormatFlags flags, 30 | const BaseEmitter* emitter, 31 | Arch arch, 32 | RegType regType, 33 | uint32_t regId, 34 | uint32_t elementType = 0, 35 | uint32_t elementIndex = 0xFFFFFFFFu) noexcept; 36 | 37 | Error ASMJIT_CDECL formatOperand( 38 | String& sb, 39 | FormatFlags flags, 40 | const BaseEmitter* emitter, 41 | Arch arch, 42 | const Operand_& op) noexcept; 43 | 44 | Error ASMJIT_CDECL formatInstruction( 45 | String& sb, 46 | FormatFlags flags, 47 | const BaseEmitter* emitter, 48 | Arch arch, 49 | const BaseInst& inst, const Operand_* operands, size_t opCount) noexcept; 50 | 51 | } // {FormatterInternal} 52 | 53 | //! \} 54 | //! \endcond 55 | 56 | ASMJIT_END_SUB_NAMESPACE 57 | 58 | #endif // !ASMJIT_NO_LOGGING 59 | #endif // ASMJIT_ARM_A64FORMATTER_P_H_INCLUDED 60 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/a64func_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_ARM_A64FUNC_P_H_INCLUDED 7 | #define ASMJIT_ARM_A64FUNC_P_H_INCLUDED 8 | 9 | #include "../core/func.h" 10 | 11 | ASMJIT_BEGIN_SUB_NAMESPACE(a64) 12 | 13 | //! \cond INTERNAL 14 | //! \addtogroup asmjit_a64 15 | //! \{ 16 | 17 | //! AArch64-specific function API (calling conventions and other utilities). 18 | namespace FuncInternal { 19 | 20 | //! Initialize `CallConv` structure (AArch64 specific). 21 | Error initCallConv(CallConv& cc, CallConvId ccId, const Environment& environment) noexcept; 22 | 23 | //! Initialize `FuncDetail` (AArch64 specific). 24 | Error initFuncDetail(FuncDetail& func, const FuncSignature& signature, uint32_t registerSize) noexcept; 25 | 26 | } // {FuncInternal} 27 | 28 | //! \} 29 | //! \endcond 30 | 31 | ASMJIT_END_SUB_NAMESPACE 32 | 33 | #endif // ASMJIT_ARM_A64FUNC_P_H_INCLUDED 34 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/a64instapi_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_ARM_A64INSTAPI_P_H_INCLUDED 7 | #define ASMJIT_ARM_A64INSTAPI_P_H_INCLUDED 8 | 9 | #include "../core/inst.h" 10 | #include "../core/operand.h" 11 | 12 | ASMJIT_BEGIN_SUB_NAMESPACE(a64) 13 | 14 | //! \cond INTERNAL 15 | //! \addtogroup asmjit_a64 16 | //! \{ 17 | 18 | namespace InstInternal { 19 | 20 | #ifndef ASMJIT_NO_TEXT 21 | Error ASMJIT_CDECL instIdToString(Arch arch, InstId instId, String& output) noexcept; 22 | InstId ASMJIT_CDECL stringToInstId(Arch arch, const char* s, size_t len) noexcept; 23 | #endif // !ASMJIT_NO_TEXT 24 | 25 | #ifndef ASMJIT_NO_VALIDATION 26 | Error ASMJIT_CDECL validate(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, ValidationFlags validationFlags) noexcept; 27 | #endif // !ASMJIT_NO_VALIDATION 28 | 29 | #ifndef ASMJIT_NO_INTROSPECTION 30 | Error ASMJIT_CDECL queryRWInfo(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, InstRWInfo* out) noexcept; 31 | Error ASMJIT_CDECL queryFeatures(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, CpuFeatures* out) noexcept; 32 | #endif // !ASMJIT_NO_INTROSPECTION 33 | 34 | } // {InstInternal} 35 | 36 | //! \} 37 | //! \endcond 38 | 39 | ASMJIT_END_SUB_NAMESPACE 40 | 41 | #endif // ASMJIT_ARM_A64INSTAPI_P_H_INCLUDED 42 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/armformatter_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_ARM_ARMFORMATTER_P_H_INCLUDED 7 | #define ASMJIT_ARM_ARMFORMATTER_P_H_INCLUDED 8 | 9 | #include "../core/api-config.h" 10 | #ifndef ASMJIT_NO_LOGGING 11 | 12 | #include "../core/formatter.h" 13 | #include "../core/string.h" 14 | #include "../arm/armglobals.h" 15 | 16 | ASMJIT_BEGIN_SUB_NAMESPACE(arm) 17 | 18 | //! \cond INTERNAL 19 | //! \addtogroup asmjit_arm 20 | //! \{ 21 | 22 | namespace FormatterInternal { 23 | 24 | Error ASMJIT_CDECL formatFeature( 25 | String& sb, 26 | uint32_t featureId) noexcept; 27 | 28 | Error ASMJIT_CDECL formatCondCode( 29 | String& sb, 30 | CondCode cc) noexcept; 31 | 32 | Error ASMJIT_CDECL formatShiftOp( 33 | String& sb, 34 | ShiftOp shiftOp) noexcept; 35 | 36 | } // {FormatterInternal} 37 | 38 | //! \} 39 | //! \endcond 40 | 41 | ASMJIT_END_SUB_NAMESPACE 42 | 43 | #endif // !ASMJIT_NO_LOGGING 44 | #endif // ASMJIT_ARM_ARMFORMATTER_P_H_INCLUDED 45 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/arm/armglobals.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_ARM_ARMGLOBALS_H_INCLUDED 7 | #define ASMJIT_ARM_ARMGLOBALS_H_INCLUDED 8 | 9 | #include "../core/archcommons.h" 10 | #include "../core/inst.h" 11 | 12 | //! \namespace asmjit::arm 13 | //! \ingroup asmjit_arm 14 | //! 15 | //! API shared between AArch32 & AArch64 backends. 16 | 17 | ASMJIT_BEGIN_SUB_NAMESPACE(arm) 18 | 19 | ASMJIT_END_SUB_NAMESPACE 20 | 21 | #endif // ASMJIT_ARM_ARMGLOBALS_H_INCLUDED 22 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/asmjit-scope-begin.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifdef _WIN32 7 | #pragma push_macro("min") 8 | #pragma push_macro("max") 9 | 10 | #ifdef min 11 | #undef min 12 | #endif 13 | 14 | #ifdef max 15 | #undef max 16 | #endif 17 | #endif 18 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/asmjit-scope-end.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifdef _WIN32 7 | #pragma pop_macro("min") 8 | #pragma pop_macro("max") 9 | #endif 10 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/asmjit.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // SPDX-License-Identifier: Zlib 4 | // Official GitHub Repository: https://github.com/asmjit/asmjit 5 | // 6 | // Copyright (c) 2008-2021 The AsmJit Authors 7 | // 8 | // This software is provided 'as-is', without any express or implied 9 | // warranty. In no event will the authors be held liable for any damages 10 | // arising from the use of this software. 11 | // 12 | // Permission is granted to anyone to use this software for any purpose, 13 | // including commercial applications, and to alter it and redistribute it 14 | // freely, subject to the following restrictions: 15 | // 16 | // 1. The origin of this software must not be misrepresented; you must not 17 | // claim that you wrote the original software. If you use this software 18 | // in a product, an acknowledgment in the product documentation would be 19 | // appreciated but is not required. 20 | // 2. Altered source versions must be plainly marked as such, and must not be 21 | // misrepresented as being the original software. 22 | // 3. This notice may not be removed or altered from any source distribution. 23 | 24 | #ifndef ASMJIT_ASMJIT_H_INCLUDED 25 | #define ASMJIT_ASMJIT_H_INCLUDED 26 | 27 | #include "./core.h" 28 | 29 | #ifndef ASMJIT_NO_X86 30 | #include "./x86.h" 31 | #endif 32 | 33 | #endif // ASMJIT_ASMJIT_H_INCLUDED 34 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/api-build_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_CORE_API_BUILD_P_H_INCLUDED 7 | #define ASMJIT_CORE_API_BUILD_P_H_INCLUDED 8 | 9 | #define ASMJIT_EXPORTS 10 | 11 | // Only turn-off these warnings when building asmjit itself. 12 | #ifdef _MSC_VER 13 | #ifndef _CRT_SECURE_NO_DEPRECATE 14 | #define _CRT_SECURE_NO_DEPRECATE 15 | #endif 16 | #ifndef _CRT_SECURE_NO_WARNINGS 17 | #define _CRT_SECURE_NO_WARNINGS 18 | #endif 19 | #endif 20 | 21 | // Dependencies only required for asmjit build, but never exposed through public headers. 22 | #ifdef _WIN32 23 | #ifndef WIN32_LEAN_AND_MEAN 24 | #define WIN32_LEAN_AND_MEAN 25 | #endif 26 | #ifndef NOMINMAX 27 | #define NOMINMAX 28 | #endif 29 | #include 30 | #endif 31 | 32 | #include "./api-config.h" 33 | 34 | #if !defined(ASMJIT_BUILD_DEBUG) && defined(__GNUC__) && !defined(__clang__) 35 | #define ASMJIT_FAVOR_SIZE __attribute__((__optimize__("Os"))) 36 | #define ASMJIT_FAVOR_SPEED __attribute__((__optimize__("O3"))) 37 | #elif ASMJIT_CXX_HAS_ATTRIBUTE(__minsize__, 0) 38 | #define ASMJIT_FAVOR_SIZE __attribute__((__minsize__)) 39 | #define ASMJIT_FAVOR_SPEED 40 | #else 41 | #define ASMJIT_FAVOR_SIZE 42 | #define ASMJIT_FAVOR_SPEED 43 | #endif 44 | 45 | // Make sure '#ifdef'ed unit tests are properly highlighted in IDE. 46 | #if !defined(ASMJIT_TEST) && defined(__INTELLISENSE__) 47 | #define ASMJIT_TEST 48 | #endif 49 | 50 | // Include a unit testing package if this is a `asmjit_test_unit` build. 51 | #if defined(ASMJIT_TEST) 52 | #include "../../../test/broken.h" 53 | #endif 54 | 55 | #endif // ASMJIT_CORE_API_BUILD_P_H_INCLUDED 56 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/environment.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include "../core/api-build_p.h" 7 | #include "../core/environment.h" 8 | 9 | ASMJIT_BEGIN_NAMESPACE 10 | 11 | // X86 Target 12 | // ---------- 13 | // 14 | // - 32-bit - Linux, OSX, BSD, and apparently also Haiku guarantee 16-byte 15 | // stack alignment. Other operating systems are assumed to have 16 | // 4-byte alignment by default for safety reasons. 17 | // - 64-bit - stack must be aligned to 16 bytes. 18 | // 19 | // ARM Target 20 | // ---------- 21 | // 22 | // - 32-bit - Stack must be aligned to 8 bytes. 23 | // - 64-bit - Stack must be aligned to 16 bytes (hardware requirement). 24 | uint32_t Environment::stackAlignment() const noexcept { 25 | if (is64Bit()) { 26 | // Assume 16-byte alignment on any 64-bit target. 27 | return 16; 28 | } 29 | else { 30 | // The following platforms use 16-byte alignment in 32-bit mode. 31 | if (isPlatformLinux() || 32 | isPlatformBSD() || 33 | isPlatformApple() || 34 | isPlatformHaiku()) { 35 | return 16u; 36 | } 37 | 38 | if (isFamilyARM()) 39 | return 8; 40 | 41 | // Bail to 4-byte alignment if we don't know. 42 | return 4; 43 | } 44 | } 45 | 46 | ASMJIT_END_NAMESPACE 47 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/errorhandler.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include "../core/api-build_p.h" 7 | #include "../core/errorhandler.h" 8 | 9 | ASMJIT_BEGIN_NAMESPACE 10 | 11 | ErrorHandler::ErrorHandler() noexcept {} 12 | ErrorHandler::~ErrorHandler() noexcept {} 13 | 14 | ASMJIT_END_NAMESPACE 15 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/formatter_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_CORE_FORMATTER_P_H_INCLUDED 7 | #define ASMJIT_CORE_FORMATTER_P_H_INCLUDED 8 | 9 | #include "../core/formatter.h" 10 | 11 | ASMJIT_BEGIN_NAMESPACE 12 | 13 | //! \cond INTERNAL 14 | //! \addtogroup asmjit_logging 15 | //! \{ 16 | 17 | namespace Formatter { 18 | 19 | static ASMJIT_FORCE_INLINE size_t paddingFromOptions(const FormatOptions& formatOptions, FormatPaddingGroup group) noexcept { 20 | static constexpr uint16_t _defaultPaddingTable[uint32_t(FormatPaddingGroup::kMaxValue) + 1] = { 44, 26 }; 21 | static_assert(uint32_t(FormatPaddingGroup::kMaxValue) + 1 == 2, "If a new group is defined it must be added here"); 22 | 23 | size_t padding = formatOptions.padding(group); 24 | return padding ? padding : size_t(_defaultPaddingTable[uint32_t(group)]); 25 | } 26 | 27 | } // {Formatter} 28 | 29 | //! \} 30 | //! \endcond 31 | 32 | ASMJIT_END_NAMESPACE 33 | 34 | #endif // ASMJIT_CORE_FORMATTER_H_P_INCLUDED 35 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/logger.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include "../core/api-build_p.h" 7 | #ifndef ASMJIT_NO_LOGGING 8 | 9 | #include "../core/logger.h" 10 | #include "../core/string.h" 11 | #include "../core/support.h" 12 | 13 | ASMJIT_BEGIN_NAMESPACE 14 | 15 | // Logger - Implementation 16 | // ======================= 17 | 18 | Logger::Logger() noexcept 19 | : _options() {} 20 | Logger::~Logger() noexcept {} 21 | 22 | Error Logger::logf(const char* fmt, ...) noexcept { 23 | Error err; 24 | va_list ap; 25 | 26 | va_start(ap, fmt); 27 | err = logv(fmt, ap); 28 | va_end(ap); 29 | 30 | return err; 31 | } 32 | 33 | Error Logger::logv(const char* fmt, va_list ap) noexcept { 34 | StringTmp<2048> sb; 35 | ASMJIT_PROPAGATE(sb.appendVFormat(fmt, ap)); 36 | return log(sb); 37 | } 38 | 39 | // FileLogger - Implementation 40 | // =========================== 41 | 42 | FileLogger::FileLogger(FILE* file) noexcept 43 | : _file(file) {} 44 | FileLogger::~FileLogger() noexcept {} 45 | 46 | Error FileLogger::_log(const char* data, size_t size) noexcept { 47 | if (!_file) 48 | return kErrorOk; 49 | 50 | if (size == SIZE_MAX) 51 | size = strlen(data); 52 | 53 | fwrite(data, 1, size, _file); 54 | return kErrorOk; 55 | } 56 | 57 | // StringLogger - Implementation 58 | // ============================= 59 | 60 | StringLogger::StringLogger() noexcept {} 61 | StringLogger::~StringLogger() noexcept {} 62 | 63 | Error StringLogger::_log(const char* data, size_t size) noexcept { 64 | return _content.append(data, size); 65 | } 66 | 67 | ASMJIT_END_NAMESPACE 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/misc_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_CORE_MISC_P_H_INCLUDED 7 | #define ASMJIT_CORE_MISC_P_H_INCLUDED 8 | 9 | #include "../core/api-config.h" 10 | 11 | ASMJIT_BEGIN_NAMESPACE 12 | 13 | //! \cond INTERNAL 14 | //! \addtogroup asmjit_utilities 15 | //! \{ 16 | 17 | #define ASMJIT_LOOKUP_TABLE_4(T, I) T((I)), T((I+1)), T((I+2)), T((I+3)) 18 | #define ASMJIT_LOOKUP_TABLE_8(T, I) ASMJIT_LOOKUP_TABLE_4(T, I), ASMJIT_LOOKUP_TABLE_4(T, I + 4) 19 | #define ASMJIT_LOOKUP_TABLE_16(T, I) ASMJIT_LOOKUP_TABLE_8(T, I), ASMJIT_LOOKUP_TABLE_8(T, I + 8) 20 | #define ASMJIT_LOOKUP_TABLE_32(T, I) ASMJIT_LOOKUP_TABLE_16(T, I), ASMJIT_LOOKUP_TABLE_16(T, I + 16) 21 | #define ASMJIT_LOOKUP_TABLE_40(T, I) ASMJIT_LOOKUP_TABLE_16(T, I), ASMJIT_LOOKUP_TABLE_16(T, I + 16), ASMJIT_LOOKUP_TABLE_8(T, I + 32) 22 | #define ASMJIT_LOOKUP_TABLE_64(T, I) ASMJIT_LOOKUP_TABLE_32(T, I), ASMJIT_LOOKUP_TABLE_32(T, I + 32) 23 | #define ASMJIT_LOOKUP_TABLE_128(T, I) ASMJIT_LOOKUP_TABLE_64(T, I), ASMJIT_LOOKUP_TABLE_64(T, I + 64) 24 | #define ASMJIT_LOOKUP_TABLE_256(T, I) ASMJIT_LOOKUP_TABLE_128(T, I), ASMJIT_LOOKUP_TABLE_128(T, I + 128) 25 | #define ASMJIT_LOOKUP_TABLE_512(T, I) ASMJIT_LOOKUP_TABLE_256(T, I), ASMJIT_LOOKUP_TABLE_256(T, I + 256) 26 | #define ASMJIT_LOOKUP_TABLE_1024(T, I) ASMJIT_LOOKUP_TABLE_512(T, I), ASMJIT_LOOKUP_TABLE_512(T, I + 512) 27 | 28 | //! \} 29 | //! \endcond 30 | 31 | ASMJIT_END_NAMESPACE 32 | 33 | #endif // ASMJIT_CORE_MISC_P_H_INCLUDED 34 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/osutils.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_CORE_OSUTILS_H_INCLUDED 7 | #define ASMJIT_CORE_OSUTILS_H_INCLUDED 8 | 9 | #include "../core/globals.h" 10 | 11 | ASMJIT_BEGIN_NAMESPACE 12 | 13 | //! \addtogroup asmjit_utilities 14 | //! \{ 15 | 16 | //! Operating system utilities. 17 | namespace OSUtils { 18 | //! Gets the current CPU tick count, used for benchmarking (1ms resolution). 19 | ASMJIT_API uint32_t getTickCount() noexcept; 20 | }; 21 | 22 | 23 | //! \cond INTERNAL 24 | //! Lock. 25 | //! 26 | //! Lock is internal, it cannot be used outside of AsmJit, however, its internal 27 | //! layout is exposed as it's used by some other classes, which are public. 28 | class Lock { 29 | public: 30 | ASMJIT_NONCOPYABLE(Lock) 31 | 32 | #if defined(_WIN32) 33 | #pragma pack(push, 8) 34 | struct ASMJIT_MAY_ALIAS Handle { 35 | void* DebugInfo; 36 | long LockCount; 37 | long RecursionCount; 38 | void* OwningThread; 39 | void* LockSemaphore; 40 | unsigned long* SpinCount; 41 | }; 42 | Handle _handle; 43 | #pragma pack(pop) 44 | #elif !defined(__EMSCRIPTEN__) 45 | typedef pthread_mutex_t Handle; 46 | Handle _handle; 47 | #endif 48 | 49 | ASMJIT_FORCE_INLINE Lock() noexcept; 50 | ASMJIT_FORCE_INLINE ~Lock() noexcept; 51 | 52 | ASMJIT_FORCE_INLINE void lock() noexcept; 53 | ASMJIT_FORCE_INLINE void unlock() noexcept; 54 | }; 55 | //! \endcond 56 | 57 | //! \} 58 | 59 | ASMJIT_END_NAMESPACE 60 | 61 | #endif // ASMJIT_CORE_OSUTILS_H_INCLUDED 62 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/target.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include "../core/api-build_p.h" 7 | #include "../core/target.h" 8 | 9 | ASMJIT_BEGIN_NAMESPACE 10 | 11 | Target::Target() noexcept : _environment() {} 12 | Target::~Target() noexcept {} 13 | 14 | ASMJIT_END_NAMESPACE 15 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/core/target.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_CORE_TARGET_H_INCLUDED 7 | #define ASMJIT_CORE_TARGET_H_INCLUDED 8 | 9 | #include "../core/archtraits.h" 10 | #include "../core/func.h" 11 | 12 | ASMJIT_BEGIN_NAMESPACE 13 | 14 | //! \addtogroup asmjit_core 15 | //! \{ 16 | 17 | //! Target is an abstract class that describes a machine code target. 18 | class ASMJIT_VIRTAPI Target { 19 | public: 20 | ASMJIT_BASE_CLASS(Target) 21 | ASMJIT_NONCOPYABLE(Target) 22 | 23 | //! Target environment information. 24 | Environment _environment; 25 | 26 | //! \name Construction & Destruction 27 | //! \{ 28 | 29 | //! Creates a `Target` instance. 30 | ASMJIT_API Target() noexcept; 31 | //! Destroys the `Target` instance. 32 | ASMJIT_API virtual ~Target() noexcept; 33 | 34 | //! \} 35 | 36 | //! \name Accessors 37 | //! \{ 38 | 39 | //! Returns target's environment. 40 | inline const Environment& environment() const noexcept { return _environment; } 41 | //! Returns the target architecture. 42 | inline Arch arch() const noexcept { return _environment.arch(); } 43 | //! Returns the target sub-architecture. 44 | inline SubArch subArch() const noexcept { return _environment.subArch(); } 45 | 46 | //! \} 47 | }; 48 | 49 | //! \} 50 | 51 | ASMJIT_END_NAMESPACE 52 | 53 | #endif // ASMJIT_CORE_TARGET_H_INCLUDED 54 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/x86/x86builder.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include "../core/api-build_p.h" 7 | #if !defined(ASMJIT_NO_X86) && !defined(ASMJIT_NO_BUILDER) 8 | 9 | #include "../x86/x86assembler.h" 10 | #include "../x86/x86builder.h" 11 | #include "../x86/x86emithelper_p.h" 12 | 13 | ASMJIT_BEGIN_SUB_NAMESPACE(x86) 14 | 15 | // x86::Builder - Construction & Destruction 16 | // ========================================= 17 | 18 | Builder::Builder(CodeHolder* code) noexcept : BaseBuilder() { 19 | _archMask = (uint64_t(1) << uint32_t(Arch::kX86)) | 20 | (uint64_t(1) << uint32_t(Arch::kX64)) ; 21 | assignEmitterFuncs(this); 22 | 23 | if (code) 24 | code->attach(this); 25 | } 26 | Builder::~Builder() noexcept {} 27 | 28 | // x86::Builder - Events 29 | // ===================== 30 | 31 | Error Builder::onAttach(CodeHolder* code) noexcept { 32 | return Base::onAttach(code); 33 | } 34 | 35 | Error Builder::onDetach(CodeHolder* code) noexcept { 36 | return Base::onDetach(code); 37 | } 38 | 39 | // x86::Builder - Finalize 40 | // ======================= 41 | 42 | Error Builder::finalize() { 43 | ASMJIT_PROPAGATE(runPasses()); 44 | Assembler a(_code); 45 | a.addEncodingOptions(encodingOptions()); 46 | a.addDiagnosticOptions(diagnosticOptions()); 47 | return serializeTo(&a); 48 | } 49 | 50 | ASMJIT_END_SUB_NAMESPACE 51 | 52 | #endif // !ASMJIT_NO_X86 && !ASMJIT_NO_BUILDER 53 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/x86/x86compiler.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include "../core/api-build_p.h" 7 | #if !defined(ASMJIT_NO_X86) && !defined(ASMJIT_NO_COMPILER) 8 | 9 | #include "../x86/x86assembler.h" 10 | #include "../x86/x86compiler.h" 11 | #include "../x86/x86instapi_p.h" 12 | #include "../x86/x86rapass_p.h" 13 | 14 | ASMJIT_BEGIN_SUB_NAMESPACE(x86) 15 | 16 | // x86::Compiler - Construction & Destruction 17 | // ========================================== 18 | 19 | Compiler::Compiler(CodeHolder* code) noexcept : BaseCompiler() { 20 | _archMask = (uint64_t(1) << uint32_t(Arch::kX86)) | 21 | (uint64_t(1) << uint32_t(Arch::kX64)) ; 22 | assignEmitterFuncs(this); 23 | 24 | if (code) 25 | code->attach(this); 26 | } 27 | Compiler::~Compiler() noexcept {} 28 | 29 | // x86::Compiler - Events 30 | // ====================== 31 | 32 | Error Compiler::onAttach(CodeHolder* code) noexcept { 33 | ASMJIT_PROPAGATE(Base::onAttach(code)); 34 | Error err = addPassT(); 35 | 36 | if (ASMJIT_UNLIKELY(err)) { 37 | onDetach(code); 38 | return err; 39 | } 40 | 41 | return kErrorOk; 42 | } 43 | 44 | Error Compiler::onDetach(CodeHolder* code) noexcept { 45 | return Base::onDetach(code); 46 | } 47 | 48 | // x86::Compiler - Finalize 49 | // ======================== 50 | 51 | Error Compiler::finalize() { 52 | ASMJIT_PROPAGATE(runPasses()); 53 | Assembler a(_code); 54 | a.addEncodingOptions(encodingOptions()); 55 | a.addDiagnosticOptions(diagnosticOptions()); 56 | return serializeTo(&a); 57 | } 58 | 59 | ASMJIT_END_SUB_NAMESPACE 60 | 61 | #endif // !ASMJIT_NO_X86 && !ASMJIT_NO_COMPILER 62 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/x86/x86emithelper_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_X86_X86EMITHELPER_P_H_INCLUDED 7 | #define ASMJIT_X86_X86EMITHELPER_P_H_INCLUDED 8 | 9 | #include "../core/api-config.h" 10 | 11 | #include "../core/emithelper_p.h" 12 | #include "../core/func.h" 13 | #include "../x86/x86emitter.h" 14 | #include "../x86/x86operand.h" 15 | 16 | ASMJIT_BEGIN_SUB_NAMESPACE(x86) 17 | 18 | //! \cond INTERNAL 19 | //! \addtogroup asmjit_x86 20 | //! \{ 21 | 22 | static inline RegType vecTypeIdToRegType(TypeId typeId) noexcept { 23 | return uint32_t(typeId) <= uint32_t(TypeId::_kVec128End) ? RegType::kX86_Xmm : 24 | uint32_t(typeId) <= uint32_t(TypeId::_kVec256End) ? RegType::kX86_Ymm : RegType::kX86_Zmm; 25 | } 26 | 27 | class EmitHelper : public BaseEmitHelper { 28 | public: 29 | bool _avxEnabled; 30 | bool _avx512Enabled; 31 | 32 | inline explicit EmitHelper(BaseEmitter* emitter = nullptr, bool avxEnabled = false, bool avx512Enabled = false) noexcept 33 | : BaseEmitHelper(emitter), 34 | _avxEnabled(avxEnabled || avx512Enabled), 35 | _avx512Enabled(avx512Enabled) {} 36 | 37 | Error emitRegMove( 38 | const Operand_& dst_, 39 | const Operand_& src_, TypeId typeId, const char* comment = nullptr) override; 40 | 41 | Error emitArgMove( 42 | const BaseReg& dst_, TypeId dstTypeId, 43 | const Operand_& src_, TypeId srcTypeId, const char* comment = nullptr) override; 44 | 45 | Error emitRegSwap( 46 | const BaseReg& a, 47 | const BaseReg& b, const char* comment = nullptr) override; 48 | 49 | Error emitProlog(const FuncFrame& frame); 50 | Error emitEpilog(const FuncFrame& frame); 51 | }; 52 | 53 | void assignEmitterFuncs(BaseEmitter* emitter); 54 | 55 | //! \} 56 | //! \endcond 57 | 58 | ASMJIT_END_SUB_NAMESPACE 59 | 60 | #endif // ASMJIT_X86_X86EMITHELPER_P_H_INCLUDED 61 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/x86/x86formatter_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_X86_X86FORMATTER_P_H_INCLUDED 7 | #define ASMJIT_X86_X86FORMATTER_P_H_INCLUDED 8 | 9 | #include "../core/api-config.h" 10 | #ifndef ASMJIT_NO_LOGGING 11 | 12 | #include "../core/formatter.h" 13 | #include "../core/string.h" 14 | #include "../x86/x86globals.h" 15 | 16 | ASMJIT_BEGIN_SUB_NAMESPACE(x86) 17 | 18 | //! \cond INTERNAL 19 | //! \addtogroup asmjit_x86 20 | //! \{ 21 | 22 | namespace FormatterInternal { 23 | 24 | Error ASMJIT_CDECL formatFeature( 25 | String& sb, 26 | uint32_t featureId) noexcept; 27 | 28 | Error ASMJIT_CDECL formatRegister( 29 | String& sb, 30 | FormatFlags flags, 31 | const BaseEmitter* emitter, 32 | Arch arch, 33 | RegType regType, 34 | uint32_t regId) noexcept; 35 | 36 | Error ASMJIT_CDECL formatOperand( 37 | String& sb, 38 | FormatFlags flags, 39 | const BaseEmitter* emitter, 40 | Arch arch, 41 | const Operand_& op) noexcept; 42 | 43 | Error ASMJIT_CDECL formatInstruction( 44 | String& sb, 45 | FormatFlags flags, 46 | const BaseEmitter* emitter, 47 | Arch arch, 48 | const BaseInst& inst, const Operand_* operands, size_t opCount) noexcept; 49 | 50 | } // {FormatterInternal} 51 | 52 | //! \} 53 | //! \endcond 54 | 55 | ASMJIT_END_SUB_NAMESPACE 56 | 57 | #endif // !ASMJIT_NO_LOGGING 58 | #endif // ASMJIT_X86_X86FORMATTER_P_H_INCLUDED 59 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/x86/x86func_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_X86_X86FUNC_P_H_INCLUDED 7 | #define ASMJIT_X86_X86FUNC_P_H_INCLUDED 8 | 9 | #include "../core/func.h" 10 | 11 | ASMJIT_BEGIN_SUB_NAMESPACE(x86) 12 | 13 | //! \cond INTERNAL 14 | //! \addtogroup asmjit_x86 15 | //! \{ 16 | 17 | //! X86-specific function API (calling conventions and other utilities). 18 | namespace FuncInternal { 19 | 20 | //! Initialize `CallConv` structure (X86 specific). 21 | Error initCallConv(CallConv& cc, CallConvId ccId, const Environment& environment) noexcept; 22 | 23 | //! Initialize `FuncDetail` (X86 specific). 24 | Error initFuncDetail(FuncDetail& func, const FuncSignature& signature, uint32_t registerSize) noexcept; 25 | 26 | } // {FuncInternal} 27 | 28 | //! \} 29 | //! \endcond 30 | 31 | ASMJIT_END_SUB_NAMESPACE 32 | 33 | #endif // ASMJIT_X86_X86FUNC_P_H_INCLUDED 34 | -------------------------------------------------------------------------------- /libs/asmjit/src/asmjit/x86/x86instapi_p.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_X86_X86INSTAPI_P_H_INCLUDED 7 | #define ASMJIT_X86_X86INSTAPI_P_H_INCLUDED 8 | 9 | #include "../core/inst.h" 10 | #include "../core/operand.h" 11 | 12 | ASMJIT_BEGIN_SUB_NAMESPACE(x86) 13 | 14 | //! \cond INTERNAL 15 | //! \addtogroup asmjit_x86 16 | //! \{ 17 | 18 | namespace InstInternal { 19 | 20 | #ifndef ASMJIT_NO_TEXT 21 | Error ASMJIT_CDECL instIdToString(Arch arch, InstId instId, String& output) noexcept; 22 | InstId ASMJIT_CDECL stringToInstId(Arch arch, const char* s, size_t len) noexcept; 23 | #endif // !ASMJIT_NO_TEXT 24 | 25 | #ifndef ASMJIT_NO_VALIDATION 26 | Error ASMJIT_CDECL validate(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, ValidationFlags validationFlags) noexcept; 27 | #endif // !ASMJIT_NO_VALIDATION 28 | 29 | #ifndef ASMJIT_NO_INTROSPECTION 30 | Error ASMJIT_CDECL queryRWInfo(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, InstRWInfo* out) noexcept; 31 | Error ASMJIT_CDECL queryFeatures(Arch arch, const BaseInst& inst, const Operand_* operands, size_t opCount, CpuFeatures* out) noexcept; 32 | #endif // !ASMJIT_NO_INTROSPECTION 33 | 34 | } // {InstInternal} 35 | 36 | //! \} 37 | //! \endcond 38 | 39 | ASMJIT_END_SUB_NAMESPACE 40 | 41 | #endif // ASMJIT_X86_X86INSTAPI_P_H_INCLUDED 42 | -------------------------------------------------------------------------------- /libs/asmjit/test/asmjit_test_compiler.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJIT_TEST_COMPILER_H_INCLUDED 7 | #define ASMJIT_TEST_COMPILER_H_INCLUDED 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | class SimpleErrorHandler : public asmjit::ErrorHandler { 15 | public: 16 | SimpleErrorHandler() 17 | : _err(asmjit::kErrorOk) {} 18 | 19 | virtual void handleError(asmjit::Error err, const char* message, asmjit::BaseEmitter* origin) { 20 | asmjit::DebugUtils::unused(origin); 21 | _err = err; 22 | _message.assign(message); 23 | } 24 | 25 | asmjit::Error _err; 26 | asmjit::String _message; 27 | }; 28 | 29 | //! A test case interface for testing AsmJit's Compiler. 30 | class TestCase { 31 | public: 32 | TestCase(const char* name = nullptr) { 33 | if (name) 34 | _name.assign(name); 35 | } 36 | 37 | virtual ~TestCase() {} 38 | 39 | inline const char* name() const { return _name.data(); } 40 | 41 | virtual void compile(asmjit::BaseCompiler& cc) = 0; 42 | virtual bool run(void* func, asmjit::String& result, asmjit::String& expect) = 0; 43 | 44 | asmjit::String _name; 45 | }; 46 | 47 | class TestApp { 48 | public: 49 | std::vector> _tests; 50 | 51 | unsigned _nFailed = 0; 52 | size_t _outputSize = 0; 53 | 54 | bool _verbose = false; 55 | bool _dumpAsm = false; 56 | bool _dumpHex = false; 57 | 58 | TestApp() noexcept {} 59 | ~TestApp() noexcept {} 60 | 61 | void add(TestCase* test) noexcept { 62 | _tests.push_back(std::unique_ptr(test)); 63 | } 64 | 65 | template 66 | inline void addT() { T::add(*this); } 67 | 68 | int handleArgs(int argc, const char* const* argv); 69 | void showInfo(); 70 | int run(); 71 | }; 72 | 73 | #endif // ASMJIT_TEST_COMPILER_H_INCLUDED 74 | -------------------------------------------------------------------------------- /libs/asmjit/test/asmjit_test_perf.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "cmdline.h" 12 | 13 | using namespace asmjit; 14 | 15 | #if !defined(ASMJIT_NO_X86) 16 | void benchmarkX86Emitters(uint32_t numIterations, bool testX86, bool testX64) noexcept; 17 | #endif 18 | 19 | #if !defined(ASMJIT_NO_AARCH64) 20 | void benchmarkA64Emitters(uint32_t numIterations); 21 | #endif 22 | 23 | int main(int argc, char* argv[]) { 24 | CmdLine cmdLine(argc, argv); 25 | uint32_t numIterations = 20000; 26 | 27 | printf("AsmJit Performance Suite v%u.%u.%u:\n\n", 28 | unsigned((ASMJIT_LIBRARY_VERSION >> 16) ), 29 | unsigned((ASMJIT_LIBRARY_VERSION >> 8) & 0xFF), 30 | unsigned((ASMJIT_LIBRARY_VERSION ) & 0xFF)); 31 | 32 | printf("Usage:\n"); 33 | printf(" --help Show usage only\n"); 34 | printf(" --quick Decrease the number of iterations to make tests quicker\n"); 35 | printf(" --arch= Select architecture to run ('all' by default)\n"); 36 | printf("\n"); 37 | 38 | if (cmdLine.hasArg("--help")) 39 | return 0; 40 | 41 | if (cmdLine.hasArg("--quick")) 42 | numIterations = 1000; 43 | 44 | const char* arch = cmdLine.valueOf("--arch", "all"); 45 | 46 | #if !defined(ASMJIT_NO_X86) 47 | bool testX86 = strcmp(arch, "all") == 0 || strcmp(arch, "x86") == 0; 48 | bool testX64 = strcmp(arch, "all") == 0 || strcmp(arch, "x64") == 0; 49 | 50 | if (testX86 || testX64) 51 | benchmarkX86Emitters(numIterations, testX86, testX64); 52 | #endif 53 | 54 | #if !defined(ASMJIT_NO_AARCH64) 55 | bool testAArch64 = strcmp(arch, "all") == 0 || strcmp(arch, "aarch64") == 0; 56 | 57 | if (testAArch64) 58 | benchmarkA64Emitters(numIterations); 59 | #endif 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /libs/asmjit/test/asmjitutils.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef ASMJITUTILS_H_INCLUDED 7 | #define ASMJITUTILS_H_INCLUDED 8 | 9 | #include 10 | 11 | static const char* asmjitArchAsString(asmjit::Arch arch) noexcept { 12 | switch (arch) { 13 | case asmjit::Arch::kX86 : return "X86"; 14 | case asmjit::Arch::kX64 : return "X64"; 15 | 16 | case asmjit::Arch::kRISCV32 : return "RISCV32"; 17 | case asmjit::Arch::kRISCV64 : return "RISCV64"; 18 | 19 | case asmjit::Arch::kARM : return "ARM"; 20 | case asmjit::Arch::kAArch64 : return "AArch64"; 21 | case asmjit::Arch::kThumb : return "Thumb"; 22 | 23 | case asmjit::Arch::kMIPS32_LE : return "MIPS_LE"; 24 | case asmjit::Arch::kMIPS64_LE : return "MIPS64_LE"; 25 | 26 | case asmjit::Arch::kARM_BE : return "ARM_BE"; 27 | case asmjit::Arch::kThumb_BE : return "Thumb_BE"; 28 | case asmjit::Arch::kAArch64_BE: return "AArch64_BE"; 29 | 30 | case asmjit::Arch::kMIPS32_BE : return "MIPS_BE"; 31 | case asmjit::Arch::kMIPS64_BE : return "MIPS64_BE"; 32 | 33 | default: 34 | return ""; 35 | } 36 | } 37 | 38 | #endif // ASMJITUTILS_H_INCLUDED 39 | -------------------------------------------------------------------------------- /libs/asmjit/test/cmdline.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef CMDLINE_H_INCLUDED 7 | #define CMDLINE_H_INCLUDED 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | class CmdLine { 14 | public: 15 | int _argc; 16 | const char* const* _argv; 17 | 18 | CmdLine(int argc, const char* const* argv) 19 | : _argc(argc), 20 | _argv(argv) {} 21 | 22 | bool hasArg(const char* key) const { 23 | for (int i = 1; i < _argc; i++) 24 | if (strcmp(key, _argv[i]) == 0) 25 | return true; 26 | return false; 27 | } 28 | 29 | const char* valueOf(const char* key, const char* defaultValue) const { 30 | size_t keySize = strlen(key); 31 | for (int i = 1; i < _argc; i++) { 32 | const char* val = _argv[i]; 33 | if (strlen(val) >= keySize + 1 && val[keySize] == '=' && memcmp(val, key, keySize) == 0) 34 | return val + keySize + 1; 35 | } 36 | 37 | return defaultValue; 38 | } 39 | 40 | int valueAsInt(const char* key, int defaultValue) const { 41 | const char* val = valueOf(key, nullptr); 42 | if (val == nullptr || val[0] == '\0') 43 | return defaultValue; 44 | 45 | return atoi(val); 46 | } 47 | 48 | unsigned valueAsUInt(const char* key, unsigned defaultValue) const { 49 | const char* val = valueOf(key, nullptr); 50 | if (val == nullptr || val[0] == '\0') 51 | return defaultValue; 52 | 53 | int v = atoi(val); 54 | if (v < 0) 55 | return defaultValue; 56 | else 57 | return unsigned(v); 58 | } 59 | }; 60 | 61 | #endif // CMDLINE_H_INCLUDED 62 | -------------------------------------------------------------------------------- /libs/asmjit/test/performancetimer.h: -------------------------------------------------------------------------------- 1 | // This file is part of AsmJit project 2 | // 3 | // See asmjit.h or LICENSE.md for license and copyright information 4 | // SPDX-License-Identifier: Zlib 5 | 6 | #ifndef PERFORMANCETIMER_H_INCLUDED 7 | #define PERFORMANCETIMER_H_INCLUDED 8 | 9 | #include 10 | #include 11 | 12 | class PerformanceTimer { 13 | public: 14 | typedef std::chrono::high_resolution_clock::time_point TimePoint; 15 | 16 | TimePoint _startTime {}; 17 | TimePoint _endTime {}; 18 | 19 | inline void start() { 20 | _startTime = std::chrono::high_resolution_clock::now(); 21 | } 22 | 23 | inline void stop() { 24 | _endTime = std::chrono::high_resolution_clock::now(); 25 | } 26 | 27 | inline double duration() const { 28 | std::chrono::duration elapsed = _endTime - _startTime; 29 | return elapsed.count() * 1000; 30 | } 31 | }; 32 | 33 | static inline double mbps(double duration, uint64_t outputSize) noexcept { 34 | if (duration == 0) 35 | return 0.0; 36 | 37 | double bytesTotal = double(outputSize); 38 | return (bytesTotal * 1000) / (duration * 1024 * 1024); 39 | } 40 | 41 | #endif // PERFORMANCETIMER_H_INCLUDED 42 | -------------------------------------------------------------------------------- /libs/asmjit/tools/configure-makefiles.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CURRENT_DIR="`pwd`" 4 | BUILD_DIR="${CURRENT_DIR}/../build" 5 | BUILD_OPTIONS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DASMJIT_TEST=1" 6 | 7 | echo "== [Configuring Build - Debug] ==" 8 | eval cmake "${CURRENT_DIR}/.." -B "${BUILD_DIR}/Debug" -DCMAKE_BUILD_TYPE=Debug ${BUILD_OPTIONS} 9 | echo "" 10 | 11 | echo "== [Configuring Build - Release] ==" 12 | eval cmake "${CURRENT_DIR}/.." -B "${BUILD_DIR}/Release" -DCMAKE_BUILD_TYPE=Release ${BUILD_OPTIONS} 13 | echo "" 14 | -------------------------------------------------------------------------------- /libs/asmjit/tools/configure-ninja.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CURRENT_DIR="`pwd`" 4 | BUILD_DIR="${CURRENT_DIR}/../build" 5 | BUILD_OPTIONS="-G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DASMJIT_TEST=1" 6 | 7 | echo "== [Configuring Build - Debug] ==" 8 | eval cmake "${CURRENT_DIR}/.." -B "${BUILD_DIR}/Debug" -DCMAKE_BUILD_TYPE=Debug ${BUILD_OPTIONS} 9 | echo "" 10 | 11 | echo "== [Configuring Build - Release] ==" 12 | eval cmake "${CURRENT_DIR}/.." -B "${BUILD_DIR}/Release" -DCMAKE_BUILD_TYPE=Release ${BUILD_OPTIONS} 13 | echo "" 14 | -------------------------------------------------------------------------------- /libs/asmjit/tools/configure-sanitizers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CURRENT_DIR="`pwd`" 4 | BUILD_DIR="${CURRENT_DIR}/../build" 5 | BUILD_OPTIONS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DASMJIT_TEST=1" 6 | 7 | echo "== [Configuring Build - Release_ASAN] ==" 8 | eval cmake "${CURRENT_DIR}/.." -B "${BUILD_DIR}/Release_ASAN" ${BUILD_OPTIONS} -DCMAKE_BUILD_TYPE=Release -DASMJIT_SANITIZE=address 9 | echo "" 10 | 11 | echo "== [Configuring Build - Release_UBSAN] ==" 12 | eval cmake "${CURRENT_DIR}/.." -B "${BUILD_DIR}/Release_UBSAN" ${BUILD_OPTIONS} -DCMAKE_BUILD_TYPE=Release -DASMJIT_SANITIZE=undefined 13 | echo "" 14 | -------------------------------------------------------------------------------- /libs/asmjit/tools/configure-vs2019-x64.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cmake .. -B "..\build_vs2019_x64" -G"Visual Studio 16" -A x64 -DASMJIT_TEST=1 3 | -------------------------------------------------------------------------------- /libs/asmjit/tools/configure-vs2019-x86.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cmake .. -B "..\build_vs2019_x86" -G"Visual Studio 16" -A Win32 -DASMJIT_TEST=1 3 | -------------------------------------------------------------------------------- /libs/asmjit/tools/configure-vs2022-x64.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cmake .. -B "..\build_vs2022_x64" -G"Visual Studio 17" -A x64 -DASMJIT_TEST=1 3 | -------------------------------------------------------------------------------- /libs/asmjit/tools/configure-vs2022-x86.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cmake .. -B "..\build_vs2022_x86" -G"Visual Studio 17" -A Win32 -DASMJIT_TEST=1 3 | -------------------------------------------------------------------------------- /libs/asmjit/tools/configure-xcode.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | CURRENT_DIR="`pwd`" 4 | BUILD_DIR="${CURRENT_DIR}/../build" 5 | BUILD_OPTIONS="-G Xcode -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DASMJIT_TEST=1" 6 | 7 | mkdir -p "${BUILD_DIR}" 8 | eval cmake "${CURRENT_DIR}/.." -B "${BUILD_DIR}" ${BUILD_OPTIONS} 9 | -------------------------------------------------------------------------------- /libs/asmjit/tools/enumgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | set -e 3 | node ./enumgen.js $@ 4 | -------------------------------------------------------------------------------- /libs/asmjit/tools/tablegen-arm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | node ./tablegen-arm.js 4 | -------------------------------------------------------------------------------- /libs/asmjit/tools/tablegen-x86.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | set -e 3 | node ./tablegen-x86.js $@ 4 | -------------------------------------------------------------------------------- /libs/asmjit/tools/tablegen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | set -e 3 | node ./tablegen-arm.js $@ 4 | node ./tablegen-x86.js $@ 5 | -------------------------------------------------------------------------------- /notes.doc: -------------------------------------------------------------------------------- 1 | root: 2 | "notes/index.txt" 3 | files: 4 | "notes" 5 | "core" 6 | "compiler" 7 | "docs" 8 | "examples" 9 | syntax for "docs/check-docs.md" : 10 | tag-start: "++" 11 | tag-end: "//" 12 | reference: "@@" 13 | syntax for "notes/docs.txt" : 14 | tag-start: "++" 15 | tag-end: "//" 16 | reference: "@@" 17 | syntax for "compiler/stz-comments.stanza" : 18 | tag-start: "++" 19 | tag-end: "//" 20 | reference: "@@" -------------------------------------------------------------------------------- /notes/KForm Passes.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StanzaOrg/lbstanza-old/722bcb168efcf739205009a69841c307b81b28a3/notes/KForm Passes.graffle -------------------------------------------------------------------------------- /notes/Stacks.graffle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StanzaOrg/lbstanza-old/722bcb168efcf739205009a69841c307b81b28a3/notes/Stacks.graffle -------------------------------------------------------------------------------- /notes/Stacks.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/StanzaOrg/lbstanza-old/722bcb168efcf739205009a69841c307b81b28a3/notes/Stacks.pdf -------------------------------------------------------------------------------- /notes/fine-grained-tco.txt: -------------------------------------------------------------------------------- 1 | # Fine Grained TCO # 2 | 3 | ## The Standard `Let` Macro ## 4 | 5 | Consider the following `let` macro: 6 | 7 | let : 8 | val msg = "World" 9 | println("Hello world") 10 | println(msg) 11 | 12 | Which expands into this: 13 | 14 | defn tempfunction () : 15 | val msg = "World" 16 | println("Hello world") 17 | println(msg) 18 | tempfunction() 19 | 20 | Note that the above implementation creates and calls a new function, which results in the creation of a new stackframe. 21 | 22 | ## Non-Solutions ## 23 | 24 | Declaring tempfunction as a TCO function does not solve the problem. Calling `tempfunction` still results in the creation of a new stackframe. Furthermore, the call stack information in `tempfunction` is thrown away. For the example above this means that the line containing `println(msg)` would not appear in the stacktrace. This is not what is desired. 25 | 26 | ## Optimization ## 27 | 28 | There is one situation in which the stackframe can be avoided, and that is when the call `tempfunction()` is in tailcall position. The system will throw away the context in which `tempfunction()` was called but this is not useful information anyway. 29 | 30 | 31 | -------------------------------------------------------------------------------- /notes/gchooks.txt: -------------------------------------------------------------------------------- 1 | Garbage collection in the VM 2 | ============================ 3 | 4 | In the virtual machine, the opcode RESERVE_OPCODE is executed in order 5 | to ensure that there is enough space on the heap for the upcoming allocations. 6 | 7 | This opcode calls the special EXTEND_HEAP_FN hook, which will check 8 | whether there is enough space on the heap. If there isn't then we jump 9 | to the following function in core. 10 | 11 | lostanza defn extend-heap (size:long) -> long 12 | 13 | This is the standard hook that is called when we need to extend the 14 | heap, and is what happens in compiled mode as well. 15 | 16 | This function is responsible for: 17 | 1) running the garbage collector. 18 | 2) checking whether enough space has been freed. 19 | 3) issuing the out-of-memory error if appropriate. 20 | 4) running the GC Notifiers when appropriate. 21 | 22 | As part of its operation, it calls the primitive: 23 | 24 | val remaining = call-prim collect-garbage(size) 25 | 26 | In compiled mode, this primitive compiles down into a straight-forward 27 | function call to this core function: 28 | 29 | lostanza defn collect-garbage (size:long) -> long 30 | 31 | This function is responsible for returning the new number of bytes 32 | remaining in the heap after garbage collection. 33 | 34 | When executed in the virtual machine, this primitives compiles down to 35 | the GC_OPCODE. In the implementation of the virtual machine, this 36 | opcode is implemented by calling the extern function: 37 | 38 | extern defn call_garbage_collector (vms:ptr, size:long) -> long 39 | 40 | This function is responsible for returning the new number of bytes 41 | remaining in the heap after garbage collection. 42 | -------------------------------------------------------------------------------- /notes/index.txt: -------------------------------------------------------------------------------- 1 | Description of the Stanza System 2 | 3 | Usage Documents: 4 | @[file:../docs/usage-docs.md] 5 | 6 | Core Library: 7 | @[file:../core/core.txt] Description of the Core System 8 | 9 | Compiler: 10 | @[file:../compiler/compiler.txt] Description of the Compiler System 11 | 12 | Examples: 13 | @[file:../examples/examples.txt] Description of Examples 14 | 15 | Development Notes: 16 | @[file:Stacks.pdf] 17 | @[file:Stacks.graffle] 18 | @[file:KForm Passes.graffle] 19 | @[file:dev.txt] 20 | @[file:todo.txt] 21 | @[file:asm.txt] 22 | @[file:vm.txt] 23 | @[file:type.txt] 24 | @[file:install.txt] 25 | @[file:kform-dev.txt] 26 | @[file:input.txt] 27 | @[file:reentrancy.txt] 28 | @[file:ui.txt] 29 | @[file:emitter.txt] 30 | @[file:regalloc.txt] 31 | @[file:docs.txt] 32 | -------------------------------------------------------------------------------- /oldtests/callc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern c_trampoline (uint64_t f, uint64_t* args, uint64_t* ret); 6 | 7 | float myplus (float x, float y){ 8 | printf("Adding %f to %f\n", x, y); 9 | return x + y; 10 | } 11 | 12 | void main () { 13 | uint64_t* args = malloc(30 * sizeof(uint64_t)); 14 | uint64_t* ret = malloc(2 * sizeof(uint64_t)); 15 | uint64_t* ptr = args; 16 | //Stack arguments 17 | *ptr = 0; ptr++; 18 | //Floating point arguments 19 | *ptr = 2; ptr++; 20 | *(float*)ptr = 42.0; ptr++; 21 | *(float*)ptr = 7.0; ptr++; 22 | //Integer arguments 23 | *ptr = 1; ptr++; 24 | *ptr = 2; ptr++; 25 | 26 | for(int i=0; i<10; i++){ 27 | uint64_t f = (uint64_t)&myplus; 28 | c_trampoline(f, args, ret); 29 | printf("Result Rax = %d, Xmm0 = %f\n", *(int*)ret, *(float*)(ret + 1)); 30 | printf("Hello world %d %d\n", i, i * 10); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /oldtests/elinfer.txt: -------------------------------------------------------------------------------- 1 | ;input : 2 | ; def 0 : 0 3 | ; def 1 : 1 4 | ;block 0 : 5 | ; here "start of program" 6 | ; use 0 7 | ; use 1 8 | ; match : 9 | ; branch 1 : () 10 | ; branch 2 : () 11 | ;block 1 : 12 | ; here "block 1" 13 | ; use 0 14 | ; use 1 15 | ; goto 3 16 | ;block 2 : 17 | ; here "block 2" 18 | ; use 0 19 | ; use 1 20 | ; def 0 : 2 21 | ; cast 1 : 4 22 | ; here "block 2b" 23 | ; use 0 24 | ; use 1 25 | ; match : 26 | ; branch 3 : () 27 | ; branch 1 : 28 | ; cast 1 : 3 29 | ;block 3 : 30 | ; here "block 3" 31 | ; use 0 32 | ; use 1 33 | 34 | ;val v = ? 35 | ;val s = ? 36 | ;if ? : 37 | ; s as Int 38 | ;for i in 0 to 10 do : 39 | ; v = v + 1 40 | ;println(v) 41 | 42 | input : () 43 | block 0 : 44 | here "Program start" 45 | def 0 : 0 46 | def 1 : 0 47 | def 2 : 0 48 | goto 1 49 | block 1 : 50 | here "if ?" 51 | cast 2 : 1 52 | use 0 53 | use 1 54 | match : 55 | branch 2 : () 56 | branch 3 : () 57 | block 2 : 58 | here "s as Int" 59 | cast 1 : 2 60 | use 0 61 | use 1 62 | goto 3 63 | block 3 : 64 | here "after if" 65 | use 0 66 | use 1 67 | here "for i in 0 to 10 do :" 68 | match : 69 | branch 4 : () 70 | branch 5 : () 71 | block 4 : 72 | here "v = v + 1" 73 | use 0 74 | use 1 75 | cast 0 : 2 76 | def 0 : 2 77 | goto 3 78 | block 5 : 79 | use 0 80 | use 1 81 | 82 | -------------------------------------------------------------------------------- /oldtests/freelist.stanza: -------------------------------------------------------------------------------- 1 | defpackage freelist : 2 | import core 3 | import collections 4 | import stz/algorithms 5 | 6 | defn test (example:Int, es:Tuple>) : 7 | val N = maximum(cat(seq(key,es), seq(value,es))) + 1 8 | test(example, N, es) 9 | 10 | defn test (example:Int, N:Int, es:Tuple>) : 11 | println("==== Example %_ ====" % [example]) 12 | ;Compute children 13 | val children = Array>(N,List()) 14 | for entry in es do : 15 | val [src, dst] = [key(entry), value(entry)] 16 | children[src] = cons(dst, children[src]) 17 | ;Transitive closure 18 | val all-children = transitive-closure(seq(KeyValue, 0 to N, children)) 19 | defn child? (c:Int, n:Int) : 20 | contains?(lookup(all-children,n), c) 21 | ;Compute ordering 22 | do(println, ambiguity-ordering(N, child?)) 23 | println("\n\n\n") 24 | 25 | defn main () : 26 | test(1, 2, []) 27 | 28 | test(2, 29 | [0 => 1 30 | 0 => 2]) 31 | 32 | test(3, 33 | [0 => 1]) 34 | 35 | test(4, 36 | [0 => 1 37 | 0 => 2 38 | 1 => 3 39 | 2 => 3]) 40 | 41 | test(5, 42 | [0 => 2 43 | 1 => 2]) 44 | 45 | test(6, 46 | [0 => 1 47 | 0 => 2 48 | 1 => 4 49 | 2 => 3]) 50 | 51 | test(7, 52 | [0 => 2 53 | 1 => 2 54 | 1 => 3 55 | 2 => 4]) 56 | 57 | test(8, 58 | [0 => 1 59 | 0 => 2 60 | 1 => 3 61 | 2 => 3 62 | 2 => 4 63 | 3 => 5 64 | 4 => 5]) 65 | 66 | main() -------------------------------------------------------------------------------- /oldtests/graph.txt: -------------------------------------------------------------------------------- 1 | pkg a : 2 | def 1 3 | def 2 4 | def 3 5 | def 4 6 | 1 => 2 7 | 1 => 3 8 | 2 => 3 9 | 2 => 4 10 | 4 => 1 11 | 12 | pkg b : 13 | import a : 14 | 1 as 5 15 | def 1 16 | def 2 17 | def 3 18 | 1 => 2 19 | 2 => 3 20 | 3 => 1 21 | 1 => 5 22 | 2 => 5 23 | 3 => 5 24 | 25 | pkg c : 26 | import a : 27 | 2 as 5 28 | def 1 29 | def 2 30 | def 3 31 | 1 => 2 32 | 2 => 3 33 | 3 => 1 34 | 1 => 5 35 | 2 => 5 36 | 3 => 5 37 | 38 | pkg d : 39 | import b : 40 | 1 as 5 41 | import c : 42 | 3 as 6 43 | def 1 44 | def 2 45 | def 3 46 | 1 => 2 47 | 2 => 3 48 | 3 => 1 49 | 1 => 5 50 | 2 => 5 51 | 3 => 5 52 | 6 => 1 53 | 6 => 2 54 | 6 => 3 55 | -------------------------------------------------------------------------------- /oldtests/read-pkg.stanza: -------------------------------------------------------------------------------- 1 | defpackage user : 2 | import core 3 | import stz/pkg-ir 4 | 5 | defn main () : 6 | val name = command-line-arguments()[1] 7 | println("===== Deserialized =====") 8 | val pkg = deserialize-pkg(name) 9 | println(pkg) 10 | println("===== Renamed =====") 11 | val pkg* = rename-pkg(pkg) 12 | println(pkg*) 13 | 14 | main() -------------------------------------------------------------------------------- /oldtests/test-macros.stanza: -------------------------------------------------------------------------------- 1 | defpackage test-macros : 2 | import core 3 | import reader 4 | import collections 5 | import stz/test-macros 6 | import stz/core-macros 7 | 8 | public defn try-out (filename:String) : 9 | val forms = read-file(filename) 10 | val expanded = parse-syntax[core + tests / #exp! ...](forms) 11 | do(println, expanded) 12 | spit("temp.stanza", expanded) 13 | call-system("stanza", [ 14 | "stanza" "run" "temp.stanza" 15 | "compiler/stz-test-framework.stanza"]) 16 | 17 | try-out("tests/test-tests.stanza") -------------------------------------------------------------------------------- /oldtests/testdb.stanza: -------------------------------------------------------------------------------- 1 | defpackage test-db : 2 | import core 3 | import collections 4 | import stz/defs-db 5 | import stz/defs-db-serializer 6 | 7 | let : 8 | val filename = command-line-arguments()[1] 9 | val db = deserialize(FileInputStream(filename)) 10 | defn print-list (name:String, list:Collection) : 11 | println("===== %_ =====" % [name]) 12 | within indented() : 13 | do(println, list) 14 | print-list("Reserved Words", reserved-words(db)) 15 | print-list("Packages", packages(db)) 16 | print-list("Package ID Definitions", pkg-id-defs(db)) 17 | print-list("ID Definitions", id-defs(db)) -------------------------------------------------------------------------------- /oldtests/testdb2.stanza: -------------------------------------------------------------------------------- 1 | defpackage test-db : 2 | import core 3 | import collections 4 | import stz/defs-db 5 | import stz/defs-db-serializer 6 | 7 | let : 8 | val filename = command-line-arguments()[1] 9 | val db = deserialize-definitions-database(FileInputStream(filename)) 10 | defn print-list (name:String, list:Collection): 11 | println("===== %_ =====" % [name]) 12 | within indented() : 13 | do(println, list) 14 | 15 | print-list("Reserved Words", reserved-words $ db) 16 | val defs = definitions(db) ; HashTable> 17 | defn items-of (src-kind:SrcDefinitionKind): 18 | to-hashtable> $ 19 | for kv in defs seq? : 20 | val defs = 21 | to-tuple $ 22 | seq(file-info, filter({kind(_) == src-kind}, value(kv))) 23 | if empty?(defs) : 24 | None() 25 | else : One $ 26 | to-string(key(kv)) => defs 27 | 28 | val possible-kinds = [ 29 | SrcDefUnknown, 30 | SrcDefMulti, 31 | SrcDefMethod, 32 | SrcDefFunction, 33 | SrcDefType, 34 | SrcDefPackage, 35 | SrcDefVariable, 36 | ] 37 | 38 | for kind in possible-kinds do : 39 | print-list(to-string $ "%_" % [kind], items-of(kind)) -------------------------------------------------------------------------------- /oldtests/tests.stanza: -------------------------------------------------------------------------------- 1 | defpackage user : 2 | import core 3 | 4 | defn main () : 5 | val file = FileInputStream("data.bin") 6 | println(get-long(file)) 7 | 8 | main() -------------------------------------------------------------------------------- /oldtests/tests2.stanza: -------------------------------------------------------------------------------- 1 | defpackage user : 2 | import core 3 | import collections 4 | import stz/algorithms 5 | 6 | defn main () : 7 | 8 | val closure = [ 9 | 1 => `(2 10 11) 10 | 2 => `(1 12) 11 | 3 => `(13 14) 12 | 4 => `(3 15 16)] 13 | val result:List>> = bipartite-closure(closure) 14 | println(result) 15 | 16 | val edges = [ 17 | `a => `(b) 18 | `b => `(e) 19 | `c => `(d) 20 | `d => `(e) 21 | `e => `(c) 22 | `f => `(g) 23 | `g => `(h) 24 | `h => `(f) 25 | `i => `(f)] 26 | println(transitive-closure(edges)) 27 | 28 | val t = HashTable<[Int,Int],String>() 29 | for i in 1 through 4 do : 30 | for j in 1 through 4 do : 31 | val x = "%_ * %_ = %_" % [i, j, i * j] 32 | t[[i, j]] = to-string(x) 33 | println(t) 34 | 35 | main() 36 | -------------------------------------------------------------------------------- /oldtests/verify-reader.stanza: -------------------------------------------------------------------------------- 1 | defpackage verify-reader : 2 | import core 3 | import collections 4 | 5 | public defn main () : 6 | val filename = command-line-arguments()[1] 7 | val tokens1 = unwrap-all(reader/read-file(filename)) 8 | val tokens2 = unwrap-all(reader2/read-file(filename)) 9 | if tokens1 != tokens2 : 10 | val filename-old = string-join $ [filename, ".old"] 11 | val filename-new = string-join $ [filename, ".new"] 12 | println("Not matched! %_ vs %_" % [filename-old, filename-new]) 13 | spit(filename-old, tokens1) 14 | spit(filename-new, tokens2) 15 | main() 16 | -------------------------------------------------------------------------------- /runtime/process.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNTIME_PROCESS_H 2 | #define RUNTIME_PROCESS_H 3 | #include 4 | #include 5 | 6 | //Represents the Process, and the channels for 7 | //communicating with it. 8 | //- pid: The id of the process. 9 | //- handle: The Windows handle to the process. Not used by other platforms. 10 | //- pipeid: A unique integer used to generate the names of the named pipes for communication. 11 | // Will be set to -1 for Windows to indicate that no named pipes are created. 12 | //- in: The standard input stream of the Process. 13 | //- out: The standard output stream of the Process. 14 | //- err: The standard error stream of the Process. 15 | typedef struct { 16 | stz_long pid; 17 | void* handle; 18 | stz_int pipeid; 19 | FILE* in; 20 | FILE* out; 21 | FILE* err; 22 | } Process; 23 | 24 | //Represents the state of the process. 25 | //- state: PROCESS_RUNNING | PROCESS_DONE | PROCESS_TERMINATED | PROCESS_STOPPED 26 | //- code: If state is PROCESS_RUNNING, then code is 0, otherwise, state is the 27 | // exit code of the process. 28 | typedef struct { 29 | stz_int state; 30 | stz_int code; 31 | } ProcessState; 32 | 33 | #define PROCESS_RUNNING 0 34 | #define PROCESS_DONE 1 35 | #define PROCESS_TERMINATED 2 36 | #define PROCESS_STOPPED 3 37 | 38 | #define STANDARD_IN 0 39 | #define STANDARD_OUT 1 40 | #define PROCESS_IN 2 41 | #define PROCESS_OUT 3 42 | #define STANDARD_ERR 4 43 | #define PROCESS_ERR 5 44 | #define NUM_STREAM_SPECS 6 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /scripts/copy-to-site.sh: -------------------------------------------------------------------------------- 1 | mv ~/Desktop/stanza.zip ~/Docs/Programming/stanzaorg/siteroot/resources/files/v1/stanza.zip 2 | mv ~/Desktop/lstanza.zip ~/Docs/Programming/stanzaorg/siteroot/resources/files/v1/lstanza.zip 3 | 4 | -------------------------------------------------------------------------------- /scripts/export.sh: -------------------------------------------------------------------------------- 1 | if [ $# -lt 1 ]; then 2 | echo "Not enough arguments" 3 | exit 2 4 | fi 5 | hg archive $1 6 | cp lstanza $1/lstanza 7 | cd $1 8 | zip -r stanza.zip pkgs fast-pkgs compiler core docs runtime License.txt stanza 9 | mv lstanza stanza 10 | zip -r lstanza.zip pkgs fast-pkgs compiler core docs runtime License.txt stanza 11 | mv stanza.zip lstanza.zip ~/Desktop/ 12 | rm -rf * 13 | -------------------------------------------------------------------------------- /scripts/finish.sh: -------------------------------------------------------------------------------- 1 | scripts/make-asmjit.sh os-x 2 | gcc -std=gnu99 -c core/sha256.c -O3 -o build/sha256.o -I include 3 | gcc -std=gnu99 -c compiler/cvm.c -O3 -o build/cvm.o -I include 4 | gcc -std=gnu99 core/threadedreader.c runtime/driver.c compiler/exec-alloc.c runtime/linenoise.c build/cvm.o build/sha256.o stanza.s -o stanza -DPLATFORM_OS_X -lm -I include -Lbin -lasmjit-os-x -lc++ 5 | -------------------------------------------------------------------------------- /scripts/lfinish.sh: -------------------------------------------------------------------------------- 1 | scripts/make-asmjit.sh linux 2 | gcc -std=gnu99 -c core/sha256.c -O3 -o build/sha256.o -fPIC -I include 3 | gcc -std=gnu99 -c compiler/cvm.c -O3 -o build/cvm.o -fPIC -I include 4 | gcc -std=gnu99 core/threadedreader.c runtime/driver.c compiler/exec-alloc.c runtime/linenoise.c build/cvm.o build/sha256.o lstanza.s -o lstanza -DPLATFORM_LINUX -D_GNU_SOURCE -lm -ldl -fPIC -I include -Lbin -lasmjit-linux -lstdc++ -lrt -lpthread 5 | -------------------------------------------------------------------------------- /scripts/make-all-platforms.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ./scripts/make.sh $1 os-x compile-clean-without-finish 3 | ./scripts/make.sh $1 linux compile-clean-without-finish 4 | ./scripts/make.sh $1 windows compile-clean-without-finish 5 | -------------------------------------------------------------------------------- /scripts/make-asmjit.bat: -------------------------------------------------------------------------------- 1 | cmake -G "MinGW Makefiles" -S libs\asmjit -B build\asmjit 2 | cmake --build build\asmjit 3 | move build\asmjit\libasmjit.a bin\libasmjit-windows.a 4 | del /Q /s build\asmjit 5 | rd /Q /s build\asmjit 6 | -------------------------------------------------------------------------------- /scripts/make-asmjit.sh: -------------------------------------------------------------------------------- 1 | # Set early failure flags 2 | set -e 3 | set -o pipefail 4 | 5 | # Sanity check: Ensure we are calling 6 | # this script with the right number of arguments. 7 | if [ $# -lt 1 ]; then 8 | echo "Not enough arguments" 9 | exit 2 10 | fi 11 | 12 | # Set OPTION as the first argument. 13 | OPTION="$1" 14 | 15 | # Compute FILENAME based upon setting of OPTION. 16 | case "$OPTION" in 17 | os-x) 18 | FILENAME="libasmjit-os-x.a" ;; 19 | linux) 20 | # gcc needs explicit flag for position-independent code. 21 | export CXXFLAGS="-fPIC" 22 | FILENAME="libasmjit-linux.a" ;; 23 | current) 24 | FILENAME="libasmjit.a" ;; 25 | *) cat 1>&2 < debug.txt 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /scripts/make-main.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i core/stringeater.stanza \ 2 | compiler/stz-params.stanza \ 3 | compiler/stz-lexer.stanza \ 4 | compiler/stz-parser.stanza \ 5 | core/macro-utils.stanza \ 6 | compiler/stz-core-macros.stanza \ 7 | compiler/stz-algorithms.stanza \ 8 | compiler/stz-il-ir.stanza \ 9 | compiler/stz-utils.stanza \ 10 | compiler/stz-ids.stanza \ 11 | compiler/stz-input.stanza \ 12 | compiler/lang-read.stanza \ 13 | compiler/lang-check.stanza \ 14 | compiler/stz-namemap.stanza \ 15 | compiler/stz-renamer.stanza \ 16 | compiler/stz-primitives.stanza \ 17 | compiler/stz-resolver.stanza \ 18 | compiler/stz-tl-ir.stanza \ 19 | compiler/stz-type.stanza \ 20 | compiler/stz-infer.stanza \ 21 | compiler/stz-type-calculus.stanza \ 22 | compiler/stz-kl-ir.stanza \ 23 | compiler/stz-kform.stanza \ 24 | compiler/stz-padder.stanza \ 25 | compiler/stz-tgt-ir.stanza \ 26 | compiler/stz-tgt.stanza \ 27 | compiler/stz-bb-ir.stanza \ 28 | compiler/stz-bb.stanza \ 29 | compiler/stz-backend.stanza \ 30 | compiler/stz-asm-ir.stanza \ 31 | compiler/stz-asm-emitter.stanza \ 32 | compiler/stz-compiler.stanza \ 33 | compiler/stz-langs.stanza \ 34 | compiler/lang-renamer.stanza \ 35 | compiler/lang-resolver.stanza \ 36 | compiler/stz-main.stanza \ 37 | -o build/stanzac \ 38 | -flags OPTIMIZE 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /scripts/make-read-pkg.sh: -------------------------------------------------------------------------------- 1 | ./stanza compiler/stz-ids.stanza \ 2 | compiler/stz-primitives.stanza \ 3 | compiler/stz-utils.stanza \ 4 | compiler/stz-kl-ir.stanza \ 5 | compiler/stz-namemap.stanza \ 6 | compiler/stz-tl-ir.stanza \ 7 | compiler/stz-params.stanza \ 8 | compiler/stz-pkg-ir.stanza \ 9 | tests/read-pkg.stanza \ 10 | -o read-pkg 11 | 12 | -------------------------------------------------------------------------------- /scripts/make-reader.sh: -------------------------------------------------------------------------------- 1 | stanza core/core.stanza \ 2 | core/collections.stanza \ 3 | compiler/stz-utils.stanza \ 4 | compiler/stz-params.stanza \ 5 | compiler/stz-ids.stanza \ 6 | compiler/stz-primitives.stanza \ 7 | compiler/stz-tl-ir.stanza \ 8 | compiler/stz-kl-ir.stanza \ 9 | compiler/stz-pl-ir.stanza \ 10 | compiler/stz-asm-ir.stanza \ 11 | compiler/stz-tgt-ir.stanza \ 12 | compiler/stz-khier.stanza \ 13 | compiler/stz-serializer.stanza \ 14 | compiler/stz-backend.stanza \ 15 | compiler/stz-asm-emitter.stanza \ 16 | compiler/stz-pkg.stanza \ 17 | compiler/stz-pkg-reader.stanza \ 18 | -o linker 19 | -------------------------------------------------------------------------------- /scripts/make-serialize-lang.sh: -------------------------------------------------------------------------------- 1 | ./stanza core/reader.stanza \ 2 | core/macro-utils.stanza \ 3 | compiler/stz-algorithms.stanza \ 4 | compiler/stz-parser.stanza \ 5 | compiler/stz-params.stanza \ 6 | compiler/stz-core-macros.stanza \ 7 | compiler/lang-serializer.stanza \ 8 | -o serialize-lang \ 9 | -flags TESTING 10 | 11 | -------------------------------------------------------------------------------- /scripts/make-test-asm.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i compiler/stz-asm-emitter.stanza -o build/test-asm -flags ASM-STANDALONE 2 | 3 | 4 | -------------------------------------------------------------------------------- /scripts/make-test-full.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i verify/test-full.stanza -o build/test-full 2 | 3 | 4 | -------------------------------------------------------------------------------- /scripts/make-test-input.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i verify/test-input.stanza -o build/test-input 2 | 3 | 4 | -------------------------------------------------------------------------------- /scripts/make-test-kl-lowered.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i verify/test-kl.stanza -o build/kl -flags LOWERED 2 | -------------------------------------------------------------------------------- /scripts/make-test-kl.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i verify/test-kl.stanza -o build/hikl 2 | -------------------------------------------------------------------------------- /scripts/make-test-macros.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i verify/test-macros.stanza -o build/test-macros 2 | 3 | 4 | -------------------------------------------------------------------------------- /scripts/make-test-regalloc.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i compiler/stz-regalloc.stanza -o build/regalloc 2 | 3 | 4 | -------------------------------------------------------------------------------- /scripts/make-test-tgt.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i verify/test-tgt.stanza -o build/tgt 2 | 3 | 4 | -------------------------------------------------------------------------------- /scripts/make-test-type-kl.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i verify/test-type-kl.stanza -o build/test-type-kl 2 | 3 | 4 | -------------------------------------------------------------------------------- /scripts/make-test-type.sh: -------------------------------------------------------------------------------- 1 | ./estanza -i verify/test-type.stanza -o build/test-type 2 | 3 | 4 | -------------------------------------------------------------------------------- /scripts/make-test.sh: -------------------------------------------------------------------------------- 1 | ./build/stanza3 boot2/core/core.stanza \ 2 | boot2/core/collections.stanza \ 3 | boot2/tests/tests2.stanza \ 4 | -o test 5 | 6 | #gcc test.s boot2/runtime/driver.c -o test 7 | -------------------------------------------------------------------------------- /scripts/make-tgt-compiler.sh: -------------------------------------------------------------------------------- 1 | ./stanza \ 2 | compiler/stz-params.stanza \ 3 | compiler/stz-utils.stanza \ 4 | compiler/stz-ids.stanza \ 5 | compiler/stz-algorithms.stanza \ 6 | compiler/stz-padder.stanza \ 7 | compiler/stz-backend.stanza \ 8 | compiler/stz-imms.stanza \ 9 | compiler/stz-tgt-ir.stanza \ 10 | compiler/stz-bb-ir.stanza \ 11 | compiler/stz-asm-ir.stanza \ 12 | compiler/stz-tgt-writer.stanza \ 13 | compiler/stz-bb.stanza \ 14 | compiler/stz-tgt-compiler.stanza \ 15 | -o tgt-compiler \ 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /scripts/run-postcompile-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # USAGES: 4 | # ./scripts/run-postcompile-tests.sh ./mystanza 5 | 6 | # Check arguments 7 | if [ $# -lt 1 ]; then 8 | echo "Not enough arguments" 9 | exit 2 10 | fi 11 | 12 | STANZA="$1" 13 | export STANZA_COMPILER="$STANZA" 14 | 15 | # Run all the tests in stanza-postcompile-tests in the VM 16 | $STANZA run-test tests/stanza.proj stz/stanza-postcompile-tests 17 | 18 | # Compile and run all the tests in stanza-postcompile-tests 19 | $STANZA compile-test build-stanza.proj tests/stanza.proj stz/stanza-postcompile-tests -o build/stanza-postcompile-tests 20 | build/stanza-postcompile-tests 21 | 22 | # Run all the tests in stz/stanza-postcompile-compiler-only-tests in the VM 23 | $STANZA compile-test build-stanza.proj tests/stanza.proj stz/stanza-postcompile-compiler-only-tests -o build/stanza-postcompile-compiler-only-tests -ccfiles tests/extern_c_callbacks.c 24 | build/stanza-postcompile-compiler-only-tests 25 | 26 | # Compile and run the tests in stz/stanza-postcompile-compiler-only-tests using a specially bootstrapped compiler 27 | $STANZA extend tests/stanza.proj -supported-vm-packages stz/test-externs -o build/stanzatest -ccfiles tests/extern_c_callbacks.c 28 | build/stanzatest run-test build-stanza.proj tests/stanza.proj stz/stanza-postcompile-compiler-only-tests 29 | -------------------------------------------------------------------------------- /scripts/run-tests.sh: -------------------------------------------------------------------------------- 1 | stanza run-test build-stanza.proj tests/stanza.proj stz/stanza-tests -not-tagged long 2 | stanza compile-test build-stanza.proj tests/stanza.proj stz/stanza-tests -o build/stanza-tests 3 | ./build/stanza-tests 4 | -------------------------------------------------------------------------------- /scripts/test-boot-prog.sh: -------------------------------------------------------------------------------- 1 | ./bootprog boot2/core/core.stanza \ 2 | boot2/core/collections.stanza \ 3 | boot2/tests/tests2.stanza \ 4 | -s boottest.s 5 | 6 | gcc boottest.s boot2/runtime/driver.c -o boottest 7 | -------------------------------------------------------------------------------- /scripts/test-boot.sh: -------------------------------------------------------------------------------- 1 | ./bin/stanzadev boot/core/core.stanza \ 2 | boot/core/collections.stanza \ 3 | boot/tests/tests2.stanza \ 4 | -o test \ 5 | -no-implicits \ 6 | -verbose 7 | 8 | -------------------------------------------------------------------------------- /scripts/test-compiler.sh: -------------------------------------------------------------------------------- 1 | ./stanza boot/core/core.stanza \ 2 | boot/core/collections.stanza \ 3 | boot/core/reader.stanza \ 4 | boot/core/macro-utils.stanza \ 5 | boot/compiler/stz-algorithms.stanza \ 6 | boot/compiler/stz-padder.stanza \ 7 | boot/compiler/stz-utils.stanza \ 8 | boot/compiler/stz-parser.stanza \ 9 | boot/compiler/stz-params.stanza \ 10 | boot/compiler/stz-core-macros.stanza \ 11 | boot/compiler/stz-ids.stanza \ 12 | boot/compiler/lang-read.stanza \ 13 | boot/compiler/lang-check.stanza \ 14 | boot/compiler/stz-primitives.stanza \ 15 | boot/compiler/stz-il-ir.stanza \ 16 | boot/compiler/stz-tl-ir.stanza \ 17 | boot/compiler/stz-kl-ir.stanza \ 18 | boot/compiler/stz-tgt-ir.stanza \ 19 | boot/compiler/stz-bb-ir.stanza \ 20 | boot/compiler/stz-asm-ir.stanza \ 21 | boot/compiler/stz-backend.stanza \ 22 | boot/compiler/stz-input.stanza \ 23 | boot/compiler/stz-namemap.stanza \ 24 | boot/compiler/stz-renamer.stanza \ 25 | boot/compiler/stz-resolver.stanza \ 26 | boot/compiler/stz-infer.stanza \ 27 | boot/compiler/stz-type-calculus.stanza \ 28 | boot/compiler/stz-type.stanza \ 29 | boot/compiler/stz-kform.stanza \ 30 | boot/compiler/stz-tgt.stanza \ 31 | boot/compiler/stz-bb.stanza \ 32 | boot/compiler/stz-asm-emitter.stanza \ 33 | boot/compiler/stz-compiler.stanza \ 34 | boot/compiler/stz-arg-parser.stanza \ 35 | boot/compiler/stz-langs.stanza \ 36 | boot/compiler/lang-renamer.stanza \ 37 | boot/compiler/lang-resolver.stanza \ 38 | boot/compiler/stz-main.stanza \ 39 | -s test.s \ 40 | -o bin/$1 \ 41 | -no-implicits \ 42 | -optimize 43 | -------------------------------------------------------------------------------- /scripts/test-main.sh: -------------------------------------------------------------------------------- 1 | ./build/stanzac -i boot/core/core.stanza \ 2 | boot/core/collections.stanza \ 3 | boot/tests/tests2.stanza \ 4 | -o test2.s \ 5 | -optimize 6 | 7 | gcc test2.s boot/runtime/driver.c -o prog2 8 | -------------------------------------------------------------------------------- /scripts/wfinish.bat: -------------------------------------------------------------------------------- 1 | call scripts\make-asmjit.bat 2 | gcc -std=gnu99 -c core/sha256.c -O3 -o build/sha256.o -I include 3 | gcc -std=gnu99 -c compiler/cvm.c -O3 -o build/cvm.o -I include 4 | gcc -std=gnu99 core/threadedreader.c core/dynamic-library.c compiler/exec-alloc.c runtime/driver.c build/cvm.o build/sha256.o wstanza.s -o wstanza -DPLATFORM_WINDOWS -Wl,-Bstatic -lm -lpthread -I include -Lbin -lasmjit-windows -lstdc++ 5 | -------------------------------------------------------------------------------- /scripts/wfinish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | if [[ -z "$CC" ]]; then 6 | if [[ "$(uname -s)" == MINGW* ]]; then 7 | # Not cross-compiling, so just use the stock GCC 8 | CC=gcc 9 | else 10 | echo 'Need to set $CC to a valid compiler or cross-compiler' >/dev/stderr 11 | exit 2 12 | fi 13 | fi 14 | 15 | CCFLAGS="-I include -DPLATFORM_WINDOWS -std=gnu99 -O3 -fPIC -Wall $CCFLAGS" 16 | 17 | [[ ! -d "build" ]] && mkdir "build" 18 | 19 | "$CC" $CCFLAGS -c core/sha256.c -o build/sha256.o 20 | "$CC" $CCFLAGS -c compiler/cvm.c -o build/cvm.o 21 | "$CC" $CCFLAGS -c runtime/driver.c -o build/driver.o 22 | 23 | "$CC" \ 24 | build/sha256.o \ 25 | build/cvm.o \ 26 | build/driver.o \ 27 | wstanza.s \ 28 | -o wstanza -Wl,-Bstatic -lm -lpthread -fPIC 29 | -------------------------------------------------------------------------------- /stanza.proj: -------------------------------------------------------------------------------- 1 | include "examples/stanza.proj" 2 | 3 | package stz/line-noise-prompter requires : 4 | ccfiles: "runtime/linenoise.c" 5 | 6 | package stz/vm requires : 7 | ccfiles: "build/cvm.o" 8 | 9 | package stz/code-template-table requires : 10 | ccfiles: "compiler/exec-alloc.c" 11 | 12 | compile file "build/cvm.o" from "compiler/cvm.c" : 13 | on-platform : 14 | os-x : "cc -std=gnu99 '{.}/compiler/cvm.c' -c -o '{.}/build/cvm.o' -O3 -D PLATFORM_OS_X" 15 | linux : "cc -std=gnu99 '{.}/compiler/cvm.c' -c -o '{.}/build/cvm.o' -O3 -D PLATFORM_LINUX -fPIC" 16 | windows : "gcc -std=gnu99 '{.}\\compiler\\cvm.c' -c -o '{.}\\build\\cvm.o' -O3 -D PLATFORM_WINDOWS" 17 | 18 | package core/sha256 requires : 19 | ccfiles: "build/sha256.o" 20 | compile file "build/sha256.o" from "core/sha256.c" : 21 | on-platform : 22 | os-x : "cc -std=gnu99 '{.}/core/sha256.c' -c -o '{.}/build/sha256.o' -O3" 23 | linux : "cc -std=gnu99 '{.}/core/sha256.c' -c -o '{.}/build/sha256.o' -O3 -fPIC" 24 | windows : "gcc -std=gnu99 '{.}\\core\\sha256.c' -c -o '{.}\\build\\sha256.o' -O3" 25 | 26 | package core/threaded-reader requires : 27 | ccfiles: "core/threadedreader.c" 28 | 29 | package core/dynamic-library requires : 30 | ccfiles: "core/dynamic-library.c" 31 | 32 | package stz/asmjit requires : 33 | ccflags: 34 | on-platform : 35 | os-x : 36 | "-L{.}/bin" 37 | "-lasmjit" 38 | "-lc++" 39 | linux : 40 | "-L{.}/bin" 41 | "-lasmjit" 42 | "-lstdc++" 43 | "-lrt" 44 | windows : 45 | "-L{.}/bin" 46 | "-lasmjit" 47 | "-lstdc++" 48 | 49 | package stz/macro-plugin requires : 50 | ccfiles: "compiler/macro-handshake.c" 51 | ccflags: "-shared" 52 | 53 | -------------------------------------------------------------------------------- /tests/build-dev-tools.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/build-dev-tools : 2 | import core 3 | import collections 4 | import stz-test-suite/test-tools 5 | 6 | ;Build a dev tool and register it. 7 | public defn build-dev-tool (name:String) : 8 | val package-name = to-string("stz-test-suite/%_" % [name]) 9 | call-stanza $ [ 10 | package-name 11 | "-o" build-file(name)] 12 | 13 | ;Retrieve an already-built dev tool. 14 | public defn dev-tool (name:String) : 15 | if file-exists?(build-file(name)) : build-file(name) 16 | else : throw(Exception("Development tool %~ not yet built." % [name])) 17 | 18 | ;Call dev tool and get output. 19 | public defn call-dev-tool (args:Tuple) -> String : 20 | val new-args = to-tuple $ 21 | for (arg in args, i in 0 to false) seq : 22 | if i == 0 : dev-tool(arg) 23 | else : arg 24 | call-system-and-get-output(new-args[0], new-args) -------------------------------------------------------------------------------- /tests/conantest02/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Stanza version to download in the form 0_12_34 matching what's in the zip filename 3 | STANZA_VERSION := 0_17_44 4 | 5 | # detect platform 6 | SYS := $(shell gcc -dumpmachine) 7 | ifneq (, $(findstring linux, $(SYS))) 8 | PLATFORM := LINUX 9 | STANZA_ZIP := lstanza_$(STANZA_VERSION).zip 10 | else ifneq (, $(findstring mingw, $(SYS))) 11 | PLATFORM := WINDOWS 12 | STANZA_ZIP := wstanza_$(STANZA_VERSION).zip 13 | else ifneq (, $(findstring darwin, $(SYS))) 14 | PLATFORM := OS_X 15 | STANZA_ZIP := stanza_$(STANZA_VERSION).zip 16 | else 17 | PLATFORM := UNKNOWN 18 | $(error Unknown platform: $(SYS)) 19 | endif 20 | 21 | CURL := curl 22 | CURL_ARGS := -LsS 23 | UNZIP := unzip -q 24 | 25 | BUILD_DIR := build 26 | STANZA_DIR := stanza 27 | STANZA_URL := http://lbstanza.org/resources/stanza/$(STANZA_ZIP) 28 | 29 | STANZA := stanza/stanza 30 | VERBOSE := -verbose 31 | 32 | .ONESHELL: 33 | .PHONY: help all clean clean-stanza clean-all 34 | 35 | 36 | all: asmjit-app 37 | 38 | 39 | # create build dir 40 | $(BUILD_DIR): 41 | mkdir build 42 | 43 | # download and unzip stanza 44 | $(STANZA_DIR): 45 | @echo "Downloading $(STANZA_ZIP)" 46 | $(RM) -r $(STANZA_DIR) 47 | $(CURL) $(CURL_ARGS) -o $(STANZA_ZIP) $(STANZA_URL) 48 | $(UNZIP) -d $(STANZA_DIR) $(STANZA_ZIP) 49 | $(RM) $(STANZA_ZIP) 50 | 51 | # install/configure stanza 52 | .stanza: | $(STANZA_DIR) 53 | cd $(STANZA_DIR) 54 | ./stanza install -platform linux -path .. 55 | cd .. 56 | 57 | 58 | # link final executable 59 | $(BUILD_DIR)/asmjit-app: stanza.proj | .stanza $(STANZA_DIR) $(BUILD_DIR) 60 | export STANZA_CONFIG="$$PWD" 61 | $(STANZA) compile asmjit-app -o $(BUILD_DIR)/asmjit-app $(VERBOSE) 62 | 63 | # convenience target 64 | asmjit-app: $(BUILD_DIR)/asmjit-app 65 | ls -l $(BUILD_DIR)/asmjit-app 66 | 67 | 68 | # clean 69 | clean: 70 | rm -rf $(BUILD_DIR) asmjit-app 71 | 72 | clean-stanza: 73 | rm -rf $(STANZA_DIR) .stanza 74 | 75 | clean-all: clean clean-stanza 76 | rm -rf .conan conanfile.txt 77 | -------------------------------------------------------------------------------- /tests/conantest02/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Overview 3 | This repo will do the following: 4 | - Download and install stanza in the current directory 5 | - Use conan to download a pre-compiled static library of asmjit 6 | - Use stanza to compile the stanza-asmjit interface code written in C++ 7 | - Use stanza to compile the asmjit-app test program written in stanza 8 | - Use stanza to link the results into an executable 9 | 10 | # Prerequisites 11 | Already have curl, conan, cmake, gcc installed 12 | No need to have stanza installed 13 | 14 | # Build 15 | 16 | ``` 17 | make stanza conan asmjit-app 18 | ``` 19 | 20 | # Run output 21 | 22 | ``` 23 | build/asmjit-app 24 | ``` 25 | 26 | # Expected output 27 | 28 | Calls a simple function in the library and outputs the result 29 | 30 | ``` 31 | RES = 67 32 | ``` -------------------------------------------------------------------------------- /tests/conantest02/asmjit-app.stanza: -------------------------------------------------------------------------------- 1 | defpackage asmjit-app : 2 | import core 3 | import stz/asmjit 4 | 5 | defn gen-const-func (a:Assembler, value:Long) -> Label : 6 | val lab = new-label(a) 7 | bind(a, lab) 8 | mov(a, eax, value) 9 | ret(a) 10 | lab 11 | 12 | defn main () : 13 | val rt = jit-runtime-new() 14 | val code = code-holder-new(rt) 15 | val a = assembler-new(code) 16 | val fl = gen-const-func(a, 67L) 17 | val f = add(rt, code) 18 | val res = call(f) 19 | println("RES = %_" % [res]) 20 | 21 | main() -------------------------------------------------------------------------------- /tests/conantest02/stanza.proj: -------------------------------------------------------------------------------- 1 | 2 | foreign-package-params(conan) : () 3 | 4 | package asmjit-app defined-in "asmjit-app.stanza" 5 | package stz/asmjit defined-in "{WORKDIR}/stanza-asmjit/stz-asmjit.stanza" 6 | package stz/asmjit requires : 7 | ccfiles: 8 | "{WORKDIR}/build/stz-asmjit.o" 9 | ccflags: 10 | on-platform: 11 | os-x : 12 | "{CONAN-INCLUDES}" 13 | "-lc++" 14 | linux : 15 | "{CONAN-INCLUDES}" 16 | "-lstdc++" 17 | foreign-packages(conan) : 18 | "asmjit/cci.20220210" 19 | 20 | compile file "{WORKDIR}/build/stz-asmjit.o" from "{WORKDIR}/stanza-asmjit/stz-asmjit.cpp" : 21 | "g++ -c -O3 {.}/stanza-asmjit/stz-asmjit.cpp --std=c++11 -o {WORKDIR}/build/stz-asmjit.o {CONAN-INCLUDES}" 22 | 23 | -------------------------------------------------------------------------------- /tests/data/ex2.proj: -------------------------------------------------------------------------------- 1 | ;Example proj file 2 | 3 | var myvar = 4 | on-platform : 5 | os-x: 6 | A 7 | B 8 | C 9 | else : 10 | D 11 | E 12 | F 13 | 14 | package myprogram requires : 15 | ccflags: "{myvar}" 16 | 17 | -------------------------------------------------------------------------------- /tests/data/ex3.proj: -------------------------------------------------------------------------------- 1 | ;Example proj file 2 | 3 | var DIR = "{.}" 4 | 5 | compile file "myfile.o" : 6 | "c++ -o {DIR}/myfile.o" 7 | -------------------------------------------------------------------------------- /tests/data/ex4.proj: -------------------------------------------------------------------------------- 1 | var ROOT = {.} 2 | 3 | var DIR = {WORKDIR} 4 | 5 | compile file "temp1" : 6 | "c++ {ROOT} {DIR}" -------------------------------------------------------------------------------- /tests/data/ex5.proj: -------------------------------------------------------------------------------- 1 | include "ex5a.proj" 2 | include? "ex5b.proj" 3 | include? "ex5c.proj" -------------------------------------------------------------------------------- /tests/data/ex5a.proj: -------------------------------------------------------------------------------- 1 | package a defined-in "a.stanza" -------------------------------------------------------------------------------- /tests/data/ex5c.proj: -------------------------------------------------------------------------------- 1 | package c defined-in "c.stanza" -------------------------------------------------------------------------------- /tests/data/ex6.proj: -------------------------------------------------------------------------------- 1 | var ROOT = {.} 2 | 3 | foreign-package-params(conan) : 4 | build-dir: "build" 5 | 6 | package root defined-in "{ROOT}/a.stanza" 7 | 8 | include "ex6a.proj" 9 | include "ex6b.proj" -------------------------------------------------------------------------------- /tests/data/ex6a.proj: -------------------------------------------------------------------------------- 1 | package roota defined-in "{ROOT}/a.stanza" -------------------------------------------------------------------------------- /tests/data/ex6b.proj: -------------------------------------------------------------------------------- 1 | package rootb defined-in "{ROOT}/b.stanza" -------------------------------------------------------------------------------- /tests/data/ex6b.stanza: -------------------------------------------------------------------------------- 1 | package rootb defined-in "{ROOT}/b.stanza" -------------------------------------------------------------------------------- /tests/data/ex7.proj: -------------------------------------------------------------------------------- 1 | package temp defined-in "{ROOT}/temp.stanza" -------------------------------------------------------------------------------- /tests/data/ex8.proj: -------------------------------------------------------------------------------- 1 | package temp defined-in "temp.stanza" 2 | 3 | package temp requires : 4 | dynamic-library: "mydlls/mylib.so" 5 | ccfiles: 6 | "mycfiles/mycfile.c" 7 | 8 | dynamic-library-dirs : 9 | "mydlls" 10 | "mydlls2" -------------------------------------------------------------------------------- /tests/exampletest01/alib.stanza: -------------------------------------------------------------------------------- 1 | defpackage example-test/alib : 2 | import core 3 | 4 | println("ALIB file of example-test.") -------------------------------------------------------------------------------- /tests/exampletest01/blib.stanza: -------------------------------------------------------------------------------- 1 | defpackage example-test/blib : 2 | import core 3 | 4 | println("BLIB file of example-test.") -------------------------------------------------------------------------------- /tests/exampletest01/main.stanza: -------------------------------------------------------------------------------- 1 | defpackage example-test/main : 2 | import core 3 | import example-test/alib 4 | import example-test/blib 5 | 6 | println("Main file of example-test.") -------------------------------------------------------------------------------- /tests/exampletest01/stanza.proj: -------------------------------------------------------------------------------- 1 | foreign-package-params(example-manager) : 2 | project-root: "." 3 | email: "patrick@li.com" 4 | 5 | package example-test/alib requires : 6 | foreign-packages(example-manager) : 7 | "EM/ALIB-V1" 8 | "EM/STDLIB-V0" 9 | "EM/STDWINDOWING-V3" 10 | 11 | package example-test/blib requires : 12 | foreign-packages(example-manager) : 13 | "EM/BLIB-V2" 14 | "EM/STDWINDOWING-V3" 15 | 16 | packages example-test/* defined-in "." -------------------------------------------------------------------------------- /tests/gen-trampoline.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz/gen-trampoline : 2 | import core 3 | import collections 4 | import stz/code-emitter 5 | import stz/asm-ir 6 | import stz/backend 7 | import stz/asm-emitter 8 | import stz/c-trampoline 9 | 10 | ;============================================================ 11 | ;============= Trampoline Assembly Generation =============== 12 | ;============================================================ 13 | 14 | ;Emitter that emits according to the given backend. 15 | defn emitter (backend:Backend) -> CodeEmitter : 16 | val label-counter = to-seq(0 to false) 17 | val o = current-output-stream() 18 | new CodeEmitter : 19 | defmethod emit (this, ins:Ins) : 20 | emit-asm(o, ins, backend) 21 | defmethod unique-label (this) : 22 | next(label-counter) 23 | 24 | ;Generate the trampoline assembly file. 25 | defn generate-trampoline-asm-file (filename:String, backend:Backend) : 26 | with-output-file(FileOutputStream(filename), 27 | fn () : 28 | compile-c-trampoline-stub(backend, emitter(backend))) 29 | 30 | ;============================================================ 31 | ;=================== Main Driver ============================ 32 | ;============================================================ 33 | 34 | defn main () : 35 | generate-trampoline-asm-file("build/osx-trampoline.s", X64Backend()) 36 | generate-trampoline-asm-file("build/linux-trampoline.s", L64Backend()) 37 | generate-trampoline-asm-file("build/windows-trampoline.s", W64Backend()) 38 | 39 | ;============================================================ 40 | ;======================= Launch! ============================ 41 | ;============================================================ 42 | 43 | main() -------------------------------------------------------------------------------- /tests/indexing-data/stanza.proj: -------------------------------------------------------------------------------- 1 | package test-package defined-in "test-package.stanza" 2 | package test-unresolved-symbol defined-in "test-unresolved-symbol.stanza" 3 | -------------------------------------------------------------------------------- /tests/indexing-data/test-package.stanza: -------------------------------------------------------------------------------- 1 | defpackage test-package : 2 | import core 3 | import collections 4 | 5 | public defn public-fn () -> Int : 0 6 | protected defn protected-fn () -> Int : 0 7 | defn private-fn () -> Int : 0 8 | 9 | public deftype PublicType 10 | protected deftype ProtectedType 11 | deftype PrivateType 12 | 13 | defn takes-fn-as-arg (body: (False) -> ?T, not-named) -> T : 14 | body(false) 15 | 16 | defmulti my-multi (arg) -> False 17 | defmethod my-multi (arg:Int) : 18 | println("Arg is an Int") 19 | 20 | public defn to-chunks (s:Seqable, chunk-sz:Int) -> Seq> : 21 | val s* = to-seq(s) 22 | generate : 23 | while not empty?(s*) : 24 | yield $ to-tuple $ 25 | for (e in s*, n in 0 to chunk-sz) seq : 26 | e 27 | 28 | defn maps-equal? (lhs:?T, rhs:?T, map-functions:Tuple<(T -> Equalable)>) -> True|False : 29 | all?({_0(lhs) == _0(rhs)}, map-functions) 30 | 31 | defn memoize* (f: (T, ((T, ?) -> S)) -> ?S) -> (T -> S) : 32 | val table = HashTable() 33 | defn recurse (key:T, rec:((T, ?) -> S)) : 34 | if not key?(table, key) : 35 | val result = f(key, rec) 36 | table[key] = result 37 | result 38 | else : 39 | table[key] 40 | fn (key:T) : 41 | recurse(key, recurse) 42 | 43 | defn apply (f: (T0, T1, T2) -> ?R, args:[?T0, ?T1, ?T2]) -> R : 44 | val [a0, a1, a2] = args 45 | f(a0, a1, a2) 46 | 47 | defn tuple-zip (f:[A0 -> ?R0, A1 -> ?R1], args:[?A0, ?A1]) -> [R0, R1] : 48 | val [f0, f1] = f 49 | val [a0, a1] = args 50 | [f0(a0), f1(a1)] 51 | 52 | doc: "A public struct." 53 | public defstruct PublicStruct 54 | 55 | val PRIVATE-VAL = 1.2345 56 | val PRIVATE-VAR = 3.14159 57 | lostanza val PRIVATE-LS-VAL : int = 1 58 | 59 | let : 60 | val scoped-variable = 1 61 | false -------------------------------------------------------------------------------- /tests/indexing-data/test-unresolved-symbol.stanza: -------------------------------------------------------------------------------- 1 | defpackage test-unresolved-symbol : 2 | import core 3 | 4 | val x = Vector() 5 | -------------------------------------------------------------------------------- /tests/macros/macro-a.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/macros/macro-a : 2 | import core 3 | import collections 4 | import stz/core-macros 5 | 6 | defsyntax macro-a-syntax : 7 | import exp4 from core 8 | 9 | defrule exp4 = (say-macro-a) : 10 | val template = `(core/println("Macro [A]")) 11 | parse-syntax[core / #exp](template) -------------------------------------------------------------------------------- /tests/macros/macro-b.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/macros/macro-b : 2 | import core 3 | import collections 4 | import stz/core-macros 5 | 6 | defsyntax macro-b-syntax : 7 | import exp4 from core 8 | 9 | defrule exp4 = (say-macro-b) : 10 | val template = `(core/println("Macro [B]")) 11 | parse-syntax[core / #exp](template) -------------------------------------------------------------------------------- /tests/macros/macro-c.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/macros/macro-c : 2 | import core 3 | import collections 4 | import stz/core-macros 5 | 6 | defsyntax macro-c-syntax : 7 | import exp4 from core 8 | 9 | defrule exp4 = (say-macro-c) : 10 | val template = `(core/println("Macro [C]")) 11 | parse-syntax[core / #exp](template) -------------------------------------------------------------------------------- /tests/macros/stanza.proj: -------------------------------------------------------------------------------- 1 | build-macros macro-a : 2 | inputs: 3 | stz-test-suite/macros/macro-a 4 | o: "../build/macro-a" 5 | 6 | build-macros macro-b : 7 | inputs: 8 | stz-test-suite/macros/macro-b 9 | o: "../build/macro-b" 10 | 11 | build-macros macro-c : 12 | inputs: 13 | stz-test-suite/macros/macro-c 14 | o: "../build/macro-c" 15 | 16 | build-macros macro-ab : 17 | inputs: 18 | stz-test-suite/macros/macro-a 19 | stz-test-suite/macros/macro-b 20 | o: "../build/macro-ab" 21 | 22 | syntax-packages (macro-a-syntax, macro-b-syntax) defined-in "../build/macro-ab" 23 | syntax-packages (macro-a-syntax) defined-in "../build/macro-a" 24 | syntax-packages (macro-b-syntax) defined-in "../build/macro-b" 25 | syntax-packages (macro-c-syntax) defined-in "../build/macro-c" 26 | -------------------------------------------------------------------------------- /tests/macros/test-macros.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz-test-suite/macros/test-macros : 3 | import core 4 | import collections 5 | 6 | deftest split-macro-b-a-syntax : 7 | #with-added-syntax(macro-b-syntax) : 8 | println("Hello world") 9 | for i in 0 to 3 do : 10 | say-macro-b 11 | for j in 0 to 3 do : 12 | #with-added-syntax(macro-a-syntax) : 13 | say-macro-b 14 | say-macro-a 15 | 16 | deftest split-macro-a-b-syntax : 17 | #with-added-syntax(macro-a-syntax) : 18 | println("Hello world") 19 | for i in 0 to 3 do : 20 | say-macro-a 21 | for j in 0 to 3 do : 22 | #with-added-syntax(macro-b-syntax) : 23 | say-macro-b 24 | say-macro-a 25 | 26 | deftest macro-ab-syntax : 27 | #with-added-syntax(macro-a-syntax, macro-b-syntax) : 28 | println("Hello world") 29 | for i in 0 to 3 do : 30 | say-macro-b 31 | for j in 0 to 3 do : 32 | say-macro-b 33 | say-macro-a -------------------------------------------------------------------------------- /tests/macros/test-macros2.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz-test-suite/macros/test-macros2 : 3 | import core 4 | import collections 5 | 6 | deftest macro-c-syntax : 7 | #with-added-syntax(macro-c-syntax) : 8 | println("Hello world") 9 | for i in 0 to 3 do : 10 | say-macro-c -------------------------------------------------------------------------------- /tests/repl-type-decl/animals.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/repl-type-decl/animals : 2 | import core 3 | import collections 4 | 5 | public deftype Dog 6 | 7 | public deftype Cat -------------------------------------------------------------------------------- /tests/repl-type-decl/base.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/repl-type-decl/base : 2 | import core 3 | import collections 4 | import stz-test-suite/repl-type-decl/animals 5 | 6 | public deftype AbstractType : 7 | Int <: AbstractType 8 | Dog <: AbstractType 9 | Cat <: AbstractType 10 | 11 | -------------------------------------------------------------------------------- /tests/repl-type-decl/child.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/repl-type-decl/child : 2 | import core 3 | import collections 4 | 5 | public val myclosure = fn () : 6 | val x:? = 23 7 | val f = stz-test-suite/repl-type-decl/side/myfunc 8 | f(x) -------------------------------------------------------------------------------- /tests/repl-type-decl/side.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/repl-type-decl/side : 2 | import core 3 | import collections 4 | import stz-test-suite/repl-type-decl/base 5 | 6 | public defn myfunc (x:AbstractType) -> False : 7 | false 8 | 9 | public defn myfunc (x:String) -> False : 10 | false -------------------------------------------------------------------------------- /tests/run.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/run : 2 | import core 3 | import collections 4 | import stz-test-suite/test-tools 5 | 6 | ;Helper: Run the tests defined in a given file. 7 | defn run-suite (name:String) : 8 | val package = to-string("stz-test-suite/%_" % [name]) 9 | try : call-stanza $ ["run-test" package] 10 | catch (e) : println(e) 11 | 12 | ;Main function 13 | defn main () : 14 | run-suite("test-proj") 15 | run-suite("test-linker") 16 | run-suite("test-package-manager") 17 | 18 | ;Launch! 19 | main() -------------------------------------------------------------------------------- /tests/stanza-postcompile-compiler-only-tests.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/stanza-postcompile-compiler-only-tests : 3 | import core 4 | import collections 5 | import stz/test-externs -------------------------------------------------------------------------------- /tests/stanza-postcompile-tests.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/stanza-postcompile-tests : 3 | import core 4 | import collections 5 | import stz/test-multis 6 | import stz/test-heap 7 | import stz/test-infer 8 | import stz/test-utils 9 | import stz/test-constants 10 | import stz/test-inline-targ 11 | 12 | ;============================================================ 13 | ;================ Compilation Errors Tests ================== 14 | ;============================================================ 15 | 16 | defn stanza-compiler () : 17 | val stanza = get-env("STANZA_COMPILER") 18 | match(stanza:String) : stanza 19 | else : fatal("The Stanza compiler needs to be set in the STANZA_COMPILER environment variable.") 20 | 21 | deftest compile-test-lostanza : 22 | val stanza = stanza-compiler() 23 | val output = call-system-and-get-output(stanza, [stanza, "tests/stanza.proj" "stz/test-lostanza" "-s" "temp.s"]) 24 | println(output) 25 | val MSG = \tests/test-lostanza.stanza:7.14: Cannot access indexed slot in expression of type ptr. 26 | #ASSERT(trim(output) == MSG) 27 | 28 | deftest test-constant-fold : 29 | val stanza = stanza-compiler() 30 | call-system(stanza, [stanza "tests/stanza.proj" "stz/test-constant-fold-gen" "-o" "build/gen-constant-fold"]) 31 | cmd $ "build/gen-constant-fold build/test-constant-fold.stanza" 32 | call-system(stanza, [stanza "build/test-constant-fold.stanza" "-o" "build/test-constant-fold"]) 33 | call-system(stanza, [stanza "build/test-constant-fold.stanza" "-o" "build/test-constant-fold-optimized" "-optimize"]) 34 | val output1 = call-system-and-get-output("build/test-constant-fold", ["build/test-constant-fold"]) 35 | val output2 = call-system-and-get-output("build/test-constant-fold-optimized", ["build/test-constant-fold-optimized"]) 36 | #ASSERT(output1 == output2) -------------------------------------------------------------------------------- /tests/stanza-tests.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/stanza-tests : 3 | import core 4 | import collections 5 | import stz/test-utils 6 | import stz/test-trampoline 7 | import stz/test-paths 8 | import stz/test-dispatch-dag 9 | import stz/test-definitions-database 10 | import stz/test-bitset-intrinsics 11 | import stz/test-meta-utils 12 | import stz/test-cycles 13 | import stz/test-shuffle 14 | import stz/test-core 15 | import stz/test-nan 16 | import stz/test-match-syntax -------------------------------------------------------------------------------- /tests/test-asmjit.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-asmjit : 3 | import core 4 | import stz/asmjit 5 | 6 | defn gen-const-func (a:Assembler, value:Long) -> Label : 7 | val lab = new-label(a) 8 | bind(a, lab) 9 | mov(a, eax, value) 10 | ret(a) 11 | lab 12 | 13 | deftest gen-asmjit-function-and-call : 14 | val rt = jit-runtime-new() 15 | val code = code-holder-new(rt) 16 | val a = assembler-new(code) 17 | val fl = gen-const-func(a, 67L) 18 | val f = add(rt, code) 19 | val res = call(f) 20 | println("RES = %_" % [res]) 21 | #ASSERT(res == 67L) 22 | 23 | -------------------------------------------------------------------------------- /tests/test-bitset-intrinsics.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-bitset-intrinsics : 3 | import core 4 | import collections 5 | 6 | lostanza var BITSET: long 7 | lostanza defn test-test-bit () -> ref : 8 | val bitset-base = addr(BITSET) 9 | for (BITSET = 1L, BITSET != 0L, BITSET = BITSET << 1L) : 10 | for (var i:long = 0L, i < 64L, i = i + 1L) : 11 | val mark = (BITSET >> i) & 1L 12 | val bit = call-prim test-bit(i, bitset-base) 13 | if mark != bit : 14 | call-c clib/printf("Mismatch at bit index: %ld (mark = %p, bit = %p)\n", i, mark bit) 15 | fatal("Incorrect test-bit behaviour.") 16 | return false 17 | 18 | deftest test-test-bit : 19 | test-test-bit() 20 | 21 | lostanza defn test-other-bit-operations () -> ref : 22 | val base:ptr = call-c clib/malloc(sizeof(long) * 10) 23 | base[2] = 0 24 | 25 | val bit0 = call-prim test-and-set-bit(135L, base) 26 | if bit0 != 0 : fatal("bit0 is incorrect. Expected to be 0.") 27 | 28 | val bit1 = call-prim test-and-set-bit(135L, base) 29 | if bit1 != 1 : fatal("bit0 is incorrect. Expected to be 1.") 30 | 31 | if base[2] != 128 : fatal("base[2] is incorrect. Expected to be 128.") 32 | 33 | val bit2 = call-prim test-and-clear-bit(135L, base) 34 | if bit2 != 1 : fatal("bit2 is incorrect. Expected to be 1.") 35 | 36 | val bit3 = call-prim test-and-clear-bit(135L, base) 37 | if bit3 != 0 : fatal("bit3 is incorrect. Expected to be 0.") 38 | 39 | call-prim set-bit(135L, base) 40 | if base[2] != 128 : fatal("base[2] is incorrect. Expected to be 128.") 41 | 42 | call-prim clear-bit(135L, base) 43 | if base[2] != 0 : fatal("base[2] is incorrect. Expected to be 128.") 44 | 45 | call-c clib/free(base) 46 | return false 47 | 48 | deftest test-other-bit-operations : 49 | test-other-bit-operations() -------------------------------------------------------------------------------- /tests/test-constants.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-constants : 3 | import core 4 | import collections 5 | 6 | lostanza defn make-long () -> ref : 7 | val m = 0xFFFFFFFFFFFFL 8 | return new Long{m} 9 | 10 | deftest test-long-literal : 11 | #ASSERT(to-string(make-long()) == "281474976710655") 12 | -------------------------------------------------------------------------------- /tests/test-core.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-core : 3 | import core 4 | import collections 5 | 6 | deftest similar-arrays : 7 | val xs = Array(5,0) 8 | val ys = Array(5,0) 9 | #ASSERT(same-contents?(xs,ys)) -------------------------------------------------------------------------------- /tests/test-heap.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-heap : 3 | import core 4 | import collections 5 | 6 | lostanza deftype MyArray : 7 | length: long 8 | var chars: byte ... 9 | 10 | lostanza defn MyArray (n:ref) -> ref : 11 | return new MyArray{n.value} 12 | 13 | lostanza defn length (a:ref) -> ref : 14 | return new Int{a.length as int} 15 | 16 | deftest allocate-large-object : 17 | val a = MyArray(2048576) 18 | #ASSERT(length(a) == 2048576) 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/test-infer.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-infer : 3 | import core 4 | import collections 5 | 6 | defn main (b:True|False) : 7 | if b : 8 | "Done" 9 | else : 10 | fatal("Fatal message") 11 | defn myfunction () : 12 | println(b) 13 | myfunction() 14 | 15 | deftest test-infer-with-unreachable-nested-function : 16 | #ASSERT(main(true) == "Done") 17 | 18 | -------------------------------------------------------------------------------- /tests/test-inline-targ.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-inline-targ : 3 | import core 4 | import collections 5 | 6 | defn myfunction (x:Int) : 7 | x as Int&T 8 | 9 | defn main () : 10 | myfunction(32) 11 | 12 | deftest test-inline-targ : 13 | #ASSERT(main() == 32) 14 | -------------------------------------------------------------------------------- /tests/test-linker.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz-test-suite/test-linker : 3 | import core 4 | import collections 5 | import stz-test-suite/build-dev-tools 6 | import stz-test-suite/test-tools 7 | 8 | deftest build-dev-linker : 9 | build-dev-tool("dev-linker") 10 | 11 | deftest link-ex1-proj : 12 | val output = call-dev-tool $ [ 13 | "dev-linker" 14 | "-packages" "core/threaded-reader" "core/sha256" 15 | "-proj" data-file("ex1.proj")] 16 | println(output) -------------------------------------------------------------------------------- /tests/test-lostanza.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-lostanza : 3 | import core 4 | import collections 5 | 6 | lostanza defn test (a:ptr, i:long) -> ptr : 7 | return addr(a[i]) 8 | -------------------------------------------------------------------------------- /tests/test-macro-plugins.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz-test-suite/test-macro-plugins : 3 | import core 4 | import collections 5 | import stz-test-suite/build-dev-tools 6 | import stz-test-suite/test-tools 7 | 8 | deftest build-macros : 9 | call-stanza $ ["build" "macro-a"] 10 | call-stanza $ ["build" "macro-b"] 11 | call-stanza $ ["build" "macro-c"] 12 | call-stanza $ ["build" "macro-ab"] 13 | 14 | deftest run-macros : 15 | call-stanza $ ["run-test" "stz-test-suite/macros/test-macros"] 16 | 17 | deftest run-macros-2 : 18 | call-stanza $ ["run-test" "stz-test-suite/macros/test-macros2"] -------------------------------------------------------------------------------- /tests/test-match-syntax.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-match-syntax : 3 | import core 4 | import collections 5 | 6 | defsyntax test-match-syntax : 7 | public defproduction item: String 8 | defrule item = (item-a) : "Item Category A" 9 | defrule item = (item-b) : "Item Category B" 10 | 11 | defsyntax imported-test-match-syntax : 12 | public import item from test-match-syntax 13 | 14 | deftest test-match-syntax : 15 | val form = `(start-items : 16 | item-a 17 | item-a 18 | item-b 19 | end-items : 20 | item-b 21 | item-b) 22 | match-syntax[imported-test-match-syntax](form) : 23 | (start-items : (?xs:#item ...) 24 | end-items : (?ys:#item ...)) : 25 | #ASSERT(xs == `("Item Category A" "Item Category A" "Item Category B")) 26 | #ASSERT(ys == `("Item Category B" "Item Category B")) 27 | (_ ...) : 28 | ;Test failure 29 | #ASSERT(false) 30 | 31 | deftest test-parse-syntax : 32 | val form = `(item-a item-a item-b) 33 | val parsed = parse-syntax[imported-test-match-syntax / #item ...](form) 34 | println(parsed) -------------------------------------------------------------------------------- /tests/test-meta-utils.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-meta-utils : 3 | import core 4 | import collections 5 | import core/meta-utils 6 | 7 | defstruct MyStruct <: Equalable & Hashable : 8 | a:Int 9 | b:String 10 | with: 11 | printer => true 12 | equalable => true 13 | hashable => true 14 | meta-utils => true 15 | 16 | defstruct MyStruct2 : 17 | b:String 18 | with: 19 | printer => true 20 | meta-utils => true 21 | 22 | deftest meta-utils-equalable : 23 | val x = MyStruct(3, "Hello") 24 | val y = MyStruct(3, "Hello") 25 | #ASSERT(x == y) 26 | 27 | deftest meta-utils-hashable : 28 | val x = MyStruct(3, "Hello") 29 | println("hash(x) = %_" % [hash(x)]) 30 | 31 | deftest meta-utils-field-values : 32 | val x = MyStruct(3, "Hello") 33 | #ASSERT(field-values(x) == [3, "Hello"]) 34 | 35 | deftest meta-utils-field-names : 36 | val x = MyStruct(3, "Hello") 37 | #ASSERT(field-names(x) == [`a, `b]) 38 | 39 | deftest meta-utils-field-entries : 40 | val x = MyStruct(3, "Hello") 41 | #ASSERT(field-entries(x) == [`a => 3, `b => "Hello"]) 42 | 43 | deftest meta-utils-field-entries-2 : 44 | val x = MyStruct2("World") 45 | #ASSERT(field-entries(x) == [`b => "World"]) 46 | 47 | deftest meta-utils-field-accessors : 48 | val x = MyStruct(3, "Hello") 49 | val accessors = field-accessors(x) 50 | val values = [3, "Hello"] 51 | for (access in accessors, v in values) do : 52 | #ASSERT(access(x) == v) 53 | 54 | 55 | -------------------------------------------------------------------------------- /tests/test-multis.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-multis : 3 | import core 4 | import collections 5 | import stz/test-utils 6 | 7 | deftype A 8 | deftype B <: A 9 | deftype C <: A 10 | deftype D <: B&C 11 | 12 | defn A () : new A 13 | defn B () : new B 14 | defn C () : new C 15 | defn D () : new D 16 | 17 | defmulti f (x:A, y:A) -> False 18 | 19 | defmethod f (a:A, b:A) : println("f A A") 20 | defmethod f (a:A, b:C) : println("f A C") 21 | defmethod f (a:C, b:A) : println("f C A") 22 | defmethod f (a:D, b:D) : println("f D D") 23 | 24 | defn A2 () : 25 | new A : 26 | defmethod f (this, b:B) : 27 | println("f A2 B") 28 | defmethod f (this, b:C) : 29 | println("f A2 C") 30 | 31 | val MULTI-PRINTOUT = \ 32 | f A A 33 | f A C 34 | f C A 35 | f D D 36 | f C A 37 | f A C 38 | f A A 39 | f A2 B 40 | f A2 C 41 | Execution Halted 42 | 43 | 44 | deftest multi-instance-method : 45 | within assert-printout(MULTI-PRINTOUT) : 46 | within execute-with-safe-halt() : f(A(), A()) 47 | within execute-with-safe-halt() : f(A(), C()) 48 | within execute-with-safe-halt() : f(C(), A()) 49 | within execute-with-safe-halt() : f(D(), D()) 50 | within execute-with-safe-halt() : f(D(), A()) 51 | within execute-with-safe-halt() : f(A(), D()) 52 | within execute-with-safe-halt() : f(A2(), A()) 53 | within execute-with-safe-halt() : f(A2(), B()) 54 | within execute-with-safe-halt() : f(A2(), C()) 55 | within execute-with-safe-halt() : f(A2(), D()) 56 | -------------------------------------------------------------------------------- /tests/test-nan.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-nan : 3 | import core 4 | import collections 5 | import stz/test-utils 6 | 7 | ;Check that the nan? predicate works. 8 | deftest nan-detection : 9 | val x = 1.0f 10 | val y = 0.0f / 0.0f 11 | #ASSERT(not nan?(x)) 12 | #ASSERT(nan?(y)) 13 | 14 | ;Check both Nan and Non-Nan cases. 15 | ;Make sure that the operators return the right results: 16 | ; <, <=, >, >=, ==, != 17 | deftest nan-operators : 18 | val one = 1.0f 19 | val two = 2.0f 20 | val nan = 0.0f / 0.0f 21 | 22 | ;Operator: < 23 | #ASSERT(one < two) 24 | #ASSERT(not two < one) 25 | #ASSERT(not one < nan) 26 | 27 | ;Operator: <= 28 | #ASSERT(one <= two) 29 | #ASSERT(not two <= one) 30 | #ASSERT(not one <= nan) 31 | 32 | ;Operator: > 33 | #ASSERT(not one > two) 34 | #ASSERT(two > one) 35 | #ASSERT(not one > nan) 36 | 37 | ;Operator: >= 38 | #ASSERT(not one >= two) 39 | #ASSERT(two >= one) 40 | #ASSERT(not one >= nan) 41 | 42 | ;Operator: == 43 | #ASSERT(one == one) 44 | #ASSERT(not one == two) 45 | #ASSERT(not one == nan) 46 | #ASSERT(not nan == nan) 47 | 48 | ;Operator: != 49 | #ASSERT(not one != one) 50 | #ASSERT(one != two) 51 | #ASSERT(one != nan) 52 | #ASSERT(nan != nan) -------------------------------------------------------------------------------- /tests/test-package-manager.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz-test-suite/test-package-manager : 3 | import core 4 | import collections 5 | import stz-test-suite/build-dev-tools 6 | import stz-test-suite/test-tools 7 | 8 | deftest build-dev-package-manager : 9 | build-dev-tool("dev-package-manager") 10 | 11 | deftest test-package-manager : 12 | val output = call-dev-tool $ [ 13 | "dev-package-manager"] 14 | println(output) -------------------------------------------------------------------------------- /tests/test-process-api.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-process-api : 3 | import core 4 | 5 | ; Poll a process until it exits, failing the test if the process 6 | ; takes longer than the timeout argumnet 7 | defn check-exits-within-timeout (timeout:Long, process:Process) : 8 | val timer = MillisecondTimer("time-process") 9 | start(timer) 10 | let loop () : 11 | #ASSERT(time(timer) < timeout) 12 | sleep-us(10L) 13 | loop() when state(process) is ProcessRunning 14 | 15 | ; This test verifies polling a short-running process works as expected 16 | deftest test-short-process : 17 | val process = Process("sleep", ["sleep", "0.01"]) 18 | check-exits-within-timeout(100L, process) 19 | 20 | ; This test verifies polling a longer-running process works as expected 21 | deftest test-long-process : 22 | val process = Process("sleep", ["sleep", "1s"]) 23 | check-exits-within-timeout(2000L, process) 24 | 25 | ; This test verifies that polling a process after it has exited works 26 | ; as expected. 27 | deftest test-short-process-exit-before-poll : 28 | val process = Process("sleep", ["sleep", "0.01"]) 29 | ; Sleep for five seconds, then poll the process. 30 | for n in 0 to 10 do : 31 | sleep-us(500L * 1000L) 32 | check-exits-within-timeout(20L, process) 33 | -------------------------------------------------------------------------------- /tests/test-proj.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz-test-suite/test-proj : 3 | import core 4 | import collections 5 | import stz-test-suite/build-dev-tools 6 | import stz-test-suite/test-tools 7 | 8 | deftest build-dev-proj : 9 | build-dev-tool("dev-proj") 10 | 11 | defn test-read-proj (filename:String) : 12 | val test-name = to-string("read-proj(%_)" % [filename]) 13 | deftest (test-name) : 14 | val output = call-dev-tool $ ["dev-proj" data-file(filename) "-package-managers" "conan"] 15 | println(output) 16 | 17 | test-read-proj("ex1.proj") 18 | test-read-proj("ex2.proj") 19 | test-read-proj("ex3.proj") 20 | test-read-proj("ex4.proj") 21 | test-read-proj("ex5.proj") 22 | 23 | deftest multiple-proj-files : 24 | val output = call-dev-tool $ ["dev-proj" 25 | data-file("ex6.proj") data-file("ex7.proj") 26 | "-package-managers" "conan"] 27 | println(output) 28 | 29 | -------------------------------------------------------------------------------- /tests/test-tools.stanza: -------------------------------------------------------------------------------- 1 | defpackage stz-test-suite/test-tools : 2 | import core 3 | import collections 4 | 5 | ;Helper: Retrieve the stanza executable. 6 | public defn stanza-executable () -> String : 7 | match(get-env("STANZA")) : 8 | (file:String) : file 9 | (f:False) : "stanza" 10 | 11 | ;Call Stanza, and throw an exception on failure. 12 | public defn call-stanza (args:Tuple) -> False : 13 | val new-args = to-tuple $ cat-all $ [[stanza-executable()], args] 14 | val ret = call-system(stanza-executable(), new-args) 15 | throw(Exception("Call to Stanza failed.")) when ret != 0 16 | 17 | ;Ensure that a directory exists, and create one if it doesn't. 18 | public defn ensure-directory (name:String) -> False : 19 | if file-exists?(name) : 20 | if file-type(name) is-not DirectoryType : 21 | throw(Exception("File %~ exists and is not a directory." % [name])) 22 | else : 23 | create-dir(name) 24 | 25 | ;Return a file in the build directory. 26 | public defn build-file (name:String) -> String : 27 | ensure-directory("build") 28 | to-string("build/%_" % [name]) 29 | 30 | ;Return a file in the data directory. 31 | public defn data-file (name:String) -> String : 32 | ensure-directory("data") 33 | to-string("data/%_" % [name]) 34 | 35 | ;Return a file in the output directory. 36 | public defn output-file (name:String) -> String : 37 | ensure-directory("output") 38 | to-string("output/%_" % [name]) -------------------------------------------------------------------------------- /tests/test-utils.stanza: -------------------------------------------------------------------------------- 1 | #use-added-syntax(tests) 2 | defpackage stz/test-utils : 3 | import core 4 | import collections 5 | 6 | public defn cmd (s:String) : 7 | val args = to-tuple(tokenize-shell-command(s)) 8 | call-system(args[0], args) 9 | 10 | public defn cmdr (s:String) -> String : 11 | val args = to-tuple(tokenize-shell-command(s)) 12 | call-system-and-get-output(args[0], args) 13 | 14 | public defn assert-cmd-returns (s:String, ret:String) : 15 | val result = cmdr(s) 16 | println(result) 17 | #ASSERT(trim(result) == trim(ret)) 18 | 19 | defstruct EchoStream <: OutputStream : 20 | buffer:StringBuffer with: (init => StringBuffer()) 21 | 22 | defmethod print (s:EchoStream, c:Char) : 23 | print(buffer(s), c) 24 | print(STANDARD-OUTPUT-STREAM, c) 25 | 26 | public defn get-printout (body:() -> ?) -> String : 27 | val stream = EchoStream() 28 | with-output-stream(stream, body) 29 | to-string(buffer(stream)) 30 | 31 | public defn assert-printout (body:() -> ?, result:String) : 32 | #ASSERT(trim(get-printout(body)) == trim(result)) 33 | 34 | public defn execute-with-safe-halt (body:() -> ?) : 35 | execute-with-error-handler(body, println{"Execution Halted"}) 36 | 37 | public defn lines-equal? (a:String, b:String) : 38 | defn lines (s:String) -> Tuple : 39 | to-tuple $ for line in split(s, "\n") seq? : 40 | val trimmed = trim(line) 41 | if empty?(trimmed) : None() 42 | else : One(trimmed) 43 | lines(a) == lines(b) 44 | 45 | --------------------------------------------------------------------------------