Switching to ML style type annotations. not separate statement from the expression
This commit is contained in:
parent
6acec5641c
commit
f3c3a76671
6 changed files with 35 additions and 36 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { tokenize } from './lexer'
|
||||
import { Parser } from './parser'
|
||||
import { compile, recompile, definitions, freeVars, dependencies, dependents, astRegistry } from './compiler'
|
||||
import { prettyPrint } from './ast'
|
||||
import { prettyPrint, prettyPrintType } from './ast'
|
||||
import type { AST } from './ast'
|
||||
import { measure } from './ui';
|
||||
|
||||
|
|
@ -118,10 +118,9 @@ export const _rt = {
|
|||
return obj === undefined ? { _tag: 'None' } : { _tag: 'Some', _0: obj };
|
||||
},
|
||||
getSource: (name: string) => {
|
||||
const ast = definitions.get(name);
|
||||
if (!ast) return "";
|
||||
const printed = prettyPrint(ast);
|
||||
return printed;
|
||||
const def = definitions.get(name);
|
||||
if (!def) return "";
|
||||
return prettyPrint(def);
|
||||
},
|
||||
"saveImage!": () => {
|
||||
const saved: Record<string, string> = {};
|
||||
|
|
@ -259,8 +258,8 @@ export const _rt = {
|
|||
|
||||
export function saveDefinitions() {
|
||||
const saved: Record<string, string> = {};
|
||||
for (const [name, ast] of definitions) {
|
||||
const source = prettyPrint({ kind: 'definition', name, body: ast });
|
||||
for (const [name, def] of definitions) {
|
||||
const source = prettyPrint(def);
|
||||
saved[name] = source;
|
||||
}
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(saved));
|
||||
|
|
@ -356,8 +355,16 @@ function valueToAst(value: any): AST {
|
|||
export function syncToAst(name: string) {
|
||||
// if (definitions.has(name)) {
|
||||
if (name in store) {
|
||||
definitions.set(name, valueToAst(store[name]));
|
||||
const source = prettyPrint({ kind: 'definition', name, body: definitions.get(name)! });
|
||||
const existing = definitions.get(name);
|
||||
const newDef: Definition = {
|
||||
kind: 'definition',
|
||||
name,
|
||||
body: valueToAst(store[name]),
|
||||
annotation: existing?.annotation,
|
||||
};
|
||||
definitions.set(name, newDef); // valueToAst(store[name]));
|
||||
// const source = prettyPrint({ kind: 'definition', name, body: definitions.get(name)! });
|
||||
const source = prettyPrint(definitions.get(name)!);
|
||||
appendChangeLog(name, source);
|
||||
saveDefinitions();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue