import { co_run, co_unit, Coroutine, Fun, fun, Prod, Sum } from 'ts-bccc'; import * as CCC from 'ts-bccc'; import * as Co from 'ts-bccc'; import * as DebuggerStream from './csharp_debugger_stream'; import * as CSharp from './CSharpTypeChecker/csharp'; import * as Sem from './Python/python'; import { zero_range } from './source_range'; export module ImpLanguageWithSuspend { let run_to_end = (log:(s:string,x:any) => void) : CCC.Fun, S>, CCC.Sum>> => { let f : CCC.Fun, S>, CCC.Sum>> = CCC.fun(p => run_to_end(log).f(p)) return (co_run().map_times(fun(s => log("Intermediate step:", JSON.stringify(s)) || s))).then(CCC.apply_pair>()).then( CCC.inl>().plus( f.plus(CCC.inr>()))) } export let get_stream = DebuggerStream.get_stream export let test_parser = () => { let source = ` interface Visitor { public b OnSome(a _a); public b onNone(); } class IntVisitorToString : Visitor { public override string OnSome(int v) { return "Value: " + v; } public override string onNone() { return "No value"; } } interface Option { b Visit(Visitor v); } class None : Option { public None() { } public override b Visit(Visitor v) { return v.onNone(); } } class Some : Option { a v; public Some(a v) { this.v = v; } public override b Visit(Visitor vis) { return vis.OnSome(this.v); } } var values_or_not = new Option[] { new None(), new Some(10), new Some(2), new None() }; typechecker_debugger; var s = ""; var v = new IntVisitorToString(); for(int i = 0; i < values_or_not.Length; i = i + 1) { var x = values_or_not[i]; s = s + x.Visit(v) + "; "; } typechecker_debugger; debugger; ` // interface Option { // bool has_value(); // a get_value(); // } // class None : Option { // public override bool has_value(){ // return false; // } // } // class Some : Option { // a value; // public Some(a value){ // this.value = value; // } // public override a get_value(){ // return this.value; // } // } // typechecker_debugger; // debugger; // class C { // a x; // public C(a x) { this.x = x; } // public (a,b) get_x(b y) { return (this.x,y); } // } // C c = new C(10); // var y = c.get_x(true); // typechecker_debugger; // test 2 // interface I // { // bool M(int x, string y); // } // class C : I where a : I { // public bool M(int x, string y) // { // return x > y.Length; // } // public bool N(a x, a y) { // return x.M(10, "dieci") && y.M(11, "undici"); // } // } // test 3 // interface I // { // bool cmp(a other); // } // class C where a : I { // public bool N(a x, a y) { // return x.cmp(y); // } // } // let hrstart = process.hrtime() let output = "" let log = function(s:string,x:any) { output = output + s + JSON.stringify(x) + "\n\n" } // let hrdiff = process.hrtime(hrstart) // let time_in_ns = hrdiff[0] * 1e9 + hrdiff[1] // log(`Timer: ${time_in_ns / 1000000}ms\n Compiler error: `, JSON.stringify(compiler_res.value)) let stream = get_stream(source, CCC.apply(CCC.inr(), {})) while (stream.kind == "step") { let show = stream.show() //{ highlighting:SourceRange, globals:Scopes, heap:Scope, functions:Immutable.Map, classes:Immutable.Map, stack:Immutable.Map } log("Step:", show.kind == "bindings" ? show.state.bindings.filter(c => c != undefined && (c.kind != "obj" || !c.is_internal)) : show.kind == "memory" ? {...show.memory, classes: show.memory.classes.filter(c => c != undefined && !c.is_internal).toMap() } : show) stream = stream.next() } let show = stream.show() log("Step:", show.kind == "bindings" ? show.state : show.kind == "memory" ? {...show.memory, classes: show.memory.classes.filter(c => c != undefined && !c.is_internal).toMap() } : show) // if (show.kind == "memory") // console.log(show.memory.classes.map((c, C_name) => c != undefined && C_name != undefined ? [C_name, c.is_internal] : [])) return output } } // console.log(ImpLanguageWithSuspend.test_imp()) console.log(ImpLanguageWithSuspend.test_parser())