diff --git a/src/core.nim b/src/core.nim index a217456..cd121d2 100644 --- a/src/core.nim +++ b/src/core.nim @@ -174,6 +174,18 @@ proc command*(cmnd: string, dataStack: var TStack, vars, gvars: var PType) = if first.kind == ntInt and second.kind == ntInt: dataStack.push(newBool(second.iValue < first.iValue)) + of "and": + var first = dataStack.pop() + var second = dataStack.pop() + if first.kind == ntBool and second.kind == ntBool: + dataStack.push(newBool(second.bValue and first.bValue)) + + of "or": + var first = dataStack.pop() + var second = dataStack.pop() + if first.kind == ntBool and second.kind == ntBool: + dataStack.push(newBool(second.bValue or first.bValue)) + of "=": var first = dataStack.pop() var second = dataStack.pop() @@ -280,13 +292,38 @@ proc command*(cmnd: string, dataStack: var TStack, vars, gvars: var PType) = else: raise invalidTypeErr($first.kind & " and " & $second.kind, "float and float", "pow") + of "round": + var first = dataStack.pop() + if first.kind == ntFloat: + dataStack.push(newInt(round(first.fValue))) + else: + raise invalidTypeErr($first.kind, "float", "round") + # Type conversion + of "type": + var first = dataStack.pop() + dataStack.push(newString($first.kind)) + of "int>float": var first = dataStack.pop() if first.kind == ntInt: dataStack.push(newFloat(float(first.iValue))) else: raise invalidTypeErr($first.kind, "int", "int>float") + + of "float>int": + var first = dataStack.pop() + if first.kind == ntFloat: + dataStack.push(newInt(int(first.fValue))) + else: + raise invalidTypeErr($first.kind, "float", "float>int") + + of "string>int": + var first = dataStack.pop() + if first.kind == ntString: + dataStack.push(newInt(first.value.parseInt())) + else: + raise invalidTypeErr($first.kind, "string", "string>int") # Exception handling of "try": diff --git a/src/interpreter.nim b/src/interpreter.nim index c0fea70..7b7aa98 100644 --- a/src/interpreter.nim +++ b/src/interpreter.nim @@ -109,6 +109,21 @@ proc toString*(item: PType, stack = False): string = else: raise newException(ERuntimeError, errorLine() & "Error: Unexpected AstNode in `$`, " & $item.node.kind) +proc `$`*(kind: TTypes): string = + case kind + of ntInt: return "int" + of ntFloat: return "float" + of ntString: return "string" + of ntBool: return "bool" + of ntList: return "list" + of ntQuot: return "quot" + of ntDict: return "dict" + of ntNil: return "nil" + of ntCmnd: return "__cmnd__" + of ntVar: return "var" + of ntFunc: return "__func__" + of ntASTNode: return "__ASTNode__" + proc isEqual*(first, second: PType): bool = if first.kind == second.kind: case first.kind diff --git a/src/system.nael b/src/system.nael index 41a1148..73e93a6 100644 --- a/src/system.nael +++ b/src/system.nael @@ -23,3 +23,6 @@ each [list, quo] ); join [list, seperator] (i let, i 0 =, s let, s "" =, (i get, list get len 1 - <) (s get (i get 0 == !) (seperator get +) () if, list get, i get nth, + s swap =, i i get inc =) while, s get); + +<= [first, second] (first get second get == first get second get < or); +>= [x,y] (y get x get <=); \ No newline at end of file diff --git a/todo.markdown b/todo.markdown index 14a239d..d1b2b6a 100644 --- a/todo.markdown +++ b/todo.markdown @@ -5,7 +5,7 @@ nael todo list * tuples * dictionaries * Loading of C Libraries -* Functions for converting types +* Functions for converting types - **Partly Done** * `string>int` * `int>string` * `float>string` @@ -14,4 +14,5 @@ nael todo list * **FIXED** * Make every error, report it's origin(function). * `[0, 0] Error: Wrong types... @ +` - **Partly done** -* Make global variables work, the `def` keyword. \ No newline at end of file +* Make global variables work, the `def` keyword. +* Make raising exceptions work, and change any functions that need exception raising, to use raise. \ No newline at end of file