Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler x #17

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a58e8d4
multi expressions, fix alpha tokens, properly call native sigs(), and…
XomaDev Aug 5, 2024
5cfc57e
migrate and test stuff into new syntax
XomaDev Aug 6, 2024
8175243
add some vision
XomaDev Aug 6, 2024
45682f7
preparing refactor for bytecode compiler
XomaDev Aug 15, 2024
331db3d
2nd: prepare and refactor for bytecode compiler
XomaDev Aug 15, 2024
6fc2545
3: Refactor for VM
XomaDev Aug 15, 2024
72b7cd1
creating a vm
XomaDev Aug 16, 2024
8ca6a59
creating a vm and disassembler
XomaDev Aug 16, 2024
1ca2e49
doing some progress
XomaDev Aug 16, 2024
8f1aeb9
doing some more progress
XomaDev Aug 16, 2024
8d54aea
continue working on the VM
XomaDev Aug 16, 2024
9411d88
continue working on the VM
XomaDev Aug 16, 2024
95d41b0
continue making a VM
XomaDev Aug 16, 2024
63c00d2
making assembler
XomaDev Aug 16, 2024
36c55cc
continue working on a vm
XomaDev Aug 16, 2024
559c623
making assembler
XomaDev Aug 17, 2024
22bd249
Merge remote-tracking branch 'origin/main'
XomaDev Aug 17, 2024
b2c7719
meow making assembler
XomaDev Aug 17, 2024
b7015b8
#2 meow making assembler
XomaDev Aug 17, 2024
b77cb5a
#3 meow making assembler
XomaDev Aug 17, 2024
0190e7f
4 meow making assembler
XomaDev Aug 17, 2024
47ba48c
5 meow making assembler
XomaDev Aug 17, 2024
439fd78
6 meow making assembler
XomaDev Aug 17, 2024
60ecf9f
7 meow making assembler
XomaDev Aug 18, 2024
e08e064
7.5 meow making assembler
XomaDev Aug 18, 2024
ce9ef71
8 meow making assembler
XomaDev Aug 18, 2024
e3d5ef3
9 meow making assembler
XomaDev Aug 18, 2024
9fa6c97
10 meow making assembler
XomaDev Aug 18, 2024
e9ba8fa
11 meow making assembler
XomaDev Aug 18, 2024
5f9b453
fib testing impl
XomaDev Aug 19, 2024
82c1a63
stack frames
XomaDev Aug 19, 2024
1eedb32
uwu
XomaDev Aug 19, 2024
dc66612
copy() bytecode and trying tea VM
XomaDev Aug 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Compiler/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions Compiler/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Compiler/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Compiler/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions Compiler/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
id("java")
kotlin("jvm")
id("war")
id("org.teavm") version "0.9.2"
}

group = "space.themelon.eia64"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
}

dependencies {
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
implementation(kotlin("stdlib-jdk8"))
implementation(teavm.libs.jsoApis)
}

teavm {
js {
addedToWebApp = true
mainClass.set("space.themelon.eia64.compiler.web.WebMain")
targetFileName.set("example.js")
}
}

tasks.register<Copy>("unzipWar") {
group = "build"

// just unzip .war after build is finishedc
val buildDirectory = layout.buildDirectory.asFile.get().absolutePath
from(zipTree("$buildDirectory/libs/${project.name}-${project.version}.war"))
into("$buildDirectory/unzipped-war")
dependsOn("build")
}

tasks.named("build") {
finalizedBy("unzipWar")
}

tasks.test {
useJUnitPlatform()
}

