Skip to content

Commit

Permalink
Update EVM type descriptor interface
Browse files Browse the repository at this point in the history
Includes methods from Batch 2. See: #49
  • Loading branch information
kwannoel committed Jul 7, 2021
1 parent 3ee39c9 commit d72e41e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
1 change: 1 addition & 0 deletions evm-runtime.ss
Original file line number Diff line number Diff line change
Expand Up @@ -754,5 +754,6 @@
(else []))
)


;; TODO &mloadat/any-size
;; TODO &mstoreat/any-size
16 changes: 8 additions & 8 deletions t/100-type-descriptors-integrationtest.ss
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

(def 100-type-descriptors-integrationtest
(test-suite "integration tests for evm type descriptors"
(test-case "EVM-type: &mem<-stack<-, size = 1"
(test-case "EVM-type: &mem/free<-stack<-, size = 1"
;; TODO Integrate this type with existing EVM types,
;; when interface has been finalized.
(define-type (Bool @ [poo.Bool EVM-Type]) .boxed?: #f .size: 1)
(def &store-true (.call Bool .&mem<-stack<- #t))
(def &store-true (.call Bool .&mem/free<-stack<- #t))

(evm-test [] (&begin
#x20 (&mstoreat brk@ 32)
Expand All @@ -21,7 +21,7 @@
result-in-memory?: #t
result-start: #x20))

(test-case "EVM-type: &mem<-stack<-, size = 65"
(test-case "EVM-type: &mem/free<-stack<-, size = 65"
;; TODO Integrate this type with existing EVM types,
;; when interface has been finalized.
(define-type (String @ [poo.String EVM-Type]) .boxed?: #t)
Expand All @@ -41,7 +41,7 @@
(def str65/3/nat 68)

(def str65 (string-join [str65/1 str65/2 str65/3] ""))
(def str65/inst (.call String .&mem<-stack<- str65))
(def str65/inst (.call String .&mem/free<-stack<- str65))

(evm-test [] (&begin
#x20 (&mstoreat brk@ 32)
Expand Down Expand Up @@ -78,19 +78,19 @@
(def str65 (string-join [str65/1 str65/2 str65/3] ""))

;; Instructions
(def &str65/mem<-stack<- (.call String .&mem<-stack<- str65)) ; Store str65 to memory
(def &str65/mem/free<-stack<- (.call String .&mem/free<-stack<- str65)) ; Store str65 to memory
(def &str65/stack<-mem (.call String .&stack<-mem str65)) ; Load str65 from memory to stack
(def &str65/mem<-stack (.call String .&mem<-stack str65)) ; Store back to memory at next 65 bytes
(def &str65/mem/free<-stack (.call String .&mem/free<-stack str65)) ; Store back to memory at next 65 bytes

(evm-test [] (&begin
;; init freememptr
#x20 (&mstoreat brk@ 32) ; -

;; Store str65 in mem
&str65/mem<-stack<- ; -
&str65/mem/free<-stack<- ; -
#x20 ; str65-offset
&str65/stack<-mem ; bytes[0-32] bytes[32-64] bytes[64-65]
&str65/mem<-stack ; -
&str65/mem/free<-stack ; -

;; Store the free memory pointer
(&mloadat brk@) DUP1 MSTORE ; -
Expand Down
68 changes: 62 additions & 6 deletions type-descriptors.ss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
)
.size: #f ; Size in bytes; Overridden for types with static size.

;; stack in: -
;; stack out: bytes/0 bytes/1 ... bytes/n
.&stack<-: (lambda (value)
(def bytes (.call @ .bytes<- value))
(&push/any-size bytes))
Expand All @@ -46,11 +48,65 @@
(def size (or .size (u8vector-length bytes)))
(&instruction size))

;; NOTE: These use free memory pointer
.&mem<-stack: (cut .&with-size &mstore/any-size <>)
;; stack in: bytes/0 bytes/1 ... bytes/n
;; mem in: -
;; stack out: -
;; mem out: bytes/0 bytes/1 ... bytes/n
;; ^ brk@
.&mem/free<-stack: (cut .&with-size &mstore/any-size <>)

;; stack in: offset bytes/0 bytes/1 ... bytes/n
;; mem in: -
;; stack out: -
;; mem out: bytes/0 bytes/1 ... bytes/n
;; ^ offset
;; TODO .&mem<-stack: (lambda (value) ...)

;; stack in: bytes/0 bytes/1 ... bytes/n
;; mem in: -
;; stack out: -
;; mem out: bytes/0 bytes/1 ... bytes/n
;; ^ offset
;; TODO .&mem-at<-stack: (lambda (value offset) ...)

;; stack in: offset
;; mem in: bytes/0 bytes/1 ... bytes/n
;; ^ offset
;; stack out: bytes/0 bytes/1 ... bytes/n
;; mem out: -
.&stack<-mem: (cut .&with-size &mload/any-size <>)
.&mem<-stack<-: (lambda (value) (&begin (.&stack<- value) (.&mem<-stack value)))
;; .&memcpy: ; TODO copy memory from one location to another
)

;; TODO pull and read from CALLDATA. from mem -> stack / stack
;; stack in: -
;; mem in: bytes/0 bytes/1 ... bytes/n
;; ^ offset
;; stack out: bytes/0 bytes/1 ... bytes/n
;; mem out: -
;; TODO .&stack<-mem-at: (cut .&with-size &mloadat/any-size <> <offset>)

;; stack in: -
;; mem in: -
;; stack out: -
;; mem out: bytes/0 bytes/1 ... bytes/n
;; ^ brk@
.&mem/free<-stack<-: (lambda (value) (&begin (.&stack<- value) (.&mem/free<-stack value)))

;; stack in: offset
;; mem in: -
;; stack out: -
;; mem out: bytes/0 bytes/1 ... bytes/n
;; ^ brk@
;; TODO .&mem<-stack<-: (lambda (value) (&begin (.&stack<- value) (.&mem<-stack value)))

;; stack in:
;; mem in: -
;; stack out: -
;; mem out: bytes/0 bytes/1 ... bytes/n
;; ^ brk@
;; TODO .&mem-at<-stack<-: (lambda (value offset) (&begin (.&stack<- value) (.&mem-at<-stack value offset)))


;; TODO
;; .&mem<-calldata: (cut .&with-size &calldatamem/any-size <>)
;; .&stack<-calldata: (cut .&with-size &calldataload/any-size <>)
;; .&memcpy: (cut .&with-size &memcpy/any-size <>)
)

0 comments on commit d72e41e

Please sign in to comment.