nxlang

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2026 License: MIT

README ΒΆ

Nxlang (Efficiency Language)

A lightweight, Go-based scripting language with Go-like syntax, bytecode virtual machine, and cross-platform support.

Go Report Card Go Version

δΈ­ζ–‡η‰ˆζœ¬

✨ Core Features

  • Familiar Syntax: Go-like syntax design, low learning curve, seamless adaptation for Go developers
  • Weak Type System: Automatic type conversion, flexible and efficient coding, reduces redundant type declarations
  • Bytecode Execution: Compiles to platform-agnostic bytecode (.nxb), runs faster than traditional interpreted languages
  • Built-in REPL: Interactive command line with syntax highlighting for quick debugging and prototyping
  • Integrated Editor: Built-in code editor, write and run scripts without additional tools
  • Rich Standard Library: Built-in support for concurrency, HTTP, file I/O, data processing, graphics, and more
  • Cross-Platform Support: Runs perfectly on Windows, Linux, macOS with no external dependencies
  • Module System: Supports module import/export with consistent function references, suitable for large project development
  • Native UTF-8: Full stack UTF-8 support, strings and files use UTF-8 encoding by default
  • High Performance: Built on Go, runtime performance far exceeds dynamic languages like Python/JavaScript

πŸš€ Quick Start

Installation

Download prebuilt binaries from Releases or build from source.

Run REPL (Interactive Mode)
nx
Execute a Script
nx path/to/script.nx
Compile to Bytecode
nx compile path/to/script.nx -o output.nxb
Run Precompiled Bytecode
nx run output.nxb

πŸ“ Example Code

// Hello World
pln("Hello, Nxlang! πŸ‘‹")

// Function definition
func factorial(n) {
    if n <= 1 { return 1 }
    return n * factorial(n - 1)
}

pln("Factorial of 10:", factorial(10))

// Module import
import { sqrt, random } from "math"
pln("sqrt(25) =", sqrt(25))
pln("Random number:", random())

// Built-in data structures
var fruits = array("Apple", "Banana", "Cherry")
var person = map("name", "Bob", "age", 28, "city", "Shanghai")

// Static methods on types
let num = int.parse("123")
let pi = float.parse("3.14159")

// Self-growing sequence
var seq1 = seq(1, 2, 3)
seq1[5] = 100  // Auto-grows sequence

// Object reference
var x = 100
var r = ref(x)
setref(r, 200)

// Control flow
for (var i = 0; i < 5; i++) {
    pln("Count:", i)
}

πŸ“¦ Standard Library

πŸ“¦ Standard Library

Math Functions

abs, sqrt, sin, cos, tan, floor, ceil, round, pow, random

String Functions

len, toUpper, toLower, trim, split, join, contains, replace, substr, startsWith, endsWith

Collection Functions

array, append, map, orderedMap, stack, queue, seq, keys, values, delete, sortMap, reverseMap

Type Conversion Functions

int, float, bool, string, byte, uint, char, bytes, chars

  • Static methods: int.parse(), float.parse(), string.parse(), bool.parse()
Object Reference Functions

ref(), deref(), setref() - Object reference and dereference support

Seq Type (Self-growing Sequence)

seq() - Create self-growing sequence with auto-expanding index access

  • Methods: Append(), Pop(), Clear(), Resize(), Fill(), Range(), Reverse(), Join(), Includes(), IndexOf(), Get(), Set()
Time Functions

now(), unix(), unixMilli(), formatTime(timestamp, format), parseTime(timeStr, format), sleep(seconds)

JSON Functions

toJson(value, indent=false) - Convert value to JSON string

Concurrency Functions

thread(func) - Spawn a new thread running the given function mutex() - Create a mutual exclusion lock rwMutex() - Create a read-write mutex waitForThreads - Wait for all threads to complete

I/O Functions

pln(...) - Print values with newline pr(...) - Print values without newline printf(format, ...) - Print formatted string readFile(filename), writeFile(filename, content) - File I/O

HTTP Functions

httpGet(url), httpPost(url, body), httpPostJSON(url, data), httpPut(url, body), httpDelete(url), httpRequest(method, url, body, headers)

  • Returns httpResponse object with fields: statusCode, body, headers
