Quellcode durchsuchen

- Added more operators

- Added operators that require values to be cast
Stan Hebben vor 6 Jahren
Ursprung
Commit
7bdf009733

+ 31
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/CallTranslator.java Datei anzeigen

@@ -0,0 +1,31 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.shared.CodePosition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface CallTranslator {
16
+	class Call {
17
+		public final CodePosition position;
18
+		public final Expression target;
19
+		public final FunctionHeader instancedHeader;
20
+		public final CallArguments arguments;
21
+		
22
+		public Call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
23
+			this.position = position;
24
+			this.target = target;
25
+			this.instancedHeader = instancedHeader;
26
+			this.arguments = arguments;
27
+		}
28
+	}
29
+	
30
+	Expression translate(Call call);
31
+}

+ 18
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionContext.java Datei anzeigen

@@ -0,0 +1,18 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.expression;
7
+
8
+import org.openzen.zenscript.codemodel.statement.Statement;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface ExpressionContext {
15
+	void addStatementBefore(Statement statement);
16
+	
17
+	void addStatementAfter(Statement statement);
18
+}

+ 4
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FunctionalMember.java Datei anzeigen

@@ -44,6 +44,10 @@ public abstract class FunctionalMember extends DefinitionMember implements ICall
44 44
 		return new CallExpression(position, target, this, instancedHeader, arguments);
45 45
 	}
46 46
 	
47
+	public final Expression call(CodePosition position, Expression target, CallArguments arguments) {
48
+		return call(position, target, header, arguments);
49
+	}
50
+	
47 51
 	@Override
