Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[fix] js,runtime,record,fold: now in cps

  • Loading branch information...
commit 422fa79d76e729fb2d3906099885110fa744754c 1 parent 35abcf7
@OpaOnWindowsNow OpaOnWindowsNow authored
View
44 compiler/qmljsimp/qmlJsImpClientLib.js
@@ -1,5 +1,5 @@
/*
- Copyright © 2011 MLstate
+ Copyright © 2011, 2012 MLstate
This file is part of Opa.
@@ -89,6 +89,7 @@ function fold_record(f, record, acc) {
switch (record) {
case true: return f("true",js_void,acc)
case false: return f("false",js_void,acc)
+ case null: return acc
default:
var tab = new Array(), field, i = 0, n;
for (field in record) _size === field || tab.push(field)
@@ -101,10 +102,31 @@ function fold_record(f, record, acc) {
}
}
+function fold_record_cps(f, record, acc, k) {
+ switch (record) {
+ case true: return f("true", js_void,acc,k)
+ case false: return f("false",js_void,acc,k)
+ case null: return return_(k,acc)
+ default:
+ var tab = new Array(), field, n;
+ for (field in record) _size == field || tab.push(field)
+ tab.sort()
+ n = tab.length
+ function recurse(i,acc){
+ field = tab[i]
+ return ( i == n ) ?
+ return_(k,acc)
+ :f(field, record[field], acc, ccont(k,function (acc){recurse(i+1,acc)}) )
+ }
+ return recurse(0,acc)
+ }
+}
+
function fold_2_record(f, record1, record2, acc) {
switch (record1) {
case true: return f("true", js_void, js_void, acc)
case false: return f("false", js_void, js_void, acc)
+ case null: return acc
default:
var tab = new Array(), field, i = 0, n;
for (field in record1) _size === field || tab.push(field)
@@ -117,6 +139,26 @@ function fold_2_record(f, record1, record2, acc) {
}
}
+function fold_2_record_cps(f, record1, record2, acc, k) {
+ switch (record) {
+ case true: return f("true", js_void, js_void, acc,k)
+ case false: return f("false",js_void, js_void, acc,k)
+ case null: return return_(k,acc)
+ default:
+ var tab = new Array(), field, n;
+ for (field in record1) _size == field || tab.push(field)
+ tab.sort()
+ n = tab.length
+ function recurse(i,acc){
+ field = tab[i]
+ return ( i == n ) ?
+ return_(k,acc)
+ :f(field, record1[field], record2[field], acc, ccont(k,function (acc){recurse(i+1,acc)}) )
+ }
+ return recurse(0,acc)
+ }
+}
+
function name_of_field(field) {
return {some : field}
}
View
10 lib/plugins/opabsl/jsbsl/bslValue.js
@@ -34,8 +34,12 @@
##register [pure] fold_record \ `fold_record` : (Record.field, 'a, 'b -> 'b), 'c, 'b -> 'b
+##register [cps-bypass, pure] fold_record_cps \ `fold_record_cps` : (Record.field, 'a, 'b, continuation('b) -> void), 'c, 'b, continuation('b) -> void
+
##register [pure] fold_2_record \ `fold_2_record` : (Record.field, 'a, 'a, 'b -> 'b), 'c, 'c, 'b -> 'b
+##register [cps-bypass, pure] fold_2_record_cps \ `fold_2_record_cps` : (Record.field, 'a, 'a, 'b, continuation('b) -> void), 'c, 'c, 'b, continuation('b) -> void
+
##register name_of_field \ `name_of_field` : Record.field -> opa[option(string)]
##register field_of_name \ `field_of_name` : string -> opa[option(Record.field)]
@@ -48,13 +52,13 @@
##register [pure] make_simple_record \ `make_simple_record` : Record.field -> _
-##register fields_indexes \ `fields_indexes` : llarray(Record.field) -> Record.fields_indexes
+##register [pure] fields_indexes \ `fields_indexes` : llarray(Record.field) -> Record.fields_indexes
-##register field_index \ `field_index`: Record.fields_indexes,Record.field -> Record.field_index
+##register [pure] field_index \ `field_index`: Record.fields_indexes,Record.field -> Record.field_index
##register [pure] dot_with_field_index \ `dot_with_field_index`: 'record,Record.field_index -> 'field_content
-##register patterns_indexes \ `patterns_indexes`: llarray(Record.fields_indexes) -> Record.patterns_indexes
+##register [pure] patterns_indexes \ `patterns_indexes`: llarray(Record.fields_indexes) -> Record.patterns_indexes
##register [pure] compare_structure \ `compare_structure`: Record.patterns_indexes,'record,'record -> int
View
2  lib/stdlib/core/opavalue.opa
@@ -341,7 +341,7 @@ OpaValue = {{
* you'll get a segfault). [folder] is a function like this :
* [folder field value_of_field acc].
*/
- fold = %%BslValue.Record.fold_record%%
+ fold = @may_cps(%%BslValue.Record.fold_record%%)
/**
* Fold two record. [fold2 folder record1 record2 acc]
Please sign in to comment.
Something went wrong with that request. Please try again.