changeset 32:2b5357b13e2d

Initial work on solver
author Mike Pavone <pavone@retrodev.com>
date Sat, 10 Aug 2013 19:54:20 -0700
parents 3690601c8c70
children b00904b36aca
files src/solver.tp
diffstat 1 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solver.tp	Sat Aug 10 19:54:20 2013 -0700
@@ -0,0 +1,44 @@
+#{
+	classify <- :prog trees {
+		testvals <- #[]
+		i <- 0
+		(os srand: (os time))
+		while: {i < 256} do: {
+			i <- i + 1
+			testvals append: (uint64: (os rand64))
+		}
+		root <- dict linear
+		foreach: trees :idx tree {
+			prog root!: tree
+			res <- prog run: (testvals get: 0)
+			arr <- root get: res withDefault: #[]
+			arr append: tree
+			if: (arr length) = 1 {
+				root set: res arr
+			}
+		}
+		#{
+			inputs <- { testvals }
+			valmap <- { root }
+		}
+	}
+
+	main <- :args {
+		size <- 3
+		if: (args length) > 1 {
+			size <- int32: (args get: 1)
+		}
+		prog <- bv program
+		if: size >= 2 {
+			trees <- (prog allOfSize: size)
+			if: (args length) > 2 {
+				ops <- (args get: 2) splitOn: ","
+				trees <- prog filterTrees: trees ops
+			}
+			info <- classify: prog trees
+			foreach: (info valmap) :val arr {
+				print: "Value: 0x" . (hex: val) ." produced by " . (string: (arr length)) . "programs\n"
+			}
+		}
+	}
+}