aboutsummaryrefslogtreecommitdiff
path: root/std.py
diff options
context:
space:
mode:
Diffstat (limited to 'std.py')
-rw-r--r--std.py60
1 files changed, 42 insertions, 18 deletions
diff --git a/std.py b/std.py
index 5e41935..7d69345 100644
--- a/std.py
+++ b/std.py
@@ -44,26 +44,50 @@ def std_debug_off():
return NebBool(True)
# math
-def std_add(arg1, arg2):
- res = arg1.value + arg2.value
- if isinstance(arg1, NebFloat) or isinstance(arg2, NebFloat):
- return NebFloat(res)
+def std_add(arg, rest):
+ float_type = True if isinstance(arg, NebFloat) else False
+ if isinstance(rest, NebNumber):
+ acc = arg.value + rest.value
+ float_type = float_type or isinstance(rest, NebFloat)
else:
- return NebInt(res)
+ acc = arg.value
+ for item in rest:
+ acc += item.value
+ float_type = float_type or isinstance(item, NebFloat)
+ if float_type:
+ return NebFloat(acc)
+ else:
+ return NebInt(acc)
-def std_subtract(arg1, arg2):
- res = arg1.value - arg2.value
- if isinstance(arg1, NebFloat) or isinstance(arg2, NebFloat):
- return NebFloat(res)
+def std_subtract(arg, rest):
+ float_type = True if isinstance(arg, NebFloat) else False
+ if isinstance(rest, NebNumber):
+ acc = arg.value - rest.value
+ float_type = float_type or isinstance(rest, NebFloat)
+ else:
+ acc = arg.value
+ for item in rest:
+ acc -= item.value
+ float_type = float_type or isinstance(item, NebFloat)
+ if float_type:
+ return NebFloat(acc)
else:
- return NebInt(res)
+ return NebInt(acc)
-def std_multiply(arg1, arg2):
- res = arg1.value * arg2.value
- if isinstance(arg1, NebFloat) or isinstance(arg2, NebFloat):
- return NebFloat(res)
+def std_multiply(arg, rest):
+ float_type = True if isinstance(arg, NebFloat) else False
+ if isinstance(rest, NebNumber):
+ acc = arg.value * rest.value
+ float_type = float_type or isinstance(rest, NebFloat)
+ else:
+ acc = arg.value
+ for item in rest:
+ acc *= item.value
+ float_type = float_type or isinstance(item, NebFloat)
+ if float_type:
+ return NebFloat(acc)
else:
- return NebInt(res)
+ return NebInt(acc)
# strings
def std_concat(arg, rest):
@@ -234,13 +258,13 @@ def build_std():
STD["debug-off"] = [debug_off]
# arithmetic
- add = FuncImpl(NebFunction("+", [NebNumber, NebNumber], NebNumber), std_add)
+ add = FuncImpl(NebFunction("+", [NebNumber, NebNumber], NebNumber, [NebNumber]), std_add)
STD["+"] = [add]
- subtract = FuncImpl(NebFunction("-", [NebNumber, NebNumber], NebNumber), std_subtract)
+ subtract = FuncImpl(NebFunction("-", [NebNumber, NebNumber], NebNumber, [NebNumber]), std_subtract)
STD["-"] = [subtract]
- multiply = FuncImpl(NebFunction("*", [NebNumber, NebNumber], NebNumber), std_multiply)
+ multiply = FuncImpl(NebFunction("*", [NebNumber, NebNumber], NebNumber, [NebNumber]), std_multiply)
STD["*"] = [multiply]
# strings