Mochi Programming Language v0.7.0 – calling Python and Go in one file

4 months ago 10

Mochi v0.7.0 streamlines agent communication, extends the foreign function interface and introduces a new eval builtin. Package imports can now reference local files and directories, making it easier to organize modules.

Agents and Streams

Agents now use stream-backed mailboxes with optional waiting semantics for deterministic ordering of events.

Foreign Function Interface

Go, Python and TypeScript runtimes list available packages and provide helpers to export extern declarations. The Go FFI supports struct types and method calls.

// Demonstrates calling Go and Python code in the same file import go "strings" as strings auto import python "math" as math // Hardcoded input let rawName = " alice " let radius = 3.0 // Use Go to trim and uppercase the name let name = strings.ToUpper(strings.TrimSpace(rawName)) // Use Python to compute circle area let area = math.pi * math.pow(radius, 2.0) // Output the result print("Hello", name + "!") print("The area of a circle with radius", radius, "is", area)

Builtins

An eval function evaluates a string of Mochi code at runtime.

// Evaluate a math expression using generate text with structured prompt import go "strings" as strings auto let raw = " 12 * (3 + 2) " let query = strings.TrimSpace(raw) // Use structured generate text let result = generate text { prompt: "You are a calculator. Return the answer to this expression:\n" + query } print("Query:", query) print("Result:", result)

Output:

Query: 12 * (3 + 2) Result: Here's how to solve the expression: 1. **Parentheses first:** 3 + 2 = 5 2. **Multiplication:** 12 * 5 = 60 **Answer: 60**

Package Imports

Relative paths starting with ./ or ../ can import local modules from single files or directories.

