Skip to content

onion-lang/onion

Repository files navigation

Onion - A Statically Typed Programming Language on JVM Build Status

Onion is an object-oriented and statically typed programming language. Source codes of Onion compiles into JVM class files as in-memory or real files.

Originally, Onion was written in Java. It has been rewritten in Scala completely except Parser, using JavaCC.

Language Snapshot

Local val / var declarations can omit types when an initializer is present, and control-flow constructs such as if are expressions.

val name = "Onion"
val label = if name.length > 0 { "ok" } else { "empty" }

def add(x: Int, y: Int): Int = x + y

val double: Int -> Int = (x) -> { return x * 2; }
val inc = (x: Int) -> { return x + 1; }
IO::println(double(21))

Architecture

The compiler parses source code into an untyped AST and then performs type checking to produce a typed AST. The old intermediate representation (IRT) has been folded into this typed tree. Code generation now runs on the typed AST via a thin compatibility layer using ASM.

Tools

onionc

Usage

onionc [options] source files...

Available options:

  • -classpath Set classpath of source files in compilation.
  • -encoding Set encoding of source files.
  • -d Set output directory of results.
  • -maxErrorReports Set the maximum number of comiplation errors reported.
  • --dump-ast Print parsed AST to stderr.
  • --dump-typed-ast Print typed AST summary to stderr.
  • --warn <off|on|error> Set warning level.
  • --Wno Suppress warnings (e.g., W0001,unused-parameter).

onionc compiles source files into class files in the directorys corresponding to module names of source files rooted by "-d" option. If "-d" is not specified, the value of "-d" is specified as the current directory.

For example, if source files which module name is "org.onion_lang" is compiled, class files are generated under:

  • Unix-like OS : org/onion_lang
  • Windows: org\onion_lang

onion

Usage

    onion [options] source files... [command line arguments]

Available options

  • -classpath classpath of source files in compilation.
  • -encoding encoding of source files.
  • -maxErrorReports the maximum number of comiplation errors reported.
  • --dump-ast Print parsed AST to stderr.
  • --dump-typed-ast Print typed AST summary to stderr.
  • --warn <off|on|error> Set warning level.
  • --Wno Suppress warnings (e.g., W0001,unused-parameter).

onion compiles source files into in-memory class files and execute them. The entry point is:

  1. A main method if there is an explicit class definition and it have the main method.
  2. The main method of the class on the top.
  3. Otherwise, the first statement on the top.

Limitations

  • The compiler still has edge cases and can crash; please report minimal repros.
  • Generics are erasure-based (no variance, wildcards, or reified type info).
  • Diagnostics are still improving; some errors may be reported later in the pipeline.

BuildHive (Jenkins)

This software includes softwares developed by Apache Software Foundation.

About

Onion - statically typed object-oriented programming language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages