Browse Source

- Fix arithmetic rules for floats

- Fix float suffixes on integers
Stan Hebben 5 years ago
parent
commit
c19e68376b

+ 60
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java View File

65
 import static org.openzen.zencode.shared.CodePosition.BUILTIN;
65
 import static org.openzen.zencode.shared.CodePosition.BUILTIN;
66
 import org.openzen.zenscript.codemodel.Module;
66
 import org.openzen.zenscript.codemodel.Module;
67
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
67
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
68
+import org.openzen.zenscript.codemodel.expression.CallArguments;
68
 import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
69
 import org.openzen.zenscript.codemodel.expression.ConstantUSizeExpression;
69
 import org.openzen.zenscript.codemodel.member.IteratorMember;
70
 import org.openzen.zenscript.codemodel.member.IteratorMember;
70
 import org.openzen.zenscript.codemodel.type.InvalidTypeID;
71
 import org.openzen.zenscript.codemodel.type.InvalidTypeID;
1158
 		inc(builtin, FLOAT_INC, FLOAT);
1159
 		inc(builtin, FLOAT_INC, FLOAT);
1159
 		dec(builtin, FLOAT_DEC, FLOAT);
1160
 		dec(builtin, FLOAT_DEC, FLOAT);
1160
 
1161
 
1162
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, BYTE, FLOAT, BYTE_TO_FLOAT);
1163
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, SBYTE, FLOAT, SBYTE_TO_FLOAT);
1164
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, SHORT, FLOAT, SHORT_TO_FLOAT);
1165
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, USHORT, FLOAT, USHORT_TO_FLOAT);
1166
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, INT, FLOAT, INT_TO_FLOAT);
1167
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, UINT, FLOAT, UINT_TO_FLOAT);
1168
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, LONG, FLOAT, LONG_TO_FLOAT);
1169
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, ULONG, FLOAT, ULONG_TO_FLOAT);
1170
+		addWithCastedOperand(builtin, FLOAT_ADD_FLOAT, USIZE, FLOAT, USIZE_TO_FLOAT);
1161
 		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT);
1171
 		add(builtin, FLOAT_ADD_FLOAT, FLOAT, FLOAT);
1162
 		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, FLOAT_TO_DOUBLE);
1172
 		add(builtin, DOUBLE_ADD_DOUBLE, DOUBLE, DOUBLE, FLOAT_TO_DOUBLE);
1163
 		
1173
 		
1174
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, BYTE, FLOAT, BYTE_TO_FLOAT);
1175
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, SBYTE, FLOAT, SBYTE_TO_FLOAT);
1176
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, SHORT, FLOAT, SHORT_TO_FLOAT);
1177
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, USHORT, FLOAT, USHORT_TO_FLOAT);
1178
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, INT, FLOAT, INT_TO_FLOAT);
1179
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, UINT, FLOAT, UINT_TO_FLOAT);
1180
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, LONG, FLOAT, LONG_TO_FLOAT);
1181
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, ULONG, FLOAT, ULONG_TO_FLOAT);
1182
+		subWithCastedOperand(builtin, FLOAT_SUB_FLOAT, USIZE, FLOAT, USIZE_TO_FLOAT);
1164
 		sub(builtin, FLOAT_SUB_FLOAT, FLOAT, FLOAT);
1183
 		sub(builtin, FLOAT_SUB_FLOAT, FLOAT, FLOAT);
1165
 		sub(builtin, DOUBLE_SUB_DOUBLE, DOUBLE, DOUBLE, LONG_TO_DOUBLE);
1184
 		sub(builtin, DOUBLE_SUB_DOUBLE, DOUBLE, DOUBLE, LONG_TO_DOUBLE);
1166
 		
1185
 		
1186
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, BYTE, FLOAT, BYTE_TO_FLOAT);
1187
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, SBYTE, FLOAT, SBYTE_TO_FLOAT);
1188
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, SHORT, FLOAT, SHORT_TO_FLOAT);
1189
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, USHORT, FLOAT, USHORT_TO_FLOAT);
1190
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, INT, FLOAT, INT_TO_FLOAT);
1191
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, UINT, FLOAT, UINT_TO_FLOAT);
1192
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, LONG, FLOAT, LONG_TO_FLOAT);
1193
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, ULONG, FLOAT, ULONG_TO_FLOAT);
1194
+		mulWithCastedOperand(builtin, FLOAT_MUL_FLOAT, USIZE, FLOAT, USIZE_TO_FLOAT);
1167
 		mul(builtin, FLOAT_MUL_FLOAT, FLOAT, FLOAT);
1195
 		mul(builtin, FLOAT_MUL_FLOAT, FLOAT, FLOAT);
1168
 		mul(builtin, DOUBLE_MUL_DOUBLE, DOUBLE, DOUBLE, LONG_TO_DOUBLE);
1196
 		mul(builtin, DOUBLE_MUL_DOUBLE, DOUBLE, DOUBLE, LONG_TO_DOUBLE);
1169
 		
1197
 		
