11import { either , option , type Option } from '../../adts.js'
2+ import { writeJSON } from '../cli/output.js'
23import { keywordHandlers as compilerKeywordHandlers } from '../compiling.js'
34import type { Atom } from '../parsing.js'
45import {
56 isFunctionNode ,
67 makeFunctionNode ,
78 makeObjectNode ,
9+ serialize ,
810 types ,
911 type KeywordElaborationResult ,
1012 type KeywordModule ,
@@ -13,18 +15,20 @@ import {
1315} from '../semantics.js'
1416import { lookupPropertyOfObjectNode } from '../semantics/object-node.js'
1517
18+ const unserializableFunction = ( ) =>
19+ either . makeLeft ( {
20+ kind : 'unserializableValue' ,
21+ message : 'this function cannot be serialized' ,
22+ } )
23+
1624const runtimeContext = makeObjectNode ( {
1725 environment : makeObjectNode ( {
1826 lookup : makeFunctionNode (
1927 {
2028 parameter : types . string ,
2129 return : types . option ( types . string ) ,
2230 } ,
23- ( ) =>
24- either . makeLeft ( {
25- kind : 'unserializableValue' ,
26- message : 'this function cannot be serialized' ,
27- } ) ,
31+ unserializableFunction ,
2832 option . none ,
2933 key => {
3034 if ( typeof key !== 'string' ) {
@@ -53,6 +57,29 @@ const runtimeContext = makeObjectNode({
5357 } ,
5458 ) ,
5559 } ) ,
60+ log : makeFunctionNode (
61+ {
62+ parameter : types . something ,
63+ return : types . object ,
64+ } ,
65+ unserializableFunction ,
66+ option . none ,
67+ output => {
68+ const serializationResult = serialize ( output )
69+ if ( either . isLeft ( serializationResult ) ) {
70+ return either . makeLeft ( {
71+ kind : 'panic' ,
72+ message : serializationResult . value . message ,
73+ } )
74+ } else {
75+ writeJSON ( process . stderr , serializationResult . value )
76+ return either . makeRight ( makeObjectNode ( { } ) )
77+ }
78+ } ,
79+ ) ,
80+ program : makeObjectNode ( {
81+ start_time : new Date ( ) . toISOString ( ) ,
82+ } ) ,
5683} )
5784
5885export const handlers = {
0 commit comments