import { Dictionary } from "../common" ; import { SyntaxTree , parseFile } from "../compiler/parser" ; let modules = new Dictionary < Dictionary < SyntaxTree . FileBlockFunction > > ( ) ; function importPrimitiveCode ( name , code ) { let thisModule = null ; if ( modules . has ( name ) ) { thisModule = modules . get ( name ) ; } else { thisModule = new Dictionary < SyntaxTree . FileBlockFunction > ( ) ; modules . set ( name , thisModule ) ; } let tree = parseFile ( code ) ; for ( let f of tree . blocks ) { if ( f . type == "function" ) { let fn = f as SyntaxTree . FileBlockFunction ; thisModule . set ( fn . name , fn ) ; } } } import * as P2D from "./primitives2d" ; importPrimitiveCode ( "P2D" , P2D . primitives ) ; import * as P3D from "./primitives3d" ; importPrimitiveCode ( "P3D" , P3D . primitives ) ; export function getModule ( name ) { return modules . get ( name ) ; } export function getModuleFunction ( name , functionName ) { return modules . get ( name ) . get ( functionName ) ; } export function forEachModuleFunction ( name , callback ) { return modules . get ( name ) . forEach ( callback ) ; }