Skip to content

Commit 6588788

Browse files
committedJul 13, 2018
Match on platform
1 parent abc694e commit 6588788

File tree

20 files changed

+140
-99
lines changed

20 files changed

+140
-99
lines changed
 

‎backend/bootstrap.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ fi
1717

1818
(
1919
cd src/
20-
rm -f main_js.wyb
21-
$WYBY main_js.wyv
20+
rm -f main.wyb
21+
$WYBY main.wyv
2222
echo "Bootstrapping..."
23-
time $WYVERN main_java.wyv > ../boot.js
24-
) || rm -f boot.js
23+
time $WYVERN main.wyv > ../boot.js
24+
) || (rm -f boot.js && exit 1)
2525

2626
./self-bootstrap.sh
2727
diff -q boot.js boot.js.old || (echo "sanity check failed" && exit 1)

‎backend/examples/algebra.wyv

+16-16
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,22 @@ def numberToString(x : Float) : String
142142
def toString(t : Term) : String
143143
def productWrap(s : Term) : String
144144
match s:
145-
s:Term => toString(s)
146145
s:Sum => "(" + toString(s) + ")"
146+
s:Term => toString(s)
147147

148148
match t:
149149
t:Constant => numberToString(t.value)
150150
t:Variable => t.name
151151
t:Sum => toString(t.u) + " + " + toString(t.v)
152152
t:Product => match t.u:
153-
u:Term => productWrap(t.u) + " * " + productWrap(t.v)
154153
u:Constant => if (floatEq(u.value, -1.0))
155154
"-" + toString(t.v)
156155
else
157156
numberToString(u.value) + toString(t.v)
157+
u:Term => productWrap(t.u) + " * " + productWrap(t.v)
158158
t:Pow => match t.u:
159-
u:Term => "(" + toString(t.u) + ")^" + numberToString(t.n)
160159
u:Variable => toString(t.u) + "^" + numberToString(t.n)
160+
u:Term => "(" + toString(t.u) + ")^" + numberToString(t.n)
161161
t:Sin => "sin(" + toString(t.u) + ")"
162162
t:Cos => "cos(" + toString(t.u) + ")"
163163
t:Exp => numberToString(t.b) + "^(" + toString(t.u) + ")"
@@ -218,8 +218,8 @@ def trySimplify2(
218218
def simplify(t : Term) : TermStep
219219
def isConstant(a : Term, n : Float) : Boolean
220220
match a:
221-
_:Term => false
222221
a:Constant => floatEq(a.value, n)
222+
_:Term => false
223223

224224
def isZero(a : Term) : Boolean
225225
isConstant(a, 0.0)
@@ -229,23 +229,23 @@ def simplify(t : Term) : TermStep
229229

230230
def isSin2(a : Term) : Boolean
231231
match a:
232-
_:Term => false
233232
a:Pow => if (floatEq(a.n, 2.0))
234233
match a.u:
235-
_:Term => false
236234
u:Sin => true
235+
_:Term => false
237236
else
238237
NoStep
238+
_:Term => false
239239

240240
def isCos2(a : Term) : Boolean
241241
match a:
242-
_:Term => false
243242
a:Pow => if (floatEq(a.n, 2.0))
244243
match a.u:
245-
_:Term => false
246244
u:Cos => true
245+
_:Term => false
247246
else
248247
NoStep
248+
_:Term => false
249249

250250
def simplifySum(a : Term, b : Term) : TermStep
251251
def zeroSumRule() : TermStep
@@ -258,10 +258,10 @@ def simplify(t : Term) : TermStep
258258

259259
def constantSumRule() : TermStep
260260
match a:
261-
a:Term => NoStep
262261
a:Constant => match b:
263-
b:Term => NoStep
264262
b:Constant => Step(Constant(a.value + b.value))
263+
b:Term => NoStep
264+
a:Term => NoStep
265265

266266
def pythagorasRule() : TermStep
267267
if (isSin2(a) && isCos2(b) || isCos2(a) && isSin2(b))
@@ -294,17 +294,17 @@ def simplify(t : Term) : TermStep
294294

295295
def constantProductRule() : TermStep
296296
match a:
297-
a:Term => NoStep
298297
a:Constant => match b:
299-
b:Term => NoStep
300298
b:Constant => Step(Constant(a.value * b.value))
299+
b:Term => NoStep
300+
a:Term => NoStep
301301

302302
def leftConstantRule() : TermStep
303303
match a:
304+
a:Constant => NoStep
304305
a:Term => match b:
305-
b:Term => NoStep
306306
b:Constant => Step(Product(b, a))
307-
a:Constant => NoStep
307+
b:Term => NoStep
308308

309309
firstMatch(zeroProductRule(),
310310
() => firstMatch(oneProductRule(),
@@ -352,11 +352,11 @@ def simplify(t : Term) : TermStep
352352

353353
def expInverseRule() : TermStep
354354
match u:
355-
u:Term => NoStep
356355
u:Log => if (floatEq(b, u.b))
357356
Step(u.u)
358357
else
359358
NoStep
359+
u:Term => NoStep
360360

361361
firstMatch(expZeroPowRule(),
362362
() => firstMatch(expZeroBaseRule(),
@@ -387,9 +387,9 @@ def simplify(t : Term) : TermStep
387387

388388
def bringDownRule() : TermStep
389389
match u:
390-
u:Term => NoStep
391390
u:Pow => Step(Product(Constant(u.n), Log(b, u.u)))
392391
u:Exp => Step(Product(u.u, Log(b, Constant(u.b))))
392+
u:Term => NoStep
393393

394394
firstMatch(logOneArgRule(),
395395
() => firstMatch(logZeroBaseRule(),

‎backend/self-bootstrap.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ fi
1313

1414
(
1515
cd src/
16-
rm -f main_js.wyb
17-
$WYBY main_js.wyv
16+
rm -f main.wyb
17+
$WYBY main.wyv
1818
)
1919
echo "Self-bootstrapping"
2020
echo -n "time: "
21-
time node boot.js src/main_js.wyb > selfboot.js || rm selfboot.js
21+
time node boot.js src/main.wyb > selfboot.js
2222
echo "Next boot"
2323
echo -n "time: "
24-
time node selfboot.js src/main_js.wyb > nextboot.js || rm selfboot.js nextboot.js
24+
time node selfboot.js src/main.wyb > nextboot.js
2525
mv boot.js boot.js.old
2626
mv nextboot.js boot.js
2727
rm selfboot.js

‎backend/src/main.wyv

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
module def compile(stdout: Stdout, support: PlatformSupport)
1+
require platform
2+
require stdout
23

4+
import support_js
5+
import support_java
36
import from_protobuf
47
import wyb_ast
58
import rename
69
import emit_js
710
import util
811

12+
val plt: system.Platform = platform
13+
14+
val support = match plt:
15+
java: system.Java => support_java.apply(java)
16+
javascript: system.JavaScript => support_js.apply(javascript)
17+
918
val from_protobuf = from_protobuf.apply(support)
1019

1120
def compileExpression(e: wyb_ast.Expression): String
@@ -36,7 +45,6 @@ def compile(wyb: Dyn): Unit
3645
val m: Int = wyb.getModulesCount()
3746
moduleLoop(m - 1)
3847

39-
def main(): Unit
40-
val filename = support.getFirstCommandLineArg()
41-
val wyb = support.loadBytecode(filename)
42-
compile(wyb)
48+
val filename = support.getFirstCommandLineArg()
49+
val wyb = support.loadBytecode(filename)
50+
compile(wyb)

‎backend/src/main_java.wyv

-10
This file was deleted.

‎backend/src/main_js.wyv

-10
This file was deleted.

‎backend/src/print_bytecode.wyv

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require stdout
2+
require support_java
23

3-
import wyvern.BackendSupport
44

55
// Designed to work with interpreter only right now
66

7-
val test = BackendSupport.loadBytecode("examples/algebra.wyb")
7+
val test = support_java.loadBytecode("main.wyb")
88
val expression = test.getModules(0).getValueModule().getExpression()
99
stdout.print(test.toString())

‎backend/src/support_java.wyv

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ def dynToList(o: Dyn): list.List
1414
bytecode.dynToList(o)
1515

1616
def getFirstCommandLineArg(): String
17-
"main_js.wyb"
17+
"main.wyb"

‎backend/test.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -e
66

77
TIMEFORMAT='%3R'
88

9-
FILES=( "${@:-examples/*.wyv}" )
9+
FILES=( ${@:-examples/*.wyv} )
1010

1111
WYBY=$WYVERN_HOME/bin/wyby
1212

@@ -16,16 +16,16 @@ if [ ! -f boot.js ]; then
1616
exit 1
1717
fi
1818

19-
for f in ${FILES[@]}; do
20-
echo "running $f:"
19+
for f in "${FILES[@]}"; do
20+
echo "running $f:" >&2
2121
(
2222
DIR="$(dirname "$f")"
2323
FILE="$(basename "$f")"
2424
cd "$DIR"
2525
rm -f "${f%.*}.wyb"
2626
$WYBY "$FILE"
2727
)
28-
echo -n "Time to compile: "
28+
echo -n "Time to compile: " >&2
2929
time node boot.js "${f%.*}.wyb" > "${f%.*}.js"
3030
time node "${f%.*}.js"
3131
done

‎examples/introductory/algebra.wyv

+16-16
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,22 @@ def numberToString(x : Number) : String
143143
def toString(t : Term) : String
144144
def productWrap(s : Term) : String
145145
match s:
146-
s:Term => toString(s)
147146
s:Sum => "(" + toString(s) + ")"
147+
s:Term => toString(s)
148148

149149
match t:
150150
t:Constant => numberToString(t.value)
151151
t:Variable => t.name
152152
t:Sum => toString(t.u) + " + " + toString(t.v)
153153
t:Product => match t.u:
154-
u:Term => productWrap(t.u) + " * " + productWrap(t.v)
155154
u:Constant => if (floatEq(u.value, -1.0))
156155
"-" + toString(t.v)
157156
else
158157
numberToString(u.value) + toString(t.v)
158+
u:Term => productWrap(t.u) + " * " + productWrap(t.v)
159159
t:Pow => match t.u:
160-
u:Term => "(" + toString(t.u) + ")^" + numberToString(t.n)
161160
u:Variable => toString(t.u) + "^" + numberToString(t.n)
161+
u:Term => "(" + toString(t.u) + ")^" + numberToString(t.n)
162162
t:Sin => "sin(" + toString(t.u) + ")"
163163
t:Cos => "cos(" + toString(t.u) + ")"
164164
t:Exp => numberToString(t.b) + "^(" + toString(t.u) + ")"
@@ -219,8 +219,8 @@ def trySimplify2(
219219
def simplify(t : Term) : TermStep
220220
def isConstant(a : Term, n : Number) : Boolean
221221
match a:
222-
_:Term => false
223222
a:Constant => floatEq(a.value, n)
223+
_:Term => false
224224

225225
def isZero(a : Term) : Boolean
226226
isConstant(a, 0.0)
@@ -230,23 +230,23 @@ def simplify(t : Term) : TermStep
230230

231231
def isSin2(a : Term) : Boolean
232232
match a:
233-
_:Term => false
234233
a:Pow => if (floatEq(a.n, 2.0))
235234
match a.u:
236-
_:Term => false
237235
u:Sin => true
236+
_:Term => false
238237
else
239238
NoStep
239+
_:Term => false
240240

241241
def isCos2(a : Term) : Boolean
242242
match a:
243-
_:Term => false
244243
a:Pow => if (floatEq(a.n, 2.0))
245244
match a.u:
246-
_:Term => false
247245
u:Cos => true
246+
_:Term => false
248247
else
249248
NoStep
249+
_:Term => false
250250

251251
def simplifySum(a : Term, b : Term) : TermStep
252252
def zeroSumRule() : TermStep
@@ -259,10 +259,10 @@ def simplify(t : Term) : TermStep
259259

260260
def constantSumRule() : TermStep
261261
match a:
262-
a:Term => NoStep
263262
a:Constant => match b:
264-
b:Term => NoStep
265263
b:Constant => Step(Constant(a.value + b.value))
264+
b:Term => NoStep
265+
a:Term => NoStep
266266

267267
def pythagorasRule() : TermStep
268268
if (isSin2(a) && isCos2(b) || isCos2(a) && isSin2(b))
@@ -295,17 +295,17 @@ def simplify(t : Term) : TermStep
295295

296296
def constantProductRule() : TermStep
297297
match a:
298-
a:Term => NoStep
299298
a:Constant => match b:
300-
b:Term => NoStep
301299
b:Constant => Step(Constant(a.value * b.value))
300+
b:Term => NoStep
301+
a:Term => NoStep
302302

303303
def leftConstantRule() : TermStep
304304
match a:
305+
a:Constant => NoStep
305306
a:Term => match b:
306-
b:Term => NoStep
307307
b:Constant => Step(Product(b, a))
308-
a:Constant => NoStep
308+
b:Term => NoStep
309309

310310
firstMatch(zeroProductRule(),
311311
() => firstMatch(oneProductRule(),
@@ -353,11 +353,11 @@ def simplify(t : Term) : TermStep
353353

354354
def expInverseRule() : TermStep
355355
match u:
356-
u:Term => NoStep
357356
u:Log => if (floatEq(b, u.b))
358357
Step(u.u)
359358
else
360359
NoStep
360+
u:Term => NoStep
361361

362362
firstMatch(expZeroPowRule(),
363363
() => firstMatch(expZeroBaseRule(),
@@ -388,9 +388,9 @@ def simplify(t : Term) : TermStep
388388

389389
def bringDownRule() : TermStep
390390
match u:
391-
u:Term => NoStep
392391
u:Pow => Step(Product(Constant(u.n), Log(b, u.u)))
393392
u:Exp => Step(Product(u.u, Log(b, Constant(u.b))))
393+
u:Term => NoStep
394394

395395
firstMatch(logOneArgRule(),
396396
() => firstMatch(logZeroBaseRule(),

‎tools/src/wyvern/stdlib/Globals.java

+16-10
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ public static Module getPreludeModule() {
102102

103103
private static SeqExpr getPrelude() {
104104
if (!usePrelude) {
105-
return new SeqExpr();
105+
SeqExpr result = new SeqExpr();
106+
result.addBinding(new BindingSite("system"), Globals.getSystemType(), Globals.getSystemValue(), false);
107+
return result;
106108
}
107109
if (prelude == null) {
108110
if (gettingPrelude) {
@@ -115,6 +117,7 @@ private static SeqExpr getPrelude() {
115117
preludeModule = ModuleResolver.getLocal().load("<prelude>", file, true);
116118
prelude = ModuleResolver.getLocal().wrap(preludeModule.getExpression(), preludeModule.getDependencies());
117119
TailCallVisitor.annotate(prelude);
120+
prelude.addBinding(new BindingSite("system"), Globals.getSystemType(), Globals.getSystemValue(), false);
118121
}
119122
return prelude;
120123
}
@@ -160,7 +163,7 @@ public static BindingSite getSystemSite() {
160163
return system;
161164
}
162165

163-
private static ValueType getSystemType() {
166+
public static ValueType getSystemType() {
164167
List<FormalArg> ifTrueArgs = Arrays.asList(
165168
new FormalArg("trueBranch", Util.unitToDynType()),
166169
new FormalArg("falseBranch", Util.unitToDynType()));
@@ -225,7 +228,7 @@ private static ValueType getSystemType() {
225228
declTypes.add(new ConcreteTypeMember("Dyn", new DynamicType()));
226229
ExtensibleTagType platformType = new ExtensibleTagType(null, Util.unitType());
227230
declTypes.add(new ConcreteTypeMember("Platform", platformType));
228-
NominalType systemPlatform = new NominalType("system", "Platform");
231+
NominalType systemPlatform = new NominalType("this", "Platform");
229232
ExtensibleTagType javaType = new ExtensibleTagType(systemPlatform, Util.unitType());
230233
declTypes.add(new ConcreteTypeMember("Java", javaType));
231234
ExtensibleTagType javascriptType = new ExtensibleTagType(systemPlatform, Util.unitType());
@@ -242,7 +245,7 @@ private static ValueType getSystemType() {
242245
declTypes.add(new AbstractTypeMember("Context"));
243246
declTypes.add(new ValDeclType("unit", Util.unitType()));
244247
declTypes.add(new EffectDeclType("ffiEffect", null, null));
245-
ValueType systemType = new StructuralType(system, declTypes);
248+
ValueType systemType = new StructuralType(new BindingSite("this"), declTypes);
246249
return systemType;
247250
}
248251

@@ -257,15 +260,18 @@ public static TypeContext getStandardTypeContext() {
257260

258261
public static EvalContext getStandardEvalContext() {
259262
EvalContext ctx = EvalContext.empty();
260-
ctx = ctx.extend(system, Globals.getSystemValue());
261263
SeqExpr sexpr = prelude;
262264
if (sexpr != null) {
263265
ctx = sexpr.interpretCtx(ctx).getSecond();
264266
}
265267
return ctx;
266268
}
267269

268-
private static ObjectValue getSystemValue() {
270+
private static Declaration platformTypeDeclaration(String platform) {
271+
return new TypeDeclaration(platform, ((ConcreteTypeMember) getSystemType().findDecl(platform, null)).getSourceType(), FileLocation.UNKNOWN);
272+
}
273+
274+
public static ObjectValue getSystemValue() {
269275
// construct a type for the system object
270276
List<Declaration> decls = new LinkedList<Declaration>();
271277
decls.add(new TypeDeclaration("Int", new NominalType("this", "Int"), FileLocation.UNKNOWN));
@@ -275,10 +281,10 @@ private static ObjectValue getSystemValue() {
275281
decls.add(new TypeDeclaration("Character", new NominalType("this", "Character"), FileLocation.UNKNOWN));
276282
decls.add(new TypeDeclaration("Dyn", new DynamicType(), FileLocation.UNKNOWN));
277283
decls.add(new TypeDeclaration("Nothing", new BottomType(), FileLocation.UNKNOWN));
278-
decls.add(new TypeDeclaration("Java", new NominalType("this", "Java"), FileLocation.UNKNOWN));
279-
decls.add(new TypeDeclaration("Platform", new NominalType("this", "Platform"), FileLocation.UNKNOWN));
280-
decls.add(new TypeDeclaration("Python", new NominalType("this", "Python"), FileLocation.UNKNOWN));
281-
decls.add(new TypeDeclaration("JavaScript", new NominalType("this", "JavaScript"), FileLocation.UNKNOWN));
284+
decls.add(platformTypeDeclaration("Platform"));
285+
decls.add(platformTypeDeclaration("Java"));
286+
decls.add(platformTypeDeclaration("Python"));
287+
decls.add(platformTypeDeclaration("JavaScript"));
282288
decls.add(new ValDeclaration("unit", Util.unitType(), Util.unitValue(), null));
283289
ObjectValue systemVal = new ObjectValue(decls, new BindingSite("this"), getSystemType(), null, null, EvalContext.empty());
284290
return systemVal;

‎tools/src/wyvern/target/corewyvernIL/decltype/EffectDeclType.java

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.HashSet;
77
import java.util.Set;
88

9+
import wyvern.stdlib.support.backend.BytecodeOuterClass;
910
import wyvern.target.corewyvernIL.IASTNode;
1011
import wyvern.target.corewyvernIL.astvisitor.ASTVisitor;
1112
import wyvern.target.corewyvernIL.effects.Effect;
@@ -33,6 +34,14 @@ public EffectSet getEffectSet() {
3334
return effectSet;
3435
}
3536

37+
@Override
38+
public BytecodeOuterClass.DeclType emitBytecode() {
39+
// stub
40+
return BytecodeOuterClass.DeclType.newBuilder().setOpaqueTypeDecl(
41+
BytecodeOuterClass.DeclType.OpaqueTypeDecl.newBuilder().setName(getName()).setStateful(false)
42+
).build();
43+
}
44+
3645
/** Conduct semantics check, by decomposing the effect sets of the two
3746
* (effect)DeclTypes before comparing them.
3847
*/

‎tools/src/wyvern/target/corewyvernIL/expression/FFI.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import wyvern.target.corewyvernIL.VarBinding;
99
import wyvern.target.corewyvernIL.astvisitor.ASTVisitor;
1010
import wyvern.target.corewyvernIL.effects.EffectAccumulator;
11+
import wyvern.target.corewyvernIL.support.EvalContext;
1112
import wyvern.target.corewyvernIL.support.GenContext;
1213
import wyvern.target.corewyvernIL.support.GenUtil;
1314
import wyvern.target.corewyvernIL.support.InterpreterState;
@@ -57,7 +58,14 @@ public String getImportName() {
5758

5859
@Override
5960
public BytecodeOuterClass.Expression emitBytecode() {
60-
return BytecodeOuterClass.Expression.newBuilder().setLiteral(BytecodeOuterClass.Expression.Literal.newBuilder().setStringLiteral("FFI")).build();
61+
return BytecodeOuterClass.Expression.newBuilder().setNewExpression(
62+
BytecodeOuterClass.Expression.NewExpression.newBuilder().setType(type.emitBytecodeType()).setSelfName("unused").build()
63+
).build();
64+
}
65+
66+
public Tag getTag(EvalContext ctx) {
67+
NominalType nt = (NominalType) this.getType();
68+
return nt.getTag(ctx);
6169
}
6270

6371
public static Pair<VarBinding, GenContext> importURI(URI uri, GenContext ctx, HasLocation errorLocation) {

‎tools/src/wyvern/target/corewyvernIL/expression/Match.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,21 @@ public BytecodeOuterClass.Expression emitBytecode() {
115115
@Override
116116
public Value interpret(EvalContext ctx) {
117117
Value matchValue = matchExpr.interpret(ctx);
118-
Tag matchTag = ((ObjectValue) matchValue).getTag();
118+
Tag matchTag;
119+
if (matchValue instanceof ObjectValue) {
120+
matchTag = ((ObjectValue) matchValue).getTag();
121+
} else if (matchValue instanceof FFI) {
122+
matchTag = ((FFI) matchValue).getTag(ctx);
123+
} else {
124+
throw new UnsupportedOperationException("Attempted to match on value without tag");
125+
}
119126
Case matchedCase = null;
120127
FailureReason reason = new FailureReason();
121128
for (Case c : cases) {
122129
ValueType caseMatchedType = c.getPattern();
123130
if (matchTag.isSubTag(caseMatchedType.getTag(ctx), ctx)) {
124131
matchedCase = c;
132+
break;
125133
}
126134
}
127135
if (matchedCase == null && elseExpr == null) {

‎tools/src/wyvern/target/corewyvernIL/expression/SeqExpr.java

-6
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,4 @@ public void merge(IExpr body) {
228228
addExpr(body);
229229
}
230230
}
231-
232-
public SeqExpr clone() {
233-
SeqExpr clone = new SeqExpr();
234-
clone.elements.addAll(this.elements);
235-
return clone;
236-
}
237231
}

‎tools/src/wyvern/target/corewyvernIL/support/ModuleResolver.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -388,24 +388,28 @@ public GenContext extendGenContext(GenContext ctx, List<TypedModuleSpec> depende
388388
return ctx;
389389
}
390390

391-
public BytecodeOuterClass.Bytecode emitBytecode(Module module, List<TypedModuleSpec> dependencies) {
391+
public SeqExpr buildPreludedExpression(Expression expression) {
392392
Module prelude = Globals.getPreludeModule();
393-
SeqExpr preludeExpression = (SeqExpr) prelude.getExpression();
393+
SeqExpr expr = new SeqExpr();
394+
expr.addBinding(new BindingSite("system"), Globals.getSystemType(), Globals.getSystemValue(), false);
395+
expr.merge(prelude.getExpression());
396+
expr.merge(expression);
397+
return expr;
398+
}
394399

400+
public BytecodeOuterClass.Bytecode emitBytecode(Module module, List<TypedModuleSpec> dependencies) {
395401
BytecodeOuterClass.Bytecode.Builder wyb = BytecodeOuterClass.Bytecode.newBuilder();
396402
wyb.setVersion(BytecodeOuterClass.Bytecode.Version.newBuilder().setMagic(42)
397403
.setMajor(0).setMinor(1))
398404
.setPath("com.todo");
399405

400-
SeqExpr expressionWithPrelude = preludeExpression.clone();
401-
expressionWithPrelude.merge(module.getExpression());
402-
403406
BytecodeOuterClass.Module.ValueModule.Builder v = BytecodeOuterClass.Module.ValueModule.newBuilder()
404407
.setType(module.getSpec().getType().emitBytecodeType())
405-
.setExpression(expressionWithPrelude.emitBytecode());
408+
.setExpression(buildPreludedExpression(module.getExpression()).emitBytecode());
406409

407410
wyb.addModules(BytecodeOuterClass.Module.newBuilder().setPath("toplevel").setValueModule(v));
408411

412+
Module prelude = Globals.getPreludeModule();
409413
dependencies.addAll(prelude.getDependencies());
410414
List<TypedModuleSpec> noDups = sortDependencies(dependencies);
411415
for (TypedModuleSpec spec : noDups) {
@@ -414,8 +418,7 @@ public BytecodeOuterClass.Bytecode emitBytecode(Module module, List<TypedModuleS
414418
if (prelude.getDependencies().contains(spec)) {
415419
e = dep.getExpression();
416420
} else {
417-
e = preludeExpression.clone();
418-
((SeqExpr) e).merge(dep.getExpression());
421+
e = buildPreludedExpression(dep.getExpression());
419422
}
420423

421424
v = BytecodeOuterClass.Module.ValueModule.newBuilder()

‎tools/src/wyvern/target/corewyvernIL/type/BottomType.java

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44

5+
import wyvern.stdlib.support.backend.BytecodeOuterClass;
56
import wyvern.target.corewyvernIL.astvisitor.ASTVisitor;
67
import wyvern.target.corewyvernIL.support.FailureReason;
78
import wyvern.target.corewyvernIL.support.TypeContext;
@@ -38,6 +39,11 @@ public <S, T> T acceptVisitor(ASTVisitor<S, T> emitILVisitor, S state) {
3839
return null;
3940
}
4041

42+
@Override
43+
public BytecodeOuterClass.Type emitBytecodeType() {
44+
return BytecodeOuterClass.Type.newBuilder().setSimpleType(BytecodeOuterClass.Type.SimpleType.Nothing).build();
45+
}
46+
4147
@Override
4248
public ValueType adapt(View v) {
4349
return this;

‎tools/src/wyvern/target/corewyvernIL/type/ExtensibleTagType.java

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Objects;
44

5+
import wyvern.stdlib.support.backend.BytecodeOuterClass;
56
import wyvern.target.corewyvernIL.astvisitor.ASTVisitor;
67
import wyvern.target.corewyvernIL.support.FailureReason;
78
import wyvern.target.corewyvernIL.support.TypeContext;
@@ -29,6 +30,23 @@ public TagType doAvoid(String varName, TypeContext ctx, int depth) {
2930
return new ExtensibleTagType(newPT, getValueType().doAvoid(varName, ctx, depth));
3031
}
3132

33+
@Override
34+
public BytecodeOuterClass.TypeDesc emitBytecodeTypeDesc() {
35+
BytecodeOuterClass.TypeDesc.Tag.Builder tag = BytecodeOuterClass.TypeDesc.Tag.newBuilder();
36+
37+
BytecodeOuterClass.Type type = getValueType().emitBytecodeType();
38+
39+
BytecodeOuterClass.TypeDesc.Builder typeDesc = BytecodeOuterClass.TypeDesc.newBuilder().setTag(tag)
40+
.setType(type);
41+
42+
NominalType parentType = getParentType();
43+
if (parentType != null) {
44+
typeDesc.setExtends(parentType.getPath() + "." + parentType.getTypeMember());
45+
}
46+
47+
return typeDesc.build();
48+
}
49+
3250
@Override
3351
public boolean isTagged(TypeContext ctx) {
3452
return true;

‎tools/src/wyvern/target/corewyvernIL/type/Type.java

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public Type(FileLocation loc) {
3434
public abstract void checkWellFormed(TypeContext ctx);
3535

3636
public BytecodeOuterClass.TypeDesc emitBytecodeTypeDesc() {
37-
3837
System.out.println("emitBytecode not implemented for " + this.getClass().getName());
3938
throw new java.lang.UnsupportedOperationException("Not yet implemented");
4039
}

‎tools/src/wyvern/tools/typedAST/core/declarations/ImportDeclaration.java

+2
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ public Pair<VarBinding, GenContext> genBinding(ModuleResolver resolver, GenConte
182182
type = Globals.JAVA_IMPORT_TYPE;
183183
} else if (resolver.getPlatform().equals("python")) {
184184
type = Globals.PYTHON_IMPORT_TYPE;
185+
} else if (resolver.getPlatform().equals("javascript")) {
186+
type = Globals.JAVASCRIPT_IMPORT_TYPE;
185187
} else {
186188
throw new RuntimeException("interpreter state has an unexpected platform " + resolver.getPlatform());
187189
}

0 commit comments

Comments
 (0)
Please sign in to comment.