Graphics/Canvas Functions

canvas(width, height), clear(canvas, r, g, b, a), drawPoint(canvas, x, y, r, g, b, a) drawLine(canvas, x0, y0, x1, y1, r, g, b, a), drawCircle(canvas, cx, cy, radius, r, g, b, a) fillCircle(canvas, cx, cy, radius, r, g, b, a), drawRectangle(canvas, x, y, w, h, r, g, b, a) fillRectangle(canvas, x, y, w, h, r, g, b, a), getPixel(canvas, x, y) savePNG(canvas, filename), loadPNG(filename)

Data/CSV Functions

readCSV(filename), writeCSV(filename, data, headers), parseCSV(csvString), toCSV(data) openCSV(filename, hasHeader), readCSVRow(reader), readCSVAll(reader), closeCSV(reader) createCSVWriter(filename), writeCSVRow(writer, row), closeCSV(writer)

Plugin System

loadPlugin(path), unloadPlugin(name), callPlugin(pluginName, funcName, args...), listPlugins()

  • Load Go-based plugins and call plugin functions from Nxlang code

πŸ—οΈ Build from Source

# Clone repository
git clone https://github.com/topxeq/nxlang.git
cd nxlang

# Build binary
go build -o nx ./cmd/nx

# Install to system (Linux/macOS)
sudo mv nx /usr/local/bin/

πŸ§ͺ Running Tests

# Run all tests
go test ./...

# Run specific package tests
go test ./vm -v

πŸ›οΈ Architecture

Nxlang follows a standard compiler-VM architecture:

  1. Lexer: Converts source code to token stream
  2. Parser: Builds Abstract Syntax Tree (AST) from tokens
  3. Compiler: Transforms AST into platform-agnostic bytecode (.nxb)
  4. Virtual Machine: Executes bytecode with stack-based evaluation
  5. Standard Library: Built-in functions and types implemented in Go
  6. Plugin System: Go-based plugins for extensibility
Project Structure
nxlang/
β”œβ”€β”€ cmd/nx/          # CLI entry point
β”œβ”€β”€ compiler/        # Bytecode compiler
β”œβ”€β”€ parser/          # Source code parser
β”œβ”€β”€ vm/              # Virtual machine
β”œβ”€β”€ types/           # Type system (Object interface)
β”œβ”€β”€ plugin/          # Plugin system
β”œβ”€β”€ graphics/        # Graphics/canvas support
β”œβ”€β”€ data/            # Data processing (CSV, etc.)
β”œβ”€β”€ tests/           # Test suites
β”‚   β”œβ”€β”€ builtin/     # Built-in function tests
β”‚   β”œβ”€β”€ features/    # Feature tests (OOP, refs, etc.)
β”‚   β”œβ”€β”€ stdlib/      # Standard library tests
β”‚   └── integration/ # Integration tests
└── examples/        # Example scripts

πŸ“„ License

MIT License - see LICENSE for details.


Made with ❀️ by TopXeQ

Directories ΒΆ

Path Synopsis
cmd
nx command
Package data provides data processing capabilities for Nxlang including CSV and Excel file handling
Package data provides data processing capabilities for Nxlang including CSV and Excel file handling
Package graphics provides image processing and graphics capabilities for Nxlang
Package graphics provides image processing and graphics capabilities for Nxlang
Package plugin provides plugin system for Nxlang Plugins are Go-based extensions that can be loaded into the Nxlang VM
Package plugin provides plugin system for Nxlang Plugins are Go-based extensions that can be loaded into the Nxlang VM
pluginhelper
Package pluginhelper provides helper functions for creating Nxlang plugins Plugin developers can use this package to simplify plugin development
Package pluginhelper provides helper functions for creating Nxlang plugins Plugin developers can use this package to simplify plugin development
plugins
example_plugin command
Example plugin for Nxlang Build this plugin with: go build -buildmode=plugin -o example.nxp plugins/example_plugin/main.go
Example plugin for Nxlang Build this plugin with: go build -buildmode=plugin -o example.nxp plugins/example_plugin/main.go
Package types defines the core type system and Object interface for Nxlang
Package types defines the core type system and Object interface for Nxlang

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL