Skip to content

Commit fc6eb51

Browse files
🎉 Major Update: Add C1 support to C0VM.ts, Add tutorial page (#33)
* ✨ Change UI and parser to support C1 * ✨ Support void* in C1 standard * 🐛 Fix tag_ptr display in struct under graph debug mode, Fix behavior of type inference on void* in struct * ✨ Support Function Pointer, but have problem in distinguish struct type and function type * ✨ Extract function types from typedef, Support function pointer in debuggers * fix folder import * ✨ Add Tutorials page * 🔥 Put debug statements into DEBUG branch Co-authored-by: chaosarium <[email protected]>
1 parent 47c00ec commit fc6eb51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1762
-1632
lines changed

src/application.css

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ body {
6363
margin-bottom: 0 !important;
6464
}
6565

66+
.ant-tabs-nav-more {
67+
padding-bottom: 0 !important;
68+
}
69+
6670
.io-area {
6771
flex-grow: 1;
6872
padding-left: .5rem;
@@ -156,10 +160,6 @@ i.editor-load-hint {
156160
flex-grow: 1;
157161
}
158162

159-
.error-output {
160-
color: #f27b7b;
161-
}
162-
163163
/* Buttons */
164164

165165
.base-btn {
@@ -271,14 +271,14 @@ code {
271271
}
272272

273273
.dbg-evaluate-tabular-btn {
274-
margin-top: 0.3rem;
274+
/* margin-top: 0.3rem; */
275275
margin-bottom: 0.3rem;
276276
vertical-align: top;
277277
display: inline-block;
278278
}
279279

280280
.dbg-evaluate-tabular-content {
281-
margin-top: 0.3rem;
281+
/* margin-top: 0.3rem; */
282282
margin-bottom: 0.3rem;
283283
vertical-align: top;
284284
display: inline-block;
@@ -292,7 +292,7 @@ p.dbg-error-information {
292292
color: #bbbbbb;
293293
}
294294

295-
p.dbg-evaluate-field-name {
295+
.dbg-evaluate-field-name {
296296
color: #006cae;
297297
}
298298

@@ -434,6 +434,14 @@ div.dbg-node-base:hover {
434434
background-color: #c0c0c00F;
435435
}
436436

437+
.stdout-info {
438+
color: #0287da;
439+
}
440+
441+
.stdout-error {
442+
color: #f27b7b;
443+
}
444+
437445
.right-aligned {
438446
text-align: right;
439447
}

src/application.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,26 @@ import CodeEditor from "./components/code-editor";
88
import AppCrashFallbackPage from "./components/app_crash_fallback";
99
import SettingPopup from "./components/settings";
1010
import { Row, Col } from "antd";
11+
import TutorialEditor from "./components/tutorial_editor";
1112

1213
export default class C0VMApplication extends React.Component<
1314
C0VMApplicationProps,
1415
C0VMApplicationState
1516
> {
1617
constructor(props: C0VMApplicationProps) {
1718
super(props);
19+
20+
const hideTutorialPanel = localStorage.getItem("hideTutorial");
21+
let showTutorial = false;
22+
if (hideTutorialPanel === null) showTutorial = true;
23+
1824
this.state = {
1925
crashed : false,
2026
c0_only : false,
2127
contentChanged : true,
2228
dbgFullScreen : false,
29+
30+
tutorialOn : showTutorial,
2331
settingMenuOn : false,
2432

2533
BC0SourceCode: "",
@@ -66,7 +74,8 @@ export default class C0VMApplication extends React.Component<
6674
/>
6775
) : null;
6876

69-
const SettingMenuComponent = <SettingPopup state={this.state} set_app_state={(ns) => this.setState(ns)}/>;
77+
const TutorialPanelComponent = <TutorialEditor state={this.state} set_app_state={(ns) => this.setState(ns)}/>;
78+
const SettingMenuComponent = <SettingPopup state={this.state} set_app_state={(ns) => this.setState(ns)}/>;
7079

7180
if (this.state.dbgFullScreen) {
7281
return <div className="page-framework">
@@ -81,6 +90,7 @@ export default class C0VMApplication extends React.Component<
8190

8291
return (
8392
<div className="page-framework">
93+
{TutorialPanelComponent}
8494
{SettingMenuComponent}
8595
{MainControlBarComponent}
8696
<Row className="main-ui-framework">

src/assets/Tab_Names.png

11.1 KB
Loading

src/assets/tutorial_rename.gif

25.6 KB
Loading

src/assets/tutorial_setbp.gif

51.8 KB
Loading

src/assets/tutorial_sorttab.gif

75.1 KB
Loading

src/components/code-editor.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from "react";
2-
import BC0Editor from "./bc0-editor";
3-
import C0EditorGroup from "./c0-editor-group";
2+
import BC0Editor from "./code_editor/bc0-editor";
3+
import C0EditorGroup from "./code_editor/c0-editor-group";
44

5-
import { Segmented, Tooltip, Upload } from "antd";
5+
import { Segmented, Space, Tooltip, Upload } from "antd";
66
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
77
import { faCode, faLock } from "@fortawesome/free-solid-svg-icons";
88
import { ConfigConsumer, ConfigConsumerProps } from "antd/es/config-provider";
@@ -20,6 +20,7 @@ export default class CodeEditor extends React.Component
2020
C0_nextKey : tabs.length === 0 ? 1 : Math.max(...tabs.map((tab) => tab.key)) + 1
2121
}
2222
this.handle_import_folder = this.handle_import_folder.bind(this);
23+
if (DEBUG) console.debug("handle_import_folder in CodeEditor is", this.handle_import_folder)
2324
}
2425

2526
push_populated_tab(tab: C0EditorTab) {
@@ -74,6 +75,8 @@ export default class CodeEditor extends React.Component
7475
// this function is called for every file in the uploaded directory, recursive.
7576
// the function is called by ant design component "Upload"
7677
handle_import_folder(F: RcFile, FList: RcFile[]) {
78+
if (DEBUG) console.debug("received a folder upload, processing one of them")
79+
7780
if (!(F.name.endsWith('.c0') || F.name.endsWith('.c1'))) {
7881
globalThis.MSG_EMITTER.warn(
7982
"File is not Imported",
@@ -196,25 +199,23 @@ export default class CodeEditor extends React.Component
196199
}
197200

198201
if (! this.props.app_state.c0_only){
199-
selectorArr.push(
200-
<Segmented
201-
key="language_selector"
202-
options={[
203-
{ label: "C0", value: "c0" },
204-
{ label: "BC0",value: "bc0"}
205-
]}
206-
defaultValue={this.state.mode}
207-
onChange={(value) => {this.setState({mode: value as "c0" | "bc0"})}}
208-
/>
209-
);
202+
selectorArr.push(<Segmented
203+
key="language_selector"
204+
options={[
205+
{ label: "Source", value: "c0" },
206+
{ label: "ByteC",value: "bc0"}
207+
]}
208+
defaultValue={this.state.mode}
209+
onChange={(value) => {this.setState({mode: value as "c0" | "bc0"})}}
210+
/>);
210211
}
211212

212213

213214
let selector = undefined;
214215
if (selectorArr.length === 1){
215216
selector = selectorArr[0];
216217
} else if (selectorArr.length === 2) {
217-
selector = <div>{selectorArr[0]} {selectorArr[1]}</div>
218+
selector = <Space size="small">{selectorArr[0]} {selectorArr[1]}</Space>
218219
}
219220

220221
if (this.props.app_state.c0_only) return this.render_c0(selector);

src/components/bc0-editor.tsx renamed to src/components/code_editor/bc0-editor.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React from "react";
22
import ReactCodeMirror, { basicSetup } from "@uiw/react-codemirror";
3+
import { language } from "@codemirror/language";
34

4-
import breakpointGutter from "./editor_extension/breakpoint_marker";
5+
import breakpointGutter from "./editor_extension/breakpoint_marker";
56
import execLineHighlighter from "./editor_extension/exec_position";
6-
import { BC0Language } from "./editor_extension/syntax/bc0";
7-
8-
import { language } from "@codemirror/language";
9-
import BC0LightTheme from "./editor_extension/bc0editor_theme";
7+
import { BC0Language } from "./editor_extension/syntax/bc0";
8+
import BC0LightTheme from "./editor_extension/bc0editor_theme";
109

1110

1211
export default class BC0Editor extends React.Component<BC0EditorProps>

src/components/c0-editor-group.tsx renamed to src/components/code_editor/c0-editor-group.tsx

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,14 @@ import { Tabs, TabsProps } from "antd";
33
import C0Editor from "./c0-editor";
44
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
55
import { faXmark, faAdd } from "@fortawesome/free-solid-svg-icons";
6-
import DraggableTabs from "./draggable_tabs";
7-
import type { RcFile } from 'antd/lib/upload';
86

7+
import DraggableTabs from "./draggable_tabs";
8+
import EditableTab from "./editable_tabs";
99

10-
import AutosizeInput from 'react-18-input-autosize';
10+
import type { RcFile } from 'antd/lib/upload';
1111

1212
const { TabPane } = Tabs;
13-
const regex_valid_file_name = /^[0-9a-zA-Z_-]+\.c0$/;
14-
15-
class EditableTab extends React.Component<EditableTabProps, EditableTabState> {
16-
17-
constructor(props: EditableTabProps) {
18-
super(props);
19-
this.state = {
20-
title: props.title,
21-
being_edited: false,
22-
wip_title: "",
23-
};
24-
this.onChange = this.onChange.bind(this);
25-
this.onKeyDown = this.onKeyDown.bind(this);
26-
this.startEditing = this.startEditing.bind(this);
27-
this.stopEditing = this.stopEditing.bind(this);
28-
}
29-
30-
componentDidUpdate(prevProps: EditableTabProps) {
31-
if (this.props.title !== prevProps.title) {
32-
this.setState({title: this.props.title})
33-
}
34-
}
35-
36-
onChange(e: React.ChangeEvent<HTMLInputElement>) {
37-
e.preventDefault();
38-
this.setState({wip_title: e.target.value});
39-
}
40-
41-
onKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
42-
if (e.key === 'Enter') {
43-
this.stopEditing();
44-
}
45-
}
46-
47-
startEditing() {
48-
this.setState({wip_title: this.state.title});
49-
this.setState({being_edited: true});
50-
}
51-
52-
async stopEditing() {
53-
await this.props.updateName(this.props.editor_key, this.state.wip_title);
54-
this.setState({
55-
being_edited: false,
56-
title: this.props.title, // update display title
57-
wip_title: this.state.title // resets title if updateName fails
58-
});
59-
}
60-
61-
render() {
62-
if (!this.state.being_edited) {
63-
return (
64-
<span onDoubleClick={this.startEditing}>{this.state.title}</span>
65-
);
66-
} else {
67-
return (
68-
<AutosizeInput
69-
className="tab-name"
70-
type="text"
71-
value={this.state.wip_title}
72-
onChange={this.onChange}
73-
onKeyDown={this.onKeyDown}
74-
onBlur={this.stopEditing}
75-
autoFocus
76-
></AutosizeInput>
77-
);
78-
}
79-
}
80-
}
81-
13+
const regex_valid_file_name = /^[0-9a-zA-Z_-]+\.c(0|1)$/;
8214

8315

8416
export default class C0EditorGroup extends React.Component <C0EditorGroupProps>
@@ -90,6 +22,7 @@ export default class C0EditorGroup extends React.Component <C0EditorGroupProps>
9022
this.on_change_key = this.on_change_key.bind(this);
9123
this.update_tab_order = this.update_tab_order.bind(this);
9224
this.set_brkpt_for_editor = this.set_brkpt_for_editor.bind(this);
25+
if (DEBUG) console.debug("handle_import_folder prop in C0EditorGroup is", this.props.handle_import_folder);
9326
}
9427

9528
set_tab_name(key: number, name: string){

src/components/c0-editor.tsx renamed to src/components/code_editor/c0-editor.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from "react";
22
import ReactCodeMirror, { basicSetup } from "@uiw/react-codemirror";
3+
import { indentUnit } from "@codemirror/language";
34

45
import { LoadDocumentPlugin } from "./editor_extension/blank_load";
5-
import { C0 } from "./editor_extension/syntax/c0";
6-
7-
import { indentUnit } from "@codemirror/language";
6+
import { C0 } from "./editor_extension/syntax/c0";
87
import execLineHighlighter from "./editor_extension/exec_position";
9-
import breakpointGutter from "./editor_extension/breakpoint_marker";
10-
import C0LightTheme from "./editor_extension/c0editor_theme";
8+
import breakpointGutter from "./editor_extension/breakpoint_marker";
9+
import C0LightTheme from "./editor_extension/c0editor_theme";
10+
1111

1212
export default class C0Editor extends React.Component<C0EditorProps>
1313
{
@@ -42,7 +42,7 @@ export default class C0Editor extends React.Component<C0EditorProps>
4242
value = {this.props.editorValue}
4343
extensions={[
4444
breakpoint_extension,
45-
LoadDocumentPlugin(".c0", this.props.updateName, this.props.handle_import_folder),
45+
LoadDocumentPlugin(".c0, .c1", this.props.updateName, this.props.handle_import_folder),
4646
basicSetup(),
4747
indentUnit.of(" "),
4848
execLineHighlighter(this.props.execLine, "light"),

0 commit comments

Comments
 (0)