summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstefan <stefan@s00.xyz>2023-05-22 20:08:09 -0400
committerstefan <stefan@s00.xyz>2023-05-22 20:08:09 -0400
commitc30e7f5f99f9ad4d9552b645d7b89d7385972f99 (patch)
treea2938c9cda3226ef7e3ea8cb84b338a41003ceb4
downloadevm-c30e7f5f99f9ad4d9552b645d7b89d7385972f99.tar.gz
stack
-rw-r--r--LICENSE16
-rw-r--r--node/go.mod5
-rw-r--r--node/go.sum2
-rw-r--r--node/node.go15
-rw-r--r--node/stack.go32
5 files changed, 70 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..aa2cfd3
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,16 @@
+ISC License
+
+Copyright (c) 2023 Stefan Weigl-Bosker <stefan@s00.xyz>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
diff --git a/node/go.mod b/node/go.mod
new file mode 100644
index 0000000..725da6d
--- /dev/null
+++ b/node/go.mod
@@ -0,0 +1,5 @@
+module s00.xyz/evm
+
+go 1.20
+
+require github.com/holiman/uint256 v1.2.2 // indirect
diff --git a/node/go.sum b/node/go.sum
new file mode 100644
index 0000000..e0f03a0
--- /dev/null
+++ b/node/go.sum
@@ -0,0 +1,2 @@
+github.com/holiman/uint256 v1.2.2 h1:TXKcSGc2WaxPD2+bmzAsVthL4+pEN0YwXcL5qED83vk=
+github.com/holiman/uint256 v1.2.2/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
diff --git a/node/node.go b/node/node.go
new file mode 100644
index 0000000..18640e9
--- /dev/null
+++ b/node/node.go
@@ -0,0 +1,15 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/holiman/uint256"
+)
+
+func main() {
+ s := NewStack()
+ x, _ := uint256.FromHex("0xfeedface")
+ s.Push(x)
+ y := s.Pop()
+ fmt.Println(y.String())
+}
diff --git a/node/stack.go b/node/stack.go
new file mode 100644
index 0000000..a5460a7
--- /dev/null
+++ b/node/stack.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "log"
+
+ "github.com/holiman/uint256"
+)
+
+const STACK_CAP = (1 << 10)
+
+type Stack []uint256.Int
+
+func NewStack() *Stack {
+ return &Stack{}
+}
+
+func (s *Stack) Push(x *uint256.Int) {
+ *s = append(*s, *x)
+ if len(*s) > STACK_CAP {
+ log.Fatal("stack overflow")
+ }
+}
+
+func (s *Stack) Pop() *uint256.Int {
+ if len(*s) <= 0 {
+ log.Fatal("stack underflow")
+ }
+
+ r := (*s)[len(*s)-1]
+ *s = (*s)[:len(*s)-1]
+ return &r
+}