implement Asm; include "draw.m"; draw : Draw; include "sys.m"; sys: Sys; include "bufio.m"; bufio: Bufio; Iobuf : import bufio; include "regex.m"; regex : Regex; include "dis.m"; dis : Dis; include "asm.m"; init(nil: ref Draw->Context, nil: list of string) { draw = load Draw Draw->PATH; sys = load Sys Sys->PATH; bufio = load Bufio Bufio->PATH; regex = load Regex Regex->PATH; f := sys->open("/usr/m/asm/bruise_TIL.dasm", Sys->OREAD); o := parse(f); } Obj.label_cell(o : self ref Obj, name : string) : int { for(labels := o.labels; labels != nil; labels = tl labels) if((hd labels).name == name) return (hd labels).cell; return -1; } parse_op(line : string) : ref Dis->Inst { return ref Dis->Inst(0, 0, 0, 0, 0); } parse(fd : ref Sys->FD) : ref Obj { obj := ref Obj(nil, nil, nil, nil, "", nil, nil, nil, nil, nil); label, opcode, ca : regex->Re; diag : string; line : string; cell : int; (label, diag) = regex->compile("([a-z]+):", 0); (opcode, diag) = regex->compile("([a-zA-Z]+) (,? ?([^ ,]+))*", 0); (ca, diag) = regex->compile("^ | +\\+", 0); cells : list of ref Cell; gvars, fvars : list of ref Dtype; match : array of (int, int); io := bufio->fopen(fd, Bufio->OREAD); while((line = io.gets('\n')) != nil) { match = regex->execute(label, line); if(match != nil) { sys->print("LABEL %s", line); obj.labels = ref Label(line, len cells) :: obj.labels; continue; } match = regex->execute(ca, line); if(match != nil) { sys->print("CA %s", line); cells = ref Cell.addr((len cells) +1) :: cells; continue; } match = regex->execute(opcode, line); if(match != nil) { sys->print("OP %s", line); cells = ref Cell.op(parse_op(line)) :: cells; continue; } } io.close(); return obj; }