Exemple #1
0
func (aw *AstWriter) writeString(n parser.Node, data, pad string) {
	aw.writeNodeBase(n.Base(), pad)

	if len(data) > 20 {
		fmt.Fprintf(aw.w, " %T(%.20q...)\n", n, data)
	} else {
		fmt.Fprintf(aw.w, " %T(%q)\n", n, data)
	}
}
Exemple #2
0
func (aw *AstWriter) writeCollection(n parser.Node, l []parser.Node, pad string) {
	aw.writeNodeBase(n.Base(), pad)
	fmt.Fprintf(aw.w, " %T {\n", n)

	for _, v := range l {
		aw.writeNode(v, pad+aw.Indent)
	}

	fmt.Fprintf(aw.w, "%s}\n", pad)
}
Exemple #3
0
func (a *assembler) buildBlockOperand(argv *[]cpu.Word, symbols *[]parser.Node, node parser.Node) (cpu.Word, error) {
	switch tt := node.(type) {
	case *parser.Name:
		if reg, ok := registers[tt.Data]; ok {
			if reg <= 0x7 {
				return reg + 0x10, nil
			}

			if reg == 0x1b {
				return 0x1a, nil
			}

			return 0, NewBuildError(
				a.ast.Files[tt.File()], tt.Line(), tt.Col(),
				"Illegal use of register %q.", tt.Data,
			)
		}

		if addr, ok := a.labels[tt.Data]; ok {
			*symbols = append(*symbols, tt)
			*argv = append(*argv, addr)
			return 0, nil
		}

		a.refs[cpu.Word(len(a.code)+1+len(*argv))] = tt
		*symbols = append(*symbols, tt)
		*argv = append(*argv, 0)
		return 0, nil

	case parser.NumericNode:
		num, err := tt.Parse()
		if err != nil {
			return 0, err
		}

		*symbols = append(*symbols, tt)
		*argv = append(*argv, num)
		return 0, nil
	}

	return 0, NewBuildError(
		a.ast.Files[node.File()], node.Line(), node.Col(),
		"Unexpected node %T. Want Name or Number.", node,
	)
}