Browse Source

- Added arithmetic support for int

- Fixed character entities
Stan Hebben 6 years ago
parent
commit
a509d45843

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.type.member;
6
 package org.openzen.zenscript.codemodel.type.member;
7
 
7
 
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.FunctionParameter;
8
 import org.openzen.zenscript.codemodel.Modifiers;
10
 import org.openzen.zenscript.codemodel.Modifiers;
11
+import org.openzen.zenscript.codemodel.OperatorType;
9
 import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
12
 import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
10
 import org.openzen.zenscript.codemodel.member.CasterMember;
13
 import org.openzen.zenscript.codemodel.member.CasterMember;
14
+import org.openzen.zenscript.codemodel.member.OperatorMember;
11
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
15
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
12
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
13
 import org.openzen.zenscript.shared.CodePosition;
17
 import org.openzen.zenscript.shared.CodePosition;
20
 	public static final ConstantGetterMember INT_GET_MIN_VALUE = new ConstantGetterMember("MIN_VALUE", position -> new ConstantIntExpression(position, Integer.MIN_VALUE));
24
 	public static final ConstantGetterMember INT_GET_MIN_VALUE = new ConstantGetterMember("MIN_VALUE", position -> new ConstantIntExpression(position, Integer.MIN_VALUE));
21
 	public static final ConstantGetterMember INT_GET_MAX_VALUE = new ConstantGetterMember("MAX_VALUE", position -> new ConstantIntExpression(position, Integer.MAX_VALUE));
25
 	public static final ConstantGetterMember INT_GET_MAX_VALUE = new ConstantGetterMember("MAX_VALUE", position -> new ConstantIntExpression(position, Integer.MAX_VALUE));
22
 	
26
 	
27
+	public static final OperatorMember INT_ADD_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.ADD, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
28
+	public static final OperatorMember INT_ADD_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.ADD, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
29
+	public static final OperatorMember INT_ADD_FLOAT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.ADD, new FunctionHeader(BasicTypeID.FLOAT, new FunctionParameter(BasicTypeID.FLOAT)));
30
+	public static final OperatorMember INT_ADD_DOUBLE = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.ADD, new FunctionHeader(BasicTypeID.DOUBLE, new FunctionParameter(BasicTypeID.DOUBLE)));
31
+	
32
+	public static final OperatorMember INT_SUB_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.SUB, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
33
+	public static final OperatorMember INT_SUB_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.SUB, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
34
+	public static final OperatorMember INT_SUB_FLOAT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.SUB, new FunctionHeader(BasicTypeID.FLOAT, new FunctionParameter(BasicTypeID.FLOAT)));
35
+	public static final OperatorMember INT_SUB_DOUBLE = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.SUB, new FunctionHeader(BasicTypeID.DOUBLE, new FunctionParameter(BasicTypeID.DOUBLE)));
36
+	
37
+	public static final OperatorMember INT_MUL_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MUL, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
38
+	public static final OperatorMember INT_MUL_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MUL, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
39
+	public static final OperatorMember INT_MUL_FLOAT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MUL, new FunctionHeader(BasicTypeID.FLOAT, new FunctionParameter(BasicTypeID.FLOAT)));
40
+	public static final OperatorMember INT_MUL_DOUBLE = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MUL, new FunctionHeader(BasicTypeID.DOUBLE, new FunctionParameter(BasicTypeID.DOUBLE)));
41
+	
42
+	public static final OperatorMember INT_DIV_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.DIV, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
43
+	public static final OperatorMember INT_DIV_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.DIV, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
44
+	public static final OperatorMember INT_DIV_FLOAT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.DIV, new FunctionHeader(BasicTypeID.FLOAT, new FunctionParameter(BasicTypeID.FLOAT)));
45
+	public static final OperatorMember INT_DIV_DOUBLE = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.DIV, new FunctionHeader(BasicTypeID.DOUBLE, new FunctionParameter(BasicTypeID.DOUBLE)));
46
+	
47
+	public static final OperatorMember INT_MOD_INT = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MOD, new FunctionHeader(BasicTypeID.INT, new FunctionParameter(BasicTypeID.INT)));
48
+	public static final OperatorMember INT_MOD_LONG = new OperatorMember(CodePosition.BUILTIN, 0, OperatorType.MOD, new FunctionHeader(BasicTypeID.LONG, new FunctionParameter(BasicTypeID.LONG)));
49
+	
23
 	public static final CasterMember INT_TO_BYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.BYTE);
50
 	public static final CasterMember INT_TO_BYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.BYTE);
24
 	public static final CasterMember INT_TO_SBYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SBYTE);
51
 	public static final CasterMember INT_TO_SBYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SBYTE);
25
 	public static final CasterMember INT_TO_SHORT = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SHORT);
52
 	public static final CasterMember INT_TO_SHORT = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SHORT);

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

266
 	
266
 	
267
 	private void visitInt() {
267
 	private void visitInt() {
268
 		registerUnaryOperations();
268
 		registerUnaryOperations();
269
-		registerArithmeticOperations(INT, INT);
270
-		registerArithmeticOperations(LONG, LONG);
271
-		registerArithmeticOperations(FLOAT, FLOAT);
272
-		registerArithmeticOperations(DOUBLE, DOUBLE);
269
+		
270
+		members.addOperator(BuiltinTypeMembers.INT_ADD_INT);
271
+		members.addOperator(BuiltinTypeMembers.INT_ADD_LONG);
272
+		members.addOperator(BuiltinTypeMembers.INT_ADD_FLOAT);
273
+		members.addOperator(BuiltinTypeMembers.INT_ADD_DOUBLE);
274
+		
275
+		members.addOperator(BuiltinTypeMembers.INT_SUB_INT);
276
+		members.addOperator(BuiltinTypeMembers.INT_SUB_LONG);
277
+		members.addOperator(BuiltinTypeMembers.INT_SUB_FLOAT);
278
+		members.addOperator(BuiltinTypeMembers.INT_SUB_DOUBLE);
279
+		
280
+		members.addOperator(BuiltinTypeMembers.INT_MUL_INT);
281
+		members.addOperator(BuiltinTypeMembers.INT_MUL_LONG);
282
+		members.addOperator(BuiltinTypeMembers.INT_MUL_FLOAT);
283
+		members.addOperator(BuiltinTypeMembers.INT_MUL_DOUBLE);
284
+		
285
+		members.addOperator(BuiltinTypeMembers.INT_DIV_INT);
286
+		members.addOperator(BuiltinTypeMembers.INT_DIV_LONG);
287
+		members.addOperator(BuiltinTypeMembers.INT_DIV_FLOAT);
288
+		members.addOperator(BuiltinTypeMembers.INT_DIV_DOUBLE);
289
+		
290
+		members.addOperator(BuiltinTypeMembers.INT_MOD_INT);
291
+		members.addOperator(BuiltinTypeMembers.INT_MOD_LONG);
292
+		
273
 		members.addGetter(BuiltinTypeMembers.INT_GET_MIN_VALUE, TypeMemberPriority.SPECIFIED);
293
 		members.addGetter(BuiltinTypeMembers.INT_GET_MIN_VALUE, TypeMemberPriority.SPECIFIED);
274
 		members.addGetter(BuiltinTypeMembers.INT_GET_MAX_VALUE, TypeMemberPriority.SPECIFIED);
294
 		members.addGetter(BuiltinTypeMembers.INT_GET_MAX_VALUE, TypeMemberPriority.SPECIFIED);
275
 		
295
 		

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

126
 		casters.add(new TypeMember<>(priority, caster));
126
 		casters.add(new TypeMember<>(priority, caster));
127
 	}
127
 	}
128
 	
128
 	
129
+	public void addField(FieldMember member) {
130
+		addField(member, TypeMemberPriority.SPECIFIED);
131
+	}
132
+	
129
 	public void addField(FieldMember member, TypeMemberPriority priority) {
133
 	public void addField(FieldMember member, TypeMemberPriority priority) {
130
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
134
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
131
 		group.setField(member, priority);
135
 		group.setField(member, priority);
132
 	}
136
 	}
133
 	
137
 	
138
+	public void addGetter(IGettableMember member) {
139
+		addGetter(member, TypeMemberPriority.SPECIFIED);
140
+	}
141
+	
134
 	public void addGetter(IGettableMember member, TypeMemberPriority priority) {
142
 	public void addGetter(IGettableMember member, TypeMemberPriority priority) {
135
 		DefinitionMemberGroup group = getOrCreateGroup(member.getName());
143
 		DefinitionMemberGroup group = getOrCreateGroup(member.getName());
136
 		group.setGetter(member, priority);
144
 		group.setGetter(member, priority);
137
 	}
145
 	}
138
 	
146
 	
147
+	public void addSetter(SetterMember member) {
148
+		addSetter(member, TypeMemberPriority.SPECIFIED);
149
+	}
150
+	
139
 	public void addSetter(SetterMember member, TypeMemberPriority priority) {
151
 	public void addSetter(SetterMember member, TypeMemberPriority priority) {
140
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
152
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
141
 		group.setSetter(member, priority);
153
 		group.setSetter(member, priority);
142
 	}
154
 	}
143
 	
155
 	
156
+	public void addMethod(MethodMember member) {
157
+		addMethod(member, TypeMemberPriority.SPECIFIED);
158
+	}
159
+	
144
 	public void addMethod(MethodMember member, TypeMemberPriority priority) {
160
 	public void addMethod(MethodMember member, TypeMemberPriority priority) {
145
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
161
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
146
 		group.addMethod(member, priority);
162
 		group.addMethod(member, priority);
147
 	}
163
 	}
148
 	
164
 	
165
+	public void addOperator(OperatorMember member) {
166
+		addOperator(member, TypeMemberPriority.SPECIFIED);
167
+	}
168
+	
149
 	public void addOperator(OperatorMember member, TypeMemberPriority priority) {
169
 	public void addOperator(OperatorMember member, TypeMemberPriority priority) {
150
 		DefinitionMemberGroup group = getOrCreateGroup(member.operator);
170
 		DefinitionMemberGroup group = getOrCreateGroup(member.operator);
151
 		group.addMethod(member, priority);
171
 		group.addMethod(member, priority);

+ 6
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java View File

27
 		BuiltinTypeMembers.INT_GET_MIN_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jInteger, "MIN_VALUE", "I"));
27
 		BuiltinTypeMembers.INT_GET_MIN_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jInteger, "MIN_VALUE", "I"));
28
 		BuiltinTypeMembers.INT_GET_MAX_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jInteger, "MAX_VALUE", "I"));
28
 		BuiltinTypeMembers.INT_GET_MAX_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jInteger, "MAX_VALUE", "I"));
29
 		
29
 		
30
+		BuiltinTypeMembers.INT_ADD_INT.setTag(JavaBytecodeImplementation.class, writer -> writer.iAdd());
31
+		BuiltinTypeMembers.INT_SUB_INT.setTag(JavaBytecodeImplementation.class, writer -> writer.iSub());
32
+		BuiltinTypeMembers.INT_MUL_INT.setTag(JavaBytecodeImplementation.class, writer -> writer.iMul());
33
+		BuiltinTypeMembers.INT_DIV_INT.setTag(JavaBytecodeImplementation.class, writer -> writer.iDiv());
34
+		BuiltinTypeMembers.INT_MOD_INT.setTag(JavaBytecodeImplementation.class, writer -> writer.iRem());
35
+		
30
 		BuiltinTypeMembers.INT_TO_BYTE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2b());
36
 		BuiltinTypeMembers.INT_TO_BYTE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2b());
31
 		BuiltinTypeMembers.INT_TO_SBYTE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2b());
37
 		BuiltinTypeMembers.INT_TO_SBYTE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2b());
32
 		BuiltinTypeMembers.INT_TO_SHORT.setTag(JavaBytecodeImplementation.class, writer -> writer.i2s());
38
 		BuiltinTypeMembers.INT_TO_SHORT.setTag(JavaBytecodeImplementation.class, writer -> writer.i2s());

+ 1
- 0
ScriptingExample/scripts/helloworld.zs View File

1
 println("Hello world!");
1
 println("Hello world!");
2
 println(5);
2
 println(5);
3
+println(1 + 3);

+ 1
- 1
Shared/src/main/java/org/openzen/zenscript/shared/CompileException.java View File

18
 	public final CompileExceptionCode code;
18
 	public final CompileExceptionCode code;
19
 	
19
 	
20
 	public CompileException(CodePosition position, CompileExceptionCode code, String message) {
20
 	public CompileException(CodePosition position, CompileExceptionCode code, String message) {
21
-		super(position.toString() + ": [" + code + "]" + message);
21
+		super(position.toString() + ": [" + code + "] " + message);
22
 		
22
 		
23
 		this.position = position;
23
 		this.position = position;
24
 		this.code = code;
24
 		this.code = code;

src/main/resources/org/openzen/zenscript/shared/characterEntities.properties → Shared/src/main/resources/org/openzen/zenscript/shared/characterEntities.properties View File


Loading…
Cancel
Save