def checkTables(ts, tt, ttc):
    Type.checkRedefined(ttc, 'ERROR: type constructor names must not match\n')

    Type.checkRedefined(tt, 'ERROR: type names must not match\n')

    ttc1 = f.reduce(lambda a, x: a + hash.toList(x), ttc, [])
    list(map(lambda x: Type.checkType(x[1][0], tt, x[1][1]), ttc1))
    list(map(lambda x: checkOnUseSugar(x, ttc), hash.toList(ts)))
    return True
Exemple #2
0
	def unifi(a,b,at,bt):
		if type(a) != list and type(b)!=list:
			if ord(a[0]) < ord('a') and ord(b[0]) < ord('a'):
				if a == b:
					return (at,bt,True)
				else:
					return (at,bt,False)
			else:
				if ord(a[0]) >= ord('a'):
					nnn = hash.get(at,a)
					if nnn == None:
						return (hash.create(256,hash.toList(at)+[(a,b)]),bt,True)
					else:
						if type(nnn) != list:
							if ord(nnn[0]) >= ord('a'):
								return (at,bt,True)
						return unifi(nnn,b,at,bt)
				else:
					nnn = hash.get(bt,b)
					if nnn == None:
						return (at,hash.create(256,hash.toList(bt)+[(b,a)]),True)
					else:
						if type(nnn) != list:
							if ord(nnn[0]) >= ord('a'):
								return (at,bt,True)
						return unifi(a,nnn,at,bt)
		elif type(a) != list:
			if ord(a[0]) >= ord('a'):
				nnn = hash.get(at,a)
				if nnn == None:
					return (hash.create(256,hash.toList(at)+[(a,b)]),bt,True)
				else:
					if type(nnn) != list:
						if ord(nnn[0]) >= ord('a'):
							return (at,bt,True)
					return unifi(nnn,b,at,bt)
			return (at,bt,False)
		elif type(b) != list:
			if ord(b[0]) >= ord('a'):
				nnn = hash.get(bt,b)
				if nnn == None:
					return (at,hash.create(256,hash.toList(bt)+[(b,a)]),True)
				else:
					if type(nnn) != list:
						if ord(nnn[0]) >= ord('a'):
							return (at,bt,True)
					return unifi(a,nnn,at,bt)
			return (at,bt,False)
		else:
			at1,bt1,b1 = unifi(a[0],b[0],at,bt)
			at2,bt2,b2 = unifi(a[1],b[1],at1,bt1)
			return (at2,bt2,b1 and b2)
		return (at,bt,False)
def checkOnUseSugar(x, t):
    listOfAll = f.reduce(lambda a, x: a + hash.toList(x), t, [])
    tOfAll = hash.create(1024, listOfAll)
    res = hash.get(tOfAll, x[0])
    if res == None:
        return True
    sys.exit('ERROR: name conflict:  syntax sugar and type constructor\n' +
             'name: ' + x[0] + '\n' + 'syntax sugar declared in line: ' +
             str(x[1]) + '\n' + 'type constructor declared in line: ' +
             str(res[1]) + '\n')
    return False
Exemple #4
0
def checkRedefined(t,msg):
	if t == []:
		return
	listOfAll = f.reduce(lambda a,x:a+hash.toList(x),t,[])
	tOfAll = hash.create(1024,listOfAll);
	def checkForName(x):
		res = hash.getAll(tOfAll,x[0])
#		print(res)
		if len(res) > 1:
			sys.exit(msg +
			'name: ' + x[0] + '\n' +
			'declared in lines: ' +
			f.reduce(lambda a,x: a + (str(x[1]) if x[1]>=0 else 'Generic') +', ', res,"") +'\n')
		return
	list(map(checkForName,listOfAll))
             'it is possinle near this text: ' + msg + '\n' +
             'I want to token ' + str(l[0]) + '\n')
tree = tree[0]

##############
tDefTypes = hash.create(128, [('Ptr', (['Ptr', 'a'], -1))] + list(
    map(lambda x:
        (x, (x, -1)), 'I8,I16,I32,U8,U16,U32,F8,F16,F32,F64'.split(','))))
