Comments (5)
Например, есть программа:
type int = number
type ints = int[]
function swap(array: ints, i: int, j: int) {
let ai = array[i]
array[i] = array[j]
array[j] = ai
}
function partition(values: ints, l: int, r: int): int {
let x = values[r]
let less = l
let i = l
while (i < r) {
let value = values[i]
if (value <= x) {
swap(values, i, less)
less = less + 1
}
i = i + 1
}
swap(values, less, r)
return less
}
function quickSortImpl(values: ints, l: int, r: int) {
if (l < r) {
let q = partition(values, l, r)
quickSortImpl(values, l, q - 1)
quickSortImpl(values, q + 1, r)
}
}
function quickSort(values: ints) {
let n = ~values
if (n != 0) {
quickSortImpl(values, 0, n - 1)
}
}
let numbers = [6,2,4,3,7,1,5,]
quickSort(numbers)
print(numbers as string)
from extended-js-subset.
Интерпретатор сгенерирует следующий набор инструкций:
0: Goto 7
1: BeginFunction swap
2: ai = array [] i
3: _t3 = array [] j
4: array[i] = _t3
5: array[j] = ai
6: Return
7: Goto 29
8: BeginFunction partition
9: x = values [] r
10: less = l
11: i = l
12: _t12 = i < r
13: IfNot _t12 Goto 24
14: value = values [] i
15: _t15 = value <= x
16: IfNot _t15 Goto 22
17: PushParameter array = values
18: PushParameter i = i
19: PushParameter j = less
20: Call (1, swap), 3
21: less = less + 1
22: i = i + 1
23: Goto 12
24: PushParameter array = values
25: PushParameter i = less
26: PushParameter j = r
27: Call (1, swap), 3
28: Return less
29: Goto 48
30: BeginFunction quickSortImpl
31: _t31 = l < r
32: IfNot _t31 Goto 47
33: PushParameter values = values
34: PushParameter l = l
35: PushParameter r = r
36: q = Call (8, partition), 3
37: PushParameter values = values
37: _t37 = q - 1
38: PushParameter l = l
40: PushParameter r = _t37
41: Call (30, quickSortImpl), 3
42: PushParameter values = values
42: _t42 = q + 1
44: PushParameter l = _t42
45: PushParameter r = r
46: Call (30, quickSortImpl), 3
47: Return
48: Goto 59
49: BeginFunction quickSort
50: n = ~values
51: _t51 = n != 0
52: IfNot _t51 Goto 58
53: _t53 = n - 1
53: PushParameter values = values
54: PushParameter l = 0
56: PushParameter r = _t53
57: Call (30, quickSortImpl), 3
58: Return
59: array numbers = [7]
60: numbers[0] = 6
61: numbers[1] = 2
62: numbers[2] = 4
63: numbers[3] = 3
64: numbers[4] = 7
65: numbers[5] = 1
66: numbers[6] = 5
67: PushParameter values = numbers
68: Call (49, quickSort), 1
69: _t69 = numbers as string
70: Print _t69
71: End
from extended-js-subset.
В приведённой программе видно дублирующиеся адреса, которые приводят к бесконечному циклу внутри виртуалки
from extended-js-subset.
Сейчас, вся кодогенерация размазана по узлам AST. Возможно, рефакторинг в #4 решит проблему.
Иначе, придётся изобретать новую систему адресации.
from extended-js-subset.
Новую систему адресации всё же пришлось изобрести
from extended-js-subset.
Related Issues (20)
- Неудобно клонировать объекты HOT 2
- Отсутствует независимая система адресации инструкций
- Баг при разборе типа
- Переход на .NET 7
- Недоступна функция forward reference для типов
- Требуется усилить уникальность HashAddress
- Инкапсуляция логики формирования имени временных переменных виртуальной машины
- Доработка доменной модели кодогенерации HOT 1
- У CommandLineSettings присутствует излишний функционал
- Изменить способ вывода HOT 1
- [feature request] возможно стоит перейти на System.CommandLine HOT 3
- Увеличить покрытие unit тестами
- [feature request] Добавить сборку релиза для маков на м1 HOT 1
- [feature request] Стоит рассмотреть переход на Native AOT publish HOT 1
- [feature request] Подключение Nullable Reference Types
- [feature request] Интеграционные тесты
- [feature request] Автоматизировать версионирование релизов
- [bug] Нельзя использовать идентификатор, частью которого является ключевое слово
- [feature request] переход на .NET 8 HOT 2
- [feature request] Изоляция домена и переход на Clean Architecture
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extended-js-subset.