├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── Makefile.msc ├── README.md ├── doc ├── cstdlib.md ├── extension.md ├── extensions │ ├── bigint.md │ ├── binary.md │ ├── queue.md │ ├── regex.md │ ├── sqlite3.md │ ├── stack.md │ ├── string.md │ ├── vector.md │ └── zip.md ├── images │ ├── fib.png │ ├── switch-case1.png │ ├── switch-case2.png │ └── switch-case3.png ├── licenses │ ├── LICENSE.bigint │ ├── LICENSE.lacc │ ├── LICENSE.miniz │ ├── LICENSE.onig │ ├── LICENSE.sqlite3 │ └── LICENSE.tinyaes └── technical.md ├── include ├── kcs.h ├── kcs │ ├── assert.h │ ├── dll.h │ └── dllcore.h ├── lacc │ ├── array.h │ ├── context.h │ ├── deque.h │ ├── hash.h │ ├── ir.h │ ├── string.h │ ├── symbol.h │ ├── token.h │ └── type.h ├── stdlib │ ├── alloca.h │ ├── float.h │ ├── stdalign.h │ ├── stdarg.h │ ├── stdbool.h │ └── stddef.h ├── wait.h └── xunistd.h ├── kcsrt ├── include │ ├── _builtin.h │ ├── _ext.h │ ├── assert.h │ ├── ctype.h │ ├── float.h │ ├── kcs │ │ ├── bigint.h │ │ ├── ext.h │ │ ├── json.h │ │ ├── khash.h │ │ ├── klist.h │ │ ├── kvec.h │ │ ├── regex.h │ │ ├── sqlite3.h │ │ └── zip.h │ ├── limits.h │ ├── math.h │ ├── setjmp.h │ ├── stdalign.h │ ├── stdarg.h │ ├── stdbool.h │ ├── stddef.h │ ├── stdint.h │ ├── stdio.h │ ├── stdlib.h │ ├── stdnoreturn.h │ ├── string.h │ └── time.h └── libsrc │ ├── _builtin.c │ ├── assert.c │ ├── ctype.c │ ├── kcs │ ├── bigint.c │ ├── ext.c │ ├── ext_aes.c │ ├── ext_binary.c │ ├── ext_regex.c │ ├── ext_sqlite3.c │ ├── ext_string.c │ ├── ext_timer.c │ ├── ext_vector.c │ ├── ext_zip.c │ └── json.y │ ├── stdio.c │ ├── stdlib.c │ ├── string.c │ └── time.c ├── make.cmd ├── samples ├── aes.c ├── algo-c │ ├── endian.c │ ├── knight.c │ ├── life.c │ ├── magic4.c │ ├── maze.c │ ├── multprec.c │ └── nqueen.c ├── bigint.c ├── fib.c ├── fib.dot ├── hash.c ├── json.c ├── list.c ├── qsort.c ├── queue.c ├── redecl.c ├── regex.c ├── sample.json ├── setjmp.c ├── sqlite3.c ├── stack.c ├── string.c ├── switch-case.c ├── vec.c ├── vector.c └── zip.c ├── src ├── _extdll │ ├── ext.c │ ├── ext │ │ ├── aesx.c │ │ ├── fileio.c │ │ ├── regex.c │ │ ├── sqlite3x.c │ │ ├── timer.c │ │ └── zip_unzip.c │ └── lib │ │ ├── aes │ │ ├── aes.c │ │ └── aes.h │ │ ├── fileio.h │ │ ├── fileio │ │ ├── _fileio.c │ │ ├── fclose.c │ │ ├── feof.c │ │ ├── fflush.c │ │ ├── fgetc.c │ │ ├── fgetpos.c │ │ ├── fgets.c │ │ ├── fopen.c │ │ ├── fprintf.c │ │ ├── fputc.c │ │ ├── fputs.c │ │ ├── fread.c │ │ ├── fseek.c │ │ ├── fsetpos.c │ │ ├── ftell.c │ │ ├── fwrite.c │ │ ├── rewind.c │ │ ├── ungetc.c │ │ ├── vfprintf.c │ │ └── vprintf.c │ │ ├── onig │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── AUTHORS │ │ ├── CMakeLists.txt │ │ ├── COPYING │ │ ├── ChangeLog │ │ ├── HISTORY │ │ ├── INSTALL │ │ ├── Makefile.am │ │ ├── NEWS │ │ ├── README │ │ ├── README.md │ │ ├── README_japanese │ │ ├── autogen.sh │ │ ├── cmake │ │ │ └── Config.cmake.in │ │ ├── compile │ │ ├── config.guess │ │ ├── config.sub │ │ ├── configure.ac │ │ ├── depcomp │ │ ├── doc │ │ │ ├── API │ │ │ ├── API.ja │ │ │ ├── CALLOUTS.API │ │ │ ├── CALLOUTS.API.ja │ │ │ ├── CALLOUTS.BUILTIN │ │ │ ├── CALLOUTS.BUILTIN.ja │ │ │ ├── FAQ │ │ │ ├── FAQ.ja │ │ │ ├── RE │ │ │ ├── RE.ja │ │ │ ├── SYNTAX.md │ │ │ └── UNICODE_PROPERTIES │ │ ├── harnesses │ │ │ ├── ascii_compatible.dict │ │ │ ├── deluxe-encode-harness.c │ │ │ ├── dict_conv.py │ │ │ ├── encode-harness.c │ │ │ ├── libfuzzer-onig.cpp │ │ │ ├── regset-harness.c │ │ │ └── syntax-harness.c │ │ ├── index.html │ │ ├── index_ja.html │ │ ├── install-sh │ │ ├── m4 │ │ │ └── .whatever │ │ ├── make_win.bat │ │ ├── make_win32.bat │ │ ├── make_win64.bat │ │ ├── missing │ │ ├── onig-config.in │ │ ├── oniguruma.pc.cmake.in │ │ ├── oniguruma.pc.in │ │ ├── sample │ │ │ ├── CMakeLists.txt │ │ │ ├── Makefile.am │ │ │ ├── bug_fix.c │ │ │ ├── callout.c │ │ │ ├── count.c │ │ │ ├── crnl.c │ │ │ ├── echo.c │ │ │ ├── encode.c │ │ │ ├── listcap.c │ │ │ ├── names.c │ │ │ ├── posix.c │ │ │ ├── regset.c │ │ │ ├── scan.c │ │ │ ├── simple.c │ │ │ ├── sql.c │ │ │ ├── syntax.c │ │ │ └── user_property.c │ │ ├── src │ │ │ ├── Makefile.am │ │ │ ├── Makefile.windows │ │ │ ├── ascii.c │ │ │ ├── big5.c │ │ │ ├── config.h.cmake.in │ │ │ ├── config.h.win32 │ │ │ ├── config.h.win64 │ │ │ ├── config.h.windows.in │ │ │ ├── cp1251.c │ │ │ ├── euc_jp.c │ │ │ ├── euc_jp_prop.c │ │ │ ├── euc_jp_prop.gperf │ │ │ ├── euc_kr.c │ │ │ ├── euc_tw.c │ │ │ ├── gb18030.c │ │ │ ├── gperf_fold_key_conv.py │ │ │ ├── gperf_unfold_key_conv.py │ │ │ ├── iso8859_1.c │ │ │ ├── iso8859_10.c │ │ │ ├── iso8859_11.c │ │ │ ├── iso8859_13.c │ │ │ ├── iso8859_14.c │ │ │ ├── iso8859_15.c │ │ │ ├── iso8859_16.c │ │ │ ├── iso8859_2.c │ │ │ ├── iso8859_3.c │ │ │ ├── iso8859_4.c │ │ │ ├── iso8859_5.c │ │ │ ├── iso8859_6.c │ │ │ ├── iso8859_7.c │ │ │ ├── iso8859_8.c │ │ │ ├── iso8859_9.c │ │ │ ├── koi8.c │ │ │ ├── koi8_r.c │ │ │ ├── make_property.sh │ │ │ ├── make_unicode_egcb.sh │ │ │ ├── make_unicode_egcb_data.py │ │ │ ├── make_unicode_fold.sh │ │ │ ├── make_unicode_fold_data.py │ │ │ ├── make_unicode_property.sh │ │ │ ├── make_unicode_property_data.py │ │ │ ├── make_unicode_wb.sh │ │ │ ├── make_unicode_wb_data.py │ │ │ ├── mktable.c │ │ │ ├── onig_init.c │ │ │ ├── oniggnu.h │ │ │ ├── onigposix.h │ │ │ ├── oniguruma.h │ │ │ ├── regcomp.c │ │ │ ├── regenc.c │ │ │ ├── regenc.h │ │ │ ├── regerror.c │ │ │ ├── regexec.c │ │ │ ├── regext.c │ │ │ ├── reggnu.c │ │ │ ├── regint.h │ │ │ ├── regparse.c │ │ │ ├── regparse.h │ │ │ ├── regposerr.c │ │ │ ├── regposix.c │ │ │ ├── regsyntax.c │ │ │ ├── regtrav.c │ │ │ ├── regversion.c │ │ │ ├── sjis.c │ │ │ ├── sjis_prop.c │ │ │ ├── sjis_prop.gperf │ │ │ ├── st.c │ │ │ ├── st.h │ │ │ ├── unicode.c │ │ │ ├── unicode_egcb_data.c │ │ │ ├── unicode_fold1_key.c │ │ │ ├── unicode_fold2_key.c │ │ │ ├── unicode_fold3_key.c │ │ │ ├── unicode_fold_data.c │ │ │ ├── unicode_property_data.c │ │ │ ├── unicode_property_data_posix.c │ │ │ ├── unicode_unfold_key.c │ │ │ ├── unicode_wb_data.c │ │ │ ├── utf16_be.c │ │ │ ├── utf16_le.c │ │ │ ├── utf32_be.c │ │ │ ├── utf32_le.c │ │ │ └── utf8.c │ │ ├── test-driver │ │ ├── test │ │ │ ├── Makefile.am │ │ │ ├── test_regset.c │ │ │ ├── test_utf8.c │ │ │ ├── testc.c │ │ │ └── testu.c │ │ └── windows │ │ │ └── testc.c │ │ ├── sqlite3 │ │ ├── shell.c │ │ ├── sqlite3.c │ │ ├── sqlite3.h │ │ └── sqlite3ext.h │ │ ├── version.md │ │ └── zip │ │ ├── miniz.c │ │ └── miniz.h ├── backend │ ├── compile.c │ ├── compile.h │ ├── graphviz │ │ ├── dot.c │ │ └── dot.h │ ├── linker.c │ ├── linker.h │ ├── vm │ │ ├── builtin │ │ │ ├── vmacpconv.c │ │ │ ├── vmacpconv.h │ │ │ └── vmbuiltin.c │ │ ├── vm.h │ │ ├── vmdump.c │ │ ├── vmimplir.c │ │ ├── vminstr.c │ │ ├── vminstr.h │ │ ├── vmrunlir.c │ │ └── vmsevelir.c │ └── x86_64 │ │ ├── abi.c │ │ ├── abi.h │ │ ├── assemble.c │ │ ├── assemble.h │ │ ├── builtin │ │ └── jitbuiltin.c │ │ ├── dwarf.c │ │ ├── dwarf.h │ │ ├── elf.c │ │ ├── elf.h │ │ ├── instr.c │ │ ├── instr.h │ │ ├── jit.c │ │ ├── jit.h │ │ ├── jit_util.c │ │ └── jit_util.h ├── context.c ├── kcs.c ├── kcsmain.c ├── kcsutil.c ├── optimizer │ ├── liveness.c │ ├── liveness.h │ ├── optimize.c │ ├── optimize.h │ ├── transform.c │ └── transform.h ├── parser │ ├── declaration.c │ ├── declaration.h │ ├── eval.c │ ├── eval.h │ ├── expression.c │ ├── expression.h │ ├── initializer.c │ ├── initializer.h │ ├── parse.c │ ├── parse.h │ ├── statement.c │ ├── statement.h │ ├── symtab.c │ ├── symtab.h │ ├── typetree.c │ └── typetree.h ├── preprocessor │ ├── directive.c │ ├── directive.h │ ├── input.c │ ├── input.h │ ├── macro.c │ ├── macro.h │ ├── preprocess.c │ ├── preprocess.h │ ├── strtab.c │ ├── strtab.h │ ├── tokenize.c │ └── tokenize.h └── util │ ├── argparse.c │ ├── argparse.h │ ├── fmemopen.c │ ├── hash.c │ └── string.c ├── test ├── test-8cc │ ├── LICENSE.txt │ ├── _testmain.c │ ├── align.c │ ├── arith.c │ ├── array.c │ ├── assign.c │ ├── bitop.c │ ├── cast.c │ ├── comp.c │ ├── constexpr.c │ ├── control.c │ ├── conversion.c │ ├── decl.c │ ├── enum.c │ ├── extern.c │ ├── float.c │ ├── float.l.c │ ├── funcargs.c │ ├── function.c │ ├── generic.c │ ├── global.c │ ├── import.c │ ├── import.h │ ├── includeguard.c │ ├── includeguard1.h │ ├── includeguard2.h │ ├── includeguard3.h │ ├── includeguard4.h │ ├── includeguard5.h │ ├── includeguard6.h │ ├── includeguard7.h │ ├── initializer.c │ ├── int.c │ ├── iso646.c │ ├── lex.c │ ├── line.c │ ├── literal.c │ ├── macro.c │ ├── macro1.h │ ├── macro2.h │ ├── noreturn.c │ ├── number.c │ ├── oldstyle.c │ ├── once.h │ ├── pointer.c │ ├── scope.c │ ├── sizeof.c │ ├── staticassert.c │ ├── stmtexpr.c │ ├── struct.c │ ├── test.cmd │ ├── test.h │ ├── test.sh │ ├── type.c │ ├── typeof.c │ ├── union.c │ ├── usualconv.c │ └── varargs.c ├── test-lacc │ ├── abstract-declaration.c │ ├── address-deref-offset.c │ ├── anonymous-members.c │ ├── anonymous-struct.c │ ├── array-decay.c │ ├── array-nested-init.c │ ├── array-param.c │ ├── array-registers.c │ ├── array-reverse-index.c │ ├── array-zero-length.c │ ├── array.c │ ├── assign-deref-float.c │ ├── assignment-type.c │ ├── bitfield-basic.c │ ├── bitfield-extend.c │ ├── bitfield-immediate-assign.c │ ├── bitfield-initialize-zero.c │ ├── bitfield-load.c │ ├── bitfield-mask.c │ ├── bitfield-packing.c │ ├── bitfield-reset-align.c │ ├── bitfield-trailing-zero.c │ ├── bitfield-types-init.c │ ├── bitfield-types.c │ ├── bitfield-unsigned-promote.c │ ├── bitfield.c │ ├── bitwise-complement.c │ ├── bitwise-constant.c │ ├── bitwise-expression.c │ ├── bitwise-sign-extend.c │ ├── byte-load.c │ ├── c11 │ │ ├── alignof.c │ │ └── static-assert.c │ ├── c99 │ │ ├── _Pragma.c │ │ ├── __func__.c │ │ ├── array-param-qualifier.c │ │ ├── array-qualifier-static.c │ │ ├── bool.c │ │ ├── compund-literal.c │ │ ├── designator-array.c │ │ ├── designator-struct.c │ │ ├── designator-union.c │ │ ├── flexible-array-arg.c │ │ ├── flexible-array.c │ │ ├── flexible-union.c │ │ ├── for-declaration.c │ │ ├── initialize-compound.c │ │ ├── initialize-object.c │ │ ├── inline-address.c │ │ ├── inline-declare.c │ │ ├── line-comment.c │ │ ├── restrict.c │ │ ├── va_copy.c │ │ ├── variadic-macro.c │ │ ├── vla-arg.c │ │ ├── vla-block-declaration.c │ │ ├── vla-compatibility.c │ │ ├── vla-matrix.c │ │ ├── vla-old-param.c │ │ ├── vla-pointer.c │ │ ├── vla-sizeof.c │ │ ├── vla-static-pointer.c │ │ ├── vla-ternary-length.c │ │ └── vla.c │ ├── cast-float-union.c │ ├── cast-float.c │ ├── cast-function-args.c │ ├── cast-immediate-truncate.c │ ├── cast.c │ ├── comma-side-effects.c │ ├── comment.c │ ├── compare.c │ ├── compound-assignment-basic.c │ ├── conditional-basic.c │ ├── conditional-constant.c │ ├── conditional-void.c │ ├── conditional.c │ ├── constant-address-index.c │ ├── constant-expression.c │ ├── constant-integer-type.c │ ├── convert-assign-immediate.c │ ├── convert-float-double.c │ ├── convert-float-int.c │ ├── convert-float-unsigned.c │ ├── convert-int-float.c │ ├── convert-unsigned-float.c │ ├── copy-struct.c │ ├── declaration-default-int.c │ ├── declarator-complex.c │ ├── declarator-parens.c │ ├── declare-auto-func.c │ ├── deref-address-offset.c │ ├── deref-array.c │ ├── deref-compare-float.c │ ├── deref-deep.c │ ├── deref-store.c │ ├── deref.c │ ├── dereference-extern.c │ ├── directive-number.c │ ├── do-continue.c │ ├── do-while.c │ ├── duffs-device.c │ ├── enum.c │ ├── exit.c │ ├── expression-div-mod.c │ ├── expression.c │ ├── fact.c │ ├── float-arithmetic.c │ ├── float-branch.c │ ├── float-compare-equal.c │ ├── float-compare-nan.c │ ├── float-compare.c │ ├── float-function.c │ ├── float-load-deref.c │ ├── for-empty-expr.c │ ├── for.c │ ├── function-char-args.c │ ├── function-implicit-declare.c │ ├── function-incomplete.c │ ├── function-pointer-call.c │ ├── function-pointer.c │ ├── function.c │ ├── gnu │ │ ├── alloca.c │ │ ├── assign-constant-float.c │ │ ├── cast-float-overflow.c │ │ ├── large-objects.c │ │ └── long-double-convert.c │ ├── goto.c │ ├── header.h │ ├── hello.c │ ├── identifier.c │ ├── immediate-branch.c │ ├── immediate-expr.c │ ├── immediate-pointer.c │ ├── include.c │ ├── increment.c │ ├── initialize-address.c │ ├── initialize-array.c │ ├── initialize-float.c │ ├── initialize-id.c │ ├── initialize-null.c │ ├── initialize-string.c │ ├── initialize-union.c │ ├── initialize.c │ ├── integer-suffix.c │ ├── ldouble-load-direct.c │ ├── line-continuation.c │ ├── line-directive.c │ ├── linebreak.c │ ├── liveness-deref-assign.c │ ├── liveness-global.c │ ├── liveness-loop.c │ ├── liveness-pointer.c │ ├── logical-and-bitwise-false.c │ ├── logical-operators-basic.c │ ├── long-double-arithmetic.c │ ├── long-double-compare.c │ ├── long-double-function.c │ ├── long-double-load.c │ ├── long-double-struct.c │ ├── long-double-union.c │ ├── macro-empty-arg.c │ ├── macro-function-paren.c │ ├── macro-keyword-define.c │ ├── macro-name-arg.c │ ├── macro-param-space.c │ ├── macro-paste.c │ ├── macro-predefined.c │ ├── macro-recursive.c │ ├── macro-refill-expand.c │ ├── macro-repeat-expand.c │ ├── macro-skip-expand.c │ ├── macro.c │ ├── main.c │ ├── negate.c │ ├── nested-macro.c │ ├── offsetof.c │ ├── old-param-decay.c │ ├── old-style-declaration.c │ ├── old-style-definition.c │ ├── padded-initialization.c │ ├── params-mixed.c │ ├── params-system-v.c │ ├── partial-initialization.c │ ├── pointer-diff.c │ ├── pointer-immediate.c │ ├── pointer.c │ ├── preprocess-expression.c │ ├── preprocess.c │ ├── preprocessor-expression.c │ ├── printstr.c │ ├── promote-unsigned.c │ ├── prototype-scope-enum.c │ ├── ptrdiff.c │ ├── push-immediate.c │ ├── qualifier-repeat.c │ ├── register-param.c │ ├── return-bitfield.c │ ├── return-compare-int.c │ ├── return-float-struct.c │ ├── return-partial-register.c │ ├── return-point.c │ ├── return-struct-basic.c │ ├── return-struct-integers.c │ ├── return-struct-mem.c │ ├── self-referential-struct.c │ ├── shift-assign.c │ ├── shift.c │ ├── short-circuit-comma.c │ ├── short-circuit.c │ ├── shortcircuit-loop.c │ ├── signed-division.c │ ├── sizeof.c │ ├── string-addr.c │ ├── string-concat.c │ ├── string-escape.c │ ├── string-index.c │ ├── string-length.c │ ├── stringify.c │ ├── strings.c │ ├── struct-alignment.c │ ├── struct-assign.c │ ├── struct-comma-call.c │ ├── struct-eightbyte-write.c │ ├── struct-init-swap.c │ ├── struct-padding.c │ ├── struct.c │ ├── switch-basic.c │ ├── switch-nested.c │ ├── tag.c │ ├── tail-compare-jump.c │ ├── test.cmd │ ├── test.sh │ ├── token.c │ ├── tokenize-partial-keyword.c │ ├── trigraph.c │ ├── typedef-function.c │ ├── typedef-initialize.c │ ├── typedef.c │ ├── unary-minus-float.c │ ├── unary-plus.c │ ├── union-bitfield.c │ ├── union-float-assign.c │ ├── union-float-param.c │ ├── union-zero-init.c │ ├── union.c │ ├── unsigned-compare-ge.c │ ├── unsigned-compare.c │ ├── unsigned-sign-extend.c │ ├── vararg-complex-1.c │ ├── vararg-complex-2.c │ ├── vararg-deref-arg.c │ ├── vararg-deref.c │ ├── vararg-float.c │ ├── vararg-param.c │ ├── vararg.c │ ├── void-statement.c │ ├── whitespace.c │ └── zero-init.c ├── test-picoc │ ├── 00_assignment.c │ ├── 00_assignment.expect │ ├── 01_comment.c │ ├── 01_comment.expect │ ├── 02_printf.c │ ├── 02_printf.expect │ ├── 03_struct.c │ ├── 03_struct.expect │ ├── 04_for.c │ ├── 04_for.expect │ ├── 05_array.c │ ├── 05_array.expect │ ├── 06_case.c │ ├── 06_case.expect │ ├── 07_function.c │ ├── 07_function.expect │ ├── 08_while.c │ ├── 08_while.expect │ ├── 09_do_while.c │ ├── 09_do_while.expect │ ├── 10_pointer.c │ ├── 10_pointer.expect │ ├── 11_precedence.c │ ├── 11_precedence.expect │ ├── 12_hashdefine.c │ ├── 12_hashdefine.expect │ ├── 13_integer_literals.c │ ├── 13_integer_literals.expect │ ├── 14_if.c │ ├── 14_if.expect │ ├── 15_recursion.c │ ├── 15_recursion.expect │ ├── 16_nesting.c │ ├── 16_nesting.expect │ ├── 17_enum.c │ ├── 17_enum.expect │ ├── 18_include.c │ ├── 18_include.expect │ ├── 18_include.h │ ├── 19_pointer_arithmetic.c │ ├── 19_pointer_arithmetic.expect │ ├── 20_pointer_comparison.c │ ├── 20_pointer_comparison.expect │ ├── 21_char_array.c │ ├── 21_char_array.expect │ ├── 22_floating_point.c │ ├── 22_floating_point.expect │ ├── 23_type_coercion.c │ ├── 23_type_coercion.expect │ ├── 24_math_library.c │ ├── 24_math_library.expect │ ├── 25_quicksort.c │ ├── 25_quicksort.expect │ ├── 26_character_constants.c │ ├── 26_character_constants.expect │ ├── 27_sizeof.c │ ├── 27_sizeof.expect │ ├── 28_strings.c │ ├── 28_strings.expect │ ├── 29_array_address.c │ ├── 29_array_address.expect │ ├── 30_hanoi.c │ ├── 30_hanoi.expect │ ├── 31_args.c │ ├── 31_args.expect │ ├── 32_led.c │ ├── 32_led.expect │ ├── 33_ternary_op.c │ ├── 33_ternary_op.expect │ ├── 34_array_assignment.c │ ├── 34_array_assignment.expect │ ├── 35_sizeof.c │ ├── 35_sizeof.expect │ ├── 36_array_initializers.c │ ├── 36_array_initializers.expect │ ├── 37_sprintf.c │ ├── 37_sprintf.expect │ ├── 38_multiple_array_index.c │ ├── 38_multiple_array_index.expect │ ├── 39_typedef.c │ ├── 39_typedef.expect │ ├── 40_stdio.c │ ├── 40_stdio.expect │ ├── 41_hashif.c │ ├── 41_hashif.expect │ ├── 42_function_pointer.c │ ├── 42_function_pointer.expect │ ├── 43_void_param.c │ ├── 43_void_param.expect │ ├── 44_scoped_declarations.c │ ├── 44_scoped_declarations.expect │ ├── 45_empty_for.c │ ├── 45_empty_for.expect │ ├── 46_grep.c │ ├── 47_switch_return.c │ ├── 47_switch_return.expect │ ├── 48_nested_break.c │ ├── 48_nested_break.expect │ ├── 49_bracket_evaluation.c │ ├── 49_bracket_evaluation.expect │ ├── 50_logical_second_arg.c │ ├── 50_logical_second_arg.expect │ ├── 51_static.c │ ├── 51_static.expect │ ├── 52_unnamed_enum.c │ ├── 52_unnamed_enum.expect │ ├── 54_goto.c │ ├── 54_goto.expect │ ├── 55_array_initializer.c │ ├── 55_array_initializer.expect │ ├── 56_cross_structure.c │ ├── 56_cross_structure.expect │ ├── 57_macro_bug.c │ ├── 57_macro_bug.expect │ ├── 58_return_outside.c │ ├── 58_return_outside.expect │ ├── 59_break_before_loop.c │ ├── 59_break_before_loop.expect │ ├── 60_local_vars.c │ ├── 60_local_vars.expect │ ├── 61_initializers.c │ ├── 61_initializers.expect │ ├── 62_float.c │ ├── 62_float.expect │ ├── 63_typedef.c │ ├── 63_typedef.expect │ ├── 64_double_prefix_op.c │ ├── 64_double_prefix_op.expect │ ├── 65_typeless.c │ ├── 65_typeless.expect │ ├── 66_printf_undefined.c │ ├── 66_printf_undefined.expect │ ├── 67_macro_crash.c │ ├── 67_macro_crash.expect │ ├── 68_return.c │ ├── 68_return.expect │ ├── 69_shebang_script.c │ ├── 69_shebang_script.expect │ ├── LICENSE.txt │ ├── basic.cmd │ ├── check.cmd │ ├── csmith.cmd │ ├── csmith.sh │ ├── csmith │ │ ├── Makefile │ │ ├── rand0.c │ │ ├── rand0.expect │ │ ├── rand1.c │ │ ├── rand1.expect │ │ ├── rand10.c │ │ ├── rand10.expect │ │ ├── rand100.c │ │ ├── rand100.expect │ │ ├── rand101.c │ │ ├── rand101.expect │ │ ├── rand102.c │ │ ├── rand102.expect │ │ ├── rand103.c │ │ ├── rand103.expect │ │ ├── rand104.c │ │ ├── rand104.expect │ │ ├── rand105.c │ │ ├── rand105.expect │ │ ├── rand106.c │ │ ├── rand106.expect │ │ ├── rand107.c │ │ ├── rand107.expect │ │ ├── rand108.c │ │ ├── rand108.expect │ │ ├── rand109.c │ │ ├── rand109.expect │ │ ├── rand11.c │ │ ├── rand11.expect │ │ ├── rand110.c │ │ ├── rand110.expect │ │ ├── rand12.c │ │ ├── rand12.expect │ │ ├── rand13.c │ │ ├── rand13.expect │ │ ├── rand14.c │ │ ├── rand14.expect │ │ ├── rand15.c │ │ ├── rand15.expect │ │ ├── rand16.c │ │ ├── rand16.expect │ │ ├── rand17.c │ │ ├── rand17.expect │ │ ├── rand18.c │ │ ├── rand18.expect │ │ ├── rand19.c │ │ ├── rand19.expect │ │ ├── rand2.c │ │ ├── rand2.expect │ │ ├── rand20.c │ │ ├── rand20.expect │ │ ├── rand21.c │ │ ├── rand21.expect │ │ ├── rand22.c │ │ ├── rand22.expect │ │ ├── rand23.c │ │ ├── rand23.expect │ │ ├── rand24.c │ │ ├── rand24.expect │ │ ├── rand25.c │ │ ├── rand25.expect │ │ ├── rand26.c │ │ ├── rand26.expect │ │ ├── rand27.c │ │ ├── rand27.expect │ │ ├── rand28.c │ │ ├── rand28.expect │ │ ├── rand29.c │ │ ├── rand29.expect │ │ ├── rand3.c │ │ ├── rand3.expect │ │ ├── rand30.c │ │ ├── rand30.expect │ │ ├── rand31.c │ │ ├── rand31.expect │ │ ├── rand32.c │ │ ├── rand32.expect │ │ ├── rand33.c │ │ ├── rand33.expect │ │ ├── rand34.c │ │ ├── rand34.expect │ │ ├── rand35.c │ │ ├── rand35.expect │ │ ├── rand36.c │ │ ├── rand36.expect │ │ ├── rand37.c │ │ ├── rand37.expect │ │ ├── rand38.c │ │ ├── rand38.expect │ │ ├── rand39.c │ │ ├── rand39.expect │ │ ├── rand4.c │ │ ├── rand4.expect │ │ ├── rand40.c │ │ ├── rand40.expect │ │ ├── rand41.c │ │ ├── rand41.expect │ │ ├── rand42.c │ │ ├── rand42.expect │ │ ├── rand43.c │ │ ├── rand43.expect │ │ ├── rand44.c │ │ ├── rand44.expect │ │ ├── rand45.c │ │ ├── rand45.expect │ │ ├── rand46.c │ │ ├── rand46.expect │ │ ├── rand47.c │ │ ├── rand47.expect │ │ ├── rand48.c │ │ ├── rand48.expect │ │ ├── rand49.c │ │ ├── rand49.expect │ │ ├── rand5.c │ │ ├── rand5.expect │ │ ├── rand50.c │ │ ├── rand50.expect │ │ ├── rand51.c │ │ ├── rand51.expect │ │ ├── rand52.c │ │ ├── rand52.expect │ │ ├── rand53.c │ │ ├── rand53.expect │ │ ├── rand54.c │ │ ├── rand54.expect │ │ ├── rand55.c │ │ ├── rand55.expect │ │ ├── rand56.c │ │ ├── rand56.expect │ │ ├── rand57.c │ │ ├── rand57.expect │ │ ├── rand58.c │ │ ├── rand58.expect │ │ ├── rand59.c │ │ ├── rand59.expect │ │ ├── rand6.c │ │ ├── rand6.expect │ │ ├── rand60.c │ │ ├── rand60.expect │ │ ├── rand61.c │ │ ├── rand61.expect │ │ ├── rand62.c │ │ ├── rand62.expect │ │ ├── rand63.c │ │ ├── rand63.expect │ │ ├── rand64.c │ │ ├── rand64.expect │ │ ├── rand65.c │ │ ├── rand65.expect │ │ ├── rand66.c │ │ ├── rand66.expect │ │ ├── rand67.c │ │ ├── rand67.expect │ │ ├── rand68.c │ │ ├── rand68.expect │ │ ├── rand69.c │ │ ├── rand69.expect │ │ ├── rand7.c │ │ ├── rand7.expect │ │ ├── rand70.c │ │ ├── rand70.expect │ │ ├── rand71.c │ │ ├── rand71.expect │ │ ├── rand72.c │ │ ├── rand72.expect │ │ ├── rand73.c │ │ ├── rand73.expect │ │ ├── rand74.c │ │ ├── rand74.expect │ │ ├── rand75.c │ │ ├── rand75.expect │ │ ├── rand76.c │ │ ├── rand76.expect │ │ ├── rand77.c │ │ ├── rand77.expect │ │ ├── rand78.c │ │ ├── rand78.expect │ │ ├── rand79.c │ │ ├── rand79.expect │ │ ├── rand8.c │ │ ├── rand8.expect │ │ ├── rand80.c │ │ ├── rand80.expect │ │ ├── rand81.c │ │ ├── rand81.expect │ │ ├── rand82.c │ │ ├── rand82.expect │ │ ├── rand83.c │ │ ├── rand83.expect │ │ ├── rand84.c │ │ ├── rand84.expect │ │ ├── rand85.c │ │ ├── rand85.expect │ │ ├── rand86.c │ │ ├── rand86.expect │ │ ├── rand87.c │ │ ├── rand87.expect │ │ ├── rand88.c │ │ ├── rand88.expect │ │ ├── rand89.c │ │ ├── rand89.expect │ │ ├── rand9.c │ │ ├── rand9.expect │ │ ├── rand90.c │ │ ├── rand90.expect │ │ ├── rand91.c │ │ ├── rand91.expect │ │ ├── rand92.c │ │ ├── rand92.expect │ │ ├── rand93.c │ │ ├── rand93.expect │ │ ├── rand94.c │ │ ├── rand94.expect │ │ ├── rand95.c │ │ ├── rand95.expect │ │ ├── rand96.c │ │ ├── rand96.expect │ │ ├── rand97.c │ │ ├── rand97.expect │ │ ├── rand98.c │ │ ├── rand98.expect │ │ ├── rand99.c │ │ └── rand99.expect │ ├── skip.cmd │ ├── test.cmd │ └── test.sh └── test-qcc │ ├── LICENSE.txt │ ├── ary.c │ ├── block.c │ ├── brk_ctn.c │ ├── cast.c │ ├── check.cmd │ ├── ctrl.c │ ├── fcall.c │ ├── float.c │ ├── for.c │ ├── funcptr.c │ ├── globalv.c │ ├── main.c │ ├── op.c │ ├── ptr.c │ ├── sizeof.c │ ├── struct.c │ ├── ternary.c │ ├── test.cmd │ ├── test.sh │ └── var.c └── utility ├── LICENSE.miniyacc └── myacc.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.dll 2 | *.exe 3 | *.obj 4 | *.exp 5 | *.map 6 | *.lib 7 | *.expect 8 | *.result 9 | test.c 10 | result.txt 11 | timeit.dat 12 | sample.db 13 | kcsrt/libsrc/kcs/ext_json.c 14 | json.output 15 | language/ 16 | -------------------------------------------------------------------------------- /doc/images/fib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/doc/images/fib.png -------------------------------------------------------------------------------- /doc/images/switch-case1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/doc/images/switch-case1.png -------------------------------------------------------------------------------- /doc/images/switch-case2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/doc/images/switch-case2.png -------------------------------------------------------------------------------- /doc/images/switch-case3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/doc/images/switch-case3.png -------------------------------------------------------------------------------- /doc/licenses/LICENSE.sqlite3: -------------------------------------------------------------------------------- 1 | The author disclaims copyright to this source code. In place of 2 | a legal notice, here is a blessing: 3 | 4 | * May you do good and not evil. 5 | * May you find forgiveness for yourself and forgive others. 6 | * May you share freely, never taking more than you give. 7 | -------------------------------------------------------------------------------- /include/kcs/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef KCC_ASSERT_H 2 | #define KCC_ASSERT_H 3 | 4 | #undef assert 5 | 6 | #ifdef NDEBUG 7 | 8 | #define assert(expression) ((void)0) 9 | 10 | #else 11 | 12 | #include 13 | #include 14 | void __kcc_assert(const char *message, const char *file, unsigned int line); 15 | #define assert(expression) (void)((!!(expression)) || (__kcc_assert(#expression, __FILE__, (unsigned)__LINE__), 0)) 16 | 17 | #endif 18 | 19 | #endif /* KCC_ASSERT_H */ 20 | -------------------------------------------------------------------------------- /include/kcs/dll.h: -------------------------------------------------------------------------------- 1 | #ifndef DLL_H 2 | #define DLL_H 3 | 4 | #include 5 | 6 | #define C_MAX_ARGS (10) 7 | typedef enum arg_value_type_ { 8 | C_INT, C_UINT, C_DBL, C_STR, C_PTR 9 | } arg_value_type_t; 10 | typedef struct arg_type_ { 11 | arg_value_type_t type; 12 | union { 13 | int64_t i; 14 | uint64_t u; 15 | double d; 16 | char *s; 17 | void *p; 18 | } value; 19 | } arg_type_t; 20 | 21 | #endif /* DLL_H */ 22 | -------------------------------------------------------------------------------- /include/stdlib/alloca.h: -------------------------------------------------------------------------------- 1 | #ifndef _ALLOCA_H 2 | #define _ALLOCA_H 3 | 4 | #define alloca(n) __builtin_alloca(n) 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/stdlib/float.h: -------------------------------------------------------------------------------- 1 | #ifndef _FLOAT_H 2 | #define _FLOAT_H 3 | 4 | /* 5 | * IEEE float. 6 | */ 7 | #define FLT_RADIX 2 8 | #define FLT_ROUNDS 1 9 | #define FLT_DIG 6 10 | #define FLT_EPSILON 1.19209290e-07f 11 | #define FLT_MANT_DIG 24 12 | #define FLT_MAX 3.40282347e+38f 13 | #define FLT_MAX_EXP 128 14 | #define FLT_MIN 1.17549435e-38f 15 | #define FLT_MIN_EXP (-125) 16 | 17 | /* 18 | * IEEE double. 19 | */ 20 | #define DBL_DIG 15 21 | #define DBL_EPSILON 2.2204460492503131e-16 22 | #define DBL_MANT_DIG 53 23 | #define DBL_MAX 1.7976931348623157e+308 24 | #define DBL_MAX_EXP 1024 25 | #define DBL_MIN 2.2250738585072014e-308 26 | #define DBL_MIN_EXP (-1021) 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/stdlib/stdalign.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDALIGN_H 2 | #define _STDALIGN_H 3 | 4 | #define alignof _Alignof 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/stdlib/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDBOOL_H 2 | #define _STDBOOL_H 3 | 4 | #define bool _Bool 5 | #define true 1 6 | #define false 0 7 | #define __bool_true_false_are_defined 1 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /include/stdlib/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | typedef __SIZE_TYPE__ size_t; 5 | typedef __PTRDIFF_TYPE__ ptrdiff_t; 6 | typedef __WCHAR_TYPE__ wchar_t; 7 | 8 | #define NULL ((void *) 0) 9 | #define offsetof(T, field) ((size_t) &((T *) 0)->field) 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /kcsrt/include/_ext.h: -------------------------------------------------------------------------------- 1 | #ifndef _EXT_H 2 | #define _EXT_H 3 | 4 | /* --------------------------------------------------------------------------------------------- 5 | KCC Extended Library - to use external dll module 6 | --------------------------------------------------------------------------------------------- */ 7 | 8 | void *kcc_extlib(void); 9 | 10 | #ifndef KCC_NO_IMPORT 11 | #if defined(__KCC_JIT__) || defined(__KCC__) 12 | #include <../libsrc/kcs/ext.c> 13 | #endif 14 | #endif 15 | 16 | #endif /* _EXT_H */ 17 | -------------------------------------------------------------------------------- /kcsrt/include/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef KCC_ASSERT_H 2 | #define KCC_ASSERT_H 3 | 4 | #include <_builtin.h> 5 | 6 | #ifdef NDEBUG 7 | #define assert(expr) ((void)0) 8 | #else 9 | void __kcc_builtin_abort(void); 10 | void __kcc_assert_fail(const char *file, int line, const char *msg); 11 | #define assert(expr) ((expr) ? (void)0 : __kcc_assert_fail(__FILE__, __LINE__, #expr)) 12 | 13 | #ifndef KCC_NO_IMPORT 14 | #if defined(__KCC_JIT__) || defined(__KCC__) 15 | #include <../libsrc/assert.c> 16 | #elif defined(__KCC__) 17 | #pragma import("assert"); 18 | #endif 19 | #endif 20 | 21 | #endif 22 | 23 | #define static_assert _Static_assert 24 | 25 | #endif /* KCC_ASSERT_H */ 26 | -------------------------------------------------------------------------------- /kcsrt/include/kcs/regex.h: -------------------------------------------------------------------------------- 1 | #ifndef REGEX_H 2 | #define REGEX_H 3 | 4 | #include <_ext.h> 5 | 6 | typedef struct regex_ { 7 | void *h; 8 | int num_regs; 9 | int beg[10]; 10 | int end[10]; 11 | } regex_t; 12 | 13 | regex_t *regex_compile(const char *pattern); 14 | int regex_search(regex_t *regex, const char *str); 15 | void regex_free(regex_t *regex); 16 | 17 | #ifndef KCC_NO_IMPORT 18 | #if defined(__KCC_JIT__) || defined(__KCC__) 19 | #include <../libsrc/kcs/ext_regex.c> 20 | #endif 21 | #endif 22 | 23 | #endif /* REGEX_H */ 24 | -------------------------------------------------------------------------------- /kcsrt/include/stdalign.h: -------------------------------------------------------------------------------- 1 | #ifndef KCC_STDALIGN_H 2 | #define KCC_STDALIGN_H 3 | 4 | #define alignof _Alignof 5 | 6 | #endif /* KCC_STDALIGN_H */ 7 | -------------------------------------------------------------------------------- /kcsrt/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef KCC_STDARG_H 2 | #define KCC_STDARG_H 3 | 4 | #include <_builtin.h> 5 | 6 | #if defined(__KCC_JIT__) 7 | typedef __builtin_va_list va_list; 8 | #define va_start(list, arg) __builtin_va_start(list, arg) 9 | #define va_arg(list, type) __builtin_va_arg(list, type) 10 | #define va_end(list) 11 | #if __STDC_VERSION__ >= 199901L 12 | # define va_copy(dst, src) (*(dst) = *(src)) 13 | #endif 14 | #else 15 | typedef char* va_list; 16 | #define va_start(ap, last) ap = (char*)&last 17 | #define va_arg(ap, typ) (*(typ*)(ap -= (sizeof(typ) < 8 ? 8 : sizeof(typ)))) 18 | #define va_copy(dst, src) dst = src 19 | #define va_end(ap) 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /kcsrt/include/stdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef KCC_STDBOOL_H 2 | #define KCC_STDBOOL_H 3 | 4 | #define bool _Bool 5 | #define true (1) 6 | #define false (0) 7 | #define __bool_true_false_are_defined (1) 8 | 9 | #endif /* KCC_STDBOOL_H */ 10 | -------------------------------------------------------------------------------- /kcsrt/include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef KCC_STDDEF_H 2 | #define KCC_STDDEF_H 3 | 4 | #include <_builtin.h> 5 | #define offsetof(T, M) ((size_t)&(((T*)0)->M)) 6 | 7 | typedef unsigned int wchar_t; 8 | typedef long double max_align_t; 9 | 10 | #endif /* KCC_STDDEF_H */ 11 | -------------------------------------------------------------------------------- /kcsrt/include/stdnoreturn.h: -------------------------------------------------------------------------------- 1 | #ifndef KCC_STDNORETURN_H 2 | #define KCC_STDNORETURN_H 3 | 4 | #define noreturn _Noreturn 5 | 6 | #endif /* KCC_STDNORETURN_H */ 7 | -------------------------------------------------------------------------------- /kcsrt/libsrc/assert.c: -------------------------------------------------------------------------------- 1 | #ifndef KCC_ASSERT_ASSERT_C 2 | #define KCC_ASSERT_ASSERT_C 3 | 4 | #define KCC_NO_IMPORT 5 | #include 6 | #undef KCC_NO_IMPORT 7 | 8 | #pragma lib("stdio"); 9 | 10 | void __kcc_assert_fail(const char *file, int line, const char *msg) 11 | { 12 | printf("Assertion failed at %s:%d\n", file, line); 13 | printf("Error: %s\n", msg); 14 | __kcc_builtin_abort(); 15 | } 16 | 17 | #endif /* KCC_ASSERT_ASSERT_C */ 18 | -------------------------------------------------------------------------------- /kcsrt/libsrc/kcs/ext.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void *kccext_handle = NULL; 5 | 6 | static void kcc_ext_atexit(void) 7 | { 8 | if (kccext_handle) { 9 | __kcc_builtin_unloadlib(kccext_handle); 10 | } 11 | } 12 | 13 | void *kcc_extlib(void) 14 | { 15 | if (!kccext_handle) { 16 | kccext_handle = __kcc_builtin_loadlib("kcsext", NULL); 17 | atexit(kcc_ext_atexit); 18 | } 19 | return kccext_handle; 20 | } 21 | -------------------------------------------------------------------------------- /kcsrt/libsrc/kcs/ext_timer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void *timer_init(void) 4 | { 5 | void *h = kcc_extlib(); 6 | void *timer = __kcc_builtin_call_p(h, "timer_init"); 7 | return timer; 8 | } 9 | 10 | double timer_elapsed(void *tmr) 11 | { 12 | void *h = kcc_extlib(); 13 | __kcc_builtin_reset_args(); 14 | __kcc_builtin_add_arg_p(tmr); 15 | double elapsed = __kcc_builtin_call_d(h, "timer_elapsed"); 16 | return elapsed; 17 | } 18 | 19 | void timer_free(void *tmr) 20 | { 21 | void *h = kcc_extlib(); 22 | __kcc_builtin_reset_args(); 23 | __kcc_builtin_add_arg_p(tmr); 24 | __kcc_builtin_call(h, "timer_free"); 25 | } 26 | -------------------------------------------------------------------------------- /make.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | nmake -f Makefile.msc %1 %2 %3 %4 %5 %6 %7 %8 %9 3 | exit /b 0 4 | -------------------------------------------------------------------------------- /samples/algo-c/endian.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | int i = 1; 7 | if (*((char *)&i)) 8 | printf("little-endian\n"); 9 | else if (*((char *)&i + (sizeof(int) - 1))) 10 | printf("big-endian\n"); 11 | else 12 | printf("unknown\n"); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /samples/fib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fib(int n) 4 | { 5 | if (n < 3) return n; 6 | return fib(n-2) + fib(n-1); 7 | } 8 | 9 | int main() 10 | { 11 | return printf("%d\n", fib(34)); 12 | } 13 | -------------------------------------------------------------------------------- /samples/fib.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | node [fontname="Courier_New",fontsize=10,style="setlinewidth(0.1)",shape=record]; 3 | edge [fontname="Courier_New",fontsize=10,style="setlinewidth(0.1)"]; 4 | label="fib" 5 | labelloc="t" 6 | L1 [label="{ \.L1 | if 3 \> n goto \.L2 }"]; 7 | L3 [label="{ \.L3 | .t1 = n - 2 | param .t1 | .t2 = call &fib | 8 | .t3 = n - 1 | param .t3 | .t4 = call &fib | return .t2 + .t4 }"]; 9 | L2 [label="{ \.L2 | return n }"]; 10 | L1:s -> L3:n; 11 | L1:s -> L2:n; 12 | } -------------------------------------------------------------------------------- /samples/qsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int cmp(const void *p, const void *q) 5 | { 6 | return *(int*)p - *(int*)q; 7 | } 8 | 9 | #define N 20 10 | int a[N]; 11 | 12 | int main(void) 13 | { 14 | int i; 15 | 16 | printf("Before:"); 17 | for (i = 0; i < N; i++) { 18 | a[i] = rand() / (RAND_MAX / 100 + 1); 19 | printf(" %2d", a[i]); 20 | } 21 | printf("\n"); 22 | qsort(a, sizeof(a)/sizeof(a[0]), sizeof(a[0]), cmp); 23 | printf("After: "); 24 | for (i = 0; i < N; i++) printf(" %2d", a[i]); 25 | printf("\n"); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /samples/queue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void queue_sample() 5 | { 6 | /* queue sample */ 7 | queue_of_(int, x); 8 | queue_enqueue(x, 100); 9 | queue_enqueue(x, 200); 10 | queue_enqueue(x, 300); 11 | while (queue_size(x) > 0) { 12 | printf("%d, ", queue_dequeue(x)); 13 | } 14 | printf("\n"); 15 | queue_free(x); 16 | } 17 | 18 | int main() 19 | { 20 | queue_sample(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /samples/redecl.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int test(int n); 4 | int test(int n) 5 | { 6 | return printf("n = %d\n", n); 7 | } 8 | 9 | int test(int n); /* no error */ 10 | 11 | /* Should be a compile error. */ 12 | int test(int n) 13 | { 14 | return printf("n = %d\n", n); 15 | } 16 | 17 | int main() 18 | { 19 | return test(12); 20 | } 21 | -------------------------------------------------------------------------------- /samples/sample.json: -------------------------------------------------------------------------------- 1 | [ 2 | "Sample", 3 | { 4 | "x": 410, 5 | "y": 150, 6 | "type": "link", 7 | "path": "/Applications" 8 | }, 9 | { 10 | "p1": { 11 | "x": 130, 12 | "y": 150, 13 | "type": "file" 14 | }, 15 | "p2": { 16 | "x": 230, 17 | "y": 90, 18 | "type": "directory" 19 | } 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /samples/stack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct val { 5 | int type; 6 | int value; 7 | }; 8 | 9 | void stack_sample() 10 | { 11 | /* stack sample */ 12 | stack_of_(struct val, x); 13 | stack_push(x, ((struct val){ .type = 1, .value = 100 })); 14 | stack_push(x, ((struct val){ .type = 1, .value = 200 })); 15 | stack_push(x, ((struct val){ .type = 2, .value = 300 })); 16 | while (stack_size(x) > 0) { 17 | printf("%d, ", stack_pop(x).value); 18 | } 19 | printf("\n"); 20 | stack_free(x); 21 | } 22 | 23 | int main() 24 | { 25 | stack_sample(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /samples/switch-case.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int switch_func(int x) 4 | { 5 | switch (x) { 6 | case 1: return 1; 7 | case 2: return 2; 8 | case 3: return 3; 9 | case 4: return 4; 10 | case 5: return 5; 11 | case 6: return 6; 12 | case 7: return 7; 13 | case 8: return 8; 14 | default: 15 | break; 16 | } 17 | return 10; 18 | } 19 | 20 | int main(void) 21 | { 22 | for (int i = -9; i < 10; ++i) { 23 | printf("[%2d] switch_func(%d) = %d\n", i, i, switch_func(i)); 24 | } 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /samples/vec.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int d; 7 | kvec_t(int) kv; 8 | kv_init(kv); 9 | kv_push(int, kv, 1); 10 | kv_push(int, kv, 10); 11 | kv_push(int, kv, 20); 12 | kv_push(int, kv, 30); 13 | kv_push(int, kv, 40); 14 | kv_A(kv, 3) = 300; /* index must exist because of static access */ 15 | kv_a(int, kv, 5) = 500; /* expanding if needed */ 16 | kv_a(int, kv, 6) = 600; 17 | printf("size: %d\n", kv.n); 18 | for (int i = 0; i < kv.n; ++i) 19 | printf("%d\n", kv_A(kv, i)); 20 | kv_destroy(kv); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /samples/vector.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void vector_sample() 5 | { 6 | /* vector sample */ 7 | vector_of_(int, x); 8 | vector_push(x, 100); 9 | vector_push(x, 200); 10 | vector_push(x, 300); 11 | for (int i = 0; i < vector_size(x); ++i) { 12 | printf("%d, ", x[i]); 13 | } 14 | printf("\n"); 15 | vector_free(x); 16 | } 17 | 18 | int main() 19 | { 20 | vector_sample(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fclose.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_fclose(fileio* stream) 6 | { 7 | if (!stream) return EOF; 8 | 9 | int ret = 0; 10 | klib_flush_buffer(stream); 11 | if (stream->handle != INVALID_HANDLE_VALUE && CloseHandle(stream->handle) == 0) { 12 | ret = EOF; 13 | } 14 | if (stream->allocated) { 15 | free(stream->buf); 16 | } 17 | free(stream); 18 | return ret; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/feof.c: -------------------------------------------------------------------------------- 1 | 2 | #include "../fileio.h" 3 | 4 | #if defined(KLIB_CONFIG_FILEIO_WIN) 5 | 6 | int klib_feof(fileio* stream) 7 | { 8 | if (stream->flags & 0x10) return 0; 9 | if (stream->flags & 0x08) return 1; 10 | int c = klib_fgetc(stream); 11 | if (c == EOF) return 1; 12 | 13 | stream->flags |= 0x10; 14 | stream->ungetc = c; 15 | return 0; 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fflush.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_fflush(fileio* stream) 6 | { 7 | if (klib_flush_buffer(stream) == EOF) { 8 | return EOF; 9 | } 10 | 11 | return FlushFileBuffers(stream->handle) ? 0 : EOF; 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fgetc.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_fgetc(fileio* stream) 6 | { 7 | if (stream != fio_stdin && klib_flush_buffer(stream) == EOF) { 8 | return EOF; 9 | } 10 | 11 | int c = EOF; 12 | if (stream->flags & 0x10) { 13 | stream->flags &= ~0x10; 14 | return stream->ungetc; 15 | } 16 | if ((stream->flags & 0x08) == 0) { 17 | char p; 18 | klib_fread(&p, 1, 1, stream); 19 | c = (int)p; 20 | } 21 | if (stream->flags & 0x08) { 22 | return EOF; 23 | } 24 | return c; 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fgetpos.c: -------------------------------------------------------------------------------- 1 | 2 | #include "../fileio.h" 3 | 4 | #if defined(KLIB_CONFIG_FILEIO_WIN) 5 | 6 | int klib_fgetpos(fileio* stream, klib_fpos_t *pos) 7 | { 8 | if (!stream || !stream->handle || !pos) { 9 | return -1; 10 | } 11 | *pos = GetFilePointerEx(stream->handle); 12 | return 0; 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fgets.c: -------------------------------------------------------------------------------- 1 | 2 | #include "../fileio.h" 3 | 4 | #if defined(KLIB_CONFIG_FILEIO_WIN) 5 | 6 | char* klib_fgets(char* s, int n, fileio* stream) 7 | { 8 | char* s0 = s; 9 | while (--n > 0) { 10 | int c = klib_fgetc(stream); 11 | if (c == EOF) { 12 | if (s0 == s) s0 = NULL; 13 | break; 14 | } 15 | *s++ = c; 16 | if (c == '\n') break; 17 | } 18 | *s = '\0'; 19 | return s0; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fprintf.c: -------------------------------------------------------------------------------- 1 | 2 | #include "../fileio.h" 3 | 4 | #if defined(KLIB_CONFIG_FILEIO_WIN) 5 | 6 | int klib_fprintf(fileio* stream, const char* format, ...) 7 | { 8 | va_list ap; 9 | va_start(ap, format); 10 | int i = klib_vfprintf(stream, format, ap); 11 | va_end(ap); 12 | return i; 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fputc.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_fputc(int c, fileio* stream) 6 | { 7 | if (c == EOF) return EOF; 8 | char p = (char)c; 9 | return (klib_fwrite(&p, 1, 1, stream) == 1) ? c : EOF; 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fputs.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_fputs(const char* s, fileio* stream) 6 | { 7 | unsigned int l = strlen(s); 8 | if (klib_fwrite(s, 1, l, stream) == l) { 9 | return 0; 10 | } 11 | return EOF; 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/fsetpos.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_fsetpos(fileio* stream, klib_fpos_t *pos) 6 | { 7 | if (!stream || !stream->handle || !pos) { 8 | return -1; 9 | } 10 | if (klib_fseek(stream, *pos, SEEK_SET) != 0) { 11 | return -1; 12 | } 13 | return 0; 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/ftell.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int64_t klib_ftell(fileio* stream) 6 | { 7 | if (klib_flush_buffer(stream) == EOF) { 8 | return EOF; 9 | } 10 | 11 | klib_fpos_t p = GetFilePointerEx(stream->handle); 12 | if (p == EOF) { 13 | return 0; 14 | } 15 | if (stream->flags & 0x10) --p; 16 | return (int64_t)p; 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/rewind.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | void klib_rewind(fileio* stream) 6 | { 7 | klib_fseek(stream, 0, SEEK_SET); 8 | stream->flags &= ~0x08; 9 | } 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/ungetc.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_ungetc(int c, fileio* stream) 6 | { 7 | if (klib_flush_buffer(stream) == EOF) { 8 | return EOF; 9 | } 10 | 11 | if (stream->flags & 0x10) return EOF; 12 | stream->flags |= 0x10; 13 | return stream->ungetc = c; 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/vfprintf.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_vfprintf(fileio* stream, const char* format, va_list arg) 6 | { 7 | char s[8192] = {0}; 8 | int i = KLIB_VSNPRINTF(s, 8191, format, arg); 9 | i = klib_fwrite(s, 1, i, stream); 10 | if (stream == fio_stdout || stream == fio_stderr) { 11 | klib_fflush(stream); 12 | } 13 | return i; 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/_extdll/lib/fileio/vprintf.c: -------------------------------------------------------------------------------- 1 | #include "../fileio.h" 2 | 3 | #if defined(KLIB_CONFIG_FILEIO_WIN) 4 | 5 | int klib_vprintf(const char* format, va_list arg) 6 | { 7 | return klib_vfprintf(fio_stdout, format, arg); 8 | } 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - gcc 5 | - clang 6 | 7 | install: true 8 | 9 | branches: 10 | except: 11 | - 5.9.6 12 | 13 | before_script: 14 | - autoreconf -fi 15 | 16 | script: 17 | - ./configure && make && make all-test 18 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/AUTHORS: -------------------------------------------------------------------------------- 1 | (K.Kosako) 2 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/src/_extdll/lib/onig/ChangeLog -------------------------------------------------------------------------------- /src/_extdll/lib/onig/NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/src/_extdll/lib/onig/NEWS -------------------------------------------------------------------------------- /src/_extdll/lib/onig/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # autogen.sh for Oniguruma 3 | 4 | echo "Generating autotools files." 5 | #autoreconf --install --force --symlink || exit 1 6 | autoreconf --install --force || exit 1 7 | 8 | echo "" 9 | echo "Run ./configure, make, and make install." 10 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 4 | check_required_components("@PROJECT_NAME@") 5 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/doc/FAQ: -------------------------------------------------------------------------------- 1 | FAQ 2006/11/14 2 | 3 | 1. Longest match 4 | 5 | You can execute the longest match by using ONIG_OPTION_FIND_LONGEST option 6 | in onig_new(). 7 | 8 | 2. Mailing list 9 | 10 | There is no mailing list for Oniguruma. 11 | 12 | // END 13 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/doc/FAQ.ja: -------------------------------------------------------------------------------- 1 | FAQ 2016/04/06 2 | 3 | 1. 最長マッチ 4 | 5 | onig_new()の中で、ONIG_OPTION_FIND_LONGESTオプション 6 | を使用すれば最長マッチになる。 7 | 8 | 9 | 2. CR + LF 10 | 11 | DOSの改行(CR(0x0c) + LF(0x0a)の連続) 12 | 13 | regenc.hの中の、以下の部分を有効にする。 14 | 15 | /* #define USE_CRNL_AS_LINE_TERMINATOR */ 16 | 17 | 18 | 3. メーリングリスト 19 | 20 | 鬼車に関するメーリングリストは存在しない。 21 | 22 | //END 23 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/m4/.whatever: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/src/_extdll/lib/onig/m4/.whatever -------------------------------------------------------------------------------- /src/_extdll/lib/onig/make_win.bat: -------------------------------------------------------------------------------- 1 | SET ONIG_DIR=%~dp0\src 2 | set THIS_DIR=%~dp0 3 | set BUILD_DIR=%cd% 4 | copy %ONIG_DIR%\config.h.windows.in %BUILD_DIR%\config.h 5 | nmake -f %ONIG_DIR%\Makefile.windows %1 6 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/make_win32.bat: -------------------------------------------------------------------------------- 1 | SET ONIG_DIR=%~dp0\src 2 | set THIS_DIR=%~dp0 3 | set BUILD_DIR=%cd% 4 | copy %ONIG_DIR%\config.h.win32 %BUILD_DIR%\config.h 5 | nmake -f %ONIG_DIR%\Makefile.windows %1 6 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/make_win64.bat: -------------------------------------------------------------------------------- 1 | SET ONIG_DIR=%~dp0\src 2 | set THIS_DIR=%~dp0 3 | set BUILD_DIR=%cd% 4 | copy %ONIG_DIR%\config.h.win64 %BUILD_DIR%\config.h 5 | nmake -f %ONIG_DIR%\Makefile.windows %1 6 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/oniguruma.pc.cmake.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | datarootdir=${prefix}/share 6 | datadir=${prefix}/share 7 | 8 | Name: oniguruma 9 | Description: Regular expression library 10 | Version: @PACKAGE_VERSION@ 11 | Requires: 12 | Libs: -L${libdir} -lonig 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/oniguruma.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | datarootdir=@datarootdir@ 6 | datadir=@datadir@ 7 | 8 | Name: oniguruma 9 | Description: Regular expression library 10 | Version: @PACKAGE_VERSION@ 11 | Requires: 12 | Libs: -L${libdir} -lonig 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/src/euc_jp_prop.gperf: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include "regenc.h" 4 | %} 5 | 6 | struct PropertyNameCtype { 7 | char *name; 8 | int ctype; 9 | }; 10 | 11 | %% 12 | Alpha, 1 13 | Blank, 2 14 | Cntrl, 3 15 | Digit, 4 16 | Graph, 5 17 | Lower, 6 18 | Print, 7 19 | Punct, 8 20 | Space, 9 21 | Upper, 10 22 | XDigit, 11 23 | Word, 12 24 | Alnum, 13 25 | ASCII, 14 26 | Hiragana, 15 27 | Katakana, 16 28 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/src/make_property.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | TMP1=gperf1.tmp 4 | TMP2=gperf2.tmp 5 | GPERF=/usr/local/bin/gperf 6 | 7 | GPERF_OPT='-pt -T -L ANSI-C' 8 | 9 | ADD_CAST='s/return +len +\+ +asso_values/return (unsigned int )len + asso_values/' 10 | 11 | ${GPERF} ${GPERF_OPT} -N onigenc_euc_jp_lookup_property_name --output-file ${TMP1} euc_jp_prop.gperf 12 | cat ${TMP1} | sed -r "${ADD_CAST}" > euc_jp_prop.c 13 | 14 | ${GPERF} ${GPERF_OPT} -N onigenc_sjis_lookup_property_name --output-file ${TMP2} sjis_prop.gperf 15 | cat ${TMP2} | sed -r "${ADD_CAST}" > sjis_prop.c 16 | 17 | rm -f ${TMP1} ${TMP2} 18 | 19 | exit 0 20 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/src/make_unicode_egcb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | NAME=unicode_egcb_data 4 | 5 | ./make_unicode_egcb_data.py > ${NAME}.c 6 | 7 | exit 0 8 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/src/make_unicode_wb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | NAME=unicode_wb_data 4 | 5 | ./make_unicode_wb_data.py > ${NAME}.c 6 | 7 | exit 0 8 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/src/sjis_prop.gperf: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include "regenc.h" 4 | %} 5 | 6 | struct PropertyNameCtype { 7 | char *name; 8 | int ctype; 9 | }; 10 | 11 | %% 12 | Alpha, 1 13 | Blank, 2 14 | Cntrl, 3 15 | Digit, 4 16 | Graph, 5 17 | Lower, 6 18 | Print, 7 19 | Punct, 8 20 | Space, 9 21 | Upper, 10 22 | XDigit, 11 23 | Word, 12 24 | Alnum, 13 25 | ASCII, 14 26 | Hiragana, 15 27 | Katakana, 16 28 | -------------------------------------------------------------------------------- /src/_extdll/lib/onig/test/testc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/src/_extdll/lib/onig/test/testc.c -------------------------------------------------------------------------------- /src/_extdll/lib/onig/windows/testc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/src/_extdll/lib/onig/windows/testc.c -------------------------------------------------------------------------------- /src/_extdll/lib/version.md: -------------------------------------------------------------------------------- 1 | # Version 2 | 3 | | Name | Version | Updated | 4 | | --------- | :-----: | :--------: | 5 | | Oniguruma | 6.9.4 | 2019/09/30 | 6 | | SQLite3 | 3.30.1 | 2019/10/28 | 7 | | miniz | 2.1.0 | 2019/09/30 | 8 | | tiny-aes | - | 2019/02/22 | 9 | -------------------------------------------------------------------------------- /src/backend/graphviz/dot.h: -------------------------------------------------------------------------------- 1 | #ifndef DOT_H 2 | #define DOT_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | /* Set output target. */ 9 | INTERNAL void dot_init(FILE *output); 10 | 11 | /* 12 | * Output internal control flow graph intermediate representation in dot 13 | * format, which can be compiled for rendering. 14 | */ 15 | INTERNAL void dotgen(struct definition *def); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/backend/linker.h: -------------------------------------------------------------------------------- 1 | #ifndef LINKER_H 2 | #define LINKER_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | /* Add command line argument to be passed to the linker. */ 9 | INTERNAL int add_linker_arg(const char *opt); 10 | 11 | /* Invoke the system linker. */ 12 | INTERNAL int invoke_linker(void); 13 | 14 | /* Free memory used for linker arguments. */ 15 | INTERNAL void clear_linker_args(void); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/backend/x86_64/dwarf.h: -------------------------------------------------------------------------------- 1 | #ifndef DWARF_H 2 | #define DWARF_H 3 | 4 | INTERNAL int dwarf_init(const char *filename); 5 | 6 | INTERNAL int dwarf_flush(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/backend/x86_64/jit_util.h: -------------------------------------------------------------------------------- 1 | #ifndef JIT_UTIL_H 2 | #define JIT_UTIL_H 3 | 4 | INTERNAL void jit_create(void **buffer, int size); 5 | INTERNAL void jit_destroy(void *buffer, int size); 6 | INTERNAL int jit_execute_int(void *main_pos); 7 | INTERNAL uint64_t jit_execute_uint64(void *main_pos); 8 | INTERNAL double jit_execute_double(void *main_pos); 9 | INTERNAL void print_stack(void); 10 | 11 | #define jit_execute(m) jit_execute_int(m) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/kcs.c: -------------------------------------------------------------------------------- 1 | 2 | extern int kcsmain(int argc, char *argv[]); 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | return kcsmain(argc, argv); 7 | } 8 | -------------------------------------------------------------------------------- /src/optimizer/liveness.h: -------------------------------------------------------------------------------- 1 | #ifndef LIVENESS_H 2 | #define LIVENESS_H 3 | 4 | #include 5 | 6 | /* 7 | * Compute liveness of each variable on every edge, before and after 8 | * every ir operation. 9 | */ 10 | INTERNAL int live_variable_analysis(struct block *block); 11 | 12 | /* 13 | * Determine whether a variable may be read after a given statement. 14 | * Return zero iff it is definitely not accessed after this point. 15 | */ 16 | INTERNAL int is_live_after( 17 | const struct symbol *sym, 18 | const struct statement *st); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/optimizer/optimize.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTIMIZE_H 2 | #define OPTIMIZE_H 3 | 4 | #include "liveness.h" 5 | 6 | #include 7 | 8 | /* Set to non-zero to enable optimization. */ 9 | INTERNAL void push_optimization(int level); 10 | 11 | /* 12 | * Do data flow analysis and perform optimizations on the intermediate 13 | * representation. Leaves the definition in a semantically equivalent, 14 | * and hopefully more consise, state. 15 | */ 16 | INTERNAL void optimize(struct definition *def); 17 | 18 | /* Disable previously set optimization, cleaning up resources. */ 19 | INTERNAL void pop_optimization(void); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/parser/expression.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPRESSION_H 2 | #define EXPRESSION_H 3 | 4 | #include 5 | 6 | INTERNAL struct block *expression(struct definition *def, struct block *block); 7 | 8 | INTERNAL struct var constant_expression(void); 9 | 10 | INTERNAL struct block *assignment_expression( 11 | struct definition *def, 12 | struct block *block); 13 | 14 | /* 15 | * Free memory used to hold function arguments. 16 | * 17 | * Should be called exactly once before exiting. 18 | */ 19 | INTERNAL void clear_argument_lists(void); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/parser/statement.h: -------------------------------------------------------------------------------- 1 | #ifndef STATEMENT_H 2 | #define STATEMENT_H 3 | 4 | #include 5 | 6 | INTERNAL struct block *statement(struct definition *def, struct block *parent); 7 | 8 | INTERNAL struct block *block(struct definition *def, struct block *parent); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/preprocessor/strtab.h: -------------------------------------------------------------------------------- 1 | #ifndef STRTAB_H 2 | #define STRTAB_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | /* 11 | * Register a string and store it internally, allocating a new copy if 12 | * needed. Manages memory ownership for all string constants used at 13 | * runtime. 14 | */ 15 | INTERNAL String str_register(const char *str, size_t len); 16 | 17 | /* Concatenate two strings together. */ 18 | INTERNAL String str_cat(String a, String b); 19 | 20 | /* Free memory used for string table. */ 21 | INTERNAL void strtab_reset(void); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /test/test-8cc/_testmain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // For test/extern.c 4 | int externvar1 = 98; 5 | int externvar2 = 99; 6 | 7 | // For test/function.c 8 | int booltest1(bool x) { 9 | return x; 10 | } 11 | -------------------------------------------------------------------------------- /test/test-8cc/constexpr.c: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | 5 | int x1[] = { 1, 2, 3, 4, 5 }; 6 | int *p1 = x1; 7 | int *q1 = x1 + 2; 8 | 9 | int x2 = 7; 10 | int *p2 = &x2 + 1; 11 | 12 | void testmain() { 13 | print("constexpr"); 14 | expect(1, *p1); 15 | expect(3, *q1); 16 | expect(7, p2[-1]); 17 | } 18 | -------------------------------------------------------------------------------- /test/test-8cc/conversion.c: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | 5 | static void test_bool() { 6 | _Bool v = 3; 7 | expect(1, v); 8 | v = 5; 9 | expect(1, v); 10 | v = 0.5; 11 | expect(1, v); 12 | v = 0.0; 13 | expect(0, v); 14 | } 15 | 16 | static void test_float() { 17 | double a = 4.0; 18 | float b = a; 19 | expectf(4, b); 20 | } 21 | 22 | void testmain() { 23 | print("type conversion"); 24 | test_bool(); 25 | test_float(); 26 | } 27 | -------------------------------------------------------------------------------- /test/test-8cc/enum.c: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | 5 | enum { g1, g2, g3 } global1; 6 | 7 | void testmain() { 8 | print("enum"); 9 | 10 | expect(0, g1); 11 | expect(2, g3); 12 | 13 | enum { x } v; 14 | expect(0, x); 15 | 16 | enum { y }; 17 | expect(0, y); 18 | 19 | enum tag { z }; 20 | enum tag a = z; 21 | expect(0, z); 22 | expect(0, a); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-8cc/extern.c: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | 5 | extern int externvar1; 6 | int extern externvar2; 7 | 8 | void testmain() { 9 | print("extern"); 10 | expect(98, externvar1); 11 | expect(99, externvar2); 12 | } 13 | 14 | #include "_testmain.c" 15 | -------------------------------------------------------------------------------- /test/test-8cc/import.c: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | 5 | // import.h would raise an error if read twice. 6 | #import "import.h" 7 | #import "import.h" 8 | #include "import.h" 9 | #import "../test/import.h" 10 | 11 | // once.h would raise an error if read twice 12 | #include "once.h" 13 | #include "once.h" 14 | #import "once.h" 15 | #include "../test/once.h" 16 | 17 | void testmain() { 18 | print("import"); 19 | } 20 | -------------------------------------------------------------------------------- /test/test-8cc/import.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #ifdef IMPORT_H 4 | #error "#import directive bug" 5 | #endif 6 | 7 | #define IMPORT_H 1 8 | -------------------------------------------------------------------------------- /test/test-8cc/includeguard1.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #ifndef INCLUDEGUARD1_H 4 | #define INCLUDEGUARD1_H 5 | #endif 6 | -------------------------------------------------------------------------------- /test/test-8cc/includeguard2.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #ifndef INCLUDEGUARD2_H 4 | #endif 5 | -------------------------------------------------------------------------------- /test/test-8cc/includeguard3.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #ifndef INCLUDEGUARD3_H 4 | #define INCLUDEGUARD3_H 5 | #endif 6 | 7 | #define FOO 1 8 | -------------------------------------------------------------------------------- /test/test-8cc/includeguard4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #ifndef INCLUDEGUARD4_H 4 | #define INCLUDEGUARD4_H 5 | #else 6 | #endif 7 | -------------------------------------------------------------------------------- /test/test-8cc/includeguard5.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #define FOO 4 | #ifndef INCLUDEGUARD5_H 5 | #define INCLUDEGUARD5_H 6 | #endif 7 | -------------------------------------------------------------------------------- /test/test-8cc/includeguard6.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #ifndef INCLUDEGUARD6_H 4 | #define INCLUDEGUARD6_H 5 | #include "includeguard7.h" 6 | -------------------------------------------------------------------------------- /test/test-8cc/includeguard7.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #endif 4 | -------------------------------------------------------------------------------- /test/test-8cc/iso646.c: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #include 4 | #include "test.h" 5 | 6 | #define SS(x) #x 7 | #define S(x) SS(x) 8 | 9 | void testmain() { 10 | print("iso646"); 11 | expect_string("&&", S(and)); 12 | expect_string("&=", S(and_eq)); 13 | expect_string("&", S(bitand)); 14 | expect_string("|", S(bitor)); 15 | expect_string("~", S(compl)); 16 | expect_string("!", S(not)); 17 | expect_string("!=", S(not_eq)); 18 | expect_string("||", S(or)); 19 | expect_string("|=", S(or_eq)); 20 | expect_string("^", S(xor)); 21 | expect_string("^=", S(xor_eq)); 22 | } 23 | -------------------------------------------------------------------------------- /test/test-8cc/macro1.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #define MACRO_1 "macro1" 4 | #if __INCLUDE_LEVEL__ != 1 5 | # error "include level" 6 | #endif 7 | -------------------------------------------------------------------------------- /test/test-8cc/macro2.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #define MACRO_2 "macro2" 4 | -------------------------------------------------------------------------------- /test/test-8cc/noreturn.c: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | #include 5 | 6 | // _Noreturn is ignored 7 | _Noreturn void f1(); 8 | noreturn void f2(); 9 | inline int f3() { return 1; } 10 | 11 | void testmain() { 12 | print("noreturn"); 13 | expect(1, f3()); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-8cc/once.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #ifdef ONCE_H 4 | #error "#pragma once bug" 5 | #endif 6 | 7 | #pragma once 8 | #define ONCE_H 1 9 | -------------------------------------------------------------------------------- /test/test-8cc/scope.c: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | 5 | void testmain() { 6 | print("scope"); 7 | 8 | int a = 31; 9 | { int a = 64; } 10 | expect(31, a); 11 | { 12 | int a = 64; 13 | expect(64, a); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/test-8cc/staticassert.c: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | 5 | int t() 6 | { 7 | _Static_assert(1, "fail"); 8 | return 1; 9 | } 10 | 11 | void testmain() { 12 | print("static assert"); 13 | _Static_assert(1, "fail"); 14 | expect(t(), 1); 15 | 16 | struct { 17 | _Static_assert(1, "fail"); 18 | } x; 19 | } 20 | -------------------------------------------------------------------------------- /test/test-8cc/stmtexpr.c: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | 5 | void testmain() { 6 | print("statement expression"); 7 | 8 | expect(3, ({ 1; 2; 3; })); 9 | expectf(3.0, ({ 1; 2; 3.0; })); 10 | expect(5, ({ int a = 5; a; })); 11 | } 12 | -------------------------------------------------------------------------------- /test/test-8cc/usualconv.c: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Rui Ueyama. Released under the MIT license. 2 | 3 | #include "test.h" 4 | #include 5 | 6 | static void test_usual_conv() { 7 | expect(1, sizeof(bool)); 8 | expect(1, sizeof((char)0)); 9 | 10 | expect(4, sizeof((bool)0 + (bool)0)); 11 | expect(4, sizeof((char)0 + (char)0)); 12 | expect(4, sizeof((char)0 + (bool)0)); 13 | expect(4, sizeof((char)0 + (int)0)); 14 | expect(8, sizeof((char)0 + (long)0)); 15 | expect(8, sizeof((char)0 + (double)0)); 16 | } 17 | 18 | void testmain() { 19 | print("usual conversion"); 20 | test_usual_conv(); 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/address-deref-offset.c: -------------------------------------------------------------------------------- 1 | struct { 2 | int x, y; 3 | } wat[] = {{1, 2}, {3, 4}}; 4 | 5 | int main(void) { 6 | int *p = &wat[1].y; 7 | return *p; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/anonymous-struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int printf(const char *, ...); 4 | 5 | struct S1 { 6 | int a; 7 | struct { 8 | struct { 9 | char b; 10 | short c; 11 | } x; 12 | char d; 13 | }; 14 | } foo = {1, 2, 3, 4}; 15 | 16 | int main(void) { 17 | return printf("%d, %d (+ %lu), %d (+ %lu), %d (+ %lu)\n", 18 | foo.a, 19 | foo.x.b, offsetof(struct S1, x.b), 20 | foo.x.c, offsetof(struct S1, x.c), 21 | foo.d, offsetof(struct S1, d)); 22 | } 23 | -------------------------------------------------------------------------------- /test/test-lacc/array-decay.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct point { 4 | int x, y; 5 | }; 6 | 7 | struct point p[3] = {{1, 2}, {3, 4}, {5, 6}}; 8 | 9 | int foo(int n, struct point arr[n]) { 10 | return arr->y; 11 | } 12 | 13 | int main(void) { 14 | int a = p->y; 15 | int b = foo(3, p); 16 | return printf("%d, %d\n", a, b); 17 | } 18 | -------------------------------------------------------------------------------- /test/test-lacc/array-nested-init.c: -------------------------------------------------------------------------------- 1 | int foo[4][3][2] = {{{0}}}; 2 | 3 | int main(void) { 4 | return foo[3][2][1] + sizeof(foo); 5 | } 6 | -------------------------------------------------------------------------------- /test/test-lacc/array-param.c: -------------------------------------------------------------------------------- 1 | int printf(const char *s, ...); 2 | 3 | struct obj { 4 | char val[8]; 5 | int len; 6 | }; 7 | 8 | struct obj func(struct obj in) { 9 | struct obj out = {{1, 2, 3}, 3}; 10 | printf("%d, %d, %d (%d)\n", in.val[0], in.val[1], in.val[7], in.len); 11 | return out; 12 | } 13 | 14 | int main(void) { 15 | struct obj foo = {{5, 7, 32, 1, 4, 1, 1, 4}, 13}; 16 | foo = func(foo); 17 | func(foo); 18 | return sizeof(foo); 19 | } 20 | -------------------------------------------------------------------------------- /test/test-lacc/array-reverse-index.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | char c[2] = {1, 2}; 3 | return 1[c]; 4 | } 5 | -------------------------------------------------------------------------------- /test/test-lacc/array-zero-length.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int foo[], bar[0]; 4 | int foo[0]; 5 | 6 | struct S { 7 | char data[0]; 8 | char x, y, z; 9 | } s1; 10 | 11 | int test(struct S s) { 12 | return printf("{%d, %d, %d}\n", s.data[0], s.data[1], s.data[2]); 13 | } 14 | 15 | int main(void) { 16 | s1.x = 3; 17 | s1.y = 2; 18 | s1.z = 1; 19 | 20 | test(s1); 21 | 22 | return printf("size: %lu, %lu\n", sizeof(foo), sizeof(struct S)); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-lacc/array.c: -------------------------------------------------------------------------------- 1 | extern char bytes[4]; 2 | 3 | char bytes[] = {1, 2, 3, 4}; 4 | 5 | char numbers[4] = "1234"; 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | int foo[2]; 10 | int bar[4][2][1]; 11 | 12 | foo[0] = 1; 13 | bar[2][1][0] = 4; 14 | 15 | return foo[0] + bar[2][1][0]; 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/assign-deref-float.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | float v; 4 | double d; 5 | 6 | int main(void) { 7 | float *p = &v, q = 3.14f; 8 | double *r = &d, s = 2.71; 9 | *p = q; 10 | *r = s; 11 | return printf("%f, %f\n", *p, *r); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/assignment-type.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char c = 'a'; 5 | int i = -1; 6 | long l; 7 | l = (c = i); 8 | 9 | printf("%ld\n", l); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield-extend.c: -------------------------------------------------------------------------------- 1 | struct fields { 2 | signed int foo:5; 3 | unsigned int bar:1; 4 | }; 5 | 6 | int main(void) { 7 | struct fields test = {0}; 8 | 9 | test.foo--; 10 | test.bar = 1; 11 | 12 | return test.foo - test.bar; 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield-immediate-assign.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct { 4 | unsigned f1 : 2; 5 | } b; 6 | 7 | int foo(void) { 8 | int a, d = -10; 9 | a = (d < (b.f1 = 2)); 10 | return printf("foo: %u, %d\n", b.f1, a); 11 | } 12 | 13 | int h, i; 14 | unsigned j; 15 | 16 | struct { 17 | signed f0 : 20; 18 | unsigned f1 : 20; 19 | } f; 20 | 21 | int bar(void) { 22 | i = (f.f0 = (h = 0x20CF9BFEL)); 23 | j = (f.f1 = (h = 0x20CF9BFEL)); 24 | return printf("bar: (%d, %d), (%u, %u)\n", f.f0, i, f.f1, j); 25 | } 26 | 27 | int main(void) { 28 | return foo() + bar(); 29 | } 30 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield-initialize-zero.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct fields { 4 | int a : 16; 5 | int b : 4; 6 | int c : 1; 7 | int d : 3; 8 | }; 9 | 10 | struct fields foo(void) { 11 | struct fields t = {5342, 3, 0, 2}; 12 | return t; 13 | } 14 | 15 | struct fields bar(void) { 16 | struct fields t = {87}; 17 | return t; 18 | } 19 | 20 | int main(void) { 21 | struct fields u = foo(), v = bar(); 22 | 23 | return printf("{%d, %d, %d, %d}, {%d, %d, %d, %d}\n", 24 | u.a, u.b, u.c, u.d, v.a, v.b, v.c, v.d); 25 | } 26 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield-load.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | union { 4 | int f1; 5 | signed f0 : 23; 6 | } foo = {0xE2D5F285L}; 7 | 8 | int f = 0; 9 | 10 | union { 11 | int f0 : 3; 12 | unsigned f1 : 2; 13 | } b = {0x04}; 14 | 15 | int out(int n, unsigned long v) { 16 | return printf("%d: %lu\n", n, v); 17 | } 18 | 19 | int cast(void) { 20 | float f = foo.f0; 21 | double d = foo.f0; 22 | return printf("%f, %f\n", f, d); 23 | } 24 | 25 | int main(void) { 26 | if (b.f1) f += 1; 27 | if (b.f0 > 0) f += 2; 28 | 29 | out(1, foo.f1); 30 | out(2, b.f0); 31 | out(3, b.f1); 32 | 33 | cast(); 34 | 35 | return printf("%d\n", f); 36 | } 37 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield-mask.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct { 4 | signed f6 : 1; 5 | } g = {0}; 6 | int f = 42; 7 | 8 | int foo(void) { 9 | g.f6 ^= 4; 10 | if (g.f6) { 11 | (f)--; 12 | } 13 | } 14 | 15 | int main(void) { 16 | foo(); 17 | return printf("%d, %d\n", g.f6, f); 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield-reset-align.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct S0 { 4 | unsigned short f0; 5 | float f1; 6 | signed : 0; 7 | unsigned int f2; 8 | short f3; 9 | char f4; 10 | unsigned short f5; 11 | } foo = {1}; 12 | 13 | int print(struct S0 s) { 14 | return printf("(%d, %f, %u, %d, %d, %d)\n", 15 | s.f0, s.f1, s.f2, s.f3, s.f4, s.f5); 16 | } 17 | 18 | int main(void) { 19 | struct S0 bar = {1, 2.0f}; 20 | return print(foo) 21 | + print(bar) 22 | + printf("%lu\n", sizeof(struct S0)); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield-trailing-zero.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct S1 { 4 | char c; 5 | int : 0; 6 | int : 0; 7 | int : 0; 8 | }; 9 | 10 | struct S2 { 11 | long l; 12 | const signed : 0; 13 | }; 14 | 15 | union U1 { 16 | int : 0; 17 | int : 0; 18 | char c; 19 | int : 0; 20 | int : 0; 21 | int : 0; 22 | int : 0; 23 | }; 24 | 25 | struct S2 foo(int i) { 26 | struct S2 s = {0}; 27 | s.l = i; 28 | return s; 29 | } 30 | 31 | int main(void) { 32 | struct S2 u = foo(42); 33 | return printf("%ld, %lu, %lu, %lu", 34 | u.l, 35 | sizeof(struct S1), 36 | sizeof(struct S2), 37 | sizeof(union U1)); 38 | } 39 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield-unsigned-promote.c: -------------------------------------------------------------------------------- 1 | static struct { 2 | unsigned f1 : 23; 3 | } f; 4 | 5 | int main() { 6 | int h = (f.f1 > -1); 7 | return h; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/bitfield.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct { 4 | unsigned f2 : 13; 5 | signed f3 : 19; 6 | int f5; 7 | signed f6 : 17; 8 | signed f7 : 7; 9 | } f = {30, 374, 1UL, -269, -2}; 10 | 11 | int main(void) { 12 | return printf("{%u, %d, %d, %d, %d} size=%lu\n", 13 | f.f2, f.f3, f.f5, f.f6, f.f7, sizeof(f)); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/bitwise-complement.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int i = 23; 3 | unsigned char c = 3; 4 | 5 | return ~i + ~c; 6 | } 7 | -------------------------------------------------------------------------------- /test/test-lacc/bitwise-constant.c: -------------------------------------------------------------------------------- 1 | static int 2 | a = 3 << 3, 3 | b = 211 >> 2, 4 | c = 5 | 0, 5 | d = 7 & 3, 6 | e = ~5, 7 | f = !0; 8 | 9 | int main(void) { 10 | return a + b + c + d + e + f; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/bitwise-expression.c: -------------------------------------------------------------------------------- 1 | int g = 0xEB0647DCL; 2 | 3 | int main(void) { 4 | int i = (0xEB0647DCL < (g | 0x4B54C5F6B4AB19F8LL)); 5 | return i; 6 | } 7 | -------------------------------------------------------------------------------- /test/test-lacc/bitwise-sign-extend.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | char f = -1L; 4 | long long g = 0x9D3BBD11537C3E80LL; 5 | 6 | int main(void) { 7 | return printf("%lld, %lld, %lld\n", 8 | (g & f), 9 | (g ^ f), 10 | (g | f)); 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/byte-load.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | unsigned char *b = "b2"; 3 | signed char *w = "w3"; 4 | return b[1] + w[1]; 5 | } 6 | -------------------------------------------------------------------------------- /test/test-lacc/c11/alignof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int printf(const char *, ...); 4 | 5 | typedef struct { 6 | void *ptr; 7 | unsigned bytes[5]; 8 | } Data; 9 | 10 | int main(void) { 11 | return printf("%lu, %lu, %lu\n", 12 | alignof(int volatile), 13 | _Alignof(void*[5]), 14 | _Alignof(const Data)); 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/c11/static-assert.c: -------------------------------------------------------------------------------- 1 | #if defined _Static_assert 2 | # error Should not be defined, but valid to ask for it 3 | #endif 4 | 5 | #include 6 | 7 | /* NOT actually on OpenBSD! (This is a bug) */ 8 | #ifdef __OpenBSD__ 9 | #define static_assert _Static_assert 10 | #endif 11 | 12 | _Static_assert('a' < 'b', "Alphabet error"); 13 | 14 | int foo(char a) { 15 | _Static_assert(sizeof(a) == 1, "Hello"); 16 | return 0; 17 | } 18 | 19 | int main(void) { 20 | return foo(42); 21 | } 22 | 23 | static_assert(1, ""); 24 | -------------------------------------------------------------------------------- /test/test-lacc/c99/_Pragma.c: -------------------------------------------------------------------------------- 1 | #define INCLUDE(x) PRAGMA(include #x) 2 | #define PRAGMA(x) _Pragma(#x) 3 | 4 | _Pragma("$") 5 | _Pragma( 6 | "\t" /* 7 | Something */ 8 | ) 9 | _Pragma 10 | ("" 11 | ) 12 | 13 | int _Pragma ( "lacc \"..\\file.c\"" ) i = 42; 14 | 15 | INCLUDE ( ..\file.c ) 16 | 17 | int main(void) { 18 | return i; 19 | } 20 | -------------------------------------------------------------------------------- /test/test-lacc/c99/__func__.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | const char *s; 4 | 5 | int foo(void) { 6 | s = __func__; 7 | return printf("%lu\n", sizeof(__func__)); 8 | } 9 | 10 | int main(void) { 11 | const char *t = __func__; 12 | foo(); 13 | return printf("%s, %s\n", t, s); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/c99/array-param-qualifier.c: -------------------------------------------------------------------------------- 1 | 2 | int foo(int a[restrict], int b[const], int c[restrict const]) { 3 | return *a + *b + *c; 4 | } 5 | 6 | int main(void) { 7 | int arr[] = {1, 2, 3}; 8 | return foo(arr, arr + 1, arr + 2); 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/c99/array-qualifier-static.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int foo(int a[static const 1][2]) { 4 | int bar(int b[restrict volatile static 2]); 5 | return bar(a[0]); 6 | } 7 | 8 | int bar(int * volatile a) { 9 | return printf("[%d, %d]\n", a[0], a[1]); 10 | } 11 | 12 | static int arr[][2] = { 13 | {1, 2}, 14 | {3, 4}, 15 | {5, 6} 16 | }; 17 | 18 | int main(void) { 19 | return foo(arr); 20 | } 21 | -------------------------------------------------------------------------------- /test/test-lacc/c99/flexible-array-arg.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct flex { 4 | int a; 5 | char b; 6 | char s[]; 7 | } foo = {1}; 8 | 9 | struct flex ret(void) { 10 | struct flex p = {3, 2}; 11 | return p; 12 | } 13 | 14 | int arg(struct flex p) { 15 | return printf("%d, %d\n", p.a, p.b); 16 | } 17 | 18 | int main(void) { 19 | struct flex p = ret(); 20 | return arg(p) + arg(foo); 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/c99/flexible-array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct S1 { 6 | int n; 7 | double d[]; 8 | }; 9 | 10 | struct S1 *alloc(int n) { 11 | struct S1 *p = malloc(sizeof(struct S1) + sizeof(double) * n); 12 | p->n = n; 13 | return p; 14 | } 15 | 16 | int main(void) { 17 | struct S1 *s = alloc(3); 18 | 19 | s->d[0] = 41.4; 20 | s->d[1] = 3.14; 21 | s->d[2] = 2.71; 22 | 23 | return printf("%lu, %ld, (%f, %f, %f)\n", 24 | sizeof(struct S1), 25 | offsetof(struct S1, d), 26 | s->d[0], s->d[1], (*s).d[2]); 27 | } 28 | -------------------------------------------------------------------------------- /test/test-lacc/c99/flexible-union.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | union U1 { 4 | struct { 5 | char c; 6 | char s[]; 7 | } foo; 8 | int a; 9 | }; 10 | 11 | union U2 { 12 | int b; 13 | union U1 bar; 14 | }; 15 | 16 | union U1 test(void) { 17 | union U1 p = {3}; 18 | p.foo.s[0] = 1; 19 | p.foo.s[1] = 2; 20 | p.foo.s[2] = 3; 21 | return p; 22 | } 23 | 24 | int main(void) { 25 | union U1 p = test(); 26 | union U2 q = {0}; 27 | 28 | q.bar = p; 29 | return printf("%lu, %lu (%d, %d, %d)\n", 30 | sizeof(union U1), 31 | sizeof(union U2), 32 | q.bar.foo.s[0], q.bar.foo.s[1], q.bar.foo.s[2]); 33 | } 34 | -------------------------------------------------------------------------------- /test/test-lacc/c99/for-declaration.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | static int i = 42; 4 | 5 | int main(void) { 6 | typedef char T; 7 | T c = 'a'; 8 | printf("i = %d\n", i); 9 | for (volatile int i = 0, *j; i < 5; ++i) 10 | printf("%d ", i); 11 | 12 | for (T c;;) { 13 | c = 'b'; 14 | break; 15 | } 16 | 17 | printf("c = %d\n", c); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /test/test-lacc/c99/initialize-compound.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | static int test1(void) { 4 | int a[] = {5, (int){2}}; 5 | return printf("%d, %d\n", a[0], a[1]); 6 | } 7 | 8 | static int test2(float x) { 9 | struct S { 10 | char c; 11 | float fs[3]; 12 | } s1 = (struct S) { 'a', .fs[0] = (float) { 1.4f } }; 13 | 14 | return printf("%c, {%f, %f, %f}\n", s1.c, s1.fs[0], s1.fs[1], s1.fs[2]); 15 | } 16 | 17 | int main(void) { 18 | test1(); 19 | test2(3.14f); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/c99/inline-address.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | static inline int foo(int a) { 4 | return puts("Hello"); 5 | } 6 | 7 | static inline int bar(void) { 8 | foo(42); 9 | } 10 | 11 | /* Declaring a pointer has same effect as calling, now inlines are defined. */ 12 | int (*f)(void) = &bar; 13 | 14 | static inline int baz(int a) { 15 | return a + 1; 16 | } 17 | 18 | int main(void) { 19 | f(); 20 | return baz(2); 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/c99/inline-declare.c: -------------------------------------------------------------------------------- 1 | static inline int bar(int); 2 | 3 | int foo(void) { 4 | return bar(42); 5 | } 6 | 7 | static inline int bar(int n) { 8 | return n + 1; 9 | } 10 | 11 | int main(void) { 12 | return foo(); 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/c99/line-comment.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | // Hello! 4 | // */ 5 | 6 | char *str = "a\"/*b"; 7 | char c = '"'; 8 | 9 | //\ 10 | foo(); 11 | 12 | /\ 13 | / bar(); 14 | 15 | int foo(int a, int b) { 16 | // 17 | int f = a/**//b; 18 | int g = a//**/o 19 | + b; 20 | return printf("%d, %d, %s, %s, %d\n", f, g, "w // t", str, c); 21 | } 22 | 23 | int main(void) {// \ to\do 24 | return /*//*/ foo(__LINE__ * 2, 2);; 25 | } 26 | -------------------------------------------------------------------------------- /test/test-lacc/c99/restrict.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | #ifdef restrict 4 | # error This is wrong 5 | #endif 6 | 7 | static int * restrict restrict restricted; 8 | 9 | int bar(int *restrict * const restrict p) { 10 | return **p; 11 | } 12 | 13 | int foo(int * restrict p) { 14 | return *p; 15 | } 16 | 17 | int main(void) { 18 | auto int n = 42; 19 | return foo(&n); 20 | } 21 | -------------------------------------------------------------------------------- /test/test-lacc/c99/va_copy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int printf(const char *, ...); 4 | 5 | static int foo(int n, ...) { 6 | int i; 7 | va_list args, copy; 8 | 9 | va_start(args, n); 10 | printf("%d\n", va_arg(args, int)); 11 | va_copy(copy, args); 12 | for (i = 0; i < n - 1; ++i) { 13 | printf("%d\n", va_arg(copy, int)); 14 | } 15 | 16 | printf("%d\n", va_arg(args, int)); 17 | va_end(args); 18 | va_end(copy); 19 | return i; 20 | } 21 | 22 | int main(void) { 23 | return foo(2, 1, 4) 24 | + foo(3, 9, 8, 6) 25 | + foo(8, 4, 5, 2, 89, 0, 71, 99, 4); 26 | } 27 | -------------------------------------------------------------------------------- /test/test-lacc/c99/variadic-macro.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Example adapted from C11 standard specification. */ 4 | #define debug(...) printf(__VA_ARGS__) 5 | #define showlist(...) puts(#__VA_ARGS__) 6 | #define report(test, ...) ((test)?puts(#test): printf(__VA_ARGS__)) 7 | 8 | int test(int x, int y) { 9 | debug("Hello World!"); 10 | debug("X = %d\n", x); 11 | showlist(The first, second, and third items.); 12 | return report(x>y, "x is %d but y is %d", x, y); 13 | } 14 | 15 | int main(void) { 16 | return test(4, 5) + test(3, 0); 17 | } 18 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla-arg.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int foo(int n, int a[][n + 1][n]) { 4 | int b = a[0][0][0]; 5 | int c = a[0][n][n - 1]; 6 | return printf("%d, %d, %lu, %lu\n", b, c, sizeof(a[0]), sizeof(a[1][n - 1])); 7 | } 8 | 9 | int main(void) { 10 | int n = 13; 11 | int a[2][n][n - 1]; 12 | 13 | a[0][0][0] = 42; 14 | a[0][n - 1][n - 2] = 33; 15 | 16 | return foo(n - 1, a); 17 | } 18 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla-block-declaration.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int bar(int n) { 4 | int a[1][n]; 5 | int i = 0, foo(int n, int (*a)[n]); 6 | 7 | for (i = 0; i < n; ++i) { 8 | a[0][i] = i + 1; 9 | } 10 | 11 | return foo(n, a); 12 | } 13 | 14 | int foo(int n, int a[][n]) { 15 | while (n--) { 16 | printf("(*a)[%d] = %d\n", n, a[0][n]); 17 | } 18 | 19 | return sizeof(*a); 20 | } 21 | 22 | int main(void) { 23 | return bar(16); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla-compatibility.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int *foo(int n) { 4 | int (*a)[n]; 5 | int (* volatile b)[n + 1]; 6 | static int k[] = {1, 2, 3}; 7 | 8 | a = &k; 9 | b = a; 10 | return *a; 11 | } 12 | 13 | int main(void) { 14 | return printf("%d, %d\n", *foo(3), foo(5)[2]); 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla-matrix.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | void print(int n, int m, int arr[n][m]) { 4 | int i, j; 5 | for (i = 0; i < n; ++i) { 6 | for (j = 0; j < m; ++j) { 7 | printf("[%d][%d] = %d\n", i, j, arr[i][j]); 8 | } 9 | } 10 | 11 | printf("%lu, %lu\n", sizeof(arr[0]), sizeof(*arr)); 12 | } 13 | 14 | void matrix(int n, int m) { 15 | int i, arr[n][m]; 16 | for (i = 0; i < n * m; ++i) { 17 | arr[i / m][i % m] = i; 18 | } 19 | 20 | print(n, m, arr); 21 | } 22 | 23 | int main(void) { 24 | matrix(2, 3); 25 | matrix(31, 87); 26 | matrix(17, 1); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla-old-param.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | #define N 42 4 | 5 | int foo(n, a) 6 | int n; 7 | int a[][n]; 8 | { 9 | int i; 10 | for (i = 0; i < n; ++i) 11 | printf("%d: %d\n", i, a[0][i]); 12 | return n; 13 | } 14 | 15 | int main(void) { 16 | int a[2][N] = {0}, i; 17 | for (i = 0; i < N; ++i) 18 | a[0][i] = i + 1; 19 | return printf("%d\n", foo(N, a)); 20 | } 21 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla-sizeof.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | int n = 42, m = 13; 5 | return printf("%lu, %lu, %lu, %lu\n", 6 | sizeof(long double [n + m]), 7 | sizeof(float *[n]), 8 | sizeof(long [n][m]), 9 | sizeof(int [n > 10 ? m + 1 : n])); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla-static-pointer.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int B[] = {1, 2, 3, 4, 5, 6}; 4 | 5 | int foo(int n) { 6 | int i; 7 | static int (*p)[n] = &B; 8 | for (i = 0; i < n; ++i) { 9 | (*p)[i] = n + i; 10 | } 11 | return n; 12 | } 13 | 14 | int main(void) { 15 | int i; 16 | foo(4); 17 | for (i = 0; i < sizeof(B) / sizeof(int); ++i) { 18 | printf("%d\n", B[i]); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla-ternary-length.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int foo(int n, float a[][n % 2 ? 5 : 6][n - 2]) { 4 | return printf("(%lu, %lu, %f, %f)\n", 5 | sizeof(a[0]), 6 | sizeof(a[n - 1][n + 1]), 7 | a[0][0][1], 8 | a[0][0][4]); 9 | } 10 | 11 | int main(void) { 12 | float p[][2][7] = {3.14, 3.1, 5.1, 7.24, 6.12, 8.12, 9.13}; 13 | return foo(6, p) + foo(7, p); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/c99/vla.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | void print(unsigned n, int arr[n]) { 4 | int i; 5 | for (i = 0; i < n; ++i) { 6 | printf("%d\n", arr[i]); 7 | } 8 | } 9 | 10 | int foo(unsigned short n) { 11 | int i, a[n]; 12 | int b[n]; 13 | 14 | for (i = 0; i < n; ++i) { 15 | a[i] = i; 16 | b[i] = a[i] - i; 17 | } 18 | 19 | print(n, a); 20 | print(n, b); 21 | 22 | for (i = 0; i < n; ++i) { 23 | a[i] = a[i] + b[i]; 24 | } 25 | 26 | print(n, a); 27 | return printf("%lu\n", sizeof(a)); 28 | } 29 | 30 | int main(void) { 31 | return foo(8); 32 | } 33 | -------------------------------------------------------------------------------- /test/test-lacc/cast-float-union.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | union { 4 | long long i; 5 | float f; 6 | } wat; 7 | 8 | int main(void) { 9 | wat.i = 0x7FFFEFFEEF; 10 | wat.f = (float) wat.i; 11 | return printf("%f\n", wat.f); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/cast-float.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | float f1 = 3.14f, f2; 3 | 4 | f2 = (double) f1 - 2; 5 | 6 | return f2; 7 | } 8 | -------------------------------------------------------------------------------- /test/test-lacc/cast-function-args.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int foo(unsigned long long a, unsigned char b, float f, double d) { 4 | return printf("%llu, %u, %f, %f\n", a, b, f, d); 5 | } 6 | 7 | int main(void) { 8 | int i = -3; 9 | float f = 3.14f; 10 | double d = 2.71; 11 | return foo(i, i, d, f); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/cast-immediate-truncate.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | long g = 0xE52DL; 4 | 5 | int main(void) { 6 | int k = (-(unsigned)(2UL)) % g; 7 | unsigned j = (unsigned char) (-2ul); 8 | int i = (char) (-2458658ul); 9 | return printf("%d, %u, %d\n", k, j, i); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/cast.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | char arr[] = {1, 2, 3, 4}; 3 | char *ptr = (char *) arr; 4 | 5 | return (int) *ptr; 6 | } 7 | -------------------------------------------------------------------------------- /test/test-lacc/comma-side-effects.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int f; 4 | int *g = &f, *h = &f; 5 | char i; 6 | 7 | void fn3(void) { 8 | *g |= 0x1B0231B7L; 9 | } 10 | 11 | int main(void) { 12 | *h = 4L; 13 | (fn3(), i); 14 | 15 | return printf("%d, %d\n", *g, *h); 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/comment.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | /* Hello! 4 | // */ 5 | 6 | char *str = "a\"/*b\"\\\\"; 7 | char c = '"', d = '\''; 8 | 9 | /*\ 10 | foo(); 11 | */ 12 | /\ 13 | * bar(); *\ 14 | / 15 | 16 | int foo/* */(int/**/a, int b) { 17 | int f = a/*\*//b; 18 | int g = a/ /**/b; 19 | return printf("%d, %d, %s, %s, %d, %d\n", f, g, "w ??=*/ /*t?\ 20 | ??", str, c, d); 21 | } 22 | 23 | int main(void) { 24 | return /*//*/ foo(__LINE__ * 2, 2);; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /test/test-lacc/compare.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int arr[] = {1, 2, 3}; 4 | 5 | void *p = &arr[0]; 6 | void *q = &arr[1]; 7 | const int *r = &arr[2]; 8 | 9 | int main(void) { 10 | return printf("%d, %d, %d, %d\n", p < q, p > q, p == r, r != q); 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/compound-assignment-basic.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 1, b = 2, c = 3, d = 4, e = 5; 3 | int f = 0x03, g = 0x03, h = 0x07; 4 | 5 | a += b; 6 | c -= c += d; 7 | e *= 2; 8 | e /= 5; 9 | d %= a - 1; 10 | f &= 0x11; 11 | g |= 0x11; 12 | h ^= 0x11; 13 | 14 | return a + b + c + d + e + f + g + h; 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/conditional-basic.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int a = 1; 4 | int b = 2; 5 | 6 | int c = (a + 1) ? (b - 2) ? b-- : b++ : 42; 7 | int d = 0 ? 1 : 2; 8 | return c + a + b + d; 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/conditional-constant.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a, b = 42; 3 | a = (1) ? (b+1) & ~1 : b; 4 | b = (0) ? (b+1) & ~1 : b; 5 | return a + b; 6 | } 7 | -------------------------------------------------------------------------------- /test/test-lacc/conditional-void.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | void speak(const char *str) { 4 | puts(str); 5 | } 6 | 7 | int main(void) { 8 | int i = 42; 9 | (i) ? speak("Hello") : speak("World"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/constant-address-index.c: -------------------------------------------------------------------------------- 1 | static void 2 | *p = (void*) &((char*)50)[2], 3 | *q = (void*) &((char*)50)[-2]; 4 | 5 | int main(void) { 6 | unsigned long v = (unsigned long) p + (unsigned long) q; 7 | return v; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/constant-expression.c: -------------------------------------------------------------------------------- 1 | #define isbit(b) ((b) < 8 ? ((1 << (b)) << 8) : ((1 << (b)) >> 8)) 2 | 3 | static int a = (2 >= 5); 4 | 5 | enum wat { 6 | CAT = isbit(1) 7 | }; 8 | 9 | int main(void) { 10 | return a + CAT; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/constant-integer-type.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | return printf("%llu, %lld, %lld, %u, %lld\n", 5 | 0xF2C889DD98AE1F63, 6 | 0xFFD2086BDu, 7 | 0xFFD2086BD, 8 | 0xFFFFFFFF, 9 | 4294967295); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/convert-assign-immediate.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | int x; 5 | x = 2.2f; 6 | return printf("%d\n", x); 7 | } 8 | -------------------------------------------------------------------------------- /test/test-lacc/convert-float-double.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | float f = 3.14; 3 | double d = 2.71f; 4 | 5 | d = f; 6 | 7 | return d; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/convert-float-int.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | float f1 = 5312.4f, f2 = -12312.14f; 5 | double d1 = 431235311.92340; 6 | 7 | char c = f2; 8 | unsigned char u = f2; 9 | short s = d1; 10 | int i = f1; 11 | long l = d1; 12 | 13 | return printf("c = %d, u = %u, s = %d, i = %d, l = %ld\n", c, u, s, i, l); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/convert-int-float.c: -------------------------------------------------------------------------------- 1 | int cvtfloat(void) { 2 | float f; 3 | unsigned char c = 0xff; 4 | f = c; 5 | return f; 6 | } 7 | 8 | int cvtdouble(void) { 9 | double d; 10 | d = 32; 11 | return d; 12 | } 13 | 14 | int main(void) { 15 | return cvtfloat() - cvtdouble(); 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/convert-unsigned-float.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | unsigned char a = 0xF1u, b = 0x89; 4 | unsigned c = 0xC2E0CF57u, d = 0x678; 5 | unsigned long long e = 0xC2E0CF57C2E0CF57UL, f = 0x456789L; 6 | 7 | int main(void) { 8 | float f1 = a, f2 = b, f3 = c, f4 = d, f5 = e, f6 = f; 9 | double d1 = a, d2 = b, d3 = c, d4 = d, d5 = e, d6 = f; 10 | 11 | return printf("(%f, %f, %f, %f, %f, %f), (%f, %f, %f, %f, %f, %f)\n", 12 | f1, f2, f3, f4, f5, f6, d1, d2, d3, d4, d5, d6); 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/copy-struct.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | long x, y; 3 | }; 4 | 5 | struct point p; 6 | 7 | int main() { 8 | struct point q = {1, 2}; 9 | 10 | p = q; 11 | return p.y; 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/declaration-default-int.c: -------------------------------------------------------------------------------- 1 | static baz = 42; 2 | 3 | bar(a, b) { 4 | return a + b + baz; 5 | } 6 | 7 | static foo(a, b) 8 | long b; 9 | { 10 | auto c = a + b; 11 | return bar(c, a * a); 12 | } 13 | 14 | main() { 15 | register m; 16 | m = foo(2, 3); 17 | return m; 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/declarator-complex.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | static char *str; 4 | 5 | static void func(void) { 6 | puts(str); 7 | } 8 | 9 | static void (*getfunc(char *s))(void) { 10 | str = s; 11 | return func; 12 | } 13 | 14 | int arr[] = {1, 2}; 15 | 16 | int bar(void) { 17 | int *(a[2]); 18 | 19 | a[0] = &arr[0]; 20 | a[1] = &arr[1]; 21 | return *a[0] + *a[1]; 22 | } 23 | 24 | int main(void) { 25 | void (*foo)(void) = getfunc("Hello World!"); 26 | foo(); 27 | return bar(); 28 | } 29 | -------------------------------------------------------------------------------- /test/test-lacc/declarator-parens.c: -------------------------------------------------------------------------------- 1 | static int ((foo))(int wat) { 2 | return wat; 3 | } 4 | 5 | int main(void) { 6 | return foo(42); 7 | } 8 | -------------------------------------------------------------------------------- /test/test-lacc/declare-auto-func.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a = 42, foo(int a), b = 2; 3 | return foo(a + b); 4 | } 5 | 6 | int bar(void) { 7 | int foo(int b); 8 | return foo(4); 9 | } 10 | 11 | int foo(int n) { 12 | int baz(int); 13 | return baz(n); 14 | } 15 | 16 | int baz(int a) { 17 | return a + a; 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/deref-address-offset.c: -------------------------------------------------------------------------------- 1 | struct { 2 | int x, y; 3 | } wat = {1, 2}; 4 | 5 | int main(void) { 6 | int p = *(&wat.y); 7 | return p; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/deref-array.c: -------------------------------------------------------------------------------- 1 | char foo[] = "Foo"; 2 | char *bar = "Bar"; 3 | 4 | int main() { 5 | char c = *foo; 6 | char d = *bar; 7 | 8 | return c + d; 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/deref-compare-float.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int g; 4 | int *i = &g; 5 | float j; 6 | 7 | int main(void) { 8 | (*i) = 0xCFBCE008LL; 9 | j = (0x0p1 > (*i)); 10 | return printf("%d, %f\n", *i, j); 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/deref-deep.c: -------------------------------------------------------------------------------- 1 | struct typetree { 2 | int type; 3 | struct typetree *next; 4 | }; 5 | 6 | struct var { 7 | struct typetree *type; 8 | }; 9 | 10 | int main() { 11 | struct typetree p = {1}; 12 | struct typetree q = {3}; 13 | struct var root; 14 | 15 | p.next = &q; 16 | root.type = &p; 17 | 18 | return root.type->next->type; 19 | } 20 | -------------------------------------------------------------------------------- /test/test-lacc/deref-store.c: -------------------------------------------------------------------------------- 1 | char *name; 2 | 3 | int main() { 4 | char text[] = "ab"; 5 | name = text; 6 | 7 | *name = '4'; 8 | 9 | return name[0]; 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/deref.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | int x, y; 3 | }; 4 | 5 | struct object { 6 | int ival; 7 | char cval; 8 | struct point *pt; 9 | }; 10 | 11 | int main() { 12 | struct point pt = {4, 5}; 13 | struct object obj = {1, 'a'}; 14 | 15 | obj.pt = &pt; 16 | obj.pt->x = 3; 17 | obj.pt->y = 4; 18 | 19 | return pt.x + pt.y; 20 | } 21 | -------------------------------------------------------------------------------- /test/test-lacc/dereference-extern.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | char *text; 3 | }; 4 | 5 | struct s *var; 6 | 7 | int main() { 8 | struct s foo = {"Hello"}; 9 | var = &foo; 10 | return var->text[0]; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/directive-number.c: -------------------------------------------------------------------------------- 1 | #if 'A' == '\301' 2 | #error Wrong 3 | #endif 4 | 5 | int main(void) { 6 | return '\301'; 7 | } 8 | -------------------------------------------------------------------------------- /test/test-lacc/do-continue.c: -------------------------------------------------------------------------------- 1 | int printf(const char *s, ...); 2 | 3 | int main(void) { 4 | int i = 10; 5 | 6 | do { 7 | if (i % 3 == 0) 8 | continue; 9 | if (i == 2) 10 | break; 11 | printf("%d\n", i); 12 | } while (i--); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/do-while.c: -------------------------------------------------------------------------------- 1 | static int foo(int n) { 2 | int i = 0; 3 | 4 | if (n > 0) 5 | do { 6 | i++; 7 | } while (i < n); 8 | else 9 | i = 42; 10 | return i; 11 | } 12 | 13 | int main(void) { 14 | return foo(0) + foo(1) + foo(13); 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/enum.c: -------------------------------------------------------------------------------- 1 | enum token { 2 | FOO, 3 | BAR = 23, 4 | BAZ = BAR + 4 5 | }; 6 | 7 | int foo(enum token tok) 8 | { 9 | return tok; 10 | } 11 | 12 | int main() { 13 | enum BOOL { TRUE, FALSE } truth = FALSE; 14 | enum token { FOO = 1 } shadow = 0; 15 | enum token t = FOO; 16 | int a; 17 | 18 | t = 3 + truth; 19 | a = t; 20 | 21 | return BAZ - a; 22 | } 23 | -------------------------------------------------------------------------------- /test/test-lacc/exit.c: -------------------------------------------------------------------------------- 1 | void exit(int status); 2 | 3 | int main() { 4 | int i = 2; 5 | switch (i) { 6 | case 1: 7 | return 1; 8 | case 2: 9 | return 2; 10 | default: 11 | exit(3); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/expression-div-mod.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 3, b = 2; 3 | long c = 6; 4 | 5 | int d = a / b; 6 | int e = a % b; 7 | int f = a / c; 8 | 9 | return d + e + f; 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/expression.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | int a = -1; 5 | int b = 2; 6 | 7 | int c = a == b == 2; 8 | int d = c < 2 > c >= 1; 9 | int e = d && c || 1; 10 | int f = (1, 2); 11 | 12 | int g[2]; 13 | 14 | c = !c + +a != -7; 15 | (g)[b - 1] = 1; 16 | 17 | printf("%lu\n", sizeof(+(char) a)); 18 | 19 | return - -c + d + e + f; 20 | } 21 | -------------------------------------------------------------------------------- /test/test-lacc/fact.c: -------------------------------------------------------------------------------- 1 | 2 | int fact(int n) 3 | { 4 | if (n) 5 | return n * fact(n - 1); 6 | return 1; 7 | } 8 | 9 | int main() 10 | { 11 | return fact(5); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/float-arithmetic.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | float f1 = 3.14f, f2, f3; 5 | double d1 = 2.71, d2, d3; 6 | 7 | f2 = f1 - (d1 - 4.2f); 8 | d2 = f2 + f1 + 3.63123; 9 | f3 = f2 / (d1 / 0.44f); 10 | d3 = d2 * f1 * 3.1; 11 | 12 | printf("f1 = %f, f2 = %f, f3 = %f\n", f1, f2, f3); 13 | printf("d1 = %f, d2 = %f, d3 = %f\n", d1, d2, d3); 14 | 15 | return f1 * d1; 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/float-branch.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | int i = 0; 5 | double d = 0.0; 6 | float f = 1.2f; 7 | 8 | if (d) { 9 | i = 42; 10 | } else if (f) { 11 | i = 32; 12 | } 13 | 14 | return i; 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/float-compare-equal.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int g = -4L, i = 0; 4 | float *f; 5 | 6 | void foo(int *p1) { 7 | f = (void *) p1; 8 | *f = (i == *f); 9 | } 10 | 11 | int main(void) { 12 | foo(&g); 13 | return printf("%d\n", g); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/float-compare.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | float f = 5.67f, g = 5.97f; 5 | double d = 3.87, p = 12.9; 6 | 7 | do { 8 | assert(f < g); 9 | assert(p > f); 10 | assert(f == f); 11 | assert(p >= d); 12 | } while (p < f); 13 | 14 | return p >= d; 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/float-function.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | float foo(double n) { 4 | return n * 2.0; 5 | } 6 | 7 | double bar(float n) { 8 | return n + foo((double) n); 9 | } 10 | 11 | int main(void) { 12 | return printf("r = %f\n", bar(3.14f)); 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/float-load-deref.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | int foo = 4; 5 | int *bar = &foo; 6 | float f = *bar; 7 | 8 | return printf("%f\n", f); 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/for-empty-expr.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | static int n = 10; 4 | 5 | int main(void) { 6 | int i = 1; 7 | for (; n;) { 8 | if (n == 7) { 9 | n--; 10 | continue; 11 | } 12 | if (n == 1) 13 | break; 14 | i += n--; 15 | } 16 | 17 | return printf("%d, %d\n", i, n); 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/for.c: -------------------------------------------------------------------------------- 1 | int main(int argc, char *argv[]) 2 | { 3 | int i, j; 4 | for (i = 1; i & 7; i = i + 1) { 5 | if (i & 2) 6 | continue; 7 | for (j = 1; j & 3; j = j + 1) { 8 | if ((j + i) ^ 3) 9 | break; 10 | } 11 | } 12 | return i + j; 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/function-char-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int foo(unsigned char c, char s) 4 | { 5 | return c + s + 1; 6 | } 7 | 8 | int main() { 9 | char c = -1; 10 | short s = -2; 11 | 12 | printf("%d\n", foo(c, s)); 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/function-implicit-declare.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | return bar(); 3 | } 4 | 5 | extern int bar(void); 6 | 7 | int bar(void) { 8 | return 42; 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/function-incomplete.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int foo(); 4 | 5 | int bar(void) { 6 | return foo() + 1; 7 | } 8 | 9 | int foo(char *n) { 10 | return 42; 11 | } 12 | 13 | int (*baz)() = &foo; 14 | 15 | int main(void) { 16 | int a = bar(); 17 | return printf("%d\n", a); 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/function-pointer-call.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | int (*foo)(const char *); 3 | 4 | int main(void) { 5 | int (*bar)(const char *); 6 | foo = puts; 7 | bar = puts; 8 | foo("Hello"); 9 | bar("How are you?"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/function.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | int noop(void); 4 | 5 | static int foo(char *list[5]) { 6 | puts(list[0]); 7 | puts(list[1]); 8 | return sizeof(list[6]); 9 | } 10 | 11 | int prints(int n, ...) { 12 | return n; 13 | } 14 | 15 | static int foo(char *list[]); 16 | 17 | char s1[] = "Hello"; 18 | char *s2 = "World"; 19 | 20 | int main() { 21 | int size = 0; 22 | char *words[2]; 23 | words[0] = s1; 24 | words[1] = s2; 25 | 26 | size = foo(words); 27 | size = size + sizeof(words); 28 | size = size + prints(2, "hei", "hoi"); 29 | 30 | return size; 31 | } 32 | -------------------------------------------------------------------------------- /test/test-lacc/gnu/alloca.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static int foo(int n, const char *str) { 6 | char *data = alloca(n); 7 | memcpy(data, str, n); 8 | 9 | return printf("%s\n", data); 10 | } 11 | 12 | static const char hello[] = "Hello world!"; 13 | 14 | int main(void) { 15 | return foo(sizeof(hello), hello); 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/gnu/assign-constant-float.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int h; 4 | float g; 5 | 6 | int main(void) { 7 | h = (g = 0x7B5p46); 8 | return printf("%d\n", h); 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/gnu/large-objects.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int printf(const char *, ...); 5 | 6 | #define SIZE (1UL << 61) 7 | 8 | struct S { 9 | short buf[SIZE]; 10 | int a; 11 | int b; 12 | }; 13 | 14 | union U { 15 | int a; 16 | char buf[SIZE]; 17 | }; 18 | 19 | int main(void) { 20 | printf("sizeof: (%lu, %lu)\n", sizeof(struct S), sizeof(union U)); 21 | printf("offset: (%lu, %lu)\n", 22 | offsetof(struct S, a), 23 | offsetof(struct S, b)); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /test/test-lacc/gnu/long-double-convert.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int tofloat(long double ld) { 4 | float a = ld; 5 | double b = ld; 6 | return printf("%f, %f\n", a, b); 7 | } 8 | 9 | int toint(long double ld) { 10 | char a = ld; 11 | unsigned char b = ld; 12 | int c = ld; 13 | unsigned int d = ld; 14 | long e = ld; 15 | unsigned long f = ld; 16 | return printf("%d, %d, %d, %u, %ld, %lu\n", a, b, c, d, e, f); 17 | } 18 | 19 | int main(void) { 20 | long double d = 3.14, e = 145260912182745.12486L, f = -972316.70L; 21 | return toint(d) + toint(e) + toint(f) 22 | + tofloat(d) + tofloat(e) + tofloat(f); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-lacc/goto.c: -------------------------------------------------------------------------------- 1 | 2 | int foo(int n) { 3 | int i; 4 | 5 | for (i = 0; i < 5; ++i) { 6 | if (i == n) 7 | goto error; 8 | } 9 | 10 | if (i == 1) 11 | quit: 12 | error: 13 | abort(); 14 | 15 | while (i == 0) 16 | regret: abort(); 17 | 18 | return 0; 19 | } 20 | 21 | int main(void) { 22 | int i = 0; 23 | 24 | start: 25 | while (i < 100) { 26 | if (i == 42) goto end; 27 | i++; 28 | goto start; 29 | i++; 30 | } 31 | 32 | end: 33 | return i + foo(i); 34 | } 35 | -------------------------------------------------------------------------------- /test/test-lacc/header.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_H 2 | #define HEADER_H 3 | 4 | #ifndef FOO 5 | #define FOO 1 6 | #endif 7 | 8 | #undef FOO 9 | 10 | #if !defined(FOO) && !(2 * FOO + 1 != 1) 11 | #define FOO 0 12 | #endif 13 | 14 | #define _BAR 500 15 | 16 | #if _BAR < 500 17 | # define _BAZ 2 18 | #elif _BAR < 600 19 | # define _BAZ 3 20 | #elif _BAR < 700 21 | # define _BAZ 4 22 | #else 23 | # define _BAZ 5 24 | #endif 25 | 26 | #if _BAZ != 3 27 | # error Wrong! 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /test/test-lacc/hello.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | char hello[] = "Hello World!"; 4 | 5 | char *how = "How are you?"; 6 | 7 | long demo, ret = 42; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | puts(hello); 12 | puts(how); 13 | return ret; 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/identifier.c: -------------------------------------------------------------------------------- 1 | static int a; 2 | extern int c; 3 | 4 | int foo() { 5 | static int b; 6 | b = 1; 7 | return b; 8 | } 9 | 10 | int c; 11 | 12 | int main(void) { 13 | extern int a; 14 | static int b; 15 | { 16 | static int a = 2; 17 | b = a; 18 | } 19 | c = 1; 20 | return a + b + c + foo(); 21 | } 22 | 23 | 24 | int c; 25 | 26 | static int a = 3; 27 | 28 | extern int u; 29 | int u; 30 | 31 | int v; 32 | extern int v; 33 | 34 | static int w(void); 35 | int w(void); 36 | 37 | static int x(void); 38 | extern int x(void); 39 | -------------------------------------------------------------------------------- /test/test-lacc/immediate-branch.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a = 42, 3 | b = (!0xDD8FB8CEL) ? 7 : 14, 4 | c = (0xDD8FB8CEL || 0), 5 | d = (0xDD8FB8CEL && 1); 6 | if (1) { 7 | a = 4; 8 | } else { 9 | a = 14; 10 | } 11 | 12 | return a + b + c + d; 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/immediate-expr.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | int h = 0xC3F30B91L; 3 | 4 | int main(void) { 5 | int f = (0x47C1471CL > (0x7DL ^ h)); 6 | printf("%d\n", f); 7 | return printf("%d, %d, %d, %f, %f, %d\n", 8 | (0xF2C889DD98AE1F63LL >= 0xAD2086BDL), 9 | (0x000010001D2086BDLL == 0x1D2086BDL), 10 | (0xF2C889DD98AE1F63LL > 0xAD2086BDL), 11 | 8.5867834283 * 3.14f, 12 | 8.5867834283 / 3.14f, 13 | 3.14 == 3.14f); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/immediate-pointer.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct point { 4 | long x, y; 5 | } p; 6 | 7 | static long offset = (long) &((struct point *) 0x8)->y; 8 | 9 | int main(void) { 10 | int *ptr = &*((int *) 0x601044); 11 | return printf("%p, %ld\n", ptr, offset); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/include.c: -------------------------------------------------------------------------------- 1 | #define include do not include 2 | 3 | #define HEADER 4 | #define HELLO(str) #str 5 | 6 | #include HEADER 7 | 8 | static size_t something = 0; 9 | 10 | #include HELLO(hello.c) 11 | -------------------------------------------------------------------------------- /test/test-lacc/increment.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a = 1; 3 | int b = a++; 4 | int c = --b; 5 | ++a; 6 | --a; 7 | return a-- + b-- - ++c; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/initialize-address.c: -------------------------------------------------------------------------------- 1 | static int a = 42, *b = &a; 2 | 3 | int *foo[] = {&a, &a, (int *) &b}; 4 | int **bar[] = {&foo[1], foo + 2}; 5 | 6 | int main(void) { 7 | static int f = 3, *p = &f; 8 | 9 | return *b + *foo[1] + *p; 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/initialize-float.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | float f = 3.5f; 4 | double d = 42.3; 5 | 6 | struct { 7 | double x; 8 | float y, z; 9 | } p = {4.2f, 9.90}; 10 | 11 | int main(void) { 12 | static double q; 13 | return printf("%f, %f, (%f, %f, %f), %f\n", f, d, p.x, p.y, p.z, q); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/initialize-id.c: -------------------------------------------------------------------------------- 1 | int id(int x) { 2 | return x; 3 | } 4 | 5 | int main(void) { 6 | int x[] = {id(1), id(0)}; 7 | return x[1]; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/initialize-null.c: -------------------------------------------------------------------------------- 1 | #ifndef NULL 2 | #define NULL (void *) 0 3 | #endif 4 | 5 | char *str = NULL; 6 | 7 | int main(void) { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/initialize-union.c: -------------------------------------------------------------------------------- 1 | union value { 2 | char v; 3 | long l; 4 | struct { 5 | long x, y; 6 | } point; 7 | }; 8 | 9 | int main() { 10 | union value v = {1}; 11 | return v.point.x; 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/initialize.c: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int x; 3 | int y; 4 | char *name; 5 | char tag[3]; 6 | } point_t; 7 | 8 | char s[] = "Hello"; 9 | 10 | point_t p = {1, 2, "Hello", {'a', 'b', 'c'}}; 11 | 12 | char tull[] = {'t', 'u', 'l', 'l', '\0'}; 13 | 14 | static char chr; 15 | static char *str; 16 | static char **ptrs; 17 | 18 | int main() { 19 | point_t q = {1, 2, "Hello", {0, 'b', 'c'}}; 20 | 21 | char t[] = {'h', 'e', 'l', 0, 'o', '\0'}; 22 | 23 | int ch = (ptrs == 0) && (str == 0) && (chr == 0); 24 | 25 | return sizeof(p.name) + p.tag[1] + s[5] + t[0] + q.x + ch; 26 | } 27 | -------------------------------------------------------------------------------- /test/test-lacc/integer-suffix.c: -------------------------------------------------------------------------------- 1 | int printf(const char *str, ...); 2 | 3 | int main(void) { 4 | return printf("%lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu, %lu\n", 5 | sizeof(42), 6 | sizeof(42l), 7 | sizeof(42L), 8 | sizeof(42u), 9 | sizeof(42U), 10 | sizeof(42ul), 11 | sizeof(42uLL), 12 | sizeof(42ULL), 13 | sizeof(42llU), 14 | sizeof(42LLu), 15 | sizeof(42LLU)); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /test/test-lacc/ldouble-load-direct.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | float f = 3.14f; 4 | double g = 2.71; 5 | 6 | int main(void) { 7 | long double d = f; 8 | long double e = g; 9 | return printf("%Lf, %Lf\n", d, e); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/line-continuation.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | char foo[] = "a\\ 4 | \"; 5 | 6 | char c1 = '\ 7 | \ 8 | a\ 9 | '; 10 | 11 | char c2 = '\ 12 | \\\ 13 | '; 14 | 15 | /* Trigraph backslash */ 16 | char c3 = '??/ 17 | a??/ 18 | '; 19 | 20 | int main(void) { 21 | printf("%s", foo); 22 | printf("%c, %c, %c\n", c1, c2, c3); 23 | return sizeof(foo); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-lacc/line-directive.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | #line __LINE__ 4 | int i = __LINE__; 5 | char *s = __FILE__; 6 | # line 10 "bar.c" 7 | int j = __LINE__; 8 | 9 | int main(void) { 10 | return printf("%d, %d, %d, %s, %s\n", 11 | __LINE__, i, j, s, __FILE__); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/linebreak.c: -------------------------------------------------------------------------------- 1 | /\ 2 | * 3 | */ # /* 4 | *\ 5 | / defi\ 6 | ne FO\ 7 | O 1\ 8 | 2 9 | 10 | int main() { 11 | return FOO; 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/liveness-deref-assign.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int l; 4 | int wat[] = {3, 4, 5}; 5 | 6 | const int *g; 7 | const int **h = &g; 8 | 9 | int main(void) { 10 | int *p; 11 | p = &wat[1]; 12 | *h = (p = &l); 13 | *p = 1; 14 | 15 | return printf("%d\n", wat[1]); 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/liveness-global.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | float a = 42.42, b; 4 | int c = 1L; 5 | float *d = &b; 6 | 7 | void fn1(void) { 8 | *d = (a = c); 9 | } 10 | 11 | int main(void) { 12 | fn1(); 13 | return printf("%f\n", a); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/liveness-loop.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | float h, g = 1.1; 4 | int i = 2, j = 0; 5 | 6 | int main(void) { 7 | h = (g = i); 8 | for (; j < 5; j++) { } 9 | 10 | return printf("%f\n", g); 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/liveness-pointer.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int k; 4 | long g; 5 | long *l = &g; 6 | 7 | float h[] = {1.1f, 2.2f, 3.3f}; 8 | 9 | float *i = &h[1]; 10 | short j = 0; 11 | 12 | int main(void) { 13 | int n = 5L; 14 | k = (n = (j)); 15 | (*l) = (0x841EC489769724D4LL); 16 | (*i) = n; 17 | return printf("%f\n", h[1]); 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/logical-and-bitwise-false.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int a = 0x01, b = 0x02; 4 | 5 | return a && b; 6 | } 7 | -------------------------------------------------------------------------------- /test/test-lacc/logical-operators-basic.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int a = 2; 4 | int b = 1; 5 | 6 | int c = a++ || 1; 7 | int d = b-- && (b = 10) && b-- && 0; 8 | return a + b + c + d; 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/long-double-arithmetic.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int main(void) { 4 | double c1 = -15.3L; 5 | long double c2 = 22.5f; 6 | 7 | long double 8 | a = (long double) c1 + c2, 9 | b = c1 - c2, 10 | c = c1 * c2, 11 | d = c1 / c2; 12 | 13 | return printf("(%f, %Lf), %Lf, %Lf, %Lf, %Lf\n", c1, c2, a, b, c, d); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/long-double-compare.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | static int test(long double d) { 4 | int i, j; 5 | long double e = 3.14L, f = 0; 6 | 7 | i = d == 1.0L; 8 | j = d != e; 9 | 10 | if (d < 3) f += 1; 11 | if (d <= e) f += 2; 12 | if (d > e) f += 3L; 13 | if (d >= e) f += 4u; 14 | 15 | return printf("%Lf, %Lf, %Lf, %d, %d\n", d, e, f, i, j); 16 | } 17 | 18 | int main(void) { 19 | double a = -3.3; 20 | long double b = 22.5f; 21 | 22 | return test(a) + test(b) + test(1.0L) + test(3.14L); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-lacc/macro-empty-arg.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | #define FOO(a, b, c) (a) 4 | #define CONCAT(x, y, z) x z ## y + 1 5 | #define STR(i, j) #i "hello" #j "world" 6 | 7 | #define GLUE(a, b) a ## b 8 | #define JOIN(a, b, c) GLUE(a, b c) 9 | 10 | static int n = JOIN(1,,1); 11 | 12 | int main(void) { 13 | int a = CONCAT(2,,); 14 | int b = CONCAT(,2,); 15 | int c = FOO(0 + a, ,); 16 | return printf(STR(,c)) + printf("%d, %d, %d, %d\n", a, b, c, n); 17 | } 18 | -------------------------------------------------------------------------------- /test/test-lacc/macro-function-paren.c: -------------------------------------------------------------------------------- 1 | #define foo(s) s + 1 2 | 3 | int main(void) { 4 | int foo = 4; 5 | return foo(1) + foo; 6 | } 7 | -------------------------------------------------------------------------------- /test/test-lacc/macro-keyword-define.c: -------------------------------------------------------------------------------- 1 | #define double int 2 | 3 | #ifndef double 4 | #error no way 5 | #endif 6 | 7 | #if double + int != defined(int) 8 | #error this should be false 9 | #endif 10 | 11 | int main(void) { 12 | double d = 42; 13 | return sizeof(d); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/macro-name-arg.c: -------------------------------------------------------------------------------- 1 | #define ADD(a, b) a + b 2 | #define APPLY(func, a, b) func(a, b) 3 | #define N APPLY(ADD, 3, 5) 4 | 5 | int main(void) { 6 | return N; 7 | } 8 | -------------------------------------------------------------------------------- /test/test-lacc/macro-param-space.c: -------------------------------------------------------------------------------- 1 | #define declare(name) extern int name (int) 2 | 3 | declare(foo); 4 | 5 | int main(void) { 6 | return foo(2); 7 | } 8 | 9 | int foo(int n) { 10 | return n + 1; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/macro-paste.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | #define FOO(s) s ## _f ## u ## nc 4 | #define STR(s) #s 5 | #define CAT(a, b) STR(a ## b) 6 | 7 | int foo_func(void) { 8 | return puts(CAT(foo, 5)); 9 | } 10 | 11 | #define glue(a, b) a ## b 12 | #define cat(a, b) glue(a, b) 13 | #define HELLOWORLD "hello" 14 | #define WORLD WORLD ", world" 15 | 16 | int test(void) { 17 | return puts(glue(HELLO, WORLD)) + puts(cat(HELLO, WORLD)); 18 | } 19 | 20 | int main(void) { 21 | return FOO(foo)() + test(); 22 | } 23 | -------------------------------------------------------------------------------- /test/test-lacc/macro-predefined.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *date = __DATE__; 4 | char *time = __TIME__; 5 | 6 | int main(void) { 7 | return strlen(date) + strlen(time); 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/macro-recursive.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | static int foo; 4 | 5 | static int max(int a, int b) { 6 | return a + b; 7 | } 8 | 9 | #define SUM(a, b) (a + b) 10 | #define foo SUM(1, foo) 11 | 12 | #define max(x, y) SUM(x, max(1, y)) 13 | 14 | int main(void) { 15 | int b = foo; 16 | int c = max(1, foo); 17 | int d = max(1, max(2, foo)); 18 | int e = max( 19 | foo + 3, 20 | max(foo, 21 | foo - 2)) 22 | + foo; 23 | return printf("%d, %d, %d, %d\n", b, c, d, e); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-lacc/macro-refill-expand.c: -------------------------------------------------------------------------------- 1 | #define FOO PRINT 2 | #define PRINT(m) printf("%s\n", m) 3 | #define BAR printf("hello: "); PRINT 4 | 5 | int printf(const char *, ...); 6 | 7 | int main(void) 8 | { 9 | FOO( 10 | 11 | 12 | "hi" 13 | 14 | "ho" 15 | 16 | ); 17 | 18 | FOO("Hello"); 19 | #if 1 20 | BAR 21 | ( 22 | "to you"); 23 | #endif 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /test/test-lacc/macro-repeat-expand.c: -------------------------------------------------------------------------------- 1 | #define __STD_TYPE 2 | #define __UQUAD_TYPE unsigned long int 3 | #define __DEV_T_TYPE __UQUAD_TYPE 4 | 5 | __STD_TYPE __UQUAD_TYPE __dev_t; 6 | 7 | int main(void) { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/macro-skip-expand.c: -------------------------------------------------------------------------------- 1 | #ifdef FOO 2 | # if FOO(1, 2) 3 | # error This should not happen 4 | # elif FOO(2, 3) 5 | # error Not this either 6 | # endif 7 | #endif 8 | 9 | int printf(const char *, ...); 10 | 11 | int square(int x) { 12 | return x * x; 13 | } 14 | 15 | #define square(x) x 16 | 17 | int main(void) { 18 | return printf("square=%d, %d, %d\n", square(square)(2), square(square 19 | (square( 20 | square))) 21 | (2), 22 | square(2)); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-lacc/macro.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | int printf(const char *, ...); 3 | 4 | #define FOO(a, b) (a b - 1) 5 | 6 | #define BAR(x) __FILE__, *d = #x, e = x ; 7 | #define max(a, b) ((a) > (b) ? (a) : (b)) 8 | 9 | /* 10 | * Some comments to confuse line counting. 11 | */ 12 | 13 | int main(void) { 14 | int a = 42, b; /* Single line comment. */ 15 | char *c = BAR( 16 | __LINE__) 17 | 18 | printf("max=%d\n", max(max(2, -1), 1)); 19 | puts(c); 20 | puts(d); 21 | 22 | puts(__FILE__); 23 | #if (__STDC_VERSION__ >= 199901) 24 | puts(__func__); 25 | #endif 26 | b = __LINE__ + FOO ( 1 + a *, 2 ) + e; 27 | return printf("%d\n", b); 28 | } 29 | -------------------------------------------------------------------------------- /test/test-lacc/main.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int a; 3 | a = 42; 4 | return a; 5 | } 6 | -------------------------------------------------------------------------------- /test/test-lacc/negate.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | static int a = 2, b = 3, c = 4; 4 | 5 | int main(void) { 6 | int d = !(a == b); 7 | int e = !(c - 1 != b); 8 | int f = !(a > e); 9 | int g = !(f <= c); 10 | 11 | return printf("%d, %d, %d, %d\n", d, e, f, g); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/nested-macro.c: -------------------------------------------------------------------------------- 1 | #define foo(v) bar(v, a + 2) 2 | #define bar(v, i) v = 42 + i; 3 | 4 | int main() { 5 | int a = 1; 6 | foo(a); 7 | return a; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/offsetof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int printf(const char *, ...); 4 | 5 | struct point { 6 | int x; 7 | long y; 8 | }; 9 | 10 | int main(void) { 11 | return printf("%lu\n", offsetof(struct point, y)); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/old-param-decay.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | #define N 42 4 | 5 | int foo(n, a) 6 | int a[31][N]; 7 | int n; 8 | { 9 | return sizeof(a) + sizeof(a[14]) + n; 10 | } 11 | 12 | int main(void) { 13 | int a[2][N] = {0}; 14 | return printf("%d\n", foo(N, a)); 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/old-style-declaration.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int foo(int n, const char *str); 4 | 5 | int foo(n, str) 6 | int n; 7 | const char *str; 8 | { 9 | return printf("%d, %s\n", n, str); 10 | } 11 | 12 | int main(void) { 13 | return foo(42, "Hello World"); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/old-style-definition.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int max(a, b) 4 | register int a, b; 5 | { 6 | return (a > b) ? a : b; 7 | } 8 | 9 | int print(line, message) 10 | int line; 11 | const char *message; 12 | { 13 | return printf("(%d): %s\n", line, message); 14 | } 15 | 16 | int main(void) { 17 | return print(max(3, -5), "Hello world"); 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/padded-initialization.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static struct point { 4 | char c; 5 | int d; 6 | } obj = {'a', 0xaabbccdd}; 7 | static char sc; 8 | 9 | int main() { 10 | sc = 'a'; 11 | printf("%c\n%d\n%c\n", obj.c, obj.d, sc); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/params-mixed.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | char x; 3 | int y; 4 | void *next; 5 | }; 6 | 7 | struct mem { 8 | int arr[255]; 9 | }; 10 | 11 | int func(struct point p, struct mem m, long a, long b, long c, long d, int e) { 12 | p.x = 1; 13 | m.arr[0] = 1; 14 | return p.y + m.arr[0] + a + b + c + d + e; 15 | } 16 | 17 | int main () { 18 | struct point p = {1, 2, 0}; 19 | struct mem arr; 20 | return func(p, arr, 1, 2, 3, 4, 5); 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/params-system-v.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Example adapted from System V ABI, Figure 3.6. 3 | */ 4 | 5 | typedef struct { 6 | int a, b; 7 | } structparm; 8 | 9 | int func(int e, int f, structparm s, int g, int h, int i, int j, int k) 10 | { 11 | return e + f + s.a + s.b + g + h + i + j + k; 12 | } 13 | 14 | int main () { 15 | structparm s = {8, 9}; 16 | int e = 1, f = 2, g = 3, h = 4, i = 5, j = 6, k = 7; 17 | return func(e, f, s, g, h, i, j, k); 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/partial-initialization.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | char c; 3 | struct { 4 | int a, b; 5 | } inner; 6 | int x, y, z, w; 7 | }; 8 | 9 | int main() 10 | { 11 | int z[][2] = { 12 | { 1 }, { 2 }, { 3 }, { 4 } 13 | }; 14 | struct point p = { 'a', { 1 }, 2 }; 15 | return 16 | z[0][0] + z[0][1] + z[2][0] + 17 | p.c + p.inner.a + p.inner.b + p.x + p.w; 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/pointer-diff.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int diff(char **first, char **last) { 4 | return printf("%ld\n", last - first); 5 | } 6 | 7 | int main(void) { 8 | char *DataList[4]; 9 | return diff(DataList, DataList + 4); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/pointer-immediate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef float vec_t[3]; 5 | 6 | typedef struct { 7 | vec_t loc; 8 | } point_t; 9 | 10 | static int offsets[] = { 11 | (unsigned long)&((point_t*)0)->loc[0], 12 | (unsigned long)&((point_t*)0)->loc[2], 13 | (unsigned long)&((vec_t*)0)[1] 14 | }; 15 | 16 | int main(void) { 17 | int *a = (((int*) 0x10) - 2); 18 | int *b = (((int*) 0x10) + 2); 19 | 20 | assert(a == (int *) 0x08); 21 | assert(b == (int *) 0x18); 22 | 23 | return printf("%d, %d, %d\n", offsets[0], offsets[1], offsets[2]); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-lacc/preprocess-expression.c: -------------------------------------------------------------------------------- 1 | #define triple(a) (3 * (a)) 2 | #define FOO 2 3 | 4 | #if (FOO ? 0 : 1) 5 | # error wrong 6 | #endif 7 | #if BAR == 0 && defined FOO && triple(1) == 3 8 | 9 | int main() { 10 | return 1; 11 | } 12 | 13 | #elif triple(0) 14 | #error Not possible 15 | #endif 16 | 17 | #define T1 ((1 ? -1 : (0, 0u)) < 0) 18 | 19 | #if T1 20 | # error Should be false 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /test/test-lacc/preprocess.c: -------------------------------------------------------------------------------- 1 | #ifdef NO 2 | # error not supposed to happen 3 | #elif 0 4 | # error "not this either" 5 | # 6 | #else 7 | # include "header.h" 8 | # define triple(a) (3 * (a)) 9 | #endif 10 | 11 | #pragma 12 | 13 | #if 1 14 | # pragma = This should be ignored 15 | #endif 16 | 17 | # 18 | # 19 | # 20 | 21 | #define iscool() 1; 22 | # 23 | #include "header.h" 24 | 25 | int main() { 26 | return FOO + triple(3) + iscool ( ); 27 | } 28 | -------------------------------------------------------------------------------- /test/test-lacc/preprocessor-expression.c: -------------------------------------------------------------------------------- 1 | #define A 9223372036854775807L 2 | #define B 2147483647 3 | 4 | int a = 5 | #if (A >= B) 6 | 1 7 | #else 8 | 2 9 | #endif 10 | ; 11 | 12 | #if (0xFFFFFFFFFFFFFFFF <= 42) 13 | # error Unsigned compare failed! 14 | #endif 15 | 16 | int main(void) { 17 | return a; 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/printstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void 5 | printstr(FILE *stream, const char *str) 6 | { 7 | char c; 8 | 9 | while ((c = *str++) != '\0') { 10 | putc(c, stream); 11 | if (isprint(c) && c != '"' && c != '\\') 12 | putc(c, stream); 13 | else 14 | fprintf(stream, "\\x%x", (int) c); 15 | } 16 | } 17 | 18 | int main() { 19 | printstr(stdout, "heisann!\n"); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/promote-unsigned.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | unsigned int ui = 12; 3 | unsigned long ul = 34; 4 | 5 | return ui + ul; 6 | } 7 | -------------------------------------------------------------------------------- /test/test-lacc/prototype-scope-enum.c: -------------------------------------------------------------------------------- 1 | enum { 2 | FOO = 1, 3 | BAR = 2 4 | }; 5 | 6 | extern int foo(enum { FOO = 4, BAR = 5 } pp, int arr[][FOO]); 7 | 8 | int main(void) { 9 | return FOO; 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/ptrdiff.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | int x, y; 3 | } points[5]; 4 | 5 | char *str = "Hello world"; 6 | 7 | int main() { 8 | char *send = str + 8; 9 | struct point *pend = points + 3; 10 | 11 | unsigned long sdiff = send - str; 12 | unsigned long pdiff = pend - points; 13 | 14 | return sdiff + pdiff; 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/push-immediate.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | int foo(int a, int b, int c, int d, int e, int f, unsigned int g) { 4 | return printf("%d, %d, %d, %d, %d, %d, %u\n", a, b, c, d, e, f, g); 5 | } 6 | 7 | int main(void) { 8 | return foo(1, 2, 3, 4, 5, 6, 0xFF000000u); 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/qualifier-repeat.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | const const int a = 42; 4 | static volatile volatile int b; 5 | 6 | int main(void) { 7 | return a + b; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/register-param.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | static int foo(register char const *str, register int i) { 4 | char c = str[0]; 5 | return printf("%s, %d, %c\n", str, i, c); 6 | } 7 | 8 | int main(void) { 9 | int i = 42; 10 | return foo("Hello", i); 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/return-bitfield.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | union U3 { 4 | int f0; 5 | signed f1 : 8; 6 | } g = {0xB37CF3EAL}; 7 | 8 | int fn3(union U3 p1) { return p1.f1; } 9 | 10 | int main(void) { 11 | int i = fn3(g); 12 | return printf("%d\n", i); 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/return-compare-int.c: -------------------------------------------------------------------------------- 1 | int printf(char *, ...); 2 | 3 | static int g; 4 | 5 | long long fn8(void) { 6 | return 0x800000000; 7 | } 8 | 9 | short fn2(void) { 10 | return (short)0x70000; 11 | } 12 | 13 | char fn1(void) { 14 | return (char)0x600; 15 | } 16 | 17 | int main(void) { 18 | if (fn8()) { 19 | g += 8; 20 | } 21 | 22 | if (fn2()) { 23 | g += 2; 24 | } 25 | 26 | if (fn1()) { 27 | g += 1; 28 | } 29 | 30 | return printf("%d\n", g); 31 | } 32 | -------------------------------------------------------------------------------- /test/test-lacc/return-float-struct.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct s { 4 | float f; 5 | } wat = {3.14f}; 6 | 7 | struct s foo(void) { 8 | return wat; 9 | } 10 | 11 | int main(void) { 12 | struct s bar = foo(); 13 | return printf("%f\n", bar.f); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/return-partial-register.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct point { 4 | char a; 5 | char b; 6 | char c; 7 | }; 8 | 9 | struct point foo(int a) { 10 | struct point p = {0}; 11 | p.a = a; 12 | return p; 13 | } 14 | 15 | struct point bar(struct point p) { 16 | struct point q;; 17 | q.a = p.a; 18 | q.b = p.b; 19 | q.c = p.c; 20 | return q; 21 | } 22 | 23 | int main(void) { 24 | struct point 25 | p = foo(42), 26 | q = bar(p); 27 | return printf("(%d, %d, %d), (%d, %d, %d)\n", 28 | p.a, p.b, p.c, q.a, q.b, q.c); 29 | } 30 | -------------------------------------------------------------------------------- /test/test-lacc/return-point.c: -------------------------------------------------------------------------------- 1 | /* Takes up more than two eightbytes, thus must be returned by memory and not 2 | * registers. 3 | */ 4 | struct point { 5 | long x, y, z; 6 | } points[] = { 7 | {1, 2, 3}, 8 | {4, 5, 6} 9 | }; 10 | 11 | struct point getPoint(int i) { 12 | return points[i]; 13 | } 14 | 15 | int main() { 16 | struct point p = getPoint(1); 17 | return p.y; 18 | } 19 | -------------------------------------------------------------------------------- /test/test-lacc/return-struct-basic.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | int x, y; /* Both fit in %rax */ 3 | }; 4 | 5 | struct point func(void) 6 | { 7 | struct point p = {1, 2}; 8 | return p; 9 | } 10 | 11 | int main () { 12 | struct point p; 13 | 14 | p = func(); 15 | return p.x + p.y; 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/return-struct-integers.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | int x, y; /* %rax */ 3 | long l; /* %rdx */ 4 | }; 5 | 6 | struct point func(void) 7 | { 8 | struct point p = {1, 2, 3}; 9 | return p; 10 | } 11 | 12 | int main() { 13 | struct point p; 14 | 15 | p = func(); 16 | return p.x + p.y + p.l; 17 | } 18 | -------------------------------------------------------------------------------- /test/test-lacc/return-struct-mem.c: -------------------------------------------------------------------------------- 1 | /* Too large to fit in two registers, pass address of result object in %rdi. */ 2 | struct mem { 3 | int x, y; 4 | char c; 5 | long l; 6 | }; 7 | 8 | struct mem func(void) 9 | { 10 | struct mem p = {1, 2, 'a', 3}; 11 | return p; 12 | } 13 | 14 | int main() { 15 | struct mem p; 16 | 17 | p = func(); 18 | return p.x + p.y + p.c + p.l; 19 | } 20 | -------------------------------------------------------------------------------- /test/test-lacc/self-referential-struct.c: -------------------------------------------------------------------------------- 1 | struct node { 2 | int value; 3 | const struct node *next; 4 | }; 5 | 6 | int main() { 7 | struct node n; 8 | n.value = 42; 9 | n.next = &n; 10 | return n.next->value; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/shift-assign.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a = 5; 3 | int b = 0x10030; 4 | 5 | a <<= 1; 6 | b >>= a; 7 | return a + b; 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/short-circuit-comma.c: -------------------------------------------------------------------------------- 1 | int f = 1; 2 | 3 | int main(void) { 4 | 1 && (f++, 1); 5 | 0 || (f++, 1); 6 | return f; 7 | } 8 | -------------------------------------------------------------------------------- /test/test-lacc/short-circuit.c: -------------------------------------------------------------------------------- 1 | int foo(void) { 2 | int f = 2, g = 0; 3 | int h = (g < 7) ^ (1 || (f = 1)); 4 | int j = (g < 7) ^ (0 && (f = 1)); 5 | return f + h + j; 6 | } 7 | 8 | int bar(void) { 9 | int i = 1, j = 1; 10 | if (13L && i) { 11 | i = 4; 12 | } 13 | if (0 || j) { 14 | j = 7; 15 | } 16 | return i + j; 17 | } 18 | 19 | int baz() { 20 | int i = 1, j = 1; 21 | j = (0 || (j + 1)); 22 | return i + j; 23 | } 24 | 25 | int main(void) { 26 | char a = 1, b = 2; 27 | 28 | int t1 = (a == 0 && (b = 0)); 29 | int t2 = a || 1 || (b = 1); 30 | 31 | return b + foo() + bar() + baz(); 32 | } 33 | -------------------------------------------------------------------------------- /test/test-lacc/shortcircuit-loop.c: -------------------------------------------------------------------------------- 1 | int foo(void) { 2 | while (1) { 3 | return 1; 4 | } 5 | } 6 | 7 | int bar(void) { 8 | int i = 0; 9 | do { 10 | if (i++) 11 | return 1; 12 | } while (1); 13 | } 14 | 15 | int baz(void) { 16 | int i; 17 | for (i = 0; 1; i++) { 18 | return 3; 19 | } 20 | } 21 | 22 | int main() { 23 | if (1) 24 | return foo() + bar() + baz(); 25 | } 26 | -------------------------------------------------------------------------------- /test/test-lacc/signed-division.c: -------------------------------------------------------------------------------- 1 | int foo() { 2 | short k = (0xDFB2L); 3 | long i = (((0x5405EA32 / (k)))); 4 | return i; 5 | } 6 | 7 | long baz(void) { 8 | char s = 'a'; 9 | return s / 3L; 10 | } 11 | 12 | int main() { 13 | short k = (0xDFB2L); 14 | int i = (((0x5405EA32L / (k)))); 15 | return i + foo() + baz(); 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/sizeof.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | typedef struct Foo Bar; 4 | 5 | int main(void) { 6 | int bar[5]; 7 | long a = sizeof(volatile char) + sizeof(bar); 8 | long b = sizeof (a = a + 2); 9 | unsigned long c = sizeof(Bar *); 10 | unsigned long d = sizeof(int (*)(char)) + sizeof(struct {char a;}); 11 | 12 | printf("sizeof(sizeof(int)) = %lu\n", sizeof(sizeof(int))); 13 | printf("sizeof a = %lu", sizeof a); 14 | printf("a = %ld, b = %ld, c = %lu, d = %lu\n", a, b, c, d); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/test-lacc/string-addr.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | /* Note that *c is still incomplete after this assignment. */ 4 | char (*c)[] = &"Hello"; 5 | 6 | int main(void) 7 | { 8 | puts(*c); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/string-concat.c: -------------------------------------------------------------------------------- 1 | int puts(const char *s); 2 | 3 | char str[] = 4 | "Hel" \ 5 | "lo" 6 | " " 7 | "wo" "rld" "!"; 8 | 9 | int main(void) { 10 | puts(str); 11 | return sizeof(str); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/string-escape.c: -------------------------------------------------------------------------------- 1 | int puts(const char *s); 2 | 3 | const char str[] = "\tconst \af \but \vat \fak \x64 \\? \? \' \" ' \r\n"; 4 | 5 | int main(void) { 6 | puts(str); 7 | puts("\1412\142\145"); 8 | return sizeof(str); 9 | } 10 | -------------------------------------------------------------------------------- /test/test-lacc/string-index.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | char a = "Hello"[2]; 3 | char b = 2["World"]; 4 | return a + b; 5 | } 6 | -------------------------------------------------------------------------------- /test/test-lacc/string-length.c: -------------------------------------------------------------------------------- 1 | static const char str[] = 2 | "Hello\0" " world," 3 | "\0 this is dog!"; 4 | 5 | int main(void) { 6 | return sizeof(str) + sizeof(""); 7 | } 8 | -------------------------------------------------------------------------------- /test/test-lacc/strings.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | char hello[] = "Hello World!"; 4 | 5 | char *how = ("How are you?" - 1) + 3; 6 | 7 | char *foo(void) 8 | { 9 | return "From foo with love"; 10 | } 11 | 12 | int main(void) 13 | { 14 | char arr[] = "How are you?"; 15 | char *offst = "How are you?" + 5; 16 | puts(hello); 17 | puts(how); 18 | puts(arr); 19 | puts(foo()); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/struct-alignment.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | long a, b; 3 | short d; 4 | int c; 5 | char e; 6 | }; 7 | 8 | struct foo { 9 | struct point point; 10 | char c[7]; 11 | union { 12 | char c; 13 | void *p; 14 | struct { 15 | int i; 16 | } s; 17 | } val; 18 | }; 19 | 20 | int main() { 21 | return sizeof(struct foo); 22 | } 23 | -------------------------------------------------------------------------------- /test/test-lacc/struct-assign.c: -------------------------------------------------------------------------------- 1 | struct { 2 | short s; 3 | } p1 = {1}, p2 = {2}; 4 | 5 | struct { 6 | char a; 7 | short b, c; 8 | } q1 = {3}, q2 = {4}; 9 | 10 | int main(void) { 11 | p1 = p2; 12 | q1 = q2; 13 | return p1.s + q1.a + q1.b + q1.c; 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/struct-comma-call.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct S3 { 4 | unsigned f0; 5 | int f1; 6 | float f2; 7 | }; 8 | 9 | char f = 41; 10 | int h = 0; 11 | 12 | void fn2(char p1, long p2) { 13 | h |= p1; 14 | } 15 | 16 | struct S3 fn3(void) { 17 | struct S3 foo = {0}; 18 | return foo; 19 | } 20 | 21 | int main(void) { 22 | fn2((0x11 & f), (fn3(), 379)); 23 | return printf("%d\n", h); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-lacc/struct-eightbyte-write.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | struct S0 { 4 | float f0; 5 | int f1; 6 | float f2; 7 | } c = {1.0f}; 8 | 9 | struct S0 *d = &c; 10 | float e = 0xBEA32D2AL; 11 | struct S0 f = {34.4f}; 12 | 13 | long g = 1L; 14 | struct S0 *j = &f; 15 | long *m = &g; 16 | 17 | struct S0 foo(void) { 18 | return *d; 19 | } 20 | 21 | int main(void) { 22 | *m = 42; 23 | (*j) = foo(); 24 | return printf("%ld, (%f, %d, %f)\n", g, f.f0, f.f1, f.f2); 25 | } 26 | -------------------------------------------------------------------------------- /test/test-lacc/struct-init-swap.c: -------------------------------------------------------------------------------- 1 | /* From Listing 3 in "Test-Case Reduction for C Compiler Bugs" paper, available 2 | * at http://www.cs.utah.edu/~regehr/papers/pldi12-preprint.pdf. 3 | */ 4 | 5 | int printf (const char *, ...); 6 | struct { 7 | int f0; 8 | int f1; 9 | int f2; 10 | } a, b = { 0, 0, 1 }; 11 | 12 | void fn1 () { 13 | a = b; 14 | a = a; 15 | } 16 | 17 | int main () { 18 | fn1 (); 19 | printf ("%d\n", a.f2); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/struct.c: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int x; 3 | int y; 4 | struct { 5 | int val; 6 | } z; 7 | } point_t; 8 | 9 | int main() { 10 | point_t point; 11 | point_t *foo; 12 | 13 | point.x = 1; 14 | point.y = 3; 15 | 16 | foo = &point; 17 | foo->x = 17; 18 | foo->z.val = 5; 19 | 20 | return point.y * point.z.val - point.x; 21 | } 22 | -------------------------------------------------------------------------------- /test/test-lacc/switch-basic.c: -------------------------------------------------------------------------------- 1 | int test(int a) { 2 | int b = 0; 3 | 4 | switch (a) { 5 | case 1: b = 2; 6 | break; 7 | case 2: b = 3; 8 | case 3: b = 0; 9 | default: 10 | b = 6; 11 | break; 12 | } 13 | 14 | return b; 15 | } 16 | 17 | int main() 18 | { 19 | return test(1) + test(2) + test(3) + test(4); 20 | } 21 | -------------------------------------------------------------------------------- /test/test-lacc/switch-nested.c: -------------------------------------------------------------------------------- 1 | int test(int a) { 2 | int b = 0; 3 | 4 | switch (a) { 5 | case 1: b = 2; 6 | break; 7 | default: 8 | switch (a - 2) { 9 | default: 10 | break; 11 | case 0: 12 | return 1; 13 | } 14 | break; 15 | case 3: b = 6; 16 | } 17 | 18 | return b; 19 | } 20 | 21 | int main() 22 | { 23 | return test(1) + test(2) + test(3) + test(4); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-lacc/tag.c: -------------------------------------------------------------------------------- 1 | 2 | struct token { 3 | int x; 4 | int y; 5 | } wat = {0, 2}; 6 | 7 | int main() { 8 | struct token t = {5, 7}; 9 | 10 | wat.y = 3; 11 | 12 | return t.x + wat.y; 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/tail-compare-jump.c: -------------------------------------------------------------------------------- 1 | int f = 0, g; 2 | long h = 42l; 3 | 4 | int main(void) { 5 | f < 0L; 6 | if (h) { 7 | g = 2; 8 | } else { 9 | g = 1; 10 | } 11 | return g; 12 | } 13 | -------------------------------------------------------------------------------- /test/test-lacc/token.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | int putchar(int); 3 | 4 | const char foo[] = "\041\042 \043\052 The answer to everything is \x34\x32 (\?)"; 5 | 6 | char bar[] = "\"The End\"\0 Nothing to see here."; 7 | 8 | char t1 = '\056'; 9 | char t2 = '\x53'; 10 | char t3 = '\n'; 11 | char t4 = '`'; 12 | char t5 = 'a'; 13 | char t6 = '\0'; 14 | 15 | int _printstuff__() { 16 | puts(foo); 17 | puts(bar); 18 | 19 | putchar(t1); 20 | t1 = '9'; 21 | putchar(t1); 22 | putchar(t2); 23 | putchar(t3); 24 | putchar(t4); 25 | putchar(t5); 26 | putchar(t6); 27 | 28 | return t5; 29 | } 30 | 31 | int main() { 32 | return _printstuff__(); 33 | } 34 | -------------------------------------------------------------------------------- /test/test-lacc/tokenize-partial-keyword.c: -------------------------------------------------------------------------------- 1 | int reg(int a) { 2 | return a; 3 | } 4 | 5 | int main(void) { 6 | int t = 1; 7 | return reg(t); 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/trigraph.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | ??= define FOO 42 4 | 5 | int main(void) ??< 6 | int bar??(??) = {??-1, '??/n', 3 ??' 7??>; 7 | printf("What??!, %d, %d, %d\n", 8 | bar[0], bar[1], bar[2]); 9 | return FOO ??! 3; 10 | ??> 11 | -------------------------------------------------------------------------------- /test/test-lacc/typedef-function.c: -------------------------------------------------------------------------------- 1 | int atoi(const char *nptr); 2 | int isalnum(int c); 3 | 4 | typedef int foo_fn(const char *); 5 | 6 | int foo(foo_fn fn) { 7 | int (*p)(const char *) = fn; 8 | return p("10"); 9 | } 10 | 11 | typedef int bar_fn(int); 12 | 13 | int bar(bar_fn fn) { 14 | return fn('a'); 15 | } 16 | 17 | int main(void) { 18 | return foo(atoi) + bar(isalnum); 19 | } 20 | -------------------------------------------------------------------------------- /test/test-lacc/unary-minus-float.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | float g, i = 0; 4 | double h, j = 0; 5 | 6 | int main(void) { 7 | g = (-i); 8 | h = (-j); 9 | return printf("%f, %f\n", g, h); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/unary-plus.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | float g; 4 | long long h = 18446744073709551615ULL; 5 | char c = 'H'; 6 | 7 | int main(void) { 8 | g = +(0 * (float) h); 9 | return printf("%f, %lu\n", g, sizeof(+c)); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/union-bitfield.c: -------------------------------------------------------------------------------- 1 | union flags { 2 | signed a : 13; 3 | const signed b : 1; 4 | unsigned long c; 5 | }; 6 | 7 | union { 8 | long f0; 9 | signed f1 : 9; 10 | } g = {1L}; 11 | 12 | int main(void) { 13 | union flags f = {2}; 14 | return f.b + f.c + g.f1; 15 | } 16 | -------------------------------------------------------------------------------- /test/test-lacc/union-float-assign.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | union U { 4 | float f0; 5 | double f1; 6 | } foo; 7 | 8 | static union U *bar = &foo; 9 | 10 | int main(void) { 11 | union U w = {3.14f}; 12 | *bar = w; 13 | return printf("%f\n", foo.f0); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/union-float-param.c: -------------------------------------------------------------------------------- 1 | int printf(const char *, ...); 2 | 3 | union obj { 4 | float f; 5 | } g = {42.5678f}; 6 | 7 | int foo(union obj v) { 8 | float *p = &v.f; 9 | return printf("%f\n", *p); 10 | } 11 | 12 | int main(void) { 13 | return foo(g); 14 | } 15 | -------------------------------------------------------------------------------- /test/test-lacc/union-zero-init.c: -------------------------------------------------------------------------------- 1 | struct obj { 2 | int mem; 3 | union either { 4 | signed char i; 5 | unsigned int u; 6 | } d; 7 | }; 8 | 9 | struct obj data = {1}; 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/test-lacc/union.c: -------------------------------------------------------------------------------- 1 | union foo { 2 | int a; 3 | long b; 4 | }; 5 | 6 | int main() { 7 | union foo bar; 8 | bar.a = 1; 9 | bar.b = 8; 10 | return sizeof(bar) + sizeof(union foo) + bar.a + bar.b; 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/unsigned-compare-ge.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | char c = 0xff; 3 | unsigned int d = 4; 4 | 5 | return c >= d; 6 | } 7 | -------------------------------------------------------------------------------- /test/test-lacc/unsigned-compare.c: -------------------------------------------------------------------------------- 1 | int g = -1L; 2 | unsigned char i = 0; 3 | 4 | int main () { 5 | unsigned char c = 0xff; 6 | int d = -1; 7 | return (c == d) + (i >= g); 8 | } 9 | -------------------------------------------------------------------------------- /test/test-lacc/unsigned-sign-extend.c: -------------------------------------------------------------------------------- 1 | int putchar(int c); 2 | 3 | int main(void) { 4 | char *data = "Hello World!", *ptr; 5 | int offset = 4; 6 | int diff = -2; 7 | 8 | ptr = data + offset + diff - diff; 9 | 10 | return putchar(*ptr); 11 | } 12 | -------------------------------------------------------------------------------- /test/test-lacc/vararg-deref-arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int printf(const char *, ...); 4 | 5 | struct point { 6 | int y[2]; 7 | } p; 8 | 9 | static void test(struct point *p, ...) 10 | { 11 | va_list args; 12 | va_start(args, p); 13 | 14 | p->y[0] = va_arg(args, int); 15 | p->y[1] = va_arg(args, int); 16 | 17 | va_end(args); 18 | } 19 | 20 | int main(void) { 21 | test(&p, 1, 2); 22 | return printf("%d, %d\n", p.y[0], p.y[1]); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-lacc/vararg-deref.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static int sum(int n, va_list *args) { 6 | int k = 0; 7 | while (n--) { 8 | k += va_arg(*args, double); 9 | } 10 | 11 | return k; 12 | } 13 | 14 | static int test(int n, ...) { 15 | va_list *args; 16 | args = malloc(sizeof(*args)); 17 | va_start(*args, n); 18 | n = sum(n, args); 19 | va_end(*args); 20 | return n; 21 | } 22 | 23 | int main(void) { 24 | return printf("%d, %d, %d\n", 25 | test(1, 4.0), 26 | test(3, 4567.0f, 124.6f, 5368.5f), 27 | test(4, 123.5, 2356.4, 5678.6, 2769.1)); 28 | } 29 | -------------------------------------------------------------------------------- /test/test-lacc/vararg-float.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int printf(const char *, ...); 4 | 5 | int foo(float a, double b, ...) { 6 | double c, d, e; 7 | va_list args; 8 | va_start(args, b); 9 | 10 | c = va_arg(args, double); 11 | d = va_arg(args, double); 12 | e = va_arg(args, double); 13 | 14 | printf("a = %f, b = %f, c = %f, d = %f, e = %f\n", a, b, c, d, e); 15 | 16 | va_end(args); 17 | return d; 18 | } 19 | 20 | int main(void) { 21 | float f = 3.14f; 22 | double d = 2.71; 23 | return foo(f, d, 4.9f, 90.0, f); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-lacc/vararg-param.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static int print(const char *format, va_list ap) 5 | { 6 | int n = 0, c; 7 | 8 | while ((c = *format++) != '\0') { 9 | if (c == '#') { 10 | c = va_arg(ap, int); 11 | } 12 | 13 | putchar(c); 14 | n++; 15 | } 16 | 17 | return n; 18 | } 19 | 20 | static int warning(const char *format, ...) 21 | { 22 | int n; 23 | va_list args; 24 | va_start(args, format); 25 | n = print(format, args); 26 | putchar('\n'); 27 | va_end(args); 28 | return n; 29 | } 30 | 31 | int main(void) { 32 | return warning("This # not #", 'A', 'C'); 33 | } 34 | -------------------------------------------------------------------------------- /test/test-lacc/void-statement.c: -------------------------------------------------------------------------------- 1 | static int i; 2 | 3 | int foo(void) { 4 | return i = 42; 5 | } 6 | 7 | int main(void) { 8 | (void) foo(); 9 | return i; 10 | } 11 | -------------------------------------------------------------------------------- /test/test-lacc/whitespace.c: -------------------------------------------------------------------------------- 1 | int puts(const char *); 2 | 3 | /* form feed, 0x0c */ 4 | 5 | int main(void) { 6 | return puts("Hello"); 7 | } 8 | -------------------------------------------------------------------------------- /test/test-lacc/zero-init.c: -------------------------------------------------------------------------------- 1 | struct point { 2 | int x, y; 3 | }; 4 | 5 | int main(void) 6 | { 7 | static int arr[16]; 8 | static struct point p; 9 | 10 | char foo[6] = {'a', 'b', 'c'}; 11 | struct point q = {3}; 12 | 13 | return p.x + arr[2] + foo[3] + q.y; 14 | } 15 | -------------------------------------------------------------------------------- /test/test-picoc/00_assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int a; 5 | a = 42; 6 | printf("%d\n", a); 7 | 8 | int b = 64; 9 | printf("%d\n", b); 10 | 11 | int c = 12, d = 34; 12 | printf("%d, %d\n", c, d); 13 | } 14 | -------------------------------------------------------------------------------- /test/test-picoc/00_assignment.expect: -------------------------------------------------------------------------------- 1 | 42 2 | 64 3 | 12, 34 4 | -------------------------------------------------------------------------------- /test/test-picoc/01_comment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | printf("Hello\n"); 5 | printf("Hello\n"); /* this is a comment */ printf("Hello\n"); 6 | printf("Hello\n"); 7 | // this is also a comment sayhello(); 8 | printf("Hello\n"); 9 | } 10 | -------------------------------------------------------------------------------- /test/test-picoc/01_comment.expect: -------------------------------------------------------------------------------- 1 | Hello 2 | Hello 3 | Hello 4 | Hello 5 | Hello 6 | -------------------------------------------------------------------------------- /test/test-picoc/02_printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | printf("Hello world\n"); 5 | 6 | int Count; 7 | for (Count = -5; Count <= 5; Count++) 8 | printf("Count = %d\n", Count); 9 | 10 | printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there"); 11 | printf("Character 'A' is '%c'\n", 65); 12 | printf("Character 'a' is '%c'\n", 'a'); 13 | } 14 | -------------------------------------------------------------------------------- /test/test-picoc/02_printf.expect: -------------------------------------------------------------------------------- 1 | Hello world 2 | Count = -5 3 | Count = -4 4 | Count = -3 5 | Count = -2 6 | Count = -1 7 | Count = 0 8 | Count = 1 9 | Count = 2 10 | Count = 3 11 | Count = 4 12 | Count = 5 13 | String 'hello', 'there' is 'hello', 'there' 14 | Character 'A' is 'A' 15 | Character 'a' is 'a' 16 | -------------------------------------------------------------------------------- /test/test-picoc/03_struct.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | struct fred 5 | { 6 | int boris; 7 | int natasha; 8 | }; 9 | 10 | struct fred bloggs; 11 | 12 | bloggs.boris = 12; 13 | bloggs.natasha = 34; 14 | 15 | printf("%d\n", bloggs.boris); 16 | printf("%d\n", bloggs.natasha); 17 | 18 | //struct fred jones[2]; 19 | //jones[0].boris = 12; 20 | //jones[0].natasha = 34; 21 | } 22 | -------------------------------------------------------------------------------- /test/test-picoc/03_struct.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | -------------------------------------------------------------------------------- /test/test-picoc/04_for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int Count; 5 | 6 | for (Count = 1; Count <= 10; Count++) 7 | { 8 | printf("%d\n", Count); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/test-picoc/04_for.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /test/test-picoc/05_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int Count; 5 | int Array[10]; 6 | 7 | for (Count = 1; Count <= 10; Count++) 8 | { 9 | Array[Count-1] = Count * Count; 10 | } 11 | 12 | for (Count = 0; Count < 10; Count++) 13 | { 14 | printf("%d\n", Array[Count]); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/test-picoc/05_array.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 4 3 | 9 4 | 16 5 | 25 6 | 36 7 | 49 8 | 64 9 | 81 10 | 100 11 | -------------------------------------------------------------------------------- /test/test-picoc/06_case.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int Count; 5 | 6 | for (Count = 0; Count < 4; Count++) 7 | { 8 | printf("%d\n", Count); 9 | switch (Count) 10 | { 11 | case 1: 12 | printf("%d\n", 1); 13 | break; 14 | 15 | case 2: 16 | printf("%d\n", 2); 17 | break; 18 | 19 | default: 20 | printf("%d\n", 0); 21 | break; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/test-picoc/06_case.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2 7 | 3 8 | 0 9 | -------------------------------------------------------------------------------- /test/test-picoc/07_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int myfunc(int x) 4 | { 5 | return x * x; 6 | } 7 | 8 | void vfunc(int a) 9 | { 10 | printf("a=%d\n", a); 11 | } 12 | 13 | void qfunc() 14 | { 15 | printf("qfunc()\n"); 16 | } 17 | 18 | void main() { 19 | printf("%d\n", myfunc(3)); 20 | printf("%d\n", myfunc(4)); 21 | 22 | vfunc(1234); 23 | 24 | qfunc(); 25 | } 26 | -------------------------------------------------------------------------------- /test/test-picoc/07_function.expect: -------------------------------------------------------------------------------- 1 | 9 2 | 16 3 | a=1234 4 | qfunc() 5 | -------------------------------------------------------------------------------- /test/test-picoc/08_while.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | 0 13 | 1 14 | 2 15 | 3 16 | 4 17 | 5 18 | 6 19 | 7 20 | 10 21 | 9 22 | 8 23 | 7 24 | 6 25 | 5 26 | 4 27 | 3 28 | -------------------------------------------------------------------------------- /test/test-picoc/09_do_while.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int a; 5 | int p; 6 | int t; 7 | 8 | a = 1; 9 | p = 0; 10 | t = 0; 11 | 12 | do 13 | { 14 | printf("%d\n", a); 15 | t = a; 16 | a = t + p; 17 | p = t; 18 | } while (a < 100); 19 | } 20 | -------------------------------------------------------------------------------- /test/test-picoc/09_do_while.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 3 5 | 5 6 | 8 7 | 13 8 | 21 9 | 34 10 | 55 11 | 89 12 | -------------------------------------------------------------------------------- /test/test-picoc/10_pointer.expect: -------------------------------------------------------------------------------- 1 | a = 42 2 | bolshevic.a = 12 3 | bolshevic.b = 34 4 | bolshevic.c = 56 5 | tsar->a = 12 6 | tsar->b = 34 7 | tsar->c = 56 8 | -------------------------------------------------------------------------------- /test/test-picoc/11_precedence.expect: -------------------------------------------------------------------------------- 1 | 134 2 | 134 3 | 0 4 | 1 5 | 1 6 | 1 7 | 1 8 | 46 9 | 1, 0 10 | 0, 1 11 | 1 12 | 1916 13 | 1916 14 | 64 15 | 4 16 | -------------------------------------------------------------------------------- /test/test-picoc/12_hashdefine.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define FRED 12 4 | #define BLOGGS(x) (12*(x)) 5 | 6 | void main() { 7 | printf("%d\n", FRED); 8 | printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3)); 9 | } 10 | -------------------------------------------------------------------------------- /test/test-picoc/12_hashdefine.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 12, 24, 36 3 | -------------------------------------------------------------------------------- /test/test-picoc/13_integer_literals.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int a = 24680; 5 | int b = 01234567; 6 | int c = 0x2468ac; 7 | int d = 0x2468AC; 8 | int e = 0x555; 9 | 10 | printf("%d\n", a); 11 | printf("%d\n", b); 12 | printf("%d\n", c); 13 | printf("%d\n", d); 14 | printf("%d\n", e); 15 | } 16 | -------------------------------------------------------------------------------- /test/test-picoc/13_integer_literals.expect: -------------------------------------------------------------------------------- 1 | 24680 2 | 342391 3 | 2386092 4 | 2386092 5 | 1365 6 | -------------------------------------------------------------------------------- /test/test-picoc/14_if.expect: -------------------------------------------------------------------------------- 1 | a is true 2 | b is false 3 | c is false 4 | c is true 5 | c is true 6 | c is false 7 | -------------------------------------------------------------------------------- /test/test-picoc/15_recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int factorial(int i) 4 | { 5 | if (i < 2) 6 | return i; 7 | else 8 | return i * factorial(i - 1); 9 | } 10 | 11 | void main() { 12 | int Count; 13 | 14 | for (Count = 1; Count <= 10; Count++) 15 | printf("%d\n", factorial(Count)); 16 | } 17 | -------------------------------------------------------------------------------- /test/test-picoc/15_recursion.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 6 4 | 24 5 | 120 6 | 720 7 | 5040 8 | 40320 9 | 362880 10 | 3628800 11 | -------------------------------------------------------------------------------- /test/test-picoc/16_nesting.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int x, y, z; 5 | 6 | for (x = 0; x < 2; x++) 7 | { 8 | for (y = 0; y < 3; y++) 9 | { 10 | for (z = 0; z < 3; z++) 11 | { 12 | printf("%d %d %d\n", x, y, z); 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/test-picoc/16_nesting.expect: -------------------------------------------------------------------------------- 1 | 0 0 0 2 | 0 0 1 3 | 0 0 2 4 | 0 1 0 5 | 0 1 1 6 | 0 1 2 7 | 0 2 0 8 | 0 2 1 9 | 0 2 2 10 | 1 0 0 11 | 1 0 1 12 | 1 0 2 13 | 1 1 0 14 | 1 1 1 15 | 1 1 2 16 | 1 2 0 17 | 1 2 1 18 | 1 2 2 19 | -------------------------------------------------------------------------------- /test/test-picoc/17_enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred 4 | { 5 | a, 6 | b, 7 | c, 8 | d, 9 | e = 54, 10 | f = 73, 11 | g, 12 | h 13 | }; 14 | 15 | enum fred frod; 16 | 17 | void main() { 18 | printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h); 19 | printf("%d\n", frod); 20 | frod = 12; 21 | printf("%d\n", frod); 22 | frod = e; 23 | printf("%d\n", frod); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-picoc/17_enum.expect: -------------------------------------------------------------------------------- 1 | 0 1 2 3 54 73 74 75 2 | 0 3 | 12 4 | 54 5 | -------------------------------------------------------------------------------- /test/test-picoc/18_include.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | printf("including\n"); 5 | #include "18_include.h" 6 | printf("done\n"); 7 | } 8 | -------------------------------------------------------------------------------- /test/test-picoc/18_include.expect: -------------------------------------------------------------------------------- 1 | including 2 | included 3 | done 4 | -------------------------------------------------------------------------------- /test/test-picoc/18_include.h: -------------------------------------------------------------------------------- 1 | printf("included\n"); 2 | -------------------------------------------------------------------------------- /test/test-picoc/19_pointer_arithmetic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int a; 5 | int *b; 6 | int *c; 7 | 8 | a = 42; 9 | b = &a; 10 | c = NULL; 11 | 12 | printf("%d\n", *b); 13 | 14 | if (b == NULL) 15 | printf("b is NULL\n"); 16 | else 17 | printf("b is not NULL\n"); 18 | 19 | if (c == NULL) 20 | printf("c is NULL\n"); 21 | else 22 | printf("c is not NULL\n"); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-picoc/19_pointer_arithmetic.expect: -------------------------------------------------------------------------------- 1 | 42 2 | b is not NULL 3 | c is NULL 4 | -------------------------------------------------------------------------------- /test/test-picoc/20_pointer_comparison.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int a; 5 | int b; 6 | int *d; 7 | int *e; 8 | d = &a; 9 | e = &b; 10 | a = 12; 11 | b = 34; 12 | printf("%d\n", *d); 13 | printf("%d\n", *e); 14 | printf("%d\n", d == e); 15 | printf("%d\n", d != e); 16 | d = e; 17 | printf("%d\n", d == e); 18 | printf("%d\n", d != e); 19 | } 20 | -------------------------------------------------------------------------------- /test/test-picoc/20_pointer_comparison.expect: -------------------------------------------------------------------------------- 1 | 12 2 | 34 3 | 0 4 | 1 5 | 1 6 | 0 7 | -------------------------------------------------------------------------------- /test/test-picoc/21_char_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int x = 'a'; 5 | char y = x; 6 | 7 | char *a = "hello"; 8 | 9 | printf("%s\n", a); 10 | 11 | int c; 12 | c = *a; 13 | 14 | char *b; 15 | for (b = a; *b != 0; b++) 16 | printf("%c: %d\n", *b, *b); 17 | 18 | char destarray[10]; 19 | char *dest = &destarray[0]; 20 | char *src = a; 21 | 22 | while (*src != 0) 23 | *dest++ = *src++; 24 | 25 | *dest = 0; 26 | 27 | printf("copied string is %s\n", destarray); 28 | } 29 | -------------------------------------------------------------------------------- /test/test-picoc/21_char_array.expect: -------------------------------------------------------------------------------- 1 | hello 2 | h: 104 3 | e: 101 4 | l: 108 5 | l: 108 6 | o: 111 7 | copied string is hello 8 | -------------------------------------------------------------------------------- /test/test-picoc/22_floating_point.expect: -------------------------------------------------------------------------------- 1 | 69.120000 2 | 69.120000 3 | -44.440000 4 | 700.665200 5 | 0.217330 6 | 1 1 0 0 0 1 7 | 0 1 1 1 0 0 8 | 0 0 0 1 1 1 9 | 69.120000 10 | -44.440000 11 | 700.665200 12 | 0.217330 13 | 12.340000 14 | -12.340000 15 | 2.000000 16 | 0.909297 17 | -------------------------------------------------------------------------------- /test/test-picoc/23_type_coercion.expect: -------------------------------------------------------------------------------- 1 | char: a 2 | char: b 3 | char: c 4 | int: 97 5 | int: 98 6 | int: 99 7 | float: 97.000000 8 | float: 98.000000 9 | float: 99.000000 10 | a 98 99.000000 11 | a 98 99.000000 12 | a 98 99.000000 13 | 97 97 14 | 97 97 15 | 97.000000 97.000000 16 | -------------------------------------------------------------------------------- /test/test-picoc/24_math_library.expect: -------------------------------------------------------------------------------- 1 | 0.119712 2 | 0.992809 3 | 0.120579 4 | 0.120290 5 | 1.450506 6 | 0.119429 7 | 0.120288 8 | 1.007209 9 | 0.119427 10 | 1.127497 11 | 0.120000 12 | -2.120264 13 | -0.920819 14 | 0.775357 15 | 0.346410 16 | 12.000000 17 | 13.000000 18 | 12.000000 19 | -------------------------------------------------------------------------------- /test/test-picoc/25_quicksort.expect: -------------------------------------------------------------------------------- 1 | 62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55 2 | 4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96 3 | -------------------------------------------------------------------------------- /test/test-picoc/26_character_constants.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | printf("%d\n", '\1'); 5 | printf("%d\n", '\10'); 6 | printf("%d\n", '\100'); 7 | printf("%d\n", '\x01'); 8 | printf("%d\n", '\x0e'); 9 | printf("%d\n", '\x10'); 10 | printf("%d\n", '\x40'); 11 | printf("test \x407\n"); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-picoc/26_character_constants.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 8 3 | 64 4 | 1 5 | 14 6 | 16 7 | 64 8 | test @7 9 | -------------------------------------------------------------------------------- /test/test-picoc/27_sizeof.expect: -------------------------------------------------------------------------------- 1 | 16 2 | 24 3 | 48 4 | 1 5 | 4 6 | 8 7 | -------------------------------------------------------------------------------- /test/test-picoc/28_strings.expect: -------------------------------------------------------------------------------- 1 | hello 2 | gollo 3 | 1 4 | 1 5 | 1 6 | 5 7 | gollo! 8 | 1 9 | 1 10 | 1 11 | 1 12 | ollo! 13 | lo! 14 | 1 15 | grrrr! 16 | grgrr! 17 | 1 18 | 1 19 | 1 20 | -------------------------------------------------------------------------------- /test/test-picoc/29_array_address.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() { 5 | char a[10]; 6 | strcpy(a, "abcdef"); 7 | printf("%s\n", &a[1]); 8 | } 9 | -------------------------------------------------------------------------------- /test/test-picoc/29_array_address.expect: -------------------------------------------------------------------------------- 1 | bcdef 2 | -------------------------------------------------------------------------------- /test/test-picoc/31_args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int Count; 6 | 7 | printf("hello world %d\n", argc); 8 | for (Count = 0; Count < argc; Count++) 9 | printf("arg %d: %s\n", Count, argv[Count]); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/test-picoc/31_args.expect: -------------------------------------------------------------------------------- 1 | hello world 5 2 | arg 0: 31_args.c 3 | arg 1: arg1 4 | arg 2: arg2 5 | arg 3: arg3 6 | arg 4: arg4 7 | -------------------------------------------------------------------------------- /test/test-picoc/32_led.expect: -------------------------------------------------------------------------------- 1 | _ _ _ _ 2 | | _| _| |_| |_ |_ | 3 | | |_ _| | _| |_| | 4 | 5 | -------------------------------------------------------------------------------- /test/test-picoc/33_ternary_op.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int Count; 5 | 6 | for (Count = 0; Count < 10; Count++) 7 | { 8 | printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/test-picoc/33_ternary_op.expect: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 4 4 | 9 5 | 16 6 | 15 7 | 18 8 | 21 9 | 24 10 | 27 11 | -------------------------------------------------------------------------------- /test/test-picoc/34_array_assignment.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int a[4]; 5 | 6 | a[0] = 12; 7 | a[1] = 23; 8 | a[2] = 34; 9 | a[3] = 45; 10 | 11 | printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]); 12 | 13 | int* b; 14 | 15 | b = a; 16 | 17 | printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]); 18 | } 19 | -------------------------------------------------------------------------------- /test/test-picoc/34_array_assignment.expect: -------------------------------------------------------------------------------- 1 | 12 23 34 45 2 | 12 23 34 45 3 | -------------------------------------------------------------------------------- /test/test-picoc/35_sizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | char a; 5 | short b; 6 | 7 | printf("%d %d\n", sizeof(char), sizeof(a)); 8 | printf("%d %d\n", sizeof(short), sizeof(b)); 9 | } 10 | -------------------------------------------------------------------------------- /test/test-picoc/35_sizeof.expect: -------------------------------------------------------------------------------- 1 | 1 1 2 | 2 2 3 | -------------------------------------------------------------------------------- /test/test-picoc/36_array_initializers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int Count; 5 | 6 | int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 }; 7 | 8 | for (Count = 0; Count < 10; Count++) 9 | printf("%d: %d\n", Count, Array[Count]); 10 | 11 | int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, }; 12 | 13 | for (Count = 0; Count < 10; Count++) 14 | printf("%d: %d\n", Count, Array2[Count]); 15 | } 16 | -------------------------------------------------------------------------------- /test/test-picoc/36_array_initializers.expect: -------------------------------------------------------------------------------- 1 | 0: 12 2 | 1: 34 3 | 2: 56 4 | 3: 78 5 | 4: 90 6 | 5: 123 7 | 6: 456 8 | 7: 789 9 | 8: 8642 10 | 9: 9753 11 | 0: 12 12 | 1: 34 13 | 2: 56 14 | 3: 78 15 | 4: 90 16 | 5: 123 17 | 6: 456 18 | 7: 789 19 | 8: 8642 20 | 9: 9753 21 | -------------------------------------------------------------------------------- /test/test-picoc/37_sprintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | char Buf[100]; 5 | int Count; 6 | 7 | for (Count = 1; Count <= 20; Count++) 8 | { 9 | sprintf(Buf, "->%02d<-\n", Count); 10 | printf("%s", Buf); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/test-picoc/37_sprintf.expect: -------------------------------------------------------------------------------- 1 | ->01<- 2 | ->02<- 3 | ->03<- 4 | ->04<- 5 | ->05<- 6 | ->06<- 7 | ->07<- 8 | ->08<- 9 | ->09<- 10 | ->10<- 11 | ->11<- 12 | ->12<- 13 | ->13<- 14 | ->14<- 15 | ->15<- 16 | ->16<- 17 | ->17<- 18 | ->18<- 19 | ->19<- 20 | ->20<- 21 | -------------------------------------------------------------------------------- /test/test-picoc/38_multiple_array_index.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int a[4][4]; 5 | int b = 0; 6 | int x; 7 | int y; 8 | 9 | for (x = 0; x < 4; x++) 10 | { 11 | for (y = 0; y < 4; y++) 12 | { 13 | b++; 14 | a[x][y] = b; 15 | } 16 | } 17 | 18 | 19 | 20 | for (x = 0; x < 4; x++) 21 | { 22 | printf("x=%d: ", x); 23 | for (y = 0; y < 4; y++) 24 | { 25 | printf("%d%s", a[x][y], y < 3 ? " " : ""); 26 | } 27 | printf("\n"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/test-picoc/38_multiple_array_index.expect: -------------------------------------------------------------------------------- 1 | x=0: 1 2 3 4 2 | x=1: 5 6 7 8 3 | x=2: 9 10 11 12 4 | x=3: 13 14 15 16 5 | -------------------------------------------------------------------------------- /test/test-picoc/39_typedef.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef int MyInt; 4 | 5 | struct FunStruct 6 | { 7 | int i; 8 | int j; 9 | }; 10 | 11 | typedef struct FunStruct MyFunStruct; 12 | 13 | typedef MyFunStruct *MoreFunThanEver; 14 | 15 | void main() { 16 | MyInt a = 1; 17 | printf("%d\n", a); 18 | 19 | MyFunStruct b; 20 | b.i = 12; 21 | b.j = 34; 22 | printf("%d,%d\n", b.i, b.j); 23 | 24 | MoreFunThanEver c = &b; 25 | printf("%d,%d\n", c->i, c->j); 26 | } 27 | -------------------------------------------------------------------------------- /test/test-picoc/39_typedef.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 12,34 3 | 12,34 4 | -------------------------------------------------------------------------------- /test/test-picoc/40_stdio.expect: -------------------------------------------------------------------------------- 1 | hello 2 | ch: 104 'h' 3 | ch: 101 'e' 4 | ch: 108 'l' 5 | ch: 108 'l' 6 | ch: 111 'o' 7 | ch: 10 '.' 8 | ch: 104 'h' 9 | ch: 101 'e' 10 | ch: 108 'l' 11 | ch: 108 'l' 12 | ch: 111 'o' 13 | ch: 10 '.' 14 | ch: 104 'h' 15 | ch: 101 'e' 16 | ch: 108 'l' 17 | ch: 108 'l' 18 | ch: 111 'o' 19 | ch: 10 '.' 20 | ch: 104 'h' 21 | ch: 101 'e' 22 | ch: 108 'l' 23 | ch: 108 'l' 24 | ch: 111 'o' 25 | ch: 10 '.' 26 | x: hello 27 | x: hello 28 | -------------------------------------------------------------------------------- /test/test-picoc/41_hashif.expect: -------------------------------------------------------------------------------- 1 | #include test 2 | b 3 | g 4 | i 5 | p 6 | r 7 | -------------------------------------------------------------------------------- /test/test-picoc/42_function_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred(int p) 4 | { 5 | printf("yo %d\n", p); 6 | return 42; 7 | } 8 | 9 | int (*f)(int) = &fred; 10 | 11 | int main() 12 | { 13 | printf("%d\n", (*f)(24)); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /test/test-picoc/42_function_pointer.expect: -------------------------------------------------------------------------------- 1 | yo 24 2 | 42 3 | -------------------------------------------------------------------------------- /test/test-picoc/43_void_param.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(void) 4 | { 5 | printf("yo\n"); 6 | } 7 | 8 | void main() { 9 | fred(); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-picoc/43_void_param.expect: -------------------------------------------------------------------------------- 1 | yo 2 | -------------------------------------------------------------------------------- /test/test-picoc/44_scoped_declarations.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() { 4 | int a; 5 | 6 | for (a = 0; a < 2; a++) 7 | { 8 | int b = a; 9 | } 10 | 11 | printf("it's all good\n"); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-picoc/44_scoped_declarations.expect: -------------------------------------------------------------------------------- 1 | it's all good 2 | -------------------------------------------------------------------------------- /test/test-picoc/45_empty_for.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int Count = 0; 6 | 7 | for (;;) 8 | { 9 | Count++; 10 | printf("%d\n", Count); 11 | if (Count >= 10) 12 | break; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /test/test-picoc/45_empty_for.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 11 | -------------------------------------------------------------------------------- /test/test-picoc/47_switch_return.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred(int x) 4 | { 5 | switch (x) 6 | { 7 | case 1: printf("1\n"); return; 8 | case 2: printf("2\n"); break; 9 | case 3: printf("3\n"); return; 10 | } 11 | 12 | printf("out\n"); 13 | } 14 | 15 | int main() 16 | { 17 | fred(1); 18 | fred(2); 19 | fred(3); 20 | 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /test/test-picoc/47_switch_return.expect: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | out 4 | 3 5 | -------------------------------------------------------------------------------- /test/test-picoc/48_nested_break.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a; 6 | char b; 7 | 8 | a = 0; 9 | while (a < 2) 10 | { 11 | printf("%d", a++); 12 | break; 13 | 14 | b = 'A'; 15 | while (b < 'C') 16 | { 17 | printf("%c", b++); 18 | } 19 | printf("e"); 20 | } 21 | printf("\n"); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /test/test-picoc/48_nested_break.expect: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /test/test-picoc/49_bracket_evaluation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct point 4 | { 5 | double x; 6 | double y; 7 | }; 8 | 9 | struct point point_array[100]; 10 | 11 | int main() 12 | { 13 | int my_point = 10; 14 | 15 | point_array[my_point].x = 12.34; 16 | point_array[my_point].y = 56.78; 17 | 18 | printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /test/test-picoc/49_bracket_evaluation.expect: -------------------------------------------------------------------------------- 1 | 12.340000, 56.780000 2 | -------------------------------------------------------------------------------- /test/test-picoc/50_logical_second_arg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fred() 4 | { 5 | printf("fred\n"); 6 | return 0; 7 | } 8 | 9 | int joe() 10 | { 11 | printf("joe\n"); 12 | return 1; 13 | } 14 | 15 | int main() 16 | { 17 | printf("%d\n", fred() && joe()); 18 | printf("%d\n", fred() || joe()); 19 | printf("%d\n", joe() && fred()); 20 | printf("%d\n", joe() || fred()); 21 | printf("%d\n", fred() && (1 + joe())); 22 | printf("%d\n", fred() || (0 + joe())); 23 | printf("%d\n", joe() && (0 + fred())); 24 | printf("%d\n", joe() || (1 + fred())); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /test/test-picoc/50_logical_second_arg.expect: -------------------------------------------------------------------------------- 1 | fred 2 | 0 3 | fred 4 | joe 5 | 1 6 | joe 7 | fred 8 | 0 9 | joe 10 | 1 11 | fred 12 | 0 13 | fred 14 | joe 15 | 1 16 | joe 17 | fred 18 | 0 19 | joe 20 | 1 21 | -------------------------------------------------------------------------------- /test/test-picoc/51_static.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int fred = 1234; 4 | static int joe; 5 | 6 | void henry() 7 | { 8 | static int fred = 4567; 9 | 10 | printf("%d\n", fred); 11 | fred++; 12 | } 13 | 14 | void main() 15 | { 16 | printf("%d\n", fred); 17 | henry(); 18 | henry(); 19 | henry(); 20 | henry(); 21 | printf("%d\n", fred); 22 | fred = 8901; 23 | joe = 2345; 24 | printf("%d\n", fred); 25 | printf("%d\n", joe); 26 | } 27 | -------------------------------------------------------------------------------- /test/test-picoc/51_static.expect: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | 4568 4 | 4569 5 | 4570 6 | 1234 7 | 8901 8 | 2345 9 | -------------------------------------------------------------------------------- /test/test-picoc/52_unnamed_enum.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | enum fred { a, b, c }; 4 | 5 | void main() 6 | { 7 | printf("a=%d\n", a); 8 | printf("b=%d\n", b); 9 | printf("c=%d\n", c); 10 | 11 | enum fred d; 12 | 13 | typedef enum { e, f, g } h; 14 | typedef enum { i, j, k } m; 15 | 16 | printf("e=%d\n", e); 17 | printf("f=%d\n", f); 18 | printf("g=%d\n", g); 19 | 20 | printf("i=%d\n", i); 21 | printf("j=%d\n", j); 22 | printf("k=%d\n", k); 23 | } 24 | -------------------------------------------------------------------------------- /test/test-picoc/52_unnamed_enum.expect: -------------------------------------------------------------------------------- 1 | a=0 2 | b=1 3 | c=2 4 | e=0 5 | f=1 6 | g=2 7 | i=0 8 | j=1 9 | k=2 10 | -------------------------------------------------------------------------------- /test/test-picoc/54_goto.expect: -------------------------------------------------------------------------------- 1 | In fred() 2 | At end 3 | In joe() 4 | c = 1234 5 | done 6 | In henry() 7 | b = 1234 8 | done 9 | -------------------------------------------------------------------------------- /test/test-picoc/55_array_initializer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int fred[3] = { 12, 34, 56 }; 6 | double joe[] = { 23.4, 56.7, 89.0 }; 7 | 8 | printf("%d %d %d\n", fred[0], fred[1], fred[2]); 9 | printf("%f %f %f\n", joe[0], joe[1], joe[2]); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /test/test-picoc/55_array_initializer.expect: -------------------------------------------------------------------------------- 1 | 12 34 56 2 | 23.400000 56.700000 89.000000 3 | -------------------------------------------------------------------------------- /test/test-picoc/56_cross_structure.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct s1; 4 | 5 | struct s2 6 | { 7 | struct s1 *s; 8 | }; 9 | 10 | struct s1 11 | { 12 | struct s2 *s; 13 | }; 14 | 15 | void main() 16 | { 17 | printf("ok\n"); 18 | } 19 | -------------------------------------------------------------------------------- /test/test-picoc/56_cross_structure.expect: -------------------------------------------------------------------------------- 1 | ok 2 | -------------------------------------------------------------------------------- /test/test-picoc/57_macro_bug.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | 3 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 4 | 5 | void main() 6 | { 7 | float x = MIN(1,2); 8 | int y = 14; 9 | float z; 10 | z = MIN(y, 13.5); 11 | y = MIN(y, 13); 12 | 13 | float pi = 3.14; 14 | int pi_int = pi; 15 | 16 | printf("Macro test: %d %d %f %d \n", (int)x, y, z, pi_int); 17 | } 18 | -------------------------------------------------------------------------------- /test/test-picoc/57_macro_bug.expect: -------------------------------------------------------------------------------- 1 | Macro test: 1 13 13.500000 3 2 | -------------------------------------------------------------------------------- /test/test-picoc/58_return_outside.c: -------------------------------------------------------------------------------- 1 | // should not crash 2 | return 0; 3 | -------------------------------------------------------------------------------- /test/test-picoc/58_return_outside.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/test/test-picoc/58_return_outside.expect -------------------------------------------------------------------------------- /test/test-picoc/59_break_before_loop.expect: -------------------------------------------------------------------------------- 1 | 2 | Test 1 3 | a=0 4 | 5 | Test 2 6 | a=0 7 | 8 | Test 3 9 | c=0 10 | foo 11 | 12 | Test 4 13 | c=0 14 | foo 15 | c=1 16 | foo 17 | c=2 18 | foo 19 | c=3 20 | foo 21 | c=4 22 | foo 23 | c=5 24 | foo 25 | c=6 26 | foo 27 | c=7 28 | foo 29 | c=8 30 | foo 31 | c=9 32 | foo 33 | -------------------------------------------------------------------------------- /test/test-picoc/60_local_vars.expect: -------------------------------------------------------------------------------- 1 | first for 2 | 0 3 | 1 4 | 2 5 | second for 6 | 0 7 | 1 8 | 2 9 | foo: first for 10 | foo: 0 11 | foo: 1 12 | foo: 2 13 | foo: while: 5 14 | foo: second for 15 | foo: 0 16 | foo: 1 17 | foo: 2 18 | foo: 0 19 | foo: 1 20 | foo: 2 21 | -------------------------------------------------------------------------------- /test/test-picoc/62_float.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | double x = 3.14; 6 | double y = 1e-3; 7 | double z = 1e-13; 8 | double q = 4.0f / 3.0f; 9 | printf("%f %f %f %f\n", x, y, z * 1e15, q); 10 | } 11 | -------------------------------------------------------------------------------- /test/test-picoc/62_float.expect: -------------------------------------------------------------------------------- 1 | 3.140000 0.001000 100.000000 1.333333 2 | -------------------------------------------------------------------------------- /test/test-picoc/63_typedef.expect: -------------------------------------------------------------------------------- 1 | -104<1> 2 | -17768<2> 3 | -19088744<4> 4 | -1250999861249<8> 5 | 152<1> 6 | 47768<2> 7 | 4275878552<4> 8 | 280223976849407<8> 9 | -19088744 10 | (1, 3) 11 | (1, 2) 12 | -------------------------------------------------------------------------------- /test/test-picoc/64_double_prefix_op.c: -------------------------------------------------------------------------------- 1 | // credits: CSmith, a random generator of C programs. 2 | 3 | #include "stdio.h" 4 | 5 | void func_1(void) 6 | { 7 | int x = 5; 8 | int* px = &x; 9 | int** ppx = &px; 10 | int*** pppx = &ppx; 11 | int a = - - x; 12 | printf("a=%d\n", a); 13 | int b = - - - x; 14 | printf("b=%d\n", b); 15 | int c = -***pppx; 16 | printf("c=%d\n", c); 17 | int d = - -****&pppx; 18 | printf("d=%d\n", d); 19 | } 20 | 21 | void main() 22 | { 23 | func_1(); 24 | } 25 | -------------------------------------------------------------------------------- /test/test-picoc/64_double_prefix_op.expect: -------------------------------------------------------------------------------- 1 | a=5 2 | b=-5 3 | c=-5 4 | d=5 5 | -------------------------------------------------------------------------------- /test/test-picoc/65_typeless.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | 3 | void main() 4 | { 5 | x = 3.9; 6 | y = 4; 7 | z = &y; 8 | msg = "hi there"; 9 | printf("%d %d %d %s\n", x*2, y*2, *z, msg); 10 | printf("%d %d %d\n", sizeof(x), sizeof(y), sizeof(msg)); 11 | for (i = 1; i <= 3; i++) 12 | printf("%d\n", i); 13 | 14 | /* this should fail 15 | { 16 | int q = 5; 17 | } 18 | q = 3.14; // should say error 19 | */ 20 | } 21 | -------------------------------------------------------------------------------- /test/test-picoc/65_typeless.expect: -------------------------------------------------------------------------------- 1 | 7 8 4 hi there 2 | 8 8 8 3 | 1 4 | 2 5 | 3 6 | -------------------------------------------------------------------------------- /test/test-picoc/66_printf_undefined.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fred() 4 | { 5 | printf("test\n"); 6 | } 7 | 8 | void main() 9 | { 10 | fred(); 11 | } 12 | -------------------------------------------------------------------------------- /test/test-picoc/66_printf_undefined.expect: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /test/test-picoc/67_macro_crash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void printArray(void) { 4 | #define SIZE 10 5 | int array[SIZE] = {5, 4, 3, 9, 1, 8, 6, 7, 5, 2}; 6 | printf("4: %d\n", array[4]); 7 | } 8 | 9 | void main() 10 | { 11 | printArray(); 12 | } 13 | -------------------------------------------------------------------------------- /test/test-picoc/67_macro_crash.expect: -------------------------------------------------------------------------------- 1 | 4: 1 2 | -------------------------------------------------------------------------------- /test/test-picoc/68_return.expect: -------------------------------------------------------------------------------- 1 | Here's a print statement before quitting. 2 | returning; there should be no further output. 3 | -------------------------------------------------------------------------------- /test/test-picoc/69_shebang_script.c: -------------------------------------------------------------------------------- 1 | #! 2 | -------------------------------------------------------------------------------- /test/test-picoc/69_shebang_script.expect: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kcs/c2d116feb9591fce9260439f11e07a152ccc62c4/test/test-picoc/69_shebang_script.expect -------------------------------------------------------------------------------- /test/test-picoc/check.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | if "%1"=="fail" goto SHIFTED_ERROR 3 | SET DETAIL=false 4 | if "%1"=="detail" goto SHIFTED 5 | goto TEST_CHECK 6 | 7 | :SHIFTED_ERROR 8 | shift 9 | goto ERROR 10 | 11 | :SHIFTED 12 | SET DETAIL=true 13 | shift 14 | 15 | :TEST_CHECK 16 | %CC% %1 %2 %3 %4 %5 %6 %7 %8 %9 > result.txt 17 | fc result.txt %~dpn1.expect > NUL 2>&1 18 | if ERRORLEVEL 1 goto ERROR 19 | REM type result.txt 20 | ECHO Test Passed: %~n1 21 | del result.txt 22 | exit /b 0 23 | 24 | :ERROR 25 | ECHO *** Test Failed: %~n1 26 | if "%DETAIL%"=="true" fc result.txt %~dpn1.expect 27 | exit /b 1 28 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand1.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 21F8EACC 2 | ...checksum after hashing g_7 : CCC413BE 3 | before stmt(6): checksum = CCC413BE 4 | ...checksum after hashing g_2 : 2144DF1C 5 | ...checksum after hashing g_7 : 80406CE8 6 | before stmt(4): checksum = 80406CE8 7 | ...checksum after hashing g_2 : 2144DF1C 8 | ...checksum after hashing g_7 : 7E73FB15 9 | before stmt(5): checksum = 7E73FB15 10 | ...checksum after hashing g_2 : 2144DF1C 11 | ...checksum after hashing g_7 : 7E73FB15 12 | checksum = 7e73fb15 13 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand10.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_6 : 3A4BD710 2 | before stmt(1): checksum = 3A4BD710 3 | ...checksum after hashing g_6 : A9360626 4 | before stmt(2): checksum = A9360626 5 | ...checksum after hashing g_6 : A9360626 6 | checksum = a9360626 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand100.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand102.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 2144DF1C 2 | ...checksum after hashing g_5 : EF1A5D2A 3 | before stmt(1): checksum = EF1A5D2A 4 | ...checksum after hashing g_2 : 2144DF1C 5 | ...checksum after hashing g_5 : 6522DF69 6 | before stmt(2): checksum = 6522DF69 7 | ...checksum after hashing g_2 : 2144DF1C 8 | ...checksum after hashing g_5 : 6522DF69 9 | checksum = 6522df69 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand103.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_5 : 42013849 2 | before stmt(1): checksum = 42013849 3 | ...checksum after hashing g_5 : 42013849 4 | before stmt(2): checksum = 42013849 5 | ...checksum after hashing g_5 : 42013849 6 | checksum = 42013849 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand105.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_4 : DA94A023 2 | ...checksum after hashing g_5 : E4E064A 3 | before stmt(1): checksum = E4E064A 4 | ...checksum after hashing g_4 : 99F8B879 5 | ...checksum after hashing g_5 : 9E562FC5 6 | before stmt(2): checksum = 9E562FC5 7 | ...checksum after hashing g_4 : 99F8B879 8 | ...checksum after hashing g_5 : 9E562FC5 9 | before stmt(3): checksum = 9E562FC5 10 | ...checksum after hashing g_4 : 99F8B879 11 | ...checksum after hashing g_5 : 9E562FC5 12 | checksum = 9e562fc5 13 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand18.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand20.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 709D68A8 2 | ...checksum after hashing g_66 : 878CF3C0 3 | before stmt(156): checksum = 878CF3C0 4 | ...checksum after hashing g_2 : 4EF93F78 5 | ...checksum after hashing g_66 : 8DBC164 6 | before stmt(157): checksum = 8DBC164 7 | ...checksum after hashing g_2 : 4EF93F78 8 | ...checksum after hashing g_66 : 8DBC164 9 | before stmt(158): checksum = 8DBC164 10 | ...checksum after hashing g_2 : 4EF93F78 11 | ...checksum after hashing g_66 : 8DBC164 12 | before stmt(159): checksum = 8DBC164 13 | ...checksum after hashing g_2 : 4EF93F78 14 | ...checksum after hashing g_66 : 8DBC164 15 | checksum = 8dbc164 16 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand22.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : FEDD6B44 2 | before stmt(1): checksum = FEDD6B44 3 | ...checksum after hashing g_2 : FEDD6B44 4 | checksum = fedd6b44 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand30.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_5 : 6228C746 2 | ...checksum after hashing g_6 : F53AF6E6 3 | before stmt(1): checksum = F53AF6E6 4 | ...checksum after hashing g_5 : 2144DF1C 5 | ...checksum after hashing g_6 : 6522DF69 6 | before stmt(2): checksum = 6522DF69 7 | ...checksum after hashing g_5 : 2144DF1C 8 | ...checksum after hashing g_6 : 6522DF69 9 | checksum = 6522df69 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand31.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 3AF5F102 2 | before stmt(1): checksum = 3AF5F102 3 | ...checksum after hashing g_2 : 3AF5F102 4 | checksum = 3af5f102 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand32.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 6EB49C38 2 | ...checksum after hashing g_8 : 23198C4F 3 | before stmt(5): checksum = 23198C4F 4 | ...checksum after hashing g_2 : 2144DF1C 5 | ...checksum after hashing g_8 : 8C4A3A03 6 | before stmt(4): checksum = 8C4A3A03 7 | ...checksum after hashing g_2 : 2144DF1C 8 | ...checksum after hashing g_8 : 8C4A3A03 9 | checksum = 8c4a3a03 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand33.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_13 : A0BB2A5F 2 | ...checksum after hashing g_15 : 22A53F2D 3 | before stmt(1): checksum = 22A53F2D 4 | ...checksum after hashing g_13 : 99F8B879 5 | ...checksum after hashing g_15 : DD3A379F 6 | before stmt(2): checksum = DD3A379F 7 | ...checksum after hashing g_13 : 99F8B879 8 | ...checksum after hashing g_15 : 1134B892 9 | before stmt(3): checksum = 1134B892 10 | ...checksum after hashing g_13 : 99F8B879 11 | ...checksum after hashing g_15 : 1134B892 12 | before stmt(4): checksum = 1134B892 13 | ...checksum after hashing g_13 : 99F8B879 14 | ...checksum after hashing g_15 : 1134B892 15 | checksum = 1134b892 16 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand34.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_4 : FC626330 2 | before stmt(1): checksum = FC626330 3 | ...checksum after hashing g_4 : FC626330 4 | before stmt(2): checksum = FC626330 5 | ...checksum after hashing g_4 : FC626330 6 | checksum = fc626330 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand37.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : FFFFFFFF 2 | before stmt(1): checksum = FFFFFFFF 3 | ...checksum after hashing g_3 : FFFFFFFF 4 | before stmt(2): checksum = FFFFFFFF 5 | ...checksum after hashing g_3 : FFFFFFFF 6 | checksum = ffffffff 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand4.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 6C2C6BC2 2 | before stmt(1): checksum = 6C2C6BC2 3 | ...checksum after hashing g_2 : 6C2C6BC2 4 | checksum = 6c2c6bc2 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand45.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand46.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 95BECAFF 2 | before stmt(1): checksum = 95BECAFF 3 | ...checksum after hashing g_2 : 95BECAFF 4 | checksum = 95becaff 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand48.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 589C16F5 2 | before stmt(1): checksum = 589C16F5 3 | ...checksum after hashing g_2 : 589C16F5 4 | checksum = 589c16f5 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand5.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand51.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_4 : 99F8B879 2 | ...checksum after hashing g_23 : A1F2983E 3 | before stmt(1): checksum = A1F2983E 4 | ...checksum after hashing g_4 : FFFFFFFF 5 | ...checksum after hashing g_23 : F785B836 6 | before stmt(2): checksum = F785B836 7 | ...checksum after hashing g_4 : FFFFFFFF 8 | ...checksum after hashing g_23 : 4F39DF53 9 | before stmt(3): checksum = 4F39DF53 10 | ...checksum after hashing g_4 : FFFFFFFF 11 | ...checksum after hashing g_23 : 4F39DF53 12 | checksum = 4f39df53 13 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand53.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand55.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand56.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : C2E54802 2 | ...checksum after hashing g_13 : B27BA86E 3 | before stmt(1): checksum = B27BA86E 4 | ...checksum after hashing g_3 : C2E54802 5 | ...checksum after hashing g_13 : AC7CF0B 6 | before stmt(2): checksum = AC7CF0B 7 | ...checksum after hashing g_3 : C2E54802 8 | ...checksum after hashing g_13 : AC7CF0B 9 | checksum = ac7cf0b 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand57.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_4 : C41578FF 2 | before stmt(1): checksum = C41578FF 3 | ...checksum after hashing g_4 : FFFFFFFF 4 | before stmt(2): checksum = FFFFFFFF 5 | ...checksum after hashing g_4 : FFFFFFFF 6 | checksum = ffffffff 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand58.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : 8E1FD904 2 | ...checksum after hashing g_7 : 2E90CEA2 3 | before stmt(1): checksum = 2E90CEA2 4 | ...checksum after hashing g_3 : 8E1FD904 5 | ...checksum after hashing g_7 : 962CA9C7 6 | before stmt(2): checksum = 962CA9C7 7 | ...checksum after hashing g_3 : 8E1FD904 8 | ...checksum after hashing g_7 : 962CA9C7 9 | checksum = 962ca9c7 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand59.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_6[i] : 99F8B879 2 | index = [0] 3 | before stmt(1): checksum = 99F8B879 4 | ...checksum after hashing g_6[i] : 2144DF1C 5 | index = [0] 6 | before stmt(2): checksum = 2144DF1C 7 | ...checksum after hashing g_6[i] : 2144DF1C 8 | index = [0] 9 | checksum = 2144df1c 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand62.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : 59ED14B9 2 | ...checksum after hashing g_9 : 861DEE8D 3 | ...checksum after hashing g_10 : 8FD9D688 4 | before stmt(1): checksum = 8FD9D688 5 | ...checksum after hashing g_3 : 59ED14B9 6 | ...checksum after hashing g_9 : 861DEE8D 7 | ...checksum after hashing g_10 : 3765B1ED 8 | before stmt(2): checksum = 3765B1ED 9 | ...checksum after hashing g_3 : 59ED14B9 10 | ...checksum after hashing g_9 : 861DEE8D 11 | ...checksum after hashing g_10 : 3765B1ED 12 | checksum = 3765b1ed 13 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand63.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 99F8B879 2 | before stmt(1): checksum = 99F8B879 3 | ...checksum after hashing g_2 : 99F8B879 4 | checksum = 99f8b879 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand64.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : 99F8B879 2 | before stmt(1): checksum = 99F8B879 3 | ...checksum after hashing g_3 : 99F8B879 4 | before stmt(2): checksum = 99F8B879 5 | ...checksum after hashing g_3 : 99F8B879 6 | checksum = 99f8b879 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand65.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : D3B2FBCA 2 | ...checksum after hashing g_4 : 75AE5697 3 | before stmt(1): checksum = 75AE5697 4 | ...checksum after hashing g_2 : D3B2FBCA 5 | ...checksum after hashing g_4 : D38C0442 6 | before stmt(2): checksum = D38C0442 7 | ...checksum after hashing g_2 : D3B2FBCA 8 | ...checksum after hashing g_4 : D38C0442 9 | checksum = d38c0442 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand67.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : DDD9C989 2 | before stmt(1): checksum = DDD9C989 3 | ...checksum after hashing g_2 : DDD9C989 4 | checksum = ddd9c989 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand68.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 709D68A8 2 | before stmt(5): checksum = 709D68A8 3 | ...checksum after hashing g_2 : 2144DF1C 4 | before stmt(4): checksum = 2144DF1C 5 | ...checksum after hashing g_2 : 2144DF1C 6 | checksum = 2144df1c 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand69.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand7.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 7DA58FB2 2 | ...checksum after hashing g_4 : EEF9C0D4 3 | before stmt(1): checksum = EEF9C0D4 4 | ...checksum after hashing g_2 : 7DA58FB2 5 | ...checksum after hashing g_4 : DD731033 6 | before stmt(2): checksum = DD731033 7 | ...checksum after hashing g_2 : 7DA58FB2 8 | ...checksum after hashing g_4 : DD731033 9 | checksum = dd731033 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand70.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : 5E931C1C 2 | before stmt(1): checksum = 5E931C1C 3 | ...checksum after hashing g_3 : 99F8B879 4 | before stmt(6): checksum = 99F8B879 5 | ...checksum after hashing g_3 : 82F7B075 6 | before stmt(7): checksum = 82F7B075 7 | ...checksum after hashing g_3 : 82F7B075 8 | before stmt(8): checksum = 82F7B075 9 | ...checksum after hashing g_3 : 82F7B075 10 | checksum = 82f7b075 11 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand71.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 10A543AE 2 | before stmt(1): checksum = 10A543AE 3 | ...checksum after hashing g_2 : 10A543AE 4 | checksum = 10a543ae 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand72.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_4 : 99F8B879 2 | before stmt(1): checksum = 99F8B879 3 | ...checksum after hashing g_4 : 99F8B879 4 | before stmt(2): checksum = 99F8B879 5 | ...checksum after hashing g_4 : 99F8B879 6 | checksum = 99f8b879 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand74.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 33F170F2 2 | before stmt(1): checksum = 33F170F2 3 | ...checksum after hashing g_2 : 33F170F2 4 | checksum = 33f170f2 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand75.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : 709D68A8 2 | ...checksum after hashing g_17 : 11792F75 3 | before stmt(1): checksum = 11792F75 4 | ...checksum after hashing g_3 : 709D68A8 5 | ...checksum after hashing g_17 : A9C54810 6 | before stmt(2): checksum = A9C54810 7 | ...checksum after hashing g_3 : 709D68A8 8 | ...checksum after hashing g_17 : A9C54810 9 | checksum = a9c54810 10 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand76.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : F8E7C17F 2 | ...checksum after hashing g_4 : EC2203A9 3 | before stmt(1): checksum = EC2203A9 4 | ...checksum after hashing g_2 : F8E7C17F 5 | ...checksum after hashing g_4 : 549E64CC 6 | before stmt(2): checksum = 549E64CC 7 | ...checksum after hashing g_2 : F8E7C17F 8 | ...checksum after hashing g_4 : 9890EBC1 9 | before stmt(3): checksum = 9890EBC1 10 | ...checksum after hashing g_2 : F8E7C17F 11 | ...checksum after hashing g_4 : 9890EBC1 12 | checksum = 9890ebc1 13 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand77.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 51C84373 2 | before stmt(1): checksum = 51C84373 3 | ...checksum after hashing g_2 : 51C84373 4 | checksum = 51c84373 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand78.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand79.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : 2144DF1C 2 | before stmt(5): checksum = 2144DF1C 3 | ...checksum after hashing g_2 : 709D68A8 4 | before stmt(4): checksum = 709D68A8 5 | ...checksum after hashing g_2 : 709D68A8 6 | checksum = 709d68a8 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand81.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand86.expect: -------------------------------------------------------------------------------- 1 | before stmt(1): checksum = 0 2 | checksum = 0 3 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand89.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : B8EA74BD 2 | before stmt(1): checksum = B8EA74BD 3 | ...checksum after hashing g_3 : B8EA74BD 4 | before stmt(2): checksum = B8EA74BD 5 | ...checksum after hashing g_3 : B8EA74BD 6 | checksum = b8ea74bd 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand90.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_4 : 9C78C8D1 2 | before stmt(1): checksum = 9C78C8D1 3 | ...checksum after hashing g_4 : 9C78C8D1 4 | before stmt(2): checksum = 9C78C8D1 5 | ...checksum after hashing g_4 : 9C78C8D1 6 | before stmt(3): checksum = 9C78C8D1 7 | ...checksum after hashing g_4 : 9C78C8D1 8 | checksum = 9c78c8d1 9 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand91.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_2 : EDF47603 2 | before stmt(1): checksum = EDF47603 3 | ...checksum after hashing g_2 : EDF47603 4 | checksum = edf47603 5 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand93.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_3 : D89B59D1 2 | before stmt(1): checksum = D89B59D1 3 | ...checksum after hashing g_3 : D89B59D1 4 | before stmt(2): checksum = D89B59D1 5 | ...checksum after hashing g_3 : D89B59D1 6 | checksum = d89b59d1 7 | -------------------------------------------------------------------------------- /test/test-picoc/csmith/rand98.expect: -------------------------------------------------------------------------------- 1 | ...checksum after hashing g_5 : FFFFFFFF 2 | before stmt(4): checksum = FFFFFFFF 3 | ...checksum after hashing g_5 : FFFFFFFF 4 | before stmt(2): checksum = FFFFFFFF 5 | ...checksum after hashing g_5 : FFFFFFFF 6 | before stmt(3): checksum = FFFFFFFF 7 | ...checksum after hashing g_5 : FFFFFFFF 8 | before stmt(5): checksum = FFFFFFFF 9 | ...checksum after hashing g_5 : FFFFFFFF 10 | checksum = ffffffff 11 | -------------------------------------------------------------------------------- /test/test-picoc/skip.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM ECHO Skipping Tests(%~n1) because %~2 3 | exit /b 0 4 | -------------------------------------------------------------------------------- /test/test-picoc/test.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | pushd %~dp0 3 | call basic.cmd %1 4 | popd 5 | -------------------------------------------------------------------------------- /test/test-qcc/ary.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int a[10]; 3 | a[1] = 65; 4 | char s[10]; 5 | s[0] = a[1]; 6 | int b[4] = {1, 3, 5, 12}; 7 | if(b[0] != 1) return 1; 8 | if(b[1] != 3) return 1; 9 | if(b[2] != 5) return 1; 10 | if(b[3] != 12) return 1; 11 | return 0; 12 | } 13 | 14 | #include "main.c" 15 | -------------------------------------------------------------------------------- /test/test-qcc/block.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int i = 2; 3 | { 4 | int i = 3; 5 | } 6 | if(i == 2) return 0; 7 | return 1; 8 | } 9 | 10 | #include "main.c" 11 | -------------------------------------------------------------------------------- /test/test-qcc/brk_ctn.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int count = 0; 3 | for(int i = 0; i < 10; i++) { 4 | if(i == 2) continue; 5 | if(i == 5) break; 6 | count++; 7 | } 8 | return count != 4; 9 | } 10 | 11 | #include "main.c" 12 | -------------------------------------------------------------------------------- /test/test-qcc/cast.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int f = (int)1.32; 3 | struct { int a, b; } *s; 4 | void *vs = (void *)s; 5 | if(f != 1) return 1; 6 | return 0; 7 | } 8 | 9 | #include "main.c" 10 | -------------------------------------------------------------------------------- /test/test-qcc/check.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | if "%1"=="fail" goto SHIFTED_ERROR 3 | SET DETAIL=false 4 | if "%1"=="detail" goto SHIFTED 5 | goto TEST_CHECK 6 | 7 | :SHIFTED_ERROR 8 | shift 9 | goto ERROR 10 | 11 | :SHIFTED 12 | SET DETAIL=true 13 | shift 14 | 15 | :TEST_CHECK 16 | %CC% -DTEST_NAME="%~n1" %1 %2 %3 %4 %5 %6 %7 %8 %9 17 | if ERRORLEVEL 1 goto ERROR 18 | REM type result.txt 19 | ECHO Test Passed: %~n1 20 | exit /b 0 21 | 22 | :ERROR 23 | ECHO *** Test Failed: %~n1 24 | exit /b 1 25 | -------------------------------------------------------------------------------- /test/test-qcc/ctrl.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int i; 3 | i = 0; 4 | while(i < 10) { 5 | if(i % 2 == 0) { 6 | } else { 7 | } 8 | i += 1; 9 | } 10 | return 0; 11 | } 12 | 13 | #include "main.c" 14 | -------------------------------------------------------------------------------- /test/test-qcc/fcall.c: -------------------------------------------------------------------------------- 1 | int f() { 2 | return 123; 3 | } 4 | 5 | int test() { 6 | int ret; 7 | ret = f(); 8 | return 0; 9 | } 10 | 11 | #include "main.c" 12 | -------------------------------------------------------------------------------- /test/test-qcc/float.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | double x = 2; 3 | x /= 3; 4 | int false1 = 0.2 > x; 5 | int true1 = 0.3 < x; 6 | int true2 = 0.3 != 3.2; 7 | return 8 | ( 9 | true1 && 10 | true2 && 11 | false1 == 0) ? 0 : 1; 12 | } 13 | 14 | #include "main.c" 15 | -------------------------------------------------------------------------------- /test/test-qcc/for.c: -------------------------------------------------------------------------------- 1 | void loop() { 2 | for(int i = 0; i < 10; i++) 3 | i + 2; 4 | return; 5 | } 6 | 7 | int test() { 8 | int i, sum; 9 | sum = 0; 10 | loop(); 11 | for(i = 1; i <= 10; i += 1) 12 | sum += i; 13 | return 0; 14 | } 15 | 16 | #include "main.c" 17 | -------------------------------------------------------------------------------- /test/test-qcc/funcptr.c: -------------------------------------------------------------------------------- 1 | int add(int a, int b) { 2 | return a + b; 3 | } 4 | 5 | int test() { 6 | int (*fnptr)(int, int) = add; 7 | return fnptr(2, 3) == 5 ? 0 : 1; 8 | } 9 | 10 | #include "main.c" 11 | -------------------------------------------------------------------------------- /test/test-qcc/globalv.c: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | int a; 3 | } A; 4 | 5 | A a1, a2; 6 | int a[2], i = 100; 7 | char *s; 8 | 9 | int test() { 10 | return 0; 11 | } 12 | 13 | #include "main.c" 14 | -------------------------------------------------------------------------------- /test/test-qcc/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define TNS(name) "test " #name 4 | #define TN(name) TNS(name) 5 | 6 | int main(void) { 7 | int ret_code = test(); 8 | // if(ret_code == 0) 9 | // printf(TN(TEST_NAME) " ... OK\n"); 10 | // else 11 | // printf(TN(TEST_NAME) " ... FAILED\n"); 12 | return ret_code; 13 | } 14 | -------------------------------------------------------------------------------- /test/test-qcc/op.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | 1 + 2; 3 | 3 * 4; 4 | 2 & 1; 5 | return 0; 6 | } 7 | 8 | #include "main.c" 9 | -------------------------------------------------------------------------------- /test/test-qcc/ptr.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int a, *b; 3 | a = 10; 4 | b = &a; 5 | *b = 100; 6 | a++; 7 | return 0; 8 | } 9 | 10 | #include "main.c" 11 | -------------------------------------------------------------------------------- /test/test-qcc/sizeof.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int int_size = sizeof(int); 3 | int char_size = sizeof(char); 4 | int ptr_size = sizeof(int *); 5 | int ary_size = sizeof(int [10]); 6 | return 0; 7 | } 8 | 9 | #include "main.c" 10 | -------------------------------------------------------------------------------- /test/test-qcc/ternary.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int i = 1; 3 | if((i == 1 ? 2 : 3) != 2) return 1; 4 | return 0; 5 | } 6 | 7 | #include "main.c" 8 | -------------------------------------------------------------------------------- /test/test-qcc/test.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | SET OPT=-x 3 | if NOT "%1" == "" SET OPT=%1 4 | SET CC=..\..\kcc.exe %OPT% 5 | SET TEST=check.cmd detail 6 | SET SKIP=skip.cmd 7 | 8 | pushd %~dp0 9 | call %TEST% ary.c 10 | call %TEST% block.c 11 | call %TEST% brk_ctn.c 12 | call %TEST% cast.c 13 | call %TEST% ctrl.c 14 | call %TEST% fcall.c 15 | call %TEST% float.c 16 | call %TEST% for.c 17 | call %TEST% funcptr.c 18 | call %TEST% globalv.c 19 | call %TEST% op.c 20 | call %TEST% ptr.c 21 | call %TEST% sizeof.c 22 | call %TEST% struct.c 23 | call %TEST% ternary.c 24 | call %TEST% var.c 25 | popd 26 | -------------------------------------------------------------------------------- /test/test-qcc/var.c: -------------------------------------------------------------------------------- 1 | int test() { 2 | int a, b, c, i = 10; 3 | a = b = c = 100 + i; 4 | { 5 | int q = 10; 6 | } 7 | int x[] = {1, 2}; 8 | return 0; 9 | } 10 | 11 | #include "main.c" 12 | --------------------------------------------------------------------------------