standardTemplates

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Add standardTemplate = standardTemplate{
	Body: `global.get $%s
global.get $%s
i64.add
global.set $%s`,
	Inputs:  []string{"a", "b"},
	Outputs: []string{"result"},
	FormatBody: func(t standardTemplate, nodeId string, varMap map[string]*ast.Junction) string {
		a := varMap[utils.JunctionKey(nodeId, "a")]
		b := varMap[utils.JunctionKey(nodeId, "b")]
		return fmt.Sprintf(t.Body,
			mapVarJunctionVariable(a.NodeId, a.VarId),
			mapVarJunctionVariable(b.NodeId, b.VarId),
			mapVarJunctionVariable(nodeId, t.Outputs[0]),
		)
	},
}
View Source
var Divide standardTemplate = standardTemplate{
	Body: `global.get $%s
global.get $%s
i64.div_s
global.set $%s`,
	Inputs:  []string{"a", "b"},
	Outputs: []string{"result"},
	FormatBody: func(t standardTemplate, nodeId string, varMap map[string]*ast.Junction) string {
		a := varMap[utils.JunctionKey(nodeId, "a")]
		b := varMap[utils.JunctionKey(nodeId, "b")]
		return fmt.Sprintf(t.Body,
			mapVarJunctionVariable(a.NodeId, a.VarId),
			mapVarJunctionVariable(b.NodeId, b.VarId),
			mapVarJunctionVariable(nodeId, t.Outputs[0]),
		)
	},
}
View Source
var GetMemory = standardTemplate{
	Body: `call $_get
i64.extend_i32_s
global.set $%s`,
	Outputs: []string{"value"},
	FormatBody: func(t standardTemplate, nodeId string, nodeVarMap map[string]*ast.Junction) string {
		return fmt.Sprintf(t.Body, mapVarJunctionVariable(nodeId, t.Outputs[0]))
	},
}
View Source
var Modulo standardTemplate = standardTemplate{
	Body: `global.get $%s
global.get $%s
i64.rem_s
global.set $%s`,
	Inputs:  []string{"a", "b"},
	Outputs: []string{"result"},
	FormatBody: func(t standardTemplate, nodeId string, varMap map[string]*ast.Junction) string {
		a := varMap[utils.JunctionKey(nodeId, "a")]
		b := varMap[utils.JunctionKey(nodeId, "b")]
		return fmt.Sprintf(t.Body,
			mapVarJunctionVariable(a.NodeId, a.VarId),
			mapVarJunctionVariable(b.NodeId, b.VarId),
			mapVarJunctionVariable(nodeId, t.Outputs[0]),
		)
	},
}
View Source
var Move standardTemplate = standardTemplate{
	Body: `global.get $%s
i32.wrap_i64
call $_move`,
	Inputs: []string{"direction"},
	FormatBody: func(t standardTemplate, nodeId string, nodeVarMap map[string]*ast.Junction) string {
		direction := nodeVarMap[utils.JunctionKey(nodeId, t.Inputs[0])]
		return fmt.Sprintf(t.Body, mapVarJunctionVariable(direction.NodeId, direction.VarId))
	},
}
View Source
var Multiply standardTemplate = standardTemplate{
	Body: `global.get $%s
global.get $%s
i64.mul
global.set $%s`,
	Inputs:  []string{"a", "b"},
	Outputs: []string{"result"},
	FormatBody: func(t standardTemplate, nodeId string, varMap map[string]*ast.Junction) string {
		a := varMap[utils.JunctionKey(nodeId, "a")]
		b := varMap[utils.JunctionKey(nodeId, "b")]
		return fmt.Sprintf(t.Body,
			mapVarJunctionVariable(a.NodeId, a.VarId),
			mapVarJunctionVariable(b.NodeId, b.VarId),
			mapVarJunctionVariable(nodeId, t.Outputs[0]),
		)
	},
}
View Source
var Print standardTemplate = standardTemplate{
	Body: `global.get $%s
i32.wrap_i64
call $_log`,
	Inputs: []string{"text"},
	FormatBody: func(t standardTemplate, nodeId string, nodeVarMap map[string]*ast.Junction) string {
		text := nodeVarMap[utils.JunctionKey(nodeId, t.Inputs[0])]
		return fmt.Sprintf(t.Body, mapVarJunctionVariable(text.NodeId, text.VarId))
	},
}
View Source
var SetMemory = standardTemplate{
	Body: `global.get $%s
i32.wrap_i64
call $_set`,
	Inputs: []string{"value"},
	FormatBody: func(t standardTemplate, nodeId string, nodeVarMap map[string]*ast.Junction) string {
		value := nodeVarMap[utils.JunctionKey(nodeId, t.Inputs[0])]
		return fmt.Sprintf(t.Body, mapVarJunctionVariable(value.NodeId, value.VarId))
	},
}
View Source
var StandardTemplates = map[string]*standardTemplate{
	"Print":     &Print,
	"Add":       &Add,
	"Subtract":  &Subtract,
	"Multiply":  &Multiply,
	"Divide":    &Divide,
	"Modulo":    &Modulo,
	"Move":      &Move,
	"SetMemory": &SetMemory,
	"GetMemory": &GetMemory,
}
View Source
var Subtract standardTemplate = standardTemplate{
	Body: `global.get $%s
global.get $%s
i64.sub
global.set $%s`,
	Inputs:  []string{"a", "b"},
	Outputs: []string{"result"},
	FormatBody: func(t standardTemplate, nodeId string, varMap map[string]*ast.Junction) string {
		a := varMap[utils.JunctionKey(nodeId, "a")]
		b := varMap[utils.JunctionKey(nodeId, "b")]
		return fmt.Sprintf(t.Body,
			mapVarJunctionVariable(a.NodeId, a.VarId),
			mapVarJunctionVariable(b.NodeId, b.VarId),
			mapVarJunctionVariable(nodeId, t.Outputs[0]),
		)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL