Última atividade 1747970823

This is a full implementation of a Viznut pattern generator, including a small windowing framework and a full stack machine DSL.

wryl revisou este gist 1747970823. Ir para a revisão

1 file changed, 7 insertions, 7 deletions

window-management.nv

@@ -44,16 +44,16 @@
44 44
45 45 |:: start :screen resolution: $x $y?|
46 46 :@graphics: set-resolution $x $y
47 - ::main loop
47 + :: main loop
48 48
49 49 |:: main loop :quit:|
50 50 |:: main loop|
51 - ::poll for input
52 - ::handle input
53 - ::update
54 - ::draw
55 - ::display
56 - ::main loop
51 + :: poll for input
52 + :: handle input
53 + :: update
54 + :: draw
55 + :: display
56 + :: main loop
57 57
58 58 |::|:: start
59 59

wryl revisou este gist 1747970259. Ir para a revisão

3 files changed, 209 insertions

stack-machine.nv(arquivo criado)

@@ -0,0 +1,108 @@
1 + |:push: :: $x|
2 + :: push $x
3 + |:push:|
4 +
5 + |:set: :: $name :data: $value|
6 + :: set $name $value
7 + |:set: :: $name|
8 + :error: stack underflow
9 +
10 + |:get: :: $name|
11 + :: get $name
12 +
13 + |:: push $n|
14 + :data: $n
15 +
16 + |:: duplicate :data: $n|
17 + :data: $n
18 + :data: $n
19 + |:: duplicate|
20 + :error: stack underflow
21 +
22 + |:: drop :data: $n|
23 + |:: drop|
24 + :error: stack underflow
25 +
26 + |:: swap :swap: $x :data: $y|
27 + :data: $y
28 + :data: $x
29 + |:: swap :swap: $x|
30 + :error: stack underflow
31 + |:: swap? :data: $x|
32 + :swap: $x
33 +
34 + |:compare: :@math: $x|
35 + :data: $x
36 + |:compare: $x :data: $y|
37 + :compare:
38 + :@math: compare $y $x
39 +
40 + |:: greater :data: less | :data: false
41 + |:: greater :data: equal | :data: false
42 + |:: greater :data: greater| :data: true
43 + |:: greater? :data: $x|
44 + :compare: $x
45 +
46 + |:: abs :@math: less|
47 + ::(# -1 *)
48 + |:: abs :@math: $x|
49 + |:: abs? :data: $x?|
50 + :@math: compare $x 0
51 +
52 + |:: math $op :@math: $n|
53 + :data: $n
54 + |:: math $op? :@math: $op $x :data: $y|
55 + :@math: $op $y $x
56 + |:: math $op :@math: $op $x|
57 + :error: stack underflow
58 + |:: math $op? :data: $x|
59 + :@math: $op $x
60 + |:: math $op|
61 + :error: stack underflow
62 +
63 + |:: print :data: $x|
64 + :@stdio: print $x
65 + |:: print|
66 + :error: stack underflow
67 +
68 + |:reset variables:? :checked variables: $x $y|
69 + :variables: $x $y
70 + |:reset variables:|
71 +
72 + |:: set $x $y :variables: $x $|
73 + :variables: $x $y
74 + :reset variables:
75 + |:: set $x $y? :variables: $v $|
76 + :checked variables: $v $
77 + :reset variables:
78 + |:: set $x $y|
79 + :variables: $x $y
80 +
81 + |:: get $x :variables: $x $y?|
82 + :data: $y
83 + :reset variables:
84 + |:: get $x :variables: $v $|
85 + :checked variables: $v $
86 + :reset variables:
87 + |:: get $x|
88 + :error: $x not found
89 +
90 + |:: set | :set:
91 + |:: get | :get:
92 + |:: add | :: math add
93 + |:: subtract| :: math subtract
94 + |:: multiply| :: math multiply
95 + |:: divide | :: math divide
96 + |:: modulo | :: math modulo
97 + |:: and | :: math and
98 + |:: dup | :: duplicate
99 +
100 + |:: +| :: add
101 + |:: -| :: subtract
102 + |:: *| :: multiply
103 + |:: /| :: divide
104 + |:: %| :: modulo
105 + |:: &| :: and
106 + |:: >| :: greater
107 +
108 + |:: #| :push:

viznut.nv(arquivo criado)

@@ -0,0 +1,42 @@
1 + |:: next pixel :screen resolution: $x $y? :pixel: $x $y|
2 + :pixel: 0 0
3 + :finished frame:
4 + |:: next pixel :screen resolution: $x $ry? :pixel: $x $py|
5 + :pixel: 0 $py
6 + :: next row
7 + |:: next pixel :pixel: $x $y :@math: $n|
8 + :pixel: $n $y
9 + |:: next pixel? :pixel: $x $y?|
10 + :@math: add $x 1
11 +
12 + |:: next row :pixel: $x $y :@math: $n|
13 + :pixel: $x $n
14 + |:: next row? :pixel: $x $y?|
15 + :@math: add $y 1
16 +
17 + ||:pixel: 0 0
18 + |:: plot :data: true :pixel: $x $y?|
19 + :@graphics: set-pixel $x $y 255 255 255
20 + |:: plot :data: false :pixel: $x $y?|
21 + :@graphics: set-pixel $x $y 0 0 0
22 + |:: plot :pixel: $x $y?|
23 + :: viznut $x $y
24 + :: plot
25 +
26 + |:: draw a frame :finished frame:|
27 + |:: draw a frame|
28 + :: plot :: next pixel
29 + :: draw a frame
30 +
31 + |:: draw|
32 + :: clear the screen
33 + :: draw a frame
34 + :: draw FPS
35 +
36 + |:: viznut $x $y|::(
37 + # $x # $y + # $x # $y - &
38 + # 24 % abs # 9 >
39 + )
40 +
41 + |::|
42 + :screen resolution: 64 64

window-management.nv(arquivo criado)

@@ -0,0 +1,59 @@
1 + |: Default handlers. :|
2 + |:: update|
3 + |:: handle input|
4 + |:: draw|
5 +
6 + |:: draw FPS| :@graphics: draw-fps
7 +
8 + |:: clear the screen :screen color: $r $g $b?|
9 + :@graphics: clear-screen $r $g $b
10 + |:: clear the screen|
11 + :@graphics: clear-screen 0 0 0
12 +
13 + |:: display| :@graphics: display
14 +
15 + |:: poll for input|
16 + :@input: poll-input
17 + :@input: get-mouse-position
18 + :@input: check-mouse-button 0
19 + :@input: check-mouse-button 2
20 +
21 + |:@input: mouse-button-pressed 0| :left mouse: pressed
22 + |:@input: mouse-button-pressed 1| :middle mouse: pressed
23 + |:@input: mouse-button-pressed 2| :right mouse: pressed
24 + |:@input: mouse-button-released $x|
25 + |:@input: mouse-position $x $y| :mouse position: $x $y
26 +
27 + |:@signal: quit| :quit:
28 +
29 + |:left mouse: $x|
30 + |:middle mouse: $x|
31 + |:right mouse: $x|
32 + |:mouse position: $x $y|
33 +
34 + |:: check if $key is pressed|
35 + ::check if $key was pressed
36 + |:: check if $key was pressed :@input: key-pressed $key|
37 + :key pressed: $key
38 + |:: check if $key was pressed :@input: key-released $key|
39 + :key released: $key
40 + |:: check if $key was pressed?|
41 + :@input: check-key $key
42 + |:key pressed: $key|
43 + |:key released: $key|
44 +
45 + |:: start :screen resolution: $x $y?|
46 + :@graphics: set-resolution $x $y
47 + ::main loop
48 +
49 + |:: main loop :quit:|
50 + |:: main loop|
51 + ::poll for input
52 + ::handle input
53 + ::update
54 + ::draw
55 + ::display
56 + ::main loop
57 +
58 + |::|:: start
59 +
Próximo Anterior