tDefConstructor = hash.create(128,
                              [('Ptr', (Type.strToType('a -> Ptr a'), -1))])

tSugar, tTypes, tTypeConstructor = getTables(tree[1])
checkTables(tSugar,[tTypes,tDefTypes],[tTypeConstructor,tDefConstructor])\

#########################################################
tmpL = (listNameFromScopeWithOptions(tree[1]) + hash.toList(tTypeConstructor) +
        hash.toList(tDefConstructor))
tFromThis = hash.create(256, tmpL)
tree = fixAst.fixAst(tree[1][-1][1][2][1], tFromThis, tSugar)
print(tree)

#########################################################

# invalid check types
# unifi with types template
# redefined check
# other for full type include system?

#check for use sugar word -

# TODO
Exemple #6
0
def checkType(t,ts,line):
	if ts == []:
		return
	listOfAll = f.reduce(lambda a,x: a + hash.toList(x),ts,[])
	tOfAll = hash.create(1024,listOfAll)
	def check(x):
		if type(x) == list:
			return check(x[0]) and check(x[1])
		if ord(x[0]) >= ord('a') and ord(x[0]) <= ord('z'):
			return True
#		print(x)
		res = hash.getAll(tOfAll,x)
#		print(len(res))
		if len(res) == 0:
			sys.exit('ERROR: missing type declaration\n'+
				'Undeclared type: ' + x +'\n' +
				'in line: ' + str(line))
		return True


	def checkNameUses(x):
#		print('In check: ',x)
		if type(x) == list:
			if type(x[0]) != list:
				if ord(x[0][0]) >= ord('A') and ord(x[0][0]) <= ord('X'):
					isThisC = hash.get(tOfAll,x[0])
#					print(x,isThisC[0])
					if type(isThisC[0]) != list:
#						pass
						return checkNameUses(x[0]) and checkNameUses(x[1])
					else:
#						_,_,b = unifi(x, isThisC[0])
#						if b == False:
#							sys.exit('ERROR: wrong parameters for type\n' +
#									 'in line: ' + str(line) + '\n' +
#									 'for type: ' + x[0] + '\n' +
#									 'declared in line: ' + str(isThisC[1]) + '\n' +
#									 'with pattern: ' + str(isThisC[0]) + '\n' +
#									 '            | ' + toString(isThisC[0]) + '\n' +
#									 'in full type: ' + str(t) + '\n' +
#									 '            | ' + toString(t) + '\n' +
#									 'in local pattern: ' + str(x) + '\n' +
#									 '                | ' + toString(x) + '\n' )
#							return False
#							print('Error:',toString(x),x,isThisC[1])
						return checkNameUses(x[1])
				else:
					return checkNameUses(x[1])
			else:
				return checkNameUses(x[0]) and checkNameUses(x[1])
		else:
#			print(x)
			if ord(x[0]) >= ord('A') and ord(x[0]) <= ord('X'):
				isThisC = hash.get(tOfAll,x)
				if isThisC != None:
#					print(isThisC)
					if type(isThisC[0]) != list:
						return True
					else:
						sys.exit('ERROR: missing parameters for type\n' +
								 'in line: ' + str(line) + '\n' +
								 'for type: ' + x + '\n' +
								 'declared in line: ' + str(isThisC[1]) + '\n' +
								 'with pattern: ' + str(isThisC[0]) + '\n' +
								 '            | ' + toString(isThisC[0]) + '\n' +
								 'in full type: ' + str(t) + '\n' +
								 '            | ' + toString(t) + '\n' )
#						print('Error:',x,isThisC[1],isThisC[0])
						return False
				else:
					sys.exit('ERROR: undefined type:' + str(x) +'\n' +
							  'in line: ' + str(line) + '\n')
					return False
			else:
				return True

	if check(t) == True:
		if checkNameUses(t):
			return True
		else:
			return False
	else:
		return False