import { error } from "./lexer.js"; export class context{ #list = {}; constructor(){ console.log("create"); } add({name,size,amount=1,type = 0, content = 0}){ console.log("add",name+""); this.#list[name+""] = {size,amount,type,content}; console.log(this.#list); } find(name,pos){ let elem = this.#list[name+""]; console.log(this.#list); if(!elem) error("Can not find '"+name+"' in context!"); return elem; } build(){ let out = ` LOC Data_Segment GREG @ `; for(let Name in this.#list){ let { size, amount, type, content } = this.#list[Name]; if(size<=8&&amount==1){ out += `${Name} ${(["BYTE", "WYDE", "TETRA", "TETRA", "OCTA", "OCTA", "OCTA", "OCTA"])[size-1]} ${content}\n`; }else{ out += ` ${name} BYTE ${content} LOC ${name}+${size+amount+1}\n`; } } out+=" LOC #100\nMain"; return out; } }