You are on page 1of 34

ooc

The Quest for the Holy Grail

OSDC.fr 2010 ooc-lang.org Amos Wenger


Roadmap
I. The origins
II. The best of both worlds
III. Syntactic sweets
IV. Rocking out
V. The legacy
VI. Agora

OSDC.fr 2010 ooc-lang.org Amos Wenger


The Original Sin
● After years of self-teaching
➔ The Games Factory/MultiMedia Fusion
➔ C++/OpenGL/SDL
➔ Java/Xith3D/JOODE
● Back to the real world
➔ A C school project
➔ Deadline: 6 months
➔ No object-orientation in sight

I. The origins ooc-lang.org


The fool who challenged the gods
● A dead-end idea
➔ Java-derived syntax
➔ No structure
➔ ...instead of working on the actual project
● MOD (Miracle-Oriented Development)
➔ Naive « translator »
➔ No error checking
➔ Bug-ridden

I. The origins ooc-lang.org


The first-born
● ooc 0.1
➔ Written in Java, 11K SLOC
➔ Generates C code
➔ Handed in along with the real project
➔ « Real » project developed in a few days
➔ Success!

« Version 1.0 sucks, but ship it anyway »


Jeff Atwood (CodingHorror)

I. The origins ooc-lang.org


A curious alchemy

I. The origins ooc-lang.org


The test of time
● 4 rewrites later
➔ Syntax evolved
➔ Still written in Java
➔ Type inference
➔ Generics (horribly implemented)
● Meanwhile, on #ooc-lang/Freenode
➔ A self-hosting effort is started

I. The origins ooc-lang.org


A dream come true
● In just a few weeks
➔ rock = ooc port of the j/ooc compiler
➔ first real community effort
➔ serious cleanups
● A few more weeks, and
➔ rock compiled itself!
➔ again...
➔ and again...
➔ (with a spoon)

I. The origins ooc-lang.org


C vs Java
● Low-level ● « Object-oriented »
● « Simple » ● « Safe »
● « Lightweight » ● « Modular »
● Fuckload of libraries ● Garbage-collected

Can't we
have both?

II. The best of both worlds ooc-lang.org


ooc in a nutshell
● Modularity
➔ import = Modules
➔ use = Libraries
● Types
➔ cover = base types from C
➔ class = simple inheritance, interface, enum
● Functions
➔ name: func (…) -> Type { … }
➔ first-class, overload, defaults, varargs

II. The best of both worlds ooc-lang.org


ooc in a coconut shell
● Generics
➔ identity: func <T> (t: T) → T { t }
● try, catch = Exceptions
➔ Exception new("You dun goofed!") println()
● version = Platform-specific blocks
➔ version(trial) { Time sleepSec(5) }
● operator = Operator overload
➔ operator + (a, b: Int) { a - b } // huhu.

II. The best of both worlds ooc-lang.org


Sweet #1
● Before

Person: class {
firstname, lastname: String
init: func (firstname, lastname: String) {
this firstname = firstname
this lastname = lastname
}
}
● After

init: func (=firstname, =lastname) {}

III. Syntactic sweets ooc-lang.org


Sweet #2
● Before

import structs/ArrayList
import structs/HashMap
import structs/Stack

● After

import structs/[ArrayList, HashMap, Stack]

III. Syntactic sweets ooc-lang.org


Sweet #3
● Before

set := Set new()


set add(a)
set add(b)
set add(c)

● After

set := Set new(). add(a). add(b). add(c)

III. Syntactic sweets ooc-lang.org


Sweet #4
● Before
if(o instanceOf?(LeftBound)) {
e as LeftBound left
} else if(i instanceOf?(RightBound)) {
e as RightBound right
}
● After
match o {
case lb: LeftBound => lf left
case rb: RightBound => rb right
}

III. Syntactic sweets ooc-lang.org


Sweet #5
● Before
f: func (key: String, value: UInt) {

}
map each(f)

● After

list each(|key, value| …)

III. Syntactic sweets ooc-lang.org


covers
● Most C apis are OO
➔ include someaudiolib
➔ SomeType: cover from some_sound { ... }
➔ new: static extern(some_sound_load) func
➔ play: extern(some_sound_play) func
● We're only revealing their true nature
➔ Sound new("ka-ching.ogg") play()

III. Syntactic sweets ooc-lang.org


