Skip to content

Instantly share code, notes, and snippets.

View AlexCouch's full-sized avatar
😛
Who's asking...?

Alex Couch AlexCouch

😛
Who's asking...?
  • Spokane, Washington area
View GitHub Profile
@AlexCouch
AlexCouch / lexer.kt
Last active July 27, 2020 07:40
A lexer written with coroutines
import arrow.core.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.produce
import kotlinx.coroutines.runBlocking
fun String.advance(idx: Int): Option<Char> =
if(idx >= length){
arrow.core.none()
}else{
/**
* There are three different kinds of contexts:
* 1. Starter
* - A Starter context is a context that starts building a new time object.
* This means that we start with a non-TimeBuilder object such as Time or LocalDateTime, etc
*
* We can formally describe a starter as being the following morphism:
* A -> B
* The entire process of taking one time object and producing a new time object is an endofunctor
* A -> B -> B -> A
const ANIMAL: u8 = 1 << 0;
const TOY: u8 = 1 << 1;
const PET: u8 = 1 << 2;
struct Dog<'d>{
abstraction: u8,
name: &'d str
}
fn main() {
#include <stdint.h>
#include <stdio.h>
#define ANIMAL (1 << 0)
#define TOY (1 << 1)
#define PET (1 << 2)
typedef struct {
uint8_t abstraction;
char** name;
//Initialize the core bytecode engine. The result is the built engine object that can then be used by the IO Apps
val HIREngine = BytecodeEngine.init{
configureBytecode{
//Configure a chunk of bytecode called "identifier" which will instruct the engine how to construct this chunk.
//The order to which you call these factory methods dictates the exact order and mechanism the engine will construct the chunk
//This chunk can then be referenced by the IO Apps, for constructing a certain chunk from a certain input at a certain time
//Or for deserializing, converting, or "lowering" by the output apps.
createChunk("identifier"){
createOpcode(0x11){
this.name = "IDENTIFIER"
HIR: FE1163726461433A5C70726F6A656374735C6B6F746C696E782D6C6C766D5C746F796C616E675C72756E5C66696C65735C746573742E746F7962121320231761646451177817496E745251177917496E745253496E745455182027303541303B17783C1565000000020000000B6667000000020000000B68163F42303B17793C1565000000020000000F6667000000020000000F68163F431565000000020000000B666700000002000000106816363F156500000002000000046667000000020000000F6816282F195615650000000100000000666700000003000000006816242F20231773756251177817496E745251177917496E745253496E745455182027303541303B17783C1565000000060000000B6667000000060000000B68163F42303B17793C1565000000060000000F6667000000060000000F68163F441565000000060000000B666700000006000000106816363F156500000006000000046667000000060000000F6816282F195615650000000500000000666700000007000000006816242F2023176D756C51177817496E745251177917496E745253496E745455182027303541303B17783C15650000000A0000000B66670000000A0000000B68163F42303B17793C15650000000A0000000F66670000000A0000000F68163F4515650000000A0000000B66670000000A000000106816363F156
def val test: Int = 5 * 10
def abstract class SomeClass<T>{
def abstract fun someMemberFunction(t: T)
}
def class SomeClassForString: SomeClass<String>(){
def impl fun someMemberFunction(t: String){
println(t)
}
object DesktopComputerBlock : Block(Material.IRON), ITileEntityProvider {
init{
val name = "desktop"
this.unlocalizedName = name
this.registryName = ResourceLocation(modid, name)
this.setCreativeTab(CreativeTabs.MISC)
}
override fun onBlockActivated(worldIn: World, pos: BlockPos, state: IBlockState, playerIn: EntityPlayer, hand: EnumHand, facing: EnumFacing, hitX: Float, hitY: Float, hitZ: Float): Boolean {
if(!worldIn.isRemote && hand == EnumHand.MAIN_HAND){
#memauto //Garbage collection turned on; no pointers/references allowed!!
//Compile-time constants
#define PHASE_ONE
#define PHASE_TWO
#define PHASE_THREE
//Injection site, indicated by a * at the end of the name of the function; only one!!!
fun test*(args: Array<String>){
println("Starting test...")
import com.google.common.reflect.TypeToken
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import net.minecraft.client.Minecraft
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.util.text.TextComponentString
import net.minecraft.world.WorldServer
import net.minecraftforge.event.world.WorldEvent