48 52
 	public Expression callWithComparator(CodePosition position, CompareType operator, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
49 53
 		return new GenericCompareExpression(position, call(position, target, instancedHeader, arguments), operator);

+ 32
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/TranslatedOperatorMember.java Datei anzeigen

@@ -0,0 +1,32 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.member;
7
+
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
9
+import org.openzen.zenscript.codemodel.OperatorType;
10
+import org.openzen.zenscript.codemodel.expression.CallArguments;
11
+import org.openzen.zenscript.codemodel.expression.CallTranslator;
12
+import org.openzen.zenscript.codemodel.expression.Expression;
13
+import org.openzen.zenscript.shared.CodePosition;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class TranslatedOperatorMember extends OperatorMember {
20
+	private final CallTranslator translator;
21
+	
22
+	public TranslatedOperatorMember(CodePosition position, int modifiers, OperatorType operator, FunctionHeader header, CallTranslator translator) {
23
+		super(position, modifiers, operator, header);
24
+		
25
+		this.translator = translator;
26
+	}
27
+
28
+	@Override
29
+	public Expression call(CodePosition position, Expression target, FunctionHeader instancedHeader, CallArguments arguments) {
30
+		return translator.translate(new CallTranslator.Call(position, target, instancedHeader, arguments));
31
+	}
32
+}

+ 151
- 35
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/BuiltinTypeMembers.java Datei anzeigen

@@ -10,52 +10,168 @@ import org.openzen.zenscript.codemodel.FunctionParameter;
10 10
 import org.openzen.zenscript.codemodel.Modifiers;
11 11
 import org.openzen.zenscript.codemodel.OperatorType;
12 12
 import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
13
+import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
13 14
 import org.openzen.zenscript.codemodel.member.CasterMember;
15
+import org.openzen.zenscript.codemodel.member.GetterMember;
16
+import org.openzen.zenscript.codemodel.member.MethodMember;
14 17
 import org.openzen.zenscript.codemodel.member.OperatorMember;
15 18
 import org.openzen.zenscript.codemodel.member.builtin.ConstantGetterMember;
16
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
19
+import static org.openzen.zenscript.codemodel.type.BasicTypeID.*;
20
+import org.openzen.zenscript.codemodel.type.ITypeID;
17 21
 import org.openzen.zenscript.shared.CodePosition;
22
+import static org.openzen.zenscript.shared.CodePosition.BUILTIN;
18 23
 
19 24
 /**
20 25
  *
21 26
  * @author Hoofdgebruiker
22 27
  */
23 28
 public class BuiltinTypeMembers {
29
+	private BuiltinTypeMembers() {}
30
+	
24 31
 	public static final ConstantGetterMember INT_GET_MIN_VALUE = new ConstantGetterMember("MIN_VALUE", position -> new ConstantIntExpression(position, Integer.MIN_VALUE));
25 32
 	public static final ConstantGetterMember INT_GET_MAX_VALUE = new ConstantGetterMember("MAX_VALUE", position -> new ConstantIntExpression(position, Integer.MAX_VALUE));
26 33
 	
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
-	
50
-	public static final CasterMember INT_TO_BYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.BYTE);
51
-	public static final CasterMember INT_TO_SBYTE = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SBYTE);
52
-	public static final CasterMember INT_TO_SHORT = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.SHORT);
53
-	public static final CasterMember INT_TO_USHORT = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.USHORT);
54
-	public static final CasterMember INT_TO_UINT = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.UINT);
55
-	public static final CasterMember INT_TO_LONG = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.LONG);
56
-	public static final CasterMember INT_TO_ULONG = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.ULONG);
57
-	public static final CasterMember INT_TO_FLOAT = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.FLOAT);
58
-	public static final CasterMember INT_TO_DOUBLE = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.DOUBLE);
59
-	public static final CasterMember INT_TO_CHAR = new CasterMember(CodePosition.BUILTIN, 0, BasicTypeID.CHAR);
60
-	public static final CasterMember INT_TO_STRING = new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, BasicTypeID.STRING);
34
+	public static final ConstantGetterMember LONG_GET_MIN_VALUE = new ConstantGetterMember("MIN_VALUE", position -> new ConstantLongExpression(position, Long.MIN_VALUE));
35
+	public static final ConstantGetterMember LONG_GET_MAX_VALUE = new ConstantGetterMember("MAX_VALUE", position -> new ConstantLongExpression(position, Long.MAX_VALUE));
36
+	
37
+	public static final OperatorMember BOOL_NOT = not(BOOL);
38
+	
39
+	public static final OperatorMember BYTE_NOT = not(BYTE);
40
+	public static final OperatorMember SBYTE_NOT = not(SBYTE);
41
+	public static final OperatorMember SHORT_NOT = not(SHORT);
42
+	public static final OperatorMember USHORT_NOT = not(USHORT);
43
+	public static final OperatorMember INT_NOT = not(INT);
44
+	public static final OperatorMember UINT_NOT = not(UINT);
45
+	public static final OperatorMember LONG_NOT = not(LONG);
46
+	public static final OperatorMember ULONG_NOT = not(ULONG);
47
+	
48
+	public static final OperatorMember BYTE_NEG = neg(BYTE);
49
+	public static final OperatorMember SBYTE_NEG = neg(SBYTE);
50
+	public static final OperatorMember SHORT_NEG = neg(SHORT);
51
+	public static final OperatorMember USHORT_NEG = neg(USHORT);
52
+	public static final OperatorMember INT_NEG = neg(INT);
53
+	public static final OperatorMember UINT_NEG = neg(UINT);
54
+	public static final OperatorMember LONG_NEG = neg(LONG);
55
+	public static final OperatorMember ULONG_NEG = neg(ULONG);
56
+	public static final OperatorMember FLOAT_NEG = neg(FLOAT);
57
+	public static final OperatorMember DOUBLE_NEG = neg(DOUBLE);
58
+	
59
+	public static final OperatorMember BYTE_ADD_BYTE = add(BYTE, BYTE);
60
+	public static final OperatorMember SBYTE_ADD_SBYTE = add(SBYTE, SBYTE);
61
+	public static final OperatorMember SHORT_ADD_SHORT = add(SHORT, SHORT);
62
+	public static final OperatorMember USHORT_ADD_USHORT = add(USHORT, USHORT);
63
+	public static final OperatorMember INT_ADD_INT = add(INT, INT);
64
+	public static final OperatorMember UINT_ADD_UINT = add(UINT, UINT);
65
+	public static final OperatorMember LONG_ADD_LONG = add(LONG, LONG);
66
+	public static final OperatorMember ULONG_ADD_ULONG = add(ULONG, ULONG);
67
+	public static final OperatorMember FLOAT_ADD_FLOAT = add(FLOAT, FLOAT);
68
+	public static final OperatorMember DOUBLE_ADD_DOUBLE = add(DOUBLE, DOUBLE);
69
+	public static final OperatorMember STRING_ADD_STRING = add(STRING, STRING);
70
+	
71
+	public static final OperatorMember BYTE_SUB_BYTE = sub(BYTE, BYTE);
72
+	public static final OperatorMember SBYTE_SUB_SBYTE = sub(SBYTE, SBYTE);
73
+	public static final OperatorMember SHORT_SUB_SHORT = sub(SHORT, SHORT);
74
+	public static final OperatorMember USHORT_SUB_USHORT = sub(USHORT, USHORT);
75
+	public static final OperatorMember INT_SUB_INT = sub(INT, INT);
76
+	public static final OperatorMember UINT_SUB_UINT = sub(UINT, UINT);
77
+	public static final OperatorMember LONG_SUB_LONG = sub(LONG, LONG);
78
+	public static final OperatorMember ULONG_SUB_ULONG = sub(ULONG, ULONG);
79
+	public static final OperatorMember FLOAT_SUB_FLOAT = sub(FLOAT, FLOAT);
80
+	public static final OperatorMember DOUBLE_SUB_DOUBLE = sub(DOUBLE, DOUBLE);
81
+	
82
+	public static final OperatorMember BYTE_MUL_BYTE = mul(BYTE, BYTE);
83
+	public static final OperatorMember SBYTE_MUL_SBYTE = mul(SBYTE, SBYTE);
84
+	public static final OperatorMember SHORT_MUL_SHORT = mul(SHORT, SHORT);
85
+	public static final OperatorMember USHORT_MUL_USHORT = mul(USHORT, USHORT);
86
+	public static final OperatorMember INT_MUL_INT = mul(INT, INT);
87
+	public static final OperatorMember UINT_MUL_UINT = mul(UINT, UINT);
88
+	public static final OperatorMember LONG_MUL_LONG = mul(LONG, LONG);
89
+	public static final OperatorMember ULONG_MUL_ULONG = mul(ULONG, ULONG);
90
+	public static final OperatorMember FLOAT_MUL_FLOAT = mul(FLOAT, FLOAT);
91
+	public static final OperatorMember DOUBLE_MUL_DOUBLE = mul(DOUBLE, DOUBLE);
92
+	
93
+	public static final OperatorMember BYTE_DIV_BYTE = div(BYTE, BYTE);
94
+	public static final OperatorMember SBYTE_DIV_SBYTE = div(SBYTE, SBYTE);
95
+	public static final OperatorMember SHORT_DIV_SHORT = div(SHORT, SHORT);
96
+	public static final OperatorMember USHORT_DIV_USHORT = div(USHORT, USHORT);
97
+	public static final OperatorMember INT_DIV_INT = div(INT, INT);
98
+	public static final OperatorMember UINT_DIV_UINT = div(UINT, UINT);
99
+	public static final OperatorMember LONG_DIV_LONG = div(LONG, LONG);
100
+	public static final OperatorMember ULONG_DIV_ULONG = div(ULONG, ULONG);
101
+	public static final OperatorMember FLOAT_DIV_FLOAT = div(FLOAT, FLOAT);
102
+	public static final OperatorMember DOUBLE_DIV_DOUBLE = div(DOUBLE, DOUBLE);
103
+	
104
+	public static final OperatorMember BYTE_MOD_BYTE = mod(BYTE, BYTE);
105
+	public static final OperatorMember SBYTE_MOD_SBYTE = mod(SBYTE, SBYTE);
106
+	public static final OperatorMember SHORT_MOD_SHORT = mod(SHORT, SHORT);
107
+	public static final OperatorMember USHORT_MOD_USHORT = mod(USHORT, USHORT);
108
+	public static final OperatorMember INT_MOD_INT = mod(INT, INT);
109
+	public static final OperatorMember UINT_MOD_UINT = mod(UINT, UINT);
110
+	public static final OperatorMember LONG_MOD_LONG = mod(LONG, LONG);
111
+	public static final OperatorMember ULONG_MOD_ULONG = mod(ULONG, ULONG);
112
+	
113
+	public static final CasterMember INT_TO_BYTE = castExplicit(BYTE);
114
+	public static final CasterMember INT_TO_SBYTE = castExplicit(SBYTE);
115
+	public static final CasterMember INT_TO_SHORT = castExplicit(SHORT);
116
+	public static final CasterMember INT_TO_USHORT = castExplicit(USHORT);
117
+	public static final CasterMember INT_TO_UINT = castImplicit(UINT);
118
+	public static final CasterMember INT_TO_LONG = castImplicit(LONG);
119
+	public static final CasterMember INT_TO_ULONG = castImplicit(ULONG);
120
+	public static final CasterMember INT_TO_FLOAT = castImplicit(FLOAT);
121
+	public static final CasterMember INT_TO_DOUBLE = castImplicit(DOUBLE);
122
+	public static final CasterMember INT_TO_CHAR = castExplicit(CHAR);
123
+	public static final CasterMember INT_TO_STRING = castImplicit(STRING);
124
+	
125
+	public static final CasterMember LONG_TO_BYTE = castExplicit(BYTE);
126
+	public static final CasterMember LONG_TO_SBYTE = castExplicit(SBYTE);
127
+	public static final CasterMember LONG_TO_SHORT = castExplicit(SHORT);
128
+	public static final CasterMember LONG_TO_USHORT = castExplicit(USHORT);
129
+	public static final CasterMember LONG_TO_INT = castExplicit(INT);
130
+	public static final CasterMember LONG_TO_UINT = castExplicit(UINT);
131
+	public static final CasterMember LONG_TO_ULONG = castImplicit(ULONG);
132
+	public static final CasterMember LONG_TO_FLOAT = castImplicit(FLOAT);
133
+	public static final CasterMember LONG_TO_DOUBLE = castImplicit(DOUBLE);
134
+	public static final CasterMember LONG_TO_CHAR = castExplicit(CHAR);
135
+	public static final CasterMember LONG_TO_STRING = castImplicit(STRING);
136
+	
137
+	public static final GetterMember FLOAT_BITS = new GetterMember(BUILTIN, 0, "bits", UINT);
138
+	public static final GetterMember DOUBLE_BITS = new GetterMember(BUILTIN, 0, "bits", ULONG);
139
+	public static final MethodMember FLOAT_FROMBITS = new MethodMember(BUILTIN, Modifiers.MODIFIER_STATIC, "fromBits", new FunctionHeader(FLOAT, new FunctionParameter(UINT)));
140
+	public static final MethodMember DOUBLE_FROMBITS = new MethodMember(BUILTIN, Modifiers.MODIFIER_STATIC, "fromBits", new FunctionHeader(DOUBLE, new FunctionParameter(ULONG)));
141
+	
142
+	private static OperatorMember not(ITypeID result) {
143
+		return new OperatorMember(BUILTIN, 0, OperatorType.NOT, new FunctionHeader(result));
144
+	}
145
+	
146
+	private static OperatorMember neg(ITypeID result) {
147
+		return new OperatorMember(BUILTIN, 0, OperatorType.NEG, new FunctionHeader(result));
148
+	}
149
+	
150
+	private static OperatorMember add(ITypeID operand, ITypeID result) {
151
+		return new OperatorMember(BUILTIN, 0, OperatorType.ADD, new FunctionHeader(result, new FunctionParameter(operand)));
152
+	}
153
+	
154
+	private static OperatorMember sub(ITypeID operand, ITypeID result) {
155
+		return new OperatorMember(BUILTIN, 0, OperatorType.SUB, new FunctionHeader(result, new FunctionParameter(operand)));
156
+	}
157
+	
158
+	private static OperatorMember mul(ITypeID operand, ITypeID result) {
159
+		return new OperatorMember(BUILTIN, 0, OperatorType.MUL, new FunctionHeader(result, new FunctionParameter(operand)));
160
+	}
161
+	
162
+	private static OperatorMember div(ITypeID operand, ITypeID result) {
163
+		return new OperatorMember(BUILTIN, 0, OperatorType.DIV, new FunctionHeader(result, new FunctionParameter(operand)));
164
+	}
165
+	
166
+	private static OperatorMember mod(ITypeID operand, ITypeID result) {
167
+		return new OperatorMember(BUILTIN, 0, OperatorType.MOD, new FunctionHeader(result, new FunctionParameter(operand)));
168
+	}
169
+	
170
+	private static CasterMember castExplicit(ITypeID result) {
171
+		return new CasterMember(CodePosition.BUILTIN, 0, result);
172
+	}
173
+	
174
+	private static CasterMember castImplicit(ITypeID result) {
175
+		return new CasterMember(CodePosition.BUILTIN, Modifiers.MODIFIER_IMPLICIT, result);
176
+	}
61 177
 }

