Skip to content

Commit d025618

Browse files
committed
Initial commit
0 parents  commit d025618

File tree

7 files changed

+819
-0
lines changed

7 files changed

+819
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
target/
3+
*.iml

LICENSE

+623
Large diffs are not rendered by default.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Pikt
2+
Pikt is a work-in-progress image, pixel-based esoteric programming language that aims at generating fast and lightweight from aesthetically pleasant image sources.
3+
Pikt compiles executables via the Kotlin compiler, therefore compilation for both JVM and native targets is planned.

pom.xml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>eu.iamgio.pikt</groupId>
8+
<artifactId>pikt</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<kotlin.version>1.4.30</kotlin.version>
13+
</properties>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.jetbrains.kotlin</groupId>
18+
<artifactId>kotlin-stdlib-jdk8</artifactId>
19+
<version>${kotlin.version}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.jetbrains.kotlin</groupId>
23+
<artifactId>kotlin-test</artifactId>
24+
<version>${kotlin.version}</version>
25+
<scope>test</scope>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<sourceDirectory>src/main/kotlin</sourceDirectory>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.jetbrains.kotlin</groupId>
34+
<artifactId>kotlin-maven-plugin</artifactId>
35+
<version>${kotlin.version}</version>
36+
<executions>
37+
<execution>
38+
<id>compile</id>
39+
<phase>compile</phase>
40+
<goals>
41+
<goal>compile</goal>
42+
</goals>
43+
</execution>
44+
<execution>
45+
<id>test-compile</id>
46+
<phase>test-compile</phase>
47+
<goals>
48+
<goal>test-compile</goal>
49+
</goals>
50+
</execution>
51+
</executions>
52+
<configuration>
53+
<jvmTarget>1.8</jvmTarget>
54+
</configuration>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
59+
60+
</project>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package eu.iamgio.pikt
2+
3+
fun main() {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package eu.iamgio.pikt.properties
2+
3+
/**
4+
* Defines system for the executable to run on.
5+
*
6+
* @param argName command-line value (target=value)
7+
* @param compilerCommand command to be executed in order to let the Kotlin compiler generate an executable. (compilerPath, kotlinPath, targetExecutablePath) -> command
8+
*
9+
* @author Giorgio Garofalo
10+
*/
11+
enum class CompilationTarget(
12+
val argName: String,
13+
val compilerCommand: (String, String, String) -> String
14+
) {
15+
/**
16+
* Generates a cross-platform .jar executable
17+
*/
18+
JVM("jvm", { compilerPath, kotlinPath, targetExecutablePath -> "$compilerPath $kotlinPath -include-runtime -d $targetExecutablePath.jar" }),
19+
20+
/**
21+
* Generates a .exe executable on Windows and a .kexe executable on OSX and Linux
22+
*/
23+
NATIVE("native", { compilerPath, kotlinPath, targetExecutablePath -> "$compilerPath $kotlinPath -o $targetExecutablePath" })
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package eu.iamgio.pikt.properties
2+
3+
import java.io.File
4+
import kotlin.system.exitProcess
5+
6+
/**
7+
* Storage for properties passed from command line.
8+
*
9+
* @param source source image file ("-Dsource")
10+
* @param output output executable file without extension ("-Doutput")
11+
* @param target compilation target ("-Dtarget")
12+
* @param jvmCompilerPath optional path to the Kotlin/JVM compiler (required if [target] is [CompilationTarget.JVM]) ("-Djvmcompiler")
13+
* @param nativeCompilerPath optional path to the Kotlin/Native compiler (required if [target] is [CompilationTarget.NATIVE]) ("-Dnativecompiler")
14+
* // TODO colors properties
15+
* @author Giorgio Garofalo
16+
*/
17+
data class PiktProperties(
18+
val source: File,
19+
val output: File,
20+
val target: CompilationTarget,
21+
val jvmCompilerPath: String?,
22+
val nativeCompilerPath: String?,
23+
)
24+
25+
/**
26+
* Single-instance object that parses JVM properties into a [PiktProperties] instance
27+
*
28+
* @author Giorgio Garofalo
29+
*/
30+
object PiktPropertiesRetriever {
31+
32+
/**
33+
* Converts raw JVM properties to parsed [PiktProperties].
34+
* If any required field is missing or invalid it prints an error and exits.
35+
* @return parsed properties
36+
*/
37+
fun retrieve(): PiktProperties {
38+
val sourceProperty = System.getProperty("source")
39+
val outputProperty = System.getProperty("source")
40+
val targetProperty = System.getProperty("target")
41+
val jvmCompilerPathProperty = System.getProperty("jvmcompiler")
42+
val nativeCompilerPathProperty = System.getProperty("nativecompiler")
43+
44+
var isError = false
45+
46+
fun error(message: String) {
47+
System.err.println(message)
48+
isError = true
49+
}
50+
51+
// Source image file
52+
val source: File? = if(sourceProperty == null) {
53+
error("Source file (-Dsource) is not set.")
54+
null
55+
} else File(sourceProperty).also {
56+
if(!it.exists()) {
57+
error("Source file $it does not exist.")
58+
}
59+
}
60+
61+
// Output file without extension
62+
val output: File? = when {
63+
outputProperty != null -> File(outputProperty)
64+
source != null -> File(source.parent, source.nameWithoutExtension)
65+
else -> null
66+
}
67+
68+
// Compilation target type
69+
val target = CompilationTarget.values().firstOrNull { it.argName == targetProperty }
70+
if(target == null) {
71+
error("Compilation target $target is invalid. 'jvm' and 'native' are supported targets.")
72+
}
73+
74+
// JVM compiler
75+
if(jvmCompilerPathProperty == null && CompilationTarget.JVM == target) {
76+
error("JVM compiler (-Djvmcompiler) is not set but target is JVM.")
77+
} else if(!File(jvmCompilerPathProperty).exists()) {
78+
error("JVM compiler $jvmCompilerPathProperty does not exist.")
79+
}
80+
81+
// Native compiler
82+
if(nativeCompilerPathProperty == null && CompilationTarget.NATIVE == target) {
83+
error("Native compiler (-Dnativecompiler) is not set but target is native.")
84+
} else if(!File(nativeCompilerPathProperty).exists()) {
85+
error("Native compiler $nativeCompilerPathProperty does not exist.")
86+
}
87+
88+
if(isError) {
89+
System.err.println("Could not initialize Pikt properties. Exiting.")
90+
exitProcess(-1)
91+
}
92+
93+
return PiktProperties(
94+
source = source!!,
95+
output = output!!,
96+
target = target!!,
97+
jvmCompilerPath = jvmCompilerPathProperty,
98+
nativeCompilerPath = nativeCompilerPathProperty,
99+
)
100+
}
101+
}

0 commit comments

Comments
 (0)