Initial JS runtime and Arborix Implementation

This commit is contained in:
2026-05-06 11:30:31 -05:00
parent fe453b9b96
commit 0cd849447f
24 changed files with 1865 additions and 104 deletions

View File

@@ -1,18 +1,32 @@
module FileEval where
module FileEval
( preprocessFile
, evaluateFile
, evaluateFileWithContext
, evaluateFileResult
, evaluateFile
, compileFile
) where
import Eval
import Eval (evalTricu)
import Lexer
import Parser
import Research
import ContentStore (initContentStore, storeTerm, hashTerm)
import Wire (exportNamedBundle)
import Control.Monad ()
import Data.List (partition)
import Data.Maybe (mapMaybe)
import Data.Maybe (fromMaybe, mapMaybe)
import System.Environment (setEnv)
import System.FilePath (takeDirectory, normalise, (</>))
import System.IO ()
import System.IO (hPutStrLn, stderr)
import System.Exit (die)
import Database.SQLite.Simple (Connection, close)
import qualified Data.ByteString.Lazy as BL
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
extractMain :: Env -> Either String T
extractMain env =
@@ -152,3 +166,26 @@ isPrefixed name = '.' `elem` name
nsVariable :: String -> String -> String
nsVariable "" name = name
nsVariable moduleName name = moduleName ++ "." ++ name
-- | Compile a tricu source file to a standalone Arborix bundle.
-- Uses a temp content store so it does not collide with the global one.
compileFile :: FilePath -> FilePath -> Maybe T.Text -> IO ()
compileFile inputPath outputPath maybeExportName = do
-- Evaluate the file to get the full environment
env <- evaluateFile inputPath
-- Look up the export name: prefer explicit, then fall back to "main"
let name = fromMaybe "main" (T.unpack <$> maybeExportName)
case Map.lookup name env of
Nothing -> die $ "No definition '" ++ name ++ "' found in " ++ inputPath
Just term -> do
-- Create a temp content store
setEnv "TRICU_DB_PATH" "/tmp/tricu-compile.db"
conn <- initContentStore
-- Store the term in the temp store
_ <- storeTerm conn [name] term
-- Export the bundle (exportNamedBundle returns already-encoded bytes)
bundleData <- exportNamedBundle conn [(T.pack name, hashTerm term)]
BL.writeFile outputPath (BL.fromStrict bundleData)
close conn
putStrLn $ "Compiled " ++ inputPath ++ " -> " ++ outputPath
putStrLn $ " export: " ++ name