+ 124
- 33
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java Datei anzeigen

@@ -16,8 +16,9 @@ import org.openzen.zenscript.codemodel.OperatorType;
16 16
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
17 17
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
18 18
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
19
+import org.openzen.zenscript.codemodel.expression.CallArguments;
20
+import org.openzen.zenscript.codemodel.expression.CallTranslator;
19 21
 import org.openzen.zenscript.codemodel.expression.ConstantCharExpression;
20
-import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
21 22
 import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
22 23
 import org.openzen.zenscript.codemodel.generic.GenericParameterBound;
23 24
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
@@ -26,10 +27,12 @@ import org.openzen.zenscript.codemodel.member.CasterMember;
26 27
 import org.openzen.zenscript.codemodel.member.ConstructorMember;
27 28
 import org.openzen.zenscript.codemodel.member.EqualsMember;
28 29
 import org.openzen.zenscript.codemodel.member.FieldMember;
30
+import org.openzen.zenscript.codemodel.member.FunctionalMember;
29 31
 import org.openzen.zenscript.codemodel.member.GetterMember;
30 32
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
31 33
 import org.openzen.zenscript.codemodel.member.MethodMember;
32 34
 import org.openzen.zenscript.codemodel.member.OperatorMember;
35
+import org.openzen.zenscript.codemodel.member.TranslatedOperatorMember;
33 36
 import org.openzen.zenscript.codemodel.member.builtin.ArrayIteratorKeyValues;
