Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A closure sample to test a recent bugfix

  • Loading branch information...
commit bb9ed43d2f8412ee3f5d1c3adabea5e370306ded 1 parent 4d54877
Amos Wenger (old) authored
Showing with 30 additions and 4 deletions.
  1. +1 −3 report.md
  2. +28 −0 samples/closure.ooc
  3. +1 −1  samples/sample.use
4 report.md
View
@@ -333,13 +333,11 @@ by callsite. In theory, this might lead to combinatorial explosion (as seen
above), but in practice, module-level functions are rare enough in typical ooc
code that such an implementation is still relevant.
-Since the ooc AST[^ast] is mutable, the first step to specializing a function is to
+Since the ooc AST is mutable, the first step to specializing a function is to
keep a copy of it before any AST mutation can transform it into a full-blown
generic function. In our implementation, we simply added an `inline` member to
the `FunctionDecl` AST node.
-[^ast]: Abstract Syntax Tree.
-
The second step is to modify the function call resolution process in order to
intercept functions that are marked as specializable. This is done by adding a
condition in the `resolveCall` function of the `FunctionCall`, that calls the
28 samples/closure.ooc
View
@@ -0,0 +1,28 @@
+
+
+Jar: class <Xaneon> {
+ _cookie: Xaneon
+
+ cookie: func ~set (=_cookie)
+
+ withCookie: func (falafel: Func (Xaneon)) {
+ falafel(_cookie)
+ }
+}
+
+#specialize Jar<Char> // binks
+
+main: func {
+ j := Jar<Int> new()
+ j cookie(99)
+ j withCookie(|c|
+ printf("j's cookie = %d\n", c)
+ )
+
+ k := Jar<Char> new()
+ k cookie('c')
+ k withCookie(|c|
+ printf("k's cookie = %d\n", c)
+ )
+}
+
2  samples/sample.use
View
@@ -1 +1 @@
-Main: sorting.ooc
+Main: closure.ooc
Please sign in to comment.
Something went wrong with that request. Please try again.