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
12 changes: 0 additions & 12 deletions compiler/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,18 +905,6 @@ export const BuiltinFuncs = function() {
}
};

this.__Porffor_rawType = {
params: [ valtypeBinary, Valtype.i32 ],
typedParams: true,
locals: [],
returns: [ valtypeBinary ],
returnType: TYPES.number,
wasm: [
[ Opcodes.local_get, 1 ],
Opcodes.i32_from_u
]
};

this.__Porffor_clone = {
params: [ Valtype.i32, Valtype.i32 ],
locals: [],
Expand Down
354 changes: 177 additions & 177 deletions compiler/builtins_precompiled.js

Large diffs are not rendered by default.

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

// presume
// todo: warn here?
if (Prefs.warnAssumedType) console.warn(`Indirect call assumed to be number`);
return TYPES.number;
}

Expand Down Expand Up @@ -1524,7 +1524,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 @@ -1633,6 +1634,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 @@ -1664,7 +1666,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 @@ -5551,6 +5553,19 @@ const internalConstrs = {
type: TYPES.undefined,
notConstr: true,
length: 1
},

__Porffor_rawType: {
generate: (scope, decl) => {
const type = getNodeType(scope, decl.arguments[0]);
return [
...type,
Opcodes.i32_from
];
},
type: TYPES.number,
notConstr: true,
length: 1
}
};

Expand Down