Skip to content
Browse files

More slides.

  • Loading branch information...
1 parent 2ff576c commit 74bffc14053aef027f95cf31c0779784ad9a8911 Amos Wenger committed
Showing with 105 additions and 20 deletions.
  1. +6 −0 excerpts/generics-001-with-types.ooc
  2. +7 −0 excerpts/identity-generic2.c
  3. +4 −0 excerpts/identity-int2.c
  4. +3 −3 excerpts/logger.ooc
  5. +1 −1 excerpts/pointer-dance.c
  6. +84 −16 slides.md
View
6 excerpts/generics-001-with-types.ooc
@@ -0,0 +1,6 @@
+
+// primitive type
+answer := identity(42)
+
+// object type
+identity("foobar") println()
View
7 excerpts/identity-generic2.c
@@ -0,0 +1,7 @@
+typedef uint8_t *Any;
+
+void identity(Class *T, Any value, Any ret) {
+ if (ret) {
+ memcpy(ret, value, T->size)
+ }
+}
View
4 excerpts/identity-int2.c
@@ -0,0 +1,4 @@
+/* what is the generic version of this? */
+int identity(int value) {
+ return value;
+}
View
6 excerpts/logger.ooc
@@ -1,4 +1,4 @@
-Logger: class {
+Logger: class extends Formatter {
level: Level
out: Stream
@@ -6,8 +6,8 @@ Logger: class {
level = Level INFO
}
- log: func (msg, level = Level INFO) {
+ log: func (msg: String, level: Level) {
if (level <= this level)
- format(msg)
+ out print(format(msg))
}
}
View
2 excerpts/pointer-dance.c
@@ -1,4 +1,4 @@
-void somefunc(uint8_t value) {
+void somefunc(uint8_t *value) {
int i = *((int*) value);
// do something with i
}
View
100 slides.md
@@ -4,7 +4,7 @@
# The ooc programming language
-ooc is a general-purpose programming language. It was created in 2009 for an EPFL school project, and is now self-hosting, currently in v0.9.4
+ooc is a general-purpose programming language. It was created in 2009 for an EPFL school project, and is now self-hosting, currently in v0.9.4. It produces clean, portable C code, its SDK works on Windows, OSX, Linux, Haiku, FreeBSD, and probably more.
Has been used to create games, power live streaming backend architecture (in production), write compilers, IRC servers, IRC bots, torrent clients, implement Lisp, JIT assemblers, package managers, and more.
@@ -18,10 +18,6 @@ Has been used to create games, power live streaming backend architecture (in pro
\input{excerpts/logger-use.ooc.tex}
-# Enums
-
-\input{excerpts/level.ooc.tex}
-
# Covers (C side)
\input{excerpts/cover-struct.c.tex}
@@ -30,22 +26,94 @@ Has been used to create games, power live streaming backend architecture (in pro
\input{excerpts/cover-struct.ooc.tex}
-# C++
+# Features not covered here
+
+Well outside the scope of this presentation:
+
+ * Operator overloading
+ * Implicit conversions
+ * Cover inheritance, compound covers,
+ structured initializers
+ * Version blocks
+ * Interfaces
+ * Custom memory management
+ * Enums
+ * Pattern matching
+
+# Meta-programming in other languages
+
+C only allows macros, not generic programming. While this
+doesn't prevent the creation of generic containers, type
+safety is not guaranteed.
+
+C++ meta-programming is done via templates: compile-time
+instanciation, type safety, significant cost in compilation time
+and binary size.
+
+JVM-based languages (Java, Scala, Groovy, etc.) have generic
+classes, with type erasure because of backwards-compatibility.
+Limited compile-time type-safety (can be overriden) and no
+introspection possible at runtime.
+
+# Types
+
+A type can either be:
+
+ * A complex type: object, interface. e.g. `String`, `Logger`, etc.
+ * A primitive type: cover, cover from. e.g. `Int`, `Boolean`
+
+Java has a similar distinction (`int` vs `Integer`).
+
+In ooc, instead of boxing and unboxing, primitive types are allowed
+as generic type parameters.
+
+# Generics - Functions
+
+\input{excerpts/generics-001.ooc.tex}
+
+\input{excerpts/generics-001-with-types.ooc.tex}
+
+# Generics - Classes
+
+\input{excerpts/generics-container.ooc.tex}
+
+Number of generic parameters is not limited:
+
+\input{excerpts/generics-kv.ooc.tex}
+
+# The problem
+
+Non-generic code generates straightforward C code, but generic types
+add to the semantics of the language and have no natural C translation.
+
+\input{excerpts/identity-int2.c.tex}
+
+Generic type sizes can vary: operations on generic values must work
+whatever their actual size is at runtime. So must operations on arrays
+of generic values.
+
+# The solution
+
+All types in ooc have runtime type information, returned by the
+`TypeName_class()` function. This structure contains the width of the
+type.
+
+\input{excerpts/identity-generic2.c.tex}
+
+# The solution
+
+Calls like this one:
- * C++ doesn't compile to C anymore
- * C++ has more features
- * C++ has templates
+\input{excerpts/identity-call.ooc.tex}
-# JVM
+are translated as:
- * Java runs on a VM (mostly)
- * Java tries to stay away from platform-specific code
- * Java has type erasure in Generic
- * Scala also limited by the JVM, no reification
+\input{excerpts/identity-call.c.tex}
-# Identity specialized
+# The solution's problem
-\input{excerpts/identity-int.c.tex}
+Passing the address of generic values instead of their value directly
+is an extra indirection (dereference)
# Source size

0 comments on commit 74bffc1

Please sign in to comment.
Something went wrong with that request. Please try again.