1198
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, BYTE, FLOAT, BYTE_TO_FLOAT);
1199
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, SBYTE, FLOAT, SBYTE_TO_FLOAT);
1200
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, SHORT, FLOAT, SHORT_TO_FLOAT);
1201
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, USHORT, FLOAT, USHORT_TO_FLOAT);
1202
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, INT, FLOAT, INT_TO_FLOAT);
1203
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, UINT, FLOAT, UINT_TO_FLOAT);
1204
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, LONG, FLOAT, LONG_TO_FLOAT);
1205
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, ULONG, FLOAT, ULONG_TO_FLOAT);
1206
+		divWithCastedOperand(builtin, FLOAT_DIV_FLOAT, USIZE, FLOAT, USIZE_TO_FLOAT);
1170
 		div(builtin, FLOAT_DIV_FLOAT, FLOAT, FLOAT);
1207
 		div(builtin, FLOAT_DIV_FLOAT, FLOAT, FLOAT);
1171
 		div(builtin, DOUBLE_DIV_DOUBLE, DOUBLE, DOUBLE, LONG_TO_DOUBLE);
1208
 		div(builtin, DOUBLE_DIV_DOUBLE, DOUBLE, DOUBLE, LONG_TO_DOUBLE);
1172
 		
1209
 		
1267
 		members.getOrCreateGroup(member.operator).addMethod(method, TypeMemberPriority.SPECIFIED);
1304
 		members.getOrCreateGroup(member.operator).addMethod(method, TypeMemberPriority.SPECIFIED);
1268
 	}
1305
 	}
1269
 	
1306
 	
1307
+	private void castedOperandCall(OperatorMember member, StoredType toType, BuiltinID casterBuiltin) {
1308
+		CasterMemberRef caster = castImplicitRef(member.definition, casterBuiltin, toType);
1309
+		TranslatedOperatorMemberRef method = new TranslatedOperatorMemberRef(member, members.type, GenericMapper.EMPTY,
1310
+				call -> member.ref(members.type, null).call(call.position, call.target, new CallArguments(caster.cast(call.position, call.arguments.arguments[0], true)), call.scope));
1311
+		members.getOrCreateGroup(member.operator).addMethod(method, TypeMemberPriority.SPECIFIED);
1312
+	}
1313
+	
1270
 	private void register(IDefinitionMember member) {
1314
 	private void register(IDefinitionMember member) {
1271
 		member.registerTo(members, TypeMemberPriority.SPECIFIED, null);
1315
 		member.registerTo(members, TypeMemberPriority.SPECIFIED, null);
1272
 	}
1316
 	}
1347
 		castedTargetCall(addOp(definition, id, operand.stored, result.stored), result.stored, caster);
1391
 		castedTargetCall(addOp(definition, id, operand.stored, result.stored), result.stored, caster);
1348
 	}
1392
 	}
1349
 	
1393
 	