Changelog

  • ec8143c Add Deno FFI inference test
  • f450238 Add Deno FFI runtime and TS import support
  • 9413eb0 Add Deno math example
  • 9c4e7c8 Add DuckDB stub for non-cgo builds
  • 72c8a29 Add GenMochi generator and tests
  • 3717439 Add Go FFI runtime
  • 89fdf9f Add JSONL loader and load-with options
  • b8031fd Add Jupyter cell magic
  • f360311 Add LeetCode 11 solution in Mochi
  • 86b81e1 Add LeetCode solving agent
  • 434e706 Add Python FFI support to interpreter
  • 7564bf5 Add Python Polars example
  • 1106452 Add Two Sum example and tests
  • 915579f Add TypeScript FFI runtime
  • fc24d10 Add TypeScript import support
  • d45ccc8 Add TypeScript library to execute Mochi
  • 4f0090a Add WebAssembly build
  • 6b140d7 Add agent stream example
  • d255a55 Add basic agent runtime and interpreter integration
  • c0dc765 Add basic logical and physical plan scaffolding
  • 9e95629 Add cheatsheet command
  • 888016b Add coverage tests for llm helpers
  • ed64029 Add data runtime library
  • 58e92be Add dataset sort/skip/take query support
  • 176d572 Add dataset support to TypeScript compiler
  • 9f5a666 Add doc comments in go infer output
  • a724d83 Add eval example
  • 4b5d466 Add example mix go and python
  • 276c4ba Add group by query support
  • d00aa0a Add infer tests for python FFI
  • c3cf6bc Add inferred strings package
  • c05db8c Add integration test for FFI inference
  • b51c9e9 Add interpreter error golden tests
  • 8dcc33a Add join interpreter tests
  • 6a92fdf Add join query test for Python compiler
  • 1634105 Add join type checking and tests
  • e180ed5 Add json tags to infer structs
  • 05cdeab Add left join feature
  • 4d2c153 Add load expression with CSV support
  • 642007e Add memoization for pure calls in Go compiler
  • 9687ec5 Add module manager and update interpreter
  • 8cff754 Add package and export support
  • 7928454 Add parser golden test for cross join triple
  • 58b7be0 Add query comprehension example and interpreter support
  • 96cd98a Add real Python stdlib inference test
  • 0ec3c33 Add solution for LeetCode 2
  • 82ec9d0 Add solution for LeetCode 3442
  • 2d0a4a3 Add stdin/stdout support for load/save
  • 5431d5c Add string indexing example and support
  • 59aca0b Add strings_trim.mochi example
  • ba3db32 Add test for inference of standard library
  • c16e5dd Add toolchain option for wasm compiler
  • b1e8312 Add union operator for lists
  • a85afe2 Add waitable streams
  • 4e97f26 Add while loop support to compilers
  • d8fda35 Adjust test expectations
  • cc0e637 Cleanup README and SPEC
  • 3237a40 Expand Infer tests
  • de9f08a Fix TypeScript inference and tests
  • 294f0a3 Fix TypeScript package import function declarations
  • a2ce3b8 Fix auto FFI implementation
  • 4cdfdd0 Fix build without DuckDB
  • da06494 Fix docs example and update hello-mochi modules
  • 49550be Fix failing matrix example test
  • c667958 Fix golden outputs for generate helpers
  • be0a869 Fix race condition
  • 6892c65 Implement 'in' operator for string containment
  • 0aaa4f5 Implement runtime/agent
  • 8e627bf Merge pull request #170 from mochilang/mochilang/runtime/agent
  • c8ea710 Merge pull request #171 from mochilang/codex/integrate-agent-with-interpreter-and-ensure-correctness
  • c0b1d56 Merge pull request #172 from mochilang/codex/move-agent.mochi-and-add-golden-tests
  • 2d04025 Merge pull request #173 from mochilang/codex/update-go-compiler-to-support-agent
  • fd10118 Merge pull request #174 from mochilang/codex/update-python-compiler-for-agent-support
  • df026cf Merge pull request #175 from mochilang/codex/update-mochi-to-support-agent-block
  • a0866af Merge pull request #176 from mochilang/codex/update-golden-tests-for-compiler
  • 06725af Merge pull request #177 from mochilang/codex/update-documentation-for-new-agent-support
  • eb651d0 Merge pull request #178 from mochilang/codex/update-golden-tests-for-agents
  • edd1a7c Merge pull request #179 from mochilang/c60kjx-codex/update-golden-tests-for-agents
  • b40f244 Merge pull request #180 from mochilang/codex/implement-two-sum-solution-in-mochi
  • 0453e8c Merge pull request #181 from mochilang/codex/extend-mochi-to-support-while-statement
  • 2c566eb Merge pull request #182 from mochilang/codex/save-example-and-extend-mochi-for-string-iteration
  • 9b3c7f7 Merge pull request #183 from mochilang/codex/update-string.mochi-and-enhance-parser
  • 689c3f1 Merge pull request #184 from mochilang/codex/update-documentation-for-new-iterator-and-index-operator
  • 8998461 Merge pull request #185 from mochilang/codex/implement-solution-for-container-with-most-water
  • d406cf8 Merge pull request #186 from mochilang/codex/update-go-compiler-for-string-index-and-iterator
  • 128c760 Merge pull request #191 from mochilang/03y5p1-codex/update-python-compiler-for-string-index
  • 8236e57 Merge pull request #192 from mochilang/codex/update-readme-and-docs-for-while-statement
  • 60e96ae Merge pull request #193 from mochilang/famf5e-codex/implement-solution-for-longest-repeating-character-replaceme
  • 0a96467 Merge pull request #194 from mochilang/codex/update-typescript-compiler-settings
  • c1727b4 Merge pull request #195 from mochilang/codex/extend-go,-typescript,-python-to-support-while-statement
  • 84df934 Merge pull request #196 from mochilang/codex/write-release-notes-and-changelog-for-v0.5.0
  • 1a5ae44 Merge pull request #197 from mochilang/codex/review-and-expand-docs-folder-documents
  • a0b3416 Merge pull request #198 from mochilang/codex/review-errors.go-and-add-golden-tests
  • 1f3a015 Merge pull request #199 from mochilang/codex/review-errors.go-and-add-golden-tests
  • 61886db Merge pull request #200 from mochilang/codex/refactor-streamfield-to-typeref
  • 91a8ebf Merge pull request #201 from mochilang/codex/remove-unnecessary-golden-tests-and-error-handling
  • b612339 Merge pull request #202 from mochilang/codex/update-spec.md-with-missing-details
  • 2417f25 Merge pull request #203 from mochilang/codex/enhance-missing-features-in-go-compiler
  • 4631cb6 Merge pull request #204 from mochilang/codex/enhance-python-compiler-based-on-parser.go
  • 7218024 Merge pull request #205 from mochilang/codex/enhance-typescript-compiler-based-on-parser.go
  • a980797 Merge pull request #206 from mochilang/codex/enhance-compiler-to-exclude-async-when-no-stream-code
  • d319950 Merge pull request #207 from mochilang/codex/review-go-compiler-type-inference
  • 414e35e Merge pull request #208 from mochilang/codex/improve-type-inference-in-compilers
  • 1956af6 Merge pull request #210 from mochilang/codex/enhance-type-infer-to-remove-helperslice
  • f086bd8 Merge pull request #211 from mochilang/codex/implement-purity-check-and-compile-time-optimization
  • 70d1706 Merge pull request #212 from mochilang/ztgiok-codex/run-benchmark-and-check-output
  • b9db619 Merge pull request #214 from mochilang/codex/enhance-interpreter-with-purity-check
  • 74a89e5 Merge pull request #215 from mochilang/codex/enhance-go-compiler-with-purity-check
  • 887ecee Merge pull request #216 from mochilang/ed27u9-codex/run-benchmark-and-check-output
  • 1ef6ac1 Merge pull request #217 from mochilang/codex/enhance-argskey-for-memorization
  • 9d57688 Merge pull request #218 from mochilang/codex/update-golden-tests-for-go-compiler
  • 410870d Merge pull request #219 from mochilang/codex/add-memorization-option-in-interpreter
  • af3ee68 Merge pull request #220 from mochilang/codex/add-cheatsheet-command-to-mochi-binary
  • 92f59d6 Merge pull request #222 from mochilang/codex/apply-aot-in-interpreter-and-benchmark
  • 4af9a01 Merge pull request #223 from mochilang/bbbnga-codex/write-golden-tests-for-go-compiler-folding
  • ea797d4 Merge pull request #224 from mochilang/codex/apply-fold-let-logic-to-interpreter
  • d679e63 Merge pull request #225 from mochilang/codex/update-readme-and-docs-for-mochi-cheatsheet-command
  • 631b9f5 Merge pull request #226 from mochilang/codex/enhance-typescript-annotations-for-tests
  • bf5012b Merge pull request #227 from mochilang/codex/enhance-python-compiler-with-typehint
  • 125c1e8 Merge pull request #228 from mochilang/codex/enhance-typescript-compiler-with-type-annotator
  • 0e95cbe Merge pull request #247 from mochilang/codex/save-and-run-agent-stream-example
  • d8157f9 Merge pull request #248 from mochilang/codex/update-mochi-cheatsheet.mochi
  • 47bc3d9 Merge pull request #250 from mochilang/codex/update-documentation-to-latest-version
  • 57af018 Merge pull request #251 from mochilang/codex/write-release-notes-for-version-0.5.1
  • 05f07c4 Merge pull request #252 from mochilang/codex/implement-runtime/vector-with-flat-index-and-tests
  • 53c627f Move agent example to v0.5 and add parser golden tests
  • 8966845 Move test file and fix LeetCode example
  • a8e9a34 Refactor query handling and rename data package
  • ac38938 Remove embedded wasm and build on demand
  • ba4db77 Remove golden tests for character replacement
  • 2bf95f8 Remove sleep builtin and references
  • 3dcd926 Remove unused cast var
  • 7b9b5c9 Remove unused datav1 runtime package
  • f981739 Rename global transaction field
  • b519ae3 Support local file imports
  • c6a5609 Update README for libmochi
  • 6a251be Update compiler golden outputs
  • bb5da54 Update fold constant folding test with sum function
  • fdea2fb Update golden tests with new Go compiler
  • 9c42ec1 Update syntax files
  • 60f28a4 Use stream-based mailbox for agents
  • 8af3e4c add golden test for multi-file package
  • 9c821b9 build: add TinyGo WASM setup
  • 42dc2ae chore: add save parser tests
  • 6961b18 chore: remove unused loader interface
  • a05c968 chore: remove unused ts ffi interfaces
  • 2d09ecd chore: update benchmark results
  • 9efcb3b chore: update benchmarks
  • d97b485 ci: install deno for tests
  • 0e71f9e cleanup and add golden test
  • 87c1e3d cleanup python ffi
  • 8fcfc23 compiler: add join support
  • 52a54a0 compiler: fix query var names
  • 33427b1 compiler: inline indexing for typed collections
  • c1fcc44 compiler: inline slice for typed collections
  • 478362f compiler: skip async wait when no streams
  • b31a8e2 doc: document list union operators
  • ab9cd2c enhance go ffi inference
  • 4aa02c7 examples+interpreter: add extern object check
  • a631416 examples: add package example
  • 5865636 feat(cli): add infer command
  • 60007d8 feat(cli): add init and get commands
  • 35a0e36 feat(cli): add llm command
  • 31b65e7 feat(compile): add jvm backend via gomobile
  • 60c5d89 feat(deno): add module inference
  • 22c23bf feat(go): handle string indexing and iteration
  • ba9df90 feat(infer): include docs in extern output
  • a371c69 feat(interpreter): fold let constants
  • 65c8ef6 feat(interpreter): memoize pure function calls
  • 45ce2a0 feat(interpreter): type cast stream events
  • 9e2e4e1 feat(py): add agent support
  • 0afb7b1 feat(py): add dataset load/save
  • 49734df feat(py): add dataset query support
  • f50a68c feat(py): add join helper
  • ba684ec feat(py): add type hints in python compiler
  • 4193455 feat(py): support ffi imports
  • 2b35e52 feat(py): support string index and iteration
  • e8919f8 feat(python): add module inference
  • 18144f9 feat(runtime): add python ffi
  • af5834c feat(ts ffi): list available packages
  • fb87691 feat(ts): add dataset load/save
  • d8d07e1 feat(ts): add type annotations to functions
  • 22db442 feat(ts): annotate variable declarations
  • 180bdf1 feat(ts): support string indexing and iteration
  • 908471d feat: add AOT folding option
  • d0bce7e feat: add Go FFI integration
  • 75bc752 feat: add Go package export helpers
  • 4ab0d6d feat: add except set difference
  • c1ae502 feat: add extern printer
  • 2a6fed6 feat: add full outer join
  • ac93862 feat: add in-memory data driver
  • e66ed13 feat: add intersect set operation
  • 1dac97c feat: add join support
  • 21b9776 feat: add right join support
  • 43b1ecd feat: add sort/skip/take to query compilers
  • 929615e feat: add union all operator
  • da7e4c5 feat: add wasm compiler
  • 64993bc feat: add while statement
  • 7cceb0f feat: default alias for imports
  • a28145c feat: support cross join in queries
  • 5f37b63 ffi/go: implement package inference
  • f924a6a fix agent stream ordering and local import test
  • c32e4c3 fix diagnostic help placeholders
  • 992f7fa fix examples
  • cb79115 fix examples and enforce naming
  • 5d29848 fix ts compiler remote import test
  • 05192be go compiler: add agent support
  • acf40ca go compiler: add cast support
  • 5cad8e3 go compiler: add dataset query support and tests
  • 65348a2 go compiler: add ffi and extern support
  • 2608562 go compiler: specialize string index helper
  • 6981455 go: add basic left join support
  • 6984ab8 go: add dataset load and save support
  • 862897c go: add join helper and detection
  • 1bee317 go: improve type inference for function calls
  • 3c68792 goffi: add package listing
  • 005d618 goffi: add plugin loader
  • 755e93f goffi: support struct types and method calls
  • 2b93788 improve argsKey memoization
  • 16efcf2 improve python compiler type inference
  • 07e4f81 interpreter: add optional memoization
  • 5f7737b interpreter: improve extern object error
  • bb3a0a2 parser+interpreter: add extern declarations
  • 55b0686 parser+runtime: add extern object handling
  • 854dc7b parser: add dataset query features and tests
  • 557fb47 parser: add dataset query syntax
  • 64f23d8 parser: add join clause support
  • d054bf8 parser: capture doc comments
  • c32f950 py compiler: support model declarations and ignore cast
  • 15dc61e py compiler: support package imports
  • 8e173c2 python ffi: add Attr for dynamic access
  • 58248e4 python ffi: add export helpers
  • 800d2ca python ffi: list installed packages
  • 949c2c4 python: add ffi eval helper
  • a2888c5 refactor ffi runtimes
  • cb57b34 refactor interpreter loops
  • 2b53087 refactor interpreter operations
  • d6522a8 refactor type checker builtins
  • a9604b4 refactor(go): simplify compiler
  • ac6f2bd refactor(py): move runtime helpers to separate file
  • 2d24753 refactor(runtime): execute queries via plan
  • c0f929a refactor(ts): move runtime helpers to separate file
  • 0027643 refactor: modularize interpreter
  • 1c2fbb2 refactor: move FFI logic into runtime package
  • f98a82a refactor: move dataset helpers to runtime
  • 7de3300 refactor: move pure call eval to interpreter
  • f6abcbb refactor: move query eval to runtime/data
  • beb893a refactor: move runtime helpers
  • 642e4ae refactor: replace ts import keyword
  • 68be266 refactor: split compiler helpers
  • e22878c refactor: split python compiler
  • 12928b4 release: v0.5.0
  • fe995f0 release: v0.5.1
  • 999573b release: v0.6.0
  • eedb295 release: v0.6.1
  • f2c2354 release: v0.6.2
  • 3a78753 release: v0.6.3
  • 748df48 release: v0.7.0
  • a31570d runtime/data: remove unused query code
  • 3a30a51 runtime/goffi: remove unused plugin loader
  • 8c547e7 runtime/pythonffi: inline run logic
  • a3da8c4 runtime/vector: add vector index implementation
  • e6e3080 runtime: add JSON and YAML dataset support
  • fb86741 runtime: enhance ts ffi with reflection and tests
  • e737375 runtime: introduce extern Registry
  • 8c58295 test(deno): add inference test for std module
  • 5472078 test(types): add missing error golden tests
  • b08c0bd tests: add agent golden cases
  • a9bcb36 tests: add agent golden cases
  • c7c6284 tests: fix newline
  • d180b57 tools: add libmochi go helpers
  • 93a92a6 ts compiler: add agent block support
  • 6874432 ts compiler: add join helper
  • b6294ea ts compiler: improve type inference for selectors
  • 2cbb3ae ts compiler: support tests and expect
  • 62485c7 types: handle queryExpr in dataset type checks
  • f9ad084 types: remove unused equality error and dead code
  • 8e57433 types: validate query source is list
Read Entire Article