Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lunfardo314 committed May 24, 2024
1 parent 35da7ef commit 691528a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
34 changes: 0 additions & 34 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ var (
return []*EmbeddedFunctionData{
{"parseArgumentBytecode", 3, lib.evalParseArgumentBytecode},
{"parsePrefixBytecode", 1, lib.evalParsePrefixBytecode},
//{"evalBytecodeArg", 3, lib.evalBytecodeArg},
{"eval", 1, lib.evalBytecode}, // evaluates closed formula
}
}
Expand Down Expand Up @@ -196,14 +195,6 @@ func (lib *Library) embedBaseCrypto() {

func (lib *Library) embedBytecodeManipulation() {
// code parsing
// $0 - EasyFL bytecode
// $1 - expected call prefix (#-literal)
// $2 - number of the parameter to return
// Panics if the bytecode is not the valid call of the specified function or number of the parameter is out of bounds
// Returns code of the argument if it is a call function, or data is it is a constant
//lib.embedLong("unwrapBytecodeArg", 3, lib.evalParseArgumentBytecode)
//lib.embedLong("parseBytecodePrefix", 1, lib.evalParsePrefixBytecode)
//lib.embedLong("evalBytecodeArg", 3, lib.evalBytecodeArg)
lib.UpgradeWthEmbeddedLong(embedBytecodeManipulation(lib)...)

_, _, binCode, err := lib.CompileExpression("slice(0x01020304,1,2)")
Expand All @@ -216,31 +207,6 @@ func (lib *Library) embedBytecodeManipulation() {
lib.MustEqual(src, "2")
src = fmt.Sprintf("parsePrefixBytecode(0x%s)", hex.EncodeToString(binCode))
lib.MustEqual(src, "#slice")

//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 0)
//lib.MustEqual(src, "0x01020304")
//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 1)
//lib.MustEqual(src, "1")
//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 2)
//lib.MustEqual(src, "2")
//
//_, _, binCode, err = lib.CompileExpression("slice(concat(1,2,concat(3,4)),1,2)")
//AssertNoError(err)
//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 0)
//lib.MustEqual(src, "0x01020304")
//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 1)
//lib.MustEqual(src, "1")
//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 2)
//lib.MustEqual(src, "2")
//
//_, _, binCode, err = lib.CompileExpression("slice(concat(1,concat(2,3),4),byte(0x020301, 2),add(1,1))")
//AssertNoError(err)
//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 0)
//lib.MustEqual(src, "0x01020304")
//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 1)
//lib.MustEqual(src, "1")
//src = fmt.Sprintf("evalBytecodeArg(0x%s, #slice, %d)", hex.EncodeToString(binCode), 2)
//lib.MustEqual(src, "u64/2")
}

// -----------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,19 @@ func TestBytecodeParams(t *testing.T) {

res := EvalExpression(nil, expr, []byte{0xff})
t.Logf("eval: %s", Fmt(res))
require.EqualValues(t, []byte{0xff, 0x81, 0xff}, res)
})
t.Run("3-1", func(t *testing.T) {
const src = "concat(1,$$0, $$1, $$2)"

expr, n, code, err := lib.CompileExpression(src)
require.NoError(t, err)
require.EqualValues(t, 3, n)
t.Logf("code: %s", Fmt(code))

res := EvalExpression(nil, expr, []byte{0xff}, []byte{0xff}, []byte{0xff})
t.Logf("eval: %s", Fmt(res))
require.EqualValues(t, hex.EncodeToString(res), "0181ff81ff81ff")
})
t.Run("4", func(t *testing.T) {
res, err := lib.EvalFromSource(nil, "concat(42,41)")
Expand Down

0 comments on commit 691528a

Please sign in to comment.