Skip to content

Commit

Permalink
Fix macro errors when exposing Std or Sys with HL target. Still not w…
Browse files Browse the repository at this point in the history
…orking correctly though.
  • Loading branch information
jeremyfa committed May 21, 2019
1 parent 9bc6e34 commit a900853
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 15 deletions.
64 changes: 49 additions & 15 deletions interpret/DynamicModule.hx
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,10 @@ class DynamicModule {
// Type
var rawTypePath = t.toString();

// Workaround needed on haxe 4?
if (rawTypePath.startsWith('_Sys.')) continue;
// Sys class workarounds
// Is there a cleaner way to handle this?
if (typePath == 'Sys' && rawTypePath.startsWith('_Sys.')) continue;
if (typePath == 'Sys' && rawTypePath == 'SysError') continue;

// Compute sub type paths and alias
var alias = null;
Expand Down Expand Up @@ -659,7 +661,7 @@ class DynamicModule {
for (arg in args) {
argTypes.push(typeAsString(arg.t));
}
var retType = typeAsString(fieldType);
var retType = typeAsString(ret);
if (args.length > 0 && isStatic && field.isPublic) {
var extendedType:String = null;
switch (args[0].t) {
Expand All @@ -676,7 +678,8 @@ class DynamicModule {
retType,
argTypes,
extendedType,
field.isPublic
field.isPublic,
field.isExtern
]);
} else {
toAdd.push([
Expand All @@ -686,7 +689,8 @@ class DynamicModule {
retType,
argTypes,
null,
field.isPublic
field.isPublic,
field.isExtern
]);
}
default:
Expand Down Expand Up @@ -782,23 +786,53 @@ class DynamicModule {
}
else if (item[1] == ModuleItemKind.CLASS_FUNC || item[1] == ModuleItemKind.CLASS_VAR) {
var isStatic:Bool = item[2];
var retType:String = item[3];
var argTypes:String = item[4];
var isPublic:Bool = item[6];
if (isStatic) {
if (isPublic) {
// Static class field (public)
var expr = macro mod.add($v{item[0]}, $p{item[0].split('.')}, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]}, $v{item[5]});
addExprs.push(expr);
var isExtern:Bool = item[7];
if (item[1] == ModuleItemKind.CLASS_FUNC && isExtern) {
if (isStatic) {
if (isPublic) {
// Static class field (public)
if (item[0] == 'Std.int') {
// Kind of hardcoded case for now
var expr = macro mod.add($v{item[0]}, function(value:Dynamic):Int { return Std.int(value); }, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]}, $v{item[5]});
addExprs.push(expr);
}
else {
// Skip any other extern function for now
}
}
else {
// Static class field (private)
var expr = macro mod.add($v{item[0]}, null, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]}, $v{item[5]});
addExprs.push(expr);
}
}
else {
// Static class field (private)
var expr = macro mod.add($v{item[0]}, null, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]}, $v{item[5]});
// Instance class field
var expr = macro mod.add($v{item[0]}, null, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]});
addExprs.push(expr);
}
}
else {
// Instance class field
var expr = macro mod.add($v{item[0]}, null, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]});
addExprs.push(expr);
if (isStatic) {
if (isPublic) {
// Static class field (public)
var expr = macro mod.add($v{item[0]}, $p{item[0].split('.')}, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]}, $v{item[5]});
addExprs.push(expr);
}
else {
// Static class field (private)
var expr = macro mod.add($v{item[0]}, null, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]}, $v{item[5]});
addExprs.push(expr);
}
}
else {
// Instance class field
var expr = macro mod.add($v{item[0]}, null, $v{item[1]}, $v{item[2]}, $v{item[3]}, $v{item[4]});
addExprs.push(expr);
}
}
}
else {
Expand Down
2 changes: 2 additions & 0 deletions test-hl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
haxe test.hxml -D test_hl && node test.js
1 change: 1 addition & 0 deletions test/Host.hx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Host {

#if host_test_01
var dynClass = env.modules.get('test.script.BasicClass').dynamicClasses.get('BasicClass');
trace('dynClass: $dynClass');
dynClass.call('staticHello', ['Test 01']);
#end

Expand Down
19 changes: 19 additions & 0 deletions test/Test.hx
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,18 @@ class Test extends buddy.SingleSuite {
'-dce', 'no'
];

#elseif test_hl

var buildArgs:Array<String> = [
'-main', 'test.Host',
'-cp', '.',
'-lib', 'hscript',
'-hl', 'bin/host.hl',
'-debug',
'-D', 'interpretable',
'-dce', 'no'
];

#else // js

var buildArgs:Array<String> = [
Expand Down Expand Up @@ -482,6 +494,13 @@ class Test extends buddy.SingleSuite {
cwd: js.Node.__dirname
});

#elseif test_hl

// Run
proc = spawnSync('hl bin/host.hl', [], {
cwd: js.Node.__dirname
});

#else //js

// Run
Expand Down

0 comments on commit a900853

Please sign in to comment.