-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMiniForth.cpp
More file actions
100 lines (67 loc) · 1.86 KB
/
MiniForth.cpp
File metadata and controls
100 lines (67 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// MiniTIL.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <Windows.h>
extern "C"
{
#include "InnerInterpreter.h"
#include "MiniForth.h"
}
long long milliseconds_now() {
static LARGE_INTEGER s_frequency;
static BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency);
if (s_use_qpc) {
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
return (1000LL * now.QuadPart) / s_frequency.QuadPart;
}
else {
return GetTickCount();
}
}
int main()
{
std::cout << "Sorting...\n";
InitInterpreter();
InitWords();
//TestStack();
// execute and time the TEST1 Word
size_t count = 5;
long long average = 0;
for (size_t i = 0; i < count; i++)
{
long long start = milliseconds_now();
Execute(TEST1);
long long elapsed = milliseconds_now() - start;
average += elapsed;
std::cout << "Sort time: " << elapsed << "\n";
}
std::cout << "Average time: " << average / count << "\n";
/*
Once you step over the above Execute call, try viewing the global DataStackPtr variable
Press Shift+F9 to bring up the variable inspector and this enter this
DataStackPtr
Expand the Ptr and you will see top of stack result (IntObject with a value of 4)
Next try viewing the DataStack global variable here (the whole stack of objects).
Enter this expression
DataStack, view(array)
The ", view(array)" shows the custom Object array walking visualization and will walk the variable sized Objects on the stack!
*/
}
void TestStack()
{
Object o1, o2, o3;
MakeIntObject(&o1, 1);
MakeIntObject(&o2, 2);
MakeIntObject(&o3, 3);
Push(&DataStackPtr, &o1);
Push(&DataStackPtr, &o2);
Push(&DataStackPtr, &o3);
Object o4, o5, o6;
MakeIntObject(&o4, 0);
MakeIntObject(&o5, 0);
MakeIntObject(&o6, 0);
Pop(&DataStackPtr, &o4);
Pop(&DataStackPtr, &o5);
Pop(&DataStackPtr, &o6);
}