Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function producerMetadata(
language: Array,
processedBy: Array,
sdk: Array
): ProducerMetadata {
assert(
typeof language === "object" && typeof language.length !== "undefined"
);
assert(
typeof processedBy === "object" && typeof processedBy.length !== "undefined"
);
assert(typeof sdk === "object" && typeof sdk.length !== "undefined");
const node: ProducerMetadata = {
type: "ProducerMetadata",
language,
processedBy,
sdk
};
getGlobalOffsetByIdentifier(name) {
assert(typeof name === "string");
return this.globalsOffsetByIdentifier[name];
}
export function program(body: Array): Program {
assert(typeof body === "object" && typeof body.length !== "undefined");
const node: Program = {
type: "Program",
body
};
return node;
}
export function callInstruction(
index: Index,
instrArgs?: Array,
numeric?: Index
): CallInstruction {
if (instrArgs !== null && instrArgs !== undefined) {
assert(
typeof instrArgs === "object" && typeof instrArgs.length !== "undefined"
);
}
const node: CallInstruction = {
type: "CallInstruction",
id: "call",
index
};
if (typeof instrArgs !== "undefined" && instrArgs.length > 0) {
node.instrArgs = instrArgs;
}
if (typeof numeric !== "undefined") {
node.numeric = numeric;
export function moduleContextFromModuleAST(m) {
const moduleContext = new ModuleContext();
assert(m.type === "Module");
m.fields.forEach(field => {
switch (field.type) {
case "Start": {
moduleContext.setStart(field.index);
break;
}
case "TypeInstruction": {
moduleContext.addType(field);
break;
}
case "Func": {
moduleContext.addFunction(field);
break;
}
case "Global": {
export function instr(
id: string,
object?: Valtype,
args: Array,
namedArgs?: Object
): Instr {
assert(
typeof id === "string",
"Argument id must be of type string, given: " + typeof id
);
assert(typeof args === "object" && typeof args.length !== "undefined");
const node: Instr = {
type: "Instr",
id,
args
};
if (typeof object !== "undefined") {
node.object = object;
}
export function producerMetadataVersionedName(
name: string,
version: string
): ProducerMetadataVersionedName {
assert(
typeof name === "string",
"Argument name must be of type string, given: " + typeof name
);
assert(
typeof version === "string",
"Argument version must be of type string, given: " + typeof version
);
const node: ProducerMetadataVersionedName = {
type: "ProducerMetadataVersionedName",
name,
version
};
return node;
}
validate(instantiatedItem);
assertNotAlreadyExported(node.name);
moduleInstance.exports.push({
name: node.name,
value: {
type: node.descr.exportType,
addr: instantiatedItem.addr
}
});
} else if (isNumberLiteral(node.descr.id) === true) {
const instantiatedItem = {
addr: instantiatedItemInFromModule[parseInt(node.descr.id.value)]
};
assert(instantiatedItem !== undefined);
validate(instantiatedItem);
assertNotAlreadyExported(node.name);
moduleInstance.exports.push({
name: node.name,
value: {
type: node.descr.exportType,
addr: instantiatedItem.addr
}
});
} else {
throw new CompileError(
"Module exports must be referenced via an Identifier"
);
export function moduleExport(
name: string,
descr: ModuleExportDescr
): ModuleExport {
assert(
typeof name === "string",
"Argument name must be of type string, given: " + typeof name
);
const node: ModuleExport = {
type: "ModuleExport",
name,
descr
};
return node;
}
export function numberLiteral(value: number, raw: string): NumberLiteral {
assert(
typeof value === "number",
"Argument value must be of type number, given: " + typeof value
);
assert(
typeof raw === "string",
"Argument raw must be of type string, given: " + typeof raw
);
const node: NumberLiteral = {
type: "NumberLiteral",
value,
raw
};
return node;
}