Added value checking with 'as' conversion + minor fixes to testmarkup.md

This commit is contained in:
nocturn9x 2021-03-01 19:28:58 +01:00
parent 4a9f210e28
commit cd180fe4d7
3 changed files with 30 additions and 7 deletions

View File

@ -29,10 +29,11 @@ import ../config
import ../memory
import ../meta/opcode
import arraylist
when DEBUG_TRACE_ALLOCATION:
import strformat
import exception
import strformat
import parseutils
import strutils
proc typeName*(self: ptr Obj): string =
@ -433,10 +434,16 @@ proc objAs*(self: ptr Obj, other: ObjectType): returnType =
of ObjectType.Integer:
case self.kind:
of ObjectType.String:
var str = cast[ptr String](self).toStr()
for c in str:
if not c.isDigit():
result.kind = returnTypes.Exception
result.result = newTypeError(&"invalid literal for int: '{str}'")
return
var intVal: int
discard parseInt(cast[ptr String](self).toStr(), intVal)
discard parseInt(str, intVal)
result.result = intVal.asInt()
of ObjectType.Float:
of ObjectType.Float:
var floatVal: float64
discard (parseFloat(cast[ptr Float](self).stringify(), floatVal))
result.result = int(floatVal).asInt()
@ -447,6 +454,22 @@ proc objAs*(self: ptr Obj, other: ObjectType): returnType =
of ObjectType.Float:
case self.kind:
of ObjectType.String:
var str = cast[ptr String](self).toStr()
var seenDot = false
for c in str:
if not c.isDigit():
if c == '.':
if seenDot:
result.kind = returnTypes.Exception
result.result = newTypeError(&"invalid literal for float: '{str}'")
return
else:
seenDot = true
continue
else:
result.kind = returnTypes.Exception
result.result = newTypeError(&"invalid literal for float: '{str}'")
return
var floatVal: float64
discard parseFloat(cast[ptr String](self).toStr(), floatVal)
result.result = floatVal.asFloat()

View File

@ -18,10 +18,10 @@ const language = 1
when language == 1:
const aa* = "ICBfX18gICAgX19fICAgX19fICBfX18gIF9fXyAgX19fICAgICAgIF9fICAgICAgX18gIF9fXyAgICBfX18gICBfX18gIF9fXyAgX19fICBfX18gCiAvIF8gXCAgLyBfIFwgfCBfIFwvIF9ffHxfIF98fCBfX3wgICAgICBcIFwgICAgLyAvIC8gXyBcICAvIF8gXCB8IF8gXC8gX198fF8gX3x8IF9ffAp8IChfKSB8fCAoXykgfHwgIF8vXF9fIFwgfCB8IHwgX3wgICAgICAgIFwgXC9cLyAvIHwgKF8pIHx8IChfKSB8fCAgXy9cX18gXCB8IHwgfCBffCAKIFxfX18vICBcX19fLyB8X3wgIHxfX18vfF9fX3x8X19ffCAgICAgICAgXF8vXF8vICAgXF9fXy8gIFxfX18vIHxffCAgfF9fXy98X19ffHxfX198Cgo="
const bb* = "VXd1IFdlIG1hZGUgYSBmKmNreSB3dWNreSEhIEEgd2l0dGxlIGYqY2tvIGJvaW5nbyE="
const cc* = "VGhlIGNvZGUgbW9ua2V5cyBhdCBvdXIgaGVhZHF1YXJ0ZXJzIGFyZSB3b3JraW5nIFZFV1kgSEFXRCB0byBmaXggdGhpcyEK"
proc getCurrentExceptionMessage*: string =
when language == 1:
echo decode aa

View File

@ -42,7 +42,7 @@ Modelines also have to be closed by a ']' character
on the end of this line. These lines may not contain
whitespace before the opening '[' or "//[" nor after then ending
']' characters. Inside the brackets, letters (case
insensitive), numbers, underscores and dashes form\
insensitive), numbers, underscores and dashes form
a name describing what the modeline does.
```
@ -138,7 +138,7 @@ There are two kinds of source modes, raw and mixed.
Mixed source mode can be entered if the detail `mixed`
is specified. Raw source mode can be entered if the
detail `raw` is specified. When no detail is specified,
raw source mode is entered.
raw source mode is assumed.
In raw source mode, all lines in the mode are
appended as they are to the JAPL source. In mixed