34 37
 import org.openzen.zenscript.codemodel.member.builtin.ArrayIteratorValues;
35 38
 import org.openzen.zenscript.codemodel.member.builtin.ComparatorMember;
@@ -50,6 +53,7 @@ import org.openzen.zenscript.codemodel.type.ITypeVisitor;
50 53
 import org.openzen.zenscript.codemodel.type.IteratorTypeID;
51 54
 import org.openzen.zenscript.codemodel.type.OptionalTypeID;
52 55
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
56
+import static org.openzen.zenscript.codemodel.type.member.BuiltinTypeMembers.*;
53 57
 import org.openzen.zenscript.shared.CodePosition;
54 58
 import static org.openzen.zenscript.shared.CodePosition.BUILTIN;
55 59
 
@@ -76,12 +80,17 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
76 80
 			case BOOL:
77 81
 				visitBool();
78 82
 				break;
83
+			case BYTE:
84
+				visitByte();
79 85
 			case INT:
80 86
 				visitInt();
81 87
 				break;
82 88
 			case UINT:
83 89
 				visitUInt();
84 90
 				break;
91
+			case LONG:
92
+				visitLong();
93
+				break;
85 94
 			case CHAR:
86 95
 				visitChar();
87 96
 				break;
@@ -261,49 +270,62 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
261 270
 	}
262 271
 	
263 272
 	private void visitBool() {
273
+		members.addOperator(BuiltinTypeMembers.BOOL_NOT);
264 274
 		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.NOT, new FunctionHeader(BOOL)), TypeMemberPriority.SPECIFIED);
265 275
 	}
266 276
 	
277
+	private void visitByte() {
278
+		
279
+	}
280
+	
267 281
 	private void visitInt() {
268
-		registerUnaryOperations();
282
+		members.addOperator(INT_NEG);
283
+		members.addOperator(INT_NOT);
284
+		
285
+		/*members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.PRE_INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
286
+		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.PRE_DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
287
+		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.POST_INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
288
+		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.POST_DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);*/
289
+
290
+		members.addOperator(OperatorType.COMPARE, new ComparatorMember(members.type), TypeMemberPriority.SPECIFIED);
269 291
 		
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);
292
+		members.addOperator(INT_ADD_INT);
293
+		members.addOperator(add(LONG, LONG, castedTargetCall(LONG_ADD_LONG, INT_TO_LONG)));
294
+		members.addOperator(add(FLOAT, FLOAT, castedTargetCall(FLOAT_ADD_FLOAT, INT_TO_FLOAT)));
295
+		members.addOperator(add(DOUBLE, DOUBLE, castedTargetCall(DOUBLE_ADD_DOUBLE, INT_TO_DOUBLE)));
274 296
 		
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);
297
+		members.addOperator(INT_SUB_INT);
298
+		members.addOperator(sub(LONG, LONG, castedTargetCall(LONG_SUB_LONG, INT_TO_LONG)));
299
+		members.addOperator(sub(FLOAT, FLOAT, castedTargetCall(FLOAT_SUB_FLOAT, INT_TO_FLOAT)));
300
+		members.addOperator(sub(DOUBLE, DOUBLE, castedTargetCall(DOUBLE_SUB_DOUBLE, INT_TO_DOUBLE)));
279 301
 		
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);
302
+		members.addOperator(INT_MUL_INT);
303
+		members.addOperator(mul(LONG, LONG, castedTargetCall(LONG_MUL_LONG, INT_TO_LONG)));
304
+		members.addOperator(mul(FLOAT, FLOAT, castedTargetCall(FLOAT_MUL_FLOAT, INT_TO_FLOAT)));
305
+		members.addOperator(mul(DOUBLE, DOUBLE, castedTargetCall(DOUBLE_MUL_DOUBLE, INT_TO_DOUBLE)));
284 306
 		
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);
307
+		members.addOperator(INT_DIV_INT);
308
+		members.addOperator(div(LONG, LONG, castedTargetCall(LONG_DIV_LONG, INT_TO_LONG)));
309
+		members.addOperator(div(FLOAT, FLOAT, castedTargetCall(FLOAT_DIV_FLOAT, INT_TO_FLOAT)));
310
+		members.addOperator(div(DOUBLE, DOUBLE, castedTargetCall(DOUBLE_DIV_DOUBLE, INT_TO_DOUBLE)));
289 311
 		
