Commits

Yasir M. Arsanukaev  committed c5f7264

Rename functions according to structures they convert objects to. Implement 'nil. Resolve test-2 failing.

  • Participants
  • Parent commits 60c1846

Comments (0)

Files changed (3)

File src/encode.ss

         (rnrs mutable-pairs)
         (rnrs io ports)
         (rnrs control)
-        (rnrs arithmetic bitwise))
+        (rnrs arithmetic bitwise)
+        (erl-ext-types))
 
-(define SMALL_INT 97)
-(define INT 98)
-(define SMALL_BIGNUM 110)
-(define LARGE_BIGNUM 111)
-(define FLOAT 99)
-(define ATOM 100)
-(define SMALL_TUPLE 104)
-(define LARGE_TUPLE 105)
-(define NIL 106)
-(define STRING 107)
-(define LIST 108)
-(define BIN 109)
-(define FUN 117)
-(define NEW_FUN 112)
-(define MAGIC 131)
-;(define MAX_INT (- (arithmetic-shift 1 27) 1))
-;(define MIN_INT (- (arithmetic-shift 1 27)))
-(define MAX_INT 134217727)
-(define MIN_INT -134217728)
 
 (define (map/and proc lst)
   (cond
 (define (write-str outpr str)
   (put-bytevector outpr (string->bytevector str (native-transcoder))))
 
-(define (write-symbol outpr symbol)
+(define (write-atom outpr symbol)
   (let* ((str (symbol->string symbol))
          (len (string-length str)))
     (if (< len 256)
           (for-each (lambda (x) (write-any-raw outpr x)) data)
           (write-1 outpr NIL))))
 
-(define (write-vector outpr data)
+(define (write-tuple outpr data)
   (let ((len (vector-length data)))
     (if (< len 256)
         (begin
 
 (define (write-hash outpr hash)
   (let-values (((a b) (hashtable-entries hash)))
-  (write-any-raw 
-   outpr
-   (vector
-    'bert       
-    'dict 
-    (vector-map (lambda (k v) (vector (convert k) (convert v)))
-                a
-                b)))))
+    (write-any-raw 
+     outpr
+     (vector 'bert
+             'dict
+             (vector->list
+              (vector-map (lambda (k v) (vector (convert k) (convert v)))
+                          a
+                          b))))))
 
 
 (define (write-any-raw outpr obj)
     ((hashtable? obj)
      (write-hash outpr obj))
     ((vector? obj)
-     (write-vector outpr obj))
+     (write-tuple outpr obj))
     ((symbol? obj)
-     (write-symbol outpr obj))
+     (write-atom outpr obj))
     ((integer? obj)
      (write-fixnum outpr obj))
     (else (error "write-any-raw" "Not implemented."))))
      (vector 'bert 'true))
     ((eq? obj #f)
      (vector 'bert 'false))
-    #|((void? obj)
-     (vector 'bert 'nil))|#
+    ((eqv? obj 'nil)
+     (vector 'bert 'nil))
     (else obj)))
 
 (define (encode obj)
       (error "test-1" "failed")))
 
 (define (test-2)
-  ; {bert,dict,[{one,1},{two,2},{three,3}]}
+  ; {bert,dict,[{two,2},{one,1},{three,3}]}
   (let ((h (make-eqv-hashtable)))
     (hashtable-set! h 1 'one)
     (hashtable-set! h 2 'two)
     (hashtable-set! h 3 'three)
-    (if (equal? (encode h) (u8-list->bytevector '(131 104 4 100 0 3 102 111 111 97 42 98 0 0 2 154 104 4 97 12 106 104 2 97 255 100 0 3 98 97 114 110 8 0 146 131 13 124 31 36 139 1)))
+    (if (equal? (encode h) (u8-list->bytevector '(131 104 3 100 0 4 98 101 114 116 100 0 4 100 105 99 116 108 0 0 0 3 104 2 97 2 100 0 3 116 119 111 104 2 97 1 100 0 3 111 110 101 104 2 97 3 100 0 5 116 104 114 101 101 106)))
         #t
         (error "test-2" "failed"))))
 

File src/erl-ext-types.ss

+#!r6rs
+
+(library (erl-ext-types)
+         (export SMALL_INT
+                 INT
+                 SMALL_BIGNUM
+                 LARGE_BIGNUM
+                 FLOAT
+                 ATOM
+                 SMALL_TUPLE
+                 LARGE_TUPLE
+                 NIL
+                 STRING
+                 LIST
+                 BIN
+                 FUN
+                 NEW_FUN
+                 MAGIC
+                 MAX_INT
+                 MIN_INT)
+         
+         (import (rnrs base)
+                 (rnrs arithmetic bitwise))
+         
+         (define SMALL_INT 97)
+         (define INT 98)
+         (define SMALL_BIGNUM 110)
+         (define LARGE_BIGNUM 111)
+         (define FLOAT 99)
+         (define ATOM 100)
+         (define SMALL_TUPLE 104)
+         (define LARGE_TUPLE 105)
+         (define NIL 106)
+         (define STRING 107)
+         (define LIST 108)
+         (define BIN 109)
+         (define FUN 117)
+         (define NEW_FUN 112)
+         (define MAGIC 131)
+         (define MAX_INT (- (bitwise-arithmetic-shift 1 27) 1))
+         (define MIN_INT (- (bitwise-arithmetic-shift 1 27))))
+

File src/types.ss

-(module types scheme
-        (provide SMALL_INT
-                 INT
-                 SMALL_BIGNUM
-                 LARGE_BIGNUM
-                 FLOAT
-                 ATOM
-                 SMALL_TUPLE
-                 LARGE_TUPLE
-                 NIL
-                 STRING
-                 LIST
-                 BIN
-                 FUN
-                 NEW_FUN
-                 MAGIC
-                 MAX_INT
-                 MIN_INT
-                 )
-        (define SMALL_INT 97)
-        (define INT 98)
-        (define SMALL_BIGNUM 110)
-        (define LARGE_BIGNUM 111)
-        (define FLOAT 99)
-        (define ATOM 100)
-        (define SMALL_TUPLE 104)
-        (define LARGE_TUPLE 105)
-        (define NIL 106)
-        (define STRING 107)
-        (define LIST 108)
-        (define BIN 109)
-        (define FUN 117)
-        (define NEW_FUN 112)
-        (define MAGIC 131)
-        (define MAX_INT (- (arithmetic-shift 1 27) 1))
-        (define MIN_INT (- (arithmetic-shift 1 27)))
-        )
-