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

refactor: move compile package source files into directories #195

Merged
merged 9 commits into from
Jun 7, 2022
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import util from 'util'
import B from 'bufx'
import parseCsv from 'csv-parse/lib/sync.js'
import R from 'ramda'
import split from 'split-string'
import XLSX from 'xlsx'
import parseCsv from 'csv-parse/lib/sync.js'
import B from 'bufx'

// Set true to print a stack trace in vlog
export const PRINT_VLOG_TRACE = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fs from 'fs'

import B from 'bufx'
import byline from 'byline'
import R from 'ramda'

import { canonicalVensimName } from './Helpers.js'
import { canonicalVensimName } from './helpers.js'

/**
* Read a Vensim `dat` file with static data and return a Map.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import util from 'util'
import R from 'ramda'
import B from 'bufx'
import yaml from 'js-yaml'
import { canonicalName, asort, vlog } from './Helpers.js'
import R from 'ramda'
import { canonicalName, asort, vlog } from './helpers.js'

// A subscript is a dimension or an index.
// Both have the same properties: model name, canonical name, family, values.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import R from 'ramda'
import ModelLHSReader from './ModelLHSReader.js'
import EquationGen from './EquationGen.js'
import Model from './Model.js'
import { sub, allDimensions, allMappings, subscriptFamilies } from './Subscript.js'
import { asort, lines, strlist, abend, mapIndexed } from './Helpers.js'

import { asort, lines, strlist, abend, mapIndexed } from '../_shared/helpers.js'
import { sub, allDimensions, allMappings, subscriptFamilies } from '../_shared/subscript.js'
import Model from '../model/model.js'

import EquationGen from './equation-gen.js'
import ModelLHSReader from './model-lhs-reader.js'

export function generateCode(parseTree, opts) {
return codeGenerator(parseTree, opts).generate()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
import path from 'path'
import { ModelLexer, ModelParser } from 'antlr4-vensim'
import R from 'ramda'
import XLSX from 'xlsx'
import { ModelLexer, ModelParser } from 'antlr4-vensim'
import ModelReader from './ModelReader.js'
import ModelLHSReader from './ModelLHSReader.js'
import LoopIndexVars from './LoopIndexVars.js'
import Model from './Model.js'
import {
dimensionNames,
extractMarkedDims,
hasMapping,
isDimension,
isIndex,
isTrivialDimension,
indexInSepDim,
normalizeSubscripts,
separatedVariableIndex,
sub
} from './Subscript.js'

import {
canonicalName,
cartesianProductOf,
Expand All @@ -34,7 +19,24 @@ import {
readCsv,
strToConst,
vlog
} from './Helpers.js'
} from '../_shared/helpers.js'
import {
dimensionNames,
extractMarkedDims,
hasMapping,
isDimension,
isIndex,
isTrivialDimension,
indexInSepDim,
normalizeSubscripts,
separatedVariableIndex,
sub
} from '../_shared/subscript.js'
import ModelReader from '../parse/model-reader.js'
import Model from '../model/model.js'

import LoopIndexVars from './loop-index-vars.js'
import ModelLHSReader from './model-lhs-reader.js'

export default class EquationGen extends ModelReader {
constructor(variable, extData, directData, mode, modelDirname) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isDimension } from './Subscript.js'
import { isDimension } from '../_shared/subscript.js'

export default class LoopIndexVars {
constructor(indexVars) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import R from 'ramda'
import ModelReader from './ModelReader.js'
import { createParser } from './Parser.js'
import { sub, isDimension } from './Subscript.js'
import { canonicalName } from './Helpers.js'

import { canonicalName } from '../_shared/helpers.js'
import { sub, isDimension } from '../_shared/subscript.js'
import ModelReader from '../parse/model-reader.js'
import { createParser } from '../parse/parser.js'

//
// ModelLHSReader parses the LHS of a var in Vensim format and
Expand Down
12 changes: 6 additions & 6 deletions packages/compile/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) 2022 Climate Interactive / New Venture Fund

export { generateCode } from './CodeGen.js'
export { parseAndGenerate, printNames } from './Entry.js'
export { canonicalName } from './Helpers.js'
export { parseModel } from './Parser.js'
export { preprocessModel } from './Preprocessor.js'
export { readDat } from './ReadDat.js'
export { canonicalName } from './_shared/helpers.js'
export { readDat } from './_shared/read-dat.js'
export { preprocessModel } from './preprocess/preprocessor.js'
export { parseModel } from './parse/parser.js'
export { generateCode } from './generate/code-gen.js'
export { parseAndGenerate, printNames } from './parse-and-generate.js'
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import { ModelParser } from 'antlr4-vensim'
import R from 'ramda'
import ExprReader from './ExprReader.js'
import Model from './Model.js'
import ModelReader from './ModelReader.js'
import { createParser } from './Parser.js'
import VariableReader from './VariableReader.js'
import {
extractMarkedDims,
indexNamesForSubscript,
normalizeSubscripts,
separatedVariableIndex,
sub,
isDimension
} from './Subscript.js'

import {
canonicalName,
canonicalVensimName,
Expand All @@ -29,7 +17,21 @@ import {
newLookupVarName,
newFixedDelayVarName,
cartesianProductOf
} from './Helpers.js'
} from '../_shared/helpers.js'
import {
extractMarkedDims,
indexNamesForSubscript,
normalizeSubscripts,
separatedVariableIndex,
sub,
isDimension
} from '../_shared/subscript.js'
import ModelReader from '../parse/model-reader.js'
import { createParser } from '../parse/parser.js'

import ExprReader from './expr-reader.js'
import Model from './model.js'
import VariableReader from './variable-reader.js'

// Set this true to get a list of functions used in the model. This may include lookups.
const PRINT_FUNCTION_NAMES = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ModelLexer, ModelVisitor } from 'antlr4-vensim'
import { canonicalName } from './Helpers.js'
import Model from './Model.js'
import { createParser } from './Parser.js'

import { canonicalName } from '../_shared/helpers.js'
import { createParser } from '../parse/parser.js'

import Model from './model.js'

/**
* Reads an expression and determines if it resolves to a constant numeric value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import R from 'ramda'
import B from 'bufx'
import yaml from 'js-yaml'
import toposort from './toposort.js'
import VariableReader from './VariableReader.js'
import VarNameReader from './VarNameReader.js'
import SubscriptRangeReader from './SubscriptRangeReader.js'
import EquationReader from './EquationReader.js'
import Variable from './Variable.js'
import { createParser } from './Parser.js'
import R from 'ramda'

import { decanonicalize, isIterable, listConcat, strlist, vlog, vsort } from '../_shared/helpers.js'
import {
addIndex,
allAliases,
Expand All @@ -18,8 +13,15 @@ import {
normalizeSubscripts,
sub,
subscriptFamilies
} from './Subscript.js'
import { decanonicalize, isIterable, listConcat, strlist, vlog, vsort } from './Helpers.js'
} from '../_shared/subscript.js'
import { createParser } from '../parse/parser.js'

import EquationReader from './equation-reader.js'
import SubscriptRangeReader from './subscript-range-reader.js'
import toposort from './toposort.js'
import VarNameReader from './var-name-reader.js'
import Variable from './variable.js'
import VariableReader from './variable-reader.js'

let variables = []
let inputVars = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import path from 'path'
import { ModelParser } from 'antlr4-vensim'
import R from 'ramda'
import XLSX from 'xlsx'
import ModelReader from './ModelReader.js'
import { Subscript } from './Subscript.js'
import { cFunctionName, matchRegex, readCsv } from './Helpers.js'

import { cFunctionName, matchRegex, readCsv } from '../_shared/helpers.js'
import { Subscript } from '../_shared/subscript.js'
import ModelReader from '../parse/model-reader.js'

export default class SubscriptRangeReader extends ModelReader {
constructor(modelDirname) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import ModelReader from './ModelReader.js'
import R from 'ramda'
import { createParser } from './Parser.js'
import { sub, isIndex, normalizeSubscripts } from './Subscript.js'
import { canonicalName } from './Helpers.js'

import { canonicalName } from '../_shared/helpers.js'
import { sub, isIndex, normalizeSubscripts } from '../_shared/subscript.js'
import ModelReader from '../parse/model-reader.js'
import { createParser } from '../parse/parser.js'

//
// VarNameReader reads a model var name using the parser to get the var name in C format.
// This is used to generate a variable output in the output section.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { ModelParser } from 'antlr4-vensim'
import R from 'ramda'
import ModelReader from './ModelReader.js'
import Model from './Model.js'
import Variable from './Variable.js'
import { sub, isDimension, isIndex, normalizeSubscripts, subscriptsMatch, isSubdimension } from './Subscript.js'
import { canonicalName, vlog, strlist, cartesianProductOf } from './Helpers.js'

import { canonicalName, vlog, strlist, cartesianProductOf } from '../_shared/helpers.js'
import {
sub,
isDimension,
isIndex,
normalizeSubscripts,
subscriptsMatch,
isSubdimension
} from '../_shared/subscript.js'
import ModelReader from '../parse/model-reader.js'

import Model from './model.js'
import Variable from './variable.js'

// Set true to print extra debugging information to stderr.
const DEBUG_LOG = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import path from 'path'
import B from 'bufx'

import { generateCode } from './CodeGen.js'
import { readXlsx } from './Helpers.js'
import Model from './Model.js'
import { parseModel } from './Parser.js'
import { readDat } from './ReadDat.js'
import { printSubscripts, yamlSubsList } from './Subscript.js'
import { readXlsx } from './_shared/helpers.js'
import { readDat } from './_shared/read-dat.js'
import { printSubscripts, yamlSubsList } from './_shared/subscript.js'
import { parseModel } from './parse/parser.js'
import Model from './model/model.js'
import { generateCode } from './generate/code-gen.js'

/**
* Parse a Vensim model and generate C code.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import R from 'ramda'
import B from 'bufx'
import { splitEquations, replaceDelimitedStrings } from './Helpers.js'
import R from 'ramda'
import { splitEquations, replaceDelimitedStrings } from '../_shared/helpers.js'

export let preprocessModel = (mdlFilename, spec, profile = 'genc', writeFiles = false, outDecls = []) => {
const MACROS_FILENAME = 'macros.txt'
Expand Down