290
-		members.addOperator(BuiltinTypeMembers.INT_MOD_INT);
291
-		members.addOperator(BuiltinTypeMembers.INT_MOD_LONG);
312
+		members.addOperator(INT_MOD_INT);
313
+		members.addOperator(mod(LONG, LONG, castedTargetCall(LONG_MOD_LONG, INT_TO_LONG)));
292 314
 		
293
-		members.addGetter(BuiltinTypeMembers.INT_GET_MIN_VALUE, TypeMemberPriority.SPECIFIED);
294
-		members.addGetter(BuiltinTypeMembers.INT_GET_MAX_VALUE, TypeMemberPriority.SPECIFIED);
315
+		members.addGetter(INT_GET_MIN_VALUE);
316
+		members.addGetter(INT_GET_MAX_VALUE);
295 317
 		
296
-		members.addCaster(BuiltinTypeMembers.INT_TO_BYTE, TypeMemberPriority.SPECIFIED);
297
-		members.addCaster(BuiltinTypeMembers.INT_TO_SBYTE, TypeMemberPriority.SPECIFIED);
298
-		members.addCaster(BuiltinTypeMembers.INT_TO_SHORT, TypeMemberPriority.SPECIFIED);
299
-		members.addCaster(BuiltinTypeMembers.INT_TO_USHORT, TypeMemberPriority.SPECIFIED);
300
-		members.addCaster(BuiltinTypeMembers.INT_TO_UINT, TypeMemberPriority.SPECIFIED);
301
-		members.addCaster(BuiltinTypeMembers.INT_TO_LONG, TypeMemberPriority.SPECIFIED);
302
-		members.addCaster(BuiltinTypeMembers.INT_TO_ULONG, TypeMemberPriority.SPECIFIED);
303
-		members.addCaster(BuiltinTypeMembers.INT_TO_FLOAT, TypeMemberPriority.SPECIFIED);
304
-		members.addCaster(BuiltinTypeMembers.INT_TO_DOUBLE, TypeMemberPriority.SPECIFIED);
305
-		members.addCaster(BuiltinTypeMembers.INT_TO_CHAR, TypeMemberPriority.SPECIFIED);
306
-		members.addCaster(BuiltinTypeMembers.INT_TO_STRING, TypeMemberPriority.SPECIFIED);
318
+		members.addCaster(INT_TO_BYTE);
319
+		members.addCaster(INT_TO_SBYTE);
320
+		members.addCaster(INT_TO_SHORT);
321
+		members.addCaster(INT_TO_USHORT);
322
+		members.addCaster(INT_TO_UINT);
323
+		members.addCaster(INT_TO_LONG);
324
+		members.addCaster(INT_TO_ULONG);
325
+		members.addCaster(INT_TO_FLOAT);
326
+		members.addCaster(INT_TO_DOUBLE);
327
+		members.addCaster(INT_TO_CHAR);
328
+		members.addCaster(INT_TO_STRING);
307 329
 	}
308 330
 
309 331
 	private void visitUInt() {
@@ -315,6 +337,51 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
315 337
 		members.addGetter(new ConstantGetterMember("MIN_VALUE", position -> new ConstantUIntExpression(position, 0)), TypeMemberPriority.SPECIFIED);
316 338
 		members.addGetter(new ConstantGetterMember("MAX_VALUE", position -> new ConstantUIntExpression(position, 0xFFFFFFFF)), TypeMemberPriority.SPECIFIED);
317 339
 	}
340
+	
341
+	private void visitLong() {
342
+		members.addOperator(LONG_NEG);
343
+		members.addOperator(LONG_NOT);
344
+		
345
+		/*members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.PRE_INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
346
+		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.PRE_DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
347
+		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.POST_INCREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);
348
+		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.POST_DECREMENT, unaryHeader), TypeMemberPriority.SPECIFIED);*/
349
+
350
+		members.addOperator(OperatorType.COMPARE, new ComparatorMember(members.type), TypeMemberPriority.SPECIFIED);
351
+		
352
+		members.addOperator(LONG_ADD_LONG);
353
+		members.addOperator(add(FLOAT, FLOAT, castedTargetCall(FLOAT_ADD_FLOAT, LONG_TO_FLOAT)));
354
+		members.addOperator(add(DOUBLE, DOUBLE, castedTargetCall(DOUBLE_ADD_DOUBLE, LONG_TO_DOUBLE)));
355
+		
356
+		members.addOperator(LONG_SUB_LONG);
357
+		members.addOperator(sub(FLOAT, FLOAT, castedTargetCall(FLOAT_SUB_FLOAT, LONG_TO_FLOAT)));
358
+		members.addOperator(sub(DOUBLE, DOUBLE, castedTargetCall(DOUBLE_SUB_DOUBLE, LONG_TO_DOUBLE)));
359
+		
360
+		members.addOperator(LONG_MUL_LONG);
361
+		members.addOperator(mul(FLOAT, FLOAT, castedTargetCall(FLOAT_MUL_FLOAT, LONG_TO_FLOAT)));
362
+		members.addOperator(mul(DOUBLE, DOUBLE, castedTargetCall(DOUBLE_MUL_DOUBLE, LONG_TO_DOUBLE)));
363
+		
364
+		members.addOperator(LONG_DIV_LONG);
365
+		members.addOperator(div(FLOAT, FLOAT, castedTargetCall(FLOAT_DIV_FLOAT, LONG_TO_FLOAT)));
366
+		members.addOperator(div(DOUBLE, DOUBLE, castedTargetCall(DOUBLE_DIV_DOUBLE, LONG_TO_DOUBLE)));
367
+		
368
+		members.addOperator(LONG_MOD_LONG);
369
+		
370
+		members.addGetter(LONG_GET_MIN_VALUE);
371
+		members.addGetter(LONG_GET_MAX_VALUE);
372
+		
373
+		members.addCaster(LONG_TO_BYTE);
374
+		members.addCaster(LONG_TO_SBYTE);
375
+		members.addCaster(LONG_TO_SHORT);
376
+		members.addCaster(LONG_TO_USHORT);
377
+		members.addCaster(LONG_TO_INT);
378
+		members.addCaster(LONG_TO_UINT);
379
+		members.addCaster(LONG_TO_ULONG);
380
+		members.addCaster(LONG_TO_FLOAT);
381
+		members.addCaster(LONG_TO_DOUBLE);
382
+		members.addCaster(LONG_TO_CHAR);
383
+		members.addCaster(LONG_TO_STRING);
384
+	}
318 385
 
