migrate from icloud
This commit is contained in:
		
							parent
							
								
									efc2da6505
								
							
						
					
					
						commit
						56f6aefac8
					
				| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					FC = gfortran
 | 
				
			||||||
 | 
					FCFLAGS = -O
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					all: varaq
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					varaq:
 | 
				
			||||||
 | 
						$(FC) $(FCFLAGS) -o varaq compiler.f90 main.f90
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test:
 | 
				
			||||||
 | 
						./varaq ./test.vq ./module.wasm && http-server .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					clean:
 | 
				
			||||||
 | 
						rm -f *.o *.mod varaq
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,277 @@
 | 
				
			||||||
 | 
					module tokenizer_mod
 | 
				
			||||||
 | 
					    implicit none
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    type token
 | 
				
			||||||
 | 
					        character(:), allocatable :: type
 | 
				
			||||||
 | 
					        character(:), allocatable :: value
 | 
				
			||||||
 | 
					        integer :: index
 | 
				
			||||||
 | 
					    end type token
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					contains
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    type(token) function init_token(type, value, index) result(this)
 | 
				
			||||||
 | 
					        character(:), allocatable :: type
 | 
				
			||||||
 | 
					        character(:), allocatable :: value
 | 
				
			||||||
 | 
					        integer :: index
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this%type = type
 | 
				
			||||||
 | 
					        this%value = value
 | 
				
			||||||
 | 
					        this%index = index
 | 
				
			||||||
 | 
					    end function
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function tokenize(code) result(tokens)
 | 
				
			||||||
 | 
					        character(:), allocatable :: code
 | 
				
			||||||
 | 
					        type(token), dimension(:), allocatable :: tokens
 | 
				
			||||||
 | 
					        integer :: pos1 = 1, pos2
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					        do
 | 
				
			||||||
 | 
					            pos2 = scan(code(pos1:), " \n\t\v\f\r")
 | 
				
			||||||
 | 
					            if (pos2 == 0) then
 | 
				
			||||||
 | 
					                tokens = [tokens, token("expression", code(pos1:), pos1)]
 | 
				
			||||||
 | 
					                return
 | 
				
			||||||
 | 
					            end if
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            tokens = [tokens, token("expression", code(pos1:pos1+pos2-2), pos1)]
 | 
				
			||||||
 | 
					            pos1 = pos2+pos1
 | 
				
			||||||
 | 
					        end do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    end function tokenize
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pure logical function isAlpha(c)
 | 
				
			||||||
 | 
					        character, intent(in) :: c
 | 
				
			||||||
 | 
					        isAlpha = (c .ge. 'a' .and. c .le. 'z') .or. (c .ge. 'A' .and. c .le. 'Z') .or. c .eq. '_' .or. c .eq. "'" .or. c .eq. '?'
 | 
				
			||||||
 | 
					    end function isAlpha
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pure logical function isDigit(c)
 | 
				
			||||||
 | 
					        character, intent(in) :: c
 | 
				
			||||||
 | 
					        isDigit = (c .ge. '0' .and. c .le. '9') .or. c .eq. '-'
 | 
				
			||||||
 | 
					    end function isDigit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					end module tokenizer_mod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module parser_mod
 | 
				
			||||||
 | 
					    implicit none
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					contains
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					end module parser_mod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module opcodes_mod
 | 
				
			||||||
 | 
					    implicit none 
 | 
				
			||||||
 | 
					       character, parameter :: UNREACHABLE          = achar(0)  
 | 
				
			||||||
 | 
					       character, parameter :: NOP                  = achar(1)  
 | 
				
			||||||
 | 
					       character, parameter :: BLOCK                = achar(2)  
 | 
				
			||||||
 | 
					       character, parameter :: LOOP                 = achar(3)  
 | 
				
			||||||
 | 
					       character, parameter :: IF                   = achar(4)  
 | 
				
			||||||
 | 
					       character, parameter :: ELSE                 = achar(5)  
 | 
				
			||||||
 | 
					       character, parameter :: TRY                  = achar(6)  ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: CATCH                = achar(7)  ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: THROW                = achar(8)  ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: RETHROW              = achar(9)  ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: BR_ON_EXN            = achar(10) ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: END                  = achar(11)
 | 
				
			||||||
 | 
					       character, parameter :: BR                   = achar(12)
 | 
				
			||||||
 | 
					       character, parameter :: BR_IF                = achar(13)
 | 
				
			||||||
 | 
					       character, parameter :: BR_TABLE             = achar(14)
 | 
				
			||||||
 | 
					       character, parameter :: RETURN               = achar(15)
 | 
				
			||||||
 | 
					       character, parameter :: CALL                 = achar(16)
 | 
				
			||||||
 | 
					       character, parameter :: CALL_INDIRECT        = achar(17)
 | 
				
			||||||
 | 
					       character, parameter :: RETURN_CALL          = achar(18) ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: RETURN_CALL_INDIRECT = achar(19) ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: DROP                 = achar(26)
 | 
				
			||||||
 | 
					       character, parameter :: SELECT               = achar(27)
 | 
				
			||||||
 | 
					       character, parameter :: SELECT_T             = achar(28) ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: LOCAL_GET            = achar(32)
 | 
				
			||||||
 | 
					       character, parameter :: LOCAL_SET            = achar(33)
 | 
				
			||||||
 | 
					       character, parameter :: LOCAL_TEE            = achar(34)
 | 
				
			||||||
 | 
					       character, parameter :: GLOBAL_GET           = achar(35)
 | 
				
			||||||
 | 
					       character, parameter :: GLOBAL_SET           = achar(36)
 | 
				
			||||||
 | 
					       character, parameter :: TABLE_GET            = achar(37) ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: TABLE_SET            = achar(38) ! PROPOSED
 | 
				
			||||||
 | 
					       character, parameter :: I32_LOAD             = achar(40)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LOAD             = achar(41)
 | 
				
			||||||
 | 
					       character, parameter :: F32_LOAD             = achar(42)
 | 
				
			||||||
 | 
					       character, parameter :: F64_LOAD             = achar(43)
 | 
				
			||||||
 | 
					       character, parameter :: I32_LOAD8_S          = achar(44)
 | 
				
			||||||
 | 
					       character, parameter :: I32_LOAD8_U          = achar(45)
 | 
				
			||||||
 | 
					       character, parameter :: I32_LOAD16_S         = achar(46)
 | 
				
			||||||
 | 
					       character, parameter :: I32_LOAD16_U         = achar(47)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LOAD8_S          = achar(48)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LOAD8_U          = achar(49)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LOAD16_S         = achar(50)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LOAD16_U         = achar(51)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LOAD32_S         = achar(52)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LOAD32_U         = achar(53)
 | 
				
			||||||
 | 
					       character, parameter :: I32_STORE            = achar(54)
 | 
				
			||||||
 | 
					       character, parameter :: I64_STORE            = achar(55)
 | 
				
			||||||
 | 
					       character, parameter :: F32_STORE            = achar(56)
 | 
				
			||||||
 | 
					       character, parameter :: F64_STORE            = achar(57)
 | 
				
			||||||
 | 
					       character, parameter :: I32_STORE8           = achar(58)
 | 
				
			||||||
 | 
					       character, parameter :: I32_STORE16          = achar(59)
 | 
				
			||||||
 | 
					       character, parameter :: I64_STORE8           = achar(60)
 | 
				
			||||||
 | 
					       character, parameter :: I64_STORE16          = achar(61)
 | 
				
			||||||
 | 
					       character, parameter :: I64_STORE32          = achar(62)
 | 
				
			||||||
 | 
					       character, parameter :: MEMORY_SIZE          = achar(63)
 | 
				
			||||||
 | 
					       character, parameter :: MEMORY_GROW          = achar(64)
 | 
				
			||||||
 | 
					       character, parameter :: I32_CONST            = achar(65)
 | 
				
			||||||
 | 
					       character, parameter :: I64_CONST            = achar(66)
 | 
				
			||||||
 | 
					       character, parameter :: F32_CONST            = achar(67)
 | 
				
			||||||
 | 
					       character, parameter :: F64_CONST            = achar(68)
 | 
				
			||||||
 | 
					       character, parameter :: I32_EQZ              = achar(69)
 | 
				
			||||||
 | 
					       character, parameter :: I32_EQ               = achar(70)
 | 
				
			||||||
 | 
					       character, parameter :: I32_NE               = achar(71)
 | 
				
			||||||
 | 
					       character, parameter :: I32_LT_S             = achar(72)
 | 
				
			||||||
 | 
					       character, parameter :: I32_LT_U             = achar(73)
 | 
				
			||||||
 | 
					       character, parameter :: I32_GT_S             = achar(74)
 | 
				
			||||||
 | 
					       character, parameter :: I32_GT_U             = achar(75)
 | 
				
			||||||
 | 
					       character, parameter :: I32_LE_S             = achar(76)
 | 
				
			||||||
 | 
					       character, parameter :: I32_LE_U             = achar(77)
 | 
				
			||||||
 | 
					       character, parameter :: I32_GE_S             = achar(78)
 | 
				
			||||||
 | 
					       character, parameter :: I32_GE_U             = achar(79)
 | 
				
			||||||
 | 
					       character, parameter :: I64_EQZ              = achar(80)
 | 
				
			||||||
 | 
					       character, parameter :: I64_EQ               = achar(81)
 | 
				
			||||||
 | 
					       character, parameter :: I64_NE               = achar(82)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LT_S             = achar(83)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LT_U             = achar(84)
 | 
				
			||||||
 | 
					       character, parameter :: I64_GT_S             = achar(85)
 | 
				
			||||||
 | 
					       character, parameter :: I64_GT_U             = achar(86)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LE_S             = achar(87)
 | 
				
			||||||
 | 
					       character, parameter :: I64_LE_U             = achar(88)
 | 
				
			||||||
 | 
					       character, parameter :: I64_GE_S             = achar(89)
 | 
				
			||||||
 | 
					       character, parameter :: I64_GE_U             = achar(90)
 | 
				
			||||||
 | 
					       character, parameter :: F32_EQ               = achar(91)
 | 
				
			||||||
 | 
					       character, parameter :: F32_NE               = achar(92)
 | 
				
			||||||
 | 
					       character, parameter :: F32_LT               = achar(93)
 | 
				
			||||||
 | 
					       character, parameter :: F32_GT               = achar(94)
 | 
				
			||||||
 | 
					       character, parameter :: F32_LE               = achar(95)
 | 
				
			||||||
 | 
					       character, parameter :: F32_GE               = achar(96)
 | 
				
			||||||
 | 
					       character, parameter :: F64_EQ               = achar(97)
 | 
				
			||||||
 | 
					       character, parameter :: F64_NE               = achar(98)
 | 
				
			||||||
 | 
					       character, parameter :: F64_LT               = achar(99)
 | 
				
			||||||
 | 
					       character, parameter :: F64_GT               = achar(100)
 | 
				
			||||||
 | 
					       character, parameter :: F64_LE               = achar(101)
 | 
				
			||||||
 | 
					       character, parameter :: F64_GE               = achar(102)
 | 
				
			||||||
 | 
					       character, parameter :: I32_CLZ              = achar(103)
 | 
				
			||||||
 | 
					       character, parameter :: I32_CTZ              = achar(104)
 | 
				
			||||||
 | 
					       character, parameter :: I32_POPCNT           = achar(105)
 | 
				
			||||||
 | 
					       character, parameter :: I32_ADD              = achar(106)
 | 
				
			||||||
 | 
					       character, parameter :: I32_SUB              = achar(107)
 | 
				
			||||||
 | 
					       character, parameter :: I32_MUL              = achar(108)
 | 
				
			||||||
 | 
					       character, parameter :: I32_DIV_S            = achar(109)
 | 
				
			||||||
 | 
					       character, parameter :: I32_DIV_U            = achar(110)
 | 
				
			||||||
 | 
					       character, parameter :: I32_REM_S            = achar(111)
 | 
				
			||||||
 | 
					       character, parameter :: I32_REM_U            = achar(112)
 | 
				
			||||||
 | 
					       character, parameter :: I32_AND              = achar(113)
 | 
				
			||||||
 | 
					       character, parameter :: I32_OR               = achar(114)
 | 
				
			||||||
 | 
					       character, parameter :: I32_XOR              = achar(115)
 | 
				
			||||||
 | 
					       character, parameter :: I32_SHL              = achar(116)
 | 
				
			||||||
 | 
					       character, parameter :: I32_SHR_S            = achar(117)
 | 
				
			||||||
 | 
					       character, parameter :: I32_SHR_U            = achar(118)
 | 
				
			||||||
 | 
					       character, parameter :: I32_ROTL             = achar(119)
 | 
				
			||||||
 | 
					       character, parameter :: I32_ROTR             = achar(120)
 | 
				
			||||||
 | 
					       character, parameter :: I64_CLZ              = achar(121)
 | 
				
			||||||
 | 
					       character, parameter :: I64_CTZ              = achar(122)
 | 
				
			||||||
 | 
					       character, parameter :: I64_POPCNT           = achar(123)
 | 
				
			||||||
 | 
					       character, parameter :: I64_ADD              = achar(124)
 | 
				
			||||||
 | 
					       character, parameter :: I64_SUB              = achar(125)
 | 
				
			||||||
 | 
					       character, parameter :: I64_MUL              = achar(126)
 | 
				
			||||||
 | 
					       character, parameter :: I64_DIV_S            = achar(127)
 | 
				
			||||||
 | 
					       character, parameter :: I64_DIV_U            = achar(128)
 | 
				
			||||||
 | 
					       character, parameter :: I64_REM_S            = achar(129)
 | 
				
			||||||
 | 
					       character, parameter :: I64_REM_U            = achar(130)
 | 
				
			||||||
 | 
					       character, parameter :: I64_AND              = achar(131)
 | 
				
			||||||
 | 
					       character, parameter :: I64_OR               = achar(132)
 | 
				
			||||||
 | 
					       character, parameter :: I64_XOR              = achar(133)
 | 
				
			||||||
 | 
					       character, parameter :: I64_SHL              = achar(134)
 | 
				
			||||||
 | 
					       character, parameter :: I64_SHR_S            = achar(135)
 | 
				
			||||||
 | 
					       character, parameter :: I64_SHR_U            = achar(136)
 | 
				
			||||||
 | 
					       character, parameter :: I64_ROTL             = achar(137)
 | 
				
			||||||
 | 
					       character, parameter :: I64_ROTR             = achar(138)
 | 
				
			||||||
 | 
					       character, parameter :: F32_ABS              = achar(139)
 | 
				
			||||||
 | 
					       character, parameter :: F32_NEG              = achar(140)
 | 
				
			||||||
 | 
					       character, parameter :: F32_CEIL             = achar(141)
 | 
				
			||||||
 | 
					       character, parameter :: F32_FLOOR            = achar(142)
 | 
				
			||||||
 | 
					       character, parameter :: F32_TRUNC            = achar(143)
 | 
				
			||||||
 | 
					       character, parameter :: F32_NEAREST          = achar(144)
 | 
				
			||||||
 | 
					       character, parameter :: F32_SQRT             = achar(145)
 | 
				
			||||||
 | 
					       character, parameter :: F32_ADD              = achar(146)
 | 
				
			||||||
 | 
					       character, parameter :: F32_SUB              = achar(147)
 | 
				
			||||||
 | 
					       character, parameter :: F32_MUL              = achar(148)
 | 
				
			||||||
 | 
					       character, parameter :: F32_DIV              = achar(149)
 | 
				
			||||||
 | 
					       character, parameter :: F32_MIN              = achar(150)
 | 
				
			||||||
 | 
					       character, parameter :: F32_MAX              = achar(151)
 | 
				
			||||||
 | 
					       character, parameter :: F32_COPYSIGN         = achar(152)
 | 
				
			||||||
 | 
					       character, parameter :: F64_ABS              = achar(153)
 | 
				
			||||||
 | 
					       character, parameter :: F64_NEG              = achar(154)
 | 
				
			||||||
 | 
					       character, parameter :: F64_CEIL             = achar(155)
 | 
				
			||||||
 | 
					       character, parameter :: F64_FLOOR            = achar(156)
 | 
				
			||||||
 | 
					       character, parameter :: F64_TRUNC            = achar(157)
 | 
				
			||||||
 | 
					       character, parameter :: F64_NEAREST          = achar(158)
 | 
				
			||||||
 | 
					       character, parameter :: F64_SQRT             = achar(159)
 | 
				
			||||||
 | 
					       character, parameter :: F64_ADD              = achar(160)
 | 
				
			||||||
 | 
					       character, parameter :: F64_SUB              = achar(161)
 | 
				
			||||||
 | 
					       character, parameter :: F64_MUL              = achar(162)
 | 
				
			||||||
 | 
					       character, parameter :: F64_DIV              = achar(163)
 | 
				
			||||||
 | 
					       character, parameter :: F64_MIN              = achar(164)
 | 
				
			||||||
 | 
					       character, parameter :: F64_MAX              = achar(165)
 | 
				
			||||||
 | 
					       character, parameter :: F64_COPYSIGN         = achar(166)
 | 
				
			||||||
 | 
					       character, parameter :: I32_WRAP_I64         = achar(167)
 | 
				
			||||||
 | 
					       character, parameter :: I32_TRUNC_F32_S      = achar(168)
 | 
				
			||||||
 | 
					       character, parameter :: I32_TRUNC_F32_U      = achar(169)
 | 
				
			||||||
 | 
					       character, parameter :: I32_TRUNC_F64_S      = achar(170)
 | 
				
			||||||
 | 
					       character, parameter :: I32_TRUNC_F64_U      = achar(171)
 | 
				
			||||||
 | 
					       character, parameter :: I64_EXTEND_I32_S     = achar(172)
 | 
				
			||||||
 | 
					       character, parameter :: I64_EXTEND_I32_U     = achar(173)
 | 
				
			||||||
 | 
					       character, parameter :: I64_TRUNC_F32_S      = achar(174)
 | 
				
			||||||
 | 
					       character, parameter :: I64_TRUNC_F32_U      = achar(175)
 | 
				
			||||||
 | 
					       character, parameter :: I64_TRUNC_F64_S      = achar(176)
 | 
				
			||||||
 | 
					       character, parameter :: I64_TRUNC_F64_U      = achar(177)
 | 
				
			||||||
 | 
					       character, parameter :: F32_CONVERT_I32_S    = achar(178)
 | 
				
			||||||
 | 
					       character, parameter :: F32_CONVERT_I32_U    = achar(179)
 | 
				
			||||||
 | 
					       character, parameter :: F32_CONVERT_I64_S    = achar(180)
 | 
				
			||||||
 | 
					       character, parameter :: F32_CONVERT_I64_U    = achar(181)
 | 
				
			||||||
 | 
					       character, parameter :: F32_DEMOTE_F64       = achar(182)
 | 
				
			||||||
 | 
					       character, parameter :: F64_CONVERT_I32_S    = achar(183)
 | 
				
			||||||
 | 
					       character, parameter :: F64_CONVERT_I32_U    = achar(184)
 | 
				
			||||||
 | 
					       character, parameter :: F64_CONVERT_I64_S    = achar(185)
 | 
				
			||||||
 | 
					       character, parameter :: F64_CONVERT_I64_U    = achar(186)
 | 
				
			||||||
 | 
					       character, parameter :: F64_PROMOTE_F32      = achar(187)
 | 
				
			||||||
 | 
					       character, parameter :: I32_REINTERPRET_F32  = achar(188)
 | 
				
			||||||
 | 
					       character, parameter :: I64_REINTERPRET_F64  = achar(189)
 | 
				
			||||||
 | 
					       character, parameter :: F32_REINTERPRET_I32  = achar(190)
 | 
				
			||||||
 | 
					       character, parameter :: F64_REINTERPRET_I64  = achar(191)
 | 
				
			||||||
 | 
					end module opcodes_mod
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					module types_mod
 | 
				
			||||||
 | 
					    implicit none
 | 
				
			||||||
 | 
					    ! https://webassembly.github.io/spec/core/binary/types.html
 | 
				
			||||||
 | 
					    character, parameter :: i32 = achar(127)
 | 
				
			||||||
 | 
					    character, parameter :: i64 = achar(126)
 | 
				
			||||||
 | 
					    character, parameter :: f32 = achar(125)
 | 
				
			||||||
 | 
					    character, parameter :: f64 = achar(124)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ! http://webassembly.github.io/spec/core/binary/types.html#function-types
 | 
				
			||||||
 | 
					    character, parameter :: type_function = achar(96)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    character, parameter :: type_empty_array = achar(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ! http://webassembly.github.io/spec/core/binary/modules.html#export-section
 | 
				
			||||||
 | 
					    character, parameter :: export_func     = achar(0)
 | 
				
			||||||
 | 
					    character, parameter :: export_table    = achar(1)
 | 
				
			||||||
 | 
					    character, parameter :: export_mem      = achar(2)
 | 
				
			||||||
 | 
					    character, parameter :: export_global   = achar(3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ! https://webassembly.github.io/spec/core/binary/modules.html#sections
 | 
				
			||||||
 | 
					    character, parameter :: section_custom  = achar(0)
 | 
				
			||||||
 | 
					    character, parameter :: section_type    = achar(1)
 | 
				
			||||||
 | 
					    character, parameter :: section_import  = achar(2)
 | 
				
			||||||
 | 
					    character, parameter :: section_func    = achar(3)
 | 
				
			||||||
 | 
					    character, parameter :: section_table   = achar(4)
 | 
				
			||||||
 | 
					    character, parameter :: section_memory  = achar(5)
 | 
				
			||||||
 | 
					    character, parameter :: section_global  = achar(6)
 | 
				
			||||||
 | 
					    character, parameter :: section_export  = achar(7)
 | 
				
			||||||
 | 
					    character, parameter :: section_start   = achar(8)
 | 
				
			||||||
 | 
					    character, parameter :: section_element = achar(9)
 | 
				
			||||||
 | 
					    character, parameter :: section_code    = achar(10)
 | 
				
			||||||
 | 
					    character, parameter :: section_data    = achar(11)
 | 
				
			||||||
 | 
					end module types_mod
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 25 KiB  | 
| 
						 | 
					@ -0,0 +1,30 @@
 | 
				
			||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html>
 | 
				
			||||||
 | 
						<head>
 | 
				
			||||||
 | 
							<meta charset="UTF-8" />
 | 
				
			||||||
 | 
							<meta name="viewport" content="width=device-width, initial-scale=1">
 | 
				
			||||||
 | 
							<link rel="stylesheet" href="style.css"> 
 | 
				
			||||||
 | 
						</head>
 | 
				
			||||||
 | 
						<body>
 | 
				
			||||||
 | 
					    <div class="navbar"></div>
 | 
				
			||||||
 | 
							<div class="row">
 | 
				
			||||||
 | 
								<div class="main">
 | 
				
			||||||
 | 
									<textarea
 | 
				
			||||||
 | 
										rows="20"
 | 
				
			||||||
 | 
										id="output"
 | 
				
			||||||
 | 
										class="form-control"
 | 
				
			||||||
 | 
					          style="background: black;color: white;"
 | 
				
			||||||
 | 
										wrap="off"
 | 
				
			||||||
 | 
									></textarea>
 | 
				
			||||||
 | 
									<canvas id="canvas" height="400" width="800"></canvas>
 | 
				
			||||||
 | 
									<script type="module">
 | 
				
			||||||
 | 
										WebAssembly.instantiateStreaming(fetch("module.wasm")).then((obj) => {
 | 
				
			||||||
 | 
											document.getElementById("output").innerHTML =
 | 
				
			||||||
 | 
												obj.instance.exports.main(5, 6);
 | 
				
			||||||
 | 
										});
 | 
				
			||||||
 | 
									</script>
 | 
				
			||||||
 | 
								</div>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
 | 
					    <div class="footer"></div>
 | 
				
			||||||
 | 
						</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,167 @@
 | 
				
			||||||
 | 
					program varaq_wasm_compiler
 | 
				
			||||||
 | 
					    use types_mod
 | 
				
			||||||
 | 
					    use opcodes_mod
 | 
				
			||||||
 | 
					    use tokenizer_mod
 | 
				
			||||||
 | 
					    implicit none
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    integer :: u, ios
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: tape
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    character, dimension(4) :: magic_module_header = [ achar(0), achar(97), achar(115), achar(109) ]
 | 
				
			||||||
 | 
					    character, dimension(4) :: module_version = [ achar(1), achar(0), achar(0), achar(0) ]
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: add_function_type 
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: type_section
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: func_section
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: export_section
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: code_code
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: function_body
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: code_section
 | 
				
			||||||
 | 
					    character, allocatable :: main_string(:)
 | 
				
			||||||
 | 
					    character(len = :), allocatable :: main_text
 | 
				
			||||||
 | 
					    integer :: a, b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    character(:), allocatable :: input_code
 | 
				
			||||||
 | 
					    type(token), dimension(:), allocatable :: tokens
 | 
				
			||||||
 | 
					    character(256) :: file_input, file_output
 | 
				
			||||||
 | 
					    integer :: i, sz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    call getarg(1, file_input)
 | 
				
			||||||
 | 
					    call getarg(2, file_output)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    open(u, file=file_input)
 | 
				
			||||||
 | 
					    inquire(unit=u, size=sz)
 | 
				
			||||||
 | 
					    close(u)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    allocate(character(len=sz) :: input_code)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    open(unit=u,file=file_input, status='old', access='stream')
 | 
				
			||||||
 | 
					    do i=1,sz
 | 
				
			||||||
 | 
					        read(u) input_code(i:i)
 | 
				
			||||||
 | 
					    end do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    tokens = tokenize(input_code)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    do i=1,size(tokens)
 | 
				
			||||||
 | 
					        print *, tokens(i)%index, tokens(i)%value, " ", tokens(i)%type
 | 
				
			||||||
 | 
					    end do
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    add_function_type = [type_function, encodeVector([f32, f32]), encodeVector([f32])]
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    ! the type section is a vector of function types
 | 
				
			||||||
 | 
					    type_section = createSection(section_type, encodeVector(add_function_type, 1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ! the function section is a vector of type indices that indicate the type of each function
 | 
				
			||||||
 | 
					    ! in the code section
 | 
				
			||||||
 | 
					    func_section = createSection(section_func, encodeVector([achar(0)]))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ! the export section is a vector of exported functions
 | 
				
			||||||
 | 
					    main_text = "main"
 | 
				
			||||||
 | 
					    main_string = transfer(main_text, ' ', size = len(main_text))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    export_section = createSection(section_export, encodeVector([encodeString(main_string), export_func, achar(0)], 1))
 | 
				
			||||||
 | 
					    a = 0
 | 
				
			||||||
 | 
					    b = 1
 | 
				
			||||||
 | 
					    code_code = [LOCAL_GET, unsignedLEB128(a), LOCAL_GET, unsignedLEB128(b), F32_ADD]
 | 
				
			||||||
 | 
					    function_body = encodeVector([type_empty_array, code_code, END])
 | 
				
			||||||
 | 
					    code_section = createSection(section_code, encodeVector([function_body], 1))
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    tape = [magic_module_header]
 | 
				
			||||||
 | 
					    tape = [tape, module_version]
 | 
				
			||||||
 | 
					    tape = [tape, type_section]
 | 
				
			||||||
 | 
					    tape = [tape, func_section]
 | 
				
			||||||
 | 
					    tape = [tape, export_section]
 | 
				
			||||||
 | 
					    tape = [tape, code_section]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    open(unit=u, file=file_output, access='stream', status='replace', action='write', iostat=ios)
 | 
				
			||||||
 | 
					    write(u, iostat=ios) tape
 | 
				
			||||||
 | 
					    close(u, iostat=ios)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    deallocate(tape)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					contains
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function signedLEB128(n) result(buffer)
 | 
				
			||||||
 | 
					    logical :: more
 | 
				
			||||||
 | 
					    integer :: n
 | 
				
			||||||
 | 
					    character :: byte
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: buffer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    more = .true.
 | 
				
			||||||
 | 
					    do while (more)
 | 
				
			||||||
 | 
					        byte = achar(iand(n, 127))
 | 
				
			||||||
 | 
					        n = rshift(n, 7)
 | 
				
			||||||
 | 
					        if (((n .ne. 0) .and. (iand(ichar(byte), 64) .eq. 0) .or. ((n .eq. -1) .and. (iand(ichar(byte), 64) .ne. 0)))) then
 | 
				
			||||||
 | 
					            more = .false.
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            byte = achar(ior(ichar(byte), 128))
 | 
				
			||||||
 | 
					        end if
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (allocated(buffer)) then
 | 
				
			||||||
 | 
					            buffer = [buffer, byte]
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            buffer = [byte]
 | 
				
			||||||
 | 
					        end if
 | 
				
			||||||
 | 
					    end do
 | 
				
			||||||
 | 
					end function signedLEB128
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function unsignedLEB128(n) result(buffer)
 | 
				
			||||||
 | 
					    integer :: n
 | 
				
			||||||
 | 
					    character :: byte
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: buffer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    do
 | 
				
			||||||
 | 
					      byte = achar(iand(n, 127))
 | 
				
			||||||
 | 
					      n = rshift(n, 7)
 | 
				
			||||||
 | 
					      if (n .ne. 0) then
 | 
				
			||||||
 | 
					        byte = achar(ior(ichar(byte), 128))
 | 
				
			||||||
 | 
					      end if
 | 
				
			||||||
 | 
					      if (allocated(buffer)) then
 | 
				
			||||||
 | 
					        buffer = [buffer, byte]
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					        buffer = [byte]
 | 
				
			||||||
 | 
					      end if
 | 
				
			||||||
 | 
					      if (n .eq. 0) then
 | 
				
			||||||
 | 
					        exit
 | 
				
			||||||
 | 
					      end if
 | 
				
			||||||
 | 
					    end do
 | 
				
			||||||
 | 
					end function unsignedLEB128
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function encodeString(data, length) result(arr)
 | 
				
			||||||
 | 
					    character, dimension(:) :: data
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: arr
 | 
				
			||||||
 | 
					    integer, optional :: length
 | 
				
			||||||
 | 
					    integer :: length_local
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (present(length)) then
 | 
				
			||||||
 | 
					        length_local = length
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        length_local = size(data)
 | 
				
			||||||
 | 
					    end if
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    arr = [unsignedLEB128(length_local), data]
 | 
				
			||||||
 | 
					end function encodeString
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function encodeVector(data, length) result(arr)
 | 
				
			||||||
 | 
					    character, dimension(:) :: data
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: arr
 | 
				
			||||||
 | 
					    integer, optional :: length
 | 
				
			||||||
 | 
					    integer :: length_local
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (present(length)) then
 | 
				
			||||||
 | 
					        length_local = length
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        length_local = size(data)
 | 
				
			||||||
 | 
					    end if
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    arr = [unsignedLEB128(length_local), data]
 | 
				
			||||||
 | 
					end function encodeVector
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function createSection(section, data) result (arr)
 | 
				
			||||||
 | 
					    character, dimension(:) :: data
 | 
				
			||||||
 | 
					    character, dimension(:), allocatable :: arr
 | 
				
			||||||
 | 
					    character :: section
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    arr = [section, encodeVector(data)]
 | 
				
			||||||
 | 
					end function createSection
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					end program varaq_wasm_compiler
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -0,0 +1,150 @@
 | 
				
			||||||
 | 
					* {
 | 
				
			||||||
 | 
						box-sizing: border-box;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@media (prefers-color-scheme: light) {
 | 
				
			||||||
 | 
						body {
 | 
				
			||||||
 | 
							background-color: white;
 | 
				
			||||||
 | 
							color: black;
 | 
				
			||||||
 | 
							margin-top: 0px;
 | 
				
			||||||
 | 
							margin-left: 0px;
 | 
				
			||||||
 | 
							margin-right: 0px;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						/* Header/logo Title */
 | 
				
			||||||
 | 
						.header {
 | 
				
			||||||
 | 
							padding: 60px;
 | 
				
			||||||
 | 
							text-align: center;
 | 
				
			||||||
 | 
							background: #ddd;
 | 
				
			||||||
 | 
							color: black;
 | 
				
			||||||
 | 
							width: 100%;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Style the top navigation bar */
 | 
				
			||||||
 | 
						.navbar {
 | 
				
			||||||
 | 
							display: flex;
 | 
				
			||||||
 | 
							flex-flow: row wrap;
 | 
				
			||||||
 | 
							justify-content: flex-start;
 | 
				
			||||||
 | 
							background-color: #eee;
 | 
				
			||||||
 | 
							width: 100%;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Style the navigation bar links */
 | 
				
			||||||
 | 
						.navbar a {
 | 
				
			||||||
 | 
							color: black;
 | 
				
			||||||
 | 
							padding: 10px;
 | 
				
			||||||
 | 
							text-decoration: none;
 | 
				
			||||||
 | 
							text-align: center;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Change color on hover */
 | 
				
			||||||
 | 
						.navbar a:hover {
 | 
				
			||||||
 | 
							background-color: #ddd;
 | 
				
			||||||
 | 
							color: black;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						.navbar a.active {
 | 
				
			||||||
 | 
							background-color: #ccc;
 | 
				
			||||||
 | 
							color: #222;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Column container */
 | 
				
			||||||
 | 
						.row {
 | 
				
			||||||
 | 
							display: flex;
 | 
				
			||||||
 | 
							flex-wrap: wrap;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Main column */
 | 
				
			||||||
 | 
						.main {
 | 
				
			||||||
 | 
							flex: 70%;
 | 
				
			||||||
 | 
							background-color: white;
 | 
				
			||||||
 | 
							padding: 20px;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Footer */
 | 
				
			||||||
 | 
						.footer {
 | 
				
			||||||
 | 
							padding: 20px;
 | 
				
			||||||
 | 
							text-align: center;
 | 
				
			||||||
 | 
							background: #ddd;
 | 
				
			||||||
 | 
							position: fixed;
 | 
				
			||||||
 | 
							left: 0;
 | 
				
			||||||
 | 
							bottom: 0;
 | 
				
			||||||
 | 
							width: 100%;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@media (prefers-color-scheme: dark) {
 | 
				
			||||||
 | 
						body {
 | 
				
			||||||
 | 
							background-color: black;
 | 
				
			||||||
 | 
							color: #ddd;
 | 
				
			||||||
 | 
							margin-top: 0px;
 | 
				
			||||||
 | 
							margin-left: 0px;
 | 
				
			||||||
 | 
							margin-right: 0px;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						/* Header/logo Title */
 | 
				
			||||||
 | 
						.header {
 | 
				
			||||||
 | 
							padding: 60px;
 | 
				
			||||||
 | 
							text-align: center;
 | 
				
			||||||
 | 
							background: #111;
 | 
				
			||||||
 | 
							color: #ddd;
 | 
				
			||||||
 | 
							width: 100%;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Style the top navigation bar */
 | 
				
			||||||
 | 
						.navbar {
 | 
				
			||||||
 | 
							display: flex;
 | 
				
			||||||
 | 
							flex-flow: row wrap;
 | 
				
			||||||
 | 
							justify-content: flex-start;
 | 
				
			||||||
 | 
							background-color: #222;
 | 
				
			||||||
 | 
							width: 100%;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Style the navigation bar links */
 | 
				
			||||||
 | 
						.navbar a {
 | 
				
			||||||
 | 
							color: #ddd;
 | 
				
			||||||
 | 
							padding: 14px 20px;
 | 
				
			||||||
 | 
							text-decoration: none;
 | 
				
			||||||
 | 
							text-align: center;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Change color on hover */
 | 
				
			||||||
 | 
						.navbar a:hover {
 | 
				
			||||||
 | 
							background-color: #111;
 | 
				
			||||||
 | 
							color: #ddd;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						.navbar a.active {
 | 
				
			||||||
 | 
							background-color: #ccc;
 | 
				
			||||||
 | 
							color: #222;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Column container */
 | 
				
			||||||
 | 
						.row {
 | 
				
			||||||
 | 
							display: flex;
 | 
				
			||||||
 | 
							flex-wrap: wrap;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Main column */
 | 
				
			||||||
 | 
						.main {
 | 
				
			||||||
 | 
							flex: 70%;
 | 
				
			||||||
 | 
							background-color: #000;
 | 
				
			||||||
 | 
							padding: 20px;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Footer */
 | 
				
			||||||
 | 
						.footer {
 | 
				
			||||||
 | 
							padding: 20px;
 | 
				
			||||||
 | 
							text-align: center;
 | 
				
			||||||
 | 
							background: #111;
 | 
				
			||||||
 | 
							position: fixed;
 | 
				
			||||||
 | 
							left: 0;
 | 
				
			||||||
 | 
							bottom: 0;
 | 
				
			||||||
 | 
							width: 100%;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@media screen and (max-width: 700px) {
 | 
				
			||||||
 | 
						.row,
 | 
				
			||||||
 | 
						.navbar {
 | 
				
			||||||
 | 
							flex-direction: column;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue