Ver código fonte

- Added arithmetic support for int

- Fixed character entities
Stan Hebben 6 anos atrás
pai
commit
a509d45843

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

@@ -5,9 +5,13 @@
5 5
  */
6 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 10
 import org.openzen.zenscript.codemodel.Modifiers;
11
+import org.openzen.zenscript.codemodel.OperatorType;
9 12
 import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
10 13
 import org.openzen.zenscript.codemodel.member.CasterMember;
14
+import org.openzen.zenscript.codemodel.member.OperatorMember;
11 15
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
12 16
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
13 17
 import org.openzen.zenscript.shared.CodePosition;
@@ -20,6 +24,29 @@ public class BuiltinTypeMembers {
20 24
 	public static final ConstantGetterMember INT_GET_MIN_VALUE = new ConstantGetterMember("MIN_VALUE", position -> new ConstantIntExpression(position, Integer.MIN_VALUE));
21 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 50
 	public static final CasterMember INT_TO_BYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.BYTE);
24 51
 	public static final CasterMember INT_TO_SBYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SBYTE);
25 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 Ver arquivo

@@ -266,10 +266,30 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
266 266
 	
267 267
 	private void visitInt() {
268 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 293
 		members.addGetter(BuiltinTypeMembers.INT_GET_MIN_VALUE, TypeMemberPriority.SPECIFIED);
274 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 Ver arquivo

@@ -126,26 +126,46 @@ public final class TypeMembers {
126 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 133
 	public void addField(FieldMember member, TypeMemberPriority priority) {
130 134
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
131 135
 		group.setField(member, priority);
132 136
 	}
133 137
 	
138
+	public void addGetter(IGettableMember member) {
139
+		addGetter(member, TypeMemberPriority.SPECIFIED);
140
+	}
141
+	
134 142
 	public void addGetter(IGettableMember member, TypeMemberPriority priority) {
135 143
 		DefinitionMemberGroup group = getOrCreateGroup(member.getName());
136 144
 		group.setGetter(member, priority);
137 145
 	}
138 146
 	
147
+	public void addSetter(SetterMember member) {
148
+		addSetter(member, TypeMemberPriority.SPECIFIED);
149
+	}
150
+	
139 151
 	public void addSetter(SetterMember member, TypeMemberPriority priority) {
140 152
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
141 153
 		group.setSetter(member, priority);
142 154
 	}
143 155
 	
156
+	public void addMethod(MethodMember member) {
157
+		addMethod(member, TypeMemberPriority.SPECIFIED);
158
+	}
159
+	
144 160
 	public void addMethod(MethodMember member, TypeMemberPriority priority) {
145 161
 		DefinitionMemberGroup group = getOrCreateGroup(member.name);
146 162
 		group.addMethod(member, priority);
147 163
 	}
148 164
 	
165
+	public void addOperator(OperatorMember member) {
166
+		addOperator(member, TypeMemberPriority.SPECIFIED);
167
+	}
168
+	
149 169
 	public void addOperator(OperatorMember member, TypeMemberPriority priority) {
150 170
 		DefinitionMemberGroup group = getOrCreateGroup(member.operator);
151 171
 		group.addMethod(member, priority);

+ 6
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Ver arquivo

@@ -27,6 +27,12 @@ public class JavaCompiler {
27 27
 		BuiltinTypeMembers.INT_GET_MIN_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jInteger, "MIN_VALUE", "I"));
28 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 36
 		BuiltinTypeMembers.INT_TO_BYTE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2b());
31 37
 		BuiltinTypeMembers.INT_TO_SBYTE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2b());
32 38
 		BuiltinTypeMembers.INT_TO_SHORT.setTag(JavaBytecodeImplementation.class, writer -> writer.i2s());

+ 1
- 0
ScriptingExample/scripts/helloworld.zs Ver arquivo

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

+ 1
- 1
Shared/src/main/java/org/openzen/zenscript/shared/CompileException.java Ver arquivo

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

src/main/resources/org/openzen/zenscript/shared/characterEntities.properties → Shared/src/main/resources/org/openzen/zenscript/shared/characterEntities.properties Ver arquivo


Carregando…
Cancelar
Salvar