Пример #1
0
Файл: lpp.go Проект: kpmy/lomo
func (p *pr) varDecl() {
	assert.For(p.sym.Code == lss.Var || p.sym.Code == lss.Reg, 20, "VAR block expected")
	mod := mods.NONE
	if p.is(lss.Reg) {
		mod = mods.REG
	}
	p.next()
	for {
		if p.await(lss.Ident, lss.Delimiter, lss.Separator) {
			var vl []*ir.Variable
			for {
				id := p.ident()
				v := &ir.Variable{Name: id, Unit: p.target.unit}
				vl = append(vl, v)
				p.next()
				if mod == mods.NONE && p.await(lss.Minus) || p.is(lss.Plus) {
					v.Modifier = mods.SymMod[p.sym.Code]
					p.next()
				} else if mod != mods.NONE && p.is(lss.Minus) || p.is(lss.Plus) {
					p.mark("registers private only")
				} else if mod == mods.REG {
					v.Modifier = mods.REG
				}
				if p.await(lss.Comma, lss.Separator) {
					p.next()
					p.pass(lss.Separator)
				} else {
					break
				}
			}
			if p.await(lss.Ident, lss.Separator) {
				tb := &ir.Type{}
				p.typ(p.resolve, tb)
				for _, v := range vl {
					v.Type = *tb
					if !tb.Basic {
						p.target.foreign(v.Name, v)
					}
					if !tb.Basic && v.Modifier != mods.NONE {
						p.mark("only hidden foreigns allowed")
					}
					p.target.obj(v.Name, v)
				}
			} else if p.is(lss.Unit) {
				p.next()
				tb := ir.Type{}
				tb.Basic = true
				tb.Builtin = &ir.BuiltinType{Code: types.UNIT}
				for _, v := range vl {
					v.Type = tb
					p.target.obj(v.Name, v)
				}
			} else {
				p.mark("type or identifier expected")
			}
		} else {
			break
		}
	}
}
Пример #2
0
func (p *common) typ(resolve lpp.ForeignResolver, t *ir.Type) {
	assert.For(p.sym.Code == lss.Ident, 20, "type identifier expected here but found ", p.sym.Code)
	id := p.ident()
	if it := types.TypMap[id]; it != types.UNDEF {
		t.Basic = true
		t.Builtin = &ir.BuiltinType{Code: it}
	} else if ft := resolve(id); ft != nil { //append import resolver
		t.Basic = false
		t.Foreign = ft
	} else {
		p.mark("undefined type ", id)
	}
	p.next()
}