Add display initial to engine execution

This commit is contained in:
lash
2023-04-06 09:14:53 +01:00
parent c748daa8f7
commit f0bfff3a20
6 changed files with 29 additions and 9 deletions

View File

@@ -32,8 +32,11 @@ func NewEngine(st *state.State, rs resource.Resource) Engine {
//
// It makes sure bootstrapping code has been executed, and that the exposed bytecode is ready for user input.
func(en *Engine) Init(sym string, ctx context.Context) error {
err := en.st.SetInput([]byte{})
if err != nil {
return err
}
b := vm.NewLine(nil, vm.MOVE, []string{sym}, nil, nil)
var err error
b, err = vm.Run(b, en.st, en.rs, ctx)
if err != nil {
return err
@@ -61,7 +64,7 @@ func (en *Engine) Exec(input []byte, ctx context.Context) error {
if err != nil {
return err
}
log.Printf("new execution with input 0x%x (%v)", input, len(input))
log.Printf("new execution with input '%s' (0x%x)", input, input)
code, err := en.st.GetCode()
if err != nil {
return err

View File

@@ -88,8 +88,12 @@ func TestEngineInit(t *testing.T) {
t.Fatal(err)
}
b := w.Bytes()
if !bytes.Equal(b, []byte("hello world")) {
t.Fatalf("expected result 'hello world', got %v", b)
expect_str := `hello world
1:do the foo
2:go to the bar`
if !bytes.Equal(b, []byte(expect_str)) {
t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expect_str, b)
}
input := []byte("1")