Skip to content

Instantly share code, notes, and snippets.

@natescode
Last active September 25, 2019 18:33
Show Gist options
  • Save natescode/36ca23f74441701ce378e1a552fd7f5e to your computer and use it in GitHub Desktop.
Save natescode/36ca23f74441701ce378e1a552fd7f5e to your computer and use it in GitHub Desktop.
Silicon / Sigil Language Definition

Si

Comments

// Single Line

/*
    Multi-Line

    Comment
*/

Keywords

@package Main

@if @true {
    // ...code...
}

Variables

// Let is for constants
// Strings are immutable unless you use 
@let name @str : "John"    
@let name : "John"
$name : "John"

@let age @num : 28
@let age : 18
$age : 18


$$MAX : 10

Sigils

@ - Keywords

@@ - Annotations

$ - Let Declaration

$$ - Var Declaration

^ - Nominal Type prefix

~ - Structural Type prefix

! - Mutable variable or method suffix Like convention in Ruby except this is enforced by the compiler.

// Mutable string
@str! 

// Method mutates passed data. Compiler enforces that at least one parameter is passed by reference and modified for functions and that at least a field or property is modified for methods.
#Reverse! arr

# - Method Call prefix

#Add 1,3

_ - Placeholder

[0:_]

@for ;_ < 10; {

}

a, _ : #GetTwoValues

? - Optional suffix (Like Nullable)

@num?

@let Div? $a $b : $b = 0 ? @nil : $a / $b 

Types

Silicon / Sigil is a strongly statically typed language with a very strong but flexible type system. You'll rarely see types explicitly declared as the compiler does type inference (but not auto conversion).

Silicon uses type hierarchies / unions to simplify the type system (making it run as an interpreted language quiet well too).

@num - signed integer Union of int(8|16|32|64|128) and float(32|64|128). Unlike C unions only the memory size of the used type. Generic Union or Dynamic Union. Like how we can declare an array of arbitrary size.

@nat - natural number uint(8|16|32|64|128)

@str - immutable string supports Unicode

@str! - mutable string supports Unicode

@bool - boolean @true | @false. Alias for @Bits(1).

@char - UTF-8 /16 and Unicode support. Alias for uint8 / uint16 but with different Nominal type which then has different methods / operators associated with it as well.

@bits - An arbitrarily sized continuous block of bits (Like Cell in Scheme)

Keywords

All keywords are prepended with the @ sigil.

Loop keywords

when inside loops there are some keywords that are just syntatical sugar for commonly used statements.

for $i range arr { ##Print arr[i+1]
// ^ could be written as the following ##Print $$next }

@next -> arr[i+1] @previous -> arr[i-1] @first -> arr[0] @last -> arr[len(arr)-1]

@natescode
Copy link
Author

What lang is that?

It is a language that I'm designing and building a compiler and VM for. The working name is Silicon or Si (like the symbol in the periodic table of elements). It is inspired by Golang, OCaml and several other languages.

@darilrt
Copy link

darilrt commented Sep 22, 2019

im design my own lang too, what's the purpose of Silicon

@natescode
Copy link
Author

natescode commented Sep 23, 2019

im design my own lang too, what's the purpose of Silicon

Silicon is intended to be very similar to Golang in concept but more focused on app programming (front-end + UI) as opposed to systems development. It'll also have some functional programming aspects so it'll be multi-paradigm like ReasonML / OCaml. Its goals are to be simple, minimal, clean and cross-platform. It'll target JavaScript / WASM as well.

The first bit was written in Golang but I'm writing the compiler in Reason (OCaml) now.

What are the goals for your language? What are you writing your compiler / interpreter in?

@darilrt
Copy link

darilrt commented Sep 23, 2019

The goals for my lang are, make the c programming more readable, i use the python syntax and compile to c, is like statically typed python but add enum, switch, pointers, memory allocations, templates. For c add class, methods, package structures, auto type detection like go-lang :=, lambdas, for eachs, and more features of others langs.

The first version of compiler is writted in python, haven't finished it yet.
Then i will write in slex (is the name of my lang)

Currently the lang compile but lack features.

I have simple document about syntax: Slex doc

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