Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Debug tool for printing boxed bytestrings
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBurge committed May 3, 2018
1 parent 89f49c9 commit 8017ddc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion abstract-analyzer.rkt
Expand Up @@ -8,6 +8,7 @@
(require "globals.rkt")
(require "utils.rkt")
(require "expander.rkt")
(require (submod "codegen.rkt" constants))
(require (submod "types.rkt" common))
(require (submod "types.rkt" abstract-machine))
(require (submod "types.rkt" evm-assembly))
Expand Down Expand Up @@ -635,7 +636,10 @@
(v-box (cast (rest x) RegisterValue)))]
[(? vector?) (v-vector (vector-map v-box x))]
[(? char?) (v-char x)]
[(? string?) (v-bytes (allocate-bytes! (string->bytes/utf-8 x)))]
[(? string?) (let ([ bs (string->bytes/utf-8 x) ])
(v-bytes (allocate-bytes! (bytes-append (word->bytes TAG-BYTES)
(word->bytes (bytes-length bs))
bs))))]
[_ (error "v-box: Unknown type" x)]))

(: print-debug-line (-> Void))
Expand Down
1 change: 1 addition & 0 deletions debugger.rkt
Expand Up @@ -65,6 +65,7 @@
(match t
[0 (println `(LOGNUM ,(bytes->integer bs #f)))]
[1 (println `(LOGSYM ,(string->symbol (integer->string (bytes->integer bs #f)))))]
[2 (println `(LOGSTR ,bs))]
))

(: memory-dict (-> vm-exec (Listof (List UnlinkedOffset EthWord))))
Expand Down
10 changes: 10 additions & 0 deletions psl/primitives.pmd
Expand Up @@ -274,6 +274,14 @@
(%#-log2 ptr #u32 #u0 #u1)
)

(define (%#-ioctl-print-string x)
(define ptr (%#-bytes-data x))
(define size (%#-bytes-size x))
(%#-ioctl-print-word ptr)
(%#-ioctl-print-word size)
(%#-log2 ptr size #u0 #u2)
)

; Compile-time macros

(define-syntax (%#-set-max-iterations! stx)
Expand Down Expand Up @@ -311,3 +319,5 @@
(%#-memcpy (%#-ptr-offset bytes-ptr #u2) src-ptr num-bytes)
bytes-ptr
)
(define (%#-bytes-data x) (%#-+ x (%#-* #u2 %#-WORD)))
(define (%#-bytes-size x) (%#-mem-read x #u1))
7 changes: 7 additions & 0 deletions tests/0045-strings-3.pmd
@@ -0,0 +1,7 @@
#lang pyramid

(require psl "primitives.pmd")

(set-test-result! 11)

(%#-box (%#-bytes-size "hello world"))
4 changes: 4 additions & 0 deletions utils.rkt
Expand Up @@ -171,6 +171,10 @@
(- w WORDLIMIT)
w))

(: word->bytes (-> Natural Bytes))
(define (word->bytes x)
(integer->bytes x 32 #f))

;; xxxxxxxxxxxx11111111 -> 11111111111111111
;; xxxxxxxxxxxx01111111 -> 00000000001111111
(: sign-extend (-> EthWord Natural EthWord))
Expand Down

0 comments on commit 8017ddc

Please sign in to comment.