Skip to content

Commit 3288cdc

Browse files
committed
update revision
1 parent 30bdc9b commit 3288cdc

File tree

14 files changed

+1603
-34
lines changed

14 files changed

+1603
-34
lines changed

packages/hedgehog-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"@babel/core": "^7.10.5",
2323
"@babel/preset-env": "^7.10.4",
24+
"@babel/preset-react": "^7.12.10",
2425
"@babel/preset-typescript": "^7.10.4",
2526
"@babel/standalone": "^7.10.5",
2627
"@tensorflow/tfjs": "^2.7.0",

packages/hedgehog-core/src/runtime/prelude.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { Chol, QR, LU } from '../lib/algebra';
99
import { OutputItem } from '../output/output-item';
1010
import { rawInputsToTex } from '../utilites/process-raw-inputs';
1111

12+
import * as React from 'react';
13+
import * as d3 from 'd3';
14+
1215
/*
1316
Third party libraries
1417
*/
@@ -34,7 +37,7 @@ import * as tf from '@tensorflow/tfjs';
3437
//tvm.js
3538

3639

37-
export { Sym, Mat, Scalar, _Mat, nerdamer, GPU, mathjs, tf, Chol };
40+
export { Sym, Mat, Scalar, _Mat, nerdamer, GPU, mathjs, tf, Chol, React, d3 };
3841

3942
/**
4043
* wrapper of constructing a Mat object
@@ -371,6 +374,7 @@ export function plot3DMesh(x_: any, y_: any, z_: any) {
371374
],
372375
{}
373376
);
377+
return;
374378
}
375379
draw(
376380
[
@@ -399,7 +403,8 @@ export function formulaTex(...inputs: any[]) {
399403
_OUTPUT_ITEMS_LIST_.push({ itemType: 'FORMULA', text: inputTex });
400404
}
401405

402-
export function markdown(inputMarkdown: string) {
406+
export function markdown(...inputs: any[]) {
407+
const inputMarkdown: string = rawInputsToTex(...inputs);
403408
_OUTPUT_ITEMS_LIST_.push({ itemType: 'MARKDOWN', text: inputMarkdown });
404409
}
405410

packages/hedgehog-core/src/transpiler/operator-overload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function invokedTemplate(op: any) {
1919
return (sym(LEFT_ARG)[Symbol.for("${op}")](RIGHT_ARG));
2020
else if (Array.isArray(LEFT_ARG) && (RIGHT_ARG instanceof Mat))
2121
return (mat(LEFT_ARG)[Symbol.for("${op}")](RIGHT_ARG));
22-
else if ( typeof LEFT_ARG === 'number' && (RIGHT_ARG instanceof Mat))
22+
else if ( (!isNaN(LEFT_ARG)) && (RIGHT_ARG instanceof Mat))
2323
return (scalar(LEFT_ARG)[Symbol.for("${op}")](RIGHT_ARG));
2424
else
2525
return LEFT_ARG ${op} RIGHT_ARG;

packages/hedgehog-core/src/transpiler/preprocessor.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ function getPackageLocation(packageName: string, theFullListInJson: string): str
3737

3838
/*
3939
Parse the registered package (the type 1 of import macro: *import PACKAGE_NAME: LIB_NAME_LIST)
40-
Input: the second part of current line splitted by "*import". For example, current line is "*import std:magic, cholesky",
40+
Input: secondPart: the second part of current line splitted by "*import". For example, current line is "*import std:magic, cholesky",
4141
then the input will be "std:magic, cholesky"; if current line is "let myMagic = *import std:magic", then the input should
4242
be "std:magic, cholesky"
43+
strCurrentCallStack: current call stack
4344
Output: A list of string, each string represents the corresponding hhs source file
4445
*/
45-
async function parseRegisterdPackage(secondPart: string): Promise<Array<string>> {
46+
async function parseRegisterdPackage(secondPart: string, strCurrentCallStack:string): Promise<Array<string>> {
4647
let returnListOfFunctions: string[] = [];
4748
let theFullListInJson = await fetch("https://raw.githubusercontent.com/Hedgehog-Computing/Hedgehog-Package-Manager/main/hedgehog-packages.json", { method: 'get' }).then(body => body.text());
4849
let splittedResult = secondPart.split(':');
@@ -72,11 +73,15 @@ async function parseRegisterdPackage(secondPart: string): Promise<Array<string>>
7273
if (setHHSCompleteList.has(eachItemWithoutSpace)) {
7374
let currentHHSLocation = packageLocation + eachItemWithoutSpace + ".hhs";
7475
let currentItemSourceCode = await fetch(currentHHSLocation, { method: 'get' }).then(body => body.text());
75-
returnListOfFunctions.push(currentItemSourceCode);
76+
77+
// After get the whole hhs source file, preprocess the string via DFS preprocessor
78+
// to handle the dependencies of current source file string
79+
let preprocessedCurrentItemSourceCode = await preprocessDFS(currentItemSourceCode, strCurrentCallStack + " -> " + strCurrentCallStack + ":" + eachItemWithoutSpace);
80+
returnListOfFunctions.push(preprocessedCurrentItemSourceCode);
7681
}
7782
}
7883
}
79-
else { throw "Cannot find \"includes\" key in the hedgehog-package.json configuration file! Please add a key with name \"includes\" with a complete list of exported libraries. Exception at " + secondPart}
84+
else { throw "Cannot find \"includes\" key in the hedgehog-package.json configuration file! Please add a key with name \"includes\" with a complete list of exported libraries. Exception at " + secondPart + ".\nCall Stack at: " + strCurrentCallStack}
8085
return returnListOfFunctions;
8186
}
8287

@@ -136,7 +141,7 @@ async function preprocessDFS(code: string, strCurrentCallStack: string): Promise
136141

137142
else{
138143
// otherwise, try to split with colon and comma and fetch the registered packages
139-
let result = await parseRegisterdPackage(splittedResult[1]);
144+
let result = await parseRegisterdPackage(splittedResult[1], strCurrentCallStack);
140145
let combined_result = "";
141146
result.forEach(element => {
142147
combined_result += element + "\n"

packages/hedgehog-core/src/transpiler/transpiler-core.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ async function transpilerCore(source: string) {
1111
//register preset-env
1212
babel.registerPreset('@babel/preset-env', require('@babel/preset-env'));
1313

14+
//register jsx preset
15+
babel.registerPreset('@babel/preset-react', require('@babel/preset-react'));
16+
1417
//register typescript preset
1518
babel.registerPreset(
1619
'@babel/preset-typescript',
@@ -23,8 +26,8 @@ async function transpilerCore(source: string) {
2326
preprocessed_code, // the code
2427
{
2528
plugins: ['overload'],
26-
presets: ['@babel/preset-env', '@babel/preset-typescript'],
27-
filename: 'temp.js',
29+
presets: ['@babel/preset-env', '@babel/preset-typescript', '@babel/preset-react'],
30+
filename: 'source.tsx',
2831
sourceType: 'script',
2932
}
3033
);

0 commit comments

Comments
 (0)