319 386
 	private void visitChar() {
320 387
 		registerUnaryOperations();
@@ -390,4 +457,28 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
390 457
 		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.DIV, binaryHeader), TypeMemberPriority.SPECIFIED);
391 458
 		members.addOperator(new OperatorMember(BUILTIN, 0, OperatorType.MOD, binaryHeader), TypeMemberPriority.SPECIFIED);
392 459
 	}
460
+	
461
+	private static OperatorMember add(ITypeID operand, ITypeID result, CallTranslator translator) {
462
+		return new TranslatedOperatorMember(BUILTIN, 0, OperatorType.ADD, new FunctionHeader(result, new FunctionParameter(operand)), translator);
463
+	}
464
+	
465
+	private static OperatorMember sub(ITypeID operand, ITypeID result, CallTranslator translator) {
466
+		return new TranslatedOperatorMember(BUILTIN, 0, OperatorType.SUB, new FunctionHeader(result, new FunctionParameter(operand)), translator);
467
+	}
468
+	
469
+	private static OperatorMember mul(ITypeID operand, ITypeID result, CallTranslator translator) {
470
+		return new TranslatedOperatorMember(BUILTIN, 0, OperatorType.MUL, new FunctionHeader(result, new FunctionParameter(operand)), translator);
471
+	}
472
+	
473
+	private static OperatorMember div(ITypeID operand, ITypeID result, CallTranslator translator) {
474
+		return new TranslatedOperatorMember(BUILTIN, 0, OperatorType.DIV, new FunctionHeader(result, new FunctionParameter(operand)), translator);
475
+	}
476
+	
477
+	private static OperatorMember mod(ITypeID operand, ITypeID result, CallTranslator translator) {
478
+		return new TranslatedOperatorMember(BUILTIN, 0, OperatorType.MOD, new FunctionHeader(result, new FunctionParameter(operand)), translator);
479
+	}
480
+	
481
+	private static CallTranslator castedTargetCall(FunctionalMember member, CasterMember caster) {
482
+		return call -> member.call(call.position, caster.call(call.position, call.target, CallArguments.EMPTY), call.arguments);
483
+	}
393 484
 }

+ 4
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java Datei anzeigen

@@ -115,6 +115,10 @@ public final class TypeMembers {
115 115
 		getOrCreateGroup(OperatorType.CALL).addMethod(caller, priority);
116 116
 	}
117 117
 	
