Yosuke Onoue avatar Yosuke Onoue committed 1270ce8

refresh test code

Comments (0)

Files changed (1)

 #!/usr/bin/env python
 
-import ctypes
 import otypes
 from otypes import MLDLL
 
-if __name__ == '__main__':
-    lib = MLDLL('sample.so')
-    x = lib.caml_named_value('x')
-    print lib.int_val(x)
+print 'importing mllibrary'
+lib = MLDLL('sample.so')
 
-    f = lib.caml_named_value('f')
-    res = lib.caml_callback(f, x)
-    print lib.int_val(res)
+print 'test1'
+x = lib.caml_named_value('x')
+print lib.int_val(x)
+print
 
-    y = lib.caml_named_value('y')
-    print lib.double_val(y)
+print 'test2'
+f = lib.caml_named_value('f')
+res = lib.caml_callback(f, x)
+print lib.int_val(res)
+print
 
-    d = lib.caml_alloc(1, otypes.DOUBLE_TAG)
-    lib.store_double_val(d, 0.3)
-    print lib.double_val(d)
+print 'test3'
+y = lib.caml_named_value('y')
+print lib.double_val(y)
+print
 
-    ab = lib.caml_named_value('tuple')
-    print chr(lib.int_val(lib.field(ab, 0)))
-    print chr(lib.int_val(lib.field(ab, 1)))
+print 'test4'
+d = lib.caml_alloc(1, otypes.DOUBLE_TAG)
+lib.store_double_val(d, 0.3)
+print lib.double_val(d)
+print
 
-    max3 = lib.caml_named_value('max3')
-    arg = lib.caml_alloc(3, 0)
-    lib.store_field(arg, 0, lib.val_int(3))
-    lib.store_field(arg, 1, lib.val_int(8))
-    lib.store_field(arg, 2, lib.val_int(5))
-    ret = lib.caml_callback(max3, arg)
-    print lib.int_val(ret)
-    print
+print 'test5'
+ab = lib.caml_named_value('tuple')
+print chr(lib.int_val(lib.field(ab, 0)))
+print chr(lib.int_val(lib.field(ab, 1)))
+print
 
-    l = [1,4,2,35,64,3,12,14,46,57]
+print 'test6 passing tuple'
+max3 = lib.caml_named_value('max3')
+arg = lib.caml_alloc(3, 0)
+lib.store_field(arg, 0, lib.val_int(3))
+lib.store_field(arg, 1, lib.val_int(8))
+lib.store_field(arg, 2, lib.val_int(5))
+ret = lib.caml_callback(max3, arg)
+print lib.int_val(ret)
+print
 
-    sort_array = lib.caml_named_value('sort_array')
-    ml_array = lib.caml_alloc(len(l), 0)
-    for i,item in enumerate(l):
-        lib.store_field(ml_array, i, ctypes.c_long(lib.val_int(item)))
-    lib.caml_callback(sort_array, ml_array)
-    for i in range(len(l)):
-        print lib.int_val(lib.field(ml_array, i))
+print 'test7 sorting array'
+l = [1,4,2,35,64,3,12,14,46,57]
+sort_array = lib.caml_named_value('sort_array')
+ml_array = lib.caml_alloc(len(l), 0)
+for i,item in enumerate(l):
+    lib.store_field(ml_array, i, lib.val_int(item))
+lib.caml_callback(sort_array, ml_array)
+for i in range(len(l)):
+    print lib.int_val(lib.field(ml_array, i))
+print
 
-    print
-    sort_list = lib.caml_named_value('sort_list')
-    def cons(hd, tl):
-        l = lib.caml_alloc(2, 1)
-        lib.store_field(l, 0, hd)
-        lib.store_field(l, 1, tl)
-        return l
-    tl = lib.val_emptylist()
-    tl = cons(lib.val_int(57), tl)
-    tl = cons(lib.val_int(46), tl)
-    l = cons(lib.val_int(58), tl)
-    l = lib.caml_callback(sort_list, l)
-    print lib.int_val(lib.field(l, 0))
-    l = lib.field(l, 1)
-    print lib.int_val(lib.field(l, 0))
-    l = lib.field(l, 1)
-    print lib.int_val(lib.field(l, 0))
-    
-
-    #next_item = lib.val_emptylist()
-    #for item in reversed(l):
-    #    ml_list = lib.caml_alloc(2, 0)
-    #    lib.store_field(ml_list, 0, item)
-    #    lib.store_field(ml_list, 1, next_item)
-    #    next_item = ml_list
-    #    print next_item
-    #ml_list = lib.caml_alloc(1, 0)
-    #lib.store_field(ml_list, 0, next_item)
-    #ml_list = lib.caml_callback(sort_list, ml_list)
-
-
+print 'test8 sorting list'
+sort_list = lib.caml_named_value('sort_list')
+def cons(hd, tl):
+    l = lib.caml_alloc(2, 1)
+    lib.store_field(l, 0, hd)
+    lib.store_field(l, 1, tl)
+    return l
+tl = lib.val_emptylist()
+tl = cons(lib.val_int(57), tl)
+tl = cons(lib.val_int(46), tl)
+l = cons(lib.val_int(58), tl)
+l = lib.caml_callback(sort_list, l)
+print lib.int_val(lib.field(l, 0))
+l = lib.field(l, 1)
+print lib.int_val(lib.field(l, 0))
+l = lib.field(l, 1)
+print lib.int_val(lib.field(l, 0))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.