Skip to content

Instantly share code, notes, and snippets.

View mlugg's full-sized avatar

Matthew Lugg mlugg

View GitHub Profile
@mlugg
mlugg / decl.md
Last active March 12, 2024 14:20
Zig Wars: Episode III -- Revenge of the Decl

The Problem

Decl has two main responsibilities today.

The first is to act as the "subject" of semantic analysis for anything analyzed in a comptime context. For instance, when analyzing the value of a container-level const, that declaration's Decl is the "owner" of that Sema; errors are marked on it, source locations resolved relative to it, etc. This is also where type owner decls come from - we need some context in which to perform type resolution, so we need a Decl associated with the type itself.

The second is to represent a globally named and/or addressable value. For instance, container-level consts are named and addressable. More interestingly, so are generic instantiations - you can't take their address in Zig today, but they sure as hell have one, and same with name. This is where function instance owner decls come from.

Interestingly, above, we found that owner decls for types and owner decls for function instances are fulfiling two totally separate purposes! To me, tha

@mlugg
mlugg / incremental.md
Last active September 28, 2023 02:34
Incremental Compilation and Dependency Tracking

Definitions

A Decl, like today, is either:

  • A struct, union, enum, or opaque (i.e. a type with a namespace)
  • A container-scope const, var, or fn

Types are immutable. Whenever a type declaration is analyzed, it gets it from the InternPool, keyed on the current generation (so re-analysis of a type declaration across generations always creates a distinct type). The existing owner decl is used, but its value updated to refer to the new type.

@mlugg
mlugg / FastList.hs
Last active November 1, 2020 21:23
Haskell implementation of lists with fast cons/snoc/append
{-
- This is free and unencumbered software released into the public domain.
-
- Anyone is free to copy, modify, publish, use, compile, sell, or
- distribute this software, either in source code form or as a compiled
- binary, for any purpose, commercial or non-commercial, and by any
- means.
-
- In jurisdictions that recognize copyright laws, the author or authors
- of this software dedicate any and all copyright interest in the
{-# LANGUAGE Trustworthy, OverloadedStrings, LambdaCase #-}
module Main where
import Network.Socket
import Network.Socket.ByteString
import Network.Run.TCP
import Common
import Parse
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
module Main where
import Control.Applicative
import Text.Printf
@mlugg
mlugg / BakedModelDispatcherDummyGas.java
Created June 14, 2019 16:06
DummyGasItem rendering code
package uk.co.mlugg.addedcells.mekanism.item.render;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
@mlugg
mlugg / gist:3b42263ca0d2c3e24ab48968850f4875
Created November 13, 2016 18:37
IRC Library Sample Code
import IRCClient
client = IRCClient()
client.connect("irc.vktec.co.uk", "Nick", "Username")
@client.eventHandler("chanMsg")
def onChanMsg(sender, message, action):
# Do something
@client.eventHandler("privMsg")