Taylor — A Performant Language for the Ethereum Virtual Machine (EVM)

(def! fibonacci (fn* (n) (if (or (eq n 1) (eq n 2)) 1 (add(fibonacci (sub n 1)) (fibonacci (sub n 2)) ) )))
add
34
add
3
4
add
34
(add 3 4)
(list 
0x02
0x04
(dup 2)
(swap 1)
(add 5))
(if (eq 3 4) (add 0x03 0x04) (add 0x05 0x06))switch 0x4444
(case 0x1000 (add 0x1 0x1))
(case 0x4444 (add 0x2 0x2))
(case 0x2000 (add 0x3 0x3))
(default 0x55)
(list
0x00
0x01
(loop 1 8
(list
(add (dup 4) (dup 4))
(swap 3)
(swap 4)
(pop)
)
)
(mem-store 0x00)
(return 0x00 0x20)
)
define fib ["uint256"] ["uint256"] 
if (eq 0x0 (dup 1))
(pass 0x0)
if (eq 0x1 (dup 1))
(pass 0x01)
list
add
(fib (sub (dup 4) 1 ))
(fib (sub (dup 3) 2 ))
(swap 1)
(pop)
to-deploy
list
(include "fib")
(fib (calldata-load 0x0))
(mem-store 0x00)
(return 0x00 0x20)
if 
eq
0x1
dup
1
pass
0x01
list
add
fib
sub
dup
4
1
fib
sub
dup
3
2
swap
1
pop
0x4b
0x0d
0x00
codecopy
0x4b
0x00
return
stop
after_do_fib_14
0x00
calldataload
fib
jump
after_do_fib_14:
0x00
mstore
0x20
0x00
return
fib:
dup1
0x00
eq
ifsource_9
jumpi
elsesource_9:
dup1
0x01
eq
ifsource_8
jumpi
elsesource_8:
after_do_fib_13
0x02
dup3
sub
fib
jump
after_do_fib_13:
after_do_fib_12
0x01
dup4
sub
fib
jump
after_do_fib_12:
add
swap1
pop
endif_8
jump
ifsource_8:
fib_end
jump
endif_8:
endif_9
jump
ifsource_9:
fib_end
jump
endif_9:fib_end:
swap1
jump

Comparison

object "TestFib" {
code {
datacopy(0, dataoffset("Runtime"), datasize("Runtime"))
return(0, datasize("Runtime"))
}
object "Runtime" {
code {
let input := calldataload(0x0)
let res := fib(input)
mstore(0x0, res)
return(0x0, 0x20)
function fib(nth) -> result {
switch nth
case 0 { result := 0 }
case 1 { result := 1 }
default {
result := add(fib(sub(nth, 2)), fib(sub(nth, 1)))
}}}}}

Compiled vs. Interpreted

Video Demo

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store