Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global strings
- global variables
- global stack
- global continuations
- procedure main ()
- initialize_globals ()
- @continuations[1]
- end
- procedure initialize_globals ()
- stack := []
- variables := []
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- put (variables, 0)
- continuations := list (104)
- continuations[1] := create (routine_push (420, 2))
- continuations[2] := create (routine_unary ("unary_neg", 3))
- continuations[3] := create (routine_store (1, 4))
- continuations[4] := create (routine_push (300, 5))
- continuations[5] := create (routine_store (2, 6))
- continuations[6] := create (routine_push (300, 7))
- continuations[7] := create (routine_store (3, 8))
- continuations[8] := create (routine_push (300, 9))
- continuations[9] := create (routine_unary ("unary_neg", 10))
- continuations[10] := create (routine_store (4, 11))
- continuations[11] := create (routine_push (7, 12))
- continuations[12] := create (routine_store (5, 13))
- continuations[13] := create (routine_push (15, 14))
- continuations[14] := create (routine_store (6, 15))
- continuations[15] := create (routine_push (200, 16))
- continuations[16] := create (routine_store (7, 17))
- continuations[17] := create (routine_fetch (3, 18))
- continuations[18] := create (routine_store (8, 19))
- continuations[19] := create (routine_fetch (8, 20))
- continuations[20] := create (routine_fetch (4, 21))
- continuations[21] := create (routine_binary ("binary_gt", 22))
- continuations[22] := create (routine_jz (23, 24))
- continuations[24] := create (routine_fetch (1, 25))
- continuations[25] := create (routine_store (9, 26))
- continuations[26] := create (routine_fetch (9, 27))
- continuations[27] := create (routine_fetch (2, 28))
- continuations[28] := create (routine_binary ("binary_lt", 29))
- continuations[29] := create (routine_jz (30, 31))
- continuations[31] := create (routine_push (0, 32))
- continuations[32] := create (routine_store (10, 33))
- continuations[33] := create (routine_push (0, 34))
- continuations[34] := create (routine_store (11, 35))
- continuations[35] := create (routine_push (32, 36))
- continuations[36] := create (routine_store (12, 37))
- continuations[37] := create (routine_push (0, 38))
- continuations[38] := create (routine_store (13, 39))
- continuations[39] := create (routine_fetch (13, 40))
- continuations[40] := create (routine_fetch (7, 41))
- continuations[41] := create (routine_binary ("binary_lt", 42))
- continuations[42] := create (routine_jz (43, 44))
- continuations[44] := create (routine_fetch (11, 45))
- continuations[45] := create (routine_fetch (11, 46))
- continuations[46] := create (routine_binary ("binary_mul", 47))
- continuations[47] := create (routine_push (200, 48))
- continuations[48] := create (routine_binary ("binary_div", 49))
- continuations[49] := create (routine_store (14, 50))
- continuations[50] := create (routine_fetch (10, 51))
- continuations[51] := create (routine_fetch (10, 52))
- continuations[52] := create (routine_binary ("binary_mul", 53))
- continuations[53] := create (routine_push (200, 54))
- continuations[54] := create (routine_binary ("binary_div", 55))
- continuations[55] := create (routine_store (15, 56))
- continuations[56] := create (routine_fetch (14, 57))
- continuations[57] := create (routine_fetch (15, 58))
- continuations[58] := create (routine_binary ("binary_add", 59))
- continuations[59] := create (routine_push (800, 60))
- continuations[60] := create (routine_binary ("binary_gt", 61))
- continuations[61] := create (routine_jz (62, 63))
- continuations[63] := create (routine_push (48, 64))
- continuations[64] := create (routine_fetch (13, 65))
- continuations[65] := create (routine_binary ("binary_add", 66))
- continuations[66] := create (routine_store (12, 67))
- continuations[67] := create (routine_fetch (13, 68))
- continuations[68] := create (routine_push (9, 69))
- continuations[69] := create (routine_binary ("binary_gt", 70))
- continuations[70] := create (routine_jz (71, 72))
- continuations[72] := create (routine_push (64, 73))
- continuations[73] := create (routine_store (12, 71))
- continuations[71] := create (routine_fetch (7, 74))
- continuations[74] := create (routine_store (13, 62))
- continuations[62] := create (routine_fetch (11, 75))
- continuations[75] := create (routine_fetch (10, 76))
- continuations[76] := create (routine_binary ("binary_mul", 77))
- continuations[77] := create (routine_push (100, 78))
- continuations[78] := create (routine_binary ("binary_div", 79))
- continuations[79] := create (routine_fetch (8, 80))
- continuations[80] := create (routine_binary ("binary_add", 81))
- continuations[81] := create (routine_store (10, 82))
- continuations[82] := create (routine_fetch (14, 83))
- continuations[83] := create (routine_fetch (15, 84))
- continuations[84] := create (routine_binary ("binary_sub", 85))
- continuations[85] := create (routine_fetch (9, 86))
- continuations[86] := create (routine_binary ("binary_add", 87))
- continuations[87] := create (routine_store (11, 88))
- continuations[88] := create (routine_fetch (13, 89))
- continuations[89] := create (routine_push (1, 90))
- continuations[90] := create (routine_binary ("binary_add", 91))
- continuations[91] := create (routine_store (13, 92))
- continuations[92] := create (routine_jmp (39))
- continuations[43] := create (routine_fetch (12, 93))
- continuations[93] := create (routine_prtc (94))
- continuations[94] := create (routine_fetch (9, 95))
- continuations[95] := create (routine_fetch (5, 96))
- continuations[96] := create (routine_binary ("binary_add", 97))
- continuations[97] := create (routine_store (9, 98))
- continuations[98] := create (routine_jmp (26))
- continuations[30] := create (routine_push (10, 99))
- continuations[99] := create (routine_prtc (100))
- continuations[100] := create (routine_fetch (8, 101))
- continuations[101] := create (routine_fetch (6, 102))
- continuations[102] := create (routine_binary ("binary_sub", 103))
- continuations[103] := create (routine_store (8, 104))
- continuations[104] := create (routine_jmp (19))
- continuations[23] := create (routine_halt ())
- return
- end
- procedure routine_unary_not (i_kont)
- repeat
- {
- stack[1] := (if stack[1] = 0 then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_unary_neg (i_kont)
- repeat { stack[1] := -stack[1]; @continuations[i_kont] }
- end
- procedure routine_unary (operation, i_kont)
- case operation of
- {
- "unary_not" : routine_unary_not (i_kont)
- "unary_neg" : routine_unary_neg (i_kont)
- default : fail
- }
- end
- procedure routine_binary_and (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := (if (stack[1] ~= 0 & y ~= 0) then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_binary_or (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := (if (stack[1] ~= 0 | y ~= 0) then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_binary_lt (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := (if stack[1] < y then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_binary_le (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := (if stack[1] <= y then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_binary_gt (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := (if stack[1] > y then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_binary_ge (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := (if stack[1] >= y then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_binary_eq (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := (if stack[1] = y then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_binary_ne (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := (if stack[1] ~= y then 1 else 0)
- @continuations[i_kont]
- }
- end
- procedure routine_binary_add (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := stack[1] + y
- @continuations[i_kont]
- }
- end
- procedure routine_binary_sub (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := stack[1] - y
- @continuations[i_kont]
- }
- end
- procedure routine_binary_mul (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := stack[1] * y
- @continuations[i_kont]
- }
- end
- procedure routine_binary_div (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := stack[1] / y
- @continuations[i_kont]
- }
- end
- procedure routine_binary_mod (i_kont)
- local y
- repeat {
- y := pop (stack)
- stack[1] := stack[1] % y
- @continuations[i_kont]
- }
- end
- procedure routine_binary (operation, i_kont)
- case operation of
- {
- "binary_and" : routine_binary_and (i_kont)
- "binary_or" : routine_binary_or (i_kont)
- "binary_lt" : routine_binary_lt (i_kont)
- "binary_le" : routine_binary_le (i_kont)
- "binary_gt" : routine_binary_gt (i_kont)
- "binary_ge" : routine_binary_ge (i_kont)
- "binary_eq" : routine_binary_eq (i_kont)
- "binary_ne" : routine_binary_ne (i_kont)
- "binary_add" : routine_binary_add (i_kont)
- "binary_sub" : routine_binary_sub (i_kont)
- "binary_mul" : routine_binary_mul (i_kont)
- "binary_div" : routine_binary_div (i_kont)
- "binary_mod" : routine_binary_mod (i_kont)
- default : fail
- }
- end
- procedure routine_jmp (i_kont)
- repeat @continuations[i_kont]
- end
- procedure routine_jz (i_kont_if, i_kont_else)
- repeat
- {
- if pop (stack) = 0 then
- @continuations[i_kont_if]
- else
- @continuations[i_kont_else]
- }
- end
- procedure routine_push (pushval, i_kont)
- repeat { push (stack, pushval); @continuations[i_kont] }
- end
- procedure routine_store (i_var, i_kont)
- repeat { variables[i_var] := pop (stack); @continuations[i_kont] }
- end
- procedure routine_fetch (i_var, i_kont)
- repeat { push (stack, variables[i_var]); @continuations[i_kont] }
- end
- procedure routine_prtc (i_kont)
- repeat { writes (char (pop (stack))); @continuations[i_kont] }
- end
- procedure routine_prti (i_kont)
- repeat { writes (pop (stack)); @continuations[i_kont] }
- end
- procedure routine_prts (i_kont)
- repeat { writes (strings[pop (stack) + 1]); @continuations[i_kont] }
- end
- procedure routine_halt ()
- @&main
- end
Advertisement
Advertisement