1394
+	private void addWithCastedOperand(HighLevelDefinition definition, BuiltinID id, BasicTypeID operand, BasicTypeID result, BuiltinID caster) {
1395
+		castedOperandCall(addOp(definition, id, operand.stored, result.stored), operand.stored, caster);
1396
+	}
1397
+	
1350
 	private OperatorMember subOp(HighLevelDefinition cls, BuiltinID id, StoredType operand, StoredType result) {
1398
 	private OperatorMember subOp(HighLevelDefinition cls, BuiltinID id, StoredType operand, StoredType result) {
1351
 		return new OperatorMember(
1399
 		return new OperatorMember(
1352
 				BUILTIN,
1400
 				BUILTIN,
1365
 		castedTargetCall(subOp(definition, id, operand.stored, result.stored), result.stored, caster);
1413
 		castedTargetCall(subOp(definition, id, operand.stored, result.stored), result.stored, caster);
1366
 	}
1414
 	}
1367
 	
1415
 	
1416
+	private void subWithCastedOperand(HighLevelDefinition definition, BuiltinID id, BasicTypeID operand, BasicTypeID result, BuiltinID caster) {
1417
+		castedOperandCall(subOp(definition, id, operand.stored, result.stored), operand.stored, caster);
1418
+	}
1419
+	
1368
 	private OperatorMember mulOp(HighLevelDefinition cls, BuiltinID id, StoredType operand, StoredType result) {
1420
 	private OperatorMember mulOp(HighLevelDefinition cls, BuiltinID id, StoredType operand, StoredType result) {
1369
 		return new OperatorMember(
1421
 		return new OperatorMember(
1370
 				BUILTIN,
1422
 				BUILTIN,
1383
 		castedTargetCall(mulOp(definition, id, operand.stored, result.stored), result.stored, caster);
1435
 		castedTargetCall(mulOp(definition, id, operand.stored, result.stored), result.stored, caster);
1384
 	}
1436
 	}
1385
 	
1437
 	
1438
+	private void mulWithCastedOperand(HighLevelDefinition definition, BuiltinID id, BasicTypeID operand, BasicTypeID result, BuiltinID caster) {
1439
+		castedOperandCall(mulOp(definition, id, operand.stored, result.stored), operand.stored, caster);
1440
+	}
1441
+	
1386
 	private OperatorMember divOp(HighLevelDefinition cls, BuiltinID id, StoredType operand, StoredType result) {
1442
 	private OperatorMember divOp(HighLevelDefinition cls, BuiltinID id, StoredType operand, StoredType result) {
1387
 		return new OperatorMember(
1443
 		return new OperatorMember(
1388
 				BUILTIN,
1444
 				BUILTIN,
1401
 		castedTargetCall(divOp(definition, id, operand.stored, result.stored), result.stored, caster);
1457
 		castedTargetCall(divOp(definition, id, operand.stored, result.stored), result.stored, caster);
1402
 	}
1458
 	}
1403
 	
1459
 	
1460
+	private void divWithCastedOperand(HighLevelDefinition definition, BuiltinID id, BasicTypeID operand, BasicTypeID result, BuiltinID caster) {
1461
+		castedOperandCall(divOp(definition, id, operand.stored, result.stored), operand.stored, caster);
1462
+	}
1463
+	
1404
 	private OperatorMember modOp(HighLevelDefinition cls, BuiltinID id, StoredType operand, StoredType result) {
1464
 	private OperatorMember modOp(HighLevelDefinition cls, BuiltinID id, StoredType operand, StoredType result) {
1405
 		return new OperatorMember(
1465
 		return new OperatorMember(
1406
 				BUILTIN,
1466
 				BUILTIN,

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionInt.java View File

12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
12
 import org.openzen.zenscript.codemodel.expression.CallArguments;
13
 import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
13
 import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
14
 import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
14
 import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
15
+import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
16
+import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
15
 import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
17
 import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
16
 import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
18
 import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
17
 import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
19
 import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
116
 			return new ConstantULongExpression(position, value);
118
 			return new ConstantULongExpression(position, value);
117
 		if (suffix.equals("U") || suffix.equals("u"))
119
 		if (suffix.equals("U") || suffix.equals("u"))
118
 			return new ConstantUIntExpression(position, (int)value);
120
 			return new ConstantUIntExpression(position, (int)value);
121
+		if (suffix.equals("D") || suffix.equals("d"))
122
+			return new ConstantDoubleExpression(position, value);
123
+		if (suffix.equals("F") || suffix.equals("f"))
124
+			return new ConstantFloatExpression(position, value);
119
 		
125
 		
120
 		for (StoredType hint : scope.hints) {
126
 		for (StoredType hint : scope.hints) {
121
 			if (suffix.isEmpty() && (hint.type instanceof BasicTypeID)) {
127
 			if (suffix.isEmpty() && (hint.type instanceof BasicTypeID)) {

+ 8
- 1
ScriptingExample/scripts/integration.zs View File

23
 
23
 
24
 
24
 
25
 println(<test string>);
25
 println(<test string>);
26
-println(<test string>.length);
26
+println(<test string>.name);
27
+
28
+var diamond = <item:minecraft:diamond>;
29
+var dirt = <item:minecraft:dirt>;
30
+addShapedRecipe("TestRecipe", diamond, [[dirt, dirt, dirt],[dirt, dirt, dirt],[dirt, dirt, dirt]]);
31
+
32
+var count = 10;
33
+floatMethod(5f * count);

+ 12
- 2
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Globals.java View File

37
 			System.out.println("  - " + object.getName());
37
 			System.out.println("  - " + object.getName());
38
 	}
38
 	}
39
 	
39
 	
40
-	public static String bracket(String value) {
41
-		return "BRACKET:" + value;
40
+	@Global
41
+    public static void addShapedRecipe(String name, TestClass output, TestClass[][] inputs) {
42
+		System.out.println("Added " + name);
43
+	}
44
+	
45
+	@Global
46
+	public static void floatMethod(float argument) {
47
+		System.out.println(argument);
48
+	}
49
+	
50
+	public static TestClass bracket(String value) {
51
+		return new TestClass(value);
42
 	}
52
 	}
43
 }
53
 }

+ 6
- 0
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/TestClass.java View File

33
 	public TestClass wrap(String quotes) {
33
 	public TestClass wrap(String quotes) {
34
 		return new TestClass(quotes + name + quotes);
34
 		return new TestClass(quotes + name + quotes);
35
 	}
35
 	}
36
+	
37
+	@Caster(implicit = true)
38
+	@Override
39
+	public String toString() {
40
+		return name;
41
+	}
36
 }
42
 }

+ 1
- 1
common.gradle View File

6
 apply plugin: 'maven'
6
 apply plugin: 'maven'
7
 
7
 
8
 String mavenGroupId = 'org.openzen.zencode'
8
 String mavenGroupId = 'org.openzen.zencode'
9
-String mavenVersion = '0.3.5'
9
+String mavenVersion = '0.3.6'
10
 
10
 
11
 sourceCompatibility = '1.8'
11
 sourceCompatibility = '1.8'
12
 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
12
 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

Loading…
Cancel
Save