kotlin {
jvmToolchain(11)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 14 22:16:00 IST 2024
#Thu Aug 15 23:01:51 IST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions Compiler/playground/hello.eia
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"me" + "ow"
7 changes: 7 additions & 0 deletions Compiler/playground/hello.eia.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int 1
int 2
int 3
mul
add
print
halt
Binary file added Compiler/playground/hello.eia.e
Binary file not shown.
8 changes: 4 additions & 4 deletions settings.gradle.kts → Compiler/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginManagement {
plugins {
kotlin("jvm") version "2.0.0"
kotlin("jvm") version "2.0.10"
}
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}
rootProject.name = "Eia64"
include("tests")
rootProject.name = "Compiler"

44 changes: 44 additions & 0 deletions Compiler/src/main/java/space/themelon/eia64/compiler/Compiler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package space.themelon.eia64.compiler

import space.themelon.eia64.compiler.bytecode.BytecodeVisitor
import space.themelon.eia64.compiler.bytecode.Dumper
import space.themelon.eia64.compiler.syntax.Lexer
import java.io.File
import java.io.FileOutputStream

class Compiler(
outputFile: File,
) {

companion object {
const val DEBUG = true
const val STD_LIB = "" // TODO
const val EXECUTION_DIRECTORY = "" // TODO
}

private val dumper = Dumper(FileOutputStream(outputFile))

private val externalExecutors = HashMap<String, BytecodeVisitor>()
private val mainEvaluator = BytecodeVisitor(dumper)

private val externalParsers = HashMap<String, Parser>()
private val mainParser = Parser(this)

// for now it is a one time use
fun fromString(source: String) {
mainEvaluator.dump(mainParser.parse(Lexer(source).tokens))
dumper.close()
}

// Dont touch them for now
// Let's deal with them later
fun addModule(sourceFile: String, name: String): Boolean {
if (externalParsers[name] != null) return false
externalParsers[name] = Parser(this).also { it.parse(getTokens(sourceFile)) }
return true
}

private fun getTokens(sourceFile: String) = Lexer(File(sourceFile).readText()).tokens

fun getModule(name: String) = externalParsers[name] ?: throw RuntimeException("Could not find module '$name'")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package space.themelon.eia64.compiler

class CompilerException(message: String): Exception(message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package space.themelon.eia64.compiler

import space.themelon.eia64.compiler.bytecode.Bytecode
import java.io.File
import java.io.FileWriter
import java.util.*

class Disassembler(
compiledFile: File,
outputFile: File
) {
// A program that converts compiled Eia code into assembly like human-readable format

private val bytes: ByteArray = compiledFile.readBytes()

private var index = 0
private val size: Int = compiledFile.length().toInt()

private val writer: FileWriter = FileWriter(outputFile)

init {
writer.use {
while (!isEOF()) {
disassemble()
}
}
}

private fun disassemble() {
val instruction = Bytecode.entries[next().toInt()]
val line = StringJoiner(" ")
line.add(instruction.name.lowercase())

when (instruction) {
Bytecode.INT -> line.add(readInt32().toString())
else -> { }
}

writer.write(line.toString())
writer.write("\n")
}

private fun readInt32() =
next().toInt() and 255 or
(next().toInt() and 255 shl 8) or
(next().toInt() and 255 shl 16) or
(next().toInt() and 255 shl 24)

private fun next() = bytes[index++]

private fun isEOF(): Boolean = index == size

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package space.themelon.eia64
package space.themelon.eia64.compiler

import space.themelon.eia64.expressions.*
import space.themelon.eia64.expressions.ArrayLiteral
import space.themelon.eia64.expressions.FunctionExpr
import space.themelon.eia64.signatures.Signature
import space.themelon.eia64.syntax.Token
import space.themelon.eia64.compiler.expressions.*
import space.themelon.eia64.compiler.signatures.Signature
import space.themelon.eia64.compiler.syntax.Token

abstract class Expression(
val marking: Token? = null,
Expand Down Expand Up @@ -34,6 +32,7 @@ abstract class Expression(
fun unaryOperation(expr: UnaryOperation): R
fun binaryOperation(expr: BinaryOperation): R
fun expressions(list: ExpressionList): R
fun expressionBind(bind: ExpressionBind): R
fun nativeCall(call: NativeCall): R
fun cast(cast: Cast): R
fun scope(scope: Scope): R
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package space.themelon.eia64.analysis
package space.themelon.eia64.compiler

import space.themelon.eia64.syntax.Token
import space.themelon.eia64.compiler.syntax.Token

data class ModuleInfo(
val where: Token, // for debugging and throwing errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package space.themelon.eia64.runtime
package space.themelon.eia64.compiler

class Nothing {
companion object {
Expand Down
Loading