118
+	public void addCaster(CasterMember caster) {
119
+		addCaster(caster, TypeMemberPriority.SPECIFIED);
120
+	}
121
+	
118 122
 	public void addCaster(CasterMember caster, TypeMemberPriority priority) {
119 123
 		for (int i = 0; i < casters.size(); i++) {
120 124
 			if (casters.get(i).member.getTargetType() == caster.toType) {

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeImplementation.java Datei anzeigen

@@ -12,5 +12,5 @@ import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
12 12
  * @author Hoofdgebruiker
13 13
  */
14 14
 public interface JavaBytecodeImplementation {
15
-	public void compile(JavaWriter writer);
15
+	void compile(JavaWriter writer);
16 16
 }

+ 103
- 21
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Datei anzeigen

@@ -11,8 +11,9 @@ import org.objectweb.asm.ClassWriter;
11 11
 import org.objectweb.asm.Opcodes;
12 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13 13
 import org.openzen.zenscript.codemodel.ScriptBlock;
14
+import org.openzen.zenscript.codemodel.member.DefinitionMember;
14 15
 import org.openzen.zenscript.codemodel.statement.Statement;
15
-import org.openzen.zenscript.codemodel.type.member.BuiltinTypeMembers;
16
+import static org.openzen.zenscript.codemodel.type.member.BuiltinTypeMembers.*;
16 17
 import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
17 18
 import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
18 19
 import org.openzen.zenscript.shared.SourceFile;
@@ -24,26 +25,107 @@ import org.openzen.zenscript.shared.SourceFile;
24 25
 public class JavaCompiler {
25 26
 	static {
26 27
 		JavaClassInfo jInteger = new JavaClassInfo("java/lang/Integer");
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"));
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
-		
36
-		BuiltinTypeMembers.INT_TO_BYTE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2b());
37
-		BuiltinTypeMembers.INT_TO_SBYTE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2b());
38
-		BuiltinTypeMembers.INT_TO_SHORT.setTag(JavaBytecodeImplementation.class, writer -> writer.i2s());
39
-		BuiltinTypeMembers.INT_TO_USHORT.setTag(JavaBytecodeImplementation.class, writer -> writer.i2s());
40
-		BuiltinTypeMembers.INT_TO_UINT.setTag(JavaBytecodeImplementation.class, writer -> {});
41
-		BuiltinTypeMembers.INT_TO_LONG.setTag(JavaBytecodeImplementation.class, writer -> writer.i2l());
42
-		BuiltinTypeMembers.INT_TO_ULONG.setTag(JavaBytecodeImplementation.class, writer -> writer.i2l());
43
-		BuiltinTypeMembers.INT_TO_FLOAT.setTag(JavaBytecodeImplementation.class, writer -> writer.i2f());
44
-		BuiltinTypeMembers.INT_TO_DOUBLE.setTag(JavaBytecodeImplementation.class, writer -> writer.i2d());
45
-		BuiltinTypeMembers.INT_TO_CHAR.setTag(JavaBytecodeImplementation.class, writer -> writer.i2s());
46
-		BuiltinTypeMembers.INT_TO_STRING.setTag(JavaMethodInfo.class, new JavaMethodInfo(jInteger, "toString", "(I)Ljava/lang/String;", true));
28
+		JavaClassInfo jLong = new JavaClassInfo("java/lang/Long");
29
+		JavaClassInfo jFloat = new JavaClassInfo("java/lang/Float");
30
+		JavaClassInfo jDouble = new JavaClassInfo("java/lang/Double");
31
+		
32
+		INT_GET_MIN_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jInteger, "MIN_VALUE", "I"));
33
+		INT_GET_MAX_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jInteger, "MAX_VALUE", "I"));
34
+		
35
+		LONG_GET_MIN_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jLong, "MIN_VALUE", "J"));
36
+		LONG_GET_MAX_VALUE.setTag(JavaFieldInfo.class, new JavaFieldInfo(jLong, "MAX_VALUE", "J"));
37
+		
38
+		implement(BOOL_NOT, writer -> writer.iNot());
39
+		
40
+		implement(BYTE_NOT, writer -> writer.iNot());
41
+		implement(SBYTE_NOT, writer -> writer.iNot());
42
+		implement(SHORT_NOT, writer -> writer.iNot());
43
+		implement(USHORT_NOT, writer -> writer.iNot());
44
+		implement(INT_NOT, writer -> writer.iNot());
45
+		implement(UINT_NOT, writer -> writer.iNot());
46
+		implement(LONG_NOT, writer -> writer.lNot());
47
+		implement(ULONG_NOT, writer -> writer.lNot());
48
+		
49
+		implement(BYTE_NEG, writer -> writer.iNeg());
50
+		implement(SBYTE_NEG, writer -> writer.iNeg());
51
+		implement(SHORT_NEG, writer -> writer.iNeg());
52
+		implement(USHORT_NEG, writer -> writer.iNeg());
53
+		implement(INT_NEG, writer -> writer.iNeg());
54
+		implement(UINT_NEG, writer -> writer.iNeg());
55
+		implement(LONG_NEG, writer -> writer.lNeg());
56
+		implement(ULONG_NEG, writer -> writer.lNeg());
57
+		implement(FLOAT_NEG, writer -> writer.fNeg());
58
+		implement(DOUBLE_NEG, writer -> writer.dNeg());
59
+		
60
+		implement(BYTE_ADD_BYTE, writer -> writer.iAdd());
61
+		implement(SBYTE_ADD_SBYTE, writer -> writer.iAdd());
62
+		implement(SHORT_ADD_SHORT, writer -> writer.iAdd());
63
+		implement(USHORT_ADD_USHORT, writer -> writer.iAdd());
64
+		implement(INT_ADD_INT, writer -> writer.iAdd());
65
+		implement(UINT_ADD_UINT, writer -> writer.iAdd());
66
+		implement(LONG_ADD_LONG, writer -> writer.lAdd());
67
+		implement(ULONG_ADD_ULONG, writer -> writer.lAdd());
68
+		implement(FLOAT_ADD_FLOAT, writer -> writer.fAdd());
69
+		implement(DOUBLE_ADD_DOUBLE, writer -> writer.dAdd());
70
+		// TODO: STRING_ADD_STRING
71
+		
72
+		implement(BYTE_SUB_BYTE, writer -> writer.iSub());
73
+		implement(SBYTE_SUB_SBYTE, writer -> writer.iSub());
74
+		implement(SHORT_SUB_SHORT, writer -> writer.iSub());
75
+		implement(USHORT_SUB_USHORT, writer -> writer.iSub());
76
+		implement(INT_SUB_INT, writer -> writer.iSub());
77
+		implement(UINT_SUB_UINT, writer -> writer.iSub());
78
+		implement(LONG_SUB_LONG, writer -> writer.lSub());
79
+		implement(ULONG_SUB_ULONG, writer -> writer.lSub());
80
+		implement(FLOAT_SUB_FLOAT, writer -> writer.fSub());
81
+		implement(DOUBLE_SUB_DOUBLE, writer -> writer.dSub());
82
+		
83
+		implement(BYTE_MUL_BYTE, writer -> writer.iMul());
84
+		implement(SBYTE_MUL_SBYTE, writer -> writer.iMul());
85
+		implement(SHORT_MUL_SHORT, writer -> writer.iMul());
86
+		implement(USHORT_MUL_USHORT, writer -> writer.iMul());
87
+		implement(INT_MUL_INT, writer -> writer.iMul());
88
+		implement(UINT_MUL_UINT, writer -> writer.iMul());
89
+		implement(LONG_MUL_LONG, writer -> writer.lMul());
90
+		implement(ULONG_MUL_ULONG, writer -> writer.lMul());
91
+		implement(FLOAT_MUL_FLOAT, writer -> writer.fMul());
92
+		implement(DOUBLE_MUL_DOUBLE, writer -> writer.dMul());
93
+		
94
+		implement(INT_DIV_INT, writer -> writer.iDiv());
95
+		implement(INT_MOD_INT, writer -> writer.iRem());
96
+		
97
+		implement(INT_TO_BYTE, writer -> writer.i2b());
98
+		implement(INT_TO_SBYTE, writer -> writer.i2b());
99
+		implement(INT_TO_SHORT, writer -> writer.i2s());
100
+		implement(INT_TO_USHORT, writer -> writer.i2s());
101
+		implement(INT_TO_UINT, writer -> {});
102
+		implement(INT_TO_LONG, writer -> writer.i2l());
103
+		implement(INT_TO_ULONG, writer -> writer.i2l());
104
+		implement(INT_TO_FLOAT, writer -> writer.i2f());
105
+		implement(INT_TO_DOUBLE, writer -> writer.i2d());
106
+		implement(INT_TO_CHAR, writer -> writer.i2s());
107
+		INT_TO_STRING.setTag(JavaMethodInfo.class, new JavaMethodInfo(jInteger, "toString", "(I)Ljava/lang/String;", true));
108
+		
109
+		implement(LONG_TO_BYTE, writer -> { writer.l2i(); writer.i2b(); });
110
+		implement(LONG_TO_SBYTE, writer -> { writer.l2i(); writer.i2b(); });
111
+		implement(LONG_TO_SHORT, writer -> { writer.l2i(); writer.i2s(); });
112
+		implement(LONG_TO_USHORT, writer -> { writer.l2i(); writer.i2s(); });
113
+		implement(LONG_TO_INT, writer -> writer.l2i());
114
+		implement(LONG_TO_UINT, writer -> writer.l2i());
115
+		implement(LONG_TO_ULONG, writer -> {});
116
+		implement(LONG_TO_FLOAT, writer -> writer.l2f());
117
+		implement(LONG_TO_DOUBLE, writer -> writer.l2d());
118
+		implement(LONG_TO_CHAR, writer -> { writer.l2i(); writer.i2s(); });
119
+		LONG_TO_STRING.setTag(JavaMethodInfo.class, new JavaMethodInfo(jLong, "toString", "(J)Ljava/lang/String;", true));
120
+		
121
+		FLOAT_BITS.setTag(JavaMethodInfo.class, new JavaMethodInfo(jFloat, "floatToRawIntBits", "(F)I", true));
122
+		DOUBLE_BITS.setTag(JavaMethodInfo.class, new JavaMethodInfo(jDouble, "doubleToRawLongBits", "(D)J", true));
123
+		FLOAT_FROMBITS.setTag(JavaMethodInfo.class, new JavaMethodInfo(jFloat, "intBitsToFloat", "(I)F", true));
124
+		DOUBLE_FROMBITS.setTag(JavaMethodInfo.class, new JavaMethodInfo(jDouble, "longBitsToDouble", "(J)D", true));
125
+	}
126
+	
127
+	private static void implement(DefinitionMember member, JavaBytecodeImplementation implementation) {
128
+		member.setTag(JavaBytecodeImplementation.class, implementation);
47 129
 	}
