Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
00110001011100010111100001111010 committed Jul 12, 2024
2 parents d2ad6ce + 20e749b commit 008a935
Show file tree
Hide file tree
Showing 44 changed files with 738 additions and 503 deletions.
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

34 changes: 0 additions & 34 deletions .idea/artifacts/Lazurite_jar.xml

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/compiler.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/encodings.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/jarRepositories.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

18 changes: 0 additions & 18 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

124 changes: 0 additions & 124 deletions .idea/uiDesigner.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

47 changes: 47 additions & 0 deletions src/main/java/com/kingmang/lazurite/core/TypesCastExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.kingmang.lazurite.core

import com.kingmang.lazurite.exceptions.LzrException
import com.kingmang.lazurite.runtime.ClassInstanceValue
import com.kingmang.lazurite.runtime.values.*

fun LzrValue.asLzrNumber(lazyMessage: (() -> String)? = null): LzrNumber {
return asLzrType(Types.NUMBER, lazyMessage)
}

fun LzrValue.asLzrString(lazyMessage: (() -> String)? = null): LzrString {
return asLzrType(Types.STRING, lazyMessage)
}

fun LzrValue.asLzrArray(lazyMessage: (() -> String)? = null): LzrArray {
return asLzrType(Types.ARRAY, lazyMessage)
}

fun LzrValue.asLzrMap(lazyMessage: (() -> String)? = null): LzrMap {
return asLzrType(Types.MAP, lazyMessage)
}

fun LzrValue.asLzrFunction(lazyMessage: (() -> String)? = null): LzrFunction {
return asLzrType(Types.FUNCTION, lazyMessage)
}

fun LzrValue.asLzrClass(lazyMessage: (() -> String)? = null): ClassInstanceValue {
return asLzrType(Types.CLASS, lazyMessage)
}

inline fun <reified T : Any> LzrValue.asLzrType(targetType: Int, noinline lazyMessage: (() -> String)?): T {
if (isLzrType(targetType)) return this as T
if (lazyMessage == null) throwTypeCastException(type(), targetType)
throwTypeException(lazyMessage.invoke())
}

fun throwTypeCastException(origin: Int, target: Int): Nothing {
throwTypeCastException(Types.typeToString(origin), Types.typeToString(target))
}

fun throwTypeCastException(origin: String, target: String): Nothing {
throwTypeException("Cannot cast $origin to $target")
}

fun throwTypeException(message: String): Nothing {
throw LzrException("TypeException", message)
}
30 changes: 30 additions & 0 deletions src/main/java/com/kingmang/lazurite/core/TypesCheckExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.kingmang.lazurite.core

import com.kingmang.lazurite.runtime.values.LzrValue


fun LzrValue.isLzrNumber(): Boolean {
return isLzrType(Types.NUMBER)
}

fun LzrValue.isLzrString(): Boolean {
return isLzrType(Types.STRING)
}

fun LzrValue.isLzrArray(): Boolean {
return isLzrType(Types.ARRAY)
}

fun LzrValue.isLzrMap(): Boolean {
return isLzrType(Types.MAP)
}

fun LzrValue.isLzrFunction(): Boolean {
return isLzrType(Types.FUNCTION)
}

fun LzrValue.isLzrClass(): Boolean {
return isLzrType(Types.CLASS)
}

inline fun LzrValue.isLzrType(targetType: Int): Boolean = type() == targetType
33 changes: 33 additions & 0 deletions src/main/java/com/kingmang/lazurite/core/TypesSafeCastExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kingmang.lazurite.core

import com.kingmang.lazurite.runtime.ClassInstanceValue
import com.kingmang.lazurite.runtime.values.*

fun LzrValue.asLzrNumberOrNull(): LzrNumber? {
return asLzrTypeOrNull(Types.NUMBER)
}

fun LzrValue.asLzrStringOrNull(): LzrString? {
return asLzrTypeOrNull(Types.STRING)
}

fun LzrValue.asLzrArrayOrNull(): LzrArray? {
return asLzrTypeOrNull(Types.ARRAY)
}

fun LzrValue.asLzrMapOrNull(): LzrMap? {
return asLzrTypeOrNull(Types.MAP)
}

fun LzrValue.asLzrFunctionOrNull(): LzrFunction? {
return asLzrTypeOrNull(Types.FUNCTION)
}

fun LzrValue.asLzrClassOrNull(): ClassInstanceValue? {
return asLzrTypeOrNull(Types.CLASS)
}

inline fun <reified T : Any> LzrValue.asLzrTypeOrNull(targetType: Int): T? {
if (isLzrType(targetType)) return this as T
return null
}
Loading

1 comment on commit 008a935

@00110001011100010111100001111010
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ОООЙОЙОЙ все норм все в норме идея дура пон да

Please sign in to comment.