Skip to content

add example and test#4

Open
mengzhuo wants to merge 22 commits into
mitalang:mainfrom
mengzhuo:main
Open

add example and test#4
mengzhuo wants to merge 22 commits into
mitalang:mainfrom
mengzhuo:main

Conversation

@mengzhuo
Copy link
Copy Markdown
Contributor

No description provided.

@mengzhuo mengzhuo requested a review from Copilot June 20, 2025 07:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a core MITA LISP implementation with examples and CI tests.

  • Implements a suite of standard list and logical functions in odomu.mita
  • Adds example files and a dedicated odomu_test suite
  • Updates Go runtime for deep equality (shato) and introduces a GitHub Actions workflow

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
odomu.mita Define core list, arithmetic, logical, and traversal functions
examples/odomu_test.mita Add test cases covering odomu.mita functions
examples/list.mita Add a list example (uses undefined lalalakukucha)
examples/lambda.mita Example for anonymous function application
examples/hello.mita Example for cons (upa)
examples/defn.mita Example for defining and calling mita functions
examples/cond.mita Example for conditional (dala)
examples/compare.mita Examples for comparison predicates (aba, unta)
examples/cdr.mita Example for kucha (cdr)
examples/car.mita Example for lawa (car)
examples/add.mita Example for celi (add)
elementary.go Remove old shato, add deep equality (equalExpr) & new shatoFunc
.github/workflows/mita-test.yml Add CI workflow to build and run odomu.mita tests
Comments suppressed due to low confidence (3)

