standardTemplates

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 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 Div 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 Mod 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{"move"},
	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 Mul 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 StandardTemplates = map[string]*standardTemplate{
	"Print": &Print,
	"Add":   &Add,
	"Sub":   &Sub,
	"Mul":   &Mul,
	"Div":   &Div,
	"Mod":   &Mod,
	"Move":  &Move,
}
View Source
var Sub 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