Skip to content

Commit

Permalink
add: auth when FROST_PRIVATE_REGISTRY_AUTH
Browse files Browse the repository at this point in the history
  • Loading branch information
oriollinan committed Jan 13, 2025
1 parent 880fb2d commit fa200ef
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 30 deletions.
4 changes: 2 additions & 2 deletions examples/hello.ff
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
%%

%%
% External function declarations
% Standard Library
%%
printf: foreign *byte ... -> int
import "./examples/std/io.ff"

%%
% Main function
Expand Down
15 changes: 7 additions & 8 deletions examples/julia.ff
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
%%

%%
% External function declarations
% Standard Library
%%
printf: foreign *byte ... -> int
usleep: foreign int -> never
sin: foreign double -> double
cos: foreign double -> double
import "./examples/std/io.ff"
import "./examples/std/math.ff"
import "./examples/std/uni.ff"

%%
% Function to clear the screen
Expand Down Expand Up @@ -79,13 +78,13 @@ main: never -> int = {
FRAME_DELAY: int = 50000
PI: double = 3,14159265359
t: double = 0,0

loop true {
clear_screen()

c_real: double = -0,4 + 0,4 * cos(t)
c_imag: double = 0,4 * sin(t)

render_julia(c_real c_imag)

t = t + 0,05
Expand All @@ -95,6 +94,6 @@ main: never -> int = {

usleep(FRAME_DELAY)
}

0
}
4 changes: 2 additions & 2 deletions examples/mandelbrot.ff
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
%%

%%
% External function declarations
% Standard Library
%%
printf: foreign *byte ... -> int
import "./examples/std/io.ff"

%%
% Function to render the Mandelbrot set
Expand Down
12 changes: 6 additions & 6 deletions examples/putstr.ff
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
%%

%%
% External function declarations
% Standard Library
%%
write: foreign int *byte int -> int
strlen: foreign *byte -> int
perror: foreign *byte -> never
import "./examples/std/io.ff"
import "./examples/std/string.ff"
import "./examples/std/uni.ff"

%%
% Function to write a string to stdout
Expand All @@ -20,7 +20,7 @@ putstr: *byte -> int = string {

out: int = 0
len: int = strlen(string)

from 0 to len + 1 by 1 |i: int| {
ptr: *byte = string + i

Expand All @@ -38,7 +38,7 @@ main: never -> int = {

length: int = strlen(string)
result: int = putstr(string) - 1 % account for '\0'

if not (result is length) {
perror("putstr")
ret 1
Expand Down
4 changes: 2 additions & 2 deletions examples/sierpinski.ff
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
%%

%%
% External function declarations
% Standard Library
%%
printf: foreign *byte ... -> int
import "./examples/std/io.ff"

%%
% Draw the Sierpinski Triangle
Expand Down
10 changes: 5 additions & 5 deletions examples/sine.ff
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
%%

%%
% External function declarations
% Standard Library
%%
sin: foreign double -> double
printf: foreign *byte ... -> int
usleep: foreign int -> never
import "./examples/std/io.ff"
import "./examples/std/math.ff"
import "./examples/std/uni.ff"

%%
% Function to draw the sine wave
%
% This function plots a sine wave on the terminal using ASCII characters.
% This function plots a sine wave on the terminal using ASCII characters.
% The sine wave is plotted based on the sine function and its amplitude is scaled
% to fit within the screen height.
%%
Expand Down
5 changes: 5 additions & 0 deletions examples/std/io.ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
printf: foreign *byte ... -> int
scanf: foreign *byte ... -> int
puts: foreign *byte -> int
putchar: foreign byte -> int
perror: foreign *byte -> never
22 changes: 22 additions & 0 deletions examples/std/math.ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sin: foreign double -> double
cos: foreign double -> double
tan: foreign double -> double
asin: foreign double -> double
acos: foreign double -> double
atan: foreign double -> double
atan2: foreign double double -> double
sinh: foreign double -> double
cosh: foreign double -> double
tanh: foreign double -> double
exp: foreign double -> double
log: foreign double -> double
log10: foreign double -> double
sqrt: foreign double -> double
ceil: foreign double -> double
floor: foreign double -> double
fabs: foreign double -> double
pow: foreign double double -> double
fmod: foreign double double -> double
hypot: foreign double double -> double
ldexp: foreign double int -> double
frexp: foreign double *int -> double
14 changes: 14 additions & 0 deletions examples/std/string.ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
strlen: foreign *byte -> int
strcmp: foreign *byte *byte -> int
strncmp: foreign *byte *byte int -> int
strcpy: foreign *byte *byte -> *byte
strncpy: foreign *byte *byte int -> *byte
strcat: foreign *byte *byte -> *byte
strncat: foreign *byte *byte int -> *byte
strchr: foreign *byte int -> *byte
strrchr: foreign *byte int -> *byte
strstr: foreign *byte *byte -> *byte
memset: foreign *byte int int -> *byte
memcpy: foreign *byte *byte int -> *byte
memmove: foreign *byte *byte int -> *byte
memcmp: foreign *byte *byte int -> int
9 changes: 9 additions & 0 deletions examples/std/uni.ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
write: foreign int *byte int -> int
read: foreign int *byte int -> int
close: foreign int -> int
unlink: foreign *byte -> int
access: foreign *byte int -> int
chdir: foreign *byte -> int
rmdir: foreign *byte -> int
sleep: foreign int -> int
usleep: foreign int -> int
3 changes: 2 additions & 1 deletion glados.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ library
megaparsec >=9.7.0,
mtl >=2.2.2 && <2.3,
parser-combinators >= 1.3.0,
http-conduit >= 2.3.9
http-conduit >= 2.3.9,
case-insensitive >= 1.2.1.0

hs-source-dirs: lib
default-language: Haskell2010
Expand Down
14 changes: 10 additions & 4 deletions lib/Ast/Parser/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import qualified Ast.Parser.Utils as PU
import qualified Control.Monad.IO.Class as IO
import qualified Control.Monad.State as S
import qualified Data.ByteString.Char8 as BS
import qualified Data.CaseInsensitive as CI
import qualified Network.HTTP.Simple as N
import qualified System.Environment as E
import qualified Text.Megaparsec as M

parseImport :: PU.Parser String -> PU.Parser String
Expand All @@ -24,7 +26,7 @@ parseImport p = do
S.modify $ PS.insertImport import'
S.modify $ PS.setImportDepth $ depth + 1
source <- case import' of
('.' : '/' : _) -> IO.liftIO $ localImport import'
('.' : _) -> IO.liftIO $ localImport import'
_ -> IO.liftIO $ externalImport import'
input <- M.getInput
M.setInput $ source ++ input
Expand All @@ -39,8 +41,12 @@ localImport = readFile

externalImport :: String -> IO String
externalImport url = do
req <- case N.parseRequest url of
Left err -> fail ("Invalid URL: " ++ show err)
Right req -> return req
auth <- E.lookupEnv "FROST_PRIVATE_REGISTRY_AUTH"
req <- case auth of
Just token ->
N.setRequestHeaders
[(CI.mk $ BS.pack "Authorization", BS.pack $ "Bearer " ++ token)]
<$> N.parseRequest url
Nothing -> N.parseRequest url
res <- N.httpBS req
return $ BS.unpack $ N.getResponseBody res

0 comments on commit fa200ef

Please # to comment.