shithub: mc

ref: da5bfc6d15a50130afdcd37ed9af737a81724506
dir: /mparse/stab.myr/

View raw version
use std

use "types.use"
use "tokdefs.use"
use "tok.use"
use "util.use"

pkg parse =
	const setpkg	: (f : file#, st : stab#, name : byte[:]-> void)
	const mkstab	: (-> stab#)
;;

const mkstab = {
	-> std.mk([
		.super = `std.None,
		.name = "",
		.isfunc = false,
		.syms = std.mkht(stnamehash, stnameeq),
		.types = std.mkht(stnamehash, stnameeq),
		.impls = std.mkht(stnamehash, stnameeq),
		.env = std.mkht(stnamehash, stnameeq),
	])
}

const setpkg = {f, st, name
	if st.name.len != 0
		std.fatal("package name already set for pkg {}\n", st.name)
	;;
	st.name = name
	std.htput(f.ns, name, st)
}

const stnamehash = {n
	-> std.strhash(n.name)
}

const stnameeq = {a, b
	-> std.streq(a.name, b.name)
}