Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn Porffor.rawType into a macro #116

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion compiler/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ export const BuiltinFuncs = function() {
}
};

this.__Porffor_rawType = {
this.__Porffor_dyn_rawType = {
params: [ valtypeBinary, Valtype.i32 ],
typedParams: true,
locals: [],
Expand Down
342 changes: 171 additions & 171 deletions compiler/builtins_precompiled.js

Large diffs are not rendered by default.

30 changes: 27 additions & 3 deletions compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ const getNodeType = (scope, node) => {
if (scope.locals['#last_type']) return getLastType(scope);

// presume
// todo: warn here?
if (Prefs.warnAssumedType) console.warn(`Dynamic call assumed to be number`);
BobVarioa marked this conversation as resolved.
Show resolved Hide resolved
return TYPES.number;
}

Expand Down Expand Up @@ -1478,7 +1478,8 @@ const getNodeType = (scope, node) => {
if (scope.locals['#last_type']) return getLastType(scope);

// presume
// todo: warn here?

if (Prefs.warnAssumedType) console.warn(`Call to ${name} assumed to be number`);
return TYPES.number;

// let protoFunc;
Expand Down Expand Up @@ -1587,6 +1588,7 @@ const getNodeType = (scope, node) => {
if (scope.locals['#last_type']) return getLastType(scope);

// presume
if (Prefs.warnAssumedType) console.warn(`Member access to field .${name} assumed to be number`);
return TYPES.number;
}

Expand Down Expand Up @@ -1618,7 +1620,7 @@ const getNodeType = (scope, node) => {
if (scope.locals['#last_type']) return getLastType(scope);

// presume
// todo: warn here?
if (Prefs.warnAssumedType) console.warn(`AST node ${node.type} assumed to be number`);
return TYPES.number;
})();

Expand Down Expand Up @@ -5423,6 +5425,28 @@ const internalConstrs = {
type: TYPES.undefined,
notConstr: true,
length: 1
},

__Porffor_rawType: {
generate: (scope, decl) => {
const type = getNodeType(scope, decl.arguments[0]);
if (type) {
BobVarioa marked this conversation as resolved.
Show resolved Hide resolved
return [
...type,
Opcodes.i32_from
];
}
return generate(scope, {
BobVarioa marked this conversation as resolved.
Show resolved Hide resolved
type: "CallExpression",
callee: { type: "Identifier", name: "__Porffor_dyn_rawType" },
arguments: [
decl.arguments[0]
]
});
},
type: TYPES.number,
notConstr: true,
length: 1
}
};

Expand Down