.github/workflows/mita-test.yml:21

  • The CI workflow only runs the odomu_test suite. Consider including additional example files (e.g., examples/*.mita) to ensure broader coverage of the added examples.
        run: ./mita odomu.mita examples/odomu_test.mita 

examples/list.mita:1

  • The example calls lalalakukucha, which isn't defined in odomu.mita. Either remove this example or replace it with a valid function name.
(lalalakukucha '((1 2) (3 4) ((5 6)) (7 8))) ; => 5 

elementary.go:155

  • Avoid using the literal 4 for token type; introduce a named constant (e.g., tokenTypeNumber) to improve readability and maintainability.
		if a.sada.typ == 4 { // tokenTypeNumber

Copy link
Copy Markdown

@Jason-123-cyber Jason-123-cyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve

Copy link
Copy Markdown

@Jason-123-cyber Jason-123-cyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve

mengzhuo added 15 commits May 12, 2026 15:47
- Replace Go implementation with Rust (src/*.rs)
- Add Cargo project structure
- Port all Go tests to Rust integration tests
- Fix odomu.mita for Rust semantics:
  - not: use dala/shato instead of nyeshato
  - flatten: fix atom handling in cons detection
- Update .gitignore for Rust artifacts
- Replace static mut ELEMENTARY with std::sync::OnceLock
- Remove all unsafe blocks from codebase
- Add 27 new tests covering odomu library functions:
  cadr, caddr, cddr, list, length, map, filter, reduce,
  append, reverse, assoc, member, last, nth, and, or, not,
  equal, remove, flatten
- Add edge case tests: nil/nya equality, empty lists,
  comparison operators, div by zero, args mismatch,
  stack depth protection, undefined symbols
- Total: 38 tests (35 eval + 3 parse), all passing
Replace English library function names with Hilichurlian (丘丘语):
- cadr → lawakucha, caddr → lawakuchakucha, cddr → kuchakucha
- list → sada, length → mani, map → si, filter → valo
- reduce → mosi, append → tomo, reverse → domu
- assoc → mito, member → odomu, last → zido, nth → eleka
- and → kuzi, or → todo, not → biat
- remove → kundala, flatten → pupu
- Remove redundant equal library (shato is built-in)

Update tests, examples, README, and AGENTS.md accordingly.
Avoid shadowing pre-defined variable mani (number 5).
length now uses tiga (stone/Geo).
- let → tido (放心/安心) - local variable binding
- if → ka (...吗?/疑问) - conditional branch
- progn → in (在内) - sequential evaluation
- setq → plama (击打) - variable assignment

All 42 tests pass (39 eval + 3 parse).
New examples:
- factorial.mita: recursive factorial
- fibonacci.mita: recursive Fibonacci
- higher-order.mita: map/filter/reduce with odomu.mita
- if.mita: conditional examples with ka
- lambda.mita: anonymous function via tido
- let.mita: local binding with tido
- progn.mita: sequential evaluation with in
- quicksort.mita: quicksort with local append
- setq.mita: variable assignment with plama

Fixes:
- quicksort: add local tomo def, use numeric literals
- higher-order: use sada instead of quoted symbols
- if.mita: replace hyphens with underscores in identifiers
- lambda.mita: use tido binding instead of direct invocation
- cond.mita: fix last clause syntax
- odomu_test.mita: add dependency comment
- main.rs: EOF handling when loading files vs REPL
TCO implementation:
- Add tail_expr loop in eval() to avoid recursive eval/apply stack growth
- Track in_tail_position flag through expression evaluation
- In apply() lambda branch: when in tail position and calling self,
  replace current scope instead of pushing new one
- eval_if_tco() sets tail_expr instead of recursive eval() call
- eval_list(), eval_let(), eval_progn(), eval_setq(), eval_condition()
  save/restore in_tail_position around non-tail subexpression evals
- Fix stack_depth decrement on all function return paths

Tests:
- Add test_tail_call_optimization: verifies fak_tco(10)=3628800, fak_tco(15)
- Add test_tail_call_no_stack_overflow: countdown(500) with max_depth=100
- Update test_stack_trace: TCO truncates stack traces as expected

Benchmarks (MITA vs SBCL):
- countdown(100000): MITA 0.10s, SBCL 0.01s (~10x difference, expected for
  interpreter vs compiled native code)
- fak_tco(100000): MITA 0.13s (i64 overflow), SBCL 2.9s (bignum print)

All 44 tests pass.
- Add VM core: value types, register file, execution loop
- Add instruction set: arithmetic, comparison, branching, calls, tail calls
- Add AST-to-bytecode compiler with register allocation
- Support builtins, lambdas, conditionals, let, progn, setq, cond
- Implement tail call optimization (TCO)
- Map lambda params to X18+ to avoid arg register clobbering
- Fix nested call compilation: evaluate args before loading function
- Fix cond to use unified result register across clauses
- Add VM tests for all major features
- Add bytecode compiler documentation
- Add libloading dependency for dynamic library loading
- Implement mite builtin for calling C functions from shared libraries
- Support 0-2 i64 arguments with i64 return value
- Add library caching in VM to avoid reloading
- Fix string lexer bug: remove quotes from string token text
- Add C FFI tests with test shared library
- Update GitHub Actions: Go -> Rust, compile test C lib, run cargo test
- Remove obsolete Go workflow
- Add C FFI network library (libmita_net.so) with TCP/HTTP primitives
- Add network builtins to odomu.mita: net_listen, net_accept, net_read,
  net_get_buffer, net_write, net_close, http_parse_path, http_ok,
  http_not_found
- Add server functions: serve_once, serve, run_server
- Create web server examples: web_server.mita, web_server_test.mita,
  web_server_test2.mita
- Fix VM variadic lambda support (build cons list from arg registers)
- Fix OP_TAIL inline rewrite (builtin branch pops only current frame)
- Expand VM register file 32->64 to support complex stdlib functions
- Fix enter_closure register clearing bug (was clobbering caller regs)
- Fix web_server.mita paren balance
- Remove debug eprintln!/fprintf statements
- Update AGENTS.md with networking and recent fixes
- Add sys_string_{find,length,substr,concat,split,replace,trim} builtins
- Create http.mita with HTTP server logic (parse-request, build-response, serve-loop)
- Clean up odomu.mita to keep only generic Lisp functions and socket primitives
- Add sys_args builtin and -- CLI argument separator
- Fix OP_TAIL frame handling for builtin tail calls
- Update web_server.mita to load http.mita and use new APIs
- Register string builtins in compiler builtin_index
Added 25 new functions to the standard library:
- List predicates: null, consp, atom, listp
- List search: find, position, count
- List operations: copy_list, subseq, butlast
- Set operations: adjoin, union, intersection, set_difference
- Tree operations: subst
- Logical: every, some
- Equality: eq, eql
- Control flow: when, unless, prog1, prog2
- CAR/CDR compounds: lawakuchakuchakucha, kuchakuchakucha
- List constructors: make_list
- List accessors: elekakucha

Also added new VM builtins for math and type predicates:
- Math: mod, abs, max, min, floor, ceiling, truncate, round, expt, sqrt, random
- Type predicates: zerop, plusp, minusp, evenp, oddp, numberp, consp, atom, null

All 59 tests pass.
Added serve_once function to odomu.mita to maintain backward
compatibility with web_server_test.mita example.

All 59 tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants