q

command module
v0.0.0-...-67fbc49 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 2 Imported by: 0

README

q

Godoc Report Tests Coverage Sponsor

This is a very early version of a programming language I'm currently working on.

Installation

git clone https://github.com/akyoto/q
cd q
go build

This will produce the q compiler in your current directory.

./q build examples/hello
./examples/hello/hello

Features

  • Fast compilation (<1 ms for simple programs)
  • Small binaries ("Hello World" is 247 bytes)
  • High performance (compete with C and Rust)

Todo

Compiler
  • Tokenizer
  • Scanner
  • Parallel function compiler
  • Error messages
  • Expression parser
  • Function calls
  • Infinite loop
  • Simple for loops
  • Simple if conditions
  • Syscalls
  • Detect pure functions
  • Immutable variables
  • Mutable variables via mut
  • Variable lifetime tracking
  • return values
  • import standard packages
  • expect for input validation
  • ensure for output validation
  • Data structures
  • Heap allocation
  • Type system
  • Type operator: | (User | Error)
  • Stack allocation
  • Hexadecimal, octal and binary literals
  • match keyword
  • import external packages
  • Error handling
  • Cyclic function calls
  • Multi-threading
  • Lock-free data structures
  • Multiple return values
  • Rewrite compiler in Q
  • ...
Optimizations
  • Exclude unused functions
  • Function call inlining
  • Assembly optimization backend
  • Disable contracts via -O flag
  • Expression optimization
  • Loop unrolls
  • ...
Linter
  • Unused variables
  • Unused parameters
  • Unused imports
  • Unmodified mutable variables
  • Unnecessary newlines
  • Ineffective assignments
  • ...
Operators
  • +, -, *, /
  • ==, !=, <, <=, >, >=
  • =
  • +=, -=, *=, /=
  • &=, |=
  • <<=, >>=
  • <<, >>
  • &&, ||
  • &, |
  • %
  • ...
Architecture
  • x86-64
  • WASM
  • ARM
  • ...
Platform
  • Linux
  • Mac
  • Windows
  • ...

Goals

  • No binary dependencies (not even libc)
  • No compiler dependencies (no LLVM, no GCC, ...)
  • No global state (all mutable variables are local)
  • No side effects when importing a package
  • No name shadowing, names never change their meaning
  • No complicated classes, just simple data structures
  • Type system (reduce bugs at compile time)
  • Linters (reduce bugs at compile time)
  • Tests (reduce bugs at test time)
  • Contracts (reduce bugs at run time)
  • Simple dependency management
  • Auto-formatter for source code
  • User-friendly compiler messages

FAQ

How do I navigate the source code?
  • benchmarks contains benchmarks for compilation speed
  • build contains the actual compiler source
  • cli contains the command line interface
  • examples contains a few examples that are also used in tests
  • lib contains the standard library
How do I view the produced assembly output?
q build -a
q build --assembly
How can I make a performance optimized build?
q build -O
q build --optimize

This will disable all expect and ensure checks.

How can I see where my compilation time is spent on?
q build -t
q build --time
How do I install it system-wide?
sudo ln -s $PWD/q /usr/local/bin/q
How can I include information about my system in bug reports?
q system

The output should look like this:

Platform:          linux
Architecture:      amd64
Go version:        go1.13.5
Working directory: /home/eduard/projects/akyoto/q
Compiler path:     /home/eduard/projects/akyoto/q/q
Standard library:  /home/eduard/projects/akyoto/q/lib
Last modified:     2019-12-27 11:06:47.841459978 +0900 KST
CPU:               Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
CPU threads:       12
Which editor can I use to edit Q code?

There is a simple VS Code extension with syntax highlighting.

git clone https://github.com/akyoto/vscode-q ~/.vscode/extensions/vscode-q
Is the syntax final?

Unlikely. There will be changes in the near future.

Which builtin functions are available?

There are currently 2 builtin functions, syscall and print. In the future we'd like to remove print so that syscall becomes the only builtin function.

How do I run the tests?
go test -coverpkg=./...
How do I run the benchmarks?
go test -bench=. ./benchmarks

Style

Please take a look at the style guidelines if you'd like to make a pull request.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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