|
@@ -168,7 +168,6 @@ func divi(vm *VM, args ...Value) []Value {
|
|
return IntOk(v1 / v2)
|
|
return IntOk(v1 / v2)
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
func divf(vm *VM, args ...Value) []Value {
|
|
func divf(vm *VM, args ...Value) []Value {
|
|
var v1, v2 float64
|
|
var v1, v2 float64
|
|
_, err := ParseArgs(args, &v1, &v2)
|
|
_, err := ParseArgs(args, &v1, &v2)
|
|
@@ -178,6 +177,23 @@ func divf(vm *VM, args ...Value) []Value {
|
|
return FloatOk(v1 / v2)
|
|
return FloatOk(v1 / v2)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func andb(vm * VM, args ...Value) []Value {
|
|
|
|
+ var v1, v2 bool
|
|
|
|
+ _, err := ParseArgs(args, &v1, &v2)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return Fail(err)
|
|
|
|
+ }
|
|
|
|
+ return BoolOk(v1 && v2)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func orb(vm * VM, args ...Value) []Value {
|
|
|
|
+ var v1, v2 bool
|
|
|
|
+ _, err := ParseArgs(args, &v1, &v2)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return Fail(err)
|
|
|
|
+ }
|
|
|
|
+ return BoolOk(v1 || v2)
|
|
|
|
+}
|
|
|
|
|
|
func val(vm *VM, args ...Value) []Value {
|
|
func val(vm *VM, args ...Value) []Value {
|
|
if len(args) < 1 {
|
|
if len(args) < 1 {
|
|
@@ -284,6 +300,65 @@ func get(vm *VM, val ...Value) []Value {
|
|
return Ok(vm.Lookup(target))
|
|
return Ok(vm.Lookup(target))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func fetchl(vm *VM, args ...Value) []Value {
|
|
|
|
+ var index int
|
|
|
|
+ var list *ListValue
|
|
|
|
+ _, err := ParseArgs(args, &list, &index)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return Fail(err)
|
|
|
|
+ }
|
|
|
|
+ return Ok(list.List[index])
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func storel(vm *VM, args ...Value) []Value {
|
|
|
|
+ var index int
|
|
|
|
+ var list *ListValue
|
|
|
|
+ rest, err := ParseArgs(args, &list, &index)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return Fail(err)
|
|
|
|
+ }
|
|
|
|
+ if len (rest) < 1 {
|
|
|
|
+ return Fail(fmt.Errorf("fetch: need 3 arguments"))
|
|
|
|
+ }
|
|
|
|
+ list.List[index] = rest[0]
|
|
|
|
+ return Ok(list.List[index])
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func fetchm(vm *VM, args ...Value) []Value {
|
|
|
|
+ var index Value
|
|
|
|
+ var hmap *MapValue
|
|
|
|
+ _, err := ParseArgs(args, &hmap, &index)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return Fail(err)
|
|
|
|
+ }
|
|
|
|
+ return Ok(hmap.Map[index])
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func storem(vm *VM, args ...Value) []Value {
|
|
|
|
+ var index Value
|
|
|
|
+ var hmap *MapValue
|
|
|
|
+ rest, err := ParseArgs(args, &hmap, &index)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return Fail(err)
|
|
|
|
+ }
|
|
|
|
+ if len (rest) < 1 {
|
|
|
|
+ return Fail(fmt.Errorf("fetch: need 3 arguments"))
|
|
|
|
+ }
|
|
|
|
+ hmap.Map[index] = rest[0]
|
|
|
|
+ return Ok(hmap.Map[index])
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func newmap(vm *VM, args ...Value) []Value {
|
|
|
|
+ result := make(map[Value] Value)
|
|
|
|
+ for i := 1; i < len(args) ; i+=2 {
|
|
|
|
+ result[args[i-1]] = args[i]
|
|
|
|
+ }
|
|
|
|
+ return Ok(NewMapValue(result))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
func help(vm *VM, val ...Value) [] Value {
|
|
func help(vm *VM, val ...Value) [] Value {
|
|
if len(val) < 1 {
|
|
if len(val) < 1 {
|
|
fmt.Printf("help <callable> will display help on the callable\n\nThe following commands are available:\n")
|
|
fmt.Printf("help <callable> will display help on the callable\n\nThe following commands are available:\n")
|
|
@@ -340,36 +415,26 @@ func exit(vm *VM, val ...Value) [] Value {
|
|
func (vm *VM) RegisterBuiltins() {
|
|
func (vm *VM) RegisterBuiltins() {
|
|
vm.RegisterBuiltinWithHelp("addi", addi, `[Int Int] -> Int: adds two integers together`)
|
|
vm.RegisterBuiltinWithHelp("addi", addi, `[Int Int] -> Int: adds two integers together`)
|
|
vm.RegisterBuiltinWithHelp("addf", addf, `[Int Int] -> Int: adds two floats together`)
|
|
vm.RegisterBuiltinWithHelp("addf", addf, `[Int Int] -> Int: adds two floats together`)
|
|
|
|
+ vm.RegisterBuiltinWithHelp("andb", andb, `[Bool Bool] -> Bool: returns true if all it's arguments are true`)
|
|
vm.RegisterBuiltin("cover", cover)
|
|
vm.RegisterBuiltin("cover", cover)
|
|
|
|
+ vm.RegisterBuiltin("fetchl", fetchl)
|
|
|
|
+ vm.RegisterBuiltin("fetchm", fetchm)
|
|
vm.RegisterBuiltin("sumi", sumi)
|
|
vm.RegisterBuiltin("sumi", sumi)
|
|
vm.RegisterBuiltin("sumf", sumf)
|
|
vm.RegisterBuiltin("sumf", sumf)
|
|
vm.RegisterBuiltin("subi", subi)
|
|
vm.RegisterBuiltin("subi", subi)
|
|
vm.RegisterBuiltin("subf", subf)
|
|
vm.RegisterBuiltin("subf", subf)
|
|
vm.RegisterBuiltin("divi", divi)
|
|
vm.RegisterBuiltin("divi", divi)
|
|
vm.RegisterBuiltin("divf", divf)
|
|
vm.RegisterBuiltin("divf", divf)
|
|
|
|
+ vm.RegisterBuiltin("map", newmap)
|
|
vm.RegisterBuiltin("muli", muli)
|
|
vm.RegisterBuiltin("muli", muli)
|
|
vm.RegisterBuiltin("mulf", mulf)
|
|
vm.RegisterBuiltin("mulf", mulf)
|
|
- err := vm.AddOverload("mul", "mulf", FloatTypeValue, FloatTypeValue)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Printf("Errror registering overload: %s", err)
|
|
|
|
- }
|
|
|
|
- err = vm.AddOverload("mul", "muli", IntTypeValue, IntTypeValue)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Printf("Errror registering overload: %s", err)
|
|
|
|
- }
|
|
|
|
- err = vm.AddOverload("mul", "mulf", FloatTypeValue, IntTypeValue)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Printf("Errror registering overload: %s", err)
|
|
|
|
- }
|
|
|
|
- err = vm.AddOverload("mul", "mulf", IntTypeValue, FloatTypeValue)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Printf("Errror registering overload: %s", err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ vm.RegisterBuiltinWithHelp("orb", orb, `[Bool Bool] -> Bool: returns true if on of it's arguments is true`)
|
|
// vm.RegisterCover("add")
|
|
// vm.RegisterCover("add")
|
|
vm.RegisterBuiltin("p", p)
|
|
vm.RegisterBuiltin("p", p)
|
|
vm.RegisterBuiltin("println", println)
|
|
vm.RegisterBuiltin("println", println)
|
|
- vm.RegisterBuiltin("printf", printf)
|
|
|
|
|
|
+ vm.RegisterBuiltin("printf", printf)
|
|
|
|
+ vm.RegisterBuiltin("storel", storel)
|
|
|
|
+ vm.RegisterBuiltin("storem", storem)
|
|
vm.RegisterBuiltin("trace", trace)
|
|
vm.RegisterBuiltin("trace", trace)
|
|
vm.RegisterBuiltin("to", to)
|
|
vm.RegisterBuiltin("to", to)
|
|
vm.RegisterBuiltin("types", types)
|
|
vm.RegisterBuiltin("types", types)
|
|
@@ -379,8 +444,26 @@ func (vm *VM) RegisterBuiltins() {
|
|
vm.RegisterBuiltin("help", help)
|
|
vm.RegisterBuiltin("help", help)
|
|
vm.RegisterBuiltin("explain", explain)
|
|
vm.RegisterBuiltin("explain", explain)
|
|
vm.RegisterBuiltin("exit", exit)
|
|
vm.RegisterBuiltin("exit", exit)
|
|
- vm.SetHelp("mul", " Num: Multiplies two numbers. Cover for muli and mulf.")
|
|
|
|
|
|
|
|
|
|
+ vm.AddOverloads("mul",
|
|
|
|
+ Over("mulf", FloatTypeValue, FloatTypeValue),
|
|
|
|
+ Over("muli", IntTypeValue, IntTypeValue),
|
|
|
|
+ Over("mulf", FloatTypeValue, IntTypeValue),
|
|
|
|
+ Over("mulf", FloatTypeValue, IntTypeValue))
|
|
|
|
+
|
|
|
|
+ vm.SetHelp("mul", " Num: Multiplies two numbers. Cover for muli and mulf.")
|
|
|
|
+ vm.AddOverloads("fetch",
|
|
|
|
+ Over("fetchl", ListTypeValue, IntTypeValue),
|
|
|
|
+ Over("fetchm", MapTypeValue, AnyTypeValue),
|
|
|
|
+ )
|
|
|
|
+ vm.SetHelp("fetch", " storage, index. Fetch value in storage at given index.")
|
|
|
|
+ /*
|
|
|
|
+ vm.AddOverloads("store",
|
|
|
|
+ Over("storel", ListTypeValue, IntTypeValue, AnyTypeValue),
|
|
|
|
+ Over("storem", MapTypeValue, AnyTypeValue, AnyTypeValue),
|
|
|
|
+ )
|
|
|
|
+ vm.SetHelp("store", " storage, index, value. Store value in storage at given index.")
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|