48 130
 	
49 131
 	private final JavaModule target;

+ 4
- 4
Parser/src/main/java/org/openzen/zenscript/lexer/Token.java Datei anzeigen

@@ -11,11 +11,11 @@ import org.openzen.zenscript.shared.CodePosition;
11 11
  */
12 12
 public interface Token<TT extends TokenType>
13 13
 {
14
-	public CodePosition getPosition();
14
+	CodePosition getPosition();
15 15
 	
16
-	public TT getType();
16
+	TT getType();
17 17
 	
18
-	public String getContent();
18
+	String getContent();
19 19
 	
20
-	public String getWhitespaceBefore();
20
+	String getWhitespaceBefore();
21 21
 }

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/lexer/TokenType.java Datei anzeigen

@@ -14,7 +14,7 @@ package org.openzen.zenscript.lexer;
14 14
  */
15 15
 public interface TokenType
16 16
 {
17
-	public String getRegexp();
17
+	String getRegexp();
18 18
 	
19
-	public boolean isWhitespace();
19
+	boolean isWhitespace();
20 20
 }

+ 3
- 1
ScriptingExample/scripts/helloworld.zs Datei anzeigen

@@ -1,3 +1,5 @@
1 1
 println("Hello \&copy; world!");
2 2
 println(5);
3
-println(1 + 3);
3
+println(2 + 5);
4
+println(1 - 2);
5
+println(1 + 3 as long);

+ 2
- 2
Shared/src/main/java/org/openzen/zenscript/shared/StringUtils.java Datei anzeigen

@@ -223,7 +223,7 @@ public class StringUtils {
223 223
 	 * @param hex hex digit
224 224
 	 * @return converted value
225 225
 	 */
226
-	public static int readHexCharacter(char hex)
226
+	private static int readHexCharacter(char hex)
227 227
 	{
228 228
 		if (hex >= '0' && hex <= '9')
229 229
 			return hex - '0';
@@ -267,7 +267,7 @@ public class StringUtils {
267 267
 	 * @throws IllegalArgumentException if the given string does not contain a
268 268
 	 *	valid character entity at the given position
269 269
 	 */
270
-	public static CharacterEntity readCharacterEntity(String str, int offset)
270
+	private static CharacterEntity readCharacterEntity(String str, int offset)
271 271
 	{
272 272
 		if (offset + 3 >= str.length())
273 273
 			throw new IllegalArgumentException("Not a proper character entity");

Laden…
Abbrechen
Speichern