├── .gitattributes ├── .github └── workflows │ ├── c-cpp.yml │ ├── main.yml │ ├── scoop-bucket-update.yml │ └── unit-test.yml ├── .gitignore ├── .gitmodules ├── .spectest ├── ChangeLog.md ├── ChangeLog_v1.0.x.md ├── ChangeLog_v1.1.x.md ├── LICENSE ├── Makefile ├── README.md ├── bin └── checkver.ps1 ├── bucket └── kinx.json ├── build ├── Makefile ├── Makefile.msc ├── description-pak ├── kinx.rc ├── kinxi.ico ├── make.cmd ├── mkdeb.sh ├── template │ ├── install.nsi │ ├── kinx.rc │ ├── mkdeb.sh │ ├── theme │ │ └── standard │ │ │ ├── installer.ico │ │ │ ├── installer.png │ │ │ ├── uninstaller.ico │ │ │ ├── uninstaller.png │ │ │ ├── wizard-uninst.bmp │ │ │ └── wizard.bmp │ └── version.h └── utility │ ├── VersionSetup.kx │ ├── install.sh │ ├── kmyacc │ ├── kmyacc.c.parser │ ├── kmyacc.exe │ ├── package_win64.kx │ └── src │ ├── addpath.c │ ├── kecho.c │ └── timex.c ├── docs ├── HowClassWorks.md ├── InstallerWelcome.png ├── Kip.md ├── Package.md ├── QuickReference.md ├── Reference │ ├── Exception │ │ └── RuntimeException.md │ ├── Object │ │ ├── Array.md │ │ ├── Binary.md │ │ ├── Double.md │ │ ├── File.md │ │ ├── Integer.md │ │ ├── Math.md │ │ ├── Regex.md │ │ ├── String.md │ │ ├── System.md │ │ └── SystemTimer.md │ └── _Index.md ├── _config.yml ├── benchmark │ ├── .spectest │ └── README.md ├── fibkx.png ├── index.md ├── kinx.png ├── kinxlogo.png ├── licenses │ ├── LICENSE.ansicolor_32 │ ├── LICENSE.bigz │ ├── LICENSE.duktape │ ├── LICENSE.dynzasm │ ├── LICENSE.getopt │ ├── LICENSE.klib │ ├── LICENSE.libclipboard │ ├── LICENSE.libpng │ ├── LICENSE.miniyacc │ ├── LICENSE.minizip │ ├── LICENSE.oniguruma │ ├── LICENSE.picosat │ ├── LICENSE.sljit │ ├── LICENSE.sqlite3 │ ├── LICENSE.udis86 │ ├── LICENSE.webview │ └── LICENSE.xsel ├── spec │ ├── algorithm │ │ ├── README.md │ │ ├── cannibal.md │ │ ├── crc32.md │ │ ├── heapsort.md │ │ ├── knight.md │ │ ├── lifegame.md │ │ ├── mandelbrot.md │ │ ├── mergesort.md │ │ ├── nqueens.md │ │ ├── qsort.md │ │ └── satsolver.md │ ├── command │ │ └── arguments.md │ ├── definition │ │ ├── class.md │ │ ├── closure.md │ │ ├── fiber.md │ │ ├── function.md │ │ ├── lambda.md │ │ ├── module.md │ │ ├── native.md │ │ └── native │ │ │ ├── array.md │ │ │ ├── math.md │ │ │ ├── native_expr.md │ │ │ ├── switch_case.md │ │ │ └── switch_when.md │ ├── images │ │ ├── colorize_example.png │ │ └── string_color.png │ ├── lib │ │ ├── basic │ │ │ ├── clipboard.md │ │ │ ├── colorize.md │ │ │ ├── csv_tsv.md │ │ │ ├── datetime.md │ │ │ ├── directory.md │ │ │ ├── enumerable.md │ │ │ ├── file.md │ │ │ ├── functional.md │ │ │ ├── getopt.md │ │ │ ├── iconv.md │ │ │ ├── imath.md │ │ │ ├── jit.md │ │ │ ├── json.md │ │ │ ├── parsek.md │ │ │ ├── process.md │ │ │ ├── range.md │ │ │ ├── regex.md │ │ │ ├── semanticver.md │ │ │ ├── sqlite.md │ │ │ ├── system.md │ │ │ ├── xml.md │ │ │ └── zip.md │ │ ├── function │ │ │ ├── define_exception.md │ │ │ └── eval.md │ │ ├── net │ │ │ ├── http.md │ │ │ └── ssh.md │ │ └── primitive │ │ │ ├── array.md │ │ │ ├── binary.md │ │ │ ├── double.md │ │ │ ├── exception.md │ │ │ ├── integer.md │ │ │ └── string.md │ ├── others │ │ ├── bugfixes.md │ │ ├── realnumber.md │ │ ├── string_isIntegerString.md │ │ └── string_next.md │ ├── spectest │ │ └── README.md │ └── statement │ │ ├── block.md │ │ ├── declaration.md │ │ ├── do_while.md │ │ ├── enum.md │ │ ├── expression.md │ │ ├── expression │ │ ├── add_sub.md │ │ ├── assign.md │ │ ├── bit_and.md │ │ ├── bit_or.md │ │ ├── bit_shift.md │ │ ├── bit_xor.md │ │ ├── case_when.md │ │ ├── comparison.md │ │ ├── equals.md │ │ ├── exponent.md │ │ ├── function_composition.md │ │ ├── logical_and.md │ │ ├── logical_or.md │ │ ├── logical_undef.md │ │ ├── matching.md │ │ ├── mul_div.md │ │ ├── pipeline.md │ │ ├── postfix.md │ │ ├── range.md │ │ ├── ternary.md │ │ ├── typecheck.md │ │ └── unary.md │ │ ├── for.md │ │ ├── for_in.md │ │ ├── if_else.md │ │ ├── mixin.md │ │ ├── namespace.md │ │ ├── return.md │ │ ├── switch_case.md │ │ ├── switch_when.md │ │ ├── throw.md │ │ ├── try_catch_finally.md │ │ ├── using.md │ │ ├── while.md │ │ └── yield.md ├── spectest.png └── utility │ ├── debugger.md │ ├── images │ ├── debugger.png │ ├── debugger_d.png │ └── repl.gif │ └── repl.md ├── examples ├── ansicolor.kx ├── apply.kx ├── args.kx ├── array_sort.kx ├── arrayobj.kx ├── bench │ ├── fib.py │ ├── fib.py3 │ ├── fib.rb │ ├── mergesort.kx │ ├── mergesort.py │ ├── mergesort.rb │ ├── qsort.kx │ ├── qsort.py │ └── qsort.rb ├── binary.kx ├── blockfunc.kx ├── bubsort.kx ├── c │ ├── callback.c │ ├── runkinx.c │ └── sharedlib.c ├── cannibal.kx ├── class1.kx ├── class2.kx ├── class3.kx ├── closure.kx ├── colorize.kx ├── csv.kx ├── csv1.csv ├── database.kx ├── datetime.kx ├── do_while.kx ├── double.kx ├── enumerable.kx ├── esc │ ├── progress.kx │ ├── sample1.kx │ ├── sample2.kx │ ├── sample3.kx │ ├── sample4.kx │ ├── sample5.kx │ └── sample6.kx ├── eval.kx ├── fact.kx ├── fib.kx ├── fib2.kx ├── fib_n.kx ├── fiber.kx ├── finally_return.kx ├── finally_throw.kx ├── for.kx ├── hanoi.kx ├── heapsort.kx ├── http.kx ├── iconv.kx ├── idprop.kx ├── initialize.kx ├── inner.kx ├── inssort.kx ├── instanceOf.kx ├── integer.kx ├── isolate1.kx ├── isolate2.kx ├── jit_fib.kx ├── jit_x64.kx ├── jitclib.kx ├── jitx.kx ├── json.kx ├── knight.kx ├── lambda.kx ├── life.kx ├── magic4.kx ├── magicsq.kx ├── mandelbrot.kx ├── mandelbrotn.kx ├── mergsort.kx ├── methodMissing.kx ├── mixin.kx ├── modan_shogi.kx ├── namespacex.kx ├── native.kx ├── native_dbl.kx ├── native_fact.kx ├── native_fib.kx ├── native_label.kx ├── native_lex.kx ├── native_qsort.kx ├── native_sum.kx ├── native_swtch_case.kx ├── native_too_deep.kx ├── native_trycatch.kx ├── nqueens.kx ├── option.kx ├── parser.kx ├── parser2.kx ├── parser3.kx ├── pdf │ ├── arc.kx │ ├── encoding.kx │ ├── ext_gstate.kx │ ├── font.kx │ ├── fontwidth.kx │ ├── jp.kx │ ├── jp2.kx │ ├── sjis.txt │ └── text.kx ├── pipeline.kx ├── qsort.kx ├── regex.kx ├── regex2.kx ├── sample.kx ├── sat.kx ├── sat2.kx ├── sat_nqueens.kx ├── sat_numplace.kx ├── sat_raw.kx ├── signal.kx ├── slctsort.kx ├── spread.kx ├── sqlite.kx ├── ssh.kx ├── string.kx ├── string_each.kx ├── switch_case.kx ├── switch_when.kx ├── tcpclient.kx ├── tcpserver.kx ├── throw.kx ├── throw1.kx ├── throw2.kx ├── trycatch.kx ├── tsv.kx ├── tsv1.tsv ├── while.kx ├── xml.kx ├── xml_sample.xml └── zip.kx ├── include ├── ansicolor_w32.h ├── bign.h ├── bigz.h ├── dbg.h ├── fileutil.h ├── getopt.h ├── ir.h ├── jit.h ├── khash.h ├── kinx.h ├── klist.h ├── kstr.h ├── kutil.h ├── kvec.h ├── kxalloc.h ├── kxastobject.h ├── kxexec.h ├── kxiconv.h ├── kxirutil.h ├── kxnative.h ├── kxnet.h ├── kxoptimizer.h ├── kxthread.h ├── kxutf8.h ├── libkinx.h ├── parser.h ├── parser.tab.h ├── version.h └── webview.h ├── install.nsi ├── lib ├── exec │ ├── PathInstUtil.kx │ ├── etc │ │ └── kipmain.yml │ ├── kip.kx │ ├── kxrepl.kx │ ├── kxtest.kx │ ├── pathInst.kx │ ├── pathUninst.kx │ ├── repl.kx │ └── spectest.kx ├── std │ ├── CSV.kx │ ├── DateTime.kx │ ├── Jit.kx │ ├── LinkedList.kx │ ├── MarkdownConsole.kx │ ├── MarkdownParser.kx │ ├── Parsek.kx │ ├── PdfCore.kx │ ├── Process.kx │ ├── SatisfiablitySolver.kx │ ├── SemanticVersion.kx │ ├── WebView.kx │ ├── kxarray.kx │ ├── kxbinary.kx │ ├── kxenumerable.kx │ ├── kxexception.kx │ ├── kxfile.kx │ ├── kxfunctional.kx │ ├── kxgetopt.kx │ ├── kxisolate.kx │ ├── kxnet.kx │ ├── kxnumeric.kx │ ├── kxsqlite.kx │ ├── kxstartup.kx │ ├── kxstring.kx │ ├── kxsysutil.kx │ ├── kxxml.kx │ ├── net │ │ ├── Ssh.kx │ │ ├── http.kx │ │ └── socket.kx │ └── pkg │ │ └── Develop.kx └── webview │ └── materialize │ ├── LICENSE │ ├── README.md │ ├── css │ ├── fonts.css │ ├── materialize.css │ └── materialize.min.css │ ├── fonts │ ├── MaterialIcons-Regular.eot │ ├── MaterialIcons-Regular.ttf │ ├── MaterialIcons-Regular.woff │ └── MaterialIcons-Regular.woff2 │ └── js │ ├── materialize.js │ └── materialize.min.js ├── make.cmd └── src ├── allocator.c ├── alloccore.c ├── allocutil.c ├── ast_analyzer.c ├── ast_defdisp.c ├── ast_display.c ├── ast_gencode.c ├── ast_native.c ├── ast_object.c ├── bign.c ├── bigz.c ├── disasm-x64 ├── libudis86 │ ├── Makefile.am │ ├── decode.c │ ├── decode.h │ ├── extern.h │ ├── itab.c │ ├── itab.h │ ├── syn-att.c │ ├── syn-intel.c │ ├── syn.c │ ├── syn.h │ ├── types.h │ ├── udint.h │ └── udis86.c └── udis86.h ├── disasm ├── LICENSE ├── arch │ ├── arm │ │ ├── aload.c │ │ ├── aload.h │ │ ├── arm.c │ │ ├── arm.h │ │ ├── arm.ins │ │ ├── astrings.c │ │ └── astrings.h │ ├── mips │ │ ├── mips.c │ │ ├── mips.h │ │ ├── mips.ins │ │ ├── mload.c │ │ ├── mload.h │ │ ├── mstrings.c │ │ └── mstrings.h │ └── x86 │ │ ├── x64.ins │ │ ├── x86.c │ │ ├── x86.h │ │ ├── x86.ins │ │ ├── x86asm.c │ │ ├── x86asm.h │ │ ├── x86load.c │ │ ├── x86load.h │ │ ├── x86strings.c │ │ └── x86strings.h ├── common │ ├── common.h │ ├── file.c │ ├── file.h │ ├── table.c │ ├── table.h │ ├── trie.c │ └── trie.h ├── dis.c ├── dis.h ├── disas.c ├── disas.h ├── dss.c ├── dss.h ├── gen │ ├── Makefile │ ├── gen.c │ ├── gen.h │ └── x86.sym ├── lex.c ├── lex.h ├── main.c ├── spec │ ├── mips.spec │ └── x86.spec ├── sym.c └── sym.h ├── exec └── code │ ├── _except.inc │ ├── _impllist.md │ ├── _inlines.inc │ ├── add.inc │ ├── and.inc │ ├── append.inc │ ├── apply.inc │ ├── bnot.inc │ ├── call.inc │ ├── catch.inc │ ├── dec.inc │ ├── div.inc │ ├── enter.inc │ ├── eqeq.inc │ ├── ge.inc │ ├── gt.inc │ ├── haltnop.inc │ ├── inc.inc │ ├── jmp.inc │ ├── le.inc │ ├── lge.inc │ ├── lt.inc │ ├── mkary.inc │ ├── mod.inc │ ├── mul.inc │ ├── neg.inc │ ├── neq.inc │ ├── not.inc │ ├── or.inc │ ├── pop.inc │ ├── pow.inc │ ├── push.inc │ ├── regeq.inc │ ├── ret.inc │ ├── shl.inc │ ├── shr.inc │ ├── store.inc │ ├── sub.inc │ ├── throw.inc │ └── xor.inc ├── extlib ├── ansicolor │ └── ansicolor_w32.c ├── duktape │ ├── duk_config.h │ ├── duktape.c │ └── duktape.h ├── kc-json │ ├── .gitignore │ ├── Makefile │ ├── Makefile.msc │ ├── README.md │ ├── kc-json.c │ ├── kc-json.h │ ├── sample │ │ ├── sample.c │ │ ├── sample.json │ │ └── sample_ext1.json │ ├── src │ │ ├── kc-json.h │ │ ├── kc-json.y │ │ ├── string.c │ │ └── vector.c │ └── util │ │ ├── LICENSE.miniyacc │ │ └── myacc.c ├── kxarray.c ├── kxbinary.c ├── kxdebugger.c ├── kxdouble.c ├── kxfile.c ├── kxinteger.c ├── kxjit.c ├── kxmath.c ├── kxnet.c ├── kxpdf.c ├── kxprocess.c ├── kxregex.c ├── kxsqlite.c ├── kxssh.c ├── kxstring.c ├── kxsystem.c ├── kxwebview.c ├── kxxml.c ├── libclipboard │ ├── CMakeLists.txt │ ├── Doxyfile │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── cmake_uninstall.cmake.in │ ├── include │ │ ├── libclipboard-config.h.in │ │ └── libclipboard.h │ ├── libclipboard.pc.in │ ├── samples │ │ ├── CMakeLists.txt │ │ └── clipboard_sample1.c │ ├── src │ │ ├── clipboard_cocoa.c │ │ ├── clipboard_common.c │ │ ├── clipboard_win32.c │ │ └── clipboard_x11.c │ ├── xsel.c │ └── xsel.h ├── 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 │ │ ├── base.c │ │ ├── deluxe.c │ │ ├── dict_conv.py │ │ ├── fuzzer.options │ │ ├── libfuzzer-onig.cpp │ │ └── regset.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_back.c │ │ ├── test_options.c │ │ ├── test_regset.c │ │ ├── test_syntax.c │ │ ├── test_utf8.c │ │ ├── testc.c │ │ ├── testp.c │ │ └── testu.c │ ├── tis-ci │ │ ├── stub.c │ │ ├── test_back.config │ │ ├── test_regset.config │ │ ├── test_syntax.config │ │ ├── test_utf8.config │ │ ├── testc.config │ │ └── testu.config │ ├── tis.config │ └── windows │ │ └── testc.c ├── picosat │ ├── picosat.c │ └── picosat.h ├── sqlite │ ├── shell.c │ ├── sqlite3.c │ ├── sqlite3.def │ ├── sqlite3.h │ └── sqlite3ext.h ├── tinyweb │ └── tinyweb.c ├── version.md └── winiconv │ └── winiconv.c ├── fileutil.c ├── format.c ├── getopt.c ├── global.c ├── ir_aotcore.c ├── ir_aotdump.c ├── ir_dot.c ├── ir_dump.c ├── ir_exec.c ├── ir_exec.inl ├── ir_execdbg.c ├── ir_fix.c ├── ir_natutil.c ├── ir_util.c ├── jit ├── sljitConfig.h ├── sljitConfigInternal.h ├── sljitExecAllocator.c ├── sljitLir.c ├── sljitLir.h ├── sljitNativeARM_32.c ├── sljitNativeARM_64.c ├── sljitNativeARM_T2_32.c ├── sljitNativeMIPS_32.c ├── sljitNativeMIPS_64.c ├── sljitNativeMIPS_common.c ├── sljitNativePPC_32.c ├── sljitNativePPC_64.c ├── sljitNativePPC_common.c ├── sljitNativeSPARC_32.c ├── sljitNativeSPARC_common.c ├── sljitNativeTILEGX-encoder.c ├── sljitNativeTILEGX_64.c ├── sljitNativeX86_32.c ├── sljitNativeX86_64.c ├── sljitNativeX86_common.c ├── sljitProtExecAllocator.c └── sljitUtils.c ├── jit_util.c ├── kinx.y ├── kstr.c ├── lexer.c ├── loadlib.c ├── main.c ├── main_kxcmd.c ├── mainlib.c ├── nir_compile.c ├── nir_dot.c ├── nir_dump.c ├── optimizer ├── opt_cfold.c ├── opt_jumpx.c └── optimizer.c ├── parser.c └── string.c /.gitattributes: -------------------------------------------------------------------------------- 1 | # Kinx highlight is currently not supported but... 2 | *.kx text linguist-language=Kinx 3 | .spectest text linguist-language=JSON linguist-detectable 4 | 5 | # exclude files in directories below from github stats 6 | src/extlib/**/*.c linguist-vendored 7 | src/extlib/**/*.cpp linguist-vendored 8 | src/extlib/**/*.h linguist-vendored 9 | src/extlib/**/*.py linguist-vendored 10 | src/extlib/**/*.sh linguist-vendored 11 | src/extlib/**/*.bat linguist-vendored 12 | src/extlib/**/*.cmd linguist-vendored 13 | src/extlib/*/README.md -linguist-vendored 14 | src/extlib/*/x64/** -linguist-vendored binary 15 | -------------------------------------------------------------------------------- /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | with: 17 | submodules: recursive 18 | - name: make 19 | run: make 20 | -------------------------------------------------------------------------------- /.github/workflows/scoop-bucket-update.yml: -------------------------------------------------------------------------------- 1 | name: Update Scoop bucket 2 | 3 | on: 4 | release: 5 | types: [published] 6 | workflow_dispatch: 7 | branches: [main] 8 | 9 | jobs: 10 | update-bucket: 11 | runs-on: windows-latest 12 | steps: 13 | - name: install scoop 14 | run: | 15 | Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh') 16 | echo "$env:UserProfile\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append 17 | - uses: actions/checkout@main 18 | - name: update bucket 19 | run: bin\checkver.ps1 -Update 20 | - name: commit to main 21 | run: | 22 | git config --local user.email "action@github.com" 23 | git config --local user.name "GitHub Action" 24 | git add bucket/*.json 25 | git commit -m "update scoop bucket" 26 | - name: push 27 | uses: ad-m/github-push-action@v0.6.0 28 | with: 29 | github_token: ${{ secrets.GITHUB_TOKEN }} 30 | branch: main 31 | -------------------------------------------------------------------------------- /.github/workflows/unit-test.yml: -------------------------------------------------------------------------------- 1 | name: Unit Test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | with: 11 | submodules: recursive 12 | - name: install 13 | run: | 14 | cd build 15 | make 16 | sudo make install 17 | cd .. 18 | - name: run test 19 | run: kinx --exec:spectest -v 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Common rules 2 | *.exe 3 | *.obj 4 | *.dll 5 | *.exp 6 | *.map 7 | *.lib 8 | *.s 9 | *.output 10 | *.c.parser 11 | *.o 12 | *.a 13 | *.c 14 | *.so* 15 | *.dep 16 | *.zip 17 | *.pdb 18 | *.res 19 | *.db 20 | *.deb 21 | 22 | # Executables 23 | timex 24 | myacc 25 | kinx 26 | kxkitty 27 | kxrepl 28 | kxsel 29 | kxtest 30 | main_kxcmd 31 | 32 | # Temporary files 33 | timeit.dat 34 | temp* 35 | TEMP* 36 | kinx.map 37 | kx.tab.c 38 | kx.tab.h 39 | /memo.* 40 | /TEST.md 41 | /*.pdf 42 | /*.json 43 | /docs/userguide/*.json 44 | 45 | # Ignore build files 46 | /build/licenses 47 | /build/kinx 48 | /build/kxkitty 49 | /build/kxrepl 50 | /build/kxsel 51 | /build/kxtest 52 | /build/main_kxcmd 53 | 54 | # Ignore source files 55 | src/opt*.c 56 | src/extlib/onig 57 | src/extlib/libclipboard 58 | 59 | # Ignore files for disasm 60 | /x86.ins 61 | /x64.ins 62 | /mips.ins 63 | /arm.ins 64 | /x86.spec 65 | /mips.spec 66 | 67 | # Ignore folders 68 | /.vscode 69 | 70 | # Package configuration file. 71 | !/lib/package/ 72 | /lib/package/* 73 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/extlib/libmodules"] 2 | path = src/extlib/libmodules 3 | url = https://github.com/Kray-G/kinx-core-ext.git 4 | -------------------------------------------------------------------------------- /.spectest: -------------------------------------------------------------------------------- 1 | { 2 | "root": "docs", 3 | 4 | "testfile": "test.kx", 5 | "resultfile": "result.txt", 6 | "interpreter": "kinx", 7 | 8 | "ignoreFiles": [ 9 | "docs/spec/../benchmark/README.md", 10 | "docs/spec/spectest/README.md" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /ChangeLog_v1.1.x.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## V1.1.2 (Current Development Version) 4 | 5 | * Bug fixes 6 | * #360: Operator `<<` doesn't work for a string in a variable.. 7 | * #358: String doesn't work in JIT lib. 8 | 9 | ## V1.1.1 (Official Release) - 2021/12/27 10 | 11 | * Improvements/Enhancements 12 | * #352: JIT library enhancement. 13 | * [x] Support a string and a binary. 14 | * [x] Load a C function and use it. 15 | * [x] Direct write of a literal without Jit.IMM. 16 | * [x] Support mov8, mov16, mov32, fmov, and fmov32 for more flexible. 17 | 18 | ## V1.1.0 (Official Release) - 2021/12/06 19 | 20 | This is 1st official release version. 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2021 Kray-G 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Hook for build directory. 2 | 3 | all: 4 | (cd build; make) 5 | cp -f build/kinx ./ 6 | cp -f build/kxrepl ./ 7 | cp -f build/kxtest ./ 8 | cp -f build/kxsel ./ 9 | cp -f build/kip ./ 10 | cp -f build/*.so* ./ 11 | 12 | clean: 13 | (cd build; make clean) 14 | rm -f kinx 15 | rm -f kxrepl 16 | rm -f kxtest 17 | rm -f kxsel 18 | rm -f kip 19 | rm -f *.so* 20 | 21 | rebuild: 22 | (cd build; make clean all) 23 | cp -f build/kinx ./ 24 | cp -f build/kxrepl ./ 25 | cp -f build/kxtest ./ 26 | cp -f build/kxsel ./ 27 | cp -f build/kip ./ 28 | cp -f build/*.so* ./ 29 | 30 | install: 31 | (cd build; make install) 32 | 33 | -------------------------------------------------------------------------------- /bin/checkver.ps1: -------------------------------------------------------------------------------- 1 | if(!$env:SCOOP_HOME) { $env:SCOOP_HOME = resolve-path (split-path (split-path (scoop which scoop))) } 2 | $checkver = "$env:SCOOP_HOME/bin/checkver.ps1" 3 | $dir = "$psscriptroot/../bucket" # checks the parent dir 4 | Invoke-Expression -command "& '$checkver' -dir '$dir' $($args | ForEach-Object { "$_ " })" 5 | -------------------------------------------------------------------------------- /bucket/kinx.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.1", 3 | "description": "Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.", 4 | "homepage": "https://github.com/Kray-G/kinx", 5 | "license": "MIT", 6 | "architecture": { 7 | "64bit": { 8 | "url": "https://github.com/Kray-G/kinx/releases/download/v1.1.1/package_win64.zip", 9 | "hash": "ad30d11953bc6fb1bf89e1bf69a4107b1ea5c6c824e193e875a5dc8f5429482b" 10 | } 11 | }, 12 | "bin": [ 13 | "kinx.exe", 14 | "kxrepl.exe", 15 | "kxtest.exe", 16 | "kip.exe" 17 | ], 18 | "checkver": "github", 19 | "autoupdate": { 20 | "architecture": { 21 | "64bit": { 22 | "url": "https://github.com/Kray-G/kinx/releases/download/v$version/package_win64.zip" 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /build/description-pak: -------------------------------------------------------------------------------- 1 | Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers. 2 | -------------------------------------------------------------------------------- /build/kinx.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | KINXICO ICON "kinxi.ico" 4 | 5 | VS_VERSION_INFO VERSIONINFO 6 | FILEVERSION 1,1,1,0 7 | PRODUCTVERSION 1,1,1,0 8 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 9 | FILEFLAGS 0x00000000L 10 | FILEOS VOS__WINDOWS32 11 | FILETYPE VFT_APP 12 | FILESUBTYPE VFT2_UNKNOWN 13 | BEGIN 14 | BLOCK "VarFileInfo" 15 | BEGIN 16 | VALUE "Translation", 0x411, 1200 17 | END 18 | 19 | BLOCK "StringFileInfo" 20 | BEGIN 21 | BLOCK "041104B0" 22 | BEGIN 23 | VALUE "CompanyName", "-" 24 | VALUE "FileDescription", "The Script Kinx" 25 | VALUE "FileVersion", "1.1.1.0\0" 26 | VALUE "InternalName", "Kinx\0" 27 | VALUE "LegalCopyright", "Copyright (C) 2019-2021 Kray-G\0" 28 | VALUE "OriginalFilename", "kinx.exe\0" 29 | VALUE "ProductName", "Kinx\0" 30 | VALUE "ProductVersion", "1.1.1.0\0" 31 | END 32 | END 33 | END 34 | 35 | -------------------------------------------------------------------------------- /build/kinxi.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/kinxi.ico -------------------------------------------------------------------------------- /build/make.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if "%1" == "" ( 4 | if exist "..\kinx.exe" ( 5 | ..\kinx.exe utility\VersionSetup.kx 1.1.1 6 | ) 7 | cl.exe /DWINMAIN /Feaddpath.exe utility\src\addpath.c Advapi32.lib User32.lib /link /SUBSYSTEM:WINDOWS 8 | cl.exe /Feaddpathc.exe utility\src\addpath.c Advapi32.lib User32.lib 9 | cl.exe /Feecho.exe utility\src\kecho.c 10 | ) 11 | for /f "usebackq" %%A in (`git rev-parse HEAD`) do set VER_HASH=%%A 12 | 13 | mkdir licenses 14 | copy /y ..\docs\licenses\*.* licenses\*.* 15 | copy /y ..\src\extlib\libmodules\docs\licenses\*.* licenses\*.* 16 | 17 | if "%1" == "rebuild" goto REBUILD 18 | nmake -f Makefile.msc %* 19 | if ERRORLEVEL 1 goto ERROR 20 | goto END 21 | 22 | :REBUILD 23 | nmake -f Makefile.msc clean all 24 | if ERRORLEVEL 1 goto ERROR 25 | 26 | :END 27 | exit /b 0 28 | 29 | :ERROR 30 | exit /b 1 31 | -------------------------------------------------------------------------------- /build/mkdeb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt update 4 | apt install -y --no-install-recommends checkinstall 5 | 6 | checkinstall -D -y \ 7 | --install=no \ 8 | --fstrans=no \ 9 | --nodoc \ 10 | --reset-uids=yes \ 11 | --pkgname=kinx \ 12 | --pkgversion="1.1.1" \ 13 | --pkgrelease="0" \ 14 | --pkggroup="kinx" \ 15 | --arch=amd64 \ 16 | --pkglicense=MIT \ 17 | --maintainer="Kray-G" 18 | 19 | -------------------------------------------------------------------------------- /build/template/kinx.rc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | KINXICO ICON "kinxi.ico" 4 | 5 | VS_VERSION_INFO VERSIONINFO 6 | FILEVERSION $$VER_MAJ,$$VER_MIN,$$VER_PAT,0 7 | PRODUCTVERSION $$VER_MAJ,$$VER_MIN,$$VER_PAT,0 8 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 9 | FILEFLAGS 0x00000000L 10 | FILEOS VOS__WINDOWS32 11 | FILETYPE VFT_APP 12 | FILESUBTYPE VFT2_UNKNOWN 13 | BEGIN 14 | BLOCK "VarFileInfo" 15 | BEGIN 16 | VALUE "Translation", 0x411, 1200 17 | END 18 | 19 | BLOCK "StringFileInfo" 20 | BEGIN 21 | BLOCK "041104B0" 22 | BEGIN 23 | VALUE "CompanyName", "-" 24 | VALUE "FileDescription", "The Script Kinx" 25 | VALUE "FileVersion", "$$VER_MAJ.$$VER_MIN.$$VER_PAT.0\0" 26 | VALUE "InternalName", "Kinx\0" 27 | VALUE "LegalCopyright", "Copyright (C) 2019-2021 Kray-G\0" 28 | VALUE "OriginalFilename", "kinx.exe\0" 29 | VALUE "ProductName", "Kinx\0" 30 | VALUE "ProductVersion", "$$VER_MAJ.$$VER_MIN.$$VER_PAT.0\0" 31 | END 32 | END 33 | END 34 | -------------------------------------------------------------------------------- /build/template/mkdeb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt update 4 | apt install -y --no-install-recommends checkinstall 5 | 6 | checkinstall -D -y \ 7 | --install=no \ 8 | --fstrans=no \ 9 | --nodoc \ 10 | --reset-uids=yes \ 11 | --pkgname=kinx \ 12 | --pkgversion="$$VER_MAJ.$$VER_MIN.$$VER_PAT" \ 13 | --pkgrelease="0" \ 14 | --pkggroup="kinx" \ 15 | --arch=amd64 \ 16 | --pkglicense=MIT \ 17 | --maintainer="Kray-G" 18 | -------------------------------------------------------------------------------- /build/template/theme/standard/installer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/template/theme/standard/installer.ico -------------------------------------------------------------------------------- /build/template/theme/standard/installer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/template/theme/standard/installer.png -------------------------------------------------------------------------------- /build/template/theme/standard/uninstaller.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/template/theme/standard/uninstaller.ico -------------------------------------------------------------------------------- /build/template/theme/standard/uninstaller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/template/theme/standard/uninstaller.png -------------------------------------------------------------------------------- /build/template/theme/standard/wizard-uninst.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/template/theme/standard/wizard-uninst.bmp -------------------------------------------------------------------------------- /build/template/theme/standard/wizard.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/template/theme/standard/wizard.bmp -------------------------------------------------------------------------------- /build/template/version.h: -------------------------------------------------------------------------------- 1 | #ifndef KX_VERSION_H 2 | 3 | #if defined(_WIN32) || defined(_WIN64) 4 | #define PROGNAME "kinx.exe" 5 | #else 6 | #define PROGNAME "kinx" 7 | #endif 8 | #define VER_MAJ $$VER_MAJ 9 | #define VER_MIN $$VER_MIN 10 | #define VER_PAT $$VER_PAT 11 | #define VER_SUFFIX "" 12 | 13 | #endif /* KX_VERSION_H */ 14 | -------------------------------------------------------------------------------- /build/utility/VersionSetup.kx: -------------------------------------------------------------------------------- 1 | 2 | var Args; 3 | if ($$.length() == 2) { 4 | Args = $$[1].split('.'); 5 | } else if ($$.length() == 4) { 6 | Args = [$$[1], $$[2], $$[3]]; 7 | } else { 8 | System.println("Usage: kinx utility/%s .." % $$[0].filename()); 9 | return 1; 10 | } 11 | 12 | var version = { 13 | major: Args[0], 14 | minor: Args[1], 15 | patch: Args[2], 16 | }; 17 | System.println("Setup the version to: %d.%d.%d" 18 | % version.major 19 | % version.minor 20 | % version.patch 21 | ); 22 | 23 | function replace(infile, outfile) { 24 | var file = File.load(infile); 25 | var f = file 26 | .replace("$$VER_MAJ", ""+version.major) 27 | .replace("$$VER_MIN", ""+version.minor) 28 | .replace("$$VER_PAT", ""+version.patch); 29 | File.open(outfile, File.WRITE) { => _1.println(f) }; 30 | System.println("[OUT]: %-20s with %d.%d.%d" 31 | % outfile 32 | % version.major 33 | % version.minor 34 | % version.patch 35 | ); 36 | } 37 | 38 | replace("template/install.nsi", "../install.nsi"); 39 | replace("template/mkdeb.sh", "mkdeb.sh"); 40 | replace("template/kinx.rc", "kinx.rc"); 41 | replace("template/version.h", "../include/version.h"); 42 | -------------------------------------------------------------------------------- /build/utility/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d /usr/bin/kinxlib ]; then mkdir -p /usr/bin/kinxlib; fi; 4 | cp -f ./kinx /usr/bin/kinx 5 | cp -f ./kxrepl /usr/bin/kxrepl 6 | cp -f ./kxtest /usr/bin/kxtest 7 | cp -rf lib/* /usr/bin/kinxlib/ 8 | 9 | -------------------------------------------------------------------------------- /build/utility/kmyacc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/utility/kmyacc -------------------------------------------------------------------------------- /build/utility/kmyacc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/build/utility/kmyacc.exe -------------------------------------------------------------------------------- /build/utility/package_win64.kx: -------------------------------------------------------------------------------- 1 | var modules = [ 2 | "kinx.exe", 3 | "kx.lib", 4 | "libkinx.dll", 5 | "kxarray.dll", 6 | "kxbinary.dll", 7 | "kxdouble.dll", 8 | "kxfile.dll", 9 | "kxinteger.dll", 10 | "kxmath.dll", 11 | "kxnet.dll", 12 | "kxregex.dll", 13 | "kxsqlite.dll", 14 | "kxstring.dll", 15 | "kxsystem.dll", 16 | "kxxml.dll", 17 | "kxprocess.dll", 18 | "libcrypto-3.dll", 19 | "libssl-3.dll", 20 | "libxml2.dll", 21 | "onig.dll", 22 | "zlib.dll", 23 | "include/libkinx.h", 24 | "include/fileutil.h", 25 | "lib/", 26 | ]; 27 | 28 | const packageName = "package_win64.zip"; 29 | var zip = new Zip(packageName, File.READ|File.WRITE); 30 | modules.each(&(entry) => { 31 | System.print("Adding %-20s... " % entry); 32 | var tmr = new SystemTimer(); 33 | zip.addFile(entry); 34 | System.println("done, elapsed %6.3f s." % tmr.elapsed()); 35 | }); 36 | var size = File.filesize(packageName); 37 | System.println("- %s: Total %8.3f Mb (%d bytes)" % packageName % (size / 1024) % size); 38 | -------------------------------------------------------------------------------- /build/utility/src/kecho.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int ac, char **av) 4 | { 5 | if (ac < 2) { 6 | return 1; 7 | } 8 | printf("%s", av[1]); 9 | for (int i = 2; i < ac; ++i) { 10 | printf(" %s", av[i]); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /docs/InstallerWelcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/InstallerWelcome.png -------------------------------------------------------------------------------- /docs/Reference/Exception/RuntimeException.md: -------------------------------------------------------------------------------- 1 | # Kinx Exception Reference 2 | 3 | ## RuntimeException 4 | 5 | This is a standard exception, do it like `throw RuntimeException("message");`. 6 | -------------------------------------------------------------------------------- /docs/Reference/Object/Binary.md: -------------------------------------------------------------------------------- 1 | # Kinx Object Reference 2 | 3 | ## Binary 4 | 5 | `Binary` object is used to operate for a binary object like `<0x01,0x02>`. 6 | 7 | | Method | Meaning | 8 | | -------------------- | ------------------------------- | 9 | | `Binary.length(bin)` | Returns the length of a binary. | 10 | 11 | There is a special use case for this object. 12 | The following 2 example means the same work. 13 | 14 | ```js 15 | Binary.length(bin); 16 | bin.length(); 17 | ``` 18 | -------------------------------------------------------------------------------- /docs/Reference/Object/Double.md: -------------------------------------------------------------------------------- 1 | # Kinx Object Reference 2 | 3 | ## Double 4 | 5 | `Double` object is used to operate for a double like `1.5`. 6 | And `Math` object's function is available for Integer object like `2.0.pow(10.0)`. 7 | 8 | | Method | Meaning | 9 | | ------------------------- | ----------------------------------- | 10 | | `Double.parseInt(val)` | Converts `val` to an integer value. | 11 | | `Double.parseDouble(val)` | Converts `val` to a double value. | 12 | 13 | There is a special use case for this object. 14 | The following 2 example means the same work. 15 | 16 | ```js 17 | Double.parseInt(1.5); 18 | 1.5.parseInt(); 19 | ``` 20 | -------------------------------------------------------------------------------- /docs/Reference/Object/Integer.md: -------------------------------------------------------------------------------- 1 | # Kinx Object Reference 2 | 3 | ## Integer 4 | 5 | `Integer` object is used to operate for an integer like `100`. 6 | And `Math` object's function is available for Integer object like `2.pow(10)`. 7 | 8 | | Method | Meaning | 9 | | ------------------------------------ | --------------------------------------------------------- | 10 | | `Integer.parseInt(val)` | Converts `val` to an integer value. | 11 | | `Integer.parseDouble(val)` | Converts `val` to a double value. | 12 | | `Integer.times(val, callback)` | Loop and callback with the range from `0` to `(val - 1)`. | 13 | | `Integer.upto(val, max, callback)` | Loop and callback with the range from `val` to `max`. | 14 | | `Integer.downto(val, min, callback)` | Loop and callback with the range from `val` to `min`. | 15 | 16 | There is a special use case for this object. 17 | The following 2 example means the same work. 18 | 19 | ```js 20 | Integer.times(100, callback); 21 | 100.times(callback); 22 | ``` 23 | -------------------------------------------------------------------------------- /docs/Reference/Object/Regex.md: -------------------------------------------------------------------------------- 1 | # Kinx Object Reference 2 | 3 | ## Regex 4 | 5 | `Regex` object is used for a regular expression. 6 | `Regex` is a class, so the instance will be always created by `new` operator. 7 | 8 | | Method | Meaning | 9 | | ------------------------- | ---------------------------------------------------------------------------------------------------------- | 10 | | `re = new Regex(pattern)` | Creates an instance. | 11 | | `re.reset(str)` | Reset the search target string. | 12 | | `re.find()` | `true` if found. This can be used continuously until it has been not found. | 13 | | `re.matches()` | `true` if matches. This can be used only one time because this is checking if the target is fully matched. | 14 | -------------------------------------------------------------------------------- /docs/Reference/Object/String.md: -------------------------------------------------------------------------------- 1 | # Kinx Object Reference 2 | 3 | ## String 4 | 5 | `String` object is used to operate for a text. 6 | 7 | | Method | Meaning | 8 | | ----------------------------------- | ------------------------------------ | 9 | | `String.length(str)` | Returns the length of a string. | 10 | | `String.trim(str)` | Trims whitespaces from a string. | 11 | | `String.startsWith(str, chk)` | Returns true if str starts with chk. | 12 | | `String.endsWith(str, chk)` | Returns true if str ends with chk. | 13 | | `String.subString(str, start, len)` | Returns a sub string from a string. | 14 | | `String.parseInt(str)` | Converts `val` to an integer value. | 15 | | `String.parseDouble(str)` | Converts `val` to a double value. | 16 | | `String.toInt(str)` | Same as `parseInt`. | 17 | | `String.toDouble(str)` | Same as `parseDouble`. | 18 | 19 | There is a special use case for this object. 20 | The following 2 example means the same work. 21 | 22 | ```js 23 | String.length(str); 24 | str.length(); 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/Reference/Object/System.md: -------------------------------------------------------------------------------- 1 | # Kinx Object Reference 2 | 3 | ## System 4 | 5 | `System` object is used to realize a basic functionality. 6 | 7 | | Method | Meaning | 8 | | ---------------------- | ------------------------------------------------------------------- | 9 | | `System.print(...)` | Prints a text, converted if necessary, without a newline character. | 10 | | `System.println(...)` | Prints a text, converted if necessary, with a newline character. | 11 | | `System.abort()` | Aborting the program. | 12 | | `System.exec(cmdline)` | Executing the command with shell. | 13 | -------------------------------------------------------------------------------- /docs/Reference/Object/SystemTimer.md: -------------------------------------------------------------------------------- 1 | # Kinx Object Reference 2 | 3 | ## SystemTimer 4 | 5 | `SystemTimer` object is used to measure time. 6 | `SystemTimer` is a class, so the instance will be always created by `new` operator. 7 | 8 | | Method | Meaning | 9 | | ------------------------- | -------------------------------------------------------------- | 10 | | `tmr = new SystemTimer()` | Creates an instance. | 11 | | `tmr.restart()` | Restarts the timer. | 12 | | `tmr.elapsed()` | Returns a elapsed from starting or restarting the measurement. | 13 | -------------------------------------------------------------------------------- /docs/Reference/_Index.md: -------------------------------------------------------------------------------- 1 | # Kinx Object 2 | 3 | The document size became a little increased, so separated it. 4 | 5 | ## Auto-loaded Object References 6 | 7 | The objects written below can be usually used without any import library. 8 | 9 | * [System](Object/System.md) ... System Object for a system control. 10 | * [String](Object/String.md) ... String Object to operate a string. 11 | * [Integer](Object/Integer.md) ... Integer Object to operate an integer value. 12 | * [Double](Object/Double.md) ... Double Object to operate a duoble value. 13 | * [Binary](Object/Binary.md) ... Binary Object to operate a binary. 14 | * [Array](Object/Array.md) ... Array Object to operae an array. 15 | * [Math](Object/Math.md) ... Some mathematical operations. 16 | * [SystemTimer](Object/SystemTimer.md) ... To measure execution time. 17 | * [Regex](Object/Regex.md) ... Regular Expression Object. 18 | * [File](Object/File.md) ... File Object to access a file system. 19 | 20 | ## Exception References 21 | 22 | * [RuntimeException](Exception/RuntimeException.md) 23 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-dinky -------------------------------------------------------------------------------- /docs/benchmark/.spectest: -------------------------------------------------------------------------------- 1 | { 2 | "root": "doc/benchmark", 3 | 4 | "testfile": "test.kx", 5 | "resultfile": "result.txt", 6 | "interpreter": "kinx", 7 | } 8 | -------------------------------------------------------------------------------- /docs/fibkx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/fibkx.png -------------------------------------------------------------------------------- /docs/kinx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/kinx.png -------------------------------------------------------------------------------- /docs/kinxlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/kinxlogo.png -------------------------------------------------------------------------------- /docs/licenses/LICENSE.ansicolor_32: -------------------------------------------------------------------------------- 1 | # ansicolor-w32.c 2 | 3 | ANSI color support on windows 4 | 5 | ## Usage 6 | 7 | You can display ANSI color on windows without hacks 8 | 9 | ```c 10 | #include 11 | #ifdef _WIN32 12 | # include "ansicolor-w32.h" 13 | #endif 14 | 15 | int 16 | main(int argc, char* argv[]) { 17 | printf("\x1b[2J\x1b[1;1H\x1b[40mhello"); 18 | return 0; 19 | } 20 | ``` 21 | 22 | The library replaces the printf family functions with wrappers that recognize the ANSI escape code and render the input using the specified colors. 23 | 24 | ## License 25 | 26 | MIT 27 | 28 | ## Author 29 | 30 | Yasuhiro Matsumoto (a.k.a mattn) 31 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.duktape: -------------------------------------------------------------------------------- 1 | =============== 2 | Duktape license 3 | =============== 4 | 5 | (http://opensource.org/licenses/MIT) 6 | 7 | Copyright (c) 2013-2019 by Duktape authors (see AUTHORS.rst) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.klib: -------------------------------------------------------------------------------- 1 | /* The MIT License 2 | 3 | Copyright (c) 2008-2009, by Attractive Chaos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 21 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | */ 25 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.libclipboard: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Jeremy Tan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.miniyacc: -------------------------------------------------------------------------------- 1 | MIT/X Consortium License 2 | 3 | © 2015 Quentin Carbonneaux 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.minizip: -------------------------------------------------------------------------------- 1 | Condition of use and distribution are the same as zlib: 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgement in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.oniguruma: -------------------------------------------------------------------------------- 1 | Oniguruma LICENSE 2 | ----------------- 3 | 4 | Copyright (c) 2002-2019 K.Kosako 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.picosat: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006 - 2014, Armin Biere, Johannes Kepler University. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.sljit: -------------------------------------------------------------------------------- 1 | /* 2 | * Stack-less Just-In-Time compiler 3 | * 4 | * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, are 7 | * permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this list of 10 | * conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list 13 | * of conditions and the following disclaimer in the documentation and/or other materials 14 | * provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 21 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 22 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 24 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | -------------------------------------------------------------------------------- /docs/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 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.udis86: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2012, Vivek Thampi 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.webview: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Serge Zaitsev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/licenses/LICENSE.xsel: -------------------------------------------------------------------------------- 1 | Copyright (C) 2001 Conrad Parker 2 | 3 | Permission to use, copy, modify, distribute, and sell this software and its 4 | documentation for any purpose is hereby granted without fee, provided that 5 | the above copyright notice appear in all copies and that both that copyright 6 | notice and this permission notice appear in supporting documentation. No 7 | representations are made about the suitability of this software for any 8 | purpose. It is provided "as is" without express or implied warranty. 9 | -------------------------------------------------------------------------------- /docs/spec/algorithm/README.md: -------------------------------------------------------------------------------- 1 | # Algorithm and Data Structure 2 | 3 | Here are some algorithms and data structures. 4 | This will help your understanding. 5 | 6 | ## Sort 7 | 8 | * [Quicksort](qsort.md) 9 | * [Heapsort](heapsort.md) 10 | * [Merge Sort](mergesort.md) 11 | 12 | ## Verification 13 | 14 | * [CRC32](crc32.md) 15 | 16 | ## Game 17 | 18 | * [Life Game](lifegame.md) 19 | * [N Queens](nqueens.md) 20 | * [Knight Tour](knight.md) 21 | * [Missionaries and Cannibals Problem](cannibal.md) 22 | 23 | ## Fractals 24 | 25 | * [Mandelbrot Set](mandelbrot.md) 26 | 27 | ## Others 28 | 29 | * [SAT Solver](satsolver.md) 30 | -------------------------------------------------------------------------------- /docs/spec/algorithm/heapsort.md: -------------------------------------------------------------------------------- 1 | # Heapsort 2 | 3 | ## Overview 4 | 5 | Please see the Wikipedia. 6 | 7 | * [Heapsort - Wikipedia](https://en.wikipedia.org/wiki/Heapsort) 8 | 9 | ## Examples 10 | 11 | ### Example 1. Heapsort Algorithm 12 | 13 | #### Code 14 | 15 | ```javascript 16 | function heapsort(n, a) { 17 | var i, j, k, x; 18 | for (k = n / 2; k >= 1; k--) { 19 | i = k; x = a[i]; 20 | while ((j = 2 * i) <= n) { 21 | if (j < n && a[j] < a[j + 1]) j++; 22 | if (x >= a[j]) break; 23 | a[i] = a[j]; i = j; 24 | } 25 | a[i] = x; 26 | } 27 | while (n > 1) { 28 | x = a[n]; a[n] = a[1]; n--; 29 | i = 1; 30 | while ((j = 2 * i) <= n) { 31 | if (j < n && a[j] < a[j + 1]) j++; 32 | if (x >= a[j]) break; 33 | a[i] = a[j]; i = j; 34 | } 35 | a[i] = x; 36 | } 37 | } 38 | 39 | function show(title, a) { 40 | System.print(title); 41 | a.each(&(e, i) => { 42 | System.print(" %2d" % e) if (i >= 1); 43 | }); 44 | System.print("\n"); 45 | } 46 | 47 | function demo() { 48 | var a = [0, 69, 63, 88, 85, 26, 77, 51, 42, 16, 4, 20, 18, 18, 40, 23, 26, 24, 63, 96, 59]; 49 | 50 | show("Before:", a); 51 | heapsort(a.length() - 1, a); 52 | show("After: ", a); 53 | } 54 | 55 | demo(); 56 | ``` 57 | 58 | #### Result 59 | 60 | ``` 61 | Before: 69 63 88 85 26 77 51 42 16 4 20 18 18 40 23 26 24 63 96 59 62 | After: 4 16 18 18 20 23 24 26 26 40 42 51 59 63 63 69 77 85 88 96 63 | ``` 64 | -------------------------------------------------------------------------------- /docs/spec/algorithm/knight.md: -------------------------------------------------------------------------------- 1 | # Knight Tour 2 | 3 | ## Overview 4 | 5 | Please see the Wikipedia. 6 | 7 | * [Knight tour - Wikipedia](https://en.wikipedia.org/wiki/Knight's_tour) 8 | 9 | ## Examples 10 | 11 | ### Example 1. Knight Tour Algorithm 12 | 13 | #### Code 14 | 15 | ```javascript 16 | const N = 5; // N x N 17 | const SOLUTIONMAX = 304; 18 | 19 | var board = [], 20 | dx = [ 2, 1,-1,-2,-2,-1, 1, 2 ], 21 | dy = [ 1, 2, 2, 1,-1,-2,-2,-1 ]; 22 | var count = 0; 23 | var solution = 0; 24 | 25 | function printboard() { 26 | if (++solution < SOLUTIONMAX) return; 27 | System.print("\nSolution %d\n" % solution); 28 | for (var i = 2; i <= N + 1; i++) { 29 | for (var j = 2; j <= N + 1; j++) System.print("%4d" % board[i][j]); 30 | System.print("\n"); 31 | } 32 | } 33 | 34 | function test(x, y) { 35 | if (board[x][y] != 0) return; 36 | board[x][y] = ++count; 37 | if (count == N * N) printboard(); 38 | else for (var i = 0; i < 8; i++) test(x + dx[i], y + dy[i]); 39 | board[x][y] = 0; count--; 40 | } 41 | 42 | function knight() { 43 | for (var i = 0; i <= N + 3; i++) 44 | for (var j = 0; j <= N + 3; j++) board[i][j] = 1; 45 | for (var i = 2; i <= N + 1; i++) 46 | for (var j = 2; j <= N + 1; j++) board[i][j] = 0; 47 | test(2, 2); 48 | } 49 | 50 | knight(); 51 | ``` 52 | 53 | #### Result 54 | 55 | ``` 56 | Solution 304 57 | 1 10 5 16 25 58 | 4 17 2 11 6 59 | 9 20 13 24 15 60 | 18 3 22 7 12 61 | 21 8 19 14 23 62 | ``` 63 | -------------------------------------------------------------------------------- /docs/spec/algorithm/qsort.md: -------------------------------------------------------------------------------- 1 | # Quicksort 2 | 3 | ## Overview 4 | 5 | Please see the Wikipedia. 6 | 7 | * [Quicksort - Wikipedia](https://en.wikipedia.org/wiki/Quicksort) 8 | 9 | ## Examples 10 | 11 | ### Example 1. Quicksort Algorithm 12 | 13 | #### Code 14 | 15 | ```javascript 16 | function quicksort(a, first, last) { 17 | var i = first; 18 | var j = last; 19 | var x = a[(first + last) / 2]; 20 | while (true) { 21 | while (a[i] < x) i++; 22 | while (x < a[j]) j--; 23 | if (i >= j) break; 24 | 25 | [a[i], a[j]] = [a[j], a[i]]; 26 | ++i; --j; 27 | } 28 | if (first < i - 1) 29 | quicksort(a, first , i - 1); 30 | if (j + 1 < last) 31 | quicksort(a, j + 1, last); 32 | } 33 | 34 | function show(title, a) { 35 | System.print(title); 36 | a.each(&(e) => System.print(" %2d" % e)); 37 | System.print("\n"); 38 | } 39 | 40 | function demo() { 41 | var a = [69, 63, 88, 85, 26, 77, 51, 42, 16, 4, 20, 18, 18, 40, 23, 26, 24, 63, 96, 59]; 42 | 43 | show("Before:", a); 44 | quicksort(a, 0, a.length() - 1); 45 | show("After: ", a); 46 | } 47 | 48 | demo(); 49 | ``` 50 | 51 | #### Result 52 | 53 | ``` 54 | Before: 69 63 88 85 26 77 51 42 16 4 20 18 18 40 23 26 24 63 96 59 55 | After: 4 16 18 18 20 23 24 26 26 40 42 51 59 63 63 69 77 85 88 96 56 | ``` 57 | -------------------------------------------------------------------------------- /docs/spec/command/arguments.md: -------------------------------------------------------------------------------- 1 | # Command Line Arguments 2 | 3 | ## Overview 4 | 5 | Command line arguments will be used with `$$` as array. 6 | 7 | * `$$[0]` is a script name. 8 | * `$$[n]` is an nth argument if n >= 1. 9 | 10 | ## Examples 11 | 12 | ### Example 1. `$$` used with `each` method 13 | 14 | #### Code [args -> 1 2 3 4 5 6 7 8 end] 15 | 16 | ```javascript 17 | // 18 | // Command Line Example: 19 | // $ ./kinx test.kx 1 2 3 4 5 6 7 8 end 20 | // 21 | $$.each(&(e, i) => System.println("Argument[%d] = " % i, e)); 22 | ``` 23 | 24 | #### Result 25 | 26 | ``` 27 | Argument[0] = test.kx 28 | Argument[1] = 1 29 | Argument[2] = 2 30 | Argument[3] = 3 31 | Argument[4] = 4 32 | Argument[5] = 5 33 | Argument[6] = 6 34 | Argument[7] = 7 35 | Argument[8] = 8 36 | Argument[9] = end 37 | ``` 38 | 39 | ### Example 2. Accessing `$$` by index 40 | 41 | #### Code [args -> 1 2 3 4 5 6 7 8 end] 42 | 43 | ```javascript 44 | // 45 | // Command Line Example: 46 | // $ ./kinx test.kx 1 2 3 4 5 6 7 8 end 47 | // 48 | System.println("Argument length = ", $$.length()); 49 | for (var i = 0, len = $$.length(); i < len; ++i) { 50 | System.println("Argument[%{i}] = ", $$[i]); 51 | } 52 | ``` 53 | 54 | #### Result 55 | 56 | ``` 57 | Argument length = 10 58 | Argument[0] = test.kx 59 | Argument[1] = 1 60 | Argument[2] = 2 61 | Argument[3] = 3 62 | Argument[4] = 4 63 | Argument[5] = 5 64 | Argument[6] = 6 65 | Argument[7] = 7 66 | Argument[8] = 8 67 | Argument[9] = end 68 | ``` 69 | -------------------------------------------------------------------------------- /docs/spec/definition/closure.md: -------------------------------------------------------------------------------- 1 | # Closure 2 | 3 | ## Overview 4 | 5 | Closure is a function object which has a lexical scope. 6 | 7 | ## Examples 8 | 9 | ### Example 1. Closure example 10 | 11 | #### Code 12 | 13 | ```javascript 14 | function newCounter() { 15 | var i = 0; // a lexical variable. 16 | 17 | return function() { // an anonymous function. 18 | ++i; // a reference to a lexical variable. 19 | return i; 20 | }; 21 | } 22 | 23 | var c1 = newCounter(); 24 | System.println(c1()); // 1 25 | System.println(c1()); // 2 26 | System.println(c1()); // 3 27 | System.println(c1()); // 4 28 | System.println(c1()); // 5 29 | ``` 30 | 31 | #### Result 32 | 33 | ``` 34 | 1 35 | 2 36 | 3 37 | 4 38 | 5 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/spec/definition/native/switch_when.md: -------------------------------------------------------------------------------- 1 | # Switch-When in Native 2 | 3 | ## Overview 4 | 5 | Switch-When is supported only with integer label in native function. 6 | The label should be integer but also it can be the expression with the type of integer. 7 | 8 | ## Examples 9 | 10 | ### Example 1. Switch-When in native 11 | 12 | #### Code 13 | 14 | ```javascript 15 | var y = 19; 16 | native f(a, x) { 17 | var b = 0; 18 | switch (a) { 19 | when 1: 20 | b = a; 21 | when 5: 22 | b = a; 23 | else: 24 | b = 100; 25 | when 4: 26 | b = a; 27 | when 3: 28 | b = a; 29 | when 8: 30 | b = 10; 31 | when 9: 32 | b = a; 33 | when x: 34 | b = 1000; 35 | when y: 36 | b = 10000; 37 | when y+1: 38 | b = 100000; 39 | fallthrough; 40 | when x+3: 41 | b += 1000000; 42 | } 43 | return b; 44 | } 45 | System.println(f(1, 18)); 46 | System.println(f(2, 18)); 47 | System.println(f(3, 18)); 48 | System.println(f(4, 18)); 49 | System.println(f(5, 18)); 50 | System.println(f(6, 18)); 51 | System.println(f(7, 18)); 52 | System.println(f(8, 18)); 53 | System.println(f(9, 18)); 54 | System.println(f(18, 18)); 55 | System.println(f(19, 18)); 56 | System.println(f(20, 18)); 57 | System.println(f(21, 18)); 58 | ``` 59 | 60 | #### Result 61 | 62 | ``` 63 | 1 64 | 100 65 | 3 66 | 4 67 | 5 68 | 100 69 | 100 70 | 10 71 | 9 72 | 1000 73 | 10000 74 | 1100000 75 | 1000000 76 | ``` 77 | -------------------------------------------------------------------------------- /docs/spec/images/colorize_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/spec/images/colorize_example.png -------------------------------------------------------------------------------- /docs/spec/images/string_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/spec/images/string_color.png -------------------------------------------------------------------------------- /docs/spec/lib/basic/clipboard.md: -------------------------------------------------------------------------------- 1 | # Clipboard 2 | 3 | ## Overview 4 | 5 | This library is to read a text from clipboard and to write a text to clipboard. 6 | The basic usage is below. 7 | 8 | ```javascript 9 | var cb = new Clipboard(); 10 | cb.write(str); 11 | var r = cb.read(); 12 | ``` 13 | 14 | ## Some Examples 15 | 16 | > Disabled a spec test because it will be failed on Github Action with the message of `Can't open display: (null)`. 17 | 18 | ### Example 1. Write to Clipboard 19 | 20 | #### Code 21 | 22 | ```javascript 23 | var cb = new Clipboard(); 24 | cb.write("This is a first message."); 25 | var r = cb.read(); 26 | System.println("write done - ", r); 27 | cb.write("This message was written by other process."); 28 | ``` 29 | 30 | #### Result 31 | 32 | ``` 33 | write done - This is a first message. 34 | ``` 35 | 36 | ### Example 2. Read from Clipboard 37 | 38 | #### Code 39 | 40 | ```javascript 41 | var cb = new Clipboard(); 42 | var r = cb.read(); 43 | System.println("read - ", r); 44 | ``` 45 | 46 | #### Result 47 | 48 | ``` 49 | read - This message was written by other process. 50 | ``` 51 | -------------------------------------------------------------------------------- /docs/spec/lib/function/define_exception.md: -------------------------------------------------------------------------------- 1 | # defineException function 2 | 3 | ## Overview 4 | 5 | You can define your own exception by `System.defineException()` as below. 6 | 7 | ```javascript 8 | YourOwnExceptionClass = System.defineException('YourOwnException'); 9 | YourOwnException = YourOwnExceptionClass.create; 10 | ``` 11 | 12 | If you want to make your own library, it will be useful for your error notification. 13 | 14 | ## Examples 15 | 16 | ### Example 1. Normal case 17 | 18 | #### Code 19 | 20 | ```javascript 21 | YourOwnExceptionClass = System.defineException('YourOwnException'); 22 | YourOwnException = YourOwnExceptionClass.create; 23 | 24 | class TheClass { 25 | private initialize() { 26 | throw YourOwnException("Error!"); 27 | } 28 | } 29 | 30 | function test() { 31 | var x = new TheClass(); 32 | return x; 33 | } 34 | 35 | test(); 36 | ``` 37 | 38 | #### Result 39 | 40 | ``` 41 | Uncaught exception: No one catch the exception. 42 | YourOwnException: Error! 43 | Stack Trace Information: 44 | at function TheClass#initialize(test.kx:6) 45 | at function TheClass(test.kx:4) 46 | at function test(test.kx:11) 47 | at (test.kx:15) 48 | ``` 49 | -------------------------------------------------------------------------------- /docs/spec/others/string_next.md: -------------------------------------------------------------------------------- 1 | # String#next 2 | 3 | ## Overview 4 | 5 | `String#next` is used in Range object. 6 | 7 | * [String#next](https://docs.ruby-lang.org/en/master/String.html#method-i-next) 8 | 9 | ## Examples 10 | 11 | ### Example 1. Some examples of `String#next` 12 | 13 | #### Code 14 | 15 | ```javascript 16 | System.println("aa".next()); 17 | System.println("88".next().next()); 18 | System.println("99".next()); 19 | System.println("ZZ".next()); 20 | System.println("a9".next()); 21 | System.println("-9".next()); 22 | System.println("1.9.9".next()); 23 | System.println(".".next()); 24 | System.println("a".next()); 25 | System.println("z".next()); 26 | System.println("Ad".next()); 27 | System.println("Az".next()); 28 | System.println("zz".next()); 29 | System.println("4".next()); 30 | System.println("9".next()); 31 | System.println("a9".next()); 32 | System.println("9z".next()); 33 | System.println("4:5:9".next()); 34 | System.println("-5".next()); 35 | System.println(":9".next()); 36 | ``` 37 | 38 | #### Result 39 | 40 | ``` 41 | ab 42 | 90 43 | 100 44 | AAA 45 | b0 46 | -10 47 | 2.0.0 48 | / 49 | b 50 | aa 51 | Ae 52 | Ba 53 | aaa 54 | 5 55 | 10 56 | b0 57 | 10a 58 | 4:6:0 59 | -6 60 | :10 61 | ``` 62 | -------------------------------------------------------------------------------- /docs/spec/statement/block.md: -------------------------------------------------------------------------------- 1 | # Block statement 2 | 3 | ## Overview 4 | 5 | Block will create a scope and holding the list of a statement. 6 | Block is also one of statements. 7 | 8 | For example, `if` statement has a statement in then clause or else clause, 9 | but a block can be there instead of a single statement to hold a lot of statements. 10 | 11 | ```javascript 12 | if (a > 0) System.println("positive"); // a single statement. 13 | else if (a < 0) System.println("negative"); // a single statement. 14 | else { 15 | // block here, instead of a single statement. 16 | } 17 | ``` 18 | 19 | And also the block has a scope. 20 | The variable shadowing occurs if the same name of variable was declared. 21 | Please see the example 1. 22 | 23 | ## Examples 24 | 25 | ### Example 1. Scope 26 | 27 | #### Code 28 | 29 | ```javascript 30 | var a = 10; 31 | { 32 | var a = 100; 33 | System.println(a); // => 100 34 | } 35 | System.println(a); // => 10 36 | ``` 37 | 38 | #### Result 39 | 40 | ``` 41 | 100 42 | 10 43 | ``` 44 | -------------------------------------------------------------------------------- /docs/spec/statement/do_while.md: -------------------------------------------------------------------------------- 1 | 2 | # Do-While statement 3 | 4 | ## Overview 5 | 6 | `do-while` statement is a post-test loop. 7 | The condition will be evaluated at the tail of loop. 8 | This loop will be performed 1 time at least. 9 | 10 | ```javascript 11 | do { 12 | // loop while a equals 0. 13 | } while (a == 0); 14 | ``` 15 | 16 | ### Infinite loop 17 | 18 | If you put `true` or non-zero value at the condition, it means infinite loop. 19 | `break` statement is needed to exit an infinite loop. 20 | 21 | ```javascript 22 | do { 23 | // infinite loop. 24 | if (codition) break; 25 | } while (true); 26 | ``` 27 | 28 | This is exactly the same as `while`, therefore you had better use `while` for readability. 29 | 30 | ## Examples 31 | 32 | ### Example 1. Normal case 33 | 34 | #### Code 35 | 36 | ```javascript 37 | var a = 5; 38 | do { 39 | System.println(a); 40 | } while (a--); 41 | ``` 42 | 43 | #### Result 44 | 45 | ``` 46 | 5 47 | 4 48 | 3 49 | 2 50 | 1 51 | 0 52 | ``` 53 | 54 | ### Example 2. Infinaite loop 55 | 56 | #### Code 57 | 58 | ```javascript 59 | var i = 0; 60 | do { 61 | if (i > 1000) break; 62 | ++i; 63 | } while (true); 64 | System.println(i); 65 | ``` 66 | 67 | #### Result 68 | 69 | ``` 70 | 1001 71 | ``` 72 | -------------------------------------------------------------------------------- /docs/spec/statement/expression/logical_and.md: -------------------------------------------------------------------------------- 1 | # Logical AND Operator 2 | 3 | ## Overview 4 | 5 | Logical AND operator is a shortcut operator, 6 | and when using `&&` and LHS is `true`, the RHS will be evaluated. 7 | 8 | ```javascript 9 | var b = a && 10; // initializing 10 when a is true. 10 | ``` 11 | 12 | This can be also used with assignment operator as `&&=`. 13 | 14 | ```javascript 15 | a &&= func(); // calling func and assign it to the variable of a, only when a is true. 16 | ``` 17 | 18 | ## Examples 19 | 20 | ### Example 1. Simple use 21 | 22 | #### Code 23 | 24 | ```javascript 25 | function test(a) { 26 | return a && 10; 27 | } 28 | 29 | System.println(test(0) ?? "null"); 30 | System.println(test(1) ?? "null"); 31 | System.println(test(null) ?? "null"); 32 | ``` 33 | 34 | #### Result 35 | 36 | ``` 37 | 0 38 | 10 39 | null 40 | ``` 41 | 42 | ### Example 2. With assignment 43 | 44 | #### Code 45 | 46 | ```javascript 47 | var id; 48 | class A() { @id = id++; } 49 | 50 | function test(a) { 51 | a &&= new A(); 52 | return a ?? { id: 1 }; 53 | } 54 | 55 | var a; 56 | id = 10; 57 | System.println((a = test(a)).id); 58 | System.println((a = test(a)).id); 59 | System.println((a = test(a)).id); 60 | ``` 61 | 62 | #### Result 63 | 64 | ``` 65 | 1 66 | 10 67 | 11 68 | ``` 69 | -------------------------------------------------------------------------------- /docs/spec/statement/expression/logical_or.md: -------------------------------------------------------------------------------- 1 | # Logical OR Operator 2 | 3 | ## Overview 4 | 5 | Logical OR operator is a shortcut operator, 6 | and when using `||` and LHS is `false`, the RHS will be evaluated. 7 | 8 | ```javascript 9 | var b = a || 10; // initializing 10 when a is false. 10 | ``` 11 | 12 | This can be also used with assignment operator as `||=`. 13 | 14 | ```javascript 15 | a ||= new A(); // creating an instance only when a is false. 16 | ``` 17 | 18 | ## Examples 19 | 20 | ### Example 1. Simple use 21 | 22 | #### Code 23 | 24 | ```javascript 25 | function test(a) { 26 | return a || 10; 27 | } 28 | 29 | System.println(test(0)); 30 | System.println(test(1)); 31 | System.println(test(null)); 32 | ``` 33 | 34 | #### Result 35 | 36 | ``` 37 | 10 38 | 1 39 | 10 40 | ``` 41 | 42 | ### Example 2. With assignment 43 | 44 | #### Code 45 | 46 | ```javascript 47 | var id; 48 | class A() { @id = id++; } 49 | 50 | function test(a) { 51 | a ||= new A(); 52 | return a; 53 | } 54 | 55 | var a; 56 | id = 10; 57 | System.println((a = test(a)).id); 58 | System.println((a = test(a)).id); 59 | System.println((a = test(a)).id); 60 | ``` 61 | 62 | #### Result 63 | 64 | ``` 65 | 10 66 | 10 67 | 10 68 | ``` 69 | -------------------------------------------------------------------------------- /docs/spec/statement/expression/logical_undef.md: -------------------------------------------------------------------------------- 1 | # Logical UNDEF Operator 2 | 3 | ## Overview 4 | 5 | Logical Undef operator is a shortcut operator and this operator is like Logical OR operator of `||`. 6 | When using `||` and LHS is `false`, the RHS will be evaluated. 7 | Compared to that, whe using `??` and LHS is `null`, the RHS will be evaluated. 8 | 9 | The `false` meaning is wider than undefined/null, 10 | that is why the `??` is very useful especially when you distinguish between 0 and `null`. 11 | 12 | ```javascript 13 | var b = a ?? 0; // initializing 0 when a is uninitialized. 14 | ``` 15 | 16 | This can be also used with assignment operator as `??=`. 17 | 18 | ```javascript 19 | a ??= new A(); // creating an instance only when a is uninitialized. 20 | ``` 21 | 22 | ## Examples 23 | 24 | ### Example 1. Simple use 25 | 26 | #### Code 27 | 28 | ```javascript 29 | function test(a) { 30 | return a ?? 10; 31 | } 32 | 33 | System.println(test(0)); 34 | System.println(test(1)); 35 | System.println(test(null)); 36 | ``` 37 | 38 | #### Result 39 | 40 | ``` 41 | 0 42 | 1 43 | 10 44 | ``` 45 | 46 | ### Example 2. With assignment 47 | 48 | #### Code 49 | 50 | ```javascript 51 | var id; 52 | class A() { @id = id++; } 53 | 54 | function test(a) { 55 | a ??= new A(); 56 | return a; 57 | } 58 | 59 | var a; 60 | id = 10; 61 | System.println((a = test(a)).id); 62 | System.println((a = test(a)).id); 63 | System.println((a = test(a)).id); 64 | ``` 65 | 66 | #### Result 67 | 68 | ``` 69 | 10 70 | 10 71 | 10 72 | ``` 73 | -------------------------------------------------------------------------------- /docs/spec/statement/expression/ternary.md: -------------------------------------------------------------------------------- 1 | # Ternary Operator 2 | 3 | ## Overview 4 | 5 | Ternary operator is a simple `if-else`. 6 | `a ? b : c` means, if a is true, then b, otherwise c. 7 | 8 | ```javascript 9 | var b = a ? 10 : 20; 10 | ``` 11 | 12 | This expression is evaluated right to left. 13 | 14 | ## Examples 15 | 16 | ### Example 1. Simple use 17 | 18 | #### Code 19 | 20 | ```javascript 21 | function test(a) { 22 | return a ? 10 : 20; 23 | } 24 | 25 | System.println(test(true)); 26 | System.println(test(False)); // False object. 27 | ``` 28 | 29 | #### Result 30 | 31 | ``` 32 | 10 33 | 20 34 | ``` 35 | 36 | ### Example 2. Combination of ternary operator 37 | 38 | #### Code 39 | 40 | ```javascript 41 | function test(b1, b2, b3) { 42 | return b1 ? b2 ? 1 : 2 : b3 ? 3 : 4; 43 | } 44 | 45 | System.println(test(0, 0, 0)); 46 | System.println(test(0, 0, 1)); 47 | System.println(test(0, 1, 0)); 48 | System.println(test(0, 1, 1)); 49 | System.println(test(1, 0, 0)); 50 | System.println(test(1, 0, 1)); 51 | System.println(test(1, 1, 0)); 52 | System.println(test(1, 1, 1)); 53 | ``` 54 | 55 | #### Result 56 | 57 | ``` 58 | 4 59 | 3 60 | 4 61 | 3 62 | 2 63 | 2 64 | 1 65 | 1 66 | ``` 67 | -------------------------------------------------------------------------------- /docs/spec/statement/if_else.md: -------------------------------------------------------------------------------- 1 | 2 | # If-Else statement 3 | 4 | ## Overview 5 | 6 | `if-else` statement is a conditional jump. 7 | `else` clause is not always necessary. 8 | 9 | ```javascript 10 | if (a == 0) { 11 | // then clause 12 | } 13 | ``` 14 | 15 | Here is the example with `else` clause. 16 | 17 | ```javascript 18 | if (a == 0) { 19 | // then clause 20 | } else { 21 | // else clause 22 | } 23 | ``` 24 | 25 | You can combine multiple `if-else` statements like C. 26 | 27 | ```javascript 28 | if (a == 0) { 29 | // then clause 30 | } else if (b == 0) { 31 | // next if-else statement 32 | } else { 33 | // else clause 34 | } 35 | ``` 36 | 37 | ## Examples 38 | 39 | ### Example 1. Normal case 40 | 41 | #### Code 42 | 43 | ```javascript 44 | var age = 10; 45 | if (age < 20) { 46 | System.println("young"); 47 | } else { 48 | System.println("adult"); 49 | } 50 | ``` 51 | 52 | #### Result 53 | 54 | ``` 55 | young 56 | ``` 57 | 58 | ### Example 2. No else clause 59 | 60 | #### Code 61 | 62 | ```javascript 63 | var age = 10; 64 | if (age < 20) { 65 | System.println("young"); 66 | } 67 | ``` 68 | 69 | #### Result 70 | 71 | ``` 72 | young 73 | ``` 74 | 75 | 76 | ### Example 3. If-else combination 77 | 78 | #### Code 79 | 80 | ```javascript 81 | var age = 20; 82 | if (age < 20) { 83 | System.println("young"); 84 | } else if (age > 20) { 85 | System.println("adult"); 86 | } else { 87 | System.println("just 20"); 88 | } 89 | ``` 90 | 91 | #### Result 92 | 93 | ``` 94 | just 20 95 | ``` 96 | -------------------------------------------------------------------------------- /docs/spec/statement/mixin.md: -------------------------------------------------------------------------------- 1 | 2 | # Mixin statement 3 | 4 | ## Overview 5 | 6 | `mixin` keyword is used in a Class definition to include `Module`. 7 | As the example below, class Value will become having methods of `print` and `println` by `mixin`. 8 | 9 | ```javascript 10 | module Printable { 11 | public print() { 12 | System.print(@value); 13 | } 14 | public println() { 15 | System.println(@value); 16 | } 17 | } 18 | 19 | class Value(v) { 20 | mixin Printable; 21 | private initialize() { 22 | @value = v; 23 | } 24 | } 25 | ``` 26 | 27 | ## Examples 28 | 29 | ### Example 1. Normal case 30 | 31 | Here is the whole code of the use case of the above example. 32 | 33 | #### Code 34 | 35 | ```javascript 36 | module Printable { 37 | public print() { 38 | System.print(@value); 39 | } 40 | public println() { 41 | System.println(@value); 42 | } 43 | } 44 | 45 | class Value(v) { 46 | mixin Printable; 47 | private initialize() { 48 | @value = v; 49 | } 50 | } 51 | 52 | var val = new Value(100); 53 | val.println(); // => 100 54 | ``` 55 | 56 | #### Result 57 | 58 | ``` 59 | 100 60 | ``` 61 | -------------------------------------------------------------------------------- /docs/spec/statement/using.md: -------------------------------------------------------------------------------- 1 | # Using statement 2 | 3 | ## Overview 4 | 5 | `using` is used to load an external library. 6 | As some of standard library is not loaded automatically, you have to load it before using it. 7 | 8 | For example, [DateTime](../lib/basic/datetime.md) has to be loaded before using it if you want to use `DateTime` object. 9 | 10 | ```javascript 11 | using DateTime; 12 | ``` 13 | 14 | `using` will search the source file like `DateTime.kx` when it is used as `using DateTime;`, 15 | and loading it dynamically as a source code. 16 | It means the source code will be compiled together. 17 | 18 | ## Examples 19 | 20 | ### Example 1. DateTime 21 | 22 | #### Code 23 | 24 | ```javascript 25 | using DateTime; 26 | var a = new DateTime("2000-01-01 09:30:00"); 27 | System.println(a); 28 | ``` 29 | 30 | #### Result 31 | 32 | ``` 33 | 2000/01/01 09:30:00 34 | ``` 35 | -------------------------------------------------------------------------------- /docs/spec/statement/while.md: -------------------------------------------------------------------------------- 1 | 2 | # While statement 3 | 4 | ## Overview 5 | 6 | `while` statement is a pre-test loop. 7 | The condition will be evaluated at the head of loop. 8 | 9 | ```javascript 10 | while (a == 0) { 11 | // loop while a equals 0. 12 | } 13 | ``` 14 | 15 | ### Infinite loop 16 | 17 | If you put `true` or non-zero value at the condition, it means infinite loop. 18 | `break` statement is needed to exit an infinite loop. 19 | 20 | ```javascript 21 | while (true) { 22 | // infinite loop. 23 | if (codition) break; 24 | } 25 | ``` 26 | 27 | ## Examples 28 | 29 | ### Example 1. Normal case 30 | 31 | #### Code 32 | 33 | ```javascript 34 | var a = 5; 35 | while (a--) { 36 | System.println(a); 37 | } 38 | ``` 39 | 40 | #### Result 41 | 42 | ``` 43 | 4 44 | 3 45 | 2 46 | 1 47 | 0 48 | ``` 49 | 50 | ### Example 2. Infinaite loop 51 | 52 | #### Code 53 | 54 | ```javascript 55 | var i = 0; 56 | while (true) { 57 | if (i > 1000) break; 58 | ++i; 59 | } 60 | System.println(i); 61 | ``` 62 | 63 | #### Result 64 | 65 | ``` 66 | 1001 67 | ``` 68 | -------------------------------------------------------------------------------- /docs/spectest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/spectest.png -------------------------------------------------------------------------------- /docs/utility/images/debugger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/utility/images/debugger.png -------------------------------------------------------------------------------- /docs/utility/images/debugger_d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/utility/images/debugger_d.png -------------------------------------------------------------------------------- /docs/utility/images/repl.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/docs/utility/images/repl.gif -------------------------------------------------------------------------------- /examples/ansicolor.kx: -------------------------------------------------------------------------------- 1 | System.print(" -- "); 2 | for (b in 40..47) { 3 | System.print("\e[%{b}m %{b} \e[0m "); 4 | } 5 | System.print("\n"); 6 | for (c in [ 30, 31, 32, 33, 34, 35, 36, 37, 90, 91, 92, 93, 94, 95, 96, 97 ]) { 7 | s = (""+c); 8 | System.print("\e[%{c}m %{c} \e[0m "); 9 | for (b in 40..47) { 10 | s = "%{c};%{b}"; 11 | System.print("\e[%{s}m %{s} \e[0m "); 12 | } 13 | System.print("\n"); 14 | for (a in [ 1, 4 ]) { 15 | s = "%{c};%{a}"; 16 | System.print("\e[%{s}m %{s} \e[0m "); 17 | for (b in 40..47) { 18 | s = "%{c};%{b};%{a}"; 19 | System.print("\e[%{s}m %{s} \e[0m "); 20 | } 21 | System.print("\n"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/apply.kx: -------------------------------------------------------------------------------- 1 | 2 | function x(i) { 3 | var a; 4 | a[2] = 100; 5 | a[1][3] = 5; 6 | return a[1][3] * a[i]; 7 | } 8 | 9 | function y() { 10 | a.prop.prop = 3; 11 | b = 2; 12 | return a.prop.prop + b; 13 | } 14 | 15 | function z() { 16 | a = 2; 17 | b[2] = 10; 18 | return b[a]; 19 | } 20 | 21 | System.println("result = ", x(2) + y() + z()); 22 | -------------------------------------------------------------------------------- /examples/args.kx: -------------------------------------------------------------------------------- 1 | 2 | var l = $$.length(); 3 | for (var i = 0; i < l; ++i) { 4 | System.println("arg[%{i}] = ", $$[i]); 5 | } 6 | -------------------------------------------------------------------------------- /examples/array_sort.kx: -------------------------------------------------------------------------------- 1 | 2 | function demo(N) { 3 | var a; // array 4 | 5 | System.print("Before:"); 6 | for (var i = 0; i < N; i++) { 7 | a[i] = Integer.parseInt(Math.random() * 100); 8 | System.print(" %2d" % a[i]); 9 | } 10 | System.print("\n"); 11 | 12 | a.sort(&(a, b) => a <=> b); 13 | 14 | System.print("After: "); 15 | for (var i = 0; i < N; i++) 16 | System.print(" %2d" % a[i]); 17 | System.print("\n"); 18 | } 19 | 20 | demo(20); 21 | -------------------------------------------------------------------------------- /examples/arrayobj.kx: -------------------------------------------------------------------------------- 1 | var a = [1,2,3]; 2 | var b = { 3 | key: 1, 4 | obj: { 5 | value: 100, 6 | array: a + [2,3], 7 | } 8 | }; 9 | 10 | var x = 2; 11 | var y = 20.5; 12 | var c = [a, b, x+20, 20.5, "aaa"]; 13 | 14 | function display(obj, key, indent) { 15 | if (obj.isArray) { 16 | System.println(" " * indent, "item[%{key}]:"); 17 | for (var i = 0, l = obj.length(); i < l; ++i) { 18 | display(obj[i], i, indent+1); 19 | } 20 | } else if (obj.isObject) { 21 | System.println(" " * indent, "item[%{key}]:"); 22 | var keys = obj.keySet(); 23 | for (var i = 0, l = keys.length(); i < l; ++i) { 24 | var k = keys[i]; 25 | display(obj[k], k, indent+1); 26 | } 27 | } else { 28 | System.println(" " * indent, "item[%{key}] = ", obj); 29 | } 30 | } 31 | 32 | display(c); 33 | -------------------------------------------------------------------------------- /examples/bench/fib.py: -------------------------------------------------------------------------------- 1 | 2 | def fib(n): 3 | if n < 3: 4 | return n 5 | return fib(n-2) + fib(n-1) 6 | 7 | print fib(34) 8 | 9 | -------------------------------------------------------------------------------- /examples/bench/fib.py3: -------------------------------------------------------------------------------- 1 | 2 | def fib(n): 3 | if n < 3: 4 | return n 5 | return fib(n-2) + fib(n-1) 6 | 7 | print(fib(34)) 8 | 9 | -------------------------------------------------------------------------------- /examples/bench/fib.rb: -------------------------------------------------------------------------------- 1 | 2 | def fib(n) 3 | if n < 3 4 | return n 5 | end 6 | return fib(n-2) + fib(n-1) 7 | end 8 | 9 | print(fib(34), "\n"); 10 | 11 | -------------------------------------------------------------------------------- /examples/binary.kx: -------------------------------------------------------------------------------- 1 | var a = <1, 2, 3, 4>; 2 | var b = ; 3 | b += <2, 3, 0xFF<<4, 5<<1, 0xFF>>4>; 4 | System.println(a.length()); 5 | System.println(b.length()); 6 | 7 | for (var i = 0; i < a.length(); ++i) { 8 | System.println("a[%{i}] = %{a[i]}"); 9 | } 10 | for (var i = 0; i < b.length(); ++i) { 11 | System.println("b[%{i}] = %{b[i]}"); 12 | } 13 | -------------------------------------------------------------------------------- /examples/bubsort.kx: -------------------------------------------------------------------------------- 1 | function display(name, a) { 2 | System.println(name, a.map(&(e) => "%2d" % e).join(' ')); 3 | } 4 | 5 | function demo(N, func) { 6 | var a = N.times(&() => Integer.parseInt(Math.random() * 100)); 7 | display("Before: ", a); 8 | a = func(a); 9 | display("After: ", a); 10 | } 11 | 12 | function bubblesort(n, a) { 13 | var k = n - 1; 14 | while (k >= 0) { 15 | var j = -1; 16 | for (var i = 1; i <= k; i++) { 17 | if (a[i - 1] > a[i]) { 18 | j = i - 1; 19 | [a[i], a[j]] = [a[j], a[i]]; 20 | } 21 | } 22 | k = j; 23 | } 24 | } 25 | 26 | demo(20) { 27 | bubblesort(_1.length(), _1); 28 | return _1; 29 | }; 30 | -------------------------------------------------------------------------------- /examples/c/runkinx.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | cl -I include examples/c/runkinx.c kx.lib 5 | gcc -o runkinx.exe -I include examples/c/runkinx.c -ldl -L. -lkx 6 | */ 7 | 8 | int build_and_run_script(kinx_compiler *kc) 9 | { 10 | kinx_add_argument(kc, "34"); 11 | 12 | const char *filename = "examples/fib_n.kx"; 13 | if (!kinx_loadfile(kc, filename)) { 14 | printf("Failed to load the file: %s\n", filename); 15 | return 1; 16 | } 17 | kinx_add_code(kc, "return r;"); 18 | return kinx_run(kc); 19 | } 20 | 21 | int main(int ac, char **av) 22 | { 23 | kinx_compiler *kc = kinx_create_compiler(); 24 | if (!kc) { 25 | return 1; 26 | } 27 | 28 | int r = build_and_run_script(kc); 29 | printf("r = %d\n", r); 30 | printf("compile time = %8.3f\n", kc->timer.compile); 31 | printf("running time = %8.3f\n", kc->timer.runtime); 32 | kinx_finalize(kc); 33 | return r; 34 | } 35 | -------------------------------------------------------------------------------- /examples/class1.kx: -------------------------------------------------------------------------------- 1 | class PointObject { 2 | 3 | # Class Members. 4 | var xpos_; 5 | var ypos_; 6 | 7 | # Private: 8 | private moveX(x) { xpos_ = x; } 9 | private moveY(y) { ypos_ = y; } 10 | 11 | # Public: 12 | public getX() { return xpos_; } # Get X coord. 13 | public getY() { return ypos_; } # Get Y coord. 14 | public move(x, y) { 15 | moveX(x); 16 | moveY(y); 17 | } 18 | public print() { 19 | System.println("(x,y) = (" + xpos_ + "," + ypos_ + ")"); 20 | } 21 | 22 | } 23 | 24 | class PointBoxObject(xmax, ymax) : PointObject { 25 | var xmax_ = xmax; 26 | var ymax_ = ymax; 27 | 28 | # Override move() 29 | public move(x, y) { 30 | if (x < 0) x = 0; 31 | if (y < 0) y = 0; 32 | if (x > xmax_) x = xmax_; 33 | if (y > ymax_) y = ymax_; 34 | super.move(x, y); # super is available. 35 | } 36 | } 37 | 38 | var p1 = new PointBoxObject(50, 50); 39 | var p2 = new PointBoxObject(20, 20); 40 | 41 | p1.move(32, 32); 42 | p2.move(25, -8); 43 | 44 | p1.print(); 45 | p2.print(); 46 | -------------------------------------------------------------------------------- /examples/class2.kx: -------------------------------------------------------------------------------- 1 | class PointObject { 2 | 3 | # Class Members. 4 | var xpos_; 5 | var ypos_; 6 | 7 | # Private: 8 | private moveX(x) { xpos_ = x; } 9 | private moveY(y) { ypos_ = y; } 10 | 11 | # Public: 12 | public getX() { return xpos_; } # Get X coord. 13 | public getY() { return ypos_; } # Get Y coord. 14 | public move(x, y) { 15 | moveX(x); 16 | moveY(y); 17 | } 18 | public print() { 19 | System.println("(x,y) = (" + xpos_ + "," + ypos_ + ")"); 20 | } 21 | 22 | } 23 | 24 | class PointBoxObject(xmax, ymax) : PointObject { 25 | @xmax = xmax; 26 | @ymax = ymax; 27 | 28 | # Override move() 29 | public move(x, y) { 30 | if (x < 0) x = 0; 31 | if (y < 0) y = 0; 32 | if (x > @xmax) x = @xmax; 33 | if (y > @ymax) y = @ymax; 34 | super.move(x, y); # super is available. 35 | } 36 | } 37 | 38 | var p1 = new PointBoxObject(50, 50); 39 | var p2 = new PointBoxObject(20, 20); 40 | 41 | p1.move(32, 32); 42 | p2.move(25, -8); 43 | 44 | p1.print(); 45 | p2.print(); 46 | -------------------------------------------------------------------------------- /examples/class3.kx: -------------------------------------------------------------------------------- 1 | class Example { 2 | 3 | # Private variable. 4 | var a_; 5 | 6 | # Public property. 7 | this.value = 10; 8 | 9 | # Private method. 10 | private getAimpl() { return a_; } 11 | 12 | # Public method. 13 | public getA() { return getAimpl(); } 14 | public setA(a) { a_ = a; } 15 | 16 | public calc(x) { return x + this.value; } 17 | } 18 | 19 | var instance = new Example(); 20 | System.println("init = ", instance.value, ", calc = ", instance.calc(100)); 21 | -------------------------------------------------------------------------------- /examples/closure.kx: -------------------------------------------------------------------------------- 1 | function newCounter() { 2 | var i = 0; // a lexical variable. 3 | 4 | return function() { // an anonymous function. 5 | ++i; // a reference to a lexical variable. 6 | return i; 7 | }; 8 | } 9 | 10 | var c1 = newCounter(); 11 | System.println(c1()); // 1 12 | System.println(c1()); // 2 13 | System.println(c1()); // 3 14 | System.println(c1()); // 4 15 | System.println(c1()); // 5 16 | -------------------------------------------------------------------------------- /examples/csv.kx: -------------------------------------------------------------------------------- 1 | using CSV; 2 | 3 | var file = $$[0].parentPath() / "csv1.csv"; 4 | System.println("File: ", file); 5 | 6 | System.println("\n--- Parsing the file line by line"); 7 | CSV.parse(file) { &(line) => System.println(line) }; 8 | 9 | System.println("\n--- Parsing the whole text"); 10 | var str = File.load(file); 11 | var r = CSV.parseString(str); 12 | System.println(r.toJsonString(true)); 13 | -------------------------------------------------------------------------------- /examples/csv1.csv: -------------------------------------------------------------------------------- 1 | # comment in CSV. 2 | abcde,efgh,non-quoted string 3 | "abcde","efgh","quoted string" 4 | "abcde",efgh,"quoted & non-quoted string in the same row" 5 | "abcde",efgh,"can use , or "" in csv" 6 | "abcde",efgh,"can use newlines 7 | 8 | in the row" 9 | # another comment in CSV. 10 | abcde,efgh,not necessary \n the end of csv -------------------------------------------------------------------------------- /examples/datetime.kx: -------------------------------------------------------------------------------- 1 | using DateTime; 2 | 3 | System.println("Loop with DateTime Range"); 4 | var dt = DateTime.parse("2019-01-01 09:00:00"); 5 | for (d in (dt ... (dt >> 1))) { 6 | System.println(d); 7 | } 8 | 9 | System.println("\nThe end of the month"); 10 | System.println((dt >> 1) - 1); // The end day of January. 11 | System.println((dt >> 2) - 1); // The end day of February. 12 | -------------------------------------------------------------------------------- /examples/do_while.kx: -------------------------------------------------------------------------------- 1 | 2 | var a, b, c; 3 | b = c = 1; 4 | 5 | LABEL1: 6 | do { 7 | do { 8 | a = b * c; 9 | if (a > 100) break; 10 | if (b > 5) break LABEL1; 11 | ++b; 12 | } 13 | while (b < 10); 14 | ++c; 15 | } 16 | while (c < 20); 17 | -------------------------------------------------------------------------------- /examples/double.kx: -------------------------------------------------------------------------------- 1 | 2 | # Double.pow = Math.pow; 3 | # Double.parseDouble(2).pow(10); 4 | 5 | System.println(Math.pow); 6 | # System.println(2.pow(10)); 7 | System.println(Math.pow(2, 10)); 8 | System.println(2.pow(10)); 9 | System.println(Math.pow(2, 10)); 10 | -------------------------------------------------------------------------------- /examples/enumerable.kx: -------------------------------------------------------------------------------- 1 | 2 | # This is a Fiber example. 3 | 4 | class Enamerable(src_) { 5 | 6 | # := initialize fiber. 7 | private inirtialize() { 8 | src_ = new Fiber(src_); 9 | } 10 | 11 | # := filter 12 | public where(f) { 13 | var pf = src_; 14 | src_ = new Fiber(&{ 15 | while (true) { 16 | var v = pf.resume(); 17 | if (f(v)) { 18 | yield v; 19 | } 20 | } 21 | }); 22 | return this; 23 | } 24 | 25 | # := map 26 | public select(f) { 27 | var pf = src_; 28 | src_ = new Fiber(&{ 29 | while (true) { 30 | var v = pf.resume(); 31 | yield f(v); 32 | } 33 | }); 34 | return this; 35 | } 36 | 37 | public take(n) { 38 | var pf = src_; 39 | src_ = new Fiber(&{ 40 | --n; 41 | for (var i = 0; i < n; ++i) { 42 | yield pf.resume(); 43 | } 44 | return pf.resume(); 45 | }); 46 | return this; 47 | } 48 | 49 | public writeln() { 50 | while (src_.isAlive()) { 51 | var v = src_.resume(); 52 | System.println(v); 53 | } 54 | } 55 | 56 | } 57 | 58 | var Inf = new Fiber(&{ 59 | var i = 0; 60 | while (true) { 61 | yield i; 62 | ++i; 63 | } 64 | }); 65 | 66 | new Enamerable(Inf).where(&(v) => v % 2 == 0).select(&(v) => v * 3).take(10).writeln(); 67 | -------------------------------------------------------------------------------- /examples/esc/progress.kx: -------------------------------------------------------------------------------- 1 | System.print("0% 50% 100%\n"); 2 | System.print("+---------+---------+\n"); 3 | for (i = 0; i <= 100; i++) { 4 | for (j = 0; j < i / 5 + 1; j++) { 5 | System.print("#"); 6 | } 7 | System.print("\n"); 8 | System.print("%3d%%\n" % i); 9 | System.sleep(100); 10 | System.print("\e[2A"); 11 | } 12 | System.print("\n\nfinish!\n"); 13 | -------------------------------------------------------------------------------- /examples/esc/sample1.kx: -------------------------------------------------------------------------------- 1 | for (i = 0; i < 16; i++) { 2 | for (j = 0; j < 16; j++) { 3 | const v = i*16+j; 4 | System.print("\e[38;5;%dm%02X\e[0m " % v % v); 5 | } 6 | System.print("\n"); 7 | } 8 | -------------------------------------------------------------------------------- /examples/esc/sample2.kx: -------------------------------------------------------------------------------- 1 | for (i = 0; i < 16; i++) { 2 | for (j = 0; j < 16; j++) { 3 | const v = (i<<4) | j; 4 | System.print(" \e[48;5;%dm%02X" % v % v); 5 | } 6 | System.print("\e[0m\n"); 7 | } 8 | -------------------------------------------------------------------------------- /examples/esc/sample3.kx: -------------------------------------------------------------------------------- 1 | for (i = 0; i < 16; i++) { 2 | for (j = 0; j < 32; j++) { 3 | System.print("\e[38;2;%d;%d;255mX" % (i<<4) % (j<<3)); 4 | } 5 | System.print("\e[0m\n"); 6 | } 7 | -------------------------------------------------------------------------------- /examples/esc/sample4.kx: -------------------------------------------------------------------------------- 1 | for (i = 0; i < 16; i++) { 2 | for (j = 0; j < 32; j++) { 3 | System.print("\e[48;2;%d;%d;255m " % (i<<4) % (j<<3)); 4 | } 5 | System.print("\e[0m\n"); 6 | } 7 | -------------------------------------------------------------------------------- /examples/esc/sample5.kx: -------------------------------------------------------------------------------- 1 | System.print(" -- "); 2 | for (b in 40..47) { 3 | System.print("\e[%{b}m %{b} \e[0m "); 4 | } 5 | System.print("\n"); 6 | for (c in [ 30, 31, 32, 33, 34, 35, 36, 37, 90, 91, 92, 93, 94, 95, 96, 97 ]) { 7 | s = (""+c); 8 | System.print("\e[%{c}m %{c} \e[0m "); 9 | for (b in 40..47) { 10 | s = "%{c};%{b}"; 11 | System.print("\e[%{s}m %{s} \e[0m "); 12 | } 13 | System.print("\n"); 14 | for (a in [ 1, 4 ]) { 15 | s = "%{c};%{a}"; 16 | System.print("\e[%{s}m %{s} \e[0m "); 17 | for (b in 40..47) { 18 | s = "%{c};%{b};%{a}"; 19 | System.print("\e[%{s}m %{s} \e[0m "); 20 | } 21 | System.print("\n"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/esc/sample6.kx: -------------------------------------------------------------------------------- 1 | (0..4).each(&(r) => { 2 | var g=5; 3 | (0..5).each(&(b) => { 4 | var col = r*36 + g*6 + b + 16; 5 | System.print("\e[48;5;%dm%8d \e[0m" % col % col); 6 | }); 7 | System.println(""); 8 | }); 9 | (0..5).each(&(g) => { 10 | var r=5; 11 | (0..5).each(&(b) => { 12 | var col = r*36 + 30 - g*6 + b + 16; 13 | System.print("\e[48;5;%dm%8d \e[0m" % col % col); 14 | }); 15 | var b=5; 16 | (1..5).each(&(r) => { 17 | var col = 180 - r*36 + 30 - g*6 + b + 16; 18 | System.print("\e[48;5;%dm%8d \e[0m" % col % col); 19 | }); 20 | System.println(""); 21 | }); 22 | -------------------------------------------------------------------------------- /examples/eval.kx: -------------------------------------------------------------------------------- 1 | var a = "var i = 0; var l = $$.length(); while (i < l) System.println('eval value = ', $$[i++]); return {a:100, b:10};"; 2 | var b = a.eval(1000, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); 3 | System.println("b.a = %{b.a}"); 4 | System.println("b.b = %{b.b}"); 5 | return 1; 6 | -------------------------------------------------------------------------------- /examples/fact.kx: -------------------------------------------------------------------------------- 1 | function fact(n) { 2 | if (n < 1) return 1; 3 | return n * fact(n-1); 4 | } 5 | 6 | System.println(fact(5000)); 7 | -------------------------------------------------------------------------------- /examples/fib.kx: -------------------------------------------------------------------------------- 1 | function fib(n) { 2 | if (n < 3) return n; 3 | return fib(n-2) + fib(n-1); 4 | } 5 | 6 | System.println("fib(34) = ", fib(34)); 7 | -------------------------------------------------------------------------------- /examples/fib2.kx: -------------------------------------------------------------------------------- 1 | var a = 0, b = 1; 2 | while (a < 100) { 3 | System.println(b); 4 | [a, b] = [b, a + b]; 5 | } 6 | -------------------------------------------------------------------------------- /examples/fib_n.kx: -------------------------------------------------------------------------------- 1 | function fib(n) { 2 | if (n < 3) return n; 3 | return fib(n-2) + fib(n-1); 4 | } 5 | 6 | var r = fib($$[1].toInt()); 7 | System.println(r); 8 | -------------------------------------------------------------------------------- /examples/fiber.kx: -------------------------------------------------------------------------------- 1 | 2 | var fib = new Fiber { 3 | var a = 0, b = 1; 4 | while (true) { 5 | yield b; 6 | [a, b] = [b, a + b]; 7 | } 8 | }; 9 | 10 | var r = 35.times().map { => fib.resume() }; 11 | r.each { &(v, i) => System.println("fibonacci[%2d] = %7d" % i % v) }; 12 | -------------------------------------------------------------------------------- /examples/for.kx: -------------------------------------------------------------------------------- 1 | 2 | var a, b, c, i; 3 | b = c = 1; 4 | 5 | LABEL: 6 | for (var i = 0; i < 100; ++i) { 7 | b = 1; 8 | if (i < 10) continue LABEL; 9 | if (i > 20) break; 10 | c++; 11 | } 12 | 13 | System.println("b = ", b); 14 | System.println("c = ", c); 15 | -------------------------------------------------------------------------------- /examples/hanoi.kx: -------------------------------------------------------------------------------- 1 | function movedisk(n, a, b) { 2 | if (n > 1) movedisk(n - 1, a, 6 - a - b); 3 | System.println("Move the disk %d from %d to %d." % n % a % b); 4 | if (n > 1) movedisk(n - 1, 6 - a - b, b); 5 | } 6 | 7 | const N = 4; 8 | System.println("The steps to move %d disks from the tower 1 to the tower 2 is" 9 | " %u steps." % N % ((1 << N) - 1)); 10 | movedisk(N, 1, 2); 11 | -------------------------------------------------------------------------------- /examples/heapsort.kx: -------------------------------------------------------------------------------- 1 | function display(name, a) { 2 | System.println(name, a.map(&(e) => "%2d" % e).join(' ')); 3 | } 4 | 5 | function demo(N, func) { 6 | var a = N.times(&() => Integer.parseInt(Math.random() * 100)); 7 | display("Before: ", a); 8 | a = func(a); 9 | display("After: ", a); 10 | } 11 | 12 | function heapsort(n, a) { 13 | var i, j, k; 14 | var x; 15 | 16 | for (k = Integer.parseInt(n / 2); k >= 1; k--) { 17 | i = k; x = a[i]; 18 | while ((j = 2 * i) <= n) { 19 | if (j < n && a[j] < a[j + 1]) j++; 20 | if (x >= a[j]) break; 21 | a[i] = a[j]; i = j; 22 | } 23 | a[i] = x; 24 | } 25 | while (n > 1) { 26 | x = a[n]; a[n] = a[1]; n--; 27 | i = 1; 28 | while ((j = 2 * i) <= n) { 29 | if (j < n && a[j] < a[j + 1]) j++; 30 | if (x >= a[j]) break; 31 | a[i] = a[j]; i = j; 32 | } 33 | a[i] = x; 34 | } 35 | } 36 | 37 | demo(20) { &(a) 38 | a = [0, ...a]; 39 | heapsort(a.length() - 1, a); 40 | a.shift(); 41 | return a; 42 | }; 43 | -------------------------------------------------------------------------------- /examples/http.kx: -------------------------------------------------------------------------------- 1 | var http = new Net.Http(); 2 | 3 | # http.setDebugDetail(true, { hex: false }); 4 | # http.setDebug(&(info) => { 5 | # System.println("DBG> ", info); 6 | # }); 7 | 8 | function get(http, url) { 9 | System.println("URL = %{url}"); 10 | http.addHeader("X-Hook-K1", "What is this?"); 11 | http.addHeader("X-Hook-K3"); 12 | http.sslVerifyPeer(false); 13 | http.sslVerifyHost(false); 14 | var length = 0; 15 | http.get(url, &(data) => { 16 | System.println("Received: %d" % data.length()); 17 | length += data.length(); 18 | }); 19 | System.println("Total = %d bytes" % length); 20 | System.println(""); 21 | } 22 | 23 | get(http, "https://ja.wikipedia.org/wiki/OpenSSL"); 24 | get(http, "https://curl.haxx.se/libcurl/c/multi-debugcallback.html"); 25 | get(http, "http://herumi.in.coocan.jp/soft/xbyak.html"); 26 | -------------------------------------------------------------------------------- /examples/idprop.kx: -------------------------------------------------------------------------------- 1 | 2 | var a = [ 3 | null, 4 | 1, 5 | 9223372036854775808, 6 | "abc", 7 | "abcdef"+100, 8 | 12.5, 9 | function() {}, 10 | [1, 2, 3], 11 | { x: 100, y: 200 }, 12 | <1,2,3>, 13 | ]; 14 | 15 | var l = a.length(); 16 | for (var i = 0; i < l; ++i) { 17 | System.println("target: ", a[i]); 18 | System.println(" isUndefined = ", a[i].isUndefined); 19 | System.println(" isInteger = ", a[i].isInteger); 20 | System.println(" isBigInteger = ", a[i].isBigInteger); 21 | System.println(" isString = ", a[i].isString); 22 | System.println(" isDouble = ", a[i].isDouble); 23 | System.println(" isBinary = ", a[i].isBinary); 24 | System.println(" isFunction = ", a[i].isFunction); 25 | System.println(" isArray = ", a[i].isArray); 26 | System.println(" isObject = ", a[i].isObject); 27 | } 28 | -------------------------------------------------------------------------------- /examples/initialize.kx: -------------------------------------------------------------------------------- 1 | class Example(i, j) { 2 | private initialize() { 3 | System.println("i = ", i); 4 | System.println("j = ", j); 5 | } 6 | } 7 | 8 | new Example(10, 20); 9 | new Example(100, 200); 10 | -------------------------------------------------------------------------------- /examples/inner.kx: -------------------------------------------------------------------------------- 1 | 2 | var x = %{ 3 | aaa%{123}bbb 4 | }; 5 | System.println("'" + x.trim() + "'"); 6 | 7 | var a = 100; 8 | var b = 10; 9 | System.println("%{a * (b + 2)}"); 10 | System.println(%|%{a} * (%{b} + 2) = %{a * (b + 2)}|); 11 | System.println("'" + " aaa%{1 + (b + 2)} ".trim() + "'"); 12 | 13 | System.println(%-{ 14 | expression(1) = %{a * (b + 2)}; 15 | expression(2) = "%{a} * (%{b} + 2) = %{a * (b + 2)}"; 16 | }); 17 | 18 | System.println(%{ 19 | expression(1) = %{a * (b + 2)}; 20 | expression(2) = "%{a} * (%{b} + 2) = %{a * (b + 2)}"; 21 | }.trim()); 22 | -------------------------------------------------------------------------------- /examples/inssort.kx: -------------------------------------------------------------------------------- 1 | function display(name, a) { 2 | System.println(name, a.map(&(e) => "%2d" % e).join(' ')); 3 | } 4 | 5 | function demo(N, func) { 6 | var a = N.times(&() => Integer.parseInt(Math.random() * 100)); 7 | display("Before: ", a); 8 | a = func(a); 9 | display("After: ", a); 10 | } 11 | 12 | function inssort(n, a) { 13 | var j; 14 | for (var i = 1; i < n; i++) { 15 | var x = a[i]; 16 | for (j = i - 1; j >= 0 && a[j] > x; j--) 17 | a[j + 1] = a[j]; 18 | a[j + 1] = x; 19 | } 20 | } 21 | 22 | demo(20) { 23 | inssort(_1.length(), _1); 24 | return _1; 25 | }; 26 | -------------------------------------------------------------------------------- /examples/instanceOf.kx: -------------------------------------------------------------------------------- 1 | class Example1 { 2 | 3 | } 4 | 5 | class Example2 : Example1 { 6 | 7 | } 8 | 9 | class Example3 : Example2 { 10 | 11 | } 12 | 13 | var classNames = [ 14 | { name: "Example1", base: Example1 }, 15 | { name: "Example2", base: Example2 }, 16 | { name: "Example3", base: Example3 }, 17 | ]; 18 | 19 | function checkInstanceOf(instance, name) { 20 | var len = classNames.length(); 21 | for (var i = 0; i < len; ++i) { 22 | if (instance.instanceOf(classNames[i].base)) { 23 | System.println(name, " is the instance of ", classNames[i].name); 24 | } else { 25 | System.println("--- ", name, " is NOT the instance of ", classNames[i].name); 26 | } 27 | } 28 | } 29 | 30 | var e1 = new Example1(); 31 | var e2 = new Example2(); 32 | var e3 = new Example3(); 33 | checkInstanceOf(e1, "e1"); 34 | checkInstanceOf(e2, "e2"); 35 | checkInstanceOf(e3, "e3"); 36 | -------------------------------------------------------------------------------- /examples/integer.kx: -------------------------------------------------------------------------------- 1 | var a = 10.5; 2 | Integer.parseInt(a).times(function(i) { 3 | if (i > 0) 4 | System.print(", "); 5 | System.print(i); 6 | }); 7 | System.println(""); 8 | 9 | function listing(i, index) { 10 | if (index > 0) 11 | System.print(", "); 12 | System.print(i); 13 | } 14 | 15 | 10.times(listing); 16 | System.println(""); 17 | 18 | 5.upto(10, listing); 19 | System.println(""); 20 | 21 | 10.downto(5, listing); 22 | System.println(""); 23 | 24 | var b = 9223372036854775808 * 2; 25 | 26 | b.upto(b + 10, listing); 27 | System.println(""); 28 | 29 | b.downto(b - 10, listing); 30 | System.println(""); 31 | 32 | System.println("92233720368547758080".parseInt() / 10); 33 | System.println("92233720368547758080".parseInt() / 100); 34 | System.println("256".parseInt() * 10); 35 | -------------------------------------------------------------------------------- /examples/isolate1.kx: -------------------------------------------------------------------------------- 1 | /* 2 | `fibcode` is just a string. 3 | - Isolate#run will create a thread, compile, and run with eval. 4 | - Isolate#join will wait for the end of thread. 5 | */ 6 | var fibcode = %{ 7 | function fib(n) { 8 | return n < 3 ? n : fib(n-2) + fib(n-1); 9 | } 10 | var mutex = new Isolate.Mutex(); 11 | mutex.lock(&() => System.println("fib(%1%) = ", fib(%1%))); 12 | }; 13 | 14 | var iso = []; 15 | for (var i = 34; i > 0; --i) { 16 | iso[i] = new Isolate(fibcode % i); 17 | iso[i].run(); 18 | } 19 | for (var i = 34; i > 0; --i) { 20 | iso[i].join(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/isolate2.kx: -------------------------------------------------------------------------------- 1 | /* 2 | Isolate.Mutex is the mutex class. 3 | Isolate.Condition is the condition class. 4 | If you want 2 or more mutexes or conditions, you can distinguish it 5 | by using the name like `new Isolate.Mutex('name')`. 6 | */ 7 | var cond = %{ 8 | var m = new Isolate.Mutex(); 9 | var c = new Isolate.Condition(); 10 | m.lock(&() => { 11 | var i = 0; 12 | while (i < 10) { 13 | System.println("Wait %1%"); 14 | c.wait(m); 15 | System.println("Received %1%"); 16 | ++i; 17 | } 18 | System.println("Ended %1%"); 19 | }); 20 | }; 21 | 22 | var iso = []; 23 | for (var i = 34; i > 0; --i) { 24 | iso[i] = new Isolate(cond % i); 25 | iso[i].run(); 26 | } 27 | System.sleep(1000); 28 | var c = new Isolate.Condition(); 29 | for (var i = 34; i > 0; --i) { 30 | System.println("\nNotify ", i); 31 | c.notifyAll(); 32 | System.sleep(500); 33 | } 34 | for (var i = 34; i > 0; --i) { 35 | iso[i].join(); 36 | } 37 | -------------------------------------------------------------------------------- /examples/jit_fib.kx: -------------------------------------------------------------------------------- 1 | using Jit; 2 | 3 | var c = new Jit.Compiler(); 4 | var entry1 = c.enter(); 5 | var jump0 = c.ge(Jit.S0, Jit.IMM(3)); 6 | c.ret(Jit.S0); 7 | var l1 = c.label(); 8 | c.sub(Jit.R0, Jit.S0, Jit.IMM(2)); 9 | c.call(entry1); 10 | c.mov(Jit.S1, Jit.R0); 11 | c.sub(Jit.R0, Jit.S0, Jit.IMM(1)); 12 | c.call(entry1); 13 | c.add(Jit.R0, Jit.R0, Jit.S1); 14 | c.ret(Jit.R0); 15 | 16 | jump0.setLabel(l1); 17 | 18 | var i = Integer.parseInt($$[1]); 19 | var code = c.generate(); 20 | System.println("fib(%2d) = %d" % i % code.run(i)); 21 | -------------------------------------------------------------------------------- /examples/jit_x64.kx: -------------------------------------------------------------------------------- 1 | using Jit; 2 | 3 | var code 4 | = System.PLATFORM == "X86_64-WIN" ? <0x48, 0x89, 0xc8, 0xc3> // mov rax, rcx | ret 5 | : System.PLATFORM == "X86_64" ? <0x48, 0x89, 0xf8, 0xc3> // mov rax, rdi | ret 6 | : null; 7 | if (!code.isBinary) { 8 | throw RuntimeException("Unsupported platform: " + System.PLATFORM); 9 | } 10 | 11 | Jit.dump(code); 12 | var runner = new Jit.Runner(code); 13 | System.println(runner.run(100)); 14 | -------------------------------------------------------------------------------- /examples/json.kx: -------------------------------------------------------------------------------- 1 | 2 | function display(obj, key, indent) { 3 | if (obj.isArray) { 4 | System.println(" " * indent, "item[%{key}]:"); 5 | for (var i = 0, l = obj.length(); i < l; ++i) { 6 | display(obj[i], i, indent+1); 7 | } 8 | } else if (obj.isObject) { 9 | System.println(" " * indent, "item[%{key}]:"); 10 | var keys = obj.keySet(); 11 | for (var i = 0, l = keys.length(); i < l; ++i) { 12 | var k = keys[i]; 13 | display(obj[k], k, indent+1); 14 | } 15 | } else { 16 | System.println(" " * indent, "item[%{key}] = ", obj); 17 | } 18 | } 19 | 20 | display(JSON.parse(%{ 21 | [ "Sample" + " (" + 1 + ")", 22 | { "x": 410, "y": 150 * (20 + 1), "type": "link", "path": "/Applications" }, 23 | { 24 | "p1": { "x": 130, "y": 150, "type": "file" }, 25 | "p2": { "x": 230, "y": 90, "type": "directory" } 26 | } 27 | ] 28 | })); 29 | -------------------------------------------------------------------------------- /examples/knight.kx: -------------------------------------------------------------------------------- 1 | const N = 5; // N x N 2 | 3 | var board = [], 4 | dx = [ 2, 1,-1,-2,-2,-1, 1, 2 ], 5 | dy = [ 1, 2, 2, 1,-1,-2,-2,-1 ]; 6 | var count = 0; 7 | var solution = 0; 8 | 9 | function printboard() { 10 | System.print("\nSolution %d\n" % ++solution); 11 | for (var i = 2; i <= N + 1; i++) { 12 | for (var j = 2; j <= N + 1; j++) System.print("%4d" % board[i][j]); 13 | System.print("\n"); 14 | } 15 | } 16 | 17 | function test(x, y) { 18 | if (board[x][y] != 0) return; 19 | board[x][y] = ++count; 20 | if (count == N * N) printboard(); 21 | else for (var i = 0; i < 8; i++) test(x + dx[i], y + dy[i]); 22 | board[x][y] = 0; count--; 23 | } 24 | 25 | function knight() { 26 | for (var i = 0; i <= N + 3; i++) 27 | for (var j = 0; j <= N + 3; j++) board[i][j] = 1; 28 | for (var i = 2; i <= N + 1; i++) 29 | for (var j = 2; j <= N + 1; j++) board[i][j] = 0; 30 | test(2, 2); 31 | } 32 | 33 | knight(); 34 | -------------------------------------------------------------------------------- /examples/lambda.kx: -------------------------------------------------------------------------------- 1 | function calc(x, y, func) { 2 | return func(x, y); 3 | } 4 | 5 | System.println("add = " + calc(10, 2, &(a, b) => a + b)); 6 | System.println("sub = " + calc(10, 2, &(a, b) => a - b)); 7 | System.println("mul = " + calc(10, 2, &(a, b) => a * b)); 8 | System.println("div = " + calc(10, 2, &(a, b) => a / b)); 9 | -------------------------------------------------------------------------------- /examples/life.kx: -------------------------------------------------------------------------------- 1 | 2 | const N = 22; // Vertical 3 | const M = 78; // Horizontal 4 | var a = [], b = []; 5 | a[N/2][M/2] = a[N/2-1][M/2] = a[N/2+1][M/2] = a[N/2][M/2-1] = a[N/2-1][M/2+1] = 1; 6 | 7 | function life() { 8 | for (var g = 1; g <= 1000; g++) { 9 | System.print("Generation %4d\n" % g) if (g == 1000); 10 | for (var i = 1; i <= N; i++) { 11 | for (var j = 1; j <= M; j++) 12 | if (a[i][j]) { 13 | System.print("*") if (g == 1000); 14 | b[i-1][j-1]++; b[i-1][j]++; b[i-1][j+1]++; 15 | b[i ][j-1]++; b[i ][j+1]++; 16 | b[i+1][j-1]++; b[i+1][j]++; b[i+1][j+1]++; 17 | } else System.print(".") if (g == 1000); 18 | System.print("\n") if (g == 1000); 19 | } 20 | for (var i = 0; i <= N + 1; i++) 21 | for (var j = 0; j <= M + 1; j++) { 22 | if (b[i][j] != 2) a[i][j] = (b[i][j] == 3); 23 | b[i][j] = 0; 24 | } 25 | } 26 | } 27 | 28 | life(); 29 | -------------------------------------------------------------------------------- /examples/magic4.kx: -------------------------------------------------------------------------------- 1 | var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, 2 | x, count = 0, 3 | ok11 = []; 4 | 5 | for (x = -11; x <= 0; x++) ok[x+11] = 0; 6 | for (x = 1; x <= 16; x++) ok[x+11] = 1; 7 | for (x = 17; x <= 28; x++) ok[x+11] = 0; 8 | for (a = 1; a <= 16; a++) { ok[a+11] = 0; 9 | for (d = a + 1; d <= 16; d++) { ok[d+11] = 0; 10 | for (m = d + 1; m <= 16; m++) { ok[m+11] = 0; 11 | p = 34 - a - d - m; 12 | if (ok[p+11] && a < p) { ok[p+11] = 0; 13 | for (b = 1; b <= 16; b++) if (ok[b+11]) { ok[b+11]=0; c = 34 - a - b - d; if (ok[c+11]) { ok[c+11]=0; 14 | for (f = 1; f <= 16; f++) if (ok[f+11]) { ok[f+11]=0; k = 34 - a - f - p; if (ok[k+11]) { ok[k+11]=0; 15 | for (g = 1; g <= 16; g++) if (ok[g+11]) { ok[g+11]=0; j = 34 - d - g - m; 16 | if (ok[j+11]) { ok[j+11]=0; n = 34 - b - f - j; if (ok[n+11]) { ok[n+11]=0; o = 34 - c - g - k; if (ok[o+11]) { ok[o+11]=0; 17 | for (e = 1; e <= 16; e++) if (ok[e+11]) { ok[e+11]=0; i = 34 - a - e - m; 18 | if (ok[i+11]) { ok[i+11]=0; h = 34 - e - f - g; if (ok[h+11]) { ok[h+11]=0; l = 34 - i - j - k; 19 | if (ok[l+11]) { 20 | System.print("Solution %d\n" % ++count); 21 | System.print("%4d%4d%4d%4d\n%4d%4d%4d%4d\n%4d%4d%4d%4d\n%4d%4d%4d%4d\n" 22 | % a % b % c % d % e % f % g % h % i % j % k % l % m % n % o % p); 23 | } ok[h+11]=1; } ok[i+11]=1; } ok[e+11]=1; } ok[o+11]=1; } ok[n+11]=1; } ok[j+11]=1; } ok[g+11]=1; } ok[k+11]=1; 24 | } ok[f+11]=1; } ok[c+11]=1; } ok[b+11]=1; } ok[p+11]=1; } ok[m+11]=1; } ok[d+11]=1; } ok[a+11]=1; 25 | } 26 | -------------------------------------------------------------------------------- /examples/magicsq.kx: -------------------------------------------------------------------------------- 1 | const N = 19; // odd number 2 | var a = []; 3 | 4 | var k = 0; 5 | for (var i = - (N / 2).toInt(), end = (N / 2).toInt(); i <= end; i++) 6 | for (var j = 0; j < N; j++) 7 | a[(j - i + N) % N][(j + i + N) % N] = ++k; 8 | for (var i = 0; i < N; i++) { 9 | for (var j = 0; j < N; j++) System.print("%4d" % a[i][j]); 10 | System.print("\n"); 11 | } 12 | -------------------------------------------------------------------------------- /examples/mandelbrot.kx: -------------------------------------------------------------------------------- 1 | const BAILOUT = 16; 2 | const MAX_ITERATIONS = 1000; 3 | 4 | function mandelbrot(x, y) { 5 | var cr = y - 0.5; 6 | var ci = x; 7 | var zi = 0.0; 8 | var zr = 0.0; 9 | var i = 0; 10 | 11 | while (true) { 12 | i++; 13 | var temp = zr * zi; 14 | var zr2 = zr * zr; 15 | var zi2 = zi * zi; 16 | zr = zr2 - zi2 + cr; 17 | zi = temp + temp + ci; 18 | if (zi2 + zr2 > BAILOUT) 19 | return i; 20 | if (i > MAX_ITERATIONS) 21 | return 0; 22 | } 23 | } 24 | 25 | 26 | var tmr = new SystemTimer(); 27 | var x,y; 28 | for (y = -39; y < 39; y++) { 29 | System.print("\n"); 30 | for (x = -39; x < 39; x++) { 31 | var i = mandelbrot(x/40.0, y/40.0); 32 | if (i==0) 33 | System.print("*"); 34 | else 35 | System.print(" "); 36 | } 37 | } 38 | System.print("\n"); 39 | System.print("Kinx Elapsed %0.3f\n" % tmr.elapsed()); 40 | -------------------------------------------------------------------------------- /examples/mandelbrotn.kx: -------------------------------------------------------------------------------- 1 | const BAILOUT = 16; 2 | const MAX_ITERATIONS = 1000; 3 | 4 | native mandelbrot(x:dbl, y:dbl) { 5 | var cr = y - 0.5; 6 | var ci = x; 7 | var zi = 0.0; 8 | var zr = 0.0; 9 | var i = 0; 10 | 11 | while (true) { 12 | i++; 13 | var temp = zr * zi; 14 | var zr2 = zr * zr; 15 | var zi2 = zi * zi; 16 | zr = zr2 - zi2 + cr; 17 | zi = temp + temp + ci; 18 | if (zi2 + zr2 > BAILOUT) 19 | return i; 20 | if (i > MAX_ITERATIONS) 21 | return 0; 22 | } 23 | } 24 | 25 | 26 | var tmr = new SystemTimer(); 27 | var x,y; 28 | for (y = -39; y < 39; y++) { 29 | System.print("\n"); 30 | for (x = -39; x < 39; x++) { 31 | var i = mandelbrot(x/40.0, y/40.0); 32 | if (i==0) 33 | System.print("*"); 34 | else 35 | System.print(" "); 36 | } 37 | } 38 | System.print("\n"); 39 | System.print("Kinx(native) Elapsed %0.3f\n" % tmr.elapsed()); 40 | -------------------------------------------------------------------------------- /examples/mergsort.kx: -------------------------------------------------------------------------------- 1 | function display(name, a) { 2 | System.println(name, a.map(&(e) => "%2d" % e).join(' ')); 3 | } 4 | 5 | function demo(N, func) { 6 | var a = N.times(&() => Integer.parseInt(Math.random() * 100)); 7 | display("Before: ", a); 8 | a = func(a); 9 | display("After: ", a); 10 | } 11 | 12 | function mergesort(a, first, last) { 13 | var middle, work = []; 14 | var i, j, k, p; 15 | 16 | if (first < last) { 17 | middle = Integer.parseInt((first + last) / 2); 18 | mergesort(a, first, middle); 19 | mergesort(a, middle + 1, last); 20 | p = 0; 21 | for (i = first; i <= middle; i++) { 22 | work[p++] = a[i]; 23 | } 24 | i = middle + 1; 25 | j = 0; 26 | k = first; 27 | while (i <= last && j < p) { 28 | if (work[j] <= a[i]) { 29 | a[k++] = work[j++]; 30 | } else { 31 | a[k++] = a[i++]; 32 | } 33 | } 34 | while (j < p) { 35 | a[k++] = work[j++]; 36 | } 37 | } 38 | } 39 | 40 | demo(20) { 41 | mergesort(_1, 0, _1.length() - 1); 42 | return _1; 43 | }; 44 | -------------------------------------------------------------------------------- /examples/mixin.kx: -------------------------------------------------------------------------------- 1 | module Printable { 2 | public print() { 3 | System.print(@value); 4 | } 5 | public println() { 6 | System.println(@value); 7 | } 8 | } 9 | 10 | class Value(v) { 11 | mixin Printable; 12 | private initialize() { 13 | @value = v; 14 | } 15 | } 16 | 17 | var v = new Value(100); 18 | v.println(); // 100 19 | -------------------------------------------------------------------------------- /examples/namespacex.kx: -------------------------------------------------------------------------------- 1 | 2 | namespace Name1 { 3 | 4 | class X { 5 | public methodX() { 6 | System.println("x1"); 7 | } 8 | } 9 | 10 | var x = new X(); 11 | x.methodX(); 12 | 13 | namespace Name2 { 14 | 15 | class X { 16 | public methodX() { 17 | System.println("x2"); 18 | } 19 | } 20 | 21 | var x = new X(); 22 | x.methodX(); 23 | 24 | } # namespace Name2 25 | 26 | } # namespace Name1 27 | 28 | var x1 = new Name1.X(); 29 | x1.methodX(); 30 | 31 | var x2 = new Name1.Name2.X(); 32 | x2.methodX(); 33 | -------------------------------------------------------------------------------- /examples/native.kx: -------------------------------------------------------------------------------- 1 | var n = 10000; 2 | 3 | native loop_whilen(n) { 4 | var v = 0, i = 0; 5 | while (i <= n) { 6 | v += i++; 7 | } 8 | return v; 9 | } 10 | 11 | native loop_forn(n) { 12 | var v = 0; 13 | for (var i = 0; i <= n; ++i) { 14 | v += i; 15 | } 16 | return v; 17 | } 18 | 19 | native loop_do_whilen(n) { 20 | var v = 0, i = 0; 21 | do { 22 | v += i++; 23 | } while (i <= n); 24 | return v; 25 | } 26 | 27 | System.println("while(%{n}) = ", loop_whilen(n)); 28 | System.println("for(%{n}) = ", loop_forn(n)); 29 | System.println("do_while(%{n}) = ", loop_do_whilen(n)); 30 | 31 | function loop_while(n) { 32 | var v = 0, i = 0; 33 | while (i <= n) { 34 | v += i++; 35 | } 36 | return v; 37 | } 38 | 39 | function loop_for(n) { 40 | var i, v = 0; 41 | for (i = 0; i <= n; ++i) { 42 | v += i; 43 | } 44 | return v; 45 | } 46 | 47 | function loop_do_while(n) { 48 | var v = 0, i = 0; 49 | do { 50 | v += i++; 51 | } while (i <= n); 52 | return v; 53 | } 54 | 55 | System.println("while(%{n}) = ", loop_while(n)); 56 | System.println("for(%{n}) = ", loop_for(n)); 57 | System.println("do_while(%{n}) = ", loop_do_while(n)); 58 | -------------------------------------------------------------------------------- /examples/native_dbl.kx: -------------------------------------------------------------------------------- 1 | 2 | var b = 1.7; 3 | native test(a:dbl):dbl { 4 | return a + b; 5 | } 6 | 7 | System.println(test(1.5)); 8 | -------------------------------------------------------------------------------- /examples/native_fact.kx: -------------------------------------------------------------------------------- 1 | 2 | # here is a native function. 3 | native factn(a) { 4 | if (a < 1) return 1; 5 | return a * factn(a-1); 6 | } 7 | 8 | # integer will NOT be promoted automatically to big integer in the native function. 9 | for (var i = 0; i <= 20; ++i) { 10 | System.println("fact(%{i}) = ", factn(i)); 11 | } 12 | 13 | # overwrite the function by the same name. 14 | function fact(a) { 15 | if (a < 1) return 1; 16 | return a * fact(a-1); 17 | } 18 | 19 | # integer will be promoted automatically to big integer. 20 | for (var i = 0; i <= 20; ++i) { 21 | System.println("fact(%{i}) = ", fact(i)); 22 | } 23 | -------------------------------------------------------------------------------- /examples/native_fib.kx: -------------------------------------------------------------------------------- 1 | native fib(a) { 2 | if (a < 3) return a; 3 | return fib(a-2) + fib(a-1); 4 | } 5 | 6 | System.println("fib(34) = ", fib(34)); 7 | 8 | -------------------------------------------------------------------------------- /examples/native_label.kx: -------------------------------------------------------------------------------- 1 | var n = 10000; 2 | 3 | native loop_while(n) { 4 | var v = 0, i = 0; 5 | LABEL: 6 | while (1) { 7 | while (i <= n) { 8 | if (i == 9) { 9 | ++i; 10 | continue; 11 | } 12 | v += i++; 13 | if (i > 10) break LABEL; 14 | } 15 | } 16 | return v; 17 | } 18 | 19 | native loop_for(n) { 20 | var v = 0; 21 | LABEL: 22 | while (1) { 23 | for (var i = 0; i <= n; ++i) { 24 | if (i == 9) continue; 25 | v += i; 26 | if (i == 10) break LABEL; 27 | } 28 | } 29 | return v; 30 | } 31 | 32 | native loop_do_while(n) { 33 | var v = 0, i = 0; 34 | LABEL: 35 | while (1) { 36 | do { 37 | if (i == 9) { 38 | ++i; 39 | continue; 40 | } 41 | v += i++; 42 | if (i > 10) break LABEL; 43 | } while (i <= n); 44 | } 45 | return v; 46 | } 47 | 48 | System.println("while(%{n}) = ", loop_while(n)); 49 | System.println("for(%{n}) = ", loop_for(n)); 50 | System.println("do_while(%{n}) = ", loop_do_while(n)); 51 | -------------------------------------------------------------------------------- /examples/native_lex.kx: -------------------------------------------------------------------------------- 1 | # native function can access lexical variable. 2 | 3 | var a = 1; 4 | native test(n) { 5 | var b = a; 6 | return b + n; 7 | } 8 | 9 | System.println("test(10) = ", test(10)); 10 | 11 | var mul2:native; # Forward declaration. Same as 'mul2:native(int)' 12 | 13 | native mul2_hook(f:native, a) { 14 | return f(a); # type check. 15 | } 16 | 17 | var x, y; 18 | native test2(i) { 19 | return x = y = mul2_hook(mul2, i); # calling a lexical native function. 20 | } 21 | 22 | mul2 = native(a) { 23 | return a * 2; 24 | }; 25 | 26 | System.println("test2(10) = ", test2(10)); 27 | System.println("x = ", x); 28 | System.println("y = ", y); 29 | -------------------------------------------------------------------------------- /examples/native_sum.kx: -------------------------------------------------------------------------------- 1 | function sum(n) { 2 | var sum = 0; 3 | while (n--) { 4 | sum += n; 5 | } 6 | return sum; 7 | } 8 | 9 | native sumn(n) { 10 | var sum = 0; 11 | while (n--) { 12 | sum += n; 13 | } 14 | return sum; 15 | } 16 | 17 | System.println(sum(100)); 18 | System.println(sumn(100)); 19 | 20 | var a = 100; 21 | -------------------------------------------------------------------------------- /examples/native_swtch_case.kx: -------------------------------------------------------------------------------- 1 | var y = 19; 2 | native f(a, x) { 3 | var b = 0; 4 | switch (a) { 5 | case 1: 6 | b = a; 7 | break; 8 | case 5: 9 | b = a; 10 | break; 11 | default: 12 | b = 100; 13 | break; 14 | case 4: 15 | b = a; 16 | break; 17 | case 3: 18 | b = a; 19 | break; 20 | case 8: 21 | b = 10; 22 | break; 23 | case 9: 24 | b = a; 25 | break; 26 | case x: 27 | b = 1000; 28 | break; 29 | case y: 30 | b = 10000; 31 | break; 32 | case y+1: 33 | b = 100000; 34 | break; 35 | case x+3: 36 | b = 1000000; 37 | break; 38 | } 39 | return b; 40 | } 41 | System.println(f(1, 18)); 42 | System.println(f(2, 18)); 43 | System.println(f(3, 18)); 44 | System.println(f(4, 18)); 45 | System.println(f(5, 18)); 46 | System.println(f(6, 18)); 47 | System.println(f(7, 18)); 48 | System.println(f(8, 18)); 49 | System.println(f(9, 18)); 50 | System.println(f(18, 18)); 51 | System.println(f(19, 18)); 52 | System.println(f(20, 18)); 53 | System.println(f(21, 18)); 54 | -------------------------------------------------------------------------------- /examples/native_too_deep.kx: -------------------------------------------------------------------------------- 1 | 2 | native tooDeep(n) { 3 | return tooDeep(n-1); # infinite loop! 4 | } 5 | 6 | tooDeep(100); 7 | -------------------------------------------------------------------------------- /examples/native_trycatch.kx: -------------------------------------------------------------------------------- 1 | var b = 100; 2 | var c = 100; 3 | function test() { 4 | var d = 0; 5 | return native (n) { 6 | var a = 100; 7 | try { 8 | try { 9 | a /= d; 10 | } finally { 11 | ++b; 12 | } 13 | b %= 9; 14 | } catch (e) { 15 | c = 999; 16 | throw; 17 | } finally { 18 | ++b; 19 | } 20 | return a; 21 | }; 22 | } 23 | 24 | var try_catch = test(); 25 | try { 26 | System.println("b = ", b); 27 | System.println(try_catch(10)); 28 | } catch (e) { 29 | System.println(e.what()); 30 | e.printStackTrace(); 31 | } finally { 32 | System.println("b = ", b); 33 | System.println("c = ", c); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /examples/nqueens.kx: -------------------------------------------------------------------------------- 1 | var a = [], b = [], c = [], x = []; 2 | var solution = 0; 3 | 4 | function found(n) { 5 | System.print("\nSolution %d\n" % ++solution); 6 | for (var i = 0; i < n; i++) { 7 | for (var j = 0; j < n; j++) 8 | if (x[i] == j) System.print(" Q"); 9 | else System.print(" ."); 10 | System.print("\n"); 11 | } 12 | } 13 | 14 | function test(i, n) { 15 | for (var j = 0; j < n; j++) 16 | if (a[j] && b[i + j] && c[i - j + n - 1]) { 17 | x[i] = j; 18 | if (i < n - 1) { 19 | a[j] = b[i + j] = c[i - j + n - 1] = 0; 20 | test(i + 1, n); 21 | a[j] = b[i + j] = c[i - j + n - 1] = 1; 22 | } else found(n); 23 | } 24 | } 25 | 26 | function nqueen(n) { 27 | for (var i = 0; i < n; i++) a[i] = 1; 28 | for (var i = 0; i < 2 * n - 1; i++) b[i] = 1; 29 | for (var i = 0; i < 2 * n - 1; i++) c[i] = 1; 30 | test(0, n); 31 | } 32 | 33 | nqueen(8); 34 | -------------------------------------------------------------------------------- /examples/option.kx: -------------------------------------------------------------------------------- 1 | var opt, add, check, list = []; 2 | while (opt = System.getopt($$, "a:d", { add: 'a', delete: 'd', help: null, "do-check": '=' })) { 3 | switch (opt.type) { 4 | case 'a': // Retuns 'a' also when specofied '--add'. 5 | add = opt.arg; // ':' means the option of 'check' has an argument. 6 | System.println('-a with "%{add}"'); 7 | break; 8 | case 'd': // Retuns 'd' also when specofied '--delete'. 9 | System.println('-d'); 10 | break; 11 | case 'help': // When specified '--help'. 12 | System.println('--help'); 13 | break; 14 | case 'do-check': // When specified '--do-check'. 15 | check = opt.arg; // '=' means the option of 'check' has an argument. 16 | System.println('--do-check with "%{check}"'); 17 | break; 18 | case '-': 19 | list.push(opt.arg); 20 | break; 21 | } 22 | } 23 | 24 | System.println("Program options: ", list); 25 | -------------------------------------------------------------------------------- /examples/parser3.kx: -------------------------------------------------------------------------------- 1 | using Parsek; 2 | 3 | var $E = new Parsek(); 4 | var $D = new Parsek({ disablePackratParsing: true }); 5 | var tmr = new SystemTimer(); 6 | 7 | # rule: 8 | # S <- A 9 | # A <- P "+" A / P "-" A / P 10 | # P <- "(" A ")" / "1" 11 | # input: 12 | # (((((((((((((1))))))))))))) 13 | 14 | function generateParser($) { 15 | var S, A, P; 16 | S = $.lazy(&() => A); 17 | A = $.lazy(&() => $.alt($.seq(P, $.string('+'), A), $.seq(P, $.string('-'), A), P)); 18 | P = $.alt($.seq($.string('('), A, $.string(')')), $.string('1')); 19 | return S; 20 | } 21 | 22 | function test($) { 23 | for (var i = 0; i <= 10; ++i) { 24 | tmr.restart(); 25 | var r = generateParser($).parseAll(('(' * i) + '1' + (')' * i)); 26 | var elapsed = tmr.elapsed(); 27 | System.println(["%8.5f" % elapsed, r]); 28 | } 29 | } 30 | 31 | test($E); 32 | test($D); 33 | -------------------------------------------------------------------------------- /examples/pdf/fontwidth.kx: -------------------------------------------------------------------------------- 1 | using PdfCore; 2 | 3 | var pdf = new Pdf(); 4 | 5 | var sampTexts = [ 6 | "あいうえお", 7 | " ", 8 | "a", 9 | "b", 10 | "c", 11 | "d", 12 | "e", 13 | "i", 14 | ]; 15 | var fontname = pdf.loadTTFontFromFile("fonts/NotoSerifJP-Regular.ttf", true); 16 | var font = pdf.getFont(fontname, "UTF-8"); 17 | 18 | var page = pdf.addPage(); 19 | page.setSize(PDF_PAGE_SIZE_A4, PDF_PAGE_PORTRAIT); 20 | System.println("Page size = [%.3f, %.3f]" % page.getWidth() % page.getHeight()); 21 | 22 | page.setFontAndSize(font, 10); 23 | sampTexts.each { 24 | var width = page.textWidth(_1); 25 | System.println("%s = %f" % _1 % width); 26 | }; 27 | -------------------------------------------------------------------------------- /examples/pdf/sjis.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/examples/pdf/sjis.txt -------------------------------------------------------------------------------- /examples/pipeline.kx: -------------------------------------------------------------------------------- 1 | const double = &(n) => n * 2; 2 | const increment = &(n) => n + 1; 3 | 4 | // Normal case. 5 | var r1 = double(increment(double(double(5)))); // 42 6 | System.println(r1); 7 | 8 | // Rewrite it with a pipeline operator. 9 | var r2 = 5 |> double |> double |> increment |> double; // 42 10 | System.println(r2); 11 | 12 | class Person(name) { 13 | public said(x) { 14 | '"%{x}," %{name} said.' |> System.println; 15 | } 16 | } 17 | 18 | var john = new Person("John"); 19 | "Thank you very much" |> john.said; 20 | 21 | 64 |> Math.sqrt |> System.println; 22 | -------------------------------------------------------------------------------- /examples/qsort.kx: -------------------------------------------------------------------------------- 1 | function quicksort(a, first, last) { 2 | var i = first; 3 | var j = last; 4 | var x = a[(first + last) / 2]; 5 | while (true) { 6 | while (a[i] < x) i++; 7 | while (x < a[j]) j--; 8 | if (i >= j) break; 9 | 10 | [a[i], a[j]] = [a[j], a[i]]; 11 | ++i; --j; 12 | } 13 | if (first < i - 1) 14 | quicksort(a, first , i - 1); 15 | if (j + 1 < last) 16 | quicksort(a, j + 1, last); 17 | } 18 | 19 | function demo(N) { 20 | var a; // array 21 | 22 | System.print("Before:"); 23 | for (var i = 0; i < N; i++) { 24 | a[i] = Integer.parseInt(Math.random() * 100); 25 | System.print(" %2d" % a[i]); 26 | } 27 | System.print("\n"); 28 | 29 | quicksort(a, 0, N - 1); 30 | 31 | System.print("After: "); 32 | for (var i = 0; i < N; i++) 33 | System.print(" %2d" % a[i]); 34 | System.print("\n"); 35 | } 36 | 37 | demo(20); 38 | -------------------------------------------------------------------------------- /examples/regex.kx: -------------------------------------------------------------------------------- 1 | 2 | System.println("Find:"); 3 | var re = new Regex("aa(b+)"); 4 | re.reset("aaaaabbbabbaabbbbaaaabbb"); 5 | while (re.find()) { 6 | System.println(" found"); 7 | var group = re.group; 8 | var l = group.length(); 9 | for (var i = 0; i < l; ++i) { 10 | System.println(" [", group[i].begin, ", ", group[i].end, ")"); 11 | } 12 | } 13 | 14 | System.println("Matches:"); 15 | var re = new Regex("a+(a[ab]+)b"); 16 | re.reset("aaaaabbbabbaabbbbaaaabbb"); 17 | if (re.matches()) { 18 | System.println(" found"); 19 | var group = re.group; 20 | var l = group.length(); 21 | for (var i = 0; i < l; ++i) { 22 | System.println(" [", group[i].begin, ", ", group[i].end, ")"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/regex2.kx: -------------------------------------------------------------------------------- 1 | var a = "a=aaabbb,aabb=baaa,b=bbaaaa"; 2 | 3 | System.println("%{a}:"); 4 | while (group = (a =~ /=\w+/)) { 5 | System.println(" found"); 6 | var l = group.length(); 7 | for (var i = 0; i < l; ++i) { 8 | System.println(" [%2d,%2d) = '%s'" 9 | % group[i].begin 10 | % group[i].end 11 | % group[i].string); 12 | } 13 | } 14 | 15 | a = "abbb/aabbbaaa/bbbaa/aa"; 16 | System.println("%{a}:"); 17 | while (group = (a =~ %m(a+/))) { 18 | System.println(" found"); 19 | var l = group.length(); 20 | for (var i = 0; i < l; ++i) { 21 | System.println(" [%2d,%2d) = '%s'" 22 | % group[i].begin 23 | % group[i].end 24 | % group[i].string); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/sample.kx: -------------------------------------------------------------------------------- 1 | 2 | var a = false, x = 10; 3 | if (a) { 4 | var x = 5; 5 | var b = a = 10; 6 | var c = true; 7 | b = b * 3; 8 | var n = "aaaaaa"; 9 | n = n + " " + b; 10 | n = n + "bbbbbb"; 11 | ++b; 12 | x = a++; 13 | } 14 | if (x) { 15 | a = 2; 16 | } 17 | 18 | function xml_parse() { 19 | return 10; 20 | } 21 | 22 | function xml_parse2() { 23 | return; 24 | } 25 | 26 | class BaseClassName(i, j, k) { 27 | this.x = 10; 28 | var n_ = [1,[2,4,[5, 1],[]],3]; 29 | public method1(i) { 30 | return n_[i]; 31 | } 32 | public method2(i, n) { 33 | this.x = n; 34 | } 35 | } 36 | 37 | class ClassName(j,k) : BaseClassName(1, j, k) { 38 | var n_, v_; 39 | public get() { 40 | return n_; 41 | } 42 | private set(n, v) { 43 | try { 44 | n_ = n; 45 | } catch (e) { 46 | n_ = 0; 47 | } finally { 48 | v_ = v; 49 | } 50 | } 51 | public add(i) { 52 | try { 53 | if (n_ > 0) { 54 | return 1; 55 | } 56 | return n_ + i + x; 57 | } finally { 58 | n_ = 0; 59 | } 60 | } 61 | } 62 | 63 | function fib(n) { 64 | if (n < 3) return n; 65 | return fib(n-2) + fib(n-1); 66 | } 67 | 68 | try { 69 | var ny = (100 && 2) && 1; 70 | var nx = 200 || 2; 71 | throw nx; 72 | } catch (e) { 73 | System.println(e._type); 74 | System.println(e._what); 75 | throw; 76 | } 77 | return 1; 78 | -------------------------------------------------------------------------------- /examples/sat_raw.kx: -------------------------------------------------------------------------------- 1 | using SatisfiablitySolver; 2 | 3 | var vs = new VersionSatisfiablity(); 4 | vs.addVersion("A", "0.0.1"); 5 | vs.addVersion("A", "0.0.2"); 6 | vs.addVersion("A", "0.0.3"); 7 | vs.addVersion("B", "0.0.1"); 8 | vs.addVersion("B", "0.0.2"); 9 | vs.addVersion("B", "0.0.3"); 10 | vs.addVersion("X", "0.0.1"); 11 | vs.addVersion("X", "0.0.2"); 12 | vs.setDependency({ name: "A", version: "0.0.1" }, [{ name: "B", version: "0.0.1" }]); 13 | vs.setDependency({ name: "A", version: "0.0.2" }, [{ name: "B", version: "0.0.2" }]); 14 | vs.setDependency({ name: "A", version: "0.0.3" }, [{ name: "B", version: "0.0.3" }]); 15 | vs.setDependency({ name: "X", version: "0.0.1" }, [{ name: "A", version: "0.0.1" },{ name: "A", version: "0.0.2" },{ name: "A", version: "0.0.3" }]); 16 | vs.setDependency({ name: "X", version: "0.0.1" }, [{ name: "B", version: "0.0.2" }]); 17 | vs.setDependency({ name: "X", version: "0.0.2" }, [{ name: "B", version: "0.0.3" }]); 18 | 19 | vs.addVersion("X", "0.0.1", true); 20 | 21 | var i = 0; 22 | for (var e in vs.iterator()) { 23 | System.println("%d: " % i, e.toJsonString(true)); 24 | } 25 | -------------------------------------------------------------------------------- /examples/signal.kx: -------------------------------------------------------------------------------- 1 | var trapped = 0; 2 | 3 | Signal.trap(Signal.SIGINT, function() { 4 | System.println("SIGINT"); 5 | ++trapped; 6 | }); 7 | 8 | Signal.trap(Signal.SIGTERM, function() { 9 | System.println("SIGTERM"); 10 | return false; 11 | }); 12 | 13 | while (trapped < 10) { 14 | # System.println("trapped = " + trapped); 15 | System.sleep(0); 16 | } 17 | -------------------------------------------------------------------------------- /examples/slctsort.kx: -------------------------------------------------------------------------------- 1 | function display(name, a) { 2 | System.println(name, a.map(&(e) => "%2d" % e).join(' ')); 3 | } 4 | 5 | function demo(N, func) { 6 | var a = N.times(&() => Integer.parseInt(Math.random() * 100)); 7 | display("Before: ", a); 8 | a = func(a); 9 | display("After: ", a); 10 | } 11 | 12 | function selectsort(n, a) { 13 | var i, j, k, min; 14 | 15 | for (i = 0; i < n - 1; i++) { 16 | min = a[i]; k = i; 17 | for (j = i + 1; j < n; j++) 18 | if (a[j] < min) { min = a[j]; k = j; } 19 | a[k] = a[i]; a[i] = min; 20 | } 21 | } 22 | 23 | demo(20, &(a) => { 24 | selectsort(a.length(), a); 25 | return a; 26 | }); 27 | -------------------------------------------------------------------------------- /examples/sqlite.kx: -------------------------------------------------------------------------------- 1 | var db = new SQLite("database.db", 3000); 2 | db.exec("CREATE TABLE IF NOT EXISTS mytable " 3 | "(" 4 | "id INTEGER PRIMARY KEY AUTOINCREMENT, " 5 | "name TEXT NOT NULL" 6 | ")" 7 | ); 8 | var ins = db.prepare("INSERT INTO mytable (name) VALUES (?)"); 9 | db.transaction(&{ 10 | for (var i = 0; i < 20; ++i) { 11 | ins.bind("name(%{i})").exec(); 12 | } 13 | }); 14 | 15 | var c, r = db.prepare("SELECT * FROM mytable WHERE (id > ? AND id < ?) OR id = ?") 16 | .bind(2) 17 | .bind(8, 10) # bind() can be separated. 18 | .query(); # do binding & ready to next(). 19 | 20 | while (c = r.next()) { 21 | var cols = c.columnName; 22 | var vals = c.value; 23 | System.println("Record[%d]" % vals[0]); 24 | for (var i = 0, len = cols.length(); i < len; ++i) { 25 | System.println(" %-8s = %s" % cols[i] % vals[i]); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/ssh.kx: -------------------------------------------------------------------------------- 1 | using net.Ssh; 2 | 3 | var [, ip, user, pass] = $$; 4 | 5 | var ssh = new Net.Ssh(ip); 6 | # ssh.setTimeout(100); # for connection timeout. 7 | ssh.open { &(con) 8 | System.println("Fingerprint: ", con.getFingerprint()); 9 | 10 | con.setTimeout(10000); # for user auth timeout. 11 | con.login(user, pass); 12 | System.println("UserAuthList: ", con.getUserAuthList()); 13 | 14 | con.println("ls -lha"); 15 | var mes = con.waitfor(); 16 | System.println(mes); 17 | 18 | con.println("cat .bash_history"); 19 | var mes = con.waitfor(); 20 | System.println(mes); 21 | 22 | con.logout(); 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /examples/string.kx: -------------------------------------------------------------------------------- 1 | var s = "string"; 2 | System.println(s); 3 | System.println(s[0]); 4 | System.println(s[1]); 5 | System.println(s[2]); 6 | System.println(s[3]); 7 | System.println(s[4]); 8 | s[0] = 116; 9 | s[1] = "S"; 10 | System.println(s); 11 | 12 | a['aaa'] = s; 13 | System.println(a["aaa"]); 14 | 15 | System.println(s); 16 | System.println(s.length()); 17 | 18 | System.println([1,2,3].length()); 19 | -------------------------------------------------------------------------------- /examples/string_each.kx: -------------------------------------------------------------------------------- 1 | var s = "abcdef"; 2 | s.each { => System.println(_1) }; 3 | System.println(""); 4 | 5 | s = "aあbいcうdえeおf"; 6 | s.each { => System.println(_1) }; 7 | System.println(""); 8 | 9 | s = "あbいcうdえeおfか"; 10 | s.each { => System.println(_1) }; 11 | System.println(""); 12 | 13 | # If you want to loop for each byte, do the following. 14 | <...s>.each { => System.println(_1) }; 15 | System.println(""); 16 | -------------------------------------------------------------------------------- /examples/tcpclient.kx: -------------------------------------------------------------------------------- 1 | var soc = new Net.Socket(); 2 | var con = soc.connect({ host: "192.168.10.111", port: 10001, timeout: 10000 }); 3 | con.send($$[1] ?? "This is the message\n"); 4 | System.println(con.recv({ timeout: 10000 })); 5 | -------------------------------------------------------------------------------- /examples/tcpserver.kx: -------------------------------------------------------------------------------- 1 | 2 | const port = 10001; 3 | var serv = new Net.TcpServerSocket(port); 4 | while (true) { 5 | var con = serv.accept(); 6 | var host = con.host(); 7 | System.println("Connected from " + host); 8 | while (!con.isReadable()) { 9 | System.println("Waiting..."); 10 | System.sleep(1000); 11 | } 12 | var msg = con.recv(); 13 | System.println("received " + msg + ", and waiting 1000 ms"); 14 | System.sleep(1000); 15 | if (msg.trim() == "quit") { 16 | break; 17 | } 18 | 19 | msg = "Thank you"; 20 | con.send(msg + '\n'); 21 | System.println("Sent '" + msg + "'."); 22 | } 23 | -------------------------------------------------------------------------------- /examples/throw2.kx: -------------------------------------------------------------------------------- 1 | function test1() { 2 | var val = 1; 3 | try { 4 | return val; 5 | } 6 | finally { 7 | val = 2; 8 | } 9 | } 10 | 11 | var s_val; 12 | function test2() { 13 | s_val = 1; 14 | try { 15 | return s_val; 16 | } 17 | finally { 18 | s_val = 2; 19 | System.print("(s_val = " + s_val + ") = "); 20 | } 21 | }; 22 | 23 | System.println("Test1() = " + test1()); 24 | System.print("Test2() = "); 25 | System.println(test2()); 26 | System.println("s_val = " + s_val); 27 | -------------------------------------------------------------------------------- /examples/trycatch.kx: -------------------------------------------------------------------------------- 1 | try { 2 | var i = 1; 3 | var n = 100 + i; 4 | throw n; 5 | } catch (e) { 6 | return e; 7 | } 8 | return 1; 9 | -------------------------------------------------------------------------------- /examples/tsv.kx: -------------------------------------------------------------------------------- 1 | using CSV; 2 | 3 | var file = $$[0].parentPath() / "tsv1.tsv"; 4 | System.println("File: ", file); 5 | 6 | System.println("\n--- Parsing the file line by line"); 7 | TSV.parse(file, &(line) => { 8 | System.println(line); 9 | }); 10 | 11 | System.println("\n--- Parsing the whole text"); 12 | var str = File.load(file); 13 | var r = TSV.parseString(str); 14 | System.println(r.toJsonString(true)); 15 | -------------------------------------------------------------------------------- /examples/tsv1.tsv: -------------------------------------------------------------------------------- 1 | # comment in TSV. 2 | abcde efgh non-quoted string 3 | "abcde" "efgh" "quoted string" 4 | "abcde" efgh "quoted & non-quoted string in the same row" 5 | "abcde" efgh "can use or "" in tsv" 6 | "abcde" efgh "can use newlines 7 | 8 | in the row" 9 | # another comment in TSV. 10 | abcde efgh not necessary \n the end of tsv -------------------------------------------------------------------------------- /examples/while.kx: -------------------------------------------------------------------------------- 1 | 2 | var a, b, c; 3 | b = c = 1; 4 | 5 | LABEL: 6 | while (1) { 7 | for (var x = 0; x < 100; ) { 8 | System.println("b == %{b}, c == %{c}, x = %{x}"); 9 | if (c == 11) { 10 | break LABEL; 11 | } 12 | c++; 13 | if (c == 10) { 14 | continue; 15 | } 16 | ++x; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/xml_sample.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BON JOVI 5 | 2400 6 | 7 | 8 | 9 | GUNS N' ROSES 10 | 21000 11 | 12 | 13 | 14 | Helloween 15 | 2400 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /include/ansicolor_w32.h: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | # define fprintf(...) _fprintf_w32(__VA_ARGS__) 3 | # define printf(...) _fprintf_w32(stdout, __VA_ARGS__) 4 | # define fputs(fp, x) _fprintf_w32(fp, x); 5 | # define puts(x) _fprintf_w32(stdout, x); 6 | #endif 7 | -------------------------------------------------------------------------------- /include/dbg.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef KX_DBG_H 3 | #define KX_DBG_H 4 | 5 | #define HAVE_STDINT_H 1 6 | #define SIZEOF_VOID_P 8 7 | 8 | #include 9 | #if 0 10 | #define malloc use_kx_malloc 11 | #define realloc use_kx_realloc 12 | #define calloc use_kx_calloc 13 | #define free use_kx_free 14 | #define strdup use_kx_strdup 15 | #define strndup use_kx_strndup 16 | #define strdupa dont_use_strdupa 17 | #define strndupa dont_use_strndupa 18 | #endif 19 | 20 | struct kx_context_; 21 | typedef void *(*kx_malloc_t)(size_t size); 22 | typedef void *(*kx_realloc_t)(void *p, size_t size); 23 | typedef void *(*kx_calloc_t)(size_t count, size_t size); 24 | typedef void (*kx_free_t)(void *p); 25 | typedef char *(*kx_strdup_t)(const char *s); 26 | typedef char *(*kx_strndup_t)(const char *s, size_t n); 27 | typedef const char *(*kx_const_str_t)(struct kx_context_ *ctx, const char* name); 28 | 29 | typedef void (*set_allocator_t)(kx_malloc_t m, kx_realloc_t r, kx_calloc_t c, kx_free_t f, kx_strdup_t sd, kx_strndup_t snd, kx_const_str_t cs); 30 | extern kx_malloc_t kx_malloc; 31 | extern kx_realloc_t kx_realloc; 32 | extern kx_calloc_t kx_calloc; 33 | extern kx_free_t kx_free; 34 | extern kx_strdup_t kx_strdup; 35 | extern kx_strndup_t kx_strndup; 36 | extern kx_const_str_t kx_const_str; 37 | 38 | #define KXDBG(msg) printf("%s:%d: %s\n", __FILE__, __LINE__, msg); 39 | 40 | #endif /* KX_DBG_H */ 41 | -------------------------------------------------------------------------------- /include/getopt.h: -------------------------------------------------------------------------------- 1 | #ifndef GETOPT_H 2 | #define GETOPT_H 3 | 4 | #ifndef GETOPTORIGDEF 5 | #define getopt getoptmine 6 | #define optarg getoptarg 7 | #define optind getoptind 8 | #define opterr getopterr 9 | #define optpos getoptpos 10 | #define optproblem getoptproblem 11 | #define optprogname getoptprogname 12 | #define opteof getopteof 13 | #endif 14 | 15 | extern int getopt(int argc, char **argv, char *opts); 16 | extern char *optarg; 17 | extern int optind; 18 | extern int opterr; 19 | extern int optpos; 20 | extern int optproblem; 21 | extern char *optprogname; 22 | extern int opteof; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/jit.h: -------------------------------------------------------------------------------- 1 | #ifndef KX_JIT_H 2 | #define KX_JIT_H 3 | 4 | #define SLJIT_CONFIG_AUTO 1 5 | #include "../src/jit/sljitLir.h" 6 | 7 | #if !defined(SLJIT_64BIT_ARCHITECTURE) 8 | #error Architecture shoule be 64bit. 9 | #endif 10 | 11 | extern struct sljit_compiler *new_compiler(void); 12 | extern void *finalize_code(struct sljit_compiler *C); 13 | extern int get_code_code(struct sljit_compiler *C); 14 | extern void free_code(void *code); 15 | extern void jit_run(struct sljit_compiler *C); 16 | 17 | #if defined(_WIN32) || defined(_WIN64) || defined(__x86_64__) 18 | #include "../src/disasm-x64/udis86.h" 19 | #define USE_DISASM_X64 (1) 20 | extern int disasm_hex(struct ud* u); 21 | extern void disasm_code(void *code, int size); 22 | #else 23 | #include "disasm/disas.h" 24 | #define USE_DISASM_X64 (0) 25 | #endif 26 | 27 | #endif /* KX_JIT_H */ 28 | -------------------------------------------------------------------------------- /include/kxalloc.h: -------------------------------------------------------------------------------- 1 | #ifndef KX_ALLOC_H 2 | #define KX_ALLOC_H 3 | 4 | #include 5 | 6 | extern const char *alloc_string(kx_context_t *ctx, const char *str); 7 | extern void free_string(kx_context_t *ctx); 8 | extern const char *const_str(kx_context_t *ctx, const char* name); 9 | extern const char *const_str2(kx_context_t *ctx, const char* classname, const char* name); 10 | 11 | #endif /* KX_ALLOC_H */ 12 | -------------------------------------------------------------------------------- /include/kxiconv.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBICONV_H 2 | #define _LIBICONV_H 3 | #include 4 | 5 | #if defined(_WIN32) || defined(_WIN64) 6 | 7 | #define GLIB_COMPILATION 1 8 | #ifndef WINICONV_CONST 9 | # ifdef ICONV_CONST 10 | # define WINICONV_CONST ICONV_CONST 11 | # else 12 | # define WINICONV_CONST const 13 | # endif 14 | #endif 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | typedef void* iconv_t; 19 | iconv_t iconv_open(const char *tocode, const char *fromcode); 20 | int iconv_close(iconv_t cd); 21 | size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #else 27 | #include 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/kxoptimizer.h: -------------------------------------------------------------------------------- 1 | #ifndef KX_KXOPTIMIZER_H 2 | #define KX_KXOPTIMIZER_H 3 | 4 | #include 5 | 6 | typedef void (*opt_ast_func_t)(kx_context_t *ctx, kx_object_t *node); 7 | extern int opt_ast_constant_folding(kx_context_t *ctx, kx_object_t *node); 8 | 9 | typedef void (*opt_code_func_t)(kvec_pt(kx_code_t) *fixcode, int start); 10 | extern void opt_code_remove_jmp(kvec_pt(kx_code_t) *fixcode, int start); 11 | extern void opt_code_optimize_jmp(kvec_pt(kx_code_t) *fixcode, int start); 12 | 13 | #endif /* KX_KXOPTIMIZER_H */ 14 | -------------------------------------------------------------------------------- /include/parser.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef KX_PARSER_H 3 | #define KX_PARSER_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | typedef struct package_t_ { 10 | const char *vers; 11 | struct package_t_ *next; 12 | } package_t; 13 | KHASH_MAP_INIT_STR(package, package_t *) 14 | 15 | typedef struct name_t_ { 16 | const char *name; 17 | int line; 18 | int pos1; 19 | int pos2; 20 | } name_t; 21 | 22 | typedef struct arytype_t_ { 23 | int type; 24 | int depth; 25 | const char *name; /* class name */ 26 | } arytype_t; 27 | 28 | typedef struct named_stmt_ { 29 | const char *name; /* class name */ 30 | kx_object_t *stmt; 31 | } named_stmt_t; 32 | 33 | #ifndef KX_NO_INCLUDE_PARSER_TAB_H 34 | #include 35 | #endif /* KX_PARSER */ 36 | 37 | extern int kx_trace_fmt(kx_context_t *ctx, int nested, const char *fmt, ...); 38 | #define kx_trace(ctx, nested, ...) do {\ 39 | if (ctx->options.verbose) { \ 40 | kx_trace_fmt(ctx, nested, __VA_ARGS__);\ 41 | } \ 42 | } while (0); \ 43 | /**/ 44 | 45 | #endif /* KX_PARSER_H */ 46 | -------------------------------------------------------------------------------- /include/version.h: -------------------------------------------------------------------------------- 1 | #ifndef KX_VERSION_H 2 | 3 | #if defined(_WIN32) || defined(_WIN64) 4 | #define PROGNAME "kinx.exe" 5 | #else 6 | #define PROGNAME "kinx" 7 | #endif 8 | #define VER_MAJ 1 9 | #define VER_MIN 1 10 | #define VER_PAT 1 11 | #define VER_SUFFIX "" 12 | 13 | #endif /* KX_VERSION_H */ 14 | 15 | -------------------------------------------------------------------------------- /lib/exec/PathInstUtil.kx: -------------------------------------------------------------------------------- 1 | using Process; 2 | 3 | if (!System.PLATFORM.endsWith("-WIN")) { 4 | System.println("Not supported platform, it is only for Windows"); 5 | return 1; 6 | } 7 | 8 | KinxPath.getPathList = _function() { 9 | var [r1, w1] = new Pipe(); 10 | var p1 = new Process([$kinxpath / "addpath.exe", "list", "user"], { out: w1 }).run(); 11 | w1.close(); 12 | var res = []; 13 | while (p1.isAlive() || r1.peek() > 0) { 14 | var buf = r1.read(); 15 | if (buf.length() > 0) { 16 | res.push(buf); 17 | } 18 | } 19 | var status = p1.wait(); 20 | return status == 0 ? res.join().split(/\r?\n/) : []; 21 | }; 22 | 23 | var res = KinxPath.getPathList(); 24 | if (res.length() == 0) { 25 | System.println("Failed to get a PATH list."); 26 | return 1; 27 | } 28 | 29 | var found = false; 30 | var kinxpath = $kinxpath.replace("/", "\\"); 31 | res.each { 32 | if (g = (_1 =~ /\s*\d+:\s+(.+)/)) { 33 | if (g[1].string == kinxpath) { 34 | found = true; 35 | return false; 36 | } 37 | } 38 | }; 39 | 40 | KinxPath.AlreadyInstalled = new Boolean(found); 41 | -------------------------------------------------------------------------------- /lib/exec/kxrepl.kx: -------------------------------------------------------------------------------- 1 | using repl; 2 | -------------------------------------------------------------------------------- /lib/exec/kxtest.kx: -------------------------------------------------------------------------------- 1 | using spectest; 2 | -------------------------------------------------------------------------------- /lib/exec/pathInst.kx: -------------------------------------------------------------------------------- 1 | using PathInstUtil; 2 | 3 | System.println("Already installed : ", KinxPath.AlreadyInstalled); 4 | if (!KinxPath.AlreadyInstalled) { 5 | System.println("add [%{kinxpath}] to PATH"); 6 | var p = new Process([$kinxpath / "addpath.exe", "add", "user", kinxpath]).run(); 7 | p.wait(); 8 | KinxPath.getPathList().each { 9 | System.println(_1); 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /lib/exec/pathUninst.kx: -------------------------------------------------------------------------------- 1 | using PathInstUtil; 2 | 3 | System.println("Already installed : ", KinxPath.AlreadyInstalled); 4 | if (KinxPath.AlreadyInstalled) { 5 | System.println("remove [%{kinxpath}] from PATH"); 6 | var p = new Process([$kinxpath / "addpath.exe", "del", "user", kinxpath]).run(); 7 | p.wait(); 8 | KinxPath.getPathList().each { 9 | System.println(_1); 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /lib/webview/materialize/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2018 Materialize 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/webview/materialize/css/fonts.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Material Icons'; 3 | font-style: normal; 4 | font-weight: 400; 5 | src: url(../fonts/MaterialIcons-Regular.eot); /* For IE6-8 */ 6 | src: local('Material Icons'), 7 | local('MaterialIcons-Regular'), 8 | url(../fonts/MaterialIcons-Regular.woff2) format('woff2'), 9 | url(../fonts/MaterialIcons-Regular.woff) format('woff'), 10 | url(../fonts/MaterialIcons-Regular.ttf) format('truetype'); 11 | } 12 | 13 | .material-icons { 14 | font-family: 'Material Icons'; 15 | font-weight: normal; 16 | font-style: normal; 17 | font-size: 24px; /* Preferred icon size */ 18 | display: inline-block; 19 | line-height: 1; 20 | text-transform: none; 21 | letter-spacing: normal; 22 | word-wrap: normal; 23 | white-space: nowrap; 24 | direction: ltr; 25 | 26 | /* Support for all WebKit browsers. */ 27 | -webkit-font-smoothing: antialiased; 28 | /* Support for Safari and Chrome. */ 29 | text-rendering: optimizeLegibility; 30 | 31 | /* Support for Firefox. */ 32 | -moz-osx-font-smoothing: grayscale; 33 | 34 | /* Support for IE. */ 35 | font-feature-settings: 'liga'; 36 | } 37 | -------------------------------------------------------------------------------- /lib/webview/materialize/fonts/MaterialIcons-Regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/lib/webview/materialize/fonts/MaterialIcons-Regular.eot -------------------------------------------------------------------------------- /lib/webview/materialize/fonts/MaterialIcons-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/lib/webview/materialize/fonts/MaterialIcons-Regular.ttf -------------------------------------------------------------------------------- /lib/webview/materialize/fonts/MaterialIcons-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/lib/webview/materialize/fonts/MaterialIcons-Regular.woff -------------------------------------------------------------------------------- /lib/webview/materialize/fonts/MaterialIcons-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/lib/webview/materialize/fonts/MaterialIcons-Regular.woff2 -------------------------------------------------------------------------------- /make.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | if "%1"=="installer" goto INSTALLER 3 | if "%1"=="inst" goto INSTALLER 4 | 5 | pushd build 6 | call make.cmd %* 7 | if ERRORLEVEL 1 goto END 8 | if "%1"=="" goto COPY 9 | if "%1"=="all" goto COPY 10 | if "%1"=="rebuild" goto COPY 11 | goto END 12 | 13 | :COPY 14 | copy /y echo.exe .. 15 | copy /y kinx.exe .. 16 | copy /y kinxw.exe .. 17 | copy /y kxrepl.exe .. 18 | copy /y kxtest.exe .. 19 | copy /y kip.exe .. 20 | copy /y addpath.exe .. 21 | copy /y addpathc.exe .. 22 | copy /y kx.lib .. 23 | copy /y *.dll .. 24 | goto END 25 | 26 | :INSTALLER 27 | if exist "c:\Program Files (x86)\NSIS\Bin\makensis.exe" ( 28 | "c:\Program Files (x86)\NSIS\Bin\makensis.exe" install.nsi 29 | ) 30 | 31 | :END 32 | popd 33 | -------------------------------------------------------------------------------- /src/disasm-x64/libudis86/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # -- udis86/libudis86 3 | # 4 | 5 | PYTHON = @PYTHON@ 6 | OPTABLE = @top_srcdir@/docs/x86/optable.xml 7 | 8 | MAINTAINERCLEANFILES = Makefile.in 9 | 10 | lib_LTLIBRARIES = libudis86.la 11 | 12 | libudis86_la_SOURCES = \ 13 | itab.c \ 14 | decode.c \ 15 | syn.c \ 16 | syn-intel.c \ 17 | syn-att.c \ 18 | udis86.c \ 19 | udint.h \ 20 | syn.h \ 21 | decode.h 22 | 23 | include_ladir = ${includedir}/libudis86 24 | include_la_HEADERS = \ 25 | types.h \ 26 | extern.h \ 27 | itab.h 28 | 29 | 30 | BUILT_SOURCES = \ 31 | itab.c \ 32 | itab.h 33 | 34 | # 35 | # DLLs may not contain undefined symbol references. 36 | # We have the linker check this explicitly. 37 | # 38 | if TARGET_WINDOWS 39 | libudis86_la_LDFLAGS = -no-undefined -version-info 0:0:0 40 | endif 41 | 42 | itab.c itab.h: $(OPTABLE) \ 43 | $(top_srcdir)/scripts/ud_itab.py \ 44 | $(top_srcdir)/scripts/ud_opcode.py 45 | $(PYTHON) $(top_srcdir)/scripts/ud_itab.py $(OPTABLE) $(srcdir) 46 | 47 | 48 | clean-local: 49 | rm -rf $(BUILT_SOURCES) 50 | 51 | maintainer-clean-local: 52 | -------------------------------------------------------------------------------- /src/disasm/arch/arm/aload.h: -------------------------------------------------------------------------------- 1 | #ifndef ARM_LOAD_H 2 | #define ARM_LOAD_H 3 | 4 | #include 5 | #include 6 | #include "../../common/file.h" 7 | #include "../../common/trie.h" 8 | #include "../../common/table.h" 9 | 10 | #define MAX_MNEM_SIZE_ARM 128 11 | 12 | /*ARM Instruction Entry*/ 13 | struct arm_instr_entry { 14 | char mnemonic[MAX_MNEM_SIZE_ARM]; 15 | int instr_type; 16 | }; 17 | 18 | void arm_parse(struct trie_node *root, struct hash_table *table, int mode); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/disasm/arch/arm/arm.ins: -------------------------------------------------------------------------------- 1 | 00 invalid NA f:1 2 | 0010 mul M 3 | 0020 mla A 4 | 0030 umaal U 5 | 0040 mls A 6 | 0050 umull U 7 | 0060 umlal U 8 | 0070 smull U 9 | 0080 smlal U 10 | 01 invalid NA f:1 11 | 0000 and D 12 | 0001 eor D 13 | 0002 sub D 14 | 0003 rsb D 15 | 0004 add D 16 | 0005 adb D 17 | 0006 sbc D 18 | 0007 rsb D 19 | 0008 tst D 20 | 0009 teq D 21 | 000a cmp D 22 | 000b cmn D 23 | 000c irr D 24 | 000d mov D f:2 25 | 000e bic D 26 | 000f mvn D f:2 27 | 0100 and I 28 | 0101 eor I 29 | 0102 sub I 30 | 0103 rsb I 31 | 0104 add I 32 | 0105 adb I 33 | 0106 sbc I 34 | 0107 rsb I 35 | 0108 tst I 36 | 0109 teq I 37 | 010a cmp I 38 | 010b cmn I 39 | 010c irr I 40 | 010d mov I f:2 41 | 010e bic I 42 | 010f mvn I f:2 43 | 02 invalid NA f:4 44 | 0201 ldr O 45 | 0200 str O 46 | 03 invalid NA f:4 47 | 0301 ldr R 48 | 0300 str R 49 | 04 invalid NA f:4 50 | 0401 ldm L f:8 51 | 040100 ldmda L 52 | 040101 ldmia L 53 | 040102 ldmdb L 54 | 040103 ldmib L 55 | 040104 ldmfa L 56 | 040105 ldmfd L 57 | 040106 ldmea L 58 | 040107 ldmed L 59 | 0400 stm L f:8 60 | 040000 stmda L 61 | 040001 stmia L 62 | 040002 stmdb L 63 | 040003 stmib L 64 | 040004 stmed L 65 | 040005 stmea L 66 | 040006 stmfd L 67 | 040007 stmfa L 68 | 05 b B 69 | -------------------------------------------------------------------------------- /src/disasm/arch/arm/astrings.c: -------------------------------------------------------------------------------- 1 | #include "astrings.h" 2 | 3 | const char *arm_conditions[16] = { 4 | "eq", "ne", "cs", "cc", 5 | "mi", "pl", "vs", "vc", 6 | "hi", "ls", "ge", "lt", 7 | "gt", "le", "al", "nv" 8 | }; 9 | 10 | const char *arm_registers[16] = { 11 | "r0", "r1", "r2", "r3", 12 | "r4", "r5", "r6", "r7", 13 | "r8", "r9", "r10", "fp", 14 | "ip", "sp", "lr", "pc", 15 | }; 16 | -------------------------------------------------------------------------------- /src/disasm/arch/arm/astrings.h: -------------------------------------------------------------------------------- 1 | #ifndef ARM_STRINGS_H 2 | #define ARM_STRINGS_H 3 | 4 | extern const char *arm_conditions[16]; 5 | extern const char *arm_registers[16]; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/disasm/arch/mips/mips.h: -------------------------------------------------------------------------------- 1 | #ifndef MIPS_H 2 | #define MIPS_H 3 | 4 | #include 5 | #include 6 | #include "../../common/common.h" 7 | #include "../../dis.h" 8 | #include "mload.h" 9 | #include "mstrings.h" 10 | 11 | /*Trie node flags*/ 12 | #define INSTR_FUNC 1 13 | #define INSTR_SHIFT 2 14 | #define INSTR_NORS 4 15 | #define INSTR_NORT 8 16 | #define INSTR_NORD 16 17 | #define INSTR_RSEXT 32 18 | 19 | /*Instruction Types*/ 20 | #define TYPE_R 'R' 21 | #define TYPE_I 'I' 22 | #define TYPE_J 'J' 23 | #define TYPE_F 'F' 24 | 25 | /*Bit Macros for MIPS instruction encoding*/ 26 | #define OPCODE(instr) ((instr>>26)) 27 | #define FUNC(instr) ((instr&0x03f)) 28 | #define SHAMT(instr) ((instr>>6)&0x01f) 29 | #define RS(instr) ((instr>>21)&0x01f) 30 | #define RT(instr) ((instr>>16)&0x01f) 31 | #define RD(instr) ((instr>>11)&0x01f) 32 | #define ADDR(instr) ((instr&0x03ffffff)) 33 | #define IMM(instr) (instr&0x0ffff) 34 | 35 | struct dis *mips_disassemble(int mode, struct trie_node *node, u8 * stream, 36 | long max, uint64_t addr); 37 | void mips_decode_operands(struct dis *disas, struct mips_instr_entry *e, 38 | uint32_t instruction, u8 flags); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/disasm/arch/mips/mips.ins: -------------------------------------------------------------------------------- 1 | 00 invalid NA f:1 2 | 0000 sll R f:2 3 | 0002 srl R f:2 4 | 0008 jr R f:4 f:16 5 | 0010 mfhi R f:8 f:16 6 | 0011 mthi R f:8 f:16 7 | 0012 mflo R f:8 f:16 8 | 0013 mtlo R f:8 f:16 9 | 0020 add R 10 | 0021 addu R 11 | 0022 sub R 12 | 0023 subu R 13 | 0018 mult R f:4 14 | 0019 multu R f:4 15 | 001a div R f:4 16 | 001b divu R f:4 17 | 0027 nor R 18 | 0026 xor R 19 | 0025 or R 20 | 002a slt R 21 | 002b sltu R 22 | 02 j J 23 | 03 jal J 24 | 04 beq I 25 | 05 bne I 26 | 06 blez I 27 | 08 addi I 28 | 09 addiu I 29 | 0a slti I 30 | 0b sltiu I 31 | 0c andi I 32 | 0d ori I 33 | 0f lui I 34 | 23 lw I 35 | 24 lbu I 36 | 25 lhu I 37 | 28 sb I 38 | 29 sh I 39 | 2b sw I 40 | 11 invalid1 NA f:32 41 | 1110 invalid2 NA f:1 42 | 1111 invalid2 NA f:1 43 | 111000 add.s F 44 | 111001 sub.s F 45 | 111002 mul.s F 46 | 111003 div.s F 47 | 111100 add.d F 48 | 111101 sub.d F 49 | 111102 mul.d F 50 | 111103 div.d F 51 | -------------------------------------------------------------------------------- /src/disasm/arch/mips/mload.h: -------------------------------------------------------------------------------- 1 | #ifndef MIPS_LOAD_H 2 | #define MIPS_LOAD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "../../common/file.h" 8 | #include "../../common/trie.h" 9 | #include "../../common/table.h" 10 | 11 | #define MAX_MNEM_SIZE_MIPS 12 12 | #ifndef MODE_32B 13 | #define MODE_32B 1 14 | #endif 15 | #ifndef MODE_64B 16 | #define MODE_64B 2 17 | #endif 18 | 19 | /*MIPS Instruction Entry*/ 20 | struct mips_instr_entry { 21 | char mnemonic[MAX_MNEM_SIZE_MIPS]; 22 | char instr_type; 23 | }; 24 | 25 | void mips_parse(struct trie_node *root, struct hash_table *table, int mode); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/disasm/arch/mips/mstrings.c: -------------------------------------------------------------------------------- 1 | #include "mstrings.h" 2 | 3 | const char *mips_registers[32] = { 4 | "$zero", "$at", "$v0", "$v1", 5 | "$a0", "$a1", "$a2", "$a3", 6 | "$t0", "$t1", "$t2", "$t3", 7 | "$t4", "$t5", "$t6", "$t7", 8 | "$s0", "$s1", "$s2", "$s3", 9 | "$s4", "$s5", "$s6", "$s7", 10 | "$t8", "$t9", "$k0", "$k1", 11 | "$gp", "$sp", "$fp", "$ra" 12 | }; 13 | 14 | const char *mips_fp_registers[32] = { 15 | "$f0", "$f1", "$f2", "$f3", 16 | "$f4", "$f5", "$f6", "$f7", 17 | "$f8", "$f9", "$f10", "$f11", 18 | "$f12", "$f13", "$f14", "$f15", 19 | "$f16", "$f17", "$f18", "$f19", 20 | "$f20", "$f21", "$f22", "$f23", 21 | "$f24", "$f25", "$f26", "$f27", 22 | "$f28", "$f29", "$f30", "$f31" 23 | }; 24 | -------------------------------------------------------------------------------- /src/disasm/arch/mips/mstrings.h: -------------------------------------------------------------------------------- 1 | #ifndef MIPS_STRINGS_H 2 | #define MIPS_STRINGS_H 3 | 4 | extern const char *mips_registers[32]; 5 | extern const char *mips_fp_registers[32]; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /src/disasm/arch/x86/x86load.h: -------------------------------------------------------------------------------- 1 | #ifndef X86_LOAD_H 2 | #define X86_LOAD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "../../common/file.h" 8 | #include "../../common/trie.h" 9 | #include "../../common/table.h" 10 | 11 | #define MAX_MNEM_SIZE_X86 12 12 | #define MAX_OPER_LEN 12 13 | #define MAX_OPERANDS 3 14 | 15 | /*A copy of the MODE macros in disas*/ 16 | #ifndef MODE_32B 17 | #define MODE_32B 1 18 | #endif 19 | #ifndef MODE_64B 20 | #define MODE_64B 2 21 | #endif 22 | 23 | struct x86_instr_entry { 24 | char mnemonic[MAX_MNEM_SIZE_X86]; 25 | char operand[MAX_OPERANDS][MAX_OPER_LEN]; 26 | int num_op; 27 | }; 28 | 29 | void x86_parse(struct trie_node *root, struct hash_table * table, int mode); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/disasm/arch/x86/x86strings.h: -------------------------------------------------------------------------------- 1 | #ifndef X86_STRINGS_H 2 | #define X86_STRINGS_H 3 | 4 | #include 5 | #include 6 | 7 | #define REG_BIN_IDX(idx) (idx / 4) 8 | #define REG_SIZE_IDX(idx) (idx % 4 + 1) 9 | 10 | /*X86 General Registers*/ 11 | extern const char *general_registers[64]; 12 | 13 | /*X87 Stack Registers*/ 14 | extern const char *x87_registers[8]; 15 | 16 | /*X86 XMM Registers*/ 17 | extern const char *xmm_registers[8]; 18 | 19 | /*X86 MMX Registers*/ 20 | extern const char *mm_registers[8]; 21 | 22 | /*Operand Size Prefix Strings*/ 23 | extern const char *operand_size_prefix[4]; 24 | 25 | const char *get_register(int reg, int size, int rexb); 26 | 27 | int get_x87_index(const char *reg); 28 | int get_xmm_index(const char *reg); 29 | int get_mm_index(const char *reg); 30 | int get_register_index(const char *reg); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/disasm/common/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | 6 | /*Typedefs to make code cleaner*/ 7 | typedef unsigned char u8; 8 | typedef uint16_t u16; 9 | typedef uint32_t u32; 10 | typedef uint64_t u64; 11 | 12 | /*Convenience Macros*/ 13 | #define CHECK_FLAG(byte, flag) (!!(byte & flag)) 14 | #define SET_FLAG(byte, flag) (byte |= flag) 15 | #define SIGNED(val) ((val>>(sizeof(val)*8-1))) 16 | #define SIGN(val) ((SIGNED(val)) ? -val : val) 17 | #define BITS(val, s, e) (((val) >> (s)) & ~((unsigned)-1 << ((e) - (s)))) 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/disasm/common/file.c: -------------------------------------------------------------------------------- 1 | #include "file.h" 2 | 3 | /*Gets a line from a file or returns 1 on eof*/ 4 | int get_line(FILE * f, char *buf, long max) 5 | { 6 | memset(buf, 0, max); 7 | char c; 8 | int iter = 0; 9 | int eof = 0; 10 | while ((c = (char) fgetc(f)) != '\n' && !(eof = feof(f))) 11 | buf[iter++] = c; 12 | return eof; 13 | } 14 | 15 | /*Converts ascii hex to raw hex. EG "A" -> 0x0a */ 16 | long ascii_to_hex(unsigned char *out, char *in, long len) 17 | { 18 | long j = 0; 19 | for (int i = 0; i < len; i += 2) { 20 | out[j] = in[i] > '9' ? in[i] - 'a' + 10 : in[i] - '0'; 21 | out[j] = 22 | (out[j] << 4) | (in[i + 1] > 23 | '9' ? in[i + 1] - 'a' + 10 : in[i + 24 | 1] - 25 | '0'); 26 | j++; 27 | } 28 | return j; 29 | } 30 | -------------------------------------------------------------------------------- /src/disasm/common/file.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_H 2 | #define FILE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | long ascii_to_hex(unsigned char *out, char *in, long len); 9 | int get_line(FILE * f, char *buf, long max); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/disasm/common/table.h: -------------------------------------------------------------------------------- 1 | #ifndef TABLE_H 2 | #define TABLE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /*Generic Hash Table Implementation (depended on by disassembly semantic lookup)*/ 9 | struct hash_table { 10 | int num_buckets; 11 | struct hash_entry **buckets; 12 | }; 13 | 14 | struct hash_entry { 15 | unsigned long hash; 16 | char *mnemonic; 17 | void *value; 18 | struct hash_entry *next; 19 | }; 20 | 21 | struct hash_table *hash_table_init(int num_buckets); 22 | void hash_table_destroy(struct hash_table *table, void(destroy)(void*)); 23 | 24 | struct hash_entry *hash_entry_init(char *mnemonic, void *value); 25 | void hash_entry_destroy(struct hash_entry *entry); 26 | 27 | void hash_table_insert(struct hash_table *table, struct hash_entry *entry); 28 | struct hash_entry *hash_table_lookup(struct hash_table *table, const char *mnem); 29 | 30 | void hash_entry_insert(struct hash_entry **head, struct hash_entry *entry); 31 | struct hash_entry *hash_entry_lookup(struct hash_entry *head, const char *mnem, unsigned long hash); 32 | 33 | unsigned long hash_str(const char *str); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/disasm/common/trie.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIE_H 2 | #define TRIE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /*Opaque Trie structure for disassembly indexing. 9 | * Branch Nodes can hold flags to resolve lookup conflicts.*/ 10 | struct trie_node { 11 | struct trie_node *parent; 12 | //Trie children 13 | struct trie_node **children; 14 | int num_children; 15 | 16 | //Distance from the root node 17 | int dist; 18 | 19 | //You can set flags for branches 20 | unsigned char flags; 21 | 22 | //Key byte 23 | unsigned char key; 24 | //Opaque pointer to hold entry 25 | void *value; 26 | }; 27 | 28 | struct trie_node *trie_init(unsigned char key, void *value); 29 | void trie_destroy(struct trie_node *node); 30 | 31 | //Creates path and inserts a value. Returns trie node or NULL on failure 32 | struct trie_node *trie_insert(struct trie_node *root, unsigned char *stream, long max, 33 | void *value, unsigned char flags); 34 | //Returns the leaf node or branch if there is a lookup conflict 35 | struct trie_node *trie_lookup(struct trie_node *root, 36 | unsigned char *stream, long max); 37 | //Insertion sort trie nodes 38 | void trie_node_insert(struct trie_node *node, struct trie_node *child); 39 | //Search on a sorted trie node 40 | struct trie_node *trie_node_search(struct trie_node *node, 41 | unsigned char key); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/disasm/gen/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | EXE = gen 3 | SOURCES = $(wildcard *.c) 4 | OBJS = $(SOURCES:.c=.o) 5 | UNAME_S := $(shell uname -s) 6 | 7 | ifeq ($(UNAME_S), Linux) #LINUX 8 | ECHO_MESSAGE = "Linux" 9 | CXXFLAGS = -ggdb3 -std=c99 -Wall -Wextra -pedantic 10 | CFLAGS = $(CXXFLAGS) 11 | endif 12 | 13 | .c.o: 14 | $(CC) $(CXXFLAGS) -c -o $@ $< 15 | 16 | all: $(EXE) 17 | @echo Build complete for $(ECHO_MESSAGE) 18 | 19 | $(EXE): $(OBJS) 20 | $(CC) -o $(EXE) $(OBJS) $(CXXFLAGS) $(LIBS) 21 | 22 | run: gen 23 | ./gen *.sym 24 | 25 | clean: 26 | rm $(EXE) $(OBJS) 27 | -------------------------------------------------------------------------------- /src/disasm/gen/gen.h: -------------------------------------------------------------------------------- 1 | #ifndef GEN_H 2 | #define GEN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /*Generates symbol tables from text files*/ 10 | 11 | int get_line(FILE *f, char *buf, long max); 12 | void print_type(FILE *hfile, FILE *cfile, char *name, char **types, int nt); 13 | void print_symt(FILE *header, FILE *cfile, char *name, char **symbols, int ns); 14 | void parse_symfiles(char *filename, FILE *header, FILE *cfile); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/disasm/gen/x86.sym: -------------------------------------------------------------------------------- 1 | "+" : plus 2 | "-" : minus 3 | "*" : mult 4 | "[" : rbrk 5 | "]" : lbrk 6 | "," : comma 7 | "byte" : byte 8 | "word" : word 9 | "dword" : dword 10 | "qword" : qword 11 | -------------------------------------------------------------------------------- /src/disasm/lex.h: -------------------------------------------------------------------------------- 1 | #ifndef LEX_H 2 | #define LEX_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "sym.h" 10 | 11 | #define SYMTS(idx) (symbol_tt[idx]) 12 | #define SYMTT(idx) (symtype_tt[idx]) 13 | 14 | /* Assembly Lexer 15 | * Each language file generates a symbol table and gets an index 16 | * into a table of symbol table. 17 | * At runtime the index is passed into the lex function 18 | * */ 19 | 20 | //These are the only global token types 21 | enum token_type { 22 | t_notype, 23 | t_string, 24 | t_number 25 | }; 26 | 27 | char **lex(char *string, int *start, char *delim, int *num_tokens, int type); 28 | int token_type(char *str, int *len, int type, int ptype); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/disasm/spec/mips.spec: -------------------------------------------------------------------------------- 1 | [sll] 2 | end 3 | [srl] 4 | end 5 | [jr] 6 | end 7 | [mfhi] 8 | end 9 | [mflo] 10 | end 11 | [mtlo] 12 | end 13 | [add] 0 14 | o: $w = $0, $r = $1, $r = $2 15 | end 16 | [addu] 0 17 | o: $w = $0, $r = $1, $r = $2 18 | end 19 | [addiu] 0 20 | o: $w = $0, $r = $1, $r = $2 21 | end 22 | [sub] 0 23 | o: $w = $0, $r = $1, $r = $2 24 | end 25 | [or] 1 26 | o: $w = $0, $r = $1, $r = $2 27 | end 28 | [subu] 0 29 | o: $w = $0, $r = $1, $r = $2 30 | end 31 | [mult] 0 32 | o: $r = $0, $r = $1 33 | end 34 | -------------------------------------------------------------------------------- /src/disasm/spec/x86.spec: -------------------------------------------------------------------------------- 1 | [adc] 0 2 | o: $rw = $0, $r = $1 3 | f: $rf=.......c 4 | f: $mf=o..szapc 5 | end 6 | 7 | [sbb] 0 8 | o: $rw = $0, $r = $1 9 | f: $rf=.......c 10 | f: $mf=o..szapc 11 | end 12 | 13 | [add] 0 14 | o: $rw = $0, $r = $1 15 | f: $mf=o..szapc 16 | end 17 | 18 | [sub] 0 19 | o: $rw = $0, $r = $1 20 | f: $mf=o..szapc 21 | end 22 | 23 | [imul] 0 24 | o: $rw = $0, $r = $1, $r = $2 25 | f: $mf=o..szapc 26 | end 27 | 28 | [cmp] 0 29 | o: $r = $0, $r = $1 30 | f: $mf=o..szapc 31 | end 32 | 33 | [or] 1 34 | o: $rw = $0, $r = $1 35 | f: $rf=........ 36 | f: $mf=o..sz.pc 37 | end 38 | 39 | [and] 1 40 | o: $rw = $0, $r = $1 41 | f: $mf=o..szapc 42 | end 43 | 44 | [xor] 1 45 | o: $rw = $0, $r = $1 46 | f: $mf=o..szapc 47 | end 48 | 49 | [jb] 4 50 | o: $r = $0 51 | f: $rf=.......c 52 | end 53 | 54 | [jnb] 4 55 | o: $r = $0 56 | f: $rf=.......c 57 | end 58 | 59 | [jz] 4 60 | o: $r = $0 61 | f: $rf=....z... 62 | end 63 | 64 | [jnz] 4 65 | o: $r = $0 66 | f: $rf=....z... 67 | end 68 | 69 | [jl] 4 70 | o: $r = $0 71 | f: $rf=o..s.... 72 | end 73 | 74 | [jle] 4 75 | o: $r = $0 76 | f: $rf=o..sz... 77 | end 78 | 79 | [jge] 4 80 | o: $r = $0 81 | f: $rf=o..s.... 82 | end 83 | 84 | [jg] 4 85 | o: $r = $0 86 | f: $rf=o..sz... 87 | end 88 | 89 | [mov] 2 90 | o: $w = $0, $r = $1 91 | end 92 | 93 | [push] 3 94 | i: $rw = "esp" 95 | o: $r = $0 96 | end 97 | 98 | [pop] 3 99 | i: $rw = "esp" 100 | o: $w = $0 101 | end 102 | -------------------------------------------------------------------------------- /src/disasm/sym.c: -------------------------------------------------------------------------------- 1 | #include "sym.h" 2 | 3 | const int x86_type[] = { 4 | t_x86_plus, 5 | t_x86_minus, 6 | t_x86_mult, 7 | t_x86_rbrk, 8 | t_x86_lbrk, 9 | t_x86_comma, 10 | t_x86_byte, 11 | t_x86_word, 12 | t_x86_dword, 13 | t_x86_qword, 14 | 0 15 | }; 16 | const char *x86_sym[] = { 17 | "+", 18 | "-", 19 | "*", 20 | "[", 21 | "]", 22 | ",", 23 | "byte", 24 | "word", 25 | "dword", 26 | "qword", 27 | 0 28 | }; 29 | const char **symbol_tt[] = { 30 | (const char**)&x86_sym 31 | };const int *symtype_tt[] = { 32 | (const int*)&x86_type 33 | }; -------------------------------------------------------------------------------- /src/disasm/sym.h: -------------------------------------------------------------------------------- 1 | #ifndef SYM_H 2 | #define SYM_H 3 | 4 | /*Automatically Generated By gen.h&gen.c using all the .sym files*/ 5 | 6 | #define X86_IDX 0 7 | enum x86_types { 8 | t_x86_plus=2, 9 | t_x86_minus, 10 | t_x86_mult, 11 | t_x86_rbrk, 12 | t_x86_lbrk, 13 | t_x86_comma, 14 | t_x86_byte, 15 | t_x86_word, 16 | t_x86_dword, 17 | t_x86_qword 18 | }; 19 | extern const int x86_type[11]; 20 | extern const char *x86_sym[11]; 21 | extern const char **symbol_tt[1]; 22 | extern const int *symtype_tt[1]; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/exec/code/_except.inc: -------------------------------------------------------------------------------- 1 | /* 2 | throw system exception. 3 | */ 4 | 5 | #define THROW_SYSTEM_EXCEPTION(typ, wht) \ 6 | { \ 7 | caller = cur; \ 8 | cur = throw_system_exception(ctx, cur, frmv, typ, wht); \ 9 | KX_GOTO(); \ 10 | } \ 11 | /**/ 12 | 13 | #define THROW_SYSTEM_EXCEPTION_FMT1(typ, fmt, v1) \ 14 | { \ 15 | caller = cur; \ 16 | cur = throw_system_exception_fmt(ctx, cur, frmv, typ, fmt, v1); \ 17 | KX_GOTO(); \ 18 | } \ 19 | /**/ 20 | -------------------------------------------------------------------------------- /src/exec/code/_impllist.md: -------------------------------------------------------------------------------- 1 | | Name | Implemetation | 2 | | :-----: | :-----------: | 3 | | add | **done** | 4 | | and | **done** | 5 | | append | **done** | 6 | | apply | **done** | 7 | | call | **done** | 8 | | catch | **done** | 9 | | dec | **done** | 10 | | div | **done** | 11 | | enter | **done** | 12 | | eqeq | **done** | 13 | | ge | **done** | 14 | | gt | **done** | 15 | | haltnop | **done** | 16 | | inc | **done** | 17 | | jmp | **done** | 18 | | le | **done** | 19 | | lge | **done** | 20 | | lt | **done** | 21 | | mkary | **done** | 22 | | mod | **done** | 23 | | mul | **done** | 24 | | neg | **done** | 25 | | neq | **done** | 26 | | not | **done** | 27 | | or | **done** | 28 | | pop | **done** | 29 | | push | **done** | 30 | | ret | **done** | 31 | | shl | **done** | 32 | | shr | **done** | 33 | | store | **done** | 34 | | sub | **done** | 35 | | throw | **done** | 36 | | xor | **done** | 37 | -------------------------------------------------------------------------------- /src/exec/code/bnot.inc: -------------------------------------------------------------------------------- 1 | #define KX_BNOT_CODE() \ 2 | { \ 3 | KEX_GET_STACK_TOP(v1); \ 4 | if ((v1)->type == KX_INT_T) { \ 5 | (v1)->value.iv = ~((v1)->value.iv); \ 6 | } else if ((v1)->type == KX_BIG_T) { \ 7 | (v1)->value.bz = make_big_alive(ctx, BzNot((v1)->value.bz)); \ 8 | KX_BIGINT_CHKINT(v1); \ 9 | } else { \ 10 | THROW_SYSTEM_EXCEPTION("SystemException", "Unsupported operator"); \ 11 | } \ 12 | cur = cur->next; \ 13 | } \ 14 | /**/ 15 | -------------------------------------------------------------------------------- /src/exec/code/catch.inc: -------------------------------------------------------------------------------- 1 | #define KX_CATCH_CODE() \ 2 | { \ 3 | KEX_SAVE_VARINFO(kv_A(frmv->v, cur->value2.i)); \ 4 | kv_A(frmv->v, cur->value2.i) = (ctx)->excval; \ 5 | KEX_RESTORE_VARINFO(kv_A(frmv->v, cur->value2.i)); \ 6 | cur = cur->next; \ 7 | } \ 8 | /**/ 9 | -------------------------------------------------------------------------------- /src/exec/code/haltnop.inc: -------------------------------------------------------------------------------- 1 | #define KX_HALT_CODE() \ 2 | { \ 3 | goto LBL_KX_END_OF_CODE; \ 4 | } \ 5 | /**/ 6 | 7 | #define KX_NOP_CODE() \ 8 | { \ 9 | cur = cur->next; \ 10 | } \ 11 | /**/ 12 | 13 | #define KX_DUP_CODE() \ 14 | { \ 15 | KEX_GET_STACK_TOP(v1); \ 16 | push_value((ctx)->stack, (*v1)); \ 17 | cur = cur->next; \ 18 | } \ 19 | /**/ 20 | 21 | #define KX_IMPORT_CODE() \ 22 | { \ 23 | kx_obj_t *obj = import_library(ctx, frmv, cur); \ 24 | if (!obj) { \ 25 | THROW_SYSTEM_EXCEPTION_FMT1("SystemException", "Loading import module(%s) failed", cur->value1.s); \ 26 | } \ 27 | push_obj((ctx)->stack, obj); \ 28 | cur = cur->next; \ 29 | } \ 30 | /**/ 31 | 32 | #define KX_TYPEOF_CODE() \ 33 | { \ 34 | KEX_POP_STACK_TOP(v1); \ 35 | int r = check_typeof(v1->type == KX_LVAL_T ? v1->value.lv : v1, cur->value1.i); \ 36 | push_i((ctx)->stack, r); \ 37 | cur = cur->next; \ 38 | } \ 39 | /**/ 40 | 41 | #define KX_SET_GMM_CODE() \ 42 | { \ 43 | KEX_GET_STACK_TOP(v1); \ 44 | if (v1->type == KX_FNC_T || v1->type == KX_BFNC_T ) { \ 45 | (ctx)->objs.global_method_missing = v1->value.fn; \ 46 | } \ 47 | cur = cur->next; \ 48 | } \ 49 | /**/ 50 | -------------------------------------------------------------------------------- /src/exec/code/neg.inc: -------------------------------------------------------------------------------- 1 | #define KX_NEG_CODE() \ 2 | { \ 3 | KEX_GET_STACK_TOP(v1); \ 4 | switch ((v1)->type) { \ 5 | case KX_UND_T: { \ 6 | (v1)->value.iv = 0; \ 7 | (v1)->type = KX_INT_T; \ 8 | break; \ 9 | } \ 10 | case KX_INT_T: { \ 11 | int64_t v1val = (v1)->value.iv; \ 12 | if (v1val == INT64_MIN) { \ 13 | BigZ bi = BzFromString("8000000000000000", 16, BZ_UNTIL_END); \ 14 | BzSetSign(bi, BZ_PLUS); \ 15 | (v1)->value.bz = make_big_alive(ctx, bi); \ 16 | (v1)->type = KX_BIG_T; \ 17 | } else { \ 18 | (v1)->value.iv = -v1val; \ 19 | } \ 20 | break; \ 21 | } \ 22 | case KX_BIG_T: { \ 23 | BigZ bv = (v1)->value.bz; \ 24 | BzCmp chk = BzCompare(bv, get_int64max_plus1()); \ 25 | if (chk == BZ_EQ) { \ 26 | (v1)->value.iv = INT64_MIN; \ 27 | (v1)->type = KX_INT_T; \ 28 | } else { \ 29 | bv = BzNegate(bv); \ 30 | (v1)->value.bz = make_big_alive(ctx, bv); \ 31 | } \ 32 | break; \ 33 | } \ 34 | case KX_DBL_T: { \ 35 | (v1)->value.dv = -((v1)->value.dv); \ 36 | break; \ 37 | } \ 38 | default: \ 39 | THROW_SYSTEM_EXCEPTION("SystemException", "Unsupported Operator"); \ 40 | break; \ 41 | } \ 42 | cur = cur->next; \ 43 | } \ 44 | /**/ 45 | -------------------------------------------------------------------------------- /src/exec/code/not.inc: -------------------------------------------------------------------------------- 1 | #define KX_NOT_CODE() \ 2 | { \ 3 | KEX_GET_STACK_TOP(v1); \ 4 | KX_IS_FALSE(v1, tf); \ 5 | (v1)->value.iv = tf; \ 6 | (v1)->type = KX_INT_T; \ 7 | cur = cur->next; \ 8 | } \ 9 | /**/ 10 | -------------------------------------------------------------------------------- /src/exec/code/pop.inc: -------------------------------------------------------------------------------- 1 | #define KX_POP_CODE() \ 2 | { \ 3 | kv_remove_last((ctx)->stack); \ 4 | cur = cur->next; \ 5 | } \ 6 | /**/ 7 | 8 | #define KX_POP_C_CODE() \ 9 | { \ 10 | kv_remove_last((ctx)->exception); \ 11 | cur = cur->next; \ 12 | } \ 13 | /**/ 14 | -------------------------------------------------------------------------------- /src/exec/code/pow.inc: -------------------------------------------------------------------------------- 1 | 2 | #define KX_POW_CODE() \ 3 | { \ 4 | KEX_POP_STACK_TOP(v2); \ 5 | KEX_GET_STACK_TOP(v1); \ 6 | int exc = 0; \ 7 | kx_fnc_t *fn = kx_try_pow(ctx, cur, v1, v2, &exc); \ 8 | KX_EXCEPTION_CHECK("SystemException", exc); \ 9 | CALL_OP_FUNCTION(fn, cur, { push_value((ctx)->stack, *v2); }); \ 10 | } \ 11 | /**/ 12 | -------------------------------------------------------------------------------- /src/exec/code/regeq.inc: -------------------------------------------------------------------------------- 1 | 2 | #define KX_REGEQ_CODE() \ 3 | { \ 4 | KEX_POP_STACK_TOP(v2); \ 5 | KEX_GET_STACK_TOP(v1); \ 6 | int r = kx_regex_eq(ctx, frmv, cur, v1, v2, 1); \ 7 | KX_EXCEPTION_CHECK("RegexException", r); \ 8 | cur = cur->next; \ 9 | } \ 10 | /**/ 11 | 12 | #define KX_REGNE_CODE() \ 13 | { \ 14 | KEX_POP_STACK_TOP(v2); \ 15 | KEX_GET_STACK_TOP(v1); \ 16 | int r = kx_regex_eq(ctx, frmv, cur, v1, v2, 0); \ 17 | KX_EXCEPTION_CHECK("RegexException", r); \ 18 | cur = cur->next; \ 19 | } \ 20 | /**/ 21 | -------------------------------------------------------------------------------- /src/extlib/kc-json/.gitignore: -------------------------------------------------------------------------------- 1 | # Common 2 | dist/ 3 | bench/ 4 | 5 | # Prerequisites 6 | *.d 7 | 8 | # Object files 9 | *.o 10 | *.ko 11 | *.obj 12 | *.elf 13 | 14 | # Linker output 15 | *.ilk 16 | *.map 17 | *.exp 18 | 19 | # Precompiled Headers 20 | *.gch 21 | *.pch 22 | 23 | # Libraries 24 | *.lib 25 | *.a 26 | *.la 27 | *.lo 28 | 29 | # Shared objects (inc. Windows DLLs) 30 | *.dll 31 | *.so 32 | *.so.* 33 | *.dylib 34 | 35 | # Executables 36 | *.exe 37 | *.out 38 | *.app 39 | *.i*86 40 | *.x86_64 41 | *.hex 42 | 43 | # Debug files 44 | *.dSYM/ 45 | *.su 46 | *.idb 47 | *.pdb 48 | 49 | # Kernel Module Compile Results 50 | *.mod* 51 | *.cmd 52 | .tmp_versions/ 53 | modules.order 54 | Module.symvers 55 | Mkfile.old 56 | dkms.conf 57 | -------------------------------------------------------------------------------- /src/extlib/kc-json/Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | .SUFFIXES: 3 | 4 | NAME = kc-json 5 | CC = gcc 6 | CFLAGS = -O2 -Wno-missing-braces -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -std=gnu99 7 | 8 | all: dist/$(NAME).c dist/sample.exe 9 | 10 | dist/$(NAME).c: dist/myacc 11 | ./dist/myacc -y __json_yy -Y JSON_YY src/$(NAME).y 12 | cp -f y.tab.c dist/$(NAME).c 13 | cat src/string.c >> dist/$(NAME).c 14 | cat src/vector.c >> dist/$(NAME).c 15 | rm -f y.tab.c 16 | cp -f src/$(NAME).h dist/$(NAME).h 17 | 18 | dist/myacc: 19 | mkdir -p dist 20 | $(CC) $(CFLAGS) -o dist/myacc util/myacc.c 21 | 22 | dist/sample.exe: 23 | cp -f sample/* dist/ 24 | cd dist; \ 25 | $(CC) $(CFLAGS) -o sample sample.c kc-json.c -lm; \ 26 | cd .. 27 | 28 | sample: dist/sample 29 | cp -f sample/* dist/ 30 | cd dist; \ 31 | ./sample sample.json; \ 32 | ./sample sample_ext1.json; \ 33 | cd .. 34 | 35 | clean: 36 | rm -rf dist > /dev/null 37 | 38 | -------------------------------------------------------------------------------- /src/extlib/kc-json/Makefile.msc: -------------------------------------------------------------------------------- 1 | 2 | NAME = kc-json 3 | CC = cl 4 | LINK = link 5 | CFLAGS = /O2 /MT /Iinclude /DONIG_EXTERN=extern 6 | LFLAGS = 7 | 8 | .SUFFIXES : 9 | .SUFFIXES : .c .obj 10 | 11 | all: dist/$(NAME).c dist/$(NAME).obj dist/sample.exe 12 | 13 | dist/$(NAME).c: myacc.exe src\$(NAME).y 14 | if not exist dist mkdir dist 15 | myacc -v -y __json_yy -Y JSON_YY src\$(NAME).y 16 | copy /y src\string.c dist\$(NAME).c 17 | type src\vector.c >> dist\$(NAME).c 18 | type y.tab.c >> dist\$(NAME).c 19 | del /q y.tab.c 20 | copy /y src\$(NAME).h dist\$(NAME).h 21 | 22 | dist/$(NAME).obj: 23 | cd dist 24 | $(CC) -c $(CFLAGS) -Fo$(NAME).obj $(NAME).c 25 | cd .. 26 | 27 | myacc.exe: 28 | $(CC) $(CFLAGS) /Femyacc.exe util\myacc.c 29 | 30 | dist/sample.exe: 31 | copy /y sample\*.* dist 32 | cd dist 33 | $(CC) $(CFLAGS) /Fesample.exe sample.c kc-json.c 34 | cd .. 35 | 36 | sample: dist/sample.exe 37 | copy /y sample\*.* dist 38 | cd dist 39 | sample.exe sample.json 40 | sample.exe sample_ext1.json 41 | cd .. 42 | 43 | clean: 44 | del /s *.exe *.obj *.dll *.lib > NUL 45 | if exist dist del /q dist\*.* > NUL 46 | 47 | .c.obj: 48 | $(CC) -c $(CFLAGS) -Fo$*.obj $< 49 | -------------------------------------------------------------------------------- /src/extlib/kc-json/sample/sample.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kc-json.h" 3 | 4 | int main(int ac, char **av) 5 | { 6 | if (ac < 2) { 7 | return 1; 8 | } 9 | json_object_t *j = json_parse_file(av[1]); 10 | if (j) { 11 | /* Printing elements */ 12 | json_pretty_print(j); 13 | 14 | /* Counting elements */ 15 | int count = json_get_element_count(j); 16 | printf("element count = %d\n", count); 17 | 18 | /* Accessing elements */ 19 | json_object_t *e = json_get_element(j, 1); 20 | json_object_t *p = json_get_property(e, "path"); 21 | 22 | /* Getting the value */ 23 | string_t *s = json_get_string(p); 24 | printf("json[1].path = %s\n", s ? s->cstr : ""); 25 | 26 | /* Releasing all allocated memory */ 27 | json_free_all(j); 28 | } else { 29 | printf("Parse Error: %s\n", json_error_message()); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/extlib/kc-json/sample/sample.json: -------------------------------------------------------------------------------- 1 | [ "Sample", 2 | { "x": 410, "y": 150, "type": "link", "path": "/Applications" }, 3 | { 4 | "p1": { "x": 130, "y": 150, "type": "file" }, 5 | "p2": { "x": 230, "y": 90, "type": "directory" }, 6 | "p3": { "x": 230, "y": 775.89, "type": "directory" } 7 | }, 8 | ["aa", ["bb","cc"], "dd"] 9 | ] 10 | -------------------------------------------------------------------------------- /src/extlib/kc-json/sample/sample_ext1.json: -------------------------------------------------------------------------------- 1 | [ "Sample" + " (" + 1 + ")", 2 | { "x": 410, "y": 150 * (20 + 1), "type": "link", "path": "/Applications" }, 3 | { 4 | "p1": { "x": 130, "y": 150, "type": "file" }, 5 | "p2": { "x": 230, "y": 90, "type": "directory" } 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /src/extlib/kc-json/src/string.c: -------------------------------------------------------------------------------- 1 | #include "kc-json.h" 2 | 3 | string_t string_init_alloc(const char *cstr) 4 | { 5 | unsigned int len = strlen(cstr); 6 | unsigned int cap = KCC_CAPACITY(len); 7 | char *buf = (char *)malloc(cap * sizeof(char)); 8 | memcpy(buf, cstr, len); 9 | buf[len] = 0; 10 | return (string_t) { 11 | .len = len, 12 | .cap = cap, 13 | .cstr = buf, 14 | }; 15 | } 16 | 17 | string_t string_substr(const string_t str, int start, int len) 18 | { 19 | unsigned int end = len < 0 ? str.len : (start + len); 20 | if (0 < len && str.len < end) { 21 | end = str.len; 22 | } 23 | len = end - start; 24 | char *buf = malloc(str.cap * sizeof(char)); 25 | memcpy(buf, str.cstr + start, len); 26 | buf[len] = 0; 27 | return (string_t) { 28 | .len = len, 29 | .cap = str.cap, 30 | .cstr = buf, 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /src/extlib/kc-json/src/vector.c: -------------------------------------------------------------------------------- 1 | #include "kc-json.h" 2 | 3 | /* --------------------------------------------------------------------------------------------- 4 | KCC Extended Library - vector 5 | This is from Public Domain, cvec: https://github.com/graphitemaster/cvec 6 | --------------------------------------------------------------------------------------------- */ 7 | 8 | void vec_grow(void **vector, size_t more, size_t type_size) 9 | { 10 | vector_t *meta = vector_meta(*vector); 11 | size_t count = 0; 12 | void *data = NULL; 13 | 14 | if (*vector) { 15 | count = 2 * meta->allocated + more; 16 | data = malloc(type_size * count + sizeof(*meta)); 17 | memcpy(data, meta, type_size * count + sizeof(*meta)); 18 | free(meta); 19 | } else { 20 | count = more + 1; 21 | data = malloc(type_size * count + sizeof(*meta)); 22 | ((vector_t *)data)->used = 0; 23 | } 24 | 25 | meta = (vector_t *)data; 26 | meta->allocated = count; 27 | *vector = meta + 1; 28 | } 29 | 30 | void vec_delete(void *vector) 31 | { 32 | free(vector_meta(vector)); 33 | } 34 | -------------------------------------------------------------------------------- /src/extlib/kc-json/util/LICENSE.miniyacc: -------------------------------------------------------------------------------- 1 | MIT/X Consortium License 2 | 3 | © 2015 Quentin Carbonneaux 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/extlib/libclipboard/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Jeremy Tan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/extlib/libclipboard/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | mkdir -p build 4 | cd build; cmake ..; make clean; make 5 | cp build/lib/libclipboard.a ../../../build/libclipboard.a 6 | cp build/include/*.h include/ 7 | gcc -o kxsel -DVERSION="\"1.2.0\"" xsel.c -lX11 8 | cp ./kxsel ../../../build/ 9 | -------------------------------------------------------------------------------- /src/extlib/libclipboard/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 3 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | foreach(file ${files}) 8 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 9 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 10 | exec_program( 11 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 12 | OUTPUT_VARIABLE rm_out 13 | RETURN_VALUE rm_retval 14 | ) 15 | if(NOT "${rm_retval}" STREQUAL 0) 16 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 17 | endif(NOT "${rm_retval}" STREQUAL 0) 18 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 19 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 20 | endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 21 | endforeach(file) -------------------------------------------------------------------------------- /src/extlib/libclipboard/include/libclipboard-config.h.in: -------------------------------------------------------------------------------- 1 | /** 2 | * \file libclipboard-config.h 3 | * \brief Configuration specific options 4 | * 5 | * \copyright Copyright (C) 2016 Jeremy Tan. 6 | * This file is released under the MIT license. 7 | * See LICENSE for details. 8 | * 9 | * \details NOTE: This file is automatically generated. 10 | */ 11 | 12 | #ifndef _LIBCLIPBOARD_CONFIG_H 13 | #define _LIBCLIPBOARD_CONFIG_H 14 | 15 | /** Major version of libclipboard **/ 16 | #define LIBCLIPBOARD_VERSION_MAJOR @LIBCLIPBOARD_VERSION_MAJOR@ 17 | 18 | /** Minor version of libclipboard **/ 19 | #define LIBCLIPBOARD_VERSION_MINOR @LIBCLIPBOARD_VERSION_MINOR@ 20 | 21 | /** Are we building the Win32 backend? **/ 22 | #cmakedefine LIBCLIPBOARD_BUILD_WIN32 23 | 24 | /** Are we building the X11 backend? **/ 25 | #cmakedefine LIBCLIPBOARD_BUILD_X11 26 | 27 | /** Are we building the Cocoa (OS X) backend? **/ 28 | #cmakedefine LIBCLIPBOARD_BUILD_COCOA 29 | 30 | /** Are we building a shared library? **/ 31 | #cmakedefine LIBCLIPBOARD_BUILD_SHARED 32 | 33 | /** Are we using the stdcall calling convention? **/ 34 | #cmakedefine LIBCLIPBOARD_USE_STDCALL 35 | 36 | #endif /* _LIBCLIPBOARD_CONFIG_H */ 37 | -------------------------------------------------------------------------------- /src/extlib/libclipboard/libclipboard.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/@LIB_INSTALL_DIR@ 4 | includedir=${prefix}/include 5 | 6 | Name: lib@CMAKE_PROJECT_NAME@ 7 | Description: Cross-platform clipboard library 8 | Version: @LIBCLIPBOARD_VERSION@ 9 | Libs: -L${libdir} -lclipboard 10 | Libs.private: @LIBCLIPBOARD_PRIVATE_LIBS_LIST@ 11 | Cflags: -I${includedir} -------------------------------------------------------------------------------- /src/extlib/libclipboard/samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libclipboard sample executables 2 | 3 | # Set executables 4 | add_executable(clip_sample1 clipboard_sample1.c) 5 | 6 | # Link it with libclipboard 7 | target_link_libraries(clip_sample1 LINK_PUBLIC clipboard) 8 | -------------------------------------------------------------------------------- /src/extlib/libclipboard/src/clipboard_common.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file clipboard_common.c 3 | * \brief Common implementation functions of the clipboard. 4 | */ 5 | 6 | #include "libclipboard.h" 7 | #include 8 | 9 | LCB_API char *LCB_CC clipboard_text(clipboard_c *cb) { 10 | return clipboard_text_ex(cb, NULL, LCB_CLIPBOARD); 11 | } 12 | 13 | LCB_API bool LCB_CC clipboard_set_text(clipboard_c *cb, const char *src) { 14 | return clipboard_set_text_ex(cb, src, -1, LCB_CLIPBOARD); 15 | } 16 | -------------------------------------------------------------------------------- /src/extlib/onig/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | autom4te.cache/ 3 | ltmain.sh 4 | stamp-h1 5 | configure 6 | config.status 7 | config.h 8 | config.h.in 9 | onig-config 10 | libtool 11 | aclocal.m4 12 | Makefile.in 13 | .python-version 14 | *.o 15 | *.obj 16 | *.so 17 | *.lo 18 | *.la 19 | *.pc 20 | *.log 21 | *.dll 22 | *.lib 23 | *.exe 24 | *.exp 25 | *.gcno 26 | *.gcda 27 | *.gcov 28 | *~ 29 | .libs/ 30 | .deps/ 31 | /build 32 | /onig-*.tar.gz 33 | m4/*.m4 34 | /coverage 35 | /coverage.info 36 | /fuzzers 37 | 38 | # src/ 39 | /src/unicode_fold?_key.gperf 40 | /src/unicode_unfold_key.gperf 41 | /src/UNICODE_PROPERTIES 42 | /src/*.txt 43 | /src/mktable 44 | 45 | # test/ 46 | /test/test_utf8 47 | /test/test_options 48 | /test/testc 49 | /test/testcu 50 | /test/testp 51 | /test/test_regset 52 | /test/test_syntax 53 | /test/test_back 54 | /test/kofu-utf8.txt 55 | 56 | # sample/ 57 | /sample/crnl 58 | /sample/encode 59 | /sample/listcap 60 | /sample/names 61 | /sample/posix 62 | /sample/simple 63 | /sample/sql 64 | /sample/syntax 65 | /sample/user_property 66 | /sample/callout 67 | /sample/echo 68 | /sample/count 69 | /sample/bug_fix 70 | /sample/regset 71 | /sample/scan 72 | /sample/log* 73 | 74 | /harnesses/utf16*.dict 75 | /harnesses/fuzzer-* 76 | /harnesses/read-* 77 | /harnesses/libfuzzer-onig 78 | /harnesses/libfuzzer-onig-full 79 | /harnesses/slow-unit-* 80 | /harnesses/timeout-* 81 | /harnesses/crash-* 82 | /harnesses/oom-* 83 | -------------------------------------------------------------------------------- /src/extlib/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/extlib/onig/AUTHORS: -------------------------------------------------------------------------------- 1 | (K.Kosako) 2 | -------------------------------------------------------------------------------- /src/extlib/onig/COPYING: -------------------------------------------------------------------------------- 1 | Oniguruma LICENSE 2 | ----------------- 3 | 4 | Copyright (c) 2002-2021 K.Kosako 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /src/extlib/onig/ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/src/extlib/onig/ChangeLog -------------------------------------------------------------------------------- /src/extlib/onig/NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/src/extlib/onig/NEWS -------------------------------------------------------------------------------- /src/extlib/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/extlib/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/extlib/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/extlib/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/extlib/onig/harnesses/fuzzer.options: -------------------------------------------------------------------------------- 1 | [libfuzzer] 2 | dict = ascii_compatible.dict 3 | -------------------------------------------------------------------------------- /src/extlib/onig/harnesses/libfuzzer-onig.cpp: -------------------------------------------------------------------------------- 1 | /* libfuzzer test code for oniguruma 2 | * author: Hanno Böck, license: CC0/public domain 3 | 4 | Usage: 5 | * compile oniguruma with something like 6 | ./configure CC=clang LD=clang CFLAGS="-fsanitize-coverage=edge -fsanitize=address" \ 7 | LDFLAGS="-fsanitize-coverage=edge -fsanitize=address" 8 | * Compile libfuzzer stub and link against static libonig.a and libFuzzer.a: 9 | clang++ libfuzzer-onig.cpp src/.libs/libonig.a libFuzzer.a -o libfuzzer-onig \ 10 | -fsanitize-coverage=edge -fsanitize=address 11 | * Put sample patterns in directory "in/" 12 | * Run 13 | ./libfuzzer-onig in 14 | 15 | Consult libfuzzer docs for further details and how to create libFuzzer.a: 16 | http://llvm.org/docs/LibFuzzer.html 17 | 18 | */ 19 | #include 20 | #include 21 | #include 22 | 23 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t * Data, size_t Size) 24 | { 25 | regex_t *reg; 26 | OnigEncoding enc; 27 | 28 | enc = ONIG_ENCODING_UTF8; 29 | 30 | #ifdef FULL_TEST 31 | onig_initialize(&enc, 1); 32 | onig_set_retry_limit_in_match(120); 33 | onig_set_parse_depth_limit(120); 34 | #endif 35 | 36 | if (onig_new(®, Data, Data + Size, ONIG_OPTION_DEFAULT, enc, 37 | ONIG_SYNTAX_DEFAULT, 0) == 0) 38 | onig_free(reg); 39 | 40 | #ifdef FULL_TEST 41 | onig_end(); 42 | #endif 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/extlib/onig/m4/.whatever: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/src/extlib/onig/m4/.whatever -------------------------------------------------------------------------------- /src/extlib/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/extlib/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/extlib/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/extlib/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/extlib/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/extlib/onig/sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(oniguruma_sample C) 3 | 4 | add_executable(crnl crnl.c) 5 | target_link_libraries(crnl onig) 6 | 7 | add_executable(callout callout.c) 8 | target_link_libraries(callout onig) 9 | 10 | add_executable(echo echo.c) 11 | target_link_libraries(echo onig) 12 | 13 | add_executable(count count.c) 14 | target_link_libraries(count onig) 15 | 16 | add_executable(encode encode.c) 17 | target_link_libraries(encode onig) 18 | 19 | add_executable(listcap listcap.c) 20 | target_link_libraries(listcap onig) 21 | 22 | add_executable(names names.c) 23 | target_link_libraries(names onig) 24 | 25 | add_executable(posix posix.c) 26 | target_link_libraries(posix onig) 27 | 28 | add_executable(simple simple.c) 29 | target_link_libraries(simple onig) 30 | 31 | add_executable(sql sql.c) 32 | target_link_libraries(sql onig) 33 | 34 | add_executable(syntax syntax.c) 35 | target_link_libraries(syntax onig) 36 | -------------------------------------------------------------------------------- /src/extlib/onig/sample/Makefile.am: -------------------------------------------------------------------------------- 1 | #noinst_PROGRAMS = encode listcap names posix simple sql syntax crnl 2 | 3 | lib_onig = ../src/libonig.la 4 | LDADD = $(lib_onig) 5 | 6 | AM_CFLAGS = -Wall 7 | AM_LDFLAGS = -L$(libdir) 8 | AM_CPPFLAGS = -I$(top_srcdir)/src 9 | 10 | if ENABLE_POSIX_API 11 | TESTS = encode listcap names posix simple sql syntax user_property callout echo count bug_fix regset scan 12 | else 13 | TESTS = encode listcap names simple sql syntax user_property callout echo count bug_fix regset scan 14 | endif 15 | 16 | check_PROGRAMS = $(TESTS) 17 | 18 | encode_SOURCES = encode.c 19 | listcap_SOURCES = listcap.c 20 | names_SOURCES = names.c 21 | posix_SOURCES = posix.c 22 | simple_SOURCES = simple.c 23 | sql_SOURCES = sql.c 24 | syntax_SOURCES = syntax.c 25 | user_property_SOURCES = user_property.c 26 | callout_SOURCES = callout.c 27 | echo_SOURCES = echo.c 28 | count_SOURCES = count.c 29 | bug_fix = bug_fix.c 30 | regset_SOURCES = regset.c 31 | scan_SOURCES = scan.c 32 | 33 | sampledir = . 34 | 35 | test: $(TESTS) 36 | $(sampledir)/encode 37 | $(sampledir)/listcap 38 | $(sampledir)/names 39 | if ENABLE_POSIX_API 40 | $(sampledir)/posix 41 | endif 42 | $(sampledir)/simple 43 | $(sampledir)/sql 44 | $(sampledir)/syntax 45 | $(sampledir)/user_property 46 | $(sampledir)/callout 47 | $(sampledir)/echo 48 | $(sampledir)/count 49 | $(sampledir)/bug_fix 50 | $(sampledir)/regset 51 | $(sampledir)/scan 52 | -------------------------------------------------------------------------------- /src/extlib/onig/src/euc_jp_prop.gperf: -------------------------------------------------------------------------------- 1 | %{ 2 | #include "regint.h" 3 | %} 4 | 5 | struct PropertyNameCtype { 6 | char *name; 7 | int ctype; 8 | }; 9 | 10 | %% 11 | Alpha, 1 12 | Blank, 2 13 | Cntrl, 3 14 | Digit, 4 15 | Graph, 5 16 | Lower, 6 17 | Print, 7 18 | Punct, 8 19 | Space, 9 20 | Upper, 10 21 | XDigit, 11 22 | Word, 12 23 | Alnum, 13 24 | ASCII, 14 25 | Hiragana, 15 26 | Katakana, 16 27 | -------------------------------------------------------------------------------- /src/extlib/onig/src/make_property.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | GPERF=gperf 4 | SED=sed 5 | 6 | TMP1=gperf1.tmp 7 | TMP2=gperf2.tmp 8 | 9 | GPERF_OPT='-pt -T -L ANSI-C' 10 | 11 | ADD_CAST='s/return +len +\+ +asso_values/return (unsigned int )len + asso_values/' 12 | 13 | ${GPERF} ${GPERF_OPT} -N onigenc_euc_jp_lookup_property_name --output-file ${TMP1} euc_jp_prop.gperf 14 | cat ${TMP1} | ${SED} -r "${ADD_CAST}" > euc_jp_prop.c 15 | 16 | ${GPERF} ${GPERF_OPT} -N onigenc_sjis_lookup_property_name --output-file ${TMP2} sjis_prop.gperf 17 | cat ${TMP2} | ${SED} -r "${ADD_CAST}" > sjis_prop.c 18 | 19 | rm -f ${TMP1} ${TMP2} 20 | 21 | exit 0 22 | -------------------------------------------------------------------------------- /src/extlib/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/extlib/onig/src/make_unicode_fold.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | GPERF=gperf 4 | 5 | TMP0=gperf0.tmp 6 | TMP1=gperf1.tmp 7 | TMP2=gperf2.tmp 8 | TMP3=gperf3.tmp 9 | 10 | GPERF_OPT='-n -C -T -c -t -j1 -L ANSI-C ' 11 | 12 | ./make_unicode_fold_data.py > unicode_fold_data.c 13 | 14 | ${GPERF} ${GPERF_OPT} -F,-1,0 -N onigenc_unicode_unfold_key unicode_unfold_key.gperf > ${TMP0} 15 | ./gperf_unfold_key_conv.py < ${TMP0} > unicode_unfold_key.c 16 | 17 | ${GPERF} ${GPERF_OPT} -F,-1 -N onigenc_unicode_fold1_key unicode_fold1_key.gperf > ${TMP1} 18 | ./gperf_fold_key_conv.py 1 < ${TMP1} > unicode_fold1_key.c 19 | 20 | ${GPERF} ${GPERF_OPT} -F,-1 -N onigenc_unicode_fold2_key unicode_fold2_key.gperf > ${TMP2} 21 | ./gperf_fold_key_conv.py 2 < ${TMP2} > unicode_fold2_key.c 22 | 23 | ${GPERF} ${GPERF_OPT} -F,-1 -N onigenc_unicode_fold3_key unicode_fold3_key.gperf > ${TMP3} 24 | ./gperf_fold_key_conv.py 3 < ${TMP3} > unicode_fold3_key.c 25 | 26 | # remove redundant EOLs before EOF 27 | perl -i -pe 'BEGIN{undef $/}s/\n\n*\z/\n/;' unicode_fold_data.c 28 | perl -i -pe 'BEGIN{undef $/}s/\n\n*\z/\n/;' unicode_fold1_key.c 29 | perl -i -pe 'BEGIN{undef $/}s/\n\n*\z/\n/;' unicode_fold2_key.c 30 | perl -i -pe 'BEGIN{undef $/}s/\n\n*\z/\n/;' unicode_fold3_key.c 31 | perl -i -pe 'BEGIN{undef $/}s/\n\n*\z/\n/;' unicode_unfold_key.c 32 | 33 | rm -f ${TMP0} ${TMP1} ${TMP2} ${TMP3} 34 | rm -f unicode_unfold_key.gperf unicode_fold1_key.gperf unicode_fold2_key.gperf unicode_fold3_key.gperf 35 | 36 | exit 0 37 | -------------------------------------------------------------------------------- /src/extlib/onig/src/make_unicode_property.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | GPERF=gperf 4 | SED=sed 5 | 6 | NAME=unicode_property_data 7 | TMP1=gperf1.tmp 8 | TMP2=gperf2.tmp 9 | TMP= 10 | 11 | GPERF_OPT='-T -C -c -t -j1 -L ANSI-C --ignore-case --pic -Q unicode_prop_name_pool' 12 | POOL_CAST='s/\(int *\)\(size_t *\)&\(\(struct +unicode_prop_name_pool_t *\* *\) *0\)->unicode_prop_name_pool_str([^,]+)/pool_offset(\1)/g' 13 | ADD_STATIC='s/(const +struct +PoolPropertyNameCtype +\*)/static \1/' 14 | ADD_CAST='s/unsigned +int +hval *= *len/unsigned int hval = (unsigned int )len/' 15 | 16 | ./make_unicode_property_data.py > ${NAME}.gperf 17 | ./make_unicode_property_data.py -posix > ${NAME}_posix.gperf 18 | 19 | ${GPERF} ${GPERF_OPT} -N unicode_lookup_property_name --output-file ${TMP1} ${NAME}.gperf 20 | cat ${TMP1} | ${SED} -e 's/^#line.*$//g' | ${SED} -r "${POOL_CAST}" | ${SED} -r "${ADD_STATIC}" | ${SED} -r "${ADD_CAST}" > ${NAME}.c 21 | 22 | ${GPERF} ${GPERF_OPT} -N unicode_lookup_property_name --output-file ${TMP2} ${NAME}_posix.gperf 23 | cat ${TMP2} | ${SED} -e 's/^#line.*$//g' | ${SED} -r "${POOL_CAST}" | ${SED} -r "${ADD_STATIC}" > ${NAME}_posix.c 24 | 25 | rm -f ${NAME}.gperf ${NAME}_posix.gperf ${TMP1} ${TMP2} 26 | 27 | exit 0 28 | -------------------------------------------------------------------------------- /src/extlib/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/extlib/onig/src/sjis_prop.gperf: -------------------------------------------------------------------------------- 1 | %{ 2 | #include "regint.h" 3 | %} 4 | 5 | struct PropertyNameCtype { 6 | char *name; 7 | int ctype; 8 | }; 9 | 10 | %% 11 | Alpha, 1 12 | Blank, 2 13 | Cntrl, 3 14 | Digit, 4 15 | Graph, 5 16 | Lower, 6 17 | Print, 7 18 | Punct, 8 19 | Space, 9 20 | Upper, 10 21 | XDigit, 11 22 | Word, 12 23 | Alnum, 13 24 | ASCII, 14 25 | Hiragana, 15 26 | Katakana, 16 27 | -------------------------------------------------------------------------------- /src/extlib/onig/test/testc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/src/extlib/onig/test/testc.c -------------------------------------------------------------------------------- /src/extlib/onig/tis-ci/stub.c: -------------------------------------------------------------------------------- 1 | void srand(unsigned int seed) { 2 | return; 3 | } 4 | -------------------------------------------------------------------------------- /src/extlib/onig/tis-ci/test_back.config: -------------------------------------------------------------------------------- 1 | { 2 | "compilation_cmd": "-I ../tis-ci -I ../src -D alloca=__builtin_alloca", 3 | "files": [ 4 | "../test/test_back.c", 5 | "../src/unicode.c", 6 | "../src/regcomp.c", 7 | "../src/regenc.c", 8 | "../src/utf16_be.c", 9 | "../src/regparse.c", 10 | "../src/st.c", 11 | "../src/regexec.c", 12 | "../src/unicode_unfold_key.c", 13 | "../src/unicode_fold3_key.c", 14 | "../src/unicode_fold2_key.c", 15 | "../src/unicode_fold1_key.c", 16 | "../src/utf8.c", 17 | "../src/regerror.c", 18 | "../src/regversion.c", 19 | "../src/ascii.c" 20 | ], 21 | "machdep": "gcc_x86_64", 22 | "main": "main", 23 | "name": "test_back.c FULL", 24 | "address-alignment": 65536, /* hexadecimal 0x10000 */ 25 | "val-warn-undefined-pointer-comparison": "none" 26 | } 27 | -------------------------------------------------------------------------------- /src/extlib/onig/tis-ci/test_regset.config: -------------------------------------------------------------------------------- 1 | { 2 | "compilation_cmd": "-I ../tis-ci -I ../src -D alloca=__builtin_alloca", 3 | "files": [ 4 | "../test/test_regset.c", 5 | "../tis-ci/stub.c", 6 | "../src/regcomp.c", 7 | "../src/regenc.c", 8 | "../src/utf8.c", 9 | "../src/regexec.c", 10 | "../src/ascii.c", 11 | "../src/regparse.c", 12 | "../src/st.c", 13 | "../src/regversion.c" 14 | ], 15 | "machdep": "gcc_x86_64", 16 | "main": "main", 17 | "name": "test_regset.c FULL", 18 | "address-alignment": 65536, /* hexadecimal 0x10000 */ 19 | "val-warn-undefined-pointer-comparison": "none" 20 | } 21 | -------------------------------------------------------------------------------- /src/extlib/onig/tis-ci/test_syntax.config: -------------------------------------------------------------------------------- 1 | { 2 | "compilation_cmd": "-I ../tis-ci -I ../src -D alloca=__builtin_alloca", 3 | "files": [ 4 | "../test/test_syntax.c", 5 | "../src/unicode.c", 6 | "../src/regcomp.c", 7 | "../src/regenc.c", 8 | "../src/utf16_be.c", 9 | "../src/regparse.c", 10 | "../src/st.c", 11 | "../src/regexec.c", 12 | "../src/unicode_unfold_key.c", 13 | "../src/unicode_fold3_key.c", 14 | "../src/unicode_fold2_key.c", 15 | "../src/unicode_fold1_key.c", 16 | "../src/utf8.c", 17 | "../src/regsyntax.c", 18 | "../src/ascii.c", 19 | "../src/regversion.c" 20 | ], 21 | "machdep": "gcc_x86_64", 22 | "main": "main", 23 | "name": "test_syntax.c FULL", 24 | "address-alignment": 65536, /* hexadecimal 0x10000 */ 25 | "val-warn-undefined-pointer-comparison": "none" 26 | } 27 | -------------------------------------------------------------------------------- /src/extlib/onig/tis-ci/test_utf8.config: -------------------------------------------------------------------------------- 1 | { 2 | "compilation_cmd": "-I ../tis-ci -I ../src -D alloca=__builtin_alloca", 3 | "files": [ 4 | "../test/test_utf8.c", 5 | "../tis-ci/stub.c", 6 | "../src/regcomp.c", 7 | "../src/regenc.c", 8 | "../src/utf8.c", 9 | "../src/regexec.c", 10 | "../src/ascii.c", 11 | "../src/regparse.c", 12 | "../src/st.c", 13 | "../src/unicode.c", 14 | "../src/unicode_unfold_key.c", 15 | "../src/unicode_fold3_key.c", 16 | "../src/unicode_fold2_key.c", 17 | "../src/unicode_fold1_key.c", 18 | "../src/regversion.c" 19 | ], 20 | "machdep": "gcc_x86_64", 21 | "main": "main", 22 | "name": "test_utf8.c FULL", 23 | "address-alignment": 65536, /* hexadecimal 0x10000 */ 24 | "val-warn-undefined-pointer-comparison": "none" 25 | } 26 | -------------------------------------------------------------------------------- /src/extlib/onig/tis-ci/testc.config: -------------------------------------------------------------------------------- 1 | { 2 | "compilation_cmd": "-I ../tis-ci -I ../src -D alloca=__builtin_alloca", 3 | "files": [ 4 | "../test/testc.c", 5 | "../src/unicode.c", 6 | "../src/regcomp.c", 7 | "../src/regenc.c", 8 | "../src/utf16_be.c", 9 | "../src/regparse.c", 10 | "../src/st.c", 11 | "../src/regexec.c", 12 | "../src/unicode_unfold_key.c", 13 | "../src/unicode_fold3_key.c", 14 | "../src/unicode_fold2_key.c", 15 | "../src/unicode_fold1_key.c", 16 | "../src/euc_jp.c", 17 | "../src/euc_jp_prop.c", 18 | "../src/ascii.c", 19 | "../src/regversion.c" 20 | ], 21 | "machdep": "gcc_x86_64", 22 | "main": "main", 23 | "name": "testc.c FULL", 24 | "address-alignment": 65536, /* hexadecimal 0x10000 */ 25 | "val-warn-undefined-pointer-comparison": "none" 26 | } 27 | -------------------------------------------------------------------------------- /src/extlib/onig/tis-ci/testu.config: -------------------------------------------------------------------------------- 1 | { 2 | "compilation_cmd": "-I ../tis-ci -I ../src -D alloca=__builtin_alloca", 3 | "files": [ 4 | "../test/testu.c", 5 | "../src/unicode.c", 6 | "../src/regcomp.c", 7 | "../src/regenc.c", 8 | "../src/utf16_be.c", 9 | "../src/regparse.c", 10 | "../src/st.c", 11 | "../src/regexec.c", 12 | "../src/unicode_unfold_key.c", 13 | "../src/unicode_fold3_key.c", 14 | "../src/unicode_fold2_key.c", 15 | "../src/unicode_fold1_key.c", 16 | "../src/utf8.c", 17 | "../src/regversion.c" 18 | ], 19 | "machdep": "gcc_x86_64", 20 | "main": "main", 21 | "name": "testu.c FULL", 22 | "address-alignment": 65536, /* hexadecimal 0x10000 */ 23 | "val-warn-undefined-pointer-comparison": "none" 24 | } 25 | -------------------------------------------------------------------------------- /src/extlib/onig/windows/testc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kray-G/kinx/5f80f6e9f53c3bde8bf1532eadc99128531d09e4/src/extlib/onig/windows/testc.c -------------------------------------------------------------------------------- /src/global.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define KX_NO_INCLUDE_PARSER_TAB_H 6 | #include 7 | 8 | /* used in parsing, parsing phase is not reentrant. */ 9 | kx_lexinfo_t kx_lexinfo = {0}; 10 | kvec_t(kx_lexinfo_t) kx_lex_stack; 11 | kx_object_t *kx_obj_mgr = NULL; 12 | kx_object_t *kx_ast_root = NULL; 13 | int g_yyerror = 0; 14 | int g_yywarning = 0; 15 | kx_context_t *g_parse_ctx = NULL; 16 | khash_t(package) *g_packages = NULL; 17 | 18 | /* used in runtime. */ 19 | volatile int g_terminated = 0; 20 | kx_context_t *g_main_thread = NULL; 21 | pthread_mutex_t g_mutex; 22 | 23 | KX_DECL_MEM_ALLOCATORS(); 24 | -------------------------------------------------------------------------------- /src/ir_aotcore.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "jit/sljitLir.c" 4 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef KX_WINMAIN 4 | int WINAPI WinMain(HINSTANCE hInt, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) 5 | { 6 | int ac = __argc; 7 | char **av = __argv; 8 | #else 9 | int main(int ac, char **av) 10 | { 11 | #endif 12 | kx_malloc = malloc; 13 | kx_calloc = calloc; 14 | kx_realloc = realloc; 15 | kx_free = free; 16 | return kinx_call_main(ac, av); 17 | } 18 | -------------------------------------------------------------------------------- /src/optimizer/optimizer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void start_optimize_ast(kx_context_t *ctx, kx_object_t *node) 4 | { 5 | opt_ast_constant_folding(ctx, node); 6 | } 7 | 8 | void start_optimize_code(kx_context_t *ctx, int start) 9 | { 10 | kvec_pt(kx_code_t) *fixcode = &(ctx->fixcode); 11 | opt_code_remove_jmp(fixcode, start); 12 | opt_code_optimize_jmp(fixcode, start); 13 | } 14 | 15 | --------------------------------------------------------------------------------