compound covers
● C structs on steroids
➔ Point: cover { x, y, z: Float }
● Stack vs Heap allocation
➔ p := (3.0, 6.0, 7.0) as Point
➔ init: func@ (=x, =y, =z) {}
● By-value semantics
● Per-method by-ref semantics with func@
➔ norm: func -> Float { Math sqrt(x*x + y*y + z*z) }
➔ set: func@ (=x, =y, =z) {}

III. Syntactic sweets ooc-lang.org


apropos allocation
● So far, every object is heap-allocated
➔ Boehm GC - conservative & fast (si si.)
➔ -gc=off
● But since new is a method like any other...
➔ pool := static Pool<This> new()
➔ new: static func -> This { pool acquire() }
➔ destroy: func { pool release(this) }
➔ v := Vector3 new() // sha-zam.

III. Syntactic sweets ooc-lang.org


extend
● User-side addition of methods to any type

extend SSizeT {
times: func (f: Func(SSizeT)) {
f(this)
(this - 1) times(f)
}
}

3 times(|| knock())

III. Syntactic sweets ooc-lang.org


rock
➔ ooc compiler in ooc – Anthony Roja Buck
➔ 22K SLOC – Noel Cower
– Mark Fayngersh
➔ 132 modules
– Peter Lichard
➔ 1900 commits – Patrice Ferlet
– Amos Wenger – Nick Markwell
– Friedrich Weber – Daniel Danopia
– Rofl0r – Michael Kedzierski
– Yannic Ahrens – Tim Howard
– Joshua Rösslein – Mickael9
– Scott Olson – Viraptor
– Michael Tremel – ...

IV. Rocking out ooc-lang.org


The plan
Parsing

Error
Resolving
reporting
C backend

Generating C
Other backends
C compilation

IV. Rocking out ooc-lang.org


Drivers
● combine
➔ All at the same time
➔ Legacy
● sequence (default)
➔ One by one, lib cache
➔ Partial recompilation
● make
➔ Generates a Makefile with the C code
➔ Ideal for distribution

IV. Rocking out ooc-lang.org


Dependencies
● import text/json/Parser
➔ Not transitive (unlike include)
➔ Cyclic deps are handled
● use antigravity, sdl
➔ Name, Description, Version, Requirements
➔ Includes, Linker and compiler flags
– pkg-config
➔ SourcePath, Imports
● Bye-bye auto-tools!

IV. Rocking out ooc-lang.org


The SDK
● Mainline SDK
➔ is comfortable (net, text, structs, io, math, os...)
➔ ...but a bit large for some
● There's no such thing as « The SDK »
➔ -sdk=, $OOC_SDK
➔ Bare minimum
– Object
– Class
– a few base types

IV. Rocking out ooc-lang.org


The legacy
● oos
ooc operating system, runs on x86 real hw,
custom sdk, bits of asm but 0% C
● ooc-ti
sdk for tigcc, compiles+runs stuff on TI89!
● pyooc
use ooc code from python, json backend
zero-configuration
● ruby-inline-ooc
load+evaluate ruby code inside ooc

V. The legacy ooc-lang.org


ooc-ti

V. The legacy ooc-lang.org


The legacy II
● reincarnate
package manager, in ooc, for ooc. deps based
on usefiles, python server backend (nirvana)
● stako
a stack-based language inspired by factor
● langsniff
analyzes a text and find which language it's in
● yajit
simple just-in-time assembler - used in rock for
flattening closures

V. The legacy ooc-lang.org


teeworlds-ai

V. The legacy ooc-lang.org


The legacy III
● spry
IRC bot framework in ooc
● proof
small testing framework for ooc
● ooc-web
ooc web applicaton framework
● mustang
templating engine based on
the infamous mustache

V. The legacy ooc-lang.org


inception-engine
● game engine, OpenGL+SDL, ingame console

V. The legacy ooc-lang.org


The legacy IV

<your project here>

http://github.com/languages/ooc

V. The legacy ooc-lang.org


Questions
➔ Languages ➔ Performance
– What about Go/Vala? – Is it fast?
– What about ➔ Bindings
Scala/Clojure?
– Does lib X have
– What about C++? bindings yet?
– What about C#? – Isn't it tedious to do
➔ Development bindings?
– Can I contribute? ➔ Interoperability
– Do you want money? – Let's do rbooc!
– What's next for rock? – Let's do Perl::ooc!
– Where else can I help? – Let's do Y!

VI. Agora ooc-lang.org


Thanks for listening!

Web http://ooc-lang.org
IRC #ooc-lang on Freenode
Twitter @ooc_lang
Mail ndd@rylliog.cz

OSDC.fr 2010 ooc-lang.org Amos Wenger

You might also like