-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pork: it's got it all, ffi, state machine tokenizer, and better IDE s…
…upport
- Loading branch information
Showing
58 changed files
with
925 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// GENERATED CODE FROM PORK AST CODEGEN | ||
package gay.pizza.pork.ast.gen | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@SerialName("importPath") | ||
class ImportPath(val components: List<Symbol>) : Node() { | ||
override val type: NodeType = NodeType.ImportPath | ||
|
||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> = | ||
visitor.visitAll(components) | ||
|
||
override fun <T> visit(visitor: NodeVisitor<T>): T = | ||
visitor.visitImportPath(this) | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (other !is ImportPath) return false | ||
return other.components == components | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = components.hashCode() | ||
result = 31 * result + type.hashCode() | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
import std ffi.malloc | ||
import std ffi.struct | ||
|
||
export let timeval = ffiStructDefine( | ||
"long", "seconds", | ||
"unsigned int", "microseconds" | ||
) | ||
|
||
export let timezone = ffiStructDefine( | ||
"int", "minutes_greenwich", | ||
"int", "dst_time" | ||
) | ||
|
||
func gettimeofday(value, tz) | ||
native ffi "c" "int gettimeofday(struct timeval*, struct timezone*)" | ||
|
||
export func main() { | ||
let pointer = malloc(8192) | ||
println(pointer) | ||
free(pointer) | ||
let time = ffiStructAllocate(timeval) | ||
let zone = ffiStructAllocate(timezone) | ||
let result = gettimeofday(time, zone) | ||
let seconds = ffiStructValue(timeval, "seconds", time) | ||
println("Result:", result) | ||
println("Seconds:", seconds) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
package gay.pizza.pork.ffi | ||
|
||
import java.nio.file.Path | ||
import kotlin.io.path.* | ||
|
||
object FfiMacPlatform : FfiPlatform { | ||
private val frameworksDirectories = listOf( | ||
"/Library/Frameworks" | ||
) | ||
|
||
override fun findLibrary(name: String): Path? { | ||
override fun findLibrary(name: String): String? { | ||
val frameworksToCheck = frameworksDirectories.map { frameworkDirectory -> | ||
Path("$frameworkDirectory/$name.framework/$name") | ||
} | ||
for (framework in frameworksToCheck) { | ||
if (!framework.exists()) continue | ||
return if (framework.isSymbolicLink()) { | ||
return framework.parent.resolve(framework.readSymbolicLink()).absolute() | ||
return framework.parent.resolve(framework.readSymbolicLink()).absolutePathString() | ||
} else { | ||
framework.absolute() | ||
framework.absolutePathString() | ||
} | ||
} | ||
|
||
if (name == "c") { | ||
return "libSystem.dylib" | ||
} | ||
|
||
return null | ||
} | ||